@dxos/assistant 0.8.2-main.5ca3450 → 0.8.2-main.600d381

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.
Files changed (141) hide show
  1. package/dist/lib/browser/{chunk-OLO6SVOL.mjs → chunk-YSYP7S4W.mjs} +693 -229
  2. package/dist/lib/browser/chunk-YSYP7S4W.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +4 -443
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +42 -1
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node/{chunk-CI5Q7FBG.cjs → chunk-FTIDW4BA.cjs} +714 -257
  9. package/dist/lib/node/chunk-FTIDW4BA.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +34 -470
  11. package/dist/lib/node/index.cjs.map +4 -4
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +49 -9
  14. package/dist/lib/node/testing/index.cjs.map +4 -4
  15. package/dist/lib/node-esm/{chunk-Y3SYOFFJ.mjs → chunk-GCJNPQDJ.mjs} +693 -229
  16. package/dist/lib/node-esm/chunk-GCJNPQDJ.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +4 -443
  18. package/dist/lib/node-esm/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +42 -1
  21. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  22. package/dist/types/src/{conversation → experimental/conversation}/conversation.d.ts +2 -18
  23. package/dist/types/src/experimental/conversation/conversation.d.ts.map +1 -0
  24. package/dist/types/src/experimental/conversation/conversation.test.d.ts.map +1 -0
  25. package/dist/types/src/experimental/conversation/index.d.ts.map +1 -0
  26. package/dist/types/src/experimental/conversation/types.d.ts.map +1 -0
  27. package/dist/types/src/experimental/cypher/ast.d.ts.map +1 -0
  28. package/dist/types/src/experimental/cypher/combinators.d.ts.map +1 -0
  29. package/dist/types/src/experimental/cypher/combinators.test.d.ts.map +1 -0
  30. package/dist/types/src/experimental/cypher/echo-data-source.d.ts.map +1 -0
  31. package/dist/types/src/experimental/cypher/execution-plan.d.ts.map +1 -0
  32. package/dist/types/src/experimental/cypher/execution-plan.test.d.ts.map +1 -0
  33. package/dist/types/src/experimental/cypher/index.d.ts.map +1 -0
  34. package/dist/types/src/experimental/cypher/parjs.d.ts.map +1 -0
  35. package/dist/types/src/experimental/cypher/parser.d.ts.map +1 -0
  36. package/dist/types/src/experimental/cypher/query-executor.d.ts.map +1 -0
  37. package/dist/types/src/experimental/cypher/query-executor.test.d.ts.map +1 -0
  38. package/dist/types/src/experimental/cypher/schema.d.ts.map +1 -0
  39. package/dist/types/src/experimental/cypher/schema.test.d.ts.map +1 -0
  40. package/dist/types/src/experimental/index.d.ts +3 -0
  41. package/dist/types/src/experimental/index.d.ts.map +1 -0
  42. package/dist/types/src/experimental/ner/ner.test.d.ts +2 -0
  43. package/dist/types/src/experimental/ner/ner.test.d.ts.map +1 -0
  44. package/dist/types/src/experimental/research/exa.d.ts +6 -0
  45. package/dist/types/src/experimental/research/exa.d.ts.map +1 -0
  46. package/dist/types/src/experimental/research/research.test.d.ts +2 -0
  47. package/dist/types/src/experimental/research/research.test.d.ts.map +1 -0
  48. package/dist/types/src/index.d.ts +1 -2
  49. package/dist/types/src/index.d.ts.map +1 -1
  50. package/dist/types/src/session/index.d.ts +1 -0
  51. package/dist/types/src/session/index.d.ts.map +1 -1
  52. package/dist/types/src/session/session.d.ts +1 -0
  53. package/dist/types/src/session/session.d.ts.map +1 -1
  54. package/dist/types/src/session/tools.d.ts +18 -0
  55. package/dist/types/src/session/tools.d.ts.map +1 -0
  56. package/dist/types/src/session/version-pin.d.ts +5 -0
  57. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  58. package/dist/types/src/testing/index.d.ts +1 -0
  59. package/dist/types/src/testing/index.d.ts.map +1 -1
  60. package/dist/types/src/testing/logger.d.ts +1 -1
  61. package/dist/types/src/testing/printer.d.ts +6 -0
  62. package/dist/types/src/testing/printer.d.ts.map +1 -0
  63. package/dist/types/src/testing/query-promts.d.ts +1 -1
  64. package/dist/types/src/testing/query-promts.d.ts.map +1 -1
  65. package/dist/types/src/testing/test-data.d.ts +1 -1
  66. package/dist/types/src/testing/test-data.d.ts.map +1 -1
  67. package/package.json +19 -14
  68. package/src/ai-service/ollama-client.ts +1 -1
  69. package/src/bin/chat.ts +1 -1
  70. package/src/{conversation → experimental/conversation}/conversation.test.ts +2 -2
  71. package/src/{conversation → experimental/conversation}/conversation.ts +3 -112
  72. package/src/{cypher → experimental/cypher}/query-executor.test.ts +1 -1
  73. package/src/{cypher → experimental/cypher}/schema.test.ts +1 -1
  74. package/src/{cypher → experimental/cypher}/schema.ts +1 -1
  75. package/src/experimental/index.ts +6 -0
  76. package/src/experimental/ner/ner.test.ts +163 -0
  77. package/src/experimental/research/exa.ts +38 -0
  78. package/src/experimental/research/instructions.tpl +64 -0
  79. package/src/experimental/research/research.test.ts +263 -0
  80. package/src/index.ts +3 -2
  81. package/src/session/index.ts +1 -0
  82. package/src/session/session.test.ts +6 -41
  83. package/src/session/session.ts +11 -1
  84. package/src/session/tools.ts +117 -0
  85. package/src/session/version-pin.ts +6 -0
  86. package/src/testing/index.ts +1 -0
  87. package/src/testing/logger.ts +1 -1
  88. package/src/testing/printer.ts +41 -0
  89. package/src/testing/query-promts.ts +1 -1
  90. package/src/testing/query.test.ts +1 -2
  91. package/src/testing/test-data.ts +1 -1
  92. package/src/typedefs.d.ts +8 -0
  93. package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +0 -7
  94. package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +0 -7
  95. package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +0 -7
  96. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  97. package/dist/types/src/conversation/conversation.test.d.ts.map +0 -1
  98. package/dist/types/src/conversation/index.d.ts.map +0 -1
  99. package/dist/types/src/conversation/types.d.ts.map +0 -1
  100. package/dist/types/src/cypher/ast.d.ts.map +0 -1
  101. package/dist/types/src/cypher/combinators.d.ts.map +0 -1
  102. package/dist/types/src/cypher/combinators.test.d.ts.map +0 -1
  103. package/dist/types/src/cypher/echo-data-source.d.ts.map +0 -1
  104. package/dist/types/src/cypher/execution-plan.d.ts.map +0 -1
  105. package/dist/types/src/cypher/execution-plan.test.d.ts.map +0 -1
  106. package/dist/types/src/cypher/index.d.ts.map +0 -1
  107. package/dist/types/src/cypher/parjs.d.ts.map +0 -1
  108. package/dist/types/src/cypher/parser.d.ts.map +0 -1
  109. package/dist/types/src/cypher/query-executor.d.ts.map +0 -1
  110. package/dist/types/src/cypher/query-executor.test.d.ts.map +0 -1
  111. package/dist/types/src/cypher/schema.d.ts.map +0 -1
  112. package/dist/types/src/cypher/schema.test.d.ts.map +0 -1
  113. /package/dist/types/src/{conversation → experimental/conversation}/conversation.test.d.ts +0 -0
  114. /package/dist/types/src/{conversation → experimental/conversation}/index.d.ts +0 -0
  115. /package/dist/types/src/{conversation → experimental/conversation}/types.d.ts +0 -0
  116. /package/dist/types/src/{cypher → experimental/cypher}/ast.d.ts +0 -0
  117. /package/dist/types/src/{cypher → experimental/cypher}/combinators.d.ts +0 -0
  118. /package/dist/types/src/{cypher → experimental/cypher}/combinators.test.d.ts +0 -0
  119. /package/dist/types/src/{cypher → experimental/cypher}/echo-data-source.d.ts +0 -0
  120. /package/dist/types/src/{cypher → experimental/cypher}/execution-plan.d.ts +0 -0
  121. /package/dist/types/src/{cypher → experimental/cypher}/execution-plan.test.d.ts +0 -0
  122. /package/dist/types/src/{cypher → experimental/cypher}/index.d.ts +0 -0
  123. /package/dist/types/src/{cypher → experimental/cypher}/parjs.d.ts +0 -0
  124. /package/dist/types/src/{cypher → experimental/cypher}/parser.d.ts +0 -0
  125. /package/dist/types/src/{cypher → experimental/cypher}/query-executor.d.ts +0 -0
  126. /package/dist/types/src/{cypher → experimental/cypher}/query-executor.test.d.ts +0 -0
  127. /package/dist/types/src/{cypher → experimental/cypher}/schema.d.ts +0 -0
  128. /package/dist/types/src/{cypher → experimental/cypher}/schema.test.d.ts +0 -0
  129. /package/src/{conversation → experimental/conversation}/index.ts +0 -0
  130. /package/src/{conversation → experimental/conversation}/types.ts +0 -0
  131. /package/src/{cypher → experimental/cypher}/ast.ts +0 -0
  132. /package/src/{cypher → experimental/cypher}/combinators.test.ts +0 -0
  133. /package/src/{cypher → experimental/cypher}/combinators.ts +0 -0
  134. /package/src/{cypher → experimental/cypher}/echo-data-source.ts +0 -0
  135. /package/src/{cypher → experimental/cypher}/execution-plan.test.ts +0 -0
  136. /package/src/{cypher → experimental/cypher}/execution-plan.ts +0 -0
  137. /package/src/{cypher → experimental/cypher}/index.ts +0 -0
  138. /package/src/{cypher → experimental/cypher}/parjs-shims.d.ts +0 -0
  139. /package/src/{cypher → experimental/cypher}/parjs.ts +0 -0
  140. /package/src/{cypher → experimental/cypher}/parser.ts +0 -0
  141. /package/src/{cypher → experimental/cypher}/query-executor.ts +0 -0
@@ -1,3 +1,4 @@
1
1
  export * from './session';
2
2
  export * from './version-pin';
3
+ export * from './tools';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/session/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/session/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
@@ -220,6 +220,7 @@ export declare class AISession {
220
220
  }>;
221
221
  constructor(_options: AiSessionOptions);
222
222
  run(options: SessionRunOptions): Promise<Message[]>;
223
+ runStructured<S extends Schema.Schema.AnyNoContext>(schema: S, options: SessionRunOptions): Promise<Schema.Schema.Type<S>>;
223
224
  private _formatUserPrompt;
224
225
  private _createQueryArtifactsTool;
225
226
  private _createRequireTool;
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../../src/session/session.ts"],"names":[],"mappings":"AAIA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAEL,OAAO,EAEP,KAAK,kBAAkB,EAEvB,KAAK,IAAI,EACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,EAAgB,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EAAqB,KAAK,eAAe,EAAE,KAAK,eAAe,EAAyB,MAAM,eAAe,CAAC;AAGrH;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE;IAAE,EAAE,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,aAAa,CAAA;CAAE,EAAE,KAAK,OAAO,CACvG,GAAG,CACD,QAAQ,EACR;IACE,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CACF,CACF,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,eAAe,CAAC;IAExB,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,IAAI,EAAE,CAAC;IAEd,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,MAAM,EAAE,MAAM,CAAC;IAEf,iBAAiB,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAEnD,UAAU,CAAC,EAAE,qBAAqB,CAAC;IAEnC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,mBAAmB,CAAC,E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,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF,qBAAa,SAAS;IAmCR,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAlCrC,yBAAyB;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IAEnD,yDAAyD;IACzD,OAAO,CAAC,QAAQ,CAAiB;IAEjC,kCAAkC;IAClC,OAAO,CAAC,OAAO,CAA+B;IAE9C,gCAAgC;IAChC,OAAO,CAAC,QAAQ,CAAiB;IAEjC;;OAEG;IACH,SAAgB,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAwB;IAE/C;;OAEG;IACH,SAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAsB;IAE3C;;OAEG;IACH,SAAgB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAuB;IAE7C,SAAgB,WAAW,4CAA4B;IAEvD;;OAEG;IACH,SAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAAwB;gBAEtB,QAAQ,EAAE,gBAAgB;IAQjD,GAAG,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IA6GnD,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,iBAAiB;YASjF,iBAAiB;IAsC/B,OAAO,CAAC,yBAAyB;IAiBjC,OAAO,CAAC,kBAAkB;IA+B1B,OAAO,CAAC,mBAAmB;IAoF3B,KAAK;CAGN;;;;AAuDD,qBAAa,wBAAyB,SAAQ,6BAG7C;CAAG"}
@@ -0,0 +1,18 @@
1
+ import { Message, type Tool } from '@dxos/artifact';
2
+ export declare const isToolUse: (message: Message, { onlyToolNames }?: {
3
+ onlyToolNames?: string[];
4
+ }) => boolean;
5
+ export type RunToolsOptions = {
6
+ message: Message;
7
+ tools: Tool[];
8
+ extensions?: ToolContextExtensions;
9
+ };
10
+ export type RunToolsResult = {
11
+ type: 'continue';
12
+ message: Message;
13
+ } | {
14
+ type: 'break';
15
+ result: unknown;
16
+ };
17
+ export declare const runTools: ({ message, tools, extensions }: RunToolsOptions) => Promise<RunToolsResult>;
18
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../../src/session/tools.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,EAAc,MAAM,gBAAgB,CAAC;AAKhE,eAAO,MAAM,SAAS,GAAI,SAAS,OAAO,EAAE,oBAAmB;IAAE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,YAI/F,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,qBAAqB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,cAAc,GACtB;IACE,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEN,eAAO,MAAM,QAAQ,GAAU,gCAAgC,eAAe,KAAG,OAAO,CAAC,cAAc,CAqFtG,CAAC"}
@@ -6,6 +6,11 @@ declare const VersionPinSchema: Schema.Struct<{
6
6
  objectId: import("@dxos/echo-schema").ObjectIdClass;
7
7
  version: Schema.Schema<ObjectVersion, ObjectVersion, never>;
8
8
  }>;
9
+ /**
10
+ * Used to pin a specific version of an object during the course of a conversation.
11
+ *
12
+ * This allows us to detect when the object changes during the course of the conversation.
13
+ */
9
14
  export interface VersionPin extends Schema.Schema.Type<typeof VersionPinSchema> {
10
15
  }
11
16
  export declare const VersionPin: typeof VersionPinSchema & {
@@ -1 +1 @@
1
- {"version":3,"file":"version-pin.d.ts","sourceRoot":"","sources":["../../../../src/session/version-pin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKlE,QAAA,MAAM,gBAAgB;;;EAKpB,CAAC;AACH,MAAM,WAAW,UAAW,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC;CAAG;AAElF,eAAO,MAAM,UAAU,EAAE,OAAO,gBAAgB,GAAG;IACjD,WAAW,EAAE,aAAa,CAAC;IAC3B,UAAU,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,UAAU,CAAC;IACnD,WAAW,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,mBAAmB,CAAC;CAiBvD,CAAC"}
1
+ {"version":3,"file":"version-pin.d.ts","sourceRoot":"","sources":["../../../../src/session/version-pin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAKlE,QAAA,MAAM,gBAAgB;;;EAKpB,CAAC;AAEH;;;;GAIG;AACH,MAAM,WAAW,UAAW,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC;CAAG;AAElF,eAAO,MAAM,UAAU,EAAE,OAAO,gBAAgB,GAAG;IACjD,WAAW,EAAE,aAAa,CAAC;IAC3B,UAAU,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,UAAU,CAAC;IACnD,WAAW,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,mBAAmB,CAAC;CAiBvD,CAAC"}
@@ -4,4 +4,5 @@ export * from './ollama';
4
4
  export * from './query-promts';
5
5
  export * from './test-data';
6
6
  export * from './test-schema';
7
+ export * from './printer';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { ImageSource } from '@dxos/artifact';
2
- import type { ConversationEvent } from '../conversation';
2
+ import type { ConversationEvent } from '../experimental';
3
3
  export declare const createLogger: ({ stream, filter, onImage, }?: {
4
4
  stream?: boolean;
5
5
  filter?: (event: ConversationEvent) => boolean;
@@ -0,0 +1,6 @@
1
+ import type { Message, MessageContentBlock } from '@dxos/artifact';
2
+ export declare class ConsolePrinter {
3
+ printMessage: (message: Message) => void;
4
+ printContentBlock: (content: MessageContentBlock) => void;
5
+ }
6
+ //# sourceMappingURL=printer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../../../src/testing/printer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnE,qBAAa,cAAc;IACzB,YAAY,GAAI,SAAS,OAAO,UAM9B;IAEF,iBAAiB,GAAI,SAAS,mBAAmB,UAsB/C;CACH"}
@@ -1,5 +1,5 @@
1
1
  import { Schema } from 'effect';
2
- import { type DataSource } from '../cypher';
2
+ import { type DataSource } from '../experimental';
3
3
  export declare const createCypherTool: (dataSource: DataSource, schemaTypes?: Schema.Schema.Any[]) => import("@dxos/artifact").Tool;
4
4
  export declare const createSystemPrompt: (schemaTypes: Schema.Schema.Any[]) => string;
5
5
  //# sourceMappingURL=query-promts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-promts.d.ts","sourceRoot":"","sources":["../../../../src/testing/query-promts.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,OAAO,EAAwC,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAGlF,eAAO,MAAM,gBAAgB,GAAI,YAAY,UAAU,EAAE,cAAa,MAAM,CAAC,MAAM,CAAC,GAAG,EAAO,kCA0C1F,CAAC;AAEL,eAAO,MAAM,kBAAkB,GAAI,aAAa,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,WAiBlE,CAAC"}
1
+ {"version":3,"file":"query-promts.d.ts","sourceRoot":"","sources":["../../../../src/testing/query-promts.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,OAAO,EAAwC,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGxF,eAAO,MAAM,gBAAgB,GAAI,YAAY,UAAU,EAAE,cAAa,MAAM,CAAC,MAAM,CAAC,GAAG,EAAO,kCA0C1F,CAAC;AAEL,eAAO,MAAM,kBAAkB,GAAI,aAAa,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,WAiBlE,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { type Schema } from 'effect';
2
2
  import type { EchoDatabase } from '@dxos/echo-db';
3
3
  import { type JsonSchemaType } from '@dxos/echo-schema';
4
- import { type DataSource, type Node, type Relationship } from '../cypher';
4
+ import { type DataSource, type Node, type Relationship } from '../experimental';
5
5
  export declare const seedTestData: (db: EchoDatabase) => void;
6
6
  export declare const createTestData: () => MockDataSource;
7
7
  export declare class MockDataSource implements DataSource {
@@ -1 +1 @@
1
- {"version":3,"file":"test-data.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-data.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAIL,KAAK,cAAc,EAGpB,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACL,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,YAAY,EAGlB,MAAM,WAAW,CAAC;AAGnB,eAAO,MAAM,YAAY,GAAI,IAAI,YAAY,SAoH5C,CAAC;AAGF,eAAO,MAAM,cAAc,QAAO,cAuGjC,CAAC;AAEF,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,EAAE,MAAM,CACb,MAAM,EACN;QACE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,OAAO,CAAC;KACf,CACF,CAAM;IAEP,MAAM,EAAE,MAAM,CACZ,MAAM,EACN;QACE,IAAI,EAAE,cAAc,CAAC;QACrB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC;KAC7B,CACF,CAAM;IAEP,KAAK,EAAE,IAAI,EAAE,CAAM;IACnB,aAAa,EAAE,YAAY,EAAE,CAAM;IAE7B,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAItC,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAA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KAAE;IAIpD,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAsBvE,YAAY;CA0Eb"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/assistant",
3
- "version": "0.8.2-main.5ca3450",
3
+ "version": "0.8.2-main.600d381",
4
4
  "description": "Natural language interface to DXOS",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -37,22 +37,27 @@
37
37
  "src"
38
38
  ],
39
39
  "dependencies": {
40
+ "@xenova/transformers": "^2.17.2",
41
+ "exa-js": "^1.5.12",
40
42
  "parjs": "^1.3.9",
41
43
  "parsimmon": "^1.18.1",
42
44
  "ulidx": "^2.3.0",
43
- "@dxos/artifact": "0.8.2-main.5ca3450",
44
- "@dxos/context": "0.8.2-main.5ca3450",
45
- "@dxos/debug": "0.8.2-main.5ca3450",
46
- "@dxos/async": "0.8.2-main.5ca3450",
47
- "@dxos/echo": "0.8.2-main.5ca3450",
48
- "@dxos/echo-schema": "0.8.2-main.5ca3450",
49
- "@dxos/echo-db": "0.8.2-main.5ca3450",
50
- "@dxos/invariant": "0.8.2-main.5ca3450",
51
- "@dxos/live-object": "0.8.2-main.5ca3450",
52
- "@dxos/keys": "0.8.2-main.5ca3450",
53
- "@dxos/log": "0.8.2-main.5ca3450",
54
- "@dxos/node-std": "0.8.2-main.5ca3450",
55
- "@dxos/util": "0.8.2-main.5ca3450"
45
+ "@dxos/artifact": "0.8.2-main.600d381",
46
+ "@dxos/async": "0.8.2-main.600d381",
47
+ "@dxos/context": "0.8.2-main.600d381",
48
+ "@dxos/echo": "0.8.2-main.600d381",
49
+ "@dxos/debug": "0.8.2-main.600d381",
50
+ "@dxos/echo-protocol": "0.8.2-main.600d381",
51
+ "@dxos/echo-db": "0.8.2-main.600d381",
52
+ "@dxos/echo-schema": "0.8.2-main.600d381",
53
+ "@dxos/effect": "0.8.2-main.600d381",
54
+ "@dxos/invariant": "0.8.2-main.600d381",
55
+ "@dxos/keys": "0.8.2-main.600d381",
56
+ "@dxos/live-object": "0.8.2-main.600d381",
57
+ "@dxos/node-std": "0.8.2-main.600d381",
58
+ "@dxos/schema": "0.8.2-main.600d381",
59
+ "@dxos/log": "0.8.2-main.600d381",
60
+ "@dxos/util": "0.8.2-main.600d381"
56
61
  },
57
62
  "devDependencies": {
58
63
  "@types/parsimmon": "^1.10.9",
@@ -14,7 +14,7 @@ import { MessageCollector, emitMessageAsEvents } from './message-collector';
14
14
  import { type AIServiceClient, type GenerationStream } from './service';
15
15
  import { GenerationStreamImpl } from './stream';
16
16
  import { ToolTypes, type GenerateRequest, type GenerateResponse, type GenerationStreamEvent } from './types';
17
- import { isToolUse, runTools } from '../conversation';
17
+ import { isToolUse, runTools } from '../session';
18
18
 
19
19
  export type OllamaClientParams = {
20
20
  endpoint?: string;
package/src/bin/chat.ts CHANGED
@@ -11,7 +11,7 @@ import { SpaceId } from '@dxos/keys';
11
11
  import { log } from '@dxos/log';
12
12
 
13
13
  import { AIServiceEdgeClient, ToolTypes, DEFAULT_EDGE_MODEL } from '../ai-service';
14
- import { runLLM } from '../conversation';
14
+ import { runLLM } from '../experimental';
15
15
  import {
16
16
  AI_SERVICE_ENDPOINT,
17
17
  createLogger,
@@ -11,8 +11,8 @@ import { SpaceId } from '@dxos/keys';
11
11
  import { log } from '@dxos/log';
12
12
 
13
13
  import { runLLM, type ConversationEvent } from './conversation';
14
- import { AIServiceEdgeClient, DEFAULT_EDGE_MODEL } from '../ai-service';
15
- import { AI_SERVICE_ENDPOINT } from '../testing';
14
+ import { AIServiceEdgeClient, DEFAULT_EDGE_MODEL } from '../../ai-service';
15
+ import { AI_SERVICE_ENDPOINT } from '../../testing';
16
16
 
17
17
  // TODO(burdon): Local live LLM test.
18
18
  describe.skip('Conversation tests', () => {
@@ -2,13 +2,13 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type Tool, ToolResult, Message } from '@dxos/artifact';
6
- import { create, ObjectId } from '@dxos/echo-schema';
5
+ import { type Message, type Tool } from '@dxos/artifact';
6
+ import { ObjectId } from '@dxos/echo-schema';
7
7
  import { invariant } from '@dxos/invariant';
8
8
  import { type SpaceId } from '@dxos/keys';
9
9
  import { log } from '@dxos/log';
10
10
 
11
- import { type AIServiceClient, type GenerationStreamEvent, type LLMModel } from '../ai-service';
11
+ import { type AIServiceClient, type GenerationStreamEvent, type LLMModel } from '../../ai-service';
12
12
 
13
13
  export type CreateLLMConversationParams = {
14
14
  model: LLMModel;
@@ -140,112 +140,3 @@ export const runLLM = async (params: CreateLLMConversationParams) => {
140
140
  history,
141
141
  };
142
142
  };
143
-
144
- export const isToolUse = (message: Message, { onlyToolNames }: { onlyToolNames?: string[] } = {}) => {
145
- const block = message.content.at(-1);
146
- invariant(block);
147
- return block.type === 'tool_use' && (!onlyToolNames || onlyToolNames.includes(block.name));
148
- };
149
-
150
- export type RunToolsOptions = {
151
- message: Message;
152
- tools: Tool[];
153
- extensions?: ToolContextExtensions;
154
- };
155
-
156
- export type RunToolsResult =
157
- | {
158
- type: 'continue';
159
- message: Message;
160
- }
161
- | {
162
- type: 'break';
163
- result: unknown;
164
- };
165
-
166
- export const runTools = async ({ message, tools, extensions }: RunToolsOptions): Promise<RunToolsResult> => {
167
- const toolCalls = message.content.filter((block) => block.type === 'tool_use');
168
- invariant(toolCalls.length === 1);
169
- const toolCall = toolCalls[0];
170
- const tool = tools.find((tool) => tool.name === toolCall.name);
171
- if (!tool) {
172
- const resultMessage = create(Message, {
173
- role: 'user',
174
- content: [
175
- {
176
- type: 'tool_result',
177
- toolUseId: toolCall.id,
178
- content: `Tool not found: ${toolCall.name}`,
179
- isError: true,
180
- },
181
- ],
182
- });
183
-
184
- // TODO(burdon): Retry count?
185
- return {
186
- type: 'continue',
187
- message: resultMessage,
188
- };
189
- }
190
-
191
- let toolResult: ToolResult;
192
- try {
193
- invariant(tool.execute);
194
- toolResult = await tool.execute(toolCall.input, { extensions });
195
- } catch (error: any) {
196
- log('tool error', { error });
197
- toolResult = ToolResult.Error(error.message);
198
- }
199
-
200
- switch (toolResult.kind) {
201
- case 'error': {
202
- log('tool error', { message: toolResult.message });
203
- const resultMessage = create(Message, {
204
- role: 'user',
205
- content: [
206
- {
207
- type: 'tool_result',
208
- toolUseId: toolCall.id,
209
- content: toolResult.message,
210
- isError: true,
211
- },
212
- ],
213
- });
214
-
215
- // TODO(burdon): Retry count?
216
- return {
217
- type: 'continue',
218
- message: resultMessage,
219
- };
220
- }
221
-
222
- case 'success': {
223
- log('tool success', { result: toolResult.result });
224
- const resultMessage = create(Message, {
225
- role: 'user',
226
- content: [
227
- {
228
- type: 'tool_result',
229
- toolUseId: toolCall.id,
230
- content:
231
- typeof toolResult.result === 'string' ? toolResult.result : JSON.stringify(toolResult.result) ?? '',
232
- },
233
- ...(toolResult.extractContentBlocks ?? []),
234
- ],
235
- });
236
-
237
- return {
238
- type: 'continue',
239
- message: resultMessage,
240
- };
241
- }
242
-
243
- case 'break': {
244
- log('tool break', { result: toolResult.result });
245
- return {
246
- type: 'break',
247
- result: toolResult.result,
248
- };
249
- }
250
- }
251
- };
@@ -7,7 +7,7 @@ import { test } from 'vitest';
7
7
  import { log } from '@dxos/log';
8
8
 
9
9
  import { executeQuery } from './query-executor';
10
- import { createTestData } from '../testing';
10
+ import { createTestData } from '../../testing';
11
11
 
12
12
  test.skip('run', async ({ expect }) => {
13
13
  const dataSource = createTestData();
@@ -7,7 +7,7 @@ import { test } from 'vitest';
7
7
  import { toJsonSchema } from '@dxos/echo-schema';
8
8
 
9
9
  import { formatJsonSchemaForLLM } from './schema';
10
- import { Contact, Organization, Project, Task } from '../testing';
10
+ import { Contact, Organization, Project, Task } from '../../testing';
11
11
 
12
12
  test('Organization-Project-Task-Contact schema', async ({ expect }) => {
13
13
  const jsonSchema = [Organization, Project, Task, Contact].map((schema) => toJsonSchema(schema));
@@ -5,7 +5,7 @@
5
5
  import { raise } from '@dxos/debug';
6
6
  import { JSON_SCHEMA_ECHO_REF_ID, type JsonSchemaType } from '@dxos/echo-schema';
7
7
 
8
- import { trim } from '../util';
8
+ import { trim } from '../../util';
9
9
 
10
10
  /**
11
11
  * Formats ECHO schema to be consumed by LLM.
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './conversation';
6
+ export * from './cypher';
@@ -0,0 +1,163 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { pipeline } from '@xenova/transformers';
6
+ import { beforeAll, describe, expect, test } from 'vitest';
7
+
8
+ import { log } from '@dxos/log';
9
+ import { createTestData } from '@dxos/schema/testing';
10
+
11
+ type NerToken = {
12
+ entity: string;
13
+ score: number;
14
+ index: number;
15
+ word: string;
16
+ start: number | null;
17
+ end: number | null;
18
+ };
19
+
20
+ const createTokenGroups = (tokens: NerToken[]): NerToken[][] => {
21
+ const tokenGroups: NerToken[][] = [];
22
+
23
+ const canBeCombined = (prevToken: NerToken, currentToken: NerToken) => {
24
+ const [currentState, currentEntity] = currentToken.entity.split('-'); // B, I, O
25
+ const [prevState, prevEntity] = prevToken.entity.split('-'); // B, I, O
26
+
27
+ if (prevEntity !== currentEntity) {
28
+ return false;
29
+ }
30
+
31
+ if (prevState === 'O') {
32
+ return false;
33
+ }
34
+
35
+ if (currentState === 'I') {
36
+ return true;
37
+ }
38
+
39
+ if ((prevState === 'B' || prevState === 'I') && currentState === 'B') {
40
+ return currentToken.word.startsWith('#');
41
+ }
42
+
43
+ return false;
44
+ };
45
+
46
+ for (const token of tokens) {
47
+ if (tokenGroups.length === 0) {
48
+ tokenGroups.push([token]);
49
+ continue;
50
+ }
51
+
52
+ const lastTokenGroup = tokenGroups.at(-1)!;
53
+ if (canBeCombined(lastTokenGroup.at(-1)!, token)) {
54
+ lastTokenGroup.push(token);
55
+ continue;
56
+ }
57
+
58
+ tokenGroups.push([token]);
59
+ }
60
+
61
+ return tokenGroups;
62
+ };
63
+
64
+ const combineNerTokens = (group: NerToken[]): NerToken => {
65
+ const combinedToken: NerToken = {
66
+ entity: group.at(0)!.entity.split('-')[1],
67
+ score: group.reduce((acc, token) => acc + token.score, 0) / group.length,
68
+ index: group.at(0)!.index,
69
+ word: group.at(0)!.word,
70
+ start: group.at(0)!.start,
71
+ end: group.at(-1)!.end,
72
+ };
73
+
74
+ for (const token of group.slice(1)) {
75
+ if (token.word.startsWith('#')) {
76
+ combinedToken.word += token.word.replace(/^#+/, '');
77
+ } else {
78
+ combinedToken.word += ' ' + token.word;
79
+ }
80
+ }
81
+
82
+ return combinedToken;
83
+ };
84
+
85
+ describe.skip('Named Entity Recognition', () => {
86
+ let ner: any;
87
+
88
+ beforeAll(async () => {
89
+ // Initialize the NER pipeline
90
+ ner = await pipeline('ner', 'Xenova/bert-base-NER');
91
+ });
92
+
93
+ test.skip('should identify named entities in text', async () => {
94
+ const text = 'Elon Musk is the CEO of SpaceX and Tesla.';
95
+ const result = await ner(text);
96
+
97
+ // Verify the structure of the result
98
+ expect(Array.isArray(result)).toBe(true);
99
+ expect(result.length).toBeGreaterThan(0);
100
+
101
+ log.info('ner', { result });
102
+
103
+ // Check for specific entities
104
+ const entities = result.map((item: any) => ({
105
+ text: item.word,
106
+ entity: item.entity,
107
+ score: item.score,
108
+ }));
109
+
110
+ // Verify Elon Musk is recognized as a person
111
+ const elonMusk = entities.find((e: any) => e.text === 'Elon' || e.text === 'Musk');
112
+ expect(elonMusk).toBeDefined();
113
+ expect(elonMusk?.entity).toMatch(/PER/);
114
+
115
+ // Verify SpaceX and Tesla are recognized as organizations
116
+ const companies = entities.filter((e: any) => e.text === 'SpaceX' || e.text === 'Tesla');
117
+ expect(companies.length).toBe(2);
118
+ companies.forEach((company: any) => {
119
+ expect(company.entity).toMatch(/ORG/);
120
+ });
121
+ });
122
+
123
+ test('own data', async () => {
124
+ const { transcriptWoflram, transcriptJosiah } = await createTestData();
125
+
126
+ const blocks = [...transcriptWoflram, ...transcriptJosiah].flatMap((message) =>
127
+ message.blocks.flatMap((block) => (block.type === 'transcription' ? [block.text] : [])),
128
+ );
129
+
130
+ for (const block of blocks) {
131
+ const result = await ner(block);
132
+ const combinedTokens = createTokenGroups(result).map(combineNerTokens);
133
+ log.info('ner', { text: block, result: combinedTokens });
134
+ }
135
+ });
136
+
137
+ test('more own data', async () => {
138
+ const { transcriptMessages } = await createTestData();
139
+
140
+ const blocks = transcriptMessages.flatMap((message) =>
141
+ message.blocks.flatMap((block) => (block.type === 'transcription' ? [block.text] : [])),
142
+ );
143
+
144
+ for (const block of blocks) {
145
+ const result = await ner(block);
146
+ const combinedTokens = createTokenGroups(result).map(combineNerTokens);
147
+ log.info('ner', { text: block, result: combinedTokens });
148
+ }
149
+ });
150
+
151
+ test('should handle empty text', async () => {
152
+ const result = await ner('');
153
+ expect(Array.isArray(result)).toBe(true);
154
+ expect(result.length).toBe(0);
155
+ });
156
+
157
+ test('should handle text with no named entities', async () => {
158
+ const text = 'The weather is nice today.';
159
+ const result = await ner(text);
160
+ expect(Array.isArray(result)).toBe(true);
161
+ expect(result.length).toBe(0);
162
+ });
163
+ });
@@ -0,0 +1,38 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Schema } from 'effect';
6
+ import Exa from 'exa-js';
7
+
8
+ import { defineTool, ToolResult } from '@dxos/artifact';
9
+ import { log } from '@dxos/log';
10
+
11
+ type CreateExaToolOptions = {
12
+ apiKey: string;
13
+ };
14
+
15
+ export const createExaTool = ({ apiKey }: CreateExaToolOptions) => {
16
+ const exa = new Exa(apiKey);
17
+
18
+ return defineTool('search', {
19
+ name: 'web_search',
20
+ description: 'Search the web for information',
21
+ schema: Schema.Struct({
22
+ query: Schema.String.annotations({ description: 'The query to search for' }),
23
+ }),
24
+ execute: async ({ query }) => {
25
+ const context = await exa.searchAndContents(query, {
26
+ type: 'auto',
27
+ text: {
28
+ maxCharacters: 3_000,
29
+ },
30
+ livecrawl: 'always',
31
+ });
32
+
33
+ log.info('exa search', { query, costDollars: context.costDollars });
34
+
35
+ return ToolResult.Success(context);
36
+ },
37
+ });
38
+ };
@@ -0,0 +1,64 @@
1
+ You are an expert research agent. Your job is to assist a user by conducting in-depth research using real-time web search.
2
+ You output the results in a structured format matching the schema provided.
3
+
4
+ You are equipped with the ability to:
5
+
6
+ - Generate precise and effective search queries.
7
+ - Request web pages by query (through a `web_search` tool).
8
+ - Read the full content of retrieved pages.
9
+ - Synthesize accurate, clear, and structured answers using reliable information from the retrieved content.
10
+
11
+ Always follow these principles:
12
+
13
+ - Relevance First: Only return facts that are supported by content in the retrieved web pages. Never fabricate or guess information.
14
+ - Summarize, Don't Copy: Synthesize and rephrase content in your own words. Quote only when necessary.
15
+ - Multiple Sources: Cross-reference at least 2 sources before drawing conclusions, unless the information is directly stated and non-controversial.
16
+ - Transparency: Mention which sources were used and explain how you arrived at your conclusions.
17
+ - Accuracy Over Brevity: Prefer detailed, technically accurate explanations over shallow summaries.
18
+ - If uncertain, say so. It's better to admit uncertainty than to mislead.
19
+ - Pick the most concrete schema types for the extracted information.
20
+ - Fill the schema fields as completely as possible with the information you are confident about, do not fill the fields that you are not confident about.
21
+ - When outputting results, you can add extra data that isn't directly related to the user's question but fits the schema.
22
+
23
+ The user may ask for:
24
+
25
+ - Technical explanations
26
+ - Literature reviews
27
+ - Comparisons
28
+ - Emerging trends
29
+ - Implementation strategies
30
+
31
+ Begin by interpreting the user's request, then:
32
+
33
+ Break it into sub-questions (if applicable).
34
+
35
+ For each sub-question, generate a clear, concise web search query.
36
+
37
+ Use `web_search`(query) to retrieve information.
38
+
39
+ Extract and synthesize relevant answers.
40
+
41
+ Output should include:
42
+
43
+ - A clear, structured answer to the user’s question.
44
+ - A citation list or link list of the sources used.
45
+
46
+ Optionally, follow-up suggestions or questions for deeper inquiry.
47
+
48
+ Here's your operational instructions:
49
+
50
+ 1. Analyze user's request and identify key topics to search for (3 or more). Print them out.
51
+ 2. Perform a web search for each topic.
52
+ 3. Read and analyze the results, cross reference information from multiple sources, in case of conflict, represent the information as a range of possible values.
53
+ 4. Create a list of follow-up topics to research. Print them out.
54
+ 5. Perform a web search for each follow-up topic.
55
+ 6. Read and analyze the results, cross reference information from multiple sources, in case of conflict, represent the information as a range of possible values.
56
+ 9. Create a clear, structured answer to the user's question.
57
+ 10. Create a citation list or link list of the sources used.
58
+ 11. Select the most concrete schema types for the extracted information. You can use multiple different schema types. Print your decision and reasoning.
59
+ 12. Submit the results using the specific schema.
60
+
61
+
62
+
63
+
64
+