1
1
import { BitteToolResult } from "../types" ;
2
2
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 ;
6
7
}
7
8
8
9
interface LocalAgent {
@@ -12,10 +13,17 @@ interface LocalAgent {
12
13
} ;
13
14
}
14
15
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 > => {
19
27
const baseUrl = localAgent . spec . servers ?. [ 0 ] ?. url ;
20
28
if ( ! baseUrl ) return undefined ;
21
29
@@ -32,7 +40,12 @@ export const executeLocalToolCall = async (
32
40
try {
33
41
const args = toolCall . args ? JSON . parse ( JSON . stringify ( toolCall . args ) ) : { } ;
34
42
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
+ } ) ;
36
49
37
50
const finalUrl =
38
51
httpMethod === "GET" ? handleQueryParams ( url , remainingArgs ) : url ;
@@ -103,12 +116,18 @@ export const buildUrlWithParams = (
103
116
return { url, remainingArgs } ;
104
117
} ;
105
118
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 } => {
110
128
const headers : HeadersInit = {
111
129
"Content-Type" : "application/json" ,
130
+ ...( metadata ? { "mb-metadata" : JSON . stringify ( metadata ) } : { } ) ,
112
131
} ;
113
132
114
133
const fetchOptions : RequestInit = {
0 commit comments