@intelliweave/embedded 2.0.72-beta.1 → 2.0.72-beta.2
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/component/component.d.ts +208 -109
- package/dist/component/component.js +88 -28
- package/dist/intelliweave-wordpress.zip +0 -0
- package/dist/node/node.d.ts +233 -195
- package/dist/node/node.js +41 -24
- package/dist/react/react.d.ts +203 -106
- package/dist/react/react.js +88 -28
- package/dist/script-tag/chunk-FSRPMVAS.js +1 -0
- package/dist/script-tag/{ort.bundle.min-IUPKB45H.js → ort.bundle.min-5QOPZPPI.js} +1 -1
- package/dist/script-tag/script-tag.js +155 -3326
- package/dist/webpack/index.d.ts +233 -195
- package/dist/webpack/index.js +93 -29
- package/package.json +5 -4
- package/vitest.config.ts +17 -0
- package/dist/script-tag/chunk-AIYMQX7V.js +0 -1
|
Binary file
|
package/dist/node/node.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as onnxruntime_web from 'onnxruntime-web';
|
|
2
2
|
import { InferenceSession, Tensor } from 'onnxruntime-web';
|
|
3
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
4
3
|
import { Optional } from 'utility-types';
|
|
4
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
5
|
+
import OpenAI from 'openai';
|
|
5
6
|
import Anthropic from '@anthropic-ai/sdk';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -387,6 +388,150 @@ function int16ToFloat32BitPCM(input) {
|
|
|
387
388
|
return output;
|
|
388
389
|
}
|
|
389
390
|
|
|
391
|
+
/**
|
|
392
|
+
* This class helps organize groups of tokenized text along with removing items when the window is full.
|
|
393
|
+
*/
|
|
394
|
+
declare class TokenWindow {
|
|
395
|
+
/** Token window size */
|
|
396
|
+
size: number;
|
|
397
|
+
/** Token groups */
|
|
398
|
+
groups: TokenWindowGroup<any>[];
|
|
399
|
+
/** Create a new group */
|
|
400
|
+
createGroup(id: string): TokenWindowGroup<unknown>;
|
|
401
|
+
/** Get a group */
|
|
402
|
+
group<CustomDataType>(id: string): TokenWindowGroup<CustomDataType> | undefined;
|
|
403
|
+
/** Counts tokens in the specified text */
|
|
404
|
+
static countTokensInText(text: string): number;
|
|
405
|
+
/** Calculate current tokens in all groups */
|
|
406
|
+
countTokens(): number;
|
|
407
|
+
/** Remove overflow from all groups. */
|
|
408
|
+
removeOverflow(): void;
|
|
409
|
+
/** Remove one overflow item. Returns null if no items were able to be removed. */
|
|
410
|
+
private removeOneItem;
|
|
411
|
+
}
|
|
412
|
+
/** A token group. */
|
|
413
|
+
declare class TokenWindowGroup<DataType> {
|
|
414
|
+
/** Group ID */
|
|
415
|
+
id: string;
|
|
416
|
+
/** List of items */
|
|
417
|
+
items: TokenWindowGroupItem<DataType>[];
|
|
418
|
+
/**
|
|
419
|
+
* Weight controls how many items from this group should be kept in relation to the entire window. For example if all
|
|
420
|
+
* 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,
|
|
421
|
+
* that group will be allowed to keep double the amount of items.
|
|
422
|
+
*/
|
|
423
|
+
weight: number;
|
|
424
|
+
/** Current total token count, computed automatically. Don't update this value manually. */
|
|
425
|
+
tokenCount: number;
|
|
426
|
+
/** Group item separator. This text is added in between each item in the token window. */
|
|
427
|
+
separator: string;
|
|
428
|
+
/** Token count padding added to each item. */
|
|
429
|
+
private itemPadding;
|
|
430
|
+
/** Sets the token count padding added to each item. Useful if you don't know exactly what will be added by the LLM host. */
|
|
431
|
+
setItemPadding(padding: number): this;
|
|
432
|
+
/** Sort function */
|
|
433
|
+
private sortFunction;
|
|
434
|
+
/** Set sort function */
|
|
435
|
+
sortBy(sortFunction: (a: TokenWindowGroupItem<DataType>, b: TokenWindowGroupItem<DataType>) => number): this;
|
|
436
|
+
/** Set separator. This text is added in between each item in the token window. */
|
|
437
|
+
setSeparator(separator: string): this;
|
|
438
|
+
/**
|
|
439
|
+
* Set weight. Weight controls how many items from this group should be kept
|
|
440
|
+
* in relation to the entire window. For example if all groups have a weight
|
|
441
|
+
* of 1, each group remove items equally if full. If one has a weight of 2
|
|
442
|
+
* while the rest are 1, that group will be allowed to keep double the
|
|
443
|
+
* amount of items.
|
|
444
|
+
*/
|
|
445
|
+
setWeight(weight: number): this;
|
|
446
|
+
/** Recalculate all tokens. Note this may take a while. */
|
|
447
|
+
recalculateTokens(): void;
|
|
448
|
+
/** Add an item to the group */
|
|
449
|
+
add(item: string | TokenWindowGroupItemParams<DataType>): TokenWindowGroupItem<DataType>;
|
|
450
|
+
/** Get all items as a string */
|
|
451
|
+
getAllAsString(): string;
|
|
452
|
+
/** Get all items. Doesn't return disabled items. */
|
|
453
|
+
getAll(): TokenWindowGroupItem<DataType>[];
|
|
454
|
+
/** Remove all items from this group */
|
|
455
|
+
empty(): void;
|
|
456
|
+
}
|
|
457
|
+
/** Token group item section types */
|
|
458
|
+
declare enum TokenWindowGroupItemSectionType {
|
|
459
|
+
/** Text items represent plain text. */
|
|
460
|
+
Text = "text",
|
|
461
|
+
/** Tool call items represent a tool call requested by the AI. */
|
|
462
|
+
ToolCall = "tool_call",
|
|
463
|
+
/** Tool result items represent the result of a tool call. */
|
|
464
|
+
ToolResult = "tool_result",
|
|
465
|
+
/** Thinking section */
|
|
466
|
+
Thinking = "thinking",
|
|
467
|
+
/** Other item types */
|
|
468
|
+
Other = "other"
|
|
469
|
+
}
|
|
470
|
+
/** Token group item */
|
|
471
|
+
interface TokenWindowGroupItem<DataType> {
|
|
472
|
+
/** Each item must have a unique ID. */
|
|
473
|
+
id: string;
|
|
474
|
+
/** True if this item should never be removed */
|
|
475
|
+
cannotRemove?: boolean;
|
|
476
|
+
/** Sorting order. If not specified, uses dateAdded instead. */
|
|
477
|
+
sortOrder: number;
|
|
478
|
+
/** Date this item was added */
|
|
479
|
+
dateAdded: number;
|
|
480
|
+
/** Token count in the content */
|
|
481
|
+
tokenCount: number;
|
|
482
|
+
/** This is the actual item that gets sent to the APIs. It will be in whatever format is required for the associated API. */
|
|
483
|
+
data?: DataType;
|
|
484
|
+
/** If disabled, this item will not be included and will not add to the token count. */
|
|
485
|
+
disabled?: boolean;
|
|
486
|
+
/** Message source, ie was this message created by the user, or by the AI? */
|
|
487
|
+
source: 'user' | 'assistant';
|
|
488
|
+
/**
|
|
489
|
+
* The string content of the item, or a summary of it. This is an autogenerated field, updated when the item is added/updated in the token window group.
|
|
490
|
+
* If `data` is a string, this will be the same as `data`. If `data` is more complex, this will be a text representation of all items in the `sections` array.
|
|
491
|
+
*
|
|
492
|
+
* Note: When the response contains text and tool calls, this will add in a summary of what's happening. For better displaying, use the `sections` array.
|
|
493
|
+
*/
|
|
494
|
+
text?: string;
|
|
495
|
+
/** Message sections */
|
|
496
|
+
sections?: TokenWindowGroupItemSection[];
|
|
497
|
+
/** If this message was generated by the AI, this contains the token usage for this message. */
|
|
498
|
+
usage?: {
|
|
499
|
+
/** Number of tokens consumed from the data passed to the AI */
|
|
500
|
+
inputTokens: number;
|
|
501
|
+
/** Number of input tokens that were used in token caching */
|
|
502
|
+
cachedInputTokens: number;
|
|
503
|
+
/** Number of tokens consumed by the AI generating output */
|
|
504
|
+
outputTokens: number;
|
|
505
|
+
/** Total token usage */
|
|
506
|
+
totalTokens: number;
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
/** A section of a message returned by the AI */
|
|
510
|
+
interface TokenWindowGroupItemSection {
|
|
511
|
+
/** Section type */
|
|
512
|
+
type: TokenWindowGroupItemSectionType;
|
|
513
|
+
/** Text content when this section represents text or thinking */
|
|
514
|
+
text?: string;
|
|
515
|
+
/** The raw tool name the AI requested to be called. */
|
|
516
|
+
toolName?: string;
|
|
517
|
+
/** The ID of the KB action this tool call maps to, if any */
|
|
518
|
+
toolKbID?: string;
|
|
519
|
+
/** The name of the KB action this tool call maps to, if any */
|
|
520
|
+
toolKbName?: string;
|
|
521
|
+
/** The parameters the AI requested to be sent to the tool. Only available if type == 'tool_call' */
|
|
522
|
+
toolParameters?: any;
|
|
523
|
+
/** Successful response of the tool call. Will be null if toolErrorResponse is set. */
|
|
524
|
+
toolSuccessResponse?: any;
|
|
525
|
+
/** Error response of the tool call. Will be null if toolSuccessResponse is set. */
|
|
526
|
+
toolErrorResponse?: string;
|
|
527
|
+
/** Tool call ID. This can be used to match a tool call request with it's result. */
|
|
528
|
+
toolCallInstanceID?: string;
|
|
529
|
+
/** True if this tool call should be hidden in the UI */
|
|
530
|
+
toolCallHiddenInUI?: 'always' | 'after-complete';
|
|
531
|
+
}
|
|
532
|
+
/** Token window group item input, without the autogenerated fields */
|
|
533
|
+
type TokenWindowGroupItemParams<DataType> = Omit<Optional<TokenWindowGroupItem<DataType>, 'id' | 'dateAdded' | 'sortOrder' | 'text' | 'source' | 'sections'>, 'tokenCount'>;
|
|
534
|
+
|
|
390
535
|
/**
|
|
391
536
|
* Speech output
|
|
392
537
|
*
|
|
@@ -835,84 +980,6 @@ declare class MCPKnowledgeClient {
|
|
|
835
980
|
private performToolCall;
|
|
836
981
|
}
|
|
837
982
|
|
|
838
|
-
/**
|
|
839
|
-
* This class helps organize groups of tokenized text along with removing items when the window is full.
|
|
840
|
-
*/
|
|
841
|
-
declare class TokenWindow {
|
|
842
|
-
/** Token window size */
|
|
843
|
-
size: number;
|
|
844
|
-
/** Token groups */
|
|
845
|
-
groups: TokenWindowGroup<any>[];
|
|
846
|
-
/** Create a new group */
|
|
847
|
-
createGroup(id: string): TokenWindowGroup<unknown>;
|
|
848
|
-
/** Get a group */
|
|
849
|
-
group<CustomDataType>(id: string): TokenWindowGroup<CustomDataType> | undefined;
|
|
850
|
-
/** Calculate current tokens in all groups */
|
|
851
|
-
countTokens(): number;
|
|
852
|
-
/** Remove overflow from all groups. */
|
|
853
|
-
removeOverflow(): void;
|
|
854
|
-
/** Remove one overflow item. Returns null if no items were able to be removed. */
|
|
855
|
-
private removeOneItem;
|
|
856
|
-
}
|
|
857
|
-
/** A token group. */
|
|
858
|
-
declare class TokenWindowGroup<CustomDataType> {
|
|
859
|
-
/** Group ID */
|
|
860
|
-
id: string;
|
|
861
|
-
/** List of items */
|
|
862
|
-
items: TokenWindowGroupItem<CustomDataType>[];
|
|
863
|
-
/**
|
|
864
|
-
* Weight controls how many items from this group should be kept in relation to the entire window. For example if all
|
|
865
|
-
* 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,
|
|
866
|
-
* that group will be allowed to keep double the amount of items.
|
|
867
|
-
*/
|
|
868
|
-
weight: number;
|
|
869
|
-
/** Current total token count, computed automatically. Don't update this value manually. */
|
|
870
|
-
tokenCount: number;
|
|
871
|
-
/** Group item separator */
|
|
872
|
-
separator: string;
|
|
873
|
-
/** Token count padding added to each item. */
|
|
874
|
-
private itemPadding;
|
|
875
|
-
/** Sets the token count padding added to each item. Useful if you don't know exactly what will be added by the LLM host. */
|
|
876
|
-
setItemPadding(padding: number): this;
|
|
877
|
-
/** Sort function */
|
|
878
|
-
private sortFunction;
|
|
879
|
-
/** Set sort function */
|
|
880
|
-
sortBy(sortFunction: (a: TokenWindowGroupItem<CustomDataType>, b: TokenWindowGroupItem<CustomDataType>) => number): this;
|
|
881
|
-
/** Set separator */
|
|
882
|
-
setSeparator(separator: string): this;
|
|
883
|
-
/** Set weight */
|
|
884
|
-
setWeight(weight: number): this;
|
|
885
|
-
/** Recalculate all tokens. Note this may take a while. */
|
|
886
|
-
recalculateTokens(): void;
|
|
887
|
-
/** Add an item to the group */
|
|
888
|
-
add(item: string | Omit<Optional<TokenWindowGroupItem<CustomDataType>, 'id' | 'dateAdded' | 'sortOrder'>, 'tokenCount'>): TokenWindowGroupItem<CustomDataType>;
|
|
889
|
-
/** Get all items as a string */
|
|
890
|
-
getAllAsString(): string;
|
|
891
|
-
/** Get all items. Doesn't return disabled items. */
|
|
892
|
-
getAll(): TokenWindowGroupItem<CustomDataType>[];
|
|
893
|
-
/** Remove all items from this group */
|
|
894
|
-
empty(): void;
|
|
895
|
-
}
|
|
896
|
-
/** Token group item */
|
|
897
|
-
interface TokenWindowGroupItem<CustomDataType> {
|
|
898
|
-
/** Each item must have a unique ID. */
|
|
899
|
-
id: string;
|
|
900
|
-
/** The string content of the item */
|
|
901
|
-
content: string;
|
|
902
|
-
/** True if this item should never be removed */
|
|
903
|
-
cannotRemove?: boolean;
|
|
904
|
-
/** Sorting order. If not specified, uses dateAdded instead. */
|
|
905
|
-
sortOrder: number;
|
|
906
|
-
/** Date this item was added */
|
|
907
|
-
dateAdded: number;
|
|
908
|
-
/** Token count in the content */
|
|
909
|
-
tokenCount: number;
|
|
910
|
-
/** Anything to attach to this item */
|
|
911
|
-
customData?: CustomDataType;
|
|
912
|
-
/** If disabled, this item will not be included and will not add tot he token count. */
|
|
913
|
-
disabled?: boolean;
|
|
914
|
-
}
|
|
915
|
-
|
|
916
983
|
// ==================================================================================================
|
|
917
984
|
// JSON Schema Draft 07
|
|
918
985
|
// ==================================================================================================
|
|
@@ -1100,8 +1167,8 @@ interface ChatBaseConfig {
|
|
|
1100
1167
|
maxTokens: number;
|
|
1101
1168
|
/** Callback before the AI sends info to the LLM */
|
|
1102
1169
|
onBeforeMessageProcessing?: () => void;
|
|
1103
|
-
/** Callback when a message from the AI is returned. If
|
|
1104
|
-
onAIMessage?: (
|
|
1170
|
+
/** Callback when a message from the AI is returned. If isPartial is true, it may be incomplete and be called again with more updates. */
|
|
1171
|
+
onAIMessage?: (output: TokenWindowGroupItemParams<any>[], isPartial: boolean) => void;
|
|
1105
1172
|
/** Callback when the AI starts performing an action */
|
|
1106
1173
|
onAIToolStart?: (toolName: string, input: any) => void;
|
|
1107
1174
|
}
|
|
@@ -1115,19 +1182,17 @@ interface ChatBaseToolConfig {
|
|
|
1115
1182
|
params: JSONSchema7;
|
|
1116
1183
|
/** Callback function to process the tool */
|
|
1117
1184
|
callback: (params: any) => any;
|
|
1118
|
-
/** If true, this tool call will be removed from the message history after it is executed. */
|
|
1119
|
-
removeFromMessageHistory?: boolean;
|
|
1120
1185
|
/** If true, this item can be removed if there's not enough context available. */
|
|
1121
1186
|
canRemove?: boolean;
|
|
1122
|
-
/**
|
|
1123
|
-
|
|
1187
|
+
/** Knowledge base item this tool use represents */
|
|
1188
|
+
kbItem?: KnowledgeBaseItem;
|
|
1124
1189
|
}
|
|
1125
1190
|
/**
|
|
1126
1191
|
* API for interacting with chat APIs.
|
|
1127
1192
|
*/
|
|
1128
1193
|
declare class ChatBase<
|
|
1129
1194
|
/** Format for messages in the token window */
|
|
1130
|
-
|
|
1195
|
+
DataType = any,
|
|
1131
1196
|
/** Optional extended config */
|
|
1132
1197
|
ConfigFormat extends ChatBaseConfig = ChatBaseConfig> {
|
|
1133
1198
|
/** ID */
|
|
@@ -1146,27 +1211,58 @@ ConfigFormat extends ChatBaseConfig = ChatBaseConfig> {
|
|
|
1146
1211
|
/** Token window management */
|
|
1147
1212
|
tokenWindow: TokenWindow;
|
|
1148
1213
|
/** Token window group used for the context message */
|
|
1149
|
-
get contextGroup(): TokenWindowGroup<
|
|
1214
|
+
get contextGroup(): TokenWindowGroup<string>;
|
|
1150
1215
|
/** Token window group used for tools / actions */
|
|
1151
1216
|
get toolGroup(): TokenWindowGroup<ChatBaseToolConfig>;
|
|
1152
1217
|
/** Token window group used for messages */
|
|
1153
|
-
get messageGroup(): TokenWindowGroup<
|
|
1218
|
+
get messageGroup(): TokenWindowGroup<DataType>;
|
|
1219
|
+
/** Get the API base after stripping out exact endpoints, or undefined for the default */
|
|
1220
|
+
getBaseURL(): string | undefined;
|
|
1154
1221
|
/** Constructor */
|
|
1155
1222
|
constructor(config: ConfigFormat);
|
|
1156
|
-
/** Send a message, and get the response */
|
|
1157
|
-
sendMessage(message: string): Promise<
|
|
1223
|
+
/** Send a message, and get the response as a string. */
|
|
1224
|
+
sendMessage(message: string, onPartial?: (items: TokenWindowGroupItemParams<DataType>[]) => void): Promise<TokenWindowGroupItemParams<any>[]>;
|
|
1158
1225
|
/** Add a user message to the message history */
|
|
1159
1226
|
addUserMessage(message: string): void;
|
|
1160
1227
|
/** Add an assistant message to the message history */
|
|
1161
1228
|
addAssistantMessage(message: string): void;
|
|
1229
|
+
/** Helper to add a plain text item */
|
|
1230
|
+
protected addTextMessage(text: string, source: 'user' | 'assistant', data: DataType): void;
|
|
1162
1231
|
/** Process incoming message from the AI. Can be used to respond to encoded actions in the text response. */
|
|
1163
|
-
onBeforeIncomingMessage(message:
|
|
1232
|
+
onBeforeIncomingMessage(message: DataType): void;
|
|
1164
1233
|
/** Reset the conversation */
|
|
1165
1234
|
resetConversation(): void;
|
|
1166
1235
|
/** Trim message list */
|
|
1167
1236
|
trimMessages(): Promise<void>;
|
|
1168
1237
|
/** Register a tool. */
|
|
1169
1238
|
registerTool(tool: ChatBaseToolConfig): TokenWindowGroupItem<ChatBaseToolConfig>;
|
|
1239
|
+
/** Find a tool based on the AI-safe name */
|
|
1240
|
+
protected findToolBySafeName(toolSafeName: string): ChatBaseToolConfig | undefined;
|
|
1241
|
+
/** Execute the specified tool. Throws an error if the tool is undefined. */
|
|
1242
|
+
protected executeTool(tool: ChatBaseToolConfig | undefined, input: any): Promise<string>;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
/** Parses the response from `IntelliWeave.sendMessage()` or a collection of message items. */
|
|
1246
|
+
declare class IntelliWeaveMessageParser {
|
|
1247
|
+
/** New messages produced after sendMessage() was called */
|
|
1248
|
+
messages: TokenWindowGroupItemParams<unknown>[];
|
|
1249
|
+
/** Constructor */
|
|
1250
|
+
constructor(items: TokenWindowGroupItemParams<unknown>[]);
|
|
1251
|
+
/** Plain text output from the AI */
|
|
1252
|
+
text(): string;
|
|
1253
|
+
/** Total token usage */
|
|
1254
|
+
tokenUsage(): {
|
|
1255
|
+
cachedInputTokens: number;
|
|
1256
|
+
inputTokens: number;
|
|
1257
|
+
outputTokens: number;
|
|
1258
|
+
totalTokens: number;
|
|
1259
|
+
};
|
|
1260
|
+
/** Component sections for display */
|
|
1261
|
+
sections(): TokenWindowGroupItemParams<unknown>['sections'];
|
|
1262
|
+
/** List all tool calls that took place */
|
|
1263
|
+
toolCalls(): TokenWindowGroupItemSection[];
|
|
1264
|
+
/** Find the response for a tool call */
|
|
1265
|
+
toolResult(toolCallInstanceID: string): TokenWindowGroupItemSection | null;
|
|
1170
1266
|
}
|
|
1171
1267
|
|
|
1172
1268
|
/** Built-in action flags for the persona */
|
|
@@ -1242,6 +1338,8 @@ interface WebWeaverGPTConfig {
|
|
|
1242
1338
|
mcpServers?: MCPKnowledgeClient['config'][];
|
|
1243
1339
|
/** Built-in action flags that are currently enabled */
|
|
1244
1340
|
flags?: BuiltInActionFlags;
|
|
1341
|
+
/** Allow custom chat provider */
|
|
1342
|
+
onCreateProvider?: (config: ChatBaseConfig) => ChatBase;
|
|
1245
1343
|
}
|
|
1246
1344
|
/**
|
|
1247
1345
|
* IntelliWeave interface, loads a Persona from the hub and allows you to interact with it. This is the main entry point into the IntelliWeave
|
|
@@ -1252,7 +1350,7 @@ interface WebWeaverGPTConfig {
|
|
|
1252
1350
|
* - 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.
|
|
1253
1351
|
* - event `webweaver_error` - Fired when an error occurs during loading. This is a global event that is fired on the window object.
|
|
1254
1352
|
* - event `input` - Fired when the user sends a message to the AI.
|
|
1255
|
-
* - event `output` - Fired when the AI sends a message back to the user. If `event.detail.
|
|
1353
|
+
* - event `output` - Fired when the AI sends a message back to the user. If `event.detail.isPartial` is true, the message is incomplete and will be followed by more events.
|
|
1256
1354
|
* - event `toolstart` - Fired when the AI starts performing an action.
|
|
1257
1355
|
* - event `tool` - Fired when the AI finishes performing an action.
|
|
1258
1356
|
*/
|
|
@@ -1261,8 +1359,8 @@ declare class IntelliWeave extends EventTarget {
|
|
|
1261
1359
|
static version: string;
|
|
1262
1360
|
/** Built-in actions version - increment this when adding new actions */
|
|
1263
1361
|
static builtInActionsVersion: string;
|
|
1264
|
-
/** Callback when a message from the AI is returned. If
|
|
1265
|
-
onAIMessage?: (
|
|
1362
|
+
/** Callback when a message from the AI is returned. If isPartial is true, it may be incomplete and be called again with more updates. */
|
|
1363
|
+
onAIMessage?: (messages: TokenWindowGroupItemParams<unknown>[], isPartial: boolean) => void;
|
|
1266
1364
|
/** Callback when the AI starts performing an action */
|
|
1267
1365
|
onAIToolStart?: ChatBaseConfig['onAIToolStart'];
|
|
1268
1366
|
/** Current conversation ID */
|
|
@@ -1312,7 +1410,7 @@ declare class IntelliWeave extends EventTarget {
|
|
|
1312
1410
|
/** URL of the IntelliWeave Hub API */
|
|
1313
1411
|
hubAPI: string;
|
|
1314
1412
|
/** Set model and load data from an API key */
|
|
1315
|
-
load(apiKey: string): Promise<
|
|
1413
|
+
load(apiKey: string, config?: Partial<WebWeaverGPTConfig>): Promise<IntelliWeave>;
|
|
1316
1414
|
/** Set the current model */
|
|
1317
1415
|
setModel(id: string): void;
|
|
1318
1416
|
private _lastSystemMsg;
|
|
@@ -1320,17 +1418,15 @@ declare class IntelliWeave extends EventTarget {
|
|
|
1320
1418
|
getContextPrefix(): Promise<string>;
|
|
1321
1419
|
/** Get system message to send to the AI */
|
|
1322
1420
|
onBeforeMessageProcessing(): Promise<void>;
|
|
1323
|
-
/** @private Process incoming message from the AI. Can be used to respond to encoded actions in the text response. */
|
|
1324
|
-
processIncomingMessage(
|
|
1421
|
+
/** @private Process incoming message(s) from the AI. Can be used to respond to encoded actions in the text response. */
|
|
1422
|
+
processIncomingMessage(messages: TokenWindowGroupItemParams<unknown>[], isPartial?: boolean): void;
|
|
1325
1423
|
/** True if currently processing a message */
|
|
1326
1424
|
isProcessing: boolean;
|
|
1327
|
-
/** @private Last tracked token count for calculating per-message token usage */
|
|
1328
|
-
private _lastTrackedTokens;
|
|
1329
1425
|
/** Send a message, and get the response */
|
|
1330
|
-
sendMessage(message: string): Promise<
|
|
1426
|
+
sendMessage(message: string, onPartial?: (items: TokenWindowGroupItemParams<unknown>[]) => void): Promise<IntelliWeaveMessageParser>;
|
|
1331
1427
|
/** @private Called when the AI wants to run a KB action */
|
|
1332
1428
|
toolRunKBAction(kb: KnowledgeBaseItem, input: any): Promise<any>;
|
|
1333
|
-
/** Submit an analytics event asynchronously */
|
|
1429
|
+
/** Submit an analytics event asynchronously. These events are for use in the Conversation Analytics code. For anonymous statistic analysis, use track() instead. */
|
|
1334
1430
|
submitAnalyticsEvent(data: any): void;
|
|
1335
1431
|
/** Reset the conversation */
|
|
1336
1432
|
resetConversation(): void;
|
|
@@ -1340,12 +1436,14 @@ declare class IntelliWeave extends EventTarget {
|
|
|
1340
1436
|
exportState(): {
|
|
1341
1437
|
type: string;
|
|
1342
1438
|
conversationID: string;
|
|
1343
|
-
messages: any[] | undefined;
|
|
1439
|
+
messages: TokenWindowGroupItem<any>[] | undefined;
|
|
1344
1440
|
};
|
|
1345
1441
|
/** Import conversation state from JSON */
|
|
1346
1442
|
importState(state: any): void;
|
|
1347
1443
|
/** Clone this instance without any message history */
|
|
1348
1444
|
clone(): IntelliWeave;
|
|
1445
|
+
/** Get all messages in the conversation history */
|
|
1446
|
+
get messages(): TokenWindowGroupItem<any>[];
|
|
1349
1447
|
}
|
|
1350
1448
|
|
|
1351
1449
|
/**
|
|
@@ -1427,8 +1525,8 @@ interface KnowledgeBaseItem {
|
|
|
1427
1525
|
name: string;
|
|
1428
1526
|
/** Item tags. Helps with search optimization. */
|
|
1429
1527
|
tags?: string;
|
|
1430
|
-
/** Item content
|
|
1431
|
-
content: string
|
|
1528
|
+
/** Item content */
|
|
1529
|
+
content: string;
|
|
1432
1530
|
/** If true, this item will always be returned from all search results. */
|
|
1433
1531
|
isContext?: boolean;
|
|
1434
1532
|
/** If true, this item will not be visible to the AI. */
|
|
@@ -1441,8 +1539,8 @@ interface KnowledgeBaseItem {
|
|
|
1441
1539
|
* that was performed. If an error is thrown, the AI will respond appropriately to the user.
|
|
1442
1540
|
*/
|
|
1443
1541
|
action?: (input: any, ai: IntelliWeave) => (any | Promise<any>);
|
|
1444
|
-
/** If
|
|
1445
|
-
|
|
1542
|
+
/** If specified, will hide this action from the default UI after the AI finishes running it, or always hide it */
|
|
1543
|
+
hideActionInUI?: 'always' | 'after-complete';
|
|
1446
1544
|
}
|
|
1447
1545
|
/** Parameter definition used by IntelliWeave */
|
|
1448
1546
|
interface IntelliWeaveParameterDefinition {
|
|
@@ -1609,9 +1707,11 @@ declare class WebWeaverEmbed extends BaseComponent {
|
|
|
1609
1707
|
/** Process input text from the user */
|
|
1610
1708
|
processInput(inputText: string): Promise<void>;
|
|
1611
1709
|
/** Called when the AI responds with some text */
|
|
1612
|
-
onAIMessage(
|
|
1613
|
-
/**
|
|
1614
|
-
|
|
1710
|
+
onAIMessage(messages: TokenWindowGroupItemParams<unknown>[], isPartial: boolean): Promise<void>;
|
|
1711
|
+
/** Updates a text element */
|
|
1712
|
+
updateTextElement(elementID: string, text: string): void;
|
|
1713
|
+
/** Updates an info block element */
|
|
1714
|
+
updateInfoElement(elementID: string, text: string, iconType: string): void;
|
|
1615
1715
|
/** Called when a suggestion button is clicked */
|
|
1616
1716
|
onSuggestionClick(e: Event, suggestion: string): void;
|
|
1617
1717
|
/** Called when an LLM model is selected */
|
|
@@ -1667,55 +1767,44 @@ declare function getDefaultUserID(): string;
|
|
|
1667
1767
|
/** Convert an IntelliWeave parameter list to JSON schema. Does not modify if it's already a JSON schema. */
|
|
1668
1768
|
declare function convertParamsToJSONSchema(params: KnowledgeBaseActionParameterSchema): JSONSchema7;
|
|
1669
1769
|
|
|
1670
|
-
/**
|
|
1671
|
-
interface
|
|
1672
|
-
|
|
1673
|
-
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
1674
|
-
/** Content of the message */
|
|
1675
|
-
content: string;
|
|
1676
|
-
/** Tool call ID */
|
|
1677
|
-
tool_call_id?: string;
|
|
1678
|
-
/** Tool calls made by the AI */
|
|
1679
|
-
tool_calls?: any[];
|
|
1770
|
+
/** OpenRouter message extensions */
|
|
1771
|
+
interface OpenRouterMessage extends OpenAI.Chat.ChatCompletionAssistantMessageParam {
|
|
1772
|
+
reasoning?: string;
|
|
1680
1773
|
}
|
|
1774
|
+
/** OpenAI message format */
|
|
1775
|
+
type DataType$1 = OpenRouterMessage | OpenAI.Chat.Completions.ChatCompletionMessageParam;
|
|
1681
1776
|
/**
|
|
1682
|
-
* API for interacting with
|
|
1777
|
+
* API for interacting with Anthropic APIs.
|
|
1683
1778
|
*/
|
|
1684
|
-
declare class ChatGPT extends ChatBase<
|
|
1685
|
-
/**
|
|
1686
|
-
sendMessage(message: string): Promise<string>;
|
|
1687
|
-
/** Insert a message as if the assistant has written it */
|
|
1688
|
-
addAssistantMessage(message: string): void;
|
|
1689
|
-
/** 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. */
|
|
1779
|
+
declare class ChatGPT extends ChatBase<DataType$1> {
|
|
1780
|
+
/** Add a user message to the message history */
|
|
1690
1781
|
addUserMessage(message: string): void;
|
|
1691
|
-
/**
|
|
1692
|
-
|
|
1693
|
-
/**
|
|
1694
|
-
|
|
1695
|
-
/**
|
|
1696
|
-
|
|
1782
|
+
/** Add an assistant message to the message history */
|
|
1783
|
+
addAssistantMessage(message: string): void;
|
|
1784
|
+
/** Create the OpenAI client */
|
|
1785
|
+
protected createOpenAIClient(): OpenAI;
|
|
1786
|
+
/** Send a message, and get the response string. */
|
|
1787
|
+
sendMessage(message: string, onPartial?: (items: TokenWindowGroupItemParams<DataType$1>[]) => void): Promise<TokenWindowGroupItemParams<any>[]>;
|
|
1788
|
+
/** Parse a message block into our format */
|
|
1789
|
+
protected parseMessageBlock(messageID: string, message: OpenRouterMessage, usage: OpenAI.Completions.CompletionUsage | undefined, isPartial: boolean): TokenWindowGroupItemParams<DataType$1>;
|
|
1697
1790
|
/** Trim message list */
|
|
1698
1791
|
trimMessages(): Promise<void>;
|
|
1699
|
-
/** @private Send HTTP request to the API and return the response */
|
|
1700
|
-
sendRequest(payload: any): Promise<Response>;
|
|
1701
|
-
/** @private Send message list to the API and store the response */
|
|
1702
|
-
sendToAPI(generatePayloadOnly?: boolean): Promise<any>;
|
|
1703
|
-
/** @private Process a tool call request from the AI */
|
|
1704
|
-
processToolCall(toolCall: any): Promise<void>;
|
|
1705
1792
|
}
|
|
1706
1793
|
|
|
1794
|
+
/** Anthropic message format */
|
|
1795
|
+
type DataType = Anthropic.Messages.MessageParam;
|
|
1707
1796
|
/**
|
|
1708
1797
|
* API for interacting with Anthropic APIs.
|
|
1709
1798
|
*/
|
|
1710
|
-
declare class AnthropicChat extends ChatBase<
|
|
1799
|
+
declare class AnthropicChat extends ChatBase<DataType> {
|
|
1711
1800
|
/** Add a user message to the message history */
|
|
1712
1801
|
addUserMessage(message: string): void;
|
|
1713
1802
|
/** Add an assistant message to the message history */
|
|
1714
1803
|
addAssistantMessage(message: string): void;
|
|
1715
|
-
/** Send a message, and get the response */
|
|
1716
|
-
sendMessage(message: string): Promise<
|
|
1717
|
-
/**
|
|
1718
|
-
protected
|
|
1804
|
+
/** Send a message, and get the response string. */
|
|
1805
|
+
sendMessage(message: string, onPartial?: (items: TokenWindowGroupItemParams<DataType>[]) => void): Promise<TokenWindowGroupItemParams<any>[]>;
|
|
1806
|
+
/** Parse a message block into our format */
|
|
1807
|
+
protected parseMessageBlock(message: Anthropic.Messages.Message): TokenWindowGroupItemParams<DataType>;
|
|
1719
1808
|
/** Trim message list */
|
|
1720
1809
|
trimMessages(): Promise<void>;
|
|
1721
1810
|
}
|
|
@@ -1744,55 +1833,4 @@ declare class Logging {
|
|
|
1744
1833
|
timer(name: string, ...args: any[]): (...args: any[]) => void;
|
|
1745
1834
|
}
|
|
1746
1835
|
|
|
1747
|
-
|
|
1748
|
-
* Handles a stream of input/output events with the specified AI model.
|
|
1749
|
-
*
|
|
1750
|
-
* @event event - Fired when an event is emitted, either by the AI or wrapper code etc.
|
|
1751
|
-
*/
|
|
1752
|
-
declare class IntelliWeaveStream extends IntelliWeave {
|
|
1753
|
-
/** Events that haven't been sent to the AI yet */
|
|
1754
|
-
pendingEvents: IntelliWeaveStreamEvent[];
|
|
1755
|
-
/** Get the system message prefix, before the KB entries are added */
|
|
1756
|
-
getContextPrefix(): Promise<string>;
|
|
1757
|
-
/** Get actions to be added to the context */
|
|
1758
|
-
/** Post an event to the AI */
|
|
1759
|
-
postEvent(event: Partial<IntelliWeaveStreamEvent>): void;
|
|
1760
|
-
/** @private Called when the AI wants to run a KB action */
|
|
1761
|
-
toolRunKBAction(kb: KnowledgeBaseItem, input: any): Promise<any>;
|
|
1762
|
-
/** Output an event to the event listener(s) */
|
|
1763
|
-
private emitEvent;
|
|
1764
|
-
private _isProcessingEvents;
|
|
1765
|
-
/** Process events */
|
|
1766
|
-
private processEvents;
|
|
1767
|
-
}
|
|
1768
|
-
/** Any event */
|
|
1769
|
-
interface IntelliWeaveStreamEvent {
|
|
1770
|
-
/** Event name */
|
|
1771
|
-
eventName: string;
|
|
1772
|
-
/** Event date, unix timestamp, number of milliseconds since Jan 1 1970 */
|
|
1773
|
-
timestamp: number;
|
|
1774
|
-
/** Human-readable event date */
|
|
1775
|
-
timestampDate: string;
|
|
1776
|
-
/** Direction of this event. Input events go into the AI for processing, output events come out of the AI system. */
|
|
1777
|
-
direction: 'input' | 'output';
|
|
1778
|
-
/** Assistant hint, added automatically if there's a KB entry with the same ID. */
|
|
1779
|
-
assistantHint?: string;
|
|
1780
|
-
/** Any extra data */
|
|
1781
|
-
[key: string]: any;
|
|
1782
|
-
}
|
|
1783
|
-
/** Error event schema */
|
|
1784
|
-
interface IntelliWeaveStreamErrorEvent extends IntelliWeaveStreamEvent {
|
|
1785
|
-
/** Event name */
|
|
1786
|
-
eventName: "error";
|
|
1787
|
-
/** Error details */
|
|
1788
|
-
errorMessage: string;
|
|
1789
|
-
}
|
|
1790
|
-
/** AI speaking event */
|
|
1791
|
-
interface IntelliWeaveStreamTextOutputEvent extends IntelliWeaveStreamEvent {
|
|
1792
|
-
/** Event name */
|
|
1793
|
-
eventName: "text";
|
|
1794
|
-
/** The text spoken */
|
|
1795
|
-
text: string;
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
export { AnthropicChat, type BufferType, BufferedWebSocket, type BuiltInActionFlags, ChatBase, type ChatBaseConfig, type ChatBaseToolConfig, ChatGPT, type ChatGPTMessage, FixedBufferStream, IntelliWeave, type IntelliWeaveGlobalConfig, type IntelliWeaveParameterDefinition, IntelliWeaveStream, type IntelliWeaveStreamErrorEvent, type IntelliWeaveStreamEvent, type IntelliWeaveStreamTextOutputEvent, KnowledgeBase, type KnowledgeBaseActionParameterSchema, type KnowledgeBaseItem, type KnowledgeBaseSource, type KnowledgeBaseWebhookActionResponse, type KnowledgeBaseWebhookRequest, type KnowledgeBaseWebhookSearchResponse, type KnowledgeFetcher, Logging, MCPKnowledgeClient, ONNXModel, type ONNXTensors, Resampler, type SupportedArrayBuffers, TokenWindow, TokenWindowGroup, type TokenWindowGroupItem, type WebWeaverGPTConfig, audioToWav, convertParamsToJSONSchema, floatTo16BitPCM, floatTo64BitPCM, getDefaultUserID, int16ToFloat32BitPCM, intelliweaveConfig, intelliweaveGlobalThis, sseEvents, trimWhitespaceInText };
|
|
1836
|
+
export { AnthropicChat, type BufferType, BufferedWebSocket, type BuiltInActionFlags, ChatBase, type ChatBaseConfig, type ChatBaseToolConfig, ChatGPT, FixedBufferStream, IntelliWeave, type IntelliWeaveGlobalConfig, IntelliWeaveMessageParser, type IntelliWeaveParameterDefinition, KnowledgeBase, type KnowledgeBaseActionParameterSchema, type KnowledgeBaseItem, type KnowledgeBaseSource, type KnowledgeBaseWebhookActionResponse, type KnowledgeBaseWebhookRequest, type KnowledgeBaseWebhookSearchResponse, type KnowledgeFetcher, Logging, MCPKnowledgeClient, ONNXModel, type ONNXTensors, Resampler, type SupportedArrayBuffers, TokenWindow, TokenWindowGroup, type TokenWindowGroupItem, type TokenWindowGroupItemParams, type TokenWindowGroupItemSection, TokenWindowGroupItemSectionType, type WebWeaverGPTConfig, audioToWav, convertParamsToJSONSchema, floatTo16BitPCM, floatTo64BitPCM, getDefaultUserID, int16ToFloat32BitPCM, intelliweaveConfig, intelliweaveGlobalThis, sseEvents, trimWhitespaceInText };
|