@intelliweave/embedded 2.0.71 → 2.0.72-beta.10

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,5 +1,151 @@
1
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
1
  import { Optional } from 'utility-types';
2
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
3
+
4
+ /**
5
+ * This class helps organize groups of tokenized text along with removing items when the window is full.
6
+ */
7
+ declare class TokenWindow {
8
+ /** Token window size */
9
+ size: number;
10
+ /** Token groups */
11
+ groups: TokenWindowGroup<any>[];
12
+ /** Create a new group */
13
+ createGroup(id: string): TokenWindowGroup<unknown>;
14
+ /** Get a group */
15
+ group<CustomDataType>(id: string): TokenWindowGroup<CustomDataType> | undefined;
16
+ /** Counts tokens in the specified text */
17
+ static countTokensInText(text: string): number;
18
+ /** Calculate current tokens in all groups */
19
+ countTokens(): number;
20
+ /** Remove overflow from all groups. */
21
+ removeOverflow(): void;
22
+ /** Remove one overflow item. Returns null if no items were able to be removed. */
23
+ private removeOneItem;
24
+ }
25
+ /** A token group. */
26
+ declare class TokenWindowGroup<DataType> {
27
+ /** Group ID */
28
+ id: string;
29
+ /** List of items */
30
+ items: TokenWindowGroupItem<DataType>[];
31
+ /**
32
+ * Weight controls how many items from this group should be kept in relation to the entire window. For example if all
33
+ * 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,
34
+ * that group will be allowed to keep double the amount of items.
35
+ */
36
+ weight: number;
37
+ /** Current total token count, computed automatically. Don't update this value manually. */
38
+ tokenCount: number;
39
+ /** Group item separator. This text is added in between each item in the token window. */
40
+ separator: string;
41
+ /** Token count padding added to each item. */
42
+ private itemPadding;
43
+ /** Sets the token count padding added to each item. Useful if you don't know exactly what will be added by the LLM host. */
44
+ setItemPadding(padding: number): this;
45
+ /** Sort function */
46
+ private sortFunction;
47
+ /** Set sort function */
48
+ sortBy(sortFunction: (a: TokenWindowGroupItem<DataType>, b: TokenWindowGroupItem<DataType>) => number): this;
49
+ /** Set separator. This text is added in between each item in the token window. */
50
+ setSeparator(separator: string): this;
51
+ /**
52
+ * Set weight. Weight controls how many items from this group should be kept
53
+ * in relation to the entire window. For example if all groups have a weight
54
+ * of 1, each group remove items equally if full. If one has a weight of 2
55
+ * while the rest are 1, that group will be allowed to keep double the
56
+ * amount of items.
57
+ */
58
+ setWeight(weight: number): this;
59
+ /** Recalculate all tokens. Note this may take a while. */
60
+ recalculateTokens(): void;
61
+ /** Add an item to the group */
62
+ add(item: string | TokenWindowGroupItemParams<DataType>): TokenWindowGroupItem<DataType>;
63
+ /** Get all items as a string */
64
+ getAllAsString(): string;
65
+ /** Get all items. Doesn't return disabled items. */
66
+ getAll(): TokenWindowGroupItem<DataType>[];
67
+ /** Remove all items from this group */
68
+ empty(): void;
69
+ }
70
+ /** Token group item section types */
71
+ declare enum TokenWindowGroupItemSectionType {
72
+ /** Text items represent plain text. */
73
+ Text = "text",
74
+ /** Tool call items represent a tool call requested by the AI. */
75
+ ToolCall = "tool_call",
76
+ /** Tool result items represent the result of a tool call. */
77
+ ToolResult = "tool_result",
78
+ /** Thinking section */
79
+ Thinking = "thinking",
80
+ /** Other item types */
81
+ Other = "other"
82
+ }
83
+ /** Token group item */
84
+ interface TokenWindowGroupItem<DataType> {
85
+ /** Each item must have a unique ID. */
86
+ id: string;
87
+ /** True if this item should never be removed */
88
+ cannotRemove?: boolean;
89
+ /** Sorting order. If not specified, uses dateAdded instead. */
90
+ sortOrder: number;
91
+ /** Date this item was added */
92
+ dateAdded: number;
93
+ /** Token count in the content */
94
+ tokenCount: number;
95
+ /** This is the actual item that gets sent to the APIs. It will be in whatever format is required for the associated API. */
96
+ data?: DataType;
97
+ /** If disabled, this item will not be included and will not add to the token count. */
98
+ disabled?: boolean;
99
+ /** Message source, ie was this message created by the user, or by the AI? */
100
+ source: 'user' | 'assistant';
101
+ /**
102
+ * 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.
103
+ * 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.
104
+ *
105
+ * 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.
106
+ */
107
+ text?: string;
108
+ /** Message sections */
109
+ sections?: TokenWindowGroupItemSection[];
110
+ /** If this message was generated by the AI, this contains the token usage for this message. */
111
+ usage?: {
112
+ /** Number of tokens consumed from the data passed to the AI */
113
+ inputTokens: number;
114
+ /** Number of input tokens that were used in token caching */
115
+ cachedInputTokens: number;
116
+ /** Number of tokens consumed by the AI generating output */
117
+ outputTokens: number;
118
+ /** Total token usage */
119
+ totalTokens: number;
120
+ };
121
+ /** True if this item is still being streamed */
122
+ streamingInProgress?: boolean;
123
+ }
124
+ /** A section of a message returned by the AI */
125
+ interface TokenWindowGroupItemSection {
126
+ /** Section type */
127
+ type: TokenWindowGroupItemSectionType;
128
+ /** Text content when this section represents text or thinking */
129
+ text?: string;
130
+ /** The raw tool name the AI requested to be called. */
131
+ toolName?: string;
132
+ /** The ID of the KB action this tool call maps to, if any */
133
+ toolKbID?: string;
134
+ /** The name of the KB action this tool call maps to, if any */
135
+ toolKbName?: string;
136
+ /** The parameters the AI requested to be sent to the tool. Only available if type == 'tool_call' */
137
+ toolParameters?: any;
138
+ /** Successful response of the tool call. Will be null if toolErrorResponse is set. */
139
+ toolSuccessResponse?: any;
140
+ /** Error response of the tool call. Will be null if toolSuccessResponse is set. */
141
+ toolErrorResponse?: string;
142
+ /** Tool call ID. This can be used to match a tool call request with it's result. */
143
+ toolCallInstanceID?: string;
144
+ /** True if this tool call should be hidden in the UI */
145
+ toolCallHiddenInUI?: 'always' | 'after-complete';
146
+ }
147
+ /** Token window group item input, without the autogenerated fields */
148
+ type TokenWindowGroupItemParams<DataType> = Omit<Optional<TokenWindowGroupItem<DataType>, 'id' | 'dateAdded' | 'sortOrder' | 'text' | 'source' | 'sections'>, 'tokenCount'>;
3
149
 
4
150
  /**
5
151
  * Allows an MCP server to be used as a knowledge source for IntelliWeave.
@@ -30,6 +176,17 @@ declare class MCPKnowledgeClient {
30
176
  searchToolName?: string;
31
177
  /** Keep search function available for the AI to use. */
32
178
  searchToolVisible?: boolean;
179
+ /** Use the IntelliWeave proxy */
180
+ proxy?: {
181
+ /** If true, will send requests via the IntelliWeave MCP proxy */
182
+ enabled?: boolean;
183
+ /** The URL of the proxy server, defaults to the standard IntelliWeave proxy */
184
+ url?: string;
185
+ /** IntelliWeave API key */
186
+ apiKey?: string;
187
+ };
188
+ /** Pass extra headers to the MCP server */
189
+ headers?: Record<string, string>;
33
190
  };
34
191
  /** Constructor */
35
192
  constructor(config: MCPKnowledgeClient['config']);
@@ -40,16 +197,10 @@ declare class MCPKnowledgeClient {
40
197
  method: string;
41
198
  params?: {
42
199
  [x: string]: unknown;
43
- task?: {
44
- [x: string]: unknown;
45
- ttl?: number | null | undefined;
46
- pollInterval?: number | undefined;
47
- } | undefined;
48
200
  _meta?: {
49
201
  [x: string]: unknown;
50
202
  progressToken?: string | number | undefined;
51
203
  "io.modelcontextprotocol/related-task"?: {
52
- [x: string]: unknown;
53
204
  taskId: string;
54
205
  } | undefined;
55
206
  } | undefined;
@@ -60,8 +211,8 @@ declare class MCPKnowledgeClient {
60
211
  [x: string]: unknown;
61
212
  _meta?: {
62
213
  [x: string]: unknown;
214
+ progressToken?: string | number | undefined;
63
215
  "io.modelcontextprotocol/related-task"?: {
64
- [x: string]: unknown;
65
216
  taskId: string;
66
217
  } | undefined;
67
218
  } | undefined;
@@ -70,8 +221,8 @@ declare class MCPKnowledgeClient {
70
221
  [x: string]: unknown;
71
222
  _meta?: {
72
223
  [x: string]: unknown;
224
+ progressToken?: string | number | undefined;
73
225
  "io.modelcontextprotocol/related-task"?: {
74
- [x: string]: unknown;
75
226
  taskId: string;
76
227
  } | undefined;
77
228
  } | undefined;
@@ -80,16 +231,10 @@ declare class MCPKnowledgeClient {
80
231
  method: string;
81
232
  params?: {
82
233
  [x: string]: unknown;
83
- task?: {
84
- [x: string]: unknown;
85
- ttl?: number | null | undefined;
86
- pollInterval?: number | undefined;
87
- } | undefined;
88
234
  _meta?: {
89
235
  [x: string]: unknown;
90
236
  progressToken?: string | number | undefined;
91
237
  "io.modelcontextprotocol/related-task"?: {
92
- [x: string]: unknown;
93
238
  taskId: string;
94
239
  } | undefined;
95
240
  } | undefined;
@@ -100,8 +245,8 @@ declare class MCPKnowledgeClient {
100
245
  [x: string]: unknown;
101
246
  _meta?: {
102
247
  [x: string]: unknown;
248
+ progressToken?: string | number | undefined;
103
249
  "io.modelcontextprotocol/related-task"?: {
104
- [x: string]: unknown;
105
250
  taskId: string;
106
251
  } | undefined;
107
252
  } | undefined;
@@ -110,8 +255,8 @@ declare class MCPKnowledgeClient {
110
255
  [x: string]: unknown;
111
256
  _meta?: {
112
257
  [x: string]: unknown;
258
+ progressToken?: string | number | undefined;
113
259
  "io.modelcontextprotocol/related-task"?: {
114
- [x: string]: unknown;
115
260
  taskId: string;
116
261
  } | undefined;
117
262
  } | undefined;
@@ -312,8 +457,16 @@ declare class KnowledgeBase {
312
457
  lastResults: KnowledgeBaseItem[];
313
458
  /** Individual knowledge base entries added manually by the application */
314
459
  manualEntries: KnowledgeBaseItem[];
460
+ /** If true, allows using globally defined sources from the browser window events */
461
+ allowWindowSources: boolean;
462
+ /** If true, allows using knowledge specified in the global configuration object */
463
+ allowGlobalConfigSources: boolean;
315
464
  /** Constructor */
316
465
  constructor(ai: IntelliWeave);
466
+ /** Ensures the internal knowledge is set correctly */
467
+ ensureInternalKnowledge(): void;
468
+ /** Clears all knowledge back to the default */
469
+ reset(): void;
317
470
  /**
318
471
  * Register a new knowledge base source. You can pass either just a query function, or an ID and a query function.
319
472
  *
@@ -377,12 +530,12 @@ interface KnowledgeBaseItem {
377
530
  name: string;
378
531
  /** Item tags. Helps with search optimization. */
379
532
  tags?: string;
380
- /** Item content. Can be a function to return a dynamic string. */
381
- content: string | (() => string);
533
+ /** Item content */
534
+ content: string;
382
535
  /** If true, this item will always be returned from all search results. */
383
536
  isContext?: boolean;
384
537
  /** If true, this item will not be visible to the AI. */
385
- disabled?: boolean;
538
+ disabled?: boolean | ((ai: IntelliWeave) => boolean);
386
539
  /** List of parameters for an action function. Can either use IW's format, or a JSON Schema object. */
387
540
  parameters?: KnowledgeBaseActionParameterSchema;
388
541
  /**
@@ -391,8 +544,27 @@ interface KnowledgeBaseItem {
391
544
  * that was performed. If an error is thrown, the AI will respond appropriately to the user.
392
545
  */
393
546
  action?: (input: any, ai: IntelliWeave) => (any | Promise<any>);
394
- /** If true, this item will be removed from the AI's message history after it gets called. This is a special case for LLMs that struggle with follow-up function calls and need to use the KB search functino first. */
395
- removeFromMessageHistory?: boolean;
547
+ /** If specified, will hide this action from the default UI after the AI finishes running it, or always hide it */
548
+ hideActionInUI?: 'always' | 'after-complete';
549
+ /** Attachments such as images, etc */
550
+ attachments?: KnowledgeBaseItemAttachment[];
551
+ }
552
+ /** Knowledge base item attachment, such as an image, file, etc. */
553
+ interface KnowledgeBaseItemAttachment {
554
+ /** UUID */
555
+ uuid: string;
556
+ /** Attachment mime type */
557
+ mimeType: string;
558
+ /** File name */
559
+ name: string;
560
+ /** Full URL to access the file. This is required for the AI to be able to see the attachment. */
561
+ url?: string;
562
+ /** UNIX timestamp (milliseconds since epoch) when the file was added */
563
+ dateAdded?: number;
564
+ /** Internal path to where the file is stored */
565
+ path?: string;
566
+ /** File size */
567
+ size?: number;
396
568
  }
397
569
  /** Parameter definition used by IntelliWeave */
398
570
  interface IntelliWeaveParameterDefinition {
@@ -413,10 +585,16 @@ type KnowledgeBaseActionParameterSchema = JSONSchema7 | IntelliWeaveParameterDef
413
585
  declare class WebWeaverSpeechOutput extends EventTarget {
414
586
  /** Reference to the AI */
415
587
  private ai?;
588
+ /** Automatically speak output from the AI */
589
+ autoSpeak: boolean;
590
+ /** If enabled, connections will be pre-emptively opened to speed up text-to-speech response times, if possible */
591
+ preemptiveConnection: boolean;
416
592
  /** Constructor */
417
593
  constructor(ai: IntelliWeave);
418
- /** Called when the AI speaks */
419
- onTextOutputFromAI(e: CustomEvent): void;
594
+ /** Message IDs we've processed */
595
+ private processedMessages;
596
+ /** Called when the AI responds */
597
+ onOutputFromAI(e: CustomEvent): void;
420
598
  /** Current player vars */
421
599
  private currentPlayerVolume?;
422
600
  private currentPlayer?;
@@ -428,8 +606,15 @@ declare class WebWeaverSpeechOutput extends EventTarget {
428
606
  private maxVolumeHeard;
429
607
  /** Get current (realtime) audio output volume level, from 0 to 1 */
430
608
  get volumeLevel(): number;
609
+ /** Queued messages to speak next */
610
+ private _queuedText;
431
611
  /** Speak the text */
432
612
  speak(text: string): Promise<void>;
613
+ private _queueActive;
614
+ _runQueue(): Promise<void>;
615
+ /** ElevenLabs connection pre-cache */
616
+ private _elevenLabsPrecachedConnection?;
617
+ private _getElevenLabsConnection;
433
618
  private _speakWithLock;
434
619
  /** True if currently playing audio */
435
620
  get isSpeaking(): boolean;
@@ -572,7 +757,7 @@ declare class IntelliWeaveTranscriptionNode extends VoiceChunkOutputNode {
572
757
  static debugExportWav: boolean;
573
758
  /** Server address for transcription */
574
759
  apiAddress: string;
575
- /** OpenAI API key */
760
+ /** IntelliWeave API key */
576
761
  apiKey: string;
577
762
  /** WebSocket connection */
578
763
  private ws?;
@@ -592,6 +777,32 @@ declare class IntelliWeaveTranscriptionNode extends VoiceChunkOutputNode {
592
777
  onSocketClose(): void;
593
778
  }
594
779
 
780
+ /**
781
+ * This AudioNode uses ElevenLabs to transcribe spoken speech to text.
782
+ *
783
+ * - event `transcription` - Fired when a transcription is ready. `text` contains the transcribed text.
784
+ */
785
+ declare class ElevenLabsTranscriptionNode extends VoiceChunkOutputNode {
786
+ /** ElevenLabs API key */
787
+ apiKey: string;
788
+ /** ElevenLabs stream connection */
789
+ private connection?;
790
+ /** True if currently transcribing */
791
+ isTranscribing: boolean;
792
+ /** WebSocket shutdown timer */
793
+ private shutdownTimer?;
794
+ /** Constructor */
795
+ constructor(audioContext: AudioContext, apiKey: string);
796
+ /** Called when a voice chunk is received */
797
+ onVoiceChunk(buffer: Float32Array): Promise<void>;
798
+ /** Start reading the stream */
799
+ private startReading;
800
+ /** Called when the voice recording ends */
801
+ onVoiceEnd(buffers: Float32Array[]): Promise<void>;
802
+ /** Called when a transcription is ready */
803
+ onVoiceTranscription(text: string): void;
804
+ }
805
+
595
806
  /**
596
807
  * Handles speech recognition from the microphone
597
808
  *
@@ -617,7 +828,7 @@ declare class WebWeaverSpeechRecognition extends EventTarget {
617
828
  /** Returns true if speech recognition is supported by this persona and browser */
618
829
  get isSupported(): boolean;
619
830
  /** Currently active voice detection node */
620
- voiceDetection?: IntelliWeaveTranscriptionNode | OpenAITranscriptionNode;
831
+ voiceDetection?: IntelliWeaveTranscriptionNode | OpenAITranscriptionNode | ElevenLabsTranscriptionNode;
621
832
  /** Constructor */
622
833
  constructor(ai: IntelliWeave);
623
834
  private _skipEvents;
@@ -721,84 +932,6 @@ interface IntelliWeaveInstructConfig {
721
932
  callback?: (txt: string) => void;
722
933
  }
723
934
 
724
- /**
725
- * This class helps organize groups of tokenized text along with removing items when the window is full.
726
- */
727
- declare class TokenWindow {
728
- /** Token window size */
729
- size: number;
730
- /** Token groups */
731
- groups: TokenWindowGroup<any>[];
732
- /** Create a new group */
733
- createGroup(id: string): TokenWindowGroup<unknown>;
734
- /** Get a group */
735
- group<CustomDataType>(id: string): TokenWindowGroup<CustomDataType> | undefined;
736
- /** Calculate current tokens in all groups */
737
- countTokens(): number;
738
- /** Remove overflow from all groups. */
739
- removeOverflow(): void;
740
- /** Remove one overflow item. Returns null if no items were able to be removed. */
741
- private removeOneItem;
742
- }
743
- /** A token group. */
744
- declare class TokenWindowGroup<CustomDataType> {
745
- /** Group ID */
746
- id: string;
747
- /** List of items */
748
- items: TokenWindowGroupItem<CustomDataType>[];
749
- /**
750
- * Weight controls how many items from this group should be kept in relation to the entire window. For example if all
751
- * 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,
752
- * that group will be allowed to keep double the amount of items.
753
- */
754
- weight: number;
755
- /** Current total token count, computed automatically. Don't update this value manually. */
756
- tokenCount: number;
757
- /** Group item separator */
758
- separator: string;
759
- /** Token count padding added to each item. */
760
- private itemPadding;
761
- /** Sets the token count padding added to each item. Useful if you don't know exactly what will be added by the LLM host. */
762
- setItemPadding(padding: number): this;
763
- /** Sort function */
764
- private sortFunction;
765
- /** Set sort function */
766
- sortBy(sortFunction: (a: TokenWindowGroupItem<CustomDataType>, b: TokenWindowGroupItem<CustomDataType>) => number): this;
767
- /** Set separator */
768
- setSeparator(separator: string): this;
769
- /** Set weight */
770
- setWeight(weight: number): this;
771
- /** Recalculate all tokens. Note this may take a while. */
772
- recalculateTokens(): void;
773
- /** Add an item to the group */
774
- add(item: string | Omit<Optional<TokenWindowGroupItem<CustomDataType>, 'id' | 'dateAdded' | 'sortOrder'>, 'tokenCount'>): TokenWindowGroupItem<CustomDataType>;
775
- /** Get all items as a string */
776
- getAllAsString(): string;
777
- /** Get all items. Doesn't return disabled items. */
778
- getAll(): TokenWindowGroupItem<CustomDataType>[];
779
- /** Remove all items from this group */
780
- empty(): void;
781
- }
782
- /** Token group item */
783
- interface TokenWindowGroupItem<CustomDataType> {
784
- /** Each item must have a unique ID. */
785
- id: string;
786
- /** The string content of the item */
787
- content: string;
788
- /** True if this item should never be removed */
789
- cannotRemove?: boolean;
790
- /** Sorting order. If not specified, uses dateAdded instead. */
791
- sortOrder: number;
792
- /** Date this item was added */
793
- dateAdded: number;
794
- /** Token count in the content */
795
- tokenCount: number;
796
- /** Anything to attach to this item */
797
- customData?: CustomDataType;
798
- /** If disabled, this item will not be included and will not add tot he token count. */
799
- disabled?: boolean;
800
- }
801
-
802
935
  /** Chat config options */
803
936
  interface ChatBaseConfig {
804
937
  /** API key */
@@ -819,8 +952,8 @@ interface ChatBaseConfig {
819
952
  maxTokens: number;
820
953
  /** Callback before the AI sends info to the LLM */
821
954
  onBeforeMessageProcessing?: () => void;
822
- /** Callback when a message from the AI is returned. If isChunk is true, it may be incomplete and be called again with more updates. */
823
- onAIMessage?: (text: string, isChunk: boolean) => void;
955
+ /** Callback when a message from the AI is returned. If isPartial is true, it may be incomplete and be called again with more updates. */
956
+ onAIMessage?: (output: TokenWindowGroupItemParams<any>[], isPartial: boolean) => void;
824
957
  /** Callback when the AI starts performing an action */
825
958
  onAIToolStart?: (toolName: string, input: any) => void;
826
959
  }
@@ -834,19 +967,17 @@ interface ChatBaseToolConfig {
834
967
  params: JSONSchema7;
835
968
  /** Callback function to process the tool */
836
969
  callback: (params: any) => any;
837
- /** If true, this tool call will be removed from the message history after it is executed. */
838
- removeFromMessageHistory?: boolean;
839
970
  /** If true, this item can be removed if there's not enough context available. */
840
971
  canRemove?: boolean;
841
- /** Misc app context */
842
- [key: string]: any;
972
+ /** Knowledge base item this tool use represents */
973
+ kbItem?: KnowledgeBaseItem;
843
974
  }
844
975
  /**
845
976
  * API for interacting with chat APIs.
846
977
  */
847
978
  declare class ChatBase<
848
979
  /** Format for messages in the token window */
849
- MessageFormat = any,
980
+ DataType = any,
850
981
  /** Optional extended config */
851
982
  ConfigFormat extends ChatBaseConfig = ChatBaseConfig> {
852
983
  /** ID */
@@ -865,27 +996,95 @@ ConfigFormat extends ChatBaseConfig = ChatBaseConfig> {
865
996
  /** Token window management */
866
997
  tokenWindow: TokenWindow;
867
998
  /** Token window group used for the context message */
868
- get contextGroup(): TokenWindowGroup<any>;
999
+ get contextGroup(): TokenWindowGroup<string>;
869
1000
  /** Token window group used for tools / actions */
870
1001
  get toolGroup(): TokenWindowGroup<ChatBaseToolConfig>;
871
1002
  /** Token window group used for messages */
872
- get messageGroup(): TokenWindowGroup<MessageFormat>;
1003
+ get messageGroup(): TokenWindowGroup<DataType>;
1004
+ /** Get the API base after stripping out exact endpoints, or undefined for the default */
1005
+ getBaseURL(): string | undefined;
873
1006
  /** Constructor */
874
1007
  constructor(config: ConfigFormat);
875
- /** Send a message, and get the response */
876
- sendMessage(message: string): Promise<string>;
1008
+ /** Send a message, and get the response as a string. */
1009
+ sendMessage(message: string, onPartial?: (items: TokenWindowGroupItemParams<DataType>[]) => void): Promise<TokenWindowGroupItemParams<any>[]>;
877
1010
  /** Add a user message to the message history */
878
1011
  addUserMessage(message: string): void;
879
1012
  /** Add an assistant message to the message history */
880
1013
  addAssistantMessage(message: string): void;
1014
+ /** Helper to add a plain text item */
1015
+ protected addTextMessage(text: string, source: 'user' | 'assistant', data: DataType): void;
881
1016
  /** Process incoming message from the AI. Can be used to respond to encoded actions in the text response. */
882
- onBeforeIncomingMessage(message: MessageFormat): void;
1017
+ onBeforeIncomingMessage(message: DataType): void;
883
1018
  /** Reset the conversation */
884
1019
  resetConversation(): void;
885
1020
  /** Trim message list */
886
1021
  trimMessages(): Promise<void>;
887
1022
  /** Register a tool. */
888
1023
  registerTool(tool: ChatBaseToolConfig): TokenWindowGroupItem<ChatBaseToolConfig>;
1024
+ /** Find a tool based on the AI-safe name */
1025
+ protected findToolBySafeName(toolSafeName: string): ChatBaseToolConfig | undefined;
1026
+ /** Execute the specified tool. Throws an error if the tool is undefined. */
1027
+ protected executeTool(tool: ChatBaseToolConfig | undefined, input: any): Promise<string>;
1028
+ }
1029
+
1030
+ /** Parses the response from `IntelliWeave.sendMessage()` or a collection of message items. */
1031
+ declare class IntelliWeaveMessageParser {
1032
+ /** New messages produced after sendMessage() was called */
1033
+ messages: TokenWindowGroupItemParams<unknown>[];
1034
+ /** Constructor */
1035
+ constructor(items: TokenWindowGroupItemParams<unknown>[]);
1036
+ /** Plain text output from the AI */
1037
+ text(): string;
1038
+ /** Total token usage */
1039
+ tokenUsage(): {
1040
+ cachedInputTokens: number;
1041
+ inputTokens: number;
1042
+ outputTokens: number;
1043
+ totalTokens: number;
1044
+ };
1045
+ /** Component sections for display */
1046
+ sections(): TokenWindowGroupItemParams<unknown>['sections'];
1047
+ /** List all tool calls that took place */
1048
+ toolCalls(): TokenWindowGroupItemSection[];
1049
+ /** Find the response for a tool call */
1050
+ toolResult(toolCallInstanceID: string): TokenWindowGroupItemSection | null;
1051
+ }
1052
+
1053
+ /** Handles subagents. This allows your Persona to use other Personas as tools. */
1054
+ declare class SubAgents {
1055
+ /** Reference to the main IntelliWeave instance */
1056
+ ai: IntelliWeave;
1057
+ /** Constructor */
1058
+ constructor(ai: IntelliWeave);
1059
+ /** Subagents */
1060
+ subagents: SubAgentConfig[];
1061
+ /** Cached subagents */
1062
+ cachedSubagents: Record<string, IntelliWeave>;
1063
+ /** Register a sub-agent */
1064
+ register(config: SubAgentConfig): void;
1065
+ /** Unregister subagent */
1066
+ remove(id: string): void;
1067
+ /** Run the subagent */
1068
+ runQuery(config: SubAgentConfig, query: string): Promise<string>;
1069
+ }
1070
+ /** Sub-agent config */
1071
+ interface SubAgentConfig {
1072
+ /** ID of the sub-agent */
1073
+ id: string;
1074
+ /** API key for the persona. If not specified, uses the same api key as the main agent. */
1075
+ apiKey?: string;
1076
+ /** Name of the sub-agent */
1077
+ name?: string;
1078
+ /** Instructions for the main agent to use this sub agent */
1079
+ usageInstructions?: string;
1080
+ /** If true, will remove all Persona knowledge entries */
1081
+ clearExistingKnowledge?: boolean;
1082
+ /** Extra knowledge base sources for the sub-agent */
1083
+ knowledge?: KnowledgeFetcher;
1084
+ /** Optional extra configuration for the subagent instance */
1085
+ config?: Partial<WebWeaverGPTConfig>;
1086
+ /** Called when the subagent is loaded */
1087
+ onAgentLoaded?: (agent: IntelliWeave) => Promise<void> | void;
889
1088
  }
890
1089
 
891
1090
  /** Built-in action flags for the persona */
@@ -925,6 +1124,8 @@ interface WebWeaverGPTConfig {
925
1124
  textColor?: string;
926
1125
  /** Display mode: 'closed' (default - starts minimized) or 'open' (always open) */
927
1126
  displayMode?: 'closed' | 'open';
1127
+ /** Layout preset: 'widget' (default) or 'fullscreen' */
1128
+ layout?: 'widget' | 'fullscreen';
928
1129
  /** Positioning mode: 'fixed' (default - floats on page) or 'container' (fills parent container) */
929
1130
  positioningMode?: 'fixed' | 'container';
930
1131
  /** Horizontal position: 'left' or 'right' (default: 'right') - only used when positioningMode is 'fixed' */
@@ -935,6 +1136,8 @@ interface WebWeaverGPTConfig {
935
1136
  offsetX?: number;
936
1137
  /** Vertical offset from edge in pixels (default: 20) - only used when positioningMode is 'fixed' */
937
1138
  offsetY?: number;
1139
+ /** Identifier of an external app or service which manages this persona, if any. (eg. "chatterly") */
1140
+ managedBy?: string;
938
1141
  /** Voice information */
939
1142
  voice?: {
940
1143
  /** Provider ID */
@@ -959,6 +1162,10 @@ interface WebWeaverGPTConfig {
959
1162
  mcpServers?: MCPKnowledgeClient['config'][];
960
1163
  /** Built-in action flags that are currently enabled */
961
1164
  flags?: BuiltInActionFlags;
1165
+ /** Allow custom chat provider */
1166
+ onCreateProvider?: (config: ChatBaseConfig) => ChatBase;
1167
+ /** Subagents */
1168
+ subagents?: SubAgentConfig[];
962
1169
  }
963
1170
  /**
964
1171
  * IntelliWeave interface, loads a Persona from the hub and allows you to interact with it. This is the main entry point into the IntelliWeave
@@ -969,7 +1176,7 @@ interface WebWeaverGPTConfig {
969
1176
  * - 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.
970
1177
  * - event `webweaver_error` - Fired when an error occurs during loading. This is a global event that is fired on the window object.
971
1178
  * - event `input` - Fired when the user sends a message to the AI.
972
- * - 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.
1179
+ * - 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.
973
1180
  * - event `toolstart` - Fired when the AI starts performing an action.
974
1181
  * - event `tool` - Fired when the AI finishes performing an action.
975
1182
  */
@@ -978,14 +1185,16 @@ declare class IntelliWeave extends EventTarget {
978
1185
  static version: string;
979
1186
  /** Built-in actions version - increment this when adding new actions */
980
1187
  static builtInActionsVersion: string;
981
- /** Callback when a message from the AI is returned. If isChunk is true, it may be incomplete and be called again with more updates. */
982
- onAIMessage?: (text: string, isChunk: boolean) => void;
1188
+ /** Callback when a message from the AI is returned. If isPartial is true, it may be incomplete and be called again with more updates. */
1189
+ onAIMessage?: (messages: TokenWindowGroupItemParams<unknown>[], isPartial: boolean) => void;
983
1190
  /** Callback when the AI starts performing an action */
984
1191
  onAIToolStart?: ChatBaseConfig['onAIToolStart'];
985
1192
  /** Current conversation ID */
986
1193
  conversationID: string;
987
1194
  /** Knowledge database interface */
988
1195
  knowledgeBase: KnowledgeBase;
1196
+ /** Subagent interface */
1197
+ subAgents: SubAgents;
989
1198
  /** Last KB search that was performed */
990
1199
  private _lastKBsearch;
991
1200
  /** If set, the next time a request is made this is the KB result items that will be used, once-off. */
@@ -1029,7 +1238,7 @@ declare class IntelliWeave extends EventTarget {
1029
1238
  /** URL of the IntelliWeave Hub API */
1030
1239
  hubAPI: string;
1031
1240
  /** Set model and load data from an API key */
1032
- load(apiKey: string): Promise<WebWeaverGPTConfig>;
1241
+ load(apiKey: string, config?: Partial<WebWeaverGPTConfig>): Promise<IntelliWeave>;
1033
1242
  /** Set the current model */
1034
1243
  setModel(id: string): void;
1035
1244
  private _lastSystemMsg;
@@ -1037,18 +1246,19 @@ declare class IntelliWeave extends EventTarget {
1037
1246
  getContextPrefix(): Promise<string>;
1038
1247
  /** Get system message to send to the AI */
1039
1248
  onBeforeMessageProcessing(): Promise<void>;
1040
- /** @private Process incoming message from the AI. Can be used to respond to encoded actions in the text response. */
1041
- processIncomingMessage(message: string, isChunk?: boolean): void;
1249
+ /** @private Process incoming message(s) from the AI. Can be used to respond to encoded actions in the text response. */
1250
+ processIncomingMessage(messages: TokenWindowGroupItemParams<unknown>[], isPartial?: boolean): void;
1042
1251
  /** True if currently processing a message */
1043
1252
  isProcessing: boolean;
1044
- /** @private Last tracked token count for calculating per-message token usage */
1045
- private _lastTrackedTokens;
1046
1253
  /** Send a message, and get the response */
1047
- sendMessage(message: string): Promise<string | null>;
1254
+ sendMessage(message: string, onPartial?: (items: TokenWindowGroupItemParams<unknown>[]) => void): Promise<IntelliWeaveMessageParser>;
1048
1255
  /** @private Called when the AI wants to run a KB action */
1049
1256
  toolRunKBAction(kb: KnowledgeBaseItem, input: any): Promise<any>;
1050
- /** Submit an analytics event asynchronously */
1257
+ /** Submit an analytics event asynchronously. These events are for use in the Conversation Analytics code. For anonymous statistic analysis, use track() instead. */
1258
+ private activeAnalyticsPromises;
1051
1259
  submitAnalyticsEvent(data: any): void;
1260
+ /** Wait for all analytics events to finish */
1261
+ waitForAnalytics(): Promise<void>;
1052
1262
  /** Reset the conversation */
1053
1263
  resetConversation(): void;
1054
1264
  /** Insert a message as if the assistant has written it */
@@ -1057,12 +1267,14 @@ declare class IntelliWeave extends EventTarget {
1057
1267
  exportState(): {
1058
1268
  type: string;
1059
1269
  conversationID: string;
1060
- messages: any[] | undefined;
1270
+ messages: TokenWindowGroupItem<any>[] | undefined;
1061
1271
  };
1062
1272
  /** Import conversation state from JSON */
1063
1273
  importState(state: any): void;
1064
1274
  /** Clone this instance without any message history */
1065
1275
  clone(): IntelliWeave;
1276
+ /** Get all messages in the conversation history */
1277
+ get messages(): TokenWindowGroupItem<any>[];
1066
1278
  }
1067
1279
 
1068
1280
  /**
@@ -1147,11 +1359,18 @@ declare class WebWeaverEmbed extends BaseComponent {
1147
1359
  private _lastBackground?;
1148
1360
  private _lastTextColor?;
1149
1361
  private _lastDisplayMode?;
1362
+ private _lastLayout?;
1363
+ private _lastPersonaName?;
1364
+ private _lastHeaderLogo?;
1150
1365
  private _lastPositioningMode?;
1151
1366
  private _lastPositionX?;
1152
1367
  private _lastPositionY?;
1153
1368
  private _lastOffsetX?;
1154
1369
  private _lastOffsetY?;
1370
+ /** Apply persona-based color variants as CSS variables */
1371
+ private applyPersonaColorVariants;
1372
+ /** Parse a color string to RGB (supports hex and rgb/rgba) */
1373
+ private parseColorToRGB;
1155
1374
  /** Apply UI styles from config and attributes, prioritizing attributes */
1156
1375
  private applyConfigStylesAndAttributes;
1157
1376
  /** Called on update */
@@ -1175,13 +1394,19 @@ declare class WebWeaverEmbed extends BaseComponent {
1175
1394
  /** Process input text from the user */
1176
1395
  processInput(inputText: string): Promise<void>;
1177
1396
  /** Called when the AI responds with some text */
1178
- onAIMessage(msg: string): Promise<void>;
1179
- /** Called when the AI starts running a tool */
1180
- onAIToolStart(toolName: string, args: any): void;
1397
+ onAIMessage(messages: TokenWindowGroupItemParams<unknown>[], isPartial: boolean): Promise<void>;
1398
+ /** Updates a text element */
1399
+ updateTextElement(elementID: string, text: string): void;
1400
+ /** Updates an info block element */
1401
+ updateInfoElement(elementID: string, text: string, iconType: string): void;
1181
1402
  /** Called when a suggestion button is clicked */
1182
1403
  onSuggestionClick(e: Event, suggestion: string): void;
1183
1404
  /** Called when an LLM model is selected */
1184
1405
  onLLMModelSelect(e: CustomEvent): void;
1406
+ /** Called when the content area is scrolled */
1407
+ onContentScroll(e: Event): void;
1408
+ /** Displays whitelabeled branding for known apps */
1409
+ private updateBrandingFor;
1185
1410
  }
1186
1411
 
1187
1412
  /**