@intelliweave/embedded 1.8.63 → 1.9.65-beta.0

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.
@@ -1,85 +1,104 @@
1
- import { Optional } from 'utility-types';
2
1
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
+ import { Optional } from 'utility-types';
3
3
  import * as onnxruntime_web from 'onnxruntime-web';
4
4
  import { InferenceSession, Tensor } from 'onnxruntime-web';
5
+ import Anthropic from '@anthropic-ai/sdk';
5
6
  import React from 'react';
6
7
 
7
8
  /**
8
- * This class helps organize groups of tokenized text along with removing items when the window is full.
9
+ * Allows an MCP server to be used as a knowledge source for IntelliWeave.
9
10
  */
10
- declare class TokenWindow {
11
- /** Token window size */
12
- size: number;
13
- /** Token groups */
14
- groups: TokenWindowGroup<any>[];
15
- /** Create a new group */
16
- createGroup(id: string): TokenWindowGroup<unknown>;
17
- /** Get a group */
18
- group<CustomDataType>(id: string): TokenWindowGroup<CustomDataType> | undefined;
19
- /** Calculate current tokens in all groups */
20
- countTokens(): number;
21
- /** Remove overflow from all groups. */
22
- removeOverflow(): void;
23
- /** Remove one overflow item. Returns null if no items were able to be removed. */
24
- private removeOneItem;
25
- }
26
- /** A token group. */
27
- declare class TokenWindowGroup<CustomDataType> {
28
- /** Group ID */
29
- id: string;
30
- /** List of items */
31
- items: TokenWindowGroupItem<CustomDataType>[];
32
- /**
33
- * Weight controls how many items from this group should be kept in relation to the entire window. For example if all
34
- * groups have a weight of 1, each group remove items equally if full. If one has a weight of 2 while the rest are 1,
35
- * that group will be allowed to keep double the amount of items.
36
- */
37
- weight: number;
38
- /** Current total token count, computed automatically. Don't update this value manually. */
39
- tokenCount: number;
40
- /** Group item separator */
41
- separator: string;
42
- /** Token count padding added to each item. */
43
- private itemPadding;
44
- /** Sets the token count padding added to each item. Useful if you don't know exactly what will be added by the LLM host. */
45
- setItemPadding(padding: number): this;
46
- /** Sort function */
47
- private sortFunction;
48
- /** Set sort function */
49
- sortBy(sortFunction: (a: TokenWindowGroupItem<CustomDataType>, b: TokenWindowGroupItem<CustomDataType>) => number): this;
50
- /** Set separator */
51
- setSeparator(separator: string): this;
52
- /** Set weight */
53
- setWeight(weight: number): this;
54
- /** Recalculate all tokens. Note this may take a while. */
55
- recalculateTokens(): void;
56
- /** Add an item to the group */
57
- add(item: string | Omit<Optional<TokenWindowGroupItem<CustomDataType>, 'id' | 'dateAdded' | 'sortOrder'>, 'tokenCount'>): TokenWindowGroupItem<CustomDataType>;
58
- /** Get all items as a string */
59
- getAllAsString(): string;
60
- /** Get all items. Doesn't return disabled items. */
61
- getAll(): TokenWindowGroupItem<CustomDataType>[];
62
- /** Remove all items from this group */
63
- empty(): void;
64
- }
65
- /** Token group item */
66
- interface TokenWindowGroupItem<CustomDataType> {
67
- /** Each item must have a unique ID. */
68
- id: string;
69
- /** The string content of the item */
70
- content: string;
71
- /** True if this item should never be removed */
72
- cannotRemove?: boolean;
73
- /** Sorting order. If not specified, uses dateAdded instead. */
74
- sortOrder: number;
75
- /** Date this item was added */
76
- dateAdded: number;
77
- /** Token count in the content */
78
- tokenCount: number;
79
- /** Anything to attach to this item */
80
- customData?: CustomDataType;
81
- /** If disabled, this item will not be included and will not add tot he token count. */
82
- disabled?: boolean;
11
+ declare class MCPKnowledgeClient {
12
+ /** MCP client */
13
+ client?: Client;
14
+ /** All tools discovered on the MCP server. Only available after connect() has completed. */
15
+ tools: Awaited<ReturnType<Client['listTools']>>['tools'];
16
+ /** All toold discovered, mapped to IntelliWeave knowledge base actions */
17
+ iwActions: KnowledgeBaseItem[];
18
+ /** Statistics */
19
+ stats: {
20
+ toolsCalled: number;
21
+ };
22
+ /** Configuration */
23
+ config: {
24
+ /** Source ID */
25
+ id?: string;
26
+ /** URL to the MCP server endpoint */
27
+ baseURL?: string;
28
+ /** Custom connection function. If specified, baseURL is optional. */
29
+ connect?: () => Promise<Client>;
30
+ /**
31
+ * The name of the tool which provides knowledge searching. If specified, the search() will exclude this function and instead
32
+ * call it and show returned results. If not specified, the search() will just return all tools.
33
+ */
34
+ searchToolName?: string;
35
+ /** Keep search function available for the AI to use. */
36
+ searchToolVisible?: boolean;
37
+ };
38
+ /** Constructor */
39
+ constructor(config: MCPKnowledgeClient['config']);
40
+ /** In-progress connection attempt */
41
+ private connectionPromise?;
42
+ /** Connect to the client */
43
+ connect(): Promise<Client<{
44
+ method: string;
45
+ params?: {
46
+ [x: string]: unknown;
47
+ _meta?: {
48
+ [x: string]: unknown;
49
+ progressToken?: string | number | undefined;
50
+ } | undefined;
51
+ } | undefined;
52
+ }, {
53
+ method: string;
54
+ params?: {
55
+ [x: string]: unknown;
56
+ _meta?: {
57
+ [x: string]: unknown;
58
+ } | undefined;
59
+ } | undefined;
60
+ }, {
61
+ [x: string]: unknown;
62
+ _meta?: {
63
+ [x: string]: unknown;
64
+ } | undefined;
65
+ }>>;
66
+ connectInternal(): Promise<Client<{
67
+ method: string;
68
+ params?: {
69
+ [x: string]: unknown;
70
+ _meta?: {
71
+ [x: string]: unknown;
72
+ progressToken?: string | number | undefined;
73
+ } | undefined;
74
+ } | undefined;
75
+ }, {
76
+ method: string;
77
+ params?: {
78
+ [x: string]: unknown;
79
+ _meta?: {
80
+ [x: string]: unknown;
81
+ } | undefined;
82
+ } | undefined;
83
+ }, {
84
+ [x: string]: unknown;
85
+ _meta?: {
86
+ [x: string]: unknown;
87
+ } | undefined;
88
+ }>>;
89
+ /** Disconnect from server */
90
+ disconnect(): Promise<void>;
91
+ /** Fetch list of tools from the MCP server */
92
+ private fetchTools;
93
+ /** Cache last search result */
94
+ lastSearchQuery: string;
95
+ lastSearchResults: KnowledgeBaseItem[];
96
+ /** Perform a search query */
97
+ search(query: string): Promise<KnowledgeBaseItem[]>;
98
+ /** Perform search using the configured search function */
99
+ private performSearchCall;
100
+ /** Perform tool call. */
101
+ private performToolCall;
83
102
  }
84
103
 
85
104
  // ==================================================================================================
@@ -183,272 +202,70 @@ interface JSONSchema7 {
183
202
  items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
184
203
  additionalItems?: JSONSchema7Definition | undefined;
185
204
  maxItems?: number | undefined;
186
- minItems?: number | undefined;
187
- uniqueItems?: boolean | undefined;
188
- contains?: JSONSchema7Definition | undefined;
189
-
190
- /**
191
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
192
- */
193
- maxProperties?: number | undefined;
194
- minProperties?: number | undefined;
195
- required?: string[] | undefined;
196
- properties?: {
197
- [key: string]: JSONSchema7Definition;
198
- } | undefined;
199
- patternProperties?: {
200
- [key: string]: JSONSchema7Definition;
201
- } | undefined;
202
- additionalProperties?: JSONSchema7Definition | undefined;
203
- dependencies?: {
204
- [key: string]: JSONSchema7Definition | string[];
205
- } | undefined;
206
- propertyNames?: JSONSchema7Definition | undefined;
207
-
208
- /**
209
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
210
- */
211
- if?: JSONSchema7Definition | undefined;
212
- then?: JSONSchema7Definition | undefined;
213
- else?: JSONSchema7Definition | undefined;
214
-
215
- /**
216
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
217
- */
218
- allOf?: JSONSchema7Definition[] | undefined;
219
- anyOf?: JSONSchema7Definition[] | undefined;
220
- oneOf?: JSONSchema7Definition[] | undefined;
221
- not?: JSONSchema7Definition | undefined;
222
-
223
- /**
224
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
225
- */
226
- format?: string | undefined;
227
-
228
- /**
229
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
230
- */
231
- contentMediaType?: string | undefined;
232
- contentEncoding?: string | undefined;
233
-
234
- /**
235
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
236
- */
237
- definitions?: {
238
- [key: string]: JSONSchema7Definition;
239
- } | undefined;
240
-
241
- /**
242
- * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
243
- */
244
- title?: string | undefined;
245
- description?: string | undefined;
246
- default?: JSONSchema7Type | undefined;
247
- readOnly?: boolean | undefined;
248
- writeOnly?: boolean | undefined;
249
- examples?: JSONSchema7Type | undefined;
250
- }
251
-
252
- /** ChatGPT config options */
253
- interface ChatGPTConfig {
254
- /** API key */
255
- apiKey: string;
256
- /** Provider ID */
257
- providerID?: string;
258
- /** Endpoint URL if using a custom URL */
259
- endpoint: string;
260
- /** LLM model to use */
261
- model: string;
262
- /** System message to describe to the AI how to behave. */
263
- systemMessage: string;
264
- /** User ID used to uniquely identify users in ChatGPT's API */
265
- userID: string;
266
- /** If true, streams the text responses from the API */
267
- stream: boolean;
268
- /** Amount of estimated tokens to keep when trimming */
269
- maxTokens: number;
270
- /** Callback before the AI sends info to the LLM */
271
- onBeforeMessageProcessing?: () => void;
272
- /** Callback when a message from the AI is returned. If isChunk is true, it may be incomplete and be called again with more updates. */
273
- onAIMessage?: (text: string, isChunk: boolean) => void;
274
- /** Callback when the AI starts performing an action */
275
- onAIToolStart?: (toolName: string, input: any) => void;
276
- }
277
- /** ChatGPT tool config */
278
- interface ChatGPTToolConfig {
279
- /** Name of the tool */
280
- name: string;
281
- /** Description of the tool */
282
- description: string;
283
- /** Parameters for the tool */
284
- params: JSONSchema7;
285
- /** Callback function to process the tool */
286
- callback: (params: any) => any;
287
- /** If true, this tool call will be removed from the message history after it is executed. */
288
- removeFromMessageHistory?: boolean;
289
- /** If true, this item can be removed if there's not enough context available. */
290
- canRemove?: boolean;
291
- /** Misc app context */
292
- [key: string]: any;
293
- }
294
- /** ChatGPT message */
295
- interface ChatGPTMessage {
296
- /** Role of the message */
297
- role: 'user' | 'assistant' | 'system' | 'tool';
298
- /** Content of the message */
299
- content: string;
300
- /** Tool call ID */
301
- tool_call_id?: string;
302
- /** Tool calls made by the AI */
303
- tool_calls?: any[];
304
- }
305
- /**
306
- * API for interacting with ChatGPT APIs.
307
- */
308
- declare class ChatGPT {
309
- /** ID */
310
- id: string;
311
- /** Metadata */
312
- metadata: any;
313
- /** Config */
314
- config: ChatGPTConfig;
315
- /** The maximum tool calls in sequence the AI can make before an error is thrown. */
316
- maxToolCallsPerMessage: number;
317
- /** Statistics */
318
- stats: {
319
- /** Total tokens used this session */
320
- tokensUsed: number;
321
- };
322
- /** Token window management */
323
- tokenWindow: TokenWindow;
324
- /** Token window group used for the context message */
325
- get contextGroup(): TokenWindowGroup<any>;
326
- /** Token window group used for tools / actions */
327
- get toolGroup(): TokenWindowGroup<ChatGPTToolConfig>;
328
- /** Token window group used for messages */
329
- get messageGroup(): TokenWindowGroup<ChatGPTMessage>;
330
- /** Constructor */
331
- constructor(config: ChatGPTConfig);
332
- /** Send a message, and get the response */
333
- sendMessage(message: string): Promise<string>;
334
- /** Insert a message as if the assistant has written it */
335
- addAssistantMessage(message: string): void;
336
- /** Insert a message sent from a user. Note that doing this instead of using `sendMessage()` means you'll need to manually call `await processMessages()` and then `getLatestMessage()` to get the response. */
337
- addUserMessage(message: string): void;
338
- /** Get all messages */
339
- getMessages(): ChatGPTMessage[];
340
- /** Get latest message */
341
- getLatestMessage(): ChatGPTMessage | undefined;
342
- /** @private Process messages in the chat history */
343
- processMessages(): Promise<void>;
344
- /** Trim message list */
345
- trimMessages(): Promise<void>;
346
- /** @private Send message list to the API and store the response */
347
- sendToAPI(generatePayloadOnly?: boolean): Promise<any>;
348
- /** Process incoming message from the AI. Can be used to respond to encoded actions in the text response. */
349
- processIncomingMessage(message: string): void;
350
- /** Register a tool. */
351
- registerTool(tool: ChatGPTToolConfig): void;
352
- /** @private Process a tool call request from the AI */
353
- processToolCall(toolCall: any): Promise<void>;
354
- /** Reset the conversation */
355
- resetConversation(): void;
356
- }
357
-
358
- /**
359
- * Allows an MCP server to be used as a knowledge source for IntelliWeave.
360
- */
361
- declare class MCPKnowledgeClient {
362
- /** MCP client */
363
- client?: Client;
364
- /** All tools discovered on the MCP server. Only available after connect() has completed. */
365
- tools: Awaited<ReturnType<Client['listTools']>>['tools'];
366
- /** All toold discovered, mapped to IntelliWeave knowledge base actions */
367
- iwActions: KnowledgeBaseItem[];
368
- /** Statistics */
369
- stats: {
370
- toolsCalled: number;
371
- };
372
- /** Configuration */
373
- config: {
374
- /** Source ID */
375
- id?: string;
376
- /** URL to the MCP server endpoint */
377
- baseURL?: string;
378
- /** Custom connection function. If specified, baseURL is optional. */
379
- connect?: () => Promise<Client>;
380
- /**
381
- * The name of the tool which provides knowledge searching. If specified, the search() will exclude this function and instead
382
- * call it and show returned results. If not specified, the search() will just return all tools.
383
- */
384
- searchToolName?: string;
385
- /** Keep search function available for the AI to use. */
386
- searchToolVisible?: boolean;
387
- };
388
- /** Constructor */
389
- constructor(config: MCPKnowledgeClient['config']);
390
- /** In-progress connection attempt */
391
- private connectionPromise?;
392
- /** Connect to the client */
393
- connect(): Promise<Client<{
394
- method: string;
395
- params?: {
396
- [x: string]: unknown;
397
- _meta?: {
398
- [x: string]: unknown;
399
- progressToken?: string | number | undefined;
400
- } | undefined;
401
- } | undefined;
402
- }, {
403
- method: string;
404
- params?: {
405
- [x: string]: unknown;
406
- _meta?: {
407
- [x: string]: unknown;
408
- } | undefined;
409
- } | undefined;
410
- }, {
411
- [x: string]: unknown;
412
- _meta?: {
413
- [x: string]: unknown;
414
- } | undefined;
415
- }>>;
416
- connectInternal(): Promise<Client<{
417
- method: string;
418
- params?: {
419
- [x: string]: unknown;
420
- _meta?: {
421
- [x: string]: unknown;
422
- progressToken?: string | number | undefined;
423
- } | undefined;
424
- } | undefined;
425
- }, {
426
- method: string;
427
- params?: {
428
- [x: string]: unknown;
429
- _meta?: {
430
- [x: string]: unknown;
431
- } | undefined;
432
- } | undefined;
433
- }, {
434
- [x: string]: unknown;
435
- _meta?: {
436
- [x: string]: unknown;
437
- } | undefined;
438
- }>>;
439
- /** Disconnect from server */
440
- disconnect(): Promise<void>;
441
- /** Fetch list of tools from the MCP server */
442
- private fetchTools;
443
- /** Cache last search result */
444
- lastSearchQuery: string;
445
- lastSearchResults: KnowledgeBaseItem[];
446
- /** Perform a search query */
447
- search(query: string): Promise<KnowledgeBaseItem[]>;
448
- /** Perform search using the configured search function */
449
- private performSearchCall;
450
- /** Perform tool call. */
451
- private performToolCall;
205
+ minItems?: number | undefined;
206
+ uniqueItems?: boolean | undefined;
207
+ contains?: JSONSchema7Definition | undefined;
208
+
209
+ /**
210
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
211
+ */
212
+ maxProperties?: number | undefined;
213
+ minProperties?: number | undefined;
214
+ required?: string[] | undefined;
215
+ properties?: {
216
+ [key: string]: JSONSchema7Definition;
217
+ } | undefined;
218
+ patternProperties?: {
219
+ [key: string]: JSONSchema7Definition;
220
+ } | undefined;
221
+ additionalProperties?: JSONSchema7Definition | undefined;
222
+ dependencies?: {
223
+ [key: string]: JSONSchema7Definition | string[];
224
+ } | undefined;
225
+ propertyNames?: JSONSchema7Definition | undefined;
226
+
227
+ /**
228
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
229
+ */
230
+ if?: JSONSchema7Definition | undefined;
231
+ then?: JSONSchema7Definition | undefined;
232
+ else?: JSONSchema7Definition | undefined;
233
+
234
+ /**
235
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
236
+ */
237
+ allOf?: JSONSchema7Definition[] | undefined;
238
+ anyOf?: JSONSchema7Definition[] | undefined;
239
+ oneOf?: JSONSchema7Definition[] | undefined;
240
+ not?: JSONSchema7Definition | undefined;
241
+
242
+ /**
243
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
244
+ */
245
+ format?: string | undefined;
246
+
247
+ /**
248
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
249
+ */
250
+ contentMediaType?: string | undefined;
251
+ contentEncoding?: string | undefined;
252
+
253
+ /**
254
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
255
+ */
256
+ definitions?: {
257
+ [key: string]: JSONSchema7Definition;
258
+ } | undefined;
259
+
260
+ /**
261
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
262
+ */
263
+ title?: string | undefined;
264
+ description?: string | undefined;
265
+ default?: JSONSchema7Type | undefined;
266
+ readOnly?: boolean | undefined;
267
+ writeOnly?: boolean | undefined;
268
+ examples?: JSONSchema7Type | undefined;
452
269
  }
453
270
 
454
271
  /**
@@ -655,12 +472,179 @@ interface IntelliWeaveInstructConfig {
655
472
  callback?: (txt: string) => void;
656
473
  }
657
474
 
475
+ /**
476
+ * This class helps organize groups of tokenized text along with removing items when the window is full.
477
+ */
478
+ declare class TokenWindow {
479
+ /** Token window size */
480
+ size: number;
481
+ /** Token groups */
482
+ groups: TokenWindowGroup<any>[];
483
+ /** Create a new group */
484
+ createGroup(id: string): TokenWindowGroup<unknown>;
485
+ /** Get a group */
486
+ group<CustomDataType>(id: string): TokenWindowGroup<CustomDataType> | undefined;
487
+ /** Calculate current tokens in all groups */
488
+ countTokens(): number;
489
+ /** Remove overflow from all groups. */
490
+ removeOverflow(): void;
491
+ /** Remove one overflow item. Returns null if no items were able to be removed. */
492
+ private removeOneItem;
493
+ }
494
+ /** A token group. */
495
+ declare class TokenWindowGroup<CustomDataType> {
496
+ /** Group ID */
497
+ id: string;
498
+ /** List of items */
499
+ items: TokenWindowGroupItem<CustomDataType>[];
500
+ /**
501
+ * Weight controls how many items from this group should be kept in relation to the entire window. For example if all
502
+ * groups have a weight of 1, each group remove items equally if full. If one has a weight of 2 while the rest are 1,
503
+ * that group will be allowed to keep double the amount of items.
504
+ */
505
+ weight: number;
506
+ /** Current total token count, computed automatically. Don't update this value manually. */
507
+ tokenCount: number;
508
+ /** Group item separator */
509
+ separator: string;
510
+ /** Token count padding added to each item. */
511
+ private itemPadding;
512
+ /** Sets the token count padding added to each item. Useful if you don't know exactly what will be added by the LLM host. */
513
+ setItemPadding(padding: number): this;
514
+ /** Sort function */
515
+ private sortFunction;
516
+ /** Set sort function */
517
+ sortBy(sortFunction: (a: TokenWindowGroupItem<CustomDataType>, b: TokenWindowGroupItem<CustomDataType>) => number): this;
518
+ /** Set separator */
519
+ setSeparator(separator: string): this;
520
+ /** Set weight */
521
+ setWeight(weight: number): this;
522
+ /** Recalculate all tokens. Note this may take a while. */
523
+ recalculateTokens(): void;
524
+ /** Add an item to the group */
525
+ add(item: string | Omit<Optional<TokenWindowGroupItem<CustomDataType>, 'id' | 'dateAdded' | 'sortOrder'>, 'tokenCount'>): TokenWindowGroupItem<CustomDataType>;
526
+ /** Get all items as a string */
527
+ getAllAsString(): string;
528
+ /** Get all items. Doesn't return disabled items. */
529
+ getAll(): TokenWindowGroupItem<CustomDataType>[];
530
+ /** Remove all items from this group */
531
+ empty(): void;
532
+ }
533
+ /** Token group item */
534
+ interface TokenWindowGroupItem<CustomDataType> {
535
+ /** Each item must have a unique ID. */
536
+ id: string;
537
+ /** The string content of the item */
538
+ content: string;
539
+ /** True if this item should never be removed */
540
+ cannotRemove?: boolean;
541
+ /** Sorting order. If not specified, uses dateAdded instead. */
542
+ sortOrder: number;
543
+ /** Date this item was added */
544
+ dateAdded: number;
545
+ /** Token count in the content */
546
+ tokenCount: number;
547
+ /** Anything to attach to this item */
548
+ customData?: CustomDataType;
549
+ /** If disabled, this item will not be included and will not add tot he token count. */
550
+ disabled?: boolean;
551
+ }
552
+
553
+ /** Chat config options */
554
+ interface ChatBaseConfig {
555
+ /** API key */
556
+ apiKey: string;
557
+ /** Provider ID */
558
+ providerID?: string;
559
+ /** Endpoint URL if using a custom URL */
560
+ endpoint: string;
561
+ /** LLM model to use */
562
+ model: string;
563
+ /** System message to describe to the AI how to behave. */
564
+ systemMessage: string;
565
+ /** User ID used to uniquely identify users in ChatGPT's API */
566
+ userID: string;
567
+ /** If true, streams the text responses from the API */
568
+ stream: boolean;
569
+ /** Amount of estimated tokens to keep when trimming */
570
+ maxTokens: number;
571
+ /** Callback before the AI sends info to the LLM */
572
+ onBeforeMessageProcessing?: () => void;
573
+ /** Callback when a message from the AI is returned. If isChunk is true, it may be incomplete and be called again with more updates. */
574
+ onAIMessage?: (text: string, isChunk: boolean) => void;
575
+ /** Callback when the AI starts performing an action */
576
+ onAIToolStart?: (toolName: string, input: any) => void;
577
+ }
578
+ /** Chat tool config */
579
+ interface ChatBaseToolConfig {
580
+ /** Name of the tool, eg "perform_search" */
581
+ name: string;
582
+ /** Description of the tool */
583
+ description: string;
584
+ /** Parameters for the tool */
585
+ params: JSONSchema7;
586
+ /** Callback function to process the tool */
587
+ callback: (params: any) => any;
588
+ /** If true, this tool call will be removed from the message history after it is executed. */
589
+ removeFromMessageHistory?: boolean;
590
+ /** If true, this item can be removed if there's not enough context available. */
591
+ canRemove?: boolean;
592
+ /** Misc app context */
593
+ [key: string]: any;
594
+ }
595
+ /**
596
+ * API for interacting with chat APIs.
597
+ */
598
+ declare class ChatBase<
599
+ /** Format for messages in the token window */
600
+ MessageFormat = any,
601
+ /** Optional extended config */
602
+ ConfigFormat extends ChatBaseConfig = ChatBaseConfig> {
603
+ /** ID */
604
+ id: string;
605
+ /** Metadata */
606
+ metadata: any;
607
+ /** Config */
608
+ config: ConfigFormat;
609
+ /** The maximum tool calls in sequence the AI can make before an error is thrown. */
610
+ maxToolCallsPerMessage: number;
611
+ /** Statistics */
612
+ stats: {
613
+ /** Total tokens used this session */
614
+ tokensUsed: number;
615
+ };
616
+ /** Token window management */
617
+ tokenWindow: TokenWindow;
618
+ /** Token window group used for the context message */
619
+ get contextGroup(): TokenWindowGroup<any>;
620
+ /** Token window group used for tools / actions */
621
+ get toolGroup(): TokenWindowGroup<ChatBaseToolConfig>;
622
+ /** Token window group used for messages */
623
+ get messageGroup(): TokenWindowGroup<MessageFormat>;
624
+ /** Constructor */
625
+ constructor(config: ConfigFormat);
626
+ /** Send a message, and get the response */
627
+ sendMessage(message: string): Promise<string>;
628
+ /** Add a user message to the message history */
629
+ addUserMessage(message: string): void;
630
+ /** Add an assistant message to the message history */
631
+ addAssistantMessage(message: string): void;
632
+ /** Process incoming message from the AI. Can be used to respond to encoded actions in the text response. */
633
+ onBeforeIncomingMessage(message: MessageFormat): void;
634
+ /** Reset the conversation */
635
+ resetConversation(): void;
636
+ /** Trim message list */
637
+ trimMessages(): Promise<void>;
638
+ /** Register a tool. */
639
+ registerTool(tool: ChatBaseToolConfig): TokenWindowGroupItem<ChatBaseToolConfig>;
640
+ }
641
+
658
642
  /** Persona config received from the hub */
659
643
  interface WebWeaverGPTConfig {
660
644
  /** ID */
661
645
  id: string;
662
- /** ChatGPT config */
663
- model: ChatGPTConfig;
646
+ /** Chat API config */
647
+ model: ChatBaseConfig;
664
648
  /** If true, message history will be sent to the IntelliWeave hub for analysis */
665
649
  analytics?: boolean;
666
650
  /** Persona name */
@@ -707,7 +691,7 @@ interface WebWeaverGPTConfig {
707
691
  * - event `webweaver_loaded` - Fired when the AI is loaded with a new configuration. This is a global event that is fired on the window object.
708
692
  * - event `webweaver_error` - Fired when an error occurs during loading. This is a global event that is fired on the window object.
709
693
  * - event `input` - Fired when the user sends a message to the AI.
710
- * - event `output` - Fired when the AI sends a message back to the user. If `event.detail.isChunk` is true, the message is incomplete and will be followed by more chunks.
694
+ * - event `output` - Fired when the AI sends a message back to the user. If `event.detail.isChunk` is true, the message is incomplete and will be followed by more events.
711
695
  * - event `toolstart` - Fired when the AI starts performing an action.
712
696
  * - event `tool` - Fired when the AI finishes performing an action.
713
697
  */
@@ -717,7 +701,7 @@ declare class IntelliWeave extends EventTarget {
717
701
  /** Callback when a message from the AI is returned. If isChunk is true, it may be incomplete and be called again with more updates. */
718
702
  onAIMessage?: (text: string, isChunk: boolean) => void;
719
703
  /** Callback when the AI starts performing an action */
720
- onAIToolStart?: ChatGPTConfig['onAIToolStart'];
704
+ onAIToolStart?: ChatBaseConfig['onAIToolStart'];
721
705
  /** Current conversation ID */
722
706
  conversationID: string;
723
707
  /** Knowledge database interface */
@@ -733,11 +717,11 @@ declare class IntelliWeave extends EventTarget {
733
717
  /** Available LLMs */
734
718
  models: {
735
719
  id: string;
736
- config: ChatGPTConfig;
720
+ config: ChatBaseConfig;
737
721
  priority?: number;
738
722
  }[];
739
723
  /** Current LLM */
740
- currentModel?: ChatGPT;
724
+ currentModel?: ChatBase;
741
725
  /** The audio system. Set this to a new instance of AudioSystem to enable audio support */
742
726
  audio: AudioSystem | null;
743
727
  /** Silero VAD model blob */
@@ -767,7 +751,6 @@ declare class IntelliWeave extends EventTarget {
767
751
  getContextPrefix(): Promise<string>;
768
752
  /** Get system message to send to the AI */
769
753
  onBeforeMessageProcessing(): Promise<void>;
770
- private _lastOutput?;
771
754
  /** @private Process incoming message from the AI. Can be used to respond to encoded actions in the text response. */
772
755
  processIncomingMessage(message: string, isChunk?: boolean): void;
773
756
  /** True if currently processing a message */
@@ -788,7 +771,7 @@ declare class IntelliWeave extends EventTarget {
788
771
  exportState(): {
789
772
  type: string;
790
773
  conversationID: string;
791
- messages: (ChatGPTMessage | undefined)[] | undefined;
774
+ messages: any[] | undefined;
792
775
  };
793
776
  /** Import conversation state from JSON */
794
777
  importState(state: any): void;
@@ -878,7 +861,7 @@ declare class VoiceDetectionNode extends PCMReceiverNode {
878
861
  /** Loaded VAD model */
879
862
  private vad?;
880
863
  /** Sample rate */
881
- get sampleRate(): 8000 | 16000;
864
+ get sampleRate(): 16000 | 8000;
882
865
  /** Number of samples */
883
866
  get numberOfSamples(): number;
884
867
  /** Number of sample chunks */
@@ -1567,6 +1550,8 @@ declare class WebWeaverEmbed extends BaseComponent {
1567
1550
  resetConversation(): void;
1568
1551
  /** True if busy processing */
1569
1552
  private _isProcessing;
1553
+ /** The element which will receive the current message from the AI */
1554
+ currentOutputElement?: HTMLElement;
1570
1555
  /** Process input text from the user */
1571
1556
  processInput(inputText: string): Promise<void>;
1572
1557
  /** Called when the AI responds with some text */
@@ -1618,6 +1603,59 @@ declare function getDefaultUserID(): string;
1618
1603
  /** Convert an IntelliWeave parameter list to JSON schema. Does not modify if it's already a JSON schema. */
1619
1604
  declare function convertParamsToJSONSchema(params: KnowledgeBaseActionParameterSchema): JSONSchema7;
1620
1605
 
1606
+ /** ChatGPT message */
1607
+ interface ChatGPTMessage {
1608
+ /** Role of the message */
1609
+ role: 'user' | 'assistant' | 'system' | 'tool';
1610
+ /** Content of the message */
1611
+ content: string;
1612
+ /** Tool call ID */
1613
+ tool_call_id?: string;
1614
+ /** Tool calls made by the AI */
1615
+ tool_calls?: any[];
1616
+ }
1617
+ /**
1618
+ * API for interacting with ChatGPT APIs.
1619
+ */
1620
+ declare class ChatGPT extends ChatBase<ChatGPTMessage> {
1621
+ /** Send a message, and get the response */
1622
+ sendMessage(message: string): Promise<string>;
1623
+ /** Insert a message as if the assistant has written it */
1624
+ addAssistantMessage(message: string): void;
1625
+ /** Insert a message sent from a user. Note that doing this instead of using `sendMessage()` means you'll need to manually call `await processMessages()` and then `getLatestMessage()` to get the response. */
1626
+ addUserMessage(message: string): void;
1627
+ /** Get all messages */
1628
+ getMessages(): ChatGPTMessage[];
1629
+ /** Get latest message */
1630
+ getLatestMessage(): ChatGPTMessage | undefined;
1631
+ /** @private Process messages in the chat history */
1632
+ processMessages(): Promise<void>;
1633
+ /** Trim message list */
1634
+ trimMessages(): Promise<void>;
1635
+ /** @private Send HTTP request to the API and return the response */
1636
+ sendRequest(payload: any): Promise<Response>;
1637
+ /** @private Send message list to the API and store the response */
1638
+ sendToAPI(generatePayloadOnly?: boolean): Promise<any>;
1639
+ /** @private Process a tool call request from the AI */
1640
+ processToolCall(toolCall: any): Promise<void>;
1641
+ }
1642
+
1643
+ /**
1644
+ * API for interacting with Anthropic APIs.
1645
+ */
1646
+ declare class AnthropicChat extends ChatBase<Anthropic.Messages.MessageParam> {
1647
+ /** Add a user message to the message history */
1648
+ addUserMessage(message: string): void;
1649
+ /** Add an assistant message to the message history */
1650
+ addAssistantMessage(message: string): void;
1651
+ /** Send a message, and get the response */
1652
+ sendMessage(message: string): Promise<string>;
1653
+ /** Calls the specified tool and returns a tool_result block */
1654
+ protected performToolCall(toolUse: Anthropic.Messages.ToolUseBlockParam): Promise<Anthropic.Messages.ToolResultBlockParam>;
1655
+ /** Trim message list */
1656
+ trimMessages(): Promise<void>;
1657
+ }
1658
+
1621
1659
  /** Class to help with logging */
1622
1660
  declare class Logging {
1623
1661
  /** Current module */
@@ -1911,4 +1949,4 @@ declare function useIntelliWeave(): IntelliWeave | undefined;
1911
1949
  /** React hook to add an external KB search hook. This can provide static KB entries, or perform an async search and return dynamic entries. */
1912
1950
  declare function useIntelliWeaveKnowledge(query: KnowledgeBaseSource['query'], dependencies?: any[]): void;
1913
1951
 
1914
- export { AILogic, AudioSystem, type BaseStatisticsEvent, type BufferType, BufferedWebSocket, ChatGPT, type ChatGPTConfig, type ChatGPTMessage, type ChatGPTToolConfig, FixedBufferStream, type InputStatisticsEvent, IntelliWeave, type IntelliWeaveGlobalConfig, type IntelliWeaveInstructConfig, type IntelliWeaveParameterDefinition, IntelliWeaveProvider, IntelliWeaveStream, type IntelliWeaveStreamErrorEvent, type IntelliWeaveStreamEvent, type IntelliWeaveStreamTextOutputEvent, IntelliWeaveTranscriptionNode, KnowledgeBase, type KnowledgeBaseActionParameterSchema, type KnowledgeBaseItem, type KnowledgeBaseSearchEvent, type KnowledgeBaseSource, type KnowledgeBaseWebhookActionResponse, type KnowledgeBaseWebhookRequest, type KnowledgeBaseWebhookSearchResponse, type KnowledgeFetcher, Logging, MCPKnowledgeClient, type MessageReceiveEvent, type MessageSendEvent, ONNXModel, type ONNXTensors, OpenAITranscriptionNode, PCMPlayerNode, PCMReceiverNode, Resampler, type SessionStartEvent, type StatisticsEvent, type StatisticsEventType, type SupportedArrayBuffers, TokenWindow, TokenWindowGroup, type TokenWindowGroupItem, type ToolCallEvent, type UICloseEvent, type UIOpenEvent, VoiceChunkOutputNode, VoiceDetectionNode, type VoiceEndEvent, type VoiceStartEvent, type VoiceSubmitEvent, WebWeaverEmbed, type WebWeaverGPTConfig, WebWeaverSpeechOutput, WebWeaverSpeechRecognition, WebWeaverUI, audioToWav, convertParamsToJSONSchema, floatTo16BitPCM, floatTo64BitPCM, getDefaultUserID, int16ToFloat32BitPCM, intelliweaveConfig, intelliweaveGlobalThis, sseEvents, track, trimWhitespaceInText, useIntelliWeave, useIntelliWeaveKnowledge };
1952
+ export { AILogic, AnthropicChat, AudioSystem, type BaseStatisticsEvent, type BufferType, BufferedWebSocket, ChatBase, type ChatBaseConfig, type ChatBaseToolConfig, ChatGPT, type ChatGPTMessage, FixedBufferStream, type InputStatisticsEvent, IntelliWeave, type IntelliWeaveGlobalConfig, type IntelliWeaveInstructConfig, type IntelliWeaveParameterDefinition, IntelliWeaveProvider, IntelliWeaveStream, type IntelliWeaveStreamErrorEvent, type IntelliWeaveStreamEvent, type IntelliWeaveStreamTextOutputEvent, IntelliWeaveTranscriptionNode, KnowledgeBase, type KnowledgeBaseActionParameterSchema, type KnowledgeBaseItem, type KnowledgeBaseSearchEvent, type KnowledgeBaseSource, type KnowledgeBaseWebhookActionResponse, type KnowledgeBaseWebhookRequest, type KnowledgeBaseWebhookSearchResponse, type KnowledgeFetcher, Logging, MCPKnowledgeClient, type MessageReceiveEvent, type MessageSendEvent, ONNXModel, type ONNXTensors, OpenAITranscriptionNode, PCMPlayerNode, PCMReceiverNode, Resampler, type SessionStartEvent, type StatisticsEvent, type StatisticsEventType, type SupportedArrayBuffers, TokenWindow, TokenWindowGroup, type TokenWindowGroupItem, type ToolCallEvent, type UICloseEvent, type UIOpenEvent, VoiceChunkOutputNode, VoiceDetectionNode, type VoiceEndEvent, type VoiceStartEvent, type VoiceSubmitEvent, WebWeaverEmbed, type WebWeaverGPTConfig, WebWeaverSpeechOutput, WebWeaverSpeechRecognition, WebWeaverUI, audioToWav, convertParamsToJSONSchema, floatTo16BitPCM, floatTo64BitPCM, getDefaultUserID, int16ToFloat32BitPCM, intelliweaveConfig, intelliweaveGlobalThis, sseEvents, track, trimWhitespaceInText, useIntelliWeave, useIntelliWeaveKnowledge };