@intelliweave/embedded 1.7.59 → 1.8.61

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,4 +1,5 @@
1
1
  import { Optional } from 'utility-types';
2
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
3
 
3
4
  /**
4
5
  * This class helps organize groups of tokenized text along with removing items when the window is full.
@@ -78,6 +79,173 @@ interface TokenWindowGroupItem<CustomDataType> {
78
79
  disabled?: boolean;
79
80
  }
80
81
 
82
+ // ==================================================================================================
83
+ // JSON Schema Draft 07
84
+ // ==================================================================================================
85
+ // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
86
+ // --------------------------------------------------------------------------------------------------
87
+
88
+ /**
89
+ * Primitive type
90
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
91
+ */
92
+ type JSONSchema7TypeName =
93
+ | "string" //
94
+ | "number"
95
+ | "integer"
96
+ | "boolean"
97
+ | "object"
98
+ | "array"
99
+ | "null";
100
+
101
+ /**
102
+ * Primitive type
103
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
104
+ */
105
+ type JSONSchema7Type =
106
+ | string //
107
+ | number
108
+ | boolean
109
+ | JSONSchema7Object
110
+ | JSONSchema7Array
111
+ | null;
112
+
113
+ // Workaround for infinite type recursion
114
+ interface JSONSchema7Object {
115
+ [key: string]: JSONSchema7Type;
116
+ }
117
+
118
+ // Workaround for infinite type recursion
119
+ // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
120
+ interface JSONSchema7Array extends Array<JSONSchema7Type> {}
121
+
122
+ /**
123
+ * Meta schema
124
+ *
125
+ * Recommended values:
126
+ * - 'http://json-schema.org/schema#'
127
+ * - 'http://json-schema.org/hyper-schema#'
128
+ * - 'http://json-schema.org/draft-07/schema#'
129
+ * - 'http://json-schema.org/draft-07/hyper-schema#'
130
+ *
131
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
132
+ */
133
+ type JSONSchema7Version = string;
134
+
135
+ /**
136
+ * JSON Schema v7
137
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
138
+ */
139
+ type JSONSchema7Definition = JSONSchema7 | boolean;
140
+ interface JSONSchema7 {
141
+ $id?: string | undefined;
142
+ $ref?: string | undefined;
143
+ $schema?: JSONSchema7Version | undefined;
144
+ $comment?: string | undefined;
145
+
146
+ /**
147
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
148
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
149
+ */
150
+ $defs?: {
151
+ [key: string]: JSONSchema7Definition;
152
+ } | undefined;
153
+
154
+ /**
155
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
156
+ */
157
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
158
+ enum?: JSONSchema7Type[] | undefined;
159
+ const?: JSONSchema7Type | undefined;
160
+
161
+ /**
162
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
163
+ */
164
+ multipleOf?: number | undefined;
165
+ maximum?: number | undefined;
166
+ exclusiveMaximum?: number | undefined;
167
+ minimum?: number | undefined;
168
+ exclusiveMinimum?: number | undefined;
169
+
170
+ /**
171
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
172
+ */
173
+ maxLength?: number | undefined;
174
+ minLength?: number | undefined;
175
+ pattern?: string | undefined;
176
+
177
+ /**
178
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
179
+ */
180
+ items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
181
+ additionalItems?: JSONSchema7Definition | undefined;
182
+ maxItems?: number | undefined;
183
+ minItems?: number | undefined;
184
+ uniqueItems?: boolean | undefined;
185
+ contains?: JSONSchema7Definition | undefined;
186
+
187
+ /**
188
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
189
+ */
190
+ maxProperties?: number | undefined;
191
+ minProperties?: number | undefined;
192
+ required?: string[] | undefined;
193
+ properties?: {
194
+ [key: string]: JSONSchema7Definition;
195
+ } | undefined;
196
+ patternProperties?: {
197
+ [key: string]: JSONSchema7Definition;
198
+ } | undefined;
199
+ additionalProperties?: JSONSchema7Definition | undefined;
200
+ dependencies?: {
201
+ [key: string]: JSONSchema7Definition | string[];
202
+ } | undefined;
203
+ propertyNames?: JSONSchema7Definition | undefined;
204
+
205
+ /**
206
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
207
+ */
208
+ if?: JSONSchema7Definition | undefined;
209
+ then?: JSONSchema7Definition | undefined;
210
+ else?: JSONSchema7Definition | undefined;
211
+
212
+ /**
213
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
214
+ */
215
+ allOf?: JSONSchema7Definition[] | undefined;
216
+ anyOf?: JSONSchema7Definition[] | undefined;
217
+ oneOf?: JSONSchema7Definition[] | undefined;
218
+ not?: JSONSchema7Definition | undefined;
219
+
220
+ /**
221
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
222
+ */
223
+ format?: string | undefined;
224
+
225
+ /**
226
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
227
+ */
228
+ contentMediaType?: string | undefined;
229
+ contentEncoding?: string | undefined;
230
+
231
+ /**
232
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
233
+ */
234
+ definitions?: {
235
+ [key: string]: JSONSchema7Definition;
236
+ } | undefined;
237
+
238
+ /**
239
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
240
+ */
241
+ title?: string | undefined;
242
+ description?: string | undefined;
243
+ default?: JSONSchema7Type | undefined;
244
+ readOnly?: boolean | undefined;
245
+ writeOnly?: boolean | undefined;
246
+ examples?: JSONSchema7Type | undefined;
247
+ }
248
+
81
249
  /** ChatGPT config options */
82
250
  interface ChatGPTConfig {
83
251
  /** API key */
@@ -110,11 +278,7 @@ interface ChatGPTToolConfig {
110
278
  /** Description of the tool */
111
279
  description: string;
112
280
  /** Parameters for the tool */
113
- params: {
114
- name: string;
115
- type: string;
116
- description: string;
117
- }[];
281
+ params: JSONSchema7;
118
282
  /** Callback function to process the tool */
119
283
  callback: (params: any) => any;
120
284
  /** If true, this tool call will be removed from the message history after it is executed. */
@@ -188,6 +352,102 @@ declare class ChatGPT {
188
352
  resetConversation(): void;
189
353
  }
190
354
 
355
+ /**
356
+ * Allows an MCP server to be used as a knowledge source for IntelliWeave.
357
+ */
358
+ declare class MCPKnowledgeClient {
359
+ /** MCP client */
360
+ client?: Client;
361
+ /** All tools discovered on the MCP server. Only available after connect() has completed. */
362
+ tools: Awaited<ReturnType<Client['listTools']>>['tools'];
363
+ /** All toold discovered, mapped to IntelliWeave knowledge base actions */
364
+ iwActions: KnowledgeBaseItem[];
365
+ /** Statistics */
366
+ stats: {
367
+ toolsCalled: number;
368
+ };
369
+ /** Configuration */
370
+ config: {
371
+ /** Source ID */
372
+ id?: string;
373
+ /** URL to the MCP server endpoint */
374
+ baseURL?: string;
375
+ /** Custom connection function. If specified, baseURL is optional. */
376
+ connect?: () => Promise<Client>;
377
+ /**
378
+ * The name of the tool which provides knowledge searching. If specified, the search() will exclude this function and instead
379
+ * call it and show returned results. If not specified, the search() will just return all tools.
380
+ */
381
+ searchToolName?: string;
382
+ /** Keep search function available for the AI to use. */
383
+ searchToolVisible?: boolean;
384
+ };
385
+ /** Constructor */
386
+ constructor(config: MCPKnowledgeClient['config']);
387
+ /** In-progress connection attempt */
388
+ private connectionPromise?;
389
+ /** Connect to the client */
390
+ connect(): Promise<Client<{
391
+ method: string;
392
+ params?: {
393
+ [x: string]: unknown;
394
+ _meta?: {
395
+ [x: string]: unknown;
396
+ progressToken?: string | number | undefined;
397
+ } | undefined;
398
+ } | undefined;
399
+ }, {
400
+ method: string;
401
+ params?: {
402
+ [x: string]: unknown;
403
+ _meta?: {
404
+ [x: string]: unknown;
405
+ } | undefined;
406
+ } | undefined;
407
+ }, {
408
+ [x: string]: unknown;
409
+ _meta?: {
410
+ [x: string]: unknown;
411
+ } | undefined;
412
+ }>>;
413
+ connectInternal(): Promise<Client<{
414
+ method: string;
415
+ params?: {
416
+ [x: string]: unknown;
417
+ _meta?: {
418
+ [x: string]: unknown;
419
+ progressToken?: string | number | undefined;
420
+ } | undefined;
421
+ } | undefined;
422
+ }, {
423
+ method: string;
424
+ params?: {
425
+ [x: string]: unknown;
426
+ _meta?: {
427
+ [x: string]: unknown;
428
+ } | undefined;
429
+ } | undefined;
430
+ }, {
431
+ [x: string]: unknown;
432
+ _meta?: {
433
+ [x: string]: unknown;
434
+ } | undefined;
435
+ }>>;
436
+ /** Disconnect from server */
437
+ disconnect(): Promise<void>;
438
+ /** Fetch list of tools from the MCP server */
439
+ private fetchTools;
440
+ /** Cache last search result */
441
+ lastSearchQuery: string;
442
+ lastSearchResults: KnowledgeBaseItem[];
443
+ /** Perform a search query */
444
+ search(query: string): Promise<KnowledgeBaseItem[]>;
445
+ /** Perform search using the configured search function */
446
+ private performSearchCall;
447
+ /** Perform tool call. */
448
+ private performToolCall;
449
+ }
450
+
191
451
  /**
192
452
  * Register knowledge base sources and perform searches.
193
453
  */
@@ -227,7 +487,11 @@ declare class KnowledgeBase {
227
487
  registerSourceFromURL(url: string, id?: string): void;
228
488
  /** Clone this instance */
229
489
  clone(): KnowledgeBase;
490
+ /** Registers an MCP server as a knowledge base source */
491
+ registerMCPSource(config: MCPKnowledgeClient['config']): MCPKnowledgeClient;
230
492
  }
493
+ /** Knowledge fetcher */
494
+ type KnowledgeFetcher = (query: string) => (KnowledgeBaseItem[] | Promise<KnowledgeBaseItem[]>);
231
495
  /** Knowledge base source */
232
496
  interface KnowledgeBaseSource {
233
497
  /** Source ID */
@@ -241,11 +505,15 @@ interface KnowledgeBaseSource {
241
505
  /** If true, this source will not be queried. */
242
506
  disabled?: boolean;
243
507
  /** Source query function. This function should return a list of knowledge base entries that optionally match the query. */
244
- query?: (query: string) => (KnowledgeBaseItem[] | Promise<KnowledgeBaseItem[]>);
508
+ query?: KnowledgeFetcher;
245
509
  /** URL query for remote sources */
246
510
  url?: string;
247
511
  /** Pre-packaged knowledge base entries */
248
512
  entries?: KnowledgeBaseItem[];
513
+ /** Remote knowledge server type (default is 'iw') */
514
+ backendType?: 'mcp' | 'iw';
515
+ /** If using MCP, this is the name of the tool to use to search for knowledge */
516
+ mcpSearchToolName?: string;
249
517
  }
250
518
  /** Knowledge base item */
251
519
  interface KnowledgeBaseItem {
@@ -265,12 +533,8 @@ interface KnowledgeBaseItem {
265
533
  isContext?: boolean;
266
534
  /** If true, this item will not be visible to the AI. */
267
535
  disabled?: boolean;
268
- /** List of parameters for an action function. */
269
- parameters?: ({
270
- name: string;
271
- type: 'string' | 'boolean' | 'number';
272
- description: string;
273
- })[];
536
+ /** List of parameters for an action function. Can either use IW's format, or a JSON Schema object. */
537
+ parameters?: KnowledgeBaseActionParameterSchema;
274
538
  /**
275
539
  * Item action. The parameters are defined in `parameters`. The response is stringified and sent to the AI.
276
540
  * You can return any JSON-serializable object. You can also return a string describing to the AI the action
@@ -280,6 +544,14 @@ interface KnowledgeBaseItem {
280
544
  /** 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. */
281
545
  removeFromMessageHistory?: boolean;
282
546
  }
547
+ /** Parameter definition used by IntelliWeave */
548
+ interface IntelliWeaveParameterDefinition {
549
+ name: string;
550
+ type: 'string' | 'boolean' | 'number';
551
+ description: string;
552
+ }
553
+ /** Tool call input schema. Can either use IW's format, or a JSON Schema object */
554
+ type KnowledgeBaseActionParameterSchema = JSONSchema7 | IntelliWeaveParameterDefinition[];
283
555
 
284
556
  /**
285
557
  * Speech output
@@ -297,6 +569,14 @@ declare class WebWeaverSpeechOutput extends EventTarget {
297
569
  /** Current player vars */
298
570
  private currentPlayerVolume?;
299
571
  private currentPlayer?;
572
+ /** The audio analyser node */
573
+ private analyserNode?;
574
+ /** The audio analyser buffer */
575
+ private analyserBuffer?;
576
+ /** @private Maximum volume heard this session */
577
+ private maxVolumeHeard;
578
+ /** Get current (realtime) audio output volume level, from 0 to 1 */
579
+ get volumeLevel(): number;
300
580
  /** Speak the text */
301
581
  speak(text: string): Promise<void>;
302
582
  private _speakWithLock;
@@ -474,9 +754,9 @@ declare class WebWeaverSpeechRecognition extends EventTarget {
474
754
  /** True if recognition is running */
475
755
  isRunning: boolean;
476
756
  /** The audio analyser node */
477
- analyserNode?: AnalyserNode;
757
+ private analyserNode?;
478
758
  /** The audio analyser buffer */
479
- analyserBuffer?: Float32Array;
759
+ private analyserBuffer?;
480
760
  /** The microphone stream */
481
761
  micStream?: MediaStream;
482
762
  /** Returns true if speech recognition is supported by this persona and browser */
@@ -535,49 +815,53 @@ declare class AILogic {
535
815
  /** Constructor */
536
816
  constructor(ai: IntelliWeave);
537
817
  /** Ask the AI a yes/no question associated with the specified data. Data must be JSON-serializable, or a string of any kind of data. */
538
- boolean(question: string, data: any): Promise<boolean>;
818
+ boolean(config: IntelliWeaveInstructConfig): Promise<boolean>;
819
+ /** Ask the AI to select a choice from a list of options. */
820
+ choose(config: IntelliWeaveInstructConfig & {
821
+ /** List of choices the AI can pick from. */
822
+ options: string[];
823
+ }): Promise<string | undefined>;
539
824
  /**
540
- Ask the AI to select a choice from a list of options. The AI will return the selected choice.
541
- @param question The question to ask the AI.
542
- @param data The data to provide to the AI. This can be a string or a JSON-serializable object.
543
- @param options The list of options to choose from.
825
+ * Ask the AI to extract data from input data. The AI will return the extracted data. Possibly an array of multiple extractions.
544
826
  */
545
- choose(question: string, data: any, options: string[]): Promise<string | undefined>;
827
+ extract<T = any>(config: IntelliWeaveInstructConfig & {
828
+ /** Allow multiple items to be returned. If true, returns an array instead of an object. */
829
+ allowMultiple?: boolean;
830
+ /** Fields to extract in each object. */
831
+ extractions: {
832
+ /** Field name */
833
+ name: string;
834
+ /** Field data type */
835
+ type: 'string' | 'number' | 'boolean' | 'date' | 'email' | 'phone' | 'address';
836
+ /** Describe to the AI what data to put in this field. */
837
+ description?: string;
838
+ }[];
839
+ }): Promise<T[]>;
546
840
  /**
547
- * Ask the AI to extract data from a text. The AI will return the extracted data. Possibly an array of multiple extractions.
548
- * Example: extract(myData, true, [
549
- * { name: "id", type: "string", description: "The user's ID number." },
550
- * { name: "firstName", type: "string", description: "The user's first name" },
551
- * ])
552
- * @param question The question to ask the AI.
553
- * @param data The data to provide to the AI. This can be a string or a JSON-serializable object.
554
- * @param allowMultiple Whether to allow multiple extractions or not.
555
- * @param extractions The list of extractions to perform. Each extraction is an object with the following properties:
556
- * - name: The name of the extraction. This will be the key in the returned object.
557
- * - type: The type of the extraction. This can be "string", "number", "boolean", "date", "email", "url", "phone", "address", "name", "organization", "person", "location", "time", "duration", "money", "percentage", "quantity", "custom".
558
- * - description: A description of the extraction. This is optional.
559
- */
560
- extract(question: string, data: any, allowMultiple: boolean, extractions: {
561
- name: string;
562
- type: string;
563
- description?: string;
564
- }[]): Promise<any>;
565
- /**
566
- * Generate a Markdown document based on the input query from the user.
841
+ * Generate a Markdown document based on the data from the user.
567
842
  *
568
- * @param query The query to generate the document from.
569
- * @param callback The callback that will be called when streaming the response. Each call will contain the full text that has been generated so far.
843
+ * @param config Instruct config.
844
+ * @returns A markdown document.
570
845
  */
571
- generateMarkdown(query: string, callback: (txt: string) => void): Promise<string | null>;
846
+ generateMarkdown(config: Omit<IntelliWeaveInstructConfig, 'instruction'>): Promise<string>;
572
847
  /**
573
848
  * Perform an instruction.
574
849
  *
575
- * @param instruction Describe the action to perform.
576
- * @param query The user query to pass to the AI.
577
- * @param callback The callback that will be called when streaming the response. Each call will contain the full text that has been generated so far.
850
+ * @param config Instruct config.
578
851
  * @returns The final response from the AI.
579
852
  */
580
- instruct(instruction: string, query: string, callback: (txt: string) => void): Promise<string | null>;
853
+ instruct(config: IntelliWeaveInstructConfig): Promise<string>;
854
+ }
855
+ /** Config for any instruct call */
856
+ interface IntelliWeaveInstructConfig {
857
+ /** Instruction */
858
+ instruction: string;
859
+ /** Input data or query to process */
860
+ data: any;
861
+ /** Whether to allow the AI to use the knowledge base or not. If false, the AI will not use the knowledge base. */
862
+ allowKB?: boolean;
863
+ /** Callback that will be called when streaming the response. Each call will contain the full text that has been generated so far. */
864
+ callback?: (txt: string) => void;
581
865
  }
582
866
 
583
867
  /** Persona config received from the hub */
@@ -620,6 +904,8 @@ interface WebWeaverGPTConfig {
620
904
  };
621
905
  /** Knowledge base sources */
622
906
  knowledge?: KnowledgeBaseSource[];
907
+ /** MCP servers */
908
+ mcpServers?: MCPKnowledgeClient['config'][];
623
909
  }
624
910
  /**
625
911
  * IntelliWeave interface, loads a Persona from the hub and allows you to interact with it. This is the main entry point into the IntelliWeave