@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,6 +1,7 @@
1
1
  import * as onnxruntime_web from 'onnxruntime-web';
2
2
  import { InferenceSession, Tensor } from 'onnxruntime-web';
3
3
  import { Optional } from 'utility-types';
4
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
4
5
 
5
6
  /**
6
7
  * This is a utility class for dealing with the ONNX runtime and model loading.
@@ -463,6 +464,173 @@ interface TokenWindowGroupItem<CustomDataType> {
463
464
  disabled?: boolean;
464
465
  }
465
466
 
467
+ // ==================================================================================================
468
+ // JSON Schema Draft 07
469
+ // ==================================================================================================
470
+ // https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
471
+ // --------------------------------------------------------------------------------------------------
472
+
473
+ /**
474
+ * Primitive type
475
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
476
+ */
477
+ type JSONSchema7TypeName =
478
+ | "string" //
479
+ | "number"
480
+ | "integer"
481
+ | "boolean"
482
+ | "object"
483
+ | "array"
484
+ | "null";
485
+
486
+ /**
487
+ * Primitive type
488
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
489
+ */
490
+ type JSONSchema7Type =
491
+ | string //
492
+ | number
493
+ | boolean
494
+ | JSONSchema7Object
495
+ | JSONSchema7Array
496
+ | null;
497
+
498
+ // Workaround for infinite type recursion
499
+ interface JSONSchema7Object {
500
+ [key: string]: JSONSchema7Type;
501
+ }
502
+
503
+ // Workaround for infinite type recursion
504
+ // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
505
+ interface JSONSchema7Array extends Array<JSONSchema7Type> {}
506
+
507
+ /**
508
+ * Meta schema
509
+ *
510
+ * Recommended values:
511
+ * - 'http://json-schema.org/schema#'
512
+ * - 'http://json-schema.org/hyper-schema#'
513
+ * - 'http://json-schema.org/draft-07/schema#'
514
+ * - 'http://json-schema.org/draft-07/hyper-schema#'
515
+ *
516
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
517
+ */
518
+ type JSONSchema7Version = string;
519
+
520
+ /**
521
+ * JSON Schema v7
522
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
523
+ */
524
+ type JSONSchema7Definition = JSONSchema7 | boolean;
525
+ interface JSONSchema7 {
526
+ $id?: string | undefined;
527
+ $ref?: string | undefined;
528
+ $schema?: JSONSchema7Version | undefined;
529
+ $comment?: string | undefined;
530
+
531
+ /**
532
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
533
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
534
+ */
535
+ $defs?: {
536
+ [key: string]: JSONSchema7Definition;
537
+ } | undefined;
538
+
539
+ /**
540
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
541
+ */
542
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
543
+ enum?: JSONSchema7Type[] | undefined;
544
+ const?: JSONSchema7Type | undefined;
545
+
546
+ /**
547
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
548
+ */
549
+ multipleOf?: number | undefined;
550
+ maximum?: number | undefined;
551
+ exclusiveMaximum?: number | undefined;
552
+ minimum?: number | undefined;
553
+ exclusiveMinimum?: number | undefined;
554
+
555
+ /**
556
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
557
+ */
558
+ maxLength?: number | undefined;
559
+ minLength?: number | undefined;
560
+ pattern?: string | undefined;
561
+
562
+ /**
563
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
564
+ */
565
+ items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
566
+ additionalItems?: JSONSchema7Definition | undefined;
567
+ maxItems?: number | undefined;
568
+ minItems?: number | undefined;
569
+ uniqueItems?: boolean | undefined;
570
+ contains?: JSONSchema7Definition | undefined;
571
+
572
+ /**
573
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
574
+ */
575
+ maxProperties?: number | undefined;
576
+ minProperties?: number | undefined;
577
+ required?: string[] | undefined;
578
+ properties?: {
579
+ [key: string]: JSONSchema7Definition;
580
+ } | undefined;
581
+ patternProperties?: {
582
+ [key: string]: JSONSchema7Definition;
583
+ } | undefined;
584
+ additionalProperties?: JSONSchema7Definition | undefined;
585
+ dependencies?: {
586
+ [key: string]: JSONSchema7Definition | string[];
587
+ } | undefined;
588
+ propertyNames?: JSONSchema7Definition | undefined;
589
+
590
+ /**
591
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
592
+ */
593
+ if?: JSONSchema7Definition | undefined;
594
+ then?: JSONSchema7Definition | undefined;
595
+ else?: JSONSchema7Definition | undefined;
596
+
597
+ /**
598
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
599
+ */
600
+ allOf?: JSONSchema7Definition[] | undefined;
601
+ anyOf?: JSONSchema7Definition[] | undefined;
602
+ oneOf?: JSONSchema7Definition[] | undefined;
603
+ not?: JSONSchema7Definition | undefined;
604
+
605
+ /**
606
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
607
+ */
608
+ format?: string | undefined;
609
+
610
+ /**
611
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
612
+ */
613
+ contentMediaType?: string | undefined;
614
+ contentEncoding?: string | undefined;
615
+
616
+ /**
617
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
618
+ */
619
+ definitions?: {
620
+ [key: string]: JSONSchema7Definition;
621
+ } | undefined;
622
+
623
+ /**
624
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
625
+ */
626
+ title?: string | undefined;
627
+ description?: string | undefined;
628
+ default?: JSONSchema7Type | undefined;
629
+ readOnly?: boolean | undefined;
630
+ writeOnly?: boolean | undefined;
631
+ examples?: JSONSchema7Type | undefined;
632
+ }
633
+
466
634
  /** ChatGPT config options */
467
635
  interface ChatGPTConfig {
468
636
  /** API key */
@@ -495,11 +663,7 @@ interface ChatGPTToolConfig {
495
663
  /** Description of the tool */
496
664
  description: string;
497
665
  /** Parameters for the tool */
498
- params: {
499
- name: string;
500
- type: string;
501
- description: string;
502
- }[];
666
+ params: JSONSchema7;
503
667
  /** Callback function to process the tool */
504
668
  callback: (params: any) => any;
505
669
  /** If true, this tool call will be removed from the message history after it is executed. */
@@ -589,6 +753,14 @@ declare class WebWeaverSpeechOutput extends EventTarget {
589
753
  /** Current player vars */
590
754
  private currentPlayerVolume?;
591
755
  private currentPlayer?;
756
+ /** The audio analyser node */
757
+ private analyserNode?;
758
+ /** The audio analyser buffer */
759
+ private analyserBuffer?;
760
+ /** @private Maximum volume heard this session */
761
+ private maxVolumeHeard;
762
+ /** Get current (realtime) audio output volume level, from 0 to 1 */
763
+ get volumeLevel(): number;
592
764
  /** Speak the text */
593
765
  speak(text: string): Promise<void>;
594
766
  private _speakWithLock;
@@ -766,9 +938,9 @@ declare class WebWeaverSpeechRecognition extends EventTarget {
766
938
  /** True if recognition is running */
767
939
  isRunning: boolean;
768
940
  /** The audio analyser node */
769
- analyserNode?: AnalyserNode;
941
+ private analyserNode?;
770
942
  /** The audio analyser buffer */
771
- analyserBuffer?: Float32Array;
943
+ private analyserBuffer?;
772
944
  /** The microphone stream */
773
945
  micStream?: MediaStream;
774
946
  /** Returns true if speech recognition is supported by this persona and browser */
@@ -827,49 +999,149 @@ declare class AILogic {
827
999
  /** Constructor */
828
1000
  constructor(ai: IntelliWeave);
829
1001
  /** 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. */
830
- boolean(question: string, data: any): Promise<boolean>;
1002
+ boolean(config: IntelliWeaveInstructConfig): Promise<boolean>;
1003
+ /** Ask the AI to select a choice from a list of options. */
1004
+ choose(config: IntelliWeaveInstructConfig & {
1005
+ /** List of choices the AI can pick from. */
1006
+ options: string[];
1007
+ }): Promise<string | undefined>;
831
1008
  /**
832
- Ask the AI to select a choice from a list of options. The AI will return the selected choice.
833
- @param question The question to ask the AI.
834
- @param data The data to provide to the AI. This can be a string or a JSON-serializable object.
835
- @param options The list of options to choose from.
1009
+ * Ask the AI to extract data from input data. The AI will return the extracted data. Possibly an array of multiple extractions.
836
1010
  */
837
- choose(question: string, data: any, options: string[]): Promise<string | undefined>;
838
- /**
839
- * Ask the AI to extract data from a text. The AI will return the extracted data. Possibly an array of multiple extractions.
840
- * Example: extract(myData, true, [
841
- * { name: "id", type: "string", description: "The user's ID number." },
842
- * { name: "firstName", type: "string", description: "The user's first name" },
843
- * ])
844
- * @param question The question to ask the AI.
845
- * @param data The data to provide to the AI. This can be a string or a JSON-serializable object.
846
- * @param allowMultiple Whether to allow multiple extractions or not.
847
- * @param extractions The list of extractions to perform. Each extraction is an object with the following properties:
848
- * - name: The name of the extraction. This will be the key in the returned object.
849
- * - 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".
850
- * - description: A description of the extraction. This is optional.
851
- */
852
- extract(question: string, data: any, allowMultiple: boolean, extractions: {
853
- name: string;
854
- type: string;
855
- description?: string;
856
- }[]): Promise<any>;
1011
+ extract<T = any>(config: IntelliWeaveInstructConfig & {
1012
+ /** Allow multiple items to be returned. If true, returns an array instead of an object. */
1013
+ allowMultiple?: boolean;
1014
+ /** Fields to extract in each object. */
1015
+ extractions: {
1016
+ /** Field name */
1017
+ name: string;
1018
+ /** Field data type */
1019
+ type: 'string' | 'number' | 'boolean' | 'date' | 'email' | 'phone' | 'address';
1020
+ /** Describe to the AI what data to put in this field. */
1021
+ description?: string;
1022
+ }[];
1023
+ }): Promise<T[]>;
857
1024
  /**
858
- * Generate a Markdown document based on the input query from the user.
1025
+ * Generate a Markdown document based on the data from the user.
859
1026
  *
860
- * @param query The query to generate the document from.
861
- * @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.
1027
+ * @param config Instruct config.
1028
+ * @returns A markdown document.
862
1029
  */
863
- generateMarkdown(query: string, callback: (txt: string) => void): Promise<string | null>;
1030
+ generateMarkdown(config: Omit<IntelliWeaveInstructConfig, 'instruction'>): Promise<string>;
864
1031
  /**
865
1032
  * Perform an instruction.
866
1033
  *
867
- * @param instruction Describe the action to perform.
868
- * @param query The user query to pass to the AI.
869
- * @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.
1034
+ * @param config Instruct config.
870
1035
  * @returns The final response from the AI.
871
1036
  */
872
- instruct(instruction: string, query: string, callback: (txt: string) => void): Promise<string | null>;
1037
+ instruct(config: IntelliWeaveInstructConfig): Promise<string>;
1038
+ }
1039
+ /** Config for any instruct call */
1040
+ interface IntelliWeaveInstructConfig {
1041
+ /** Instruction */
1042
+ instruction: string;
1043
+ /** Input data or query to process */
1044
+ data: any;
1045
+ /** Whether to allow the AI to use the knowledge base or not. If false, the AI will not use the knowledge base. */
1046
+ allowKB?: boolean;
1047
+ /** Callback that will be called when streaming the response. Each call will contain the full text that has been generated so far. */
1048
+ callback?: (txt: string) => void;
1049
+ }
1050
+
1051
+ /**
1052
+ * Allows an MCP server to be used as a knowledge source for IntelliWeave.
1053
+ */
1054
+ declare class MCPKnowledgeClient {
1055
+ /** MCP client */
1056
+ client?: Client;
1057
+ /** All tools discovered on the MCP server. Only available after connect() has completed. */
1058
+ tools: Awaited<ReturnType<Client['listTools']>>['tools'];
1059
+ /** All toold discovered, mapped to IntelliWeave knowledge base actions */
1060
+ iwActions: KnowledgeBaseItem[];
1061
+ /** Statistics */
1062
+ stats: {
1063
+ toolsCalled: number;
1064
+ };
1065
+ /** Configuration */
1066
+ config: {
1067
+ /** Source ID */
1068
+ id?: string;
1069
+ /** URL to the MCP server endpoint */
1070
+ baseURL?: string;
1071
+ /** Custom connection function. If specified, baseURL is optional. */
1072
+ connect?: () => Promise<Client>;
1073
+ /**
1074
+ * The name of the tool which provides knowledge searching. If specified, the search() will exclude this function and instead
1075
+ * call it and show returned results. If not specified, the search() will just return all tools.
1076
+ */
1077
+ searchToolName?: string;
1078
+ /** Keep search function available for the AI to use. */
1079
+ searchToolVisible?: boolean;
1080
+ };
1081
+ /** Constructor */
1082
+ constructor(config: MCPKnowledgeClient['config']);
1083
+ /** In-progress connection attempt */
1084
+ private connectionPromise?;
1085
+ /** Connect to the client */
1086
+ connect(): Promise<Client<{
1087
+ method: string;
1088
+ params?: {
1089
+ [x: string]: unknown;
1090
+ _meta?: {
1091
+ [x: string]: unknown;
1092
+ progressToken?: string | number | undefined;
1093
+ } | undefined;
1094
+ } | undefined;
1095
+ }, {
1096
+ method: string;
1097
+ params?: {
1098
+ [x: string]: unknown;
1099
+ _meta?: {
1100
+ [x: string]: unknown;
1101
+ } | undefined;
1102
+ } | undefined;
1103
+ }, {
1104
+ [x: string]: unknown;
1105
+ _meta?: {
1106
+ [x: string]: unknown;
1107
+ } | undefined;
1108
+ }>>;
1109
+ connectInternal(): Promise<Client<{
1110
+ method: string;
1111
+ params?: {
1112
+ [x: string]: unknown;
1113
+ _meta?: {
1114
+ [x: string]: unknown;
1115
+ progressToken?: string | number | undefined;
1116
+ } | undefined;
1117
+ } | undefined;
1118
+ }, {
1119
+ method: string;
1120
+ params?: {
1121
+ [x: string]: unknown;
1122
+ _meta?: {
1123
+ [x: string]: unknown;
1124
+ } | undefined;
1125
+ } | undefined;
1126
+ }, {
1127
+ [x: string]: unknown;
1128
+ _meta?: {
1129
+ [x: string]: unknown;
1130
+ } | undefined;
1131
+ }>>;
1132
+ /** Disconnect from server */
1133
+ disconnect(): Promise<void>;
1134
+ /** Fetch list of tools from the MCP server */
1135
+ private fetchTools;
1136
+ /** Cache last search result */
1137
+ lastSearchQuery: string;
1138
+ lastSearchResults: KnowledgeBaseItem[];
1139
+ /** Perform a search query */
1140
+ search(query: string): Promise<KnowledgeBaseItem[]>;
1141
+ /** Perform search using the configured search function */
1142
+ private performSearchCall;
1143
+ /** Perform tool call. */
1144
+ private performToolCall;
873
1145
  }
874
1146
 
875
1147
  /** Persona config received from the hub */
@@ -912,6 +1184,8 @@ interface WebWeaverGPTConfig {
912
1184
  };
913
1185
  /** Knowledge base sources */
914
1186
  knowledge?: KnowledgeBaseSource[];
1187
+ /** MCP servers */
1188
+ mcpServers?: MCPKnowledgeClient['config'][];
915
1189
  }
916
1190
  /**
917
1191
  * IntelliWeave interface, loads a Persona from the hub and allows you to interact with it. This is the main entry point into the IntelliWeave
@@ -1046,7 +1320,11 @@ declare class KnowledgeBase {
1046
1320
  registerSourceFromURL(url: string, id?: string): void;
1047
1321
  /** Clone this instance */
1048
1322
  clone(): KnowledgeBase;
1323
+ /** Registers an MCP server as a knowledge base source */
1324
+ registerMCPSource(config: MCPKnowledgeClient['config']): MCPKnowledgeClient;
1049
1325
  }
1326
+ /** Knowledge fetcher */
1327
+ type KnowledgeFetcher = (query: string) => (KnowledgeBaseItem[] | Promise<KnowledgeBaseItem[]>);
1050
1328
  /** Knowledge base source */
1051
1329
  interface KnowledgeBaseSource {
1052
1330
  /** Source ID */
@@ -1060,11 +1338,15 @@ interface KnowledgeBaseSource {
1060
1338
  /** If true, this source will not be queried. */
1061
1339
  disabled?: boolean;
1062
1340
  /** Source query function. This function should return a list of knowledge base entries that optionally match the query. */
1063
- query?: (query: string) => (KnowledgeBaseItem[] | Promise<KnowledgeBaseItem[]>);
1341
+ query?: KnowledgeFetcher;
1064
1342
  /** URL query for remote sources */
1065
1343
  url?: string;
1066
1344
  /** Pre-packaged knowledge base entries */
1067
1345
  entries?: KnowledgeBaseItem[];
1346
+ /** Remote knowledge server type (default is 'iw') */
1347
+ backendType?: 'mcp' | 'iw';
1348
+ /** If using MCP, this is the name of the tool to use to search for knowledge */
1349
+ mcpSearchToolName?: string;
1068
1350
  }
1069
1351
  /** Knowledge base item */
1070
1352
  interface KnowledgeBaseItem {
@@ -1084,12 +1366,8 @@ interface KnowledgeBaseItem {
1084
1366
  isContext?: boolean;
1085
1367
  /** If true, this item will not be visible to the AI. */
1086
1368
  disabled?: boolean;
1087
- /** List of parameters for an action function. */
1088
- parameters?: ({
1089
- name: string;
1090
- type: 'string' | 'boolean' | 'number';
1091
- description: string;
1092
- })[];
1369
+ /** List of parameters for an action function. Can either use IW's format, or a JSON Schema object. */
1370
+ parameters?: KnowledgeBaseActionParameterSchema;
1093
1371
  /**
1094
1372
  * Item action. The parameters are defined in `parameters`. The response is stringified and sent to the AI.
1095
1373
  * You can return any JSON-serializable object. You can also return a string describing to the AI the action
@@ -1099,6 +1377,14 @@ interface KnowledgeBaseItem {
1099
1377
  /** 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. */
1100
1378
  removeFromMessageHistory?: boolean;
1101
1379
  }
1380
+ /** Parameter definition used by IntelliWeave */
1381
+ interface IntelliWeaveParameterDefinition {
1382
+ name: string;
1383
+ type: 'string' | 'boolean' | 'number';
1384
+ description: string;
1385
+ }
1386
+ /** Tool call input schema. Can either use IW's format, or a JSON Schema object */
1387
+ type KnowledgeBaseActionParameterSchema = JSONSchema7 | IntelliWeaveParameterDefinition[];
1102
1388
  /** Format for incoming KB webook. Sent from IntelliWeave to your endpoint. */
1103
1389
  interface KnowledgeBaseWebhookRequest {
1104
1390
  /** Type of the request. */
@@ -1284,6 +1570,8 @@ declare function intelliweaveConfig(): IntelliWeaveGlobalConfig;
1284
1570
  declare function sseEvents(stream: ReadableStream<Uint8Array>): AsyncGenerator<any, void, unknown>;
1285
1571
  /** Get or create a user ID for this device. */
1286
1572
  declare function getDefaultUserID(): string;
1573
+ /** Convert an IntelliWeave parameter list to JSON schema. Does not modify if it's already a JSON schema. */
1574
+ declare function convertParamsToJSONSchema(params: KnowledgeBaseActionParameterSchema): JSONSchema7;
1287
1575
 
1288
1576
  /** Class to help with logging */
1289
1577
  declare class Logging {
@@ -1360,4 +1648,4 @@ interface IntelliWeaveStreamTextOutputEvent extends IntelliWeaveStreamEvent {
1360
1648
  text: string;
1361
1649
  }
1362
1650
 
1363
- export { type BufferType, BufferedWebSocket, ChatGPT, type ChatGPTConfig, type ChatGPTMessage, type ChatGPTToolConfig, FixedBufferStream, IntelliWeave, type IntelliWeaveGlobalConfig, IntelliWeaveStream, type IntelliWeaveStreamErrorEvent, type IntelliWeaveStreamEvent, type IntelliWeaveStreamTextOutputEvent, KnowledgeBase, type KnowledgeBaseItem, type KnowledgeBaseSource, type KnowledgeBaseWebhookActionResponse, type KnowledgeBaseWebhookRequest, type KnowledgeBaseWebhookSearchResponse, Logging, ONNXModel, type ONNXTensors, Resampler, type SupportedArrayBuffers, TokenWindow, TokenWindowGroup, type TokenWindowGroupItem, type WebWeaverGPTConfig, audioToWav, floatTo16BitPCM, floatTo64BitPCM, getDefaultUserID, int16ToFloat32BitPCM, intelliweaveConfig, intelliweaveGlobalThis, sseEvents, trimWhitespaceInText };
1651
+ export { type BufferType, BufferedWebSocket, ChatGPT, type ChatGPTConfig, type ChatGPTMessage, type ChatGPTToolConfig, 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 };