Skip to content

Commit

Permalink
feat: set x-shinkai-* (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
acedward authored Dec 17, 2024
1 parent 3c9e04f commit 9241bf4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ function PlaygroundToolEditor({
handleSaveTool,
resetToolCode,
handleCreateToolCode,
xShinkaiAppId,
xShinkaiToolId,
} = useToolCode({
createToolCodeForm: form,
initialState: toolCodeInitialValues,
Expand Down Expand Up @@ -159,6 +161,8 @@ function PlaygroundToolEditor({
tools: form.getValues('tools'),
language: form.getValues('language'),
configs,
xShinkaiAppId,
xShinkaiToolId,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -321,6 +324,8 @@ export const useToolCode = ({
token: auth?.api_v2_key ?? '',
nodeAddress: auth?.node_address ?? '',
language: currentLanguage,
xShinkaiAppId,
xShinkaiToolId,
});
};

Expand Down Expand Up @@ -446,5 +451,7 @@ export const useToolCode = ({
goNextToolCode,
handleSaveTool,
resetToolCode,
xShinkaiAppId,
xShinkaiToolId,
};
};
15 changes: 11 additions & 4 deletions libs/shinkai-message-ts/src/api/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,17 @@ export const executeToolCode = async (
nodeAddress: string,
bearerToken: string,
payload: ExecuteToolCodeRequest,
xShinkaiAppId: string,
xShinkaiToolId: string,
) => {
const response = await httpClient.post(
urlJoin(nodeAddress, '/v2/code_execution'),
payload,
{
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',
},
Expand All @@ -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',
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const executeToolCode = async ({
tools,
language,
configs,
xShinkaiAppId,
xShinkaiToolId,
}: ExecuteToolCodeInput) => {
const toolTypeLanguageMap = {
[CodeLanguage.Python]: DynamicToolType.PythonDynamic,
Expand All @@ -28,5 +30,8 @@ export const executeToolCode = async ({
llm_provider: llmProviderId,
tools,
extra_config: configs,
});
},
xShinkaiAppId,
xShinkaiToolId,
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type ExecuteToolCodeInput = Token & {
llmProviderId: string;
tools: string[];
language: CodeLanguage;
xShinkaiAppId: string;
xShinkaiToolId: string;
};

export type ExecuteToolCodeOutput = ExecuteToolCodeResponse;
11 changes: 8 additions & 3 deletions libs/shinkai-node-state/src/v2/mutations/saveToolCode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export type SaveToolCodeInput = Token & {
metadata: Record<string, any>;
code?: string;
language: CodeLanguage;
xShinkaiAppId: string;
xShinkaiToolId: string;
};

export type SaveToolCodeOutput = SaveToolCodeResponse;

0 comments on commit 9241bf4

Please sign in to comment.