@reverbia/sdk 1.0.0-next.20251202092727 → 1.0.0-next.20251202130234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +26 -2
- package/dist/index.d.mts +260 -2
- package/dist/index.d.ts +260 -2
- package/dist/index.mjs +23 -1
- package/dist/react/index.cjs +319 -27
- package/dist/react/index.d.mts +160 -24
- package/dist/react/index.d.ts +160 -24
- package/dist/react/index.mjs +316 -27
- package/dist/vercel/index.cjs +1 -1
- package/dist/vercel/index.d.mts +25 -1
- package/dist/vercel/index.d.ts +25 -1
- package/dist/vercel/index.mjs +1 -1
- package/package.json +2 -2
package/dist/react/index.d.mts
CHANGED
|
@@ -74,9 +74,33 @@ type LlmapiMessage = {
|
|
|
74
74
|
/**
|
|
75
75
|
* Content is the message content
|
|
76
76
|
*/
|
|
77
|
-
content?:
|
|
77
|
+
content?: Array<LlmapiMessageContentPart>;
|
|
78
78
|
role?: LlmapiRole;
|
|
79
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* ImageURL is used when Type=image_url
|
|
82
|
+
*/
|
|
83
|
+
type LlmapiMessageContentImage = {
|
|
84
|
+
/**
|
|
85
|
+
* Detail is the OpenAI detail hint (auto|low|high)
|
|
86
|
+
*/
|
|
87
|
+
detail?: string;
|
|
88
|
+
/**
|
|
89
|
+
* URL is the image URL or data URI
|
|
90
|
+
*/
|
|
91
|
+
url?: string;
|
|
92
|
+
};
|
|
93
|
+
type LlmapiMessageContentPart = {
|
|
94
|
+
image_url?: LlmapiMessageContentImage;
|
|
95
|
+
/**
|
|
96
|
+
* Text holds the text content when Type=text
|
|
97
|
+
*/
|
|
98
|
+
text?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Type is the block type (`text` or `image_url`)
|
|
101
|
+
*/
|
|
102
|
+
type?: string;
|
|
103
|
+
};
|
|
80
104
|
type LlmapiModel = {
|
|
81
105
|
architecture?: LlmapiModelArchitecture;
|
|
82
106
|
/**
|
|
@@ -175,6 +199,64 @@ type LlmapiModelTopProvider = {
|
|
|
175
199
|
*/
|
|
176
200
|
type LlmapiRole = string;
|
|
177
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Parameter definition for a client-side tool
|
|
204
|
+
*/
|
|
205
|
+
interface ToolParameter {
|
|
206
|
+
/** Parameter name */
|
|
207
|
+
name: string;
|
|
208
|
+
/** Parameter type (string, number, boolean, etc.) */
|
|
209
|
+
type: "string" | "number" | "boolean" | "object" | "array";
|
|
210
|
+
/** Human-readable description of the parameter */
|
|
211
|
+
description: string;
|
|
212
|
+
/** Whether this parameter is required */
|
|
213
|
+
required?: boolean;
|
|
214
|
+
/** Default value if not provided */
|
|
215
|
+
default?: unknown;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Definition for a client-side tool that can be executed in the browser
|
|
219
|
+
*/
|
|
220
|
+
interface ClientTool {
|
|
221
|
+
/** Unique identifier for the tool */
|
|
222
|
+
name: string;
|
|
223
|
+
/** Human-readable description of what the tool does */
|
|
224
|
+
description: string;
|
|
225
|
+
/** Parameters the tool accepts */
|
|
226
|
+
parameters?: ToolParameter[];
|
|
227
|
+
/**
|
|
228
|
+
* The function to execute when the tool is called.
|
|
229
|
+
* Receives extracted parameters and returns a result.
|
|
230
|
+
*/
|
|
231
|
+
execute: (params: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Result of a tool selection operation
|
|
235
|
+
*/
|
|
236
|
+
interface ToolSelectionResult {
|
|
237
|
+
/** Whether a tool was selected */
|
|
238
|
+
toolSelected: boolean;
|
|
239
|
+
/** Name of the selected tool (if any) */
|
|
240
|
+
toolName?: string;
|
|
241
|
+
/** Extracted parameters for the tool */
|
|
242
|
+
parameters?: Record<string, unknown>;
|
|
243
|
+
/** Confidence score (0-1) of the selection */
|
|
244
|
+
confidence?: number;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Result of executing a client-side tool
|
|
248
|
+
*/
|
|
249
|
+
interface ToolExecutionResult {
|
|
250
|
+
/** Name of the tool that was executed */
|
|
251
|
+
toolName: string;
|
|
252
|
+
/** Whether execution was successful */
|
|
253
|
+
success: boolean;
|
|
254
|
+
/** The result returned by the tool */
|
|
255
|
+
result?: unknown;
|
|
256
|
+
/** Error message if execution failed */
|
|
257
|
+
error?: string;
|
|
258
|
+
}
|
|
259
|
+
|
|
178
260
|
type SendMessageArgs = {
|
|
179
261
|
messages: LlmapiMessage[];
|
|
180
262
|
model?: string;
|
|
@@ -185,13 +267,20 @@ type SendMessageArgs = {
|
|
|
185
267
|
* @param chunk - The content delta from the current chunk
|
|
186
268
|
*/
|
|
187
269
|
onData?: (chunk: string) => void;
|
|
270
|
+
/**
|
|
271
|
+
* Whether to run tool selection for this message.
|
|
272
|
+
* Defaults to true if tools are configured.
|
|
273
|
+
*/
|
|
274
|
+
runTools?: boolean;
|
|
188
275
|
};
|
|
189
276
|
type SendMessageResult = {
|
|
190
277
|
data: LlmapiChatCompletionResponse;
|
|
191
278
|
error: null;
|
|
279
|
+
toolExecution?: ToolExecutionResult;
|
|
192
280
|
} | {
|
|
193
281
|
data: null;
|
|
194
282
|
error: string;
|
|
283
|
+
toolExecution?: ToolExecutionResult;
|
|
195
284
|
};
|
|
196
285
|
type UseChatOptions = {
|
|
197
286
|
getToken?: () => Promise<string | null>;
|
|
@@ -226,9 +315,25 @@ type UseChatOptions = {
|
|
|
226
315
|
* Default is "ibm-granite/Granite-4.0-Nano-WebGPU"
|
|
227
316
|
*/
|
|
228
317
|
localModel?: string;
|
|
318
|
+
/**
|
|
319
|
+
* Client-side tools that can be executed in the browser.
|
|
320
|
+
* When provided, the hook will use a local model to determine
|
|
321
|
+
* if any tool should be called based on the user's message.
|
|
322
|
+
*/
|
|
323
|
+
tools?: ClientTool[];
|
|
324
|
+
/**
|
|
325
|
+
* The model to use for tool selection.
|
|
326
|
+
* Default is "onnx-community/granite-4.0-350m-ONNX-web"
|
|
327
|
+
*/
|
|
328
|
+
toolSelectorModel?: string;
|
|
329
|
+
/**
|
|
330
|
+
* Callback function to be called when a tool is executed.
|
|
331
|
+
*/
|
|
332
|
+
onToolExecution?: (result: ToolExecutionResult) => void;
|
|
229
333
|
};
|
|
230
334
|
type UseChatResult = {
|
|
231
335
|
isLoading: boolean;
|
|
336
|
+
isSelectingTool: boolean;
|
|
232
337
|
sendMessage: (args: SendMessageArgs) => Promise<SendMessageResult>;
|
|
233
338
|
/**
|
|
234
339
|
* Aborts the current streaming request if one is in progress.
|
|
@@ -257,47 +362,56 @@ type UseChatResult = {
|
|
|
257
362
|
* is encountered. Note: This is NOT called for aborted requests (see `stop()`).
|
|
258
363
|
* @param options.chatProvider - The provider to use for chat completions (default: "api").
|
|
259
364
|
* @param options.localModel - The model to use for local chat completions.
|
|
365
|
+
* @param options.tools - Client-side tools that can be executed in the browser.
|
|
366
|
+
* @param options.toolSelectorModel - The model to use for tool selection.
|
|
367
|
+
* @param options.onToolExecution - Callback function to be called when a tool is executed.
|
|
260
368
|
*
|
|
261
369
|
* @returns An object containing:
|
|
262
370
|
* - `isLoading`: A boolean indicating whether a request is currently in progress
|
|
371
|
+
* - `isSelectingTool`: A boolean indicating whether tool selection is in progress
|
|
263
372
|
* - `sendMessage`: An async function to send chat messages
|
|
264
373
|
* - `stop`: A function to abort the current request
|
|
265
374
|
*
|
|
266
375
|
* @example
|
|
267
376
|
* ```tsx
|
|
377
|
+
* // Basic usage with API
|
|
268
378
|
* const { isLoading, sendMessage, stop } = useChat({
|
|
269
|
-
* getToken: async () =>
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
379
|
+
* getToken: async () => await getAuthToken(),
|
|
380
|
+
* onFinish: (response) => console.log("Chat finished:", response),
|
|
381
|
+
* onError: (error) => console.error("Chat error:", error)
|
|
382
|
+
* });
|
|
383
|
+
*
|
|
384
|
+
* // With client-side tools
|
|
385
|
+
* const { isLoading, isSelectingTool, sendMessage } = useChat({
|
|
386
|
+
* getToken: async () => await getAuthToken(),
|
|
387
|
+
* tools: [
|
|
388
|
+
* {
|
|
389
|
+
* name: "get_weather",
|
|
390
|
+
* description: "Get the current weather for a location",
|
|
391
|
+
* parameters: [
|
|
392
|
+
* { name: "location", type: "string", description: "City name", required: true }
|
|
393
|
+
* ],
|
|
394
|
+
* execute: async ({ location }) => {
|
|
395
|
+
* // Your weather API call here
|
|
396
|
+
* return { temperature: 72, condition: "sunny" };
|
|
397
|
+
* }
|
|
398
|
+
* }
|
|
399
|
+
* ],
|
|
400
|
+
* onToolExecution: (result) => {
|
|
401
|
+
* console.log("Tool executed:", result.toolName, result.result);
|
|
279
402
|
* }
|
|
280
403
|
* });
|
|
281
404
|
*
|
|
282
405
|
* const handleSend = async () => {
|
|
283
406
|
* const result = await sendMessage({
|
|
284
|
-
* messages: [{ role: 'user', content: '
|
|
407
|
+
* messages: [{ role: 'user', content: 'What is the weather in Paris?' }],
|
|
285
408
|
* model: 'gpt-4o-mini'
|
|
286
409
|
* });
|
|
287
410
|
*
|
|
288
|
-
* if (result.
|
|
289
|
-
*
|
|
290
|
-
* console.log("Request was aborted");
|
|
291
|
-
* } else {
|
|
292
|
-
* console.error("Error:", result.error);
|
|
293
|
-
* }
|
|
294
|
-
* } else {
|
|
295
|
-
* console.log("Success:", result.data);
|
|
411
|
+
* if (result.toolExecution) {
|
|
412
|
+
* console.log("Tool was called:", result.toolExecution);
|
|
296
413
|
* }
|
|
297
414
|
* };
|
|
298
|
-
*
|
|
299
|
-
* // To stop generation:
|
|
300
|
-
* // stop();
|
|
301
415
|
* ```
|
|
302
416
|
*/
|
|
303
417
|
declare function useChat(options?: UseChatOptions): UseChatResult;
|
|
@@ -469,4 +583,26 @@ declare const extractConversationContext: (messages: Array<{
|
|
|
469
583
|
content: string;
|
|
470
584
|
}>, maxMessages?: number) => string;
|
|
471
585
|
|
|
472
|
-
|
|
586
|
+
declare const DEFAULT_TOOL_SELECTOR_MODEL = "Xenova/LaMini-GPT-124M";
|
|
587
|
+
interface ToolSelectorOptions {
|
|
588
|
+
/** Model to use for tool selection. Defaults to Xenova/LaMini-GPT-124M */
|
|
589
|
+
model?: string;
|
|
590
|
+
/** Abort signal */
|
|
591
|
+
signal?: AbortSignal;
|
|
592
|
+
/** Device to use (webgpu, wasm, cpu). Defaults to wasm */
|
|
593
|
+
device?: "webgpu" | "wasm" | "cpu";
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Select a tool based on user message using an in-browser model
|
|
597
|
+
*/
|
|
598
|
+
declare function selectTool(userMessage: string, tools: ClientTool[], options?: ToolSelectorOptions): Promise<ToolSelectionResult>;
|
|
599
|
+
/**
|
|
600
|
+
* Execute a client-side tool with the given parameters
|
|
601
|
+
*/
|
|
602
|
+
declare function executeTool(tool: ClientTool, params: Record<string, unknown>): Promise<{
|
|
603
|
+
success: boolean;
|
|
604
|
+
result?: unknown;
|
|
605
|
+
error?: string;
|
|
606
|
+
}>;
|
|
607
|
+
|
|
608
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useMemory, useModels };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -74,9 +74,33 @@ type LlmapiMessage = {
|
|
|
74
74
|
/**
|
|
75
75
|
* Content is the message content
|
|
76
76
|
*/
|
|
77
|
-
content?:
|
|
77
|
+
content?: Array<LlmapiMessageContentPart>;
|
|
78
78
|
role?: LlmapiRole;
|
|
79
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* ImageURL is used when Type=image_url
|
|
82
|
+
*/
|
|
83
|
+
type LlmapiMessageContentImage = {
|
|
84
|
+
/**
|
|
85
|
+
* Detail is the OpenAI detail hint (auto|low|high)
|
|
86
|
+
*/
|
|
87
|
+
detail?: string;
|
|
88
|
+
/**
|
|
89
|
+
* URL is the image URL or data URI
|
|
90
|
+
*/
|
|
91
|
+
url?: string;
|
|
92
|
+
};
|
|
93
|
+
type LlmapiMessageContentPart = {
|
|
94
|
+
image_url?: LlmapiMessageContentImage;
|
|
95
|
+
/**
|
|
96
|
+
* Text holds the text content when Type=text
|
|
97
|
+
*/
|
|
98
|
+
text?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Type is the block type (`text` or `image_url`)
|
|
101
|
+
*/
|
|
102
|
+
type?: string;
|
|
103
|
+
};
|
|
80
104
|
type LlmapiModel = {
|
|
81
105
|
architecture?: LlmapiModelArchitecture;
|
|
82
106
|
/**
|
|
@@ -175,6 +199,64 @@ type LlmapiModelTopProvider = {
|
|
|
175
199
|
*/
|
|
176
200
|
type LlmapiRole = string;
|
|
177
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Parameter definition for a client-side tool
|
|
204
|
+
*/
|
|
205
|
+
interface ToolParameter {
|
|
206
|
+
/** Parameter name */
|
|
207
|
+
name: string;
|
|
208
|
+
/** Parameter type (string, number, boolean, etc.) */
|
|
209
|
+
type: "string" | "number" | "boolean" | "object" | "array";
|
|
210
|
+
/** Human-readable description of the parameter */
|
|
211
|
+
description: string;
|
|
212
|
+
/** Whether this parameter is required */
|
|
213
|
+
required?: boolean;
|
|
214
|
+
/** Default value if not provided */
|
|
215
|
+
default?: unknown;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Definition for a client-side tool that can be executed in the browser
|
|
219
|
+
*/
|
|
220
|
+
interface ClientTool {
|
|
221
|
+
/** Unique identifier for the tool */
|
|
222
|
+
name: string;
|
|
223
|
+
/** Human-readable description of what the tool does */
|
|
224
|
+
description: string;
|
|
225
|
+
/** Parameters the tool accepts */
|
|
226
|
+
parameters?: ToolParameter[];
|
|
227
|
+
/**
|
|
228
|
+
* The function to execute when the tool is called.
|
|
229
|
+
* Receives extracted parameters and returns a result.
|
|
230
|
+
*/
|
|
231
|
+
execute: (params: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Result of a tool selection operation
|
|
235
|
+
*/
|
|
236
|
+
interface ToolSelectionResult {
|
|
237
|
+
/** Whether a tool was selected */
|
|
238
|
+
toolSelected: boolean;
|
|
239
|
+
/** Name of the selected tool (if any) */
|
|
240
|
+
toolName?: string;
|
|
241
|
+
/** Extracted parameters for the tool */
|
|
242
|
+
parameters?: Record<string, unknown>;
|
|
243
|
+
/** Confidence score (0-1) of the selection */
|
|
244
|
+
confidence?: number;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Result of executing a client-side tool
|
|
248
|
+
*/
|
|
249
|
+
interface ToolExecutionResult {
|
|
250
|
+
/** Name of the tool that was executed */
|
|
251
|
+
toolName: string;
|
|
252
|
+
/** Whether execution was successful */
|
|
253
|
+
success: boolean;
|
|
254
|
+
/** The result returned by the tool */
|
|
255
|
+
result?: unknown;
|
|
256
|
+
/** Error message if execution failed */
|
|
257
|
+
error?: string;
|
|
258
|
+
}
|
|
259
|
+
|
|
178
260
|
type SendMessageArgs = {
|
|
179
261
|
messages: LlmapiMessage[];
|
|
180
262
|
model?: string;
|
|
@@ -185,13 +267,20 @@ type SendMessageArgs = {
|
|
|
185
267
|
* @param chunk - The content delta from the current chunk
|
|
186
268
|
*/
|
|
187
269
|
onData?: (chunk: string) => void;
|
|
270
|
+
/**
|
|
271
|
+
* Whether to run tool selection for this message.
|
|
272
|
+
* Defaults to true if tools are configured.
|
|
273
|
+
*/
|
|
274
|
+
runTools?: boolean;
|
|
188
275
|
};
|
|
189
276
|
type SendMessageResult = {
|
|
190
277
|
data: LlmapiChatCompletionResponse;
|
|
191
278
|
error: null;
|
|
279
|
+
toolExecution?: ToolExecutionResult;
|
|
192
280
|
} | {
|
|
193
281
|
data: null;
|
|
194
282
|
error: string;
|
|
283
|
+
toolExecution?: ToolExecutionResult;
|
|
195
284
|
};
|
|
196
285
|
type UseChatOptions = {
|
|
197
286
|
getToken?: () => Promise<string | null>;
|
|
@@ -226,9 +315,25 @@ type UseChatOptions = {
|
|
|
226
315
|
* Default is "ibm-granite/Granite-4.0-Nano-WebGPU"
|
|
227
316
|
*/
|
|
228
317
|
localModel?: string;
|
|
318
|
+
/**
|
|
319
|
+
* Client-side tools that can be executed in the browser.
|
|
320
|
+
* When provided, the hook will use a local model to determine
|
|
321
|
+
* if any tool should be called based on the user's message.
|
|
322
|
+
*/
|
|
323
|
+
tools?: ClientTool[];
|
|
324
|
+
/**
|
|
325
|
+
* The model to use for tool selection.
|
|
326
|
+
* Default is "onnx-community/granite-4.0-350m-ONNX-web"
|
|
327
|
+
*/
|
|
328
|
+
toolSelectorModel?: string;
|
|
329
|
+
/**
|
|
330
|
+
* Callback function to be called when a tool is executed.
|
|
331
|
+
*/
|
|
332
|
+
onToolExecution?: (result: ToolExecutionResult) => void;
|
|
229
333
|
};
|
|
230
334
|
type UseChatResult = {
|
|
231
335
|
isLoading: boolean;
|
|
336
|
+
isSelectingTool: boolean;
|
|
232
337
|
sendMessage: (args: SendMessageArgs) => Promise<SendMessageResult>;
|
|
233
338
|
/**
|
|
234
339
|
* Aborts the current streaming request if one is in progress.
|
|
@@ -257,47 +362,56 @@ type UseChatResult = {
|
|
|
257
362
|
* is encountered. Note: This is NOT called for aborted requests (see `stop()`).
|
|
258
363
|
* @param options.chatProvider - The provider to use for chat completions (default: "api").
|
|
259
364
|
* @param options.localModel - The model to use for local chat completions.
|
|
365
|
+
* @param options.tools - Client-side tools that can be executed in the browser.
|
|
366
|
+
* @param options.toolSelectorModel - The model to use for tool selection.
|
|
367
|
+
* @param options.onToolExecution - Callback function to be called when a tool is executed.
|
|
260
368
|
*
|
|
261
369
|
* @returns An object containing:
|
|
262
370
|
* - `isLoading`: A boolean indicating whether a request is currently in progress
|
|
371
|
+
* - `isSelectingTool`: A boolean indicating whether tool selection is in progress
|
|
263
372
|
* - `sendMessage`: An async function to send chat messages
|
|
264
373
|
* - `stop`: A function to abort the current request
|
|
265
374
|
*
|
|
266
375
|
* @example
|
|
267
376
|
* ```tsx
|
|
377
|
+
* // Basic usage with API
|
|
268
378
|
* const { isLoading, sendMessage, stop } = useChat({
|
|
269
|
-
* getToken: async () =>
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
379
|
+
* getToken: async () => await getAuthToken(),
|
|
380
|
+
* onFinish: (response) => console.log("Chat finished:", response),
|
|
381
|
+
* onError: (error) => console.error("Chat error:", error)
|
|
382
|
+
* });
|
|
383
|
+
*
|
|
384
|
+
* // With client-side tools
|
|
385
|
+
* const { isLoading, isSelectingTool, sendMessage } = useChat({
|
|
386
|
+
* getToken: async () => await getAuthToken(),
|
|
387
|
+
* tools: [
|
|
388
|
+
* {
|
|
389
|
+
* name: "get_weather",
|
|
390
|
+
* description: "Get the current weather for a location",
|
|
391
|
+
* parameters: [
|
|
392
|
+
* { name: "location", type: "string", description: "City name", required: true }
|
|
393
|
+
* ],
|
|
394
|
+
* execute: async ({ location }) => {
|
|
395
|
+
* // Your weather API call here
|
|
396
|
+
* return { temperature: 72, condition: "sunny" };
|
|
397
|
+
* }
|
|
398
|
+
* }
|
|
399
|
+
* ],
|
|
400
|
+
* onToolExecution: (result) => {
|
|
401
|
+
* console.log("Tool executed:", result.toolName, result.result);
|
|
279
402
|
* }
|
|
280
403
|
* });
|
|
281
404
|
*
|
|
282
405
|
* const handleSend = async () => {
|
|
283
406
|
* const result = await sendMessage({
|
|
284
|
-
* messages: [{ role: 'user', content: '
|
|
407
|
+
* messages: [{ role: 'user', content: 'What is the weather in Paris?' }],
|
|
285
408
|
* model: 'gpt-4o-mini'
|
|
286
409
|
* });
|
|
287
410
|
*
|
|
288
|
-
* if (result.
|
|
289
|
-
*
|
|
290
|
-
* console.log("Request was aborted");
|
|
291
|
-
* } else {
|
|
292
|
-
* console.error("Error:", result.error);
|
|
293
|
-
* }
|
|
294
|
-
* } else {
|
|
295
|
-
* console.log("Success:", result.data);
|
|
411
|
+
* if (result.toolExecution) {
|
|
412
|
+
* console.log("Tool was called:", result.toolExecution);
|
|
296
413
|
* }
|
|
297
414
|
* };
|
|
298
|
-
*
|
|
299
|
-
* // To stop generation:
|
|
300
|
-
* // stop();
|
|
301
415
|
* ```
|
|
302
416
|
*/
|
|
303
417
|
declare function useChat(options?: UseChatOptions): UseChatResult;
|
|
@@ -469,4 +583,26 @@ declare const extractConversationContext: (messages: Array<{
|
|
|
469
583
|
content: string;
|
|
470
584
|
}>, maxMessages?: number) => string;
|
|
471
585
|
|
|
472
|
-
|
|
586
|
+
declare const DEFAULT_TOOL_SELECTOR_MODEL = "Xenova/LaMini-GPT-124M";
|
|
587
|
+
interface ToolSelectorOptions {
|
|
588
|
+
/** Model to use for tool selection. Defaults to Xenova/LaMini-GPT-124M */
|
|
589
|
+
model?: string;
|
|
590
|
+
/** Abort signal */
|
|
591
|
+
signal?: AbortSignal;
|
|
592
|
+
/** Device to use (webgpu, wasm, cpu). Defaults to wasm */
|
|
593
|
+
device?: "webgpu" | "wasm" | "cpu";
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Select a tool based on user message using an in-browser model
|
|
597
|
+
*/
|
|
598
|
+
declare function selectTool(userMessage: string, tools: ClientTool[], options?: ToolSelectorOptions): Promise<ToolSelectionResult>;
|
|
599
|
+
/**
|
|
600
|
+
* Execute a client-side tool with the given parameters
|
|
601
|
+
*/
|
|
602
|
+
declare function executeTool(tool: ClientTool, params: Record<string, unknown>): Promise<{
|
|
603
|
+
success: boolean;
|
|
604
|
+
result?: unknown;
|
|
605
|
+
error?: string;
|
|
606
|
+
}>;
|
|
607
|
+
|
|
608
|
+
export { type ClientTool, DEFAULT_TOOL_SELECTOR_MODEL, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, selectTool, useChat, useEncryption, useMemory, useModels };
|