fix: alignment api

This commit is contained in:
jialin
2026-05-11 19:49:21 +08:00
committed by jialin
parent 9e0dd5b003
commit b13ba0a229
33 changed files with 738 additions and 365 deletions
@@ -35,6 +35,49 @@ export const ImagePullPolicyOptions: {
export const DefaultImagePullPolicy: ImagePullPolicy = 'IfNotPresent';
export const normalizeCommand = (value: string): string[] => {
if (!value) return [];
const tokens: string[] = [];
let current = '';
let inQuote: '"' | "'" | null = null;
let quoteStart = -1;
for (const ch of value) {
if (inQuote) {
if (ch === inQuote) {
inQuote = null;
quoteStart = -1;
} else {
current += ch;
}
} else if (ch === '"' || ch === "'") {
inQuote = ch;
quoteStart = current.length;
} else if (/\s/.test(ch)) {
tokens.push(current);
current = '';
} else {
current += ch;
}
}
if (inQuote && quoteStart >= 0) {
current =
current.slice(0, quoteStart) + inQuote + current.slice(quoteStart);
}
tokens.push(current);
return tokens;
};
export const stringifyCommand = (tokens?: string[]): string => {
if (!tokens?.length) return '';
return tokens
.map((token) => {
if (!/\s/.test(token)) return token;
if (token.startsWith('"') || token.startsWith("'")) return token;
return `"${token}"`;
})
.join(' ');
};
export const templateActions = [
{
label: 'common.button.edit',
@@ -7,10 +7,13 @@ import {
} from '@gpustack/core-ui';
import { useIntl } from '@umijs/max';
import { Flex, Form } from 'antd';
import _ from 'lodash';
import { useMemo } from 'react';
import { GPUsConfigs } from '../../../resources/config/gpu-driver';
import { ImagePullPolicyOptions } from '../config';
import {
ImagePullPolicyOptions,
normalizeCommand,
stringifyCommand
} from '../config';
import { FormData } from '../config/types';
import Env from './env';
import Ports from './ports';
@@ -96,8 +99,8 @@ const Basic: React.FC<BasicProps> = ({ page = 'template' }) => {
</Form.Item>
<Form.Item<FormData>
name={['spec', 'command']}
normalize={(value: string) => _.split(value, '\n').map(_.trim)}
getValueProps={(value) => ({ value: _.join(value, '\n') })}
normalize={normalizeCommand}
getValueProps={(value) => ({ value: stringifyCommand(value) })}
>
<Textarea
label={intl.formatMessage({ id: 'gpuservice.template.command' })}
@@ -61,13 +61,20 @@ const GPUServiceTemplateForm: React.FC<TemplateFormProps> = forwardRef(
initialValues={{
spec: {
imagePullPolicy: DefaultImagePullPolicy,
command: [],
command: ['tail', '-f', '/dev/null'],
ports: [
{
protocol: 'TCP',
port: 22
}
],
volumeMount: '/workspace',
resources: {
cpu: '1',
ram: '2Gi',
localStorage: '15Gi',
accelerator: ''
},
env: []
}
}}