chore: stash code

This commit is contained in:
Junyan Qin
2026-02-02 00:27:48 +08:00
committed by huanghuoguoguo
parent a2817f6524
commit 5d3dfccae1
7 changed files with 374 additions and 11 deletions

View File

@@ -1,4 +1,7 @@
import { IDynamicFormItemSchema } from '@/app/infra/entities/form/dynamic';
import {
IDynamicFormItemSchema,
DynamicFormItemType,
} from '@/app/infra/entities/form/dynamic';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
@@ -198,6 +201,19 @@ function WebhookUrlField({
);
}
/**
* Normalize plugin manifest type names to frontend-compatible types
*/
function normalizeItemType(type: string): string {
const typeMap: Record<string, string> = {
'select-llm-model': DynamicFormItemType.LLM_MODEL_SELECTOR,
'select-knowledge-bases': DynamicFormItemType.KNOWLEDGE_BASE_MULTI_SELECTOR,
number: DynamicFormItemType.FLOAT,
json: DynamicFormItemType.TEXT,
};
return typeMap[type] || type;
}
export default function DynamicFormComponent({
itemConfigList,
onSubmit,
@@ -278,8 +294,11 @@ export default function DynamicFormComponent({
const formSchema = z.object(
editableItems.reduce(
(acc, item) => {
// Normalize type to handle plugin manifest type names
const normalizedType = normalizeItemType(item.type);
let fieldSchema;
switch (item.type) {
switch (normalizedType) {
case 'integer':
fieldSchema = z.number();
break;
@@ -333,6 +352,9 @@ export default function DynamicFormComponent({
}),
);
break;
case 'text':
fieldSchema = z.string();
break;
default:
fieldSchema = z.string();
}
@@ -486,6 +508,12 @@ export default function DynamicFormComponent({
/>
{itemConfigList.map((config) => {
// Create a normalized config with type converted to frontend format
const normalizedConfig = {
...config,
type: normalizeItemType(config.type),
};
if (config.show_if) {
const dependValue = resolveShowIfValue(
config.show_if.field,
@@ -564,7 +592,7 @@ export default function DynamicFormComponent({
) : null;
// Webhook URL fields are display-only; render outside of form binding
if (config.type === 'webhook-url') {
if (normalizedConfig.type === 'webhook-url') {
const webhookUrl = (systemContext?.webhook_url as string) || '';
const extraWebhookUrl =
(systemContext?.extra_webhook_url as string) || '';
@@ -586,7 +614,7 @@ export default function DynamicFormComponent({
);
}
if (config.type === 'embed-code') {
if (normalizedConfig.type === 'embed-code') {
const botUuid = (systemContext?.bot_uuid as string) || '';
if (!botUuid) return null;
@@ -677,7 +705,7 @@ export default function DynamicFormComponent({
}
// Boolean fields use a special inline layout
if (config.type === 'boolean') {
if (normalizedConfig.type === 'boolean') {
return (
<FormField
key={config.id}
@@ -704,7 +732,7 @@ export default function DynamicFormComponent({
</div>
<FormControl>
<DynamicFormItemComponent
config={config}
config={normalizedConfig}
field={field}
onFileUploaded={onFileUploaded}
/>
@@ -741,7 +769,7 @@ export default function DynamicFormComponent({
)}
>
<DynamicFormItemComponent
config={config}
config={normalizedConfig}
field={field}
onFileUploaded={onFileUploaded}
/>

View File

@@ -247,6 +247,7 @@ export default function DynamicFormItemComponent({
switch (config.type) {
case DynamicFormItemType.INT:
case DynamicFormItemType.FLOAT:
case DynamicFormItemType.NUMBER:
return (
<Input
type="number"
@@ -301,6 +302,15 @@ export default function DynamicFormItemComponent({
/>
);
case DynamicFormItemType.JSON:
return (
<Textarea
{...field}
className="min-h-[200px] font-mono text-sm"
placeholder='{"key": "value"}'
/>
);
case DynamicFormItemType.BOOLEAN:
return <Switch checked={field.value} onCheckedChange={field.onChange} />;

View File

@@ -59,6 +59,11 @@ export enum DynamicFormItemType {
WEBHOOK_URL = 'webhook-url',
EMBED_CODE = 'embed-code',
QR_CODE_LOGIN = 'qr-code-login',
// Plugin manifest type aliases for compatibility
SELECT_LLM_MODEL = 'select-llm-model',
SELECT_KNOWLEDGE_BASES = 'select-knowledge-bases',
NUMBER = 'number',
JSON = 'json',
}
export interface IFileConfig {