Feat: Convert the arguments parameter of the code operator to a dictionary #3221 (#8623)

### What problem does this PR solve?

Feat: Convert the arguments parameter of the code operator to a
dictionary #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-07-02 18:34:21 +08:00
committed by GitHub
parent 695bfe34a2
commit 040e4ad8a5
11 changed files with 63 additions and 125 deletions

View File

@ -22,6 +22,8 @@ import { useParams } from 'umi';
import { v4 as uuid } from 'uuid';
import { BeginId } from '../constant';
import { AgentChatLogContext } from '../context';
import { transferInputsArrayToObject } from '../form/begin-form/use-watch-change';
import { useGetBeginNodeDataQuery } from '../hooks/use-get-begin-query';
import { BeginQuery } from '../interface';
import useGraphStore from '../store';
import { receiveMessageError } from '../utils';
@ -109,6 +111,7 @@ export const useSendNextMessage = () => {
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
const { refetch } = useFetchAgent();
const { addEventList } = useContext(AgentChatLogContext);
const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
const { send, answerList, done, stopOutputMessage } = useSendMessageBySSE(
api.runCanvas,
@ -191,12 +194,22 @@ export const useSendNextMessage = () => {
);
useEffect(() => {
if (prologue) {
const query = getBeginNodeDataQuery();
if (query.length > 0) {
send({ id: agentId, inputs: transferInputsArrayToObject(query) });
} else if (prologue) {
addNewestOneAnswer({
answer: prologue,
});
}
}, [addNewestOneAnswer, prologue]);
}, [
addNewestOneAnswer,
agentId,
getBeginNodeDataQuery,
prologue,
send,
sendFormMessage,
]);
useEffect(() => {
addEventList(answerList);

View File

@ -1,86 +0,0 @@
'use client';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { toast } from 'sonner';
import { z } from 'zod';
import { Button } from '@/components/ui/button';
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@/components/ui/form';
import { Input } from '@/components/ui/input';
import { Message } from '@/interfaces/database/chat';
import { get } from 'lodash';
import { useParams } from 'umi';
import { useSendNextMessage } from './hooks';
const FormSchema = z.object({
username: z.string().min(2, {
message: 'Username must be at least 2 characters.',
}),
});
type InputFormProps = Pick<ReturnType<typeof useSendNextMessage>, 'send'> & {
message: Message;
};
export function InputForm({ send, message }: InputFormProps) {
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
username: '',
},
});
const { id: canvasId } = useParams();
function onSubmit(data: z.infer<typeof FormSchema>) {
const inputs = get(message, 'data.inputs', {});
const nextInputs = Object.entries(inputs).reduce((pre, [key, val]) => {
pre[key] = { ...val, value: data.username };
return pre;
}, {});
send({
inputs: nextInputs,
id: canvasId,
});
toast('You submitted the following values', {
description: (
<pre className="mt-2 w-[320px] rounded-md bg-neutral-950 p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code>
</pre>
),
});
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="w-2/3 space-y-6">
<FormField
control={form.control}
name="username"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="shadcn" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
);
}