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 c6542af81..6a4196d27 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 @@ -125,6 +125,8 @@ function PlaygroundToolEditor({ handleSaveTool, resetToolCode, handleCreateToolCode, + xShinkaiAppId, + xShinkaiToolId, } = useToolCode({ createToolCodeForm: form, initialState: toolCodeInitialValues, @@ -159,6 +161,8 @@ function PlaygroundToolEditor({ tools: form.getValues('tools'), language: form.getValues('language'), configs, + xShinkaiAppId, + xShinkaiToolId, }); }; 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 ed41eafcc..8cc698ea8 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 @@ -176,6 +176,9 @@ export const useToolCode = ({ 'idle' | 'pending' | 'success' | 'error' >(initialState?.state ?? 'idle'); + const [xShinkaiAppId] = useState(() => `app-id-${Date.now()}`); + const [xShinkaiToolId] = useState(() => `task-id-${Date.now()}`); + useEffect(() => { if (initialState?.code) { baseToolCodeRef.current = initialState.code; @@ -321,6 +324,8 @@ export const useToolCode = ({ token: auth?.api_v2_key ?? '', nodeAddress: auth?.node_address ?? '', language: currentLanguage, + xShinkaiAppId, + xShinkaiToolId, }); }; @@ -446,5 +451,7 @@ export const useToolCode = ({ goNextToolCode, handleSaveTool, resetToolCode, + xShinkaiAppId, + xShinkaiToolId, }; }; diff --git a/libs/shinkai-message-ts/src/api/tools/index.ts b/libs/shinkai-message-ts/src/api/tools/index.ts index e2e52739f..7ed0e8648 100644 --- a/libs/shinkai-message-ts/src/api/tools/index.ts +++ b/libs/shinkai-message-ts/src/api/tools/index.ts @@ -239,6 +239,8 @@ export const executeToolCode = async ( nodeAddress: string, bearerToken: string, payload: ExecuteToolCodeRequest, + xShinkaiAppId: string, + xShinkaiToolId: string, ) => { const response = await httpClient.post( urlJoin(nodeAddress, '/v2/code_execution'), @@ -246,9 +248,8 @@ export const executeToolCode = async ( { headers: { Authorization: `Bearer ${bearerToken}`, - // TODO: remove hardcoded values - 'x-shinkai-app-id': 'app-test', - 'x-shinkai-tool-id': 'tool-test', + 'x-shinkai-app-id': xShinkaiAppId, + 'x-shinkai-tool-id': xShinkaiToolId, }, responseType: 'json', }, @@ -260,12 +261,18 @@ export const saveToolCode = async ( nodeAddress: string, bearerToken: string, payload: SaveToolCodeRequest, + xShinkaiAppId: string, + xShinkaiToolId: string, ) => { const response = await httpClient.post( urlJoin(nodeAddress, '/v2/set_playground_tool'), payload, { - headers: { Authorization: `Bearer ${bearerToken}` }, + headers: { + Authorization: `Bearer ${bearerToken}`, + 'x-shinkai-app-id': xShinkaiAppId, + 'x-shinkai-tool-id': xShinkaiToolId, + }, responseType: 'json', }, ); 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 f402e2a24..5298d7392 100644 --- a/libs/shinkai-node-state/src/v2/mutations/executeToolCode/index.ts +++ b/libs/shinkai-node-state/src/v2/mutations/executeToolCode/index.ts @@ -15,6 +15,8 @@ export const executeToolCode = async ({ tools, language, configs, + xShinkaiAppId, + xShinkaiToolId, }: ExecuteToolCodeInput) => { const toolTypeLanguageMap = { [CodeLanguage.Python]: DynamicToolType.PythonDynamic, @@ -28,5 +30,8 @@ export const executeToolCode = async ({ llm_provider: llmProviderId, tools, extra_config: configs, - }); + }, + xShinkaiAppId, + xShinkaiToolId, + ); }; diff --git a/libs/shinkai-node-state/src/v2/mutations/executeToolCode/types.ts b/libs/shinkai-node-state/src/v2/mutations/executeToolCode/types.ts index f30015934..fa6ded0bf 100644 --- a/libs/shinkai-node-state/src/v2/mutations/executeToolCode/types.ts +++ b/libs/shinkai-node-state/src/v2/mutations/executeToolCode/types.ts @@ -12,6 +12,8 @@ export type ExecuteToolCodeInput = Token & { llmProviderId: string; tools: string[]; language: CodeLanguage; + xShinkaiAppId: string; + xShinkaiToolId: string; }; export type ExecuteToolCodeOutput = ExecuteToolCodeResponse; diff --git a/libs/shinkai-node-state/src/v2/mutations/saveToolCode/index.ts b/libs/shinkai-node-state/src/v2/mutations/saveToolCode/index.ts index 80ca7498c..635699146 100644 --- a/libs/shinkai-node-state/src/v2/mutations/saveToolCode/index.ts +++ b/libs/shinkai-node-state/src/v2/mutations/saveToolCode/index.ts @@ -9,11 +9,16 @@ export const saveToolCode = async ({ metadata, code, language, + xShinkaiAppId, + xShinkaiToolId, }: SaveToolCodeInput) => { return await saveToolCodeApi(nodeAddress, token, { code: code ?? '', metadata, - job_id: jobId, - language, - }); + job_id: jobId, + language, + }, + xShinkaiAppId, + xShinkaiToolId, + ); }; diff --git a/libs/shinkai-node-state/src/v2/mutations/saveToolCode/types.ts b/libs/shinkai-node-state/src/v2/mutations/saveToolCode/types.ts index d5d040259..7c84379f3 100644 --- a/libs/shinkai-node-state/src/v2/mutations/saveToolCode/types.ts +++ b/libs/shinkai-node-state/src/v2/mutations/saveToolCode/types.ts @@ -10,6 +10,8 @@ export type SaveToolCodeInput = Token & { metadata: Record; code?: string; language: CodeLanguage; + xShinkaiAppId: string; + xShinkaiToolId: string; }; export type SaveToolCodeOutput = SaveToolCodeResponse;