Skip to content

Commit f31263e

Browse files
committed
add mb-metadata to local toolcalls
1 parent 4af274e commit f31263e

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

src/components/chat/ChatContent.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ export const ChatContent = ({
7979
if (!localAgent) return undefined;
8080

8181
try {
82-
return await executeLocalToolCall(localAgent, toolCall);
82+
return await executeLocalToolCall({
83+
localAgent,
84+
toolCall,
85+
metadata: {
86+
accountId,
87+
evmAddress,
88+
chainId,
89+
},
90+
});
8391
} catch (error) {
8492
const errorMessage =
8593
error instanceof Error ? error.message : "Unknown error";

src/lib/local-agent.ts

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { BitteToolResult } from "../types";
22

3-
interface ToolCall {
4-
toolName: string;
5-
args?: any;
3+
interface ToolCall<NAME extends string, ARGS> {
4+
toolCallId: string;
5+
toolName: NAME;
6+
args: ARGS;
67
}
78

89
interface LocalAgent {
@@ -12,10 +13,17 @@ interface LocalAgent {
1213
};
1314
}
1415

15-
export const executeLocalToolCall = async (
16-
localAgent: LocalAgent,
17-
toolCall: ToolCall
18-
): Promise<BitteToolResult | undefined> => {
16+
interface LocalToolCallProps {
17+
localAgent: LocalAgent;
18+
toolCall: ToolCall<string, unknown>;
19+
metadata?: Record<string, unknown>;
20+
}
21+
22+
export const executeLocalToolCall = async ({
23+
localAgent,
24+
toolCall,
25+
metadata,
26+
}: LocalToolCallProps): Promise<BitteToolResult | undefined> => {
1927
const baseUrl = localAgent.spec.servers?.[0]?.url;
2028
if (!baseUrl) return undefined;
2129

@@ -32,7 +40,12 @@ export const executeLocalToolCall = async (
3240
try {
3341
const args = toolCall.args ? JSON.parse(JSON.stringify(toolCall.args)) : {};
3442
const { url, remainingArgs } = buildUrlWithParams(baseUrl, toolPath, args);
35-
const { options } = buildRequestOptions(httpMethod, remainingArgs);
43+
44+
const { options } = buildRequestOptions({
45+
httpMethod,
46+
remainingArgs,
47+
metadata,
48+
});
3649

3750
const finalUrl =
3851
httpMethod === "GET" ? handleQueryParams(url, remainingArgs) : url;
@@ -103,12 +116,18 @@ export const buildUrlWithParams = (
103116
return { url, remainingArgs };
104117
};
105118

106-
export const buildRequestOptions = (
107-
httpMethod: string,
108-
remainingArgs: any
109-
): { options: RequestInit } => {
119+
export const buildRequestOptions = ({
120+
httpMethod,
121+
remainingArgs,
122+
metadata,
123+
}: {
124+
httpMethod: string;
125+
remainingArgs: any;
126+
metadata?: Record<string, unknown>;
127+
}): { options: RequestInit } => {
110128
const headers: HeadersInit = {
111129
"Content-Type": "application/json",
130+
...(metadata ? { "mb-metadata": JSON.stringify(metadata) } : {}),
112131
};
113132

114133
const fetchOptions: RequestInit = {

src/lib/sign-message.ts

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const signMessage = async (
3737
console.error("failed in signMessage", errorMessage);
3838
throw new Error(errorMessage);
3939
});
40-
console.log("signedMessage", signedMessage);
4140

4241
// Bitte Wallet redirects so signMessage will not have a result
4342
if (signedMessage) {

0 commit comments

Comments
 (0)