From 90a9b5db8612b391816e125d7482dee8f1d0c75a Mon Sep 17 00:00:00 2001 From: paulclindo Date: Wed, 11 Dec 2024 20:51:24 -0500 Subject: [PATCH] feat: add config --- .../components/tool-playground.tsx | 40 ++++++++++++++++--- .../playground-tool/hooks/use-tool-code.ts | 2 - .../src/v2/mutations/executeToolCode/index.ts | 2 +- .../rjsf/FieldTemplate/FieldTemplate.tsx | 2 +- .../components/rjsf/TitleField/TitleField.tsx | 6 +-- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/apps/shinkai-desktop/src/components/playground-tool/components/tool-playground.tsx b/apps/shinkai-desktop/src/components/playground-tool/components/tool-playground.tsx index 6a39f7ff6..c6542af81 100644 --- a/apps/shinkai-desktop/src/components/playground-tool/components/tool-playground.tsx +++ b/apps/shinkai-desktop/src/components/playground-tool/components/tool-playground.tsx @@ -1,6 +1,5 @@ import { ReloadIcon } from '@radix-ui/react-icons'; import { FormProps } from '@rjsf/core'; -import { RJSFSchema } from '@rjsf/utils'; import validator from '@rjsf/validator-ajv8'; import { useTranslation } from '@shinkai_network/shinkai-i18n'; import { @@ -149,7 +148,7 @@ function PlaygroundToolEditor({ }); const handleRunCode: FormProps['onSubmit'] = async (data) => { - const params = data.formData; + const { configs, params } = data.formData; const updatedCodeWithoutSave = codeEditorRef.current?.value ?? ''; await executeToolCodeQuery.mutateAsync({ code: isDirtyCodeEditor ? updatedCodeWithoutSave : toolCode, @@ -159,6 +158,7 @@ function PlaygroundToolEditor({ llmProviderId: form.getValues('llmProviderId'), tools: form.getValues('tools'), language: form.getValues('language'), + configs, }); }; @@ -629,11 +629,41 @@ function PlaygroundToolEditor({ noHtml5Validate={true} onChange={(e) => setFormData(e.formData)} onSubmit={handleRunCode} - schema={ - metadataGenerationData?.parameters as RJSFSchema - } + schema={{ + type: 'object', + properties: { + ...(metadataGenerationData?.configurations + ?.properties && + Object.keys( + metadataGenerationData.configurations + .properties, + ).length > 0 + ? { + configs: + metadataGenerationData.configurations, + } + : {}), + ...(metadataGenerationData?.parameters + ?.properties && + Object.keys( + metadataGenerationData.parameters + .properties, + ).length > 0 + ? { + params: + metadataGenerationData.parameters, + } + : {}), + }, + }} uiSchema={{ 'ui:submitButtonOptions': { norender: true }, + configs: { + 'ui:title': 'Config', + }, + params: { + 'ui:title': 'Inputs', + }, }} validator={validator} /> diff --git a/apps/shinkai-desktop/src/components/playground-tool/hooks/use-tool-code.ts b/apps/shinkai-desktop/src/components/playground-tool/hooks/use-tool-code.ts index bcf4f15ba..ed41eafcc 100644 --- a/apps/shinkai-desktop/src/components/playground-tool/hooks/use-tool-code.ts +++ b/apps/shinkai-desktop/src/components/playground-tool/hooks/use-tool-code.ts @@ -410,8 +410,6 @@ export const useToolCode = ({ }, 0); }; - console.log({ toolHistory, toolCode }); - return { chatInboxId, toolCode, diff --git a/libs/shinkai-node-state/src/v2/mutations/executeToolCode/index.ts b/libs/shinkai-node-state/src/v2/mutations/executeToolCode/index.ts index 613bc4588..f402e2a24 100644 --- a/libs/shinkai-node-state/src/v2/mutations/executeToolCode/index.ts +++ b/libs/shinkai-node-state/src/v2/mutations/executeToolCode/index.ts @@ -24,7 +24,7 @@ export const executeToolCode = async ({ return await executeToolCodeApi(nodeAddress, token, { tool_type: toolTypeLanguageMap[language], code, - parameters: params, + parameters: params ?? {}, llm_provider: llmProviderId, tools, extra_config: configs, diff --git a/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx b/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx index d3178eb66..0f4e5d997 100644 --- a/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx +++ b/libs/shinkai-ui/src/components/rjsf/FieldTemplate/FieldTemplate.tsx @@ -60,7 +60,7 @@ export default function FieldTemplate< style={style} uiSchema={uiSchema} > -
+
{displayLabel && (