@intelliweave/embedded 1.8.60 → 1.8.62

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
@@ -568,8 +840,8 @@ declare class AILogic {
568
840
  /**
569
841
  * Generate a Markdown document based on the data from the user.
570
842
  *
571
- * @param query The query to generate the document from.
572
843
  * @param config Instruct config.
844
+ * @returns A markdown document.
573
845
  */
574
846
  generateMarkdown(config: Omit<IntelliWeaveInstructConfig, 'instruction'>): Promise<string>;
575
847
  /**
@@ -632,6 +904,8 @@ interface WebWeaverGPTConfig {
632
904
  };
633
905
  /** Knowledge base sources */
634
906
  knowledge?: KnowledgeBaseSource[];
907
+ /** MCP servers */
908
+ mcpServers?: MCPKnowledgeClient['config'][];
635
909
  }
636
910
  /**
637
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