@dxos/assistant 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5

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 (233) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/chunk-2TBLG3XY.mjs +1793 -0
  3. package/dist/lib/neutral/chunk-2TBLG3XY.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  5. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  6. package/dist/lib/neutral/extraction/index.mjs +219 -0
  7. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  8. package/dist/lib/neutral/index.mjs +537 -0
  9. package/dist/lib/neutral/index.mjs.map +7 -0
  10. package/dist/lib/neutral/meta.json +1 -0
  11. package/dist/lib/neutral/testing/index.mjs +111 -0
  12. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  13. package/dist/types/src/conversation/context.d.ts +155 -0
  14. package/dist/types/src/conversation/context.d.ts.map +1 -0
  15. package/dist/types/src/conversation/context.test.d.ts +2 -0
  16. package/dist/types/src/conversation/context.test.d.ts.map +1 -0
  17. package/dist/types/src/conversation/index.d.ts +2 -1
  18. package/dist/types/src/conversation/index.d.ts.map +1 -1
  19. package/dist/types/src/conversation/session.d.ts +78 -0
  20. package/dist/types/src/conversation/session.d.ts.map +1 -0
  21. package/dist/types/src/conversation/session.test.d.ts.map +1 -0
  22. package/dist/types/src/diff.d.ts +17 -0
  23. package/dist/types/src/diff.d.ts.map +1 -0
  24. package/dist/types/src/diff.test.d.ts +2 -0
  25. package/dist/types/src/diff.test.d.ts.map +1 -0
  26. package/dist/types/src/errors.d.ts +67 -0
  27. package/dist/types/src/errors.d.ts.map +1 -0
  28. package/dist/types/src/execution-graph.d.ts +85 -0
  29. package/dist/types/src/execution-graph.d.ts.map +1 -0
  30. package/dist/types/src/execution-graph.test.d.ts +2 -0
  31. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  32. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  33. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  34. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  36. package/dist/types/src/extraction/extraction.d.ts +1066 -215
  37. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  38. package/dist/types/src/extraction/index.d.ts +0 -1
  39. package/dist/types/src/extraction/index.d.ts.map +1 -1
  40. package/dist/types/src/extraction/quotes.d.ts +3 -3
  41. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  42. package/dist/types/src/functions/index.d.ts +2 -0
  43. package/dist/types/src/functions/index.d.ts.map +1 -0
  44. package/dist/types/src/functions/services.d.ts +17 -0
  45. package/dist/types/src/functions/services.d.ts.map +1 -0
  46. package/dist/types/src/functions.test.d.ts +2 -0
  47. package/dist/types/src/functions.test.d.ts.map +1 -0
  48. package/dist/types/src/index.d.ts +7 -5
  49. package/dist/types/src/index.d.ts.map +1 -1
  50. package/dist/types/src/service/AgentService.d.ts +75 -0
  51. package/dist/types/src/service/AgentService.d.ts.map +1 -0
  52. package/dist/types/src/service/AgentService.test.d.ts +2 -0
  53. package/dist/types/src/service/AgentService.test.d.ts.map +1 -0
  54. package/dist/types/src/service/agent-process.d.ts +21 -0
  55. package/dist/types/src/service/agent-process.d.ts.map +1 -0
  56. package/dist/types/src/service/index.d.ts +3 -0
  57. package/dist/types/src/service/index.d.ts.map +1 -0
  58. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  59. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  60. package/dist/types/src/session/error-handling.d.ts +4 -0
  61. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  62. package/dist/types/src/session/format.d.ts +16 -0
  63. package/dist/types/src/session/format.d.ts.map +1 -0
  64. package/dist/types/src/session/format.test.d.ts +2 -0
  65. package/dist/types/src/session/format.test.d.ts.map +1 -0
  66. package/dist/types/src/session/index.d.ts +5 -1
  67. package/dist/types/src/session/index.d.ts.map +1 -1
  68. package/dist/types/src/session/observer.d.ts +23 -0
  69. package/dist/types/src/session/observer.d.ts.map +1 -0
  70. package/dist/types/src/session/request.d.ts +106 -0
  71. package/dist/types/src/session/request.d.ts.map +1 -0
  72. package/dist/types/src/session/request.test.d.ts +2 -0
  73. package/dist/types/src/session/request.test.d.ts.map +1 -0
  74. package/dist/types/src/session/session-ollama.test.d.ts +2 -0
  75. package/dist/types/src/session/session-ollama.test.d.ts.map +1 -0
  76. package/dist/types/src/session/toolkit.d.ts +16 -0
  77. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  78. package/dist/types/src/session/version-pin.d.ts +5 -5
  79. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  80. package/dist/types/src/templates/index.d.ts +2 -0
  81. package/dist/types/src/templates/index.d.ts.map +1 -0
  82. package/dist/types/src/templates/system.d.ts +17 -0
  83. package/dist/types/src/templates/system.d.ts.map +1 -0
  84. package/dist/types/src/testing/index.d.ts +1 -2
  85. package/dist/types/src/testing/index.d.ts.map +1 -1
  86. package/dist/types/src/testing/layer.d.ts +40 -0
  87. package/dist/types/src/testing/layer.d.ts.map +1 -0
  88. package/dist/types/src/tracing.d.ts +223 -0
  89. package/dist/types/src/tracing.d.ts.map +1 -0
  90. package/dist/types/src/types/artifact.d.ts +28 -0
  91. package/dist/types/src/types/artifact.d.ts.map +1 -0
  92. package/dist/types/src/types/index.d.ts +2 -0
  93. package/dist/types/src/types/index.d.ts.map +1 -0
  94. package/dist/types/tsconfig.tsbuildinfo +1 -1
  95. package/package.json +60 -29
  96. package/src/conversation/context.test.ts +52 -0
  97. package/src/conversation/context.ts +403 -0
  98. package/src/conversation/index.ts +2 -1
  99. package/src/conversation/session.test.ts +58 -0
  100. package/src/conversation/session.ts +300 -0
  101. package/src/diff.test.ts +74 -0
  102. package/src/diff.ts +93 -0
  103. package/src/errors.ts +15 -0
  104. package/src/execution-graph.test.ts +740 -0
  105. package/src/execution-graph.ts +509 -0
  106. package/src/extraction/extraction-ner-function/index.ts +0 -1
  107. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  108. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +3 -1
  109. package/src/extraction/extraction.ts +44 -15
  110. package/src/extraction/index.ts +0 -1
  111. package/src/extraction/quotes.test.ts +3 -3
  112. package/src/extraction/quotes.ts +6 -7
  113. package/src/functions/index.ts +5 -0
  114. package/src/functions/services.ts +214 -0
  115. package/src/functions.conversations.json +1 -0
  116. package/src/functions.test.ts +88 -0
  117. package/src/index.ts +7 -5
  118. package/src/service/AgentService.conversations.json +1 -0
  119. package/src/service/AgentService.test.ts +169 -0
  120. package/src/service/AgentService.ts +184 -0
  121. package/src/service/agent-process.ts +364 -0
  122. package/src/service/index.ts +6 -0
  123. package/src/session/artifact-diff.ts +41 -0
  124. package/src/session/error-handling.ts +41 -0
  125. package/src/session/format.test.ts +132 -0
  126. package/src/session/format.ts +149 -0
  127. package/src/session/index.ts +5 -1
  128. package/src/session/observer.ts +62 -0
  129. package/src/session/request.conversations.json +1 -0
  130. package/src/session/request.test.ts +195 -0
  131. package/src/session/request.ts +344 -0
  132. package/src/session/session-ollama.test.ts +81 -0
  133. package/src/session/toolkit.ts +47 -0
  134. package/src/session/version-pin.ts +12 -12
  135. package/src/templates/index.ts +5 -0
  136. package/src/templates/instructions/format.tpl +57 -0
  137. package/src/templates/instructions/system.tpl +85 -0
  138. package/src/templates/system.ts +42 -0
  139. package/src/testing/index.ts +2 -8
  140. package/src/testing/layer.ts +236 -0
  141. package/src/tracing.ts +43 -0
  142. package/src/types/artifact.ts +89 -0
  143. package/src/types/index.ts +5 -0
  144. package/src/typings.d.ts +5 -0
  145. package/dist/lib/browser/index.mjs +0 -2019
  146. package/dist/lib/browser/index.mjs.map +0 -7
  147. package/dist/lib/browser/meta.json +0 -1
  148. package/dist/lib/node-esm/index.mjs +0 -2021
  149. package/dist/lib/node-esm/index.mjs.map +0 -7
  150. package/dist/lib/node-esm/meta.json +0 -1
  151. package/dist/types/bin/chat.d.ts +0 -2
  152. package/dist/types/bin/chat.d.ts.map +0 -1
  153. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  154. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  155. package/dist/types/src/blueprint/index.d.ts +0 -3
  156. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  157. package/dist/types/src/blueprint/registry.d.ts +0 -7
  158. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  159. package/dist/types/src/context/binder.d.ts +0 -34
  160. package/dist/types/src/context/binder.d.ts.map +0 -1
  161. package/dist/types/src/context/binding.d.ts +0 -38
  162. package/dist/types/src/context/binding.d.ts.map +0 -1
  163. package/dist/types/src/context/index.d.ts +0 -3
  164. package/dist/types/src/context/index.d.ts.map +0 -1
  165. package/dist/types/src/conversation/conversation.d.ts +0 -44
  166. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  167. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  168. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  169. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  170. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  171. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  172. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  173. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -208
  174. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  175. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  176. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  177. package/dist/types/src/research/exa.d.ts +0 -7
  178. package/dist/types/src/research/exa.d.ts.map +0 -1
  179. package/dist/types/src/research/graph.d.ts +0 -41
  180. package/dist/types/src/research/graph.d.ts.map +0 -1
  181. package/dist/types/src/research/graph.test.d.ts +0 -2
  182. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  183. package/dist/types/src/research/index.d.ts +0 -4
  184. package/dist/types/src/research/index.d.ts.map +0 -1
  185. package/dist/types/src/research/research.d.ts +0 -10
  186. package/dist/types/src/research/research.d.ts.map +0 -1
  187. package/dist/types/src/research/research.test.d.ts +0 -2
  188. package/dist/types/src/research/research.test.d.ts.map +0 -1
  189. package/dist/types/src/session/session.d.ts +0 -283
  190. package/dist/types/src/session/session.d.ts.map +0 -1
  191. package/dist/types/src/session/session.test.d.ts.map +0 -1
  192. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  193. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  194. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  195. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  196. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  197. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  198. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  199. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  200. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  201. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  202. package/dist/types/src/types.d.ts +0 -3
  203. package/dist/types/src/types.d.ts.map +0 -1
  204. package/src/blueprint/blueprint.ts +0 -75
  205. package/src/blueprint/index.ts +0 -6
  206. package/src/blueprint/registry.ts +0 -15
  207. package/src/context/binder.ts +0 -101
  208. package/src/context/binding.ts +0 -31
  209. package/src/context/index.ts +0 -6
  210. package/src/conversation/conversation.ts +0 -103
  211. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -95
  212. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -66
  213. package/src/extraction/extraction-llm-function/index.ts +0 -5
  214. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  215. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -54
  216. package/src/research/exa.ts +0 -100
  217. package/src/research/graph.test.ts +0 -15
  218. package/src/research/graph.ts +0 -337
  219. package/src/research/index.ts +0 -7
  220. package/src/research/instructions-research.tpl +0 -97
  221. package/src/research/research.test.ts +0 -190
  222. package/src/research/research.ts +0 -90
  223. package/src/session/session.test.ts +0 -275
  224. package/src/session/session.ts +0 -582
  225. package/src/session/version-pin.test.ts +0 -26
  226. package/src/summarization/summarization.test.ts +0 -221
  227. package/src/testing/exa-search-1748337321991.ts +0 -131
  228. package/src/testing/exa-search-1748337331526.ts +0 -144
  229. package/src/testing/exa-search-1748337344119.ts +0 -133
  230. package/src/typedefs.d.ts +0 -8
  231. package/src/types.ts +0 -8
  232. /package/dist/types/src/{session → conversation}/session.test.d.ts +0 -0
  233. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
@@ -1,90 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { AgentStatusReport, ConsolePrinter, ToolRegistry } from '@dxos/ai';
8
- import { create } from '@dxos/echo-schema';
9
- import { AiService, CredentialsService, DatabaseService, defineFunction, TracingService } from '@dxos/functions';
10
- import { log } from '@dxos/log';
11
- import { DataTypes } from '@dxos/schema';
12
-
13
- import { createExaTool, createMockExaTool } from './exa';
14
- import { createGraphWriterTool } from './graph';
15
- // TODO(dmaretskyi): Vite build bug with instruction files with the same filename getting mixed-up
16
- import PROMPT from './instructions-research.tpl?raw';
17
- import { AISession } from '../session';
18
-
19
- /**
20
- * Exec external service and return the results as a Subgraph.
21
- */
22
- // TODO(burdon): Rename.
23
- export const researchFn = defineFunction({
24
- description: 'Research the web for information',
25
- inputSchema: Schema.Struct({
26
- query: Schema.String.annotations({
27
- description: 'The query to search for.',
28
- }),
29
-
30
- // TOOD(burdon): Move to context.
31
- mockSearch: Schema.optional(Schema.Boolean).annotations({
32
- description: 'Whether to use the mock search tool.',
33
- default: false,
34
- }),
35
- }),
36
- outputSchema: Schema.Struct({
37
- // result: Schema.String,
38
- result: Schema.Any,
39
- }),
40
- handler: async ({ data: { query, mockSearch }, context }) => {
41
- const ai = context.getService(AiService);
42
- const credentials = context.getService(CredentialsService);
43
- const { db } = context.getService(DatabaseService);
44
- // const queues = context.getService(QueueService);
45
- const tracing = context.getService(TracingService);
46
-
47
- tracing.write(create(AgentStatusReport, { message: 'Researching...' }));
48
-
49
- const exaCredential = await credentials.getCredential({ service: 'exa.ai' });
50
- const searchTool = mockSearch ? createMockExaTool() : createExaTool({ apiKey: exaCredential.apiKey! });
51
-
52
- const printer = new ConsolePrinter();
53
- const session = new AISession({ operationModel: 'configured' });
54
- session.message.on((message) => printer.printMessage(message));
55
- session.userMessage.on((message) => printer.printMessage(message));
56
- session.block.on((block) => printer.printContentBlock(block));
57
- session.statusReport.on((status) => {
58
- log.info('[agent] status', { status });
59
- tracing.write(status);
60
- });
61
- session.streamEvent.on((event) => log('stream', { event }));
62
-
63
- const graphWriteTool = createGraphWriterTool({ db, schema: DataTypes });
64
- log.info('graphWriteTool', { schema: graphWriteTool.parameters });
65
-
66
- // TODO(dmaretskyi): Consider adding this pattern as the "Graph" output mode for the session.
67
- const result = await session.run({
68
- client: ai.client,
69
- systemPrompt: PROMPT,
70
- artifacts: [],
71
- tools: [searchTool.id, graphWriteTool.id],
72
- history: [],
73
- prompt: query,
74
- toolResolver: new ToolRegistry([searchTool, graphWriteTool]),
75
- });
76
-
77
- return {
78
- result: result as any,
79
- };
80
-
81
- // queues.contextQueue!.append(data);
82
-
83
- // return {
84
- // result: `
85
- // The research results are placed in the following objects:
86
- // ${data.map((object, id) => `[obj_${id}][dxn:echo:@:${object.id}]`).join('\n')}
87
- // `,
88
- // };
89
- },
90
- });
@@ -1,275 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
- import { describe, test } from 'vitest';
7
-
8
- import { EdgeAiServiceClient, ConsolePrinter, createTool, ToolResult, ToolRegistry } from '@dxos/ai';
9
- import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
10
- import { ArtifactId, defineArtifact } from '@dxos/artifact';
11
- import { Type, Obj } from '@dxos/echo';
12
- import { ObjectId } from '@dxos/echo-schema';
13
- import { DXN } from '@dxos/keys';
14
- import { log } from '@dxos/log';
15
-
16
- import { AISession } from './session';
17
-
18
- // Define a calendar event artifact schema.
19
- const CalendarEventSchema = Schema.Struct({
20
- title: Schema.String,
21
- startTime: Schema.String,
22
- endTime: Schema.String,
23
- description: Schema.String,
24
- }).pipe(
25
- Type.Obj({
26
- typename: 'example.com/type/CalendarEvent',
27
- version: '0.1.0',
28
- }),
29
- );
30
-
31
- type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
32
-
33
- // TODO(burdon): Flaky.
34
- describe.runIf(process.env.DX_RUN_SLOW_TESTS === '1')('AISession with Ollama', () => {
35
- test('tool', async () => {
36
- const aiClient = new EdgeAiServiceClient({ endpoint: AI_SERVICE_ENDPOINT.REMOTE });
37
- // const aiClient = new OllamaAiServiceClient({
38
- // overrides: { model: 'llama3.1:8b' },
39
- // });
40
- const session = new AISession({ operationModel: 'configured' });
41
-
42
- const printer = new ConsolePrinter();
43
- session.message.on((message) => printer.printMessage(message));
44
- session.userMessage.on((message) => printer.printMessage(message));
45
- session.block.on((block) => printer.printContentBlock(block));
46
-
47
- // session.update.on((update) => {
48
- // log('update', { update });
49
- // });
50
-
51
- const calculatorTool = createTool('test', {
52
- name: 'calculator',
53
- description: 'Adds to numbers',
54
- schema: Schema.Struct({
55
- operand1: Schema.Number,
56
- operand2: Schema.Number,
57
- }),
58
- execute: async ({ operand1, operand2 }) => {
59
- return ToolResult.Success(operand1 + operand2);
60
- },
61
- });
62
-
63
- // Test creating an itinerary
64
- const response = await session.run({
65
- client: aiClient,
66
- tools: [calculatorTool.id],
67
- artifacts: [],
68
- requiredArtifactIds: [],
69
- history: [],
70
- generationOptions: {
71
- model: '@anthropic/claude-3-5-haiku-20241022',
72
- },
73
- prompt: 'What is 10 + 20?',
74
- toolResolver: new ToolRegistry([calculatorTool]),
75
- });
76
-
77
- log('result', { response });
78
- });
79
-
80
- test('create calendar itinerary', { timeout: 60_000 }, async () => {
81
- const aiClient = new EdgeAiServiceClient({ endpoint: AI_SERVICE_ENDPOINT.REMOTE });
82
- // const aiClient = new OllamaAiServiceClient({
83
- // overrides: { model: 'llama3.1:8b' },
84
- // });
85
- const session = new AISession({ operationModel: 'configured' });
86
-
87
- const objects = new Set<string>();
88
-
89
- // Define calendar artifact.
90
- const calendarArtifact = defineArtifact({
91
- id: 'artifact:dxos.org/plugin/calendar',
92
- name: 'Calendar',
93
- instructions: 'Use this to create and query calendar events.',
94
- schema: CalendarEventSchema,
95
- tools: [
96
- createTool('calendar', {
97
- name: 'query',
98
- description: 'Query the calendar for events',
99
- schema: Schema.Struct({}),
100
- execute: async () => {
101
- return ToolResult.Success(CALENDAR_EVENTS);
102
- },
103
- }),
104
- ],
105
- });
106
-
107
- const tableArtifact = defineArtifact({
108
- id: 'artifact:dxos.org/plugin/table',
109
- name: 'Table',
110
- instructions: 'Use this to create and manage tables. Each table has a unique id.',
111
- schema: Schema.Struct({}),
112
- tools: [
113
- createTool('table', {
114
- name: 'create',
115
- description: 'Create a table',
116
- schema: Schema.Struct({
117
- data: Schema.Array(Schema.Any).annotations({ description: 'Array of data payloads to add as rows' }),
118
- }),
119
- execute: async ({ data }) => {
120
- log('create table', { data });
121
- const id = DXN.fromLocalObjectId(ObjectId.random()).toString();
122
- objects.add(id);
123
- // TODO(dmaretskyi): consider xml for refs instead of @dxn:echo:@:XXXXX
124
- return ToolResult.Success(`table @${id}`);
125
- },
126
- }),
127
- ],
128
- });
129
-
130
- const mapArtifact = defineArtifact({
131
- id: 'artifact:dxos.org/plugin/map',
132
- name: 'Map',
133
- instructions:
134
- 'Use this to create and manage maps. Maps source data from tables. Table id is required to create a map.',
135
- schema: Schema.Struct({}),
136
- tools: [
137
- createTool('map', {
138
- name: 'create',
139
- description: 'Create a map',
140
- schema: Schema.Struct({
141
- source: ArtifactId.annotations({
142
- description: 'The table that will be used as the source of the map',
143
- }),
144
- }),
145
- execute: async ({ source }) => {
146
- // TODO(dmaretskyi): Use effect-schema decode instead of manual parsing.
147
- const sourceId = ArtifactId.toDXN(source);
148
- if (!objects.has(sourceId.toString())) {
149
- return ToolResult.Error(`table id=${source} not found`);
150
- }
151
- log('create map', { sourceId });
152
- const id = DXN.fromLocalObjectId(ObjectId.random()).toString();
153
- objects.add(id);
154
- // TODO(dmaretskyi): consider xml for refs instead of @dxn:echo:@:XXXXX
155
- return ToolResult.Success(`map @${id}`);
156
- },
157
- }),
158
- ],
159
- });
160
-
161
- const scriptArtifact = defineArtifact({
162
- id: 'artifact:dxos.org/plugin/script',
163
- name: 'Script',
164
- instructions: 'Use this to create and manage scripts',
165
- schema: Schema.Struct({}),
166
- tools: [],
167
- });
168
-
169
- // session.streamEvent.on((event) => {
170
- // printStreamEvent(event);
171
- // });
172
-
173
- const printer = new ConsolePrinter();
174
- session.message.on((message) => printer.printMessage(message));
175
- session.userMessage.on((message) => printer.printMessage(message));
176
- session.block.on((block) => printer.printContentBlock(block));
177
-
178
- // session.update.on((update) => {
179
- // log('update', { update });
180
- // });
181
-
182
- // Test creating an itinerary
183
- const response = await session.run({
184
- client: aiClient,
185
- tools: [],
186
- artifacts: [calendarArtifact, tableArtifact, mapArtifact, scriptArtifact],
187
- requiredArtifactIds: [calendarArtifact.id, tableArtifact.id, mapArtifact.id, scriptArtifact.id],
188
- history: [],
189
- generationOptions: {
190
- model: '@anthropic/claude-3-5-haiku-20241022',
191
- },
192
- prompt: 'create a table and map for a travel itinerary based on events in my calendar',
193
- toolResolver: new ToolRegistry([]),
194
- });
195
-
196
- log('result', {
197
- objects,
198
- finalMessage: response.at(-1),
199
- });
200
- });
201
- });
202
-
203
- // Travel to rome, florence, livorno, siena, madrid for conferences
204
- const CALENDAR_EVENTS: CalendarEvent[] = [
205
- Obj.make(CalendarEventSchema, {
206
- title: 'Exploring Ancient Ruins in Rome',
207
- startTime: '2024-01-01T10:00:00Z',
208
- endTime: '2024-01-01T11:00:00Z',
209
- description: 'Tech conference at the historic Colosseum with networking opportunities',
210
- }),
211
- Obj.make(CalendarEventSchema, {
212
- title: 'Renaissance Tech Summit in Florence',
213
- startTime: '2024-01-01T11:00:00Z',
214
- endTime: '2024-01-01T12:00:00Z',
215
- description: 'Discussing AI innovations surrounded by Renaissance art',
216
- }),
217
- Obj.make(CalendarEventSchema, {
218
- title: 'Travel to Livorno',
219
- startTime: '2024-01-01T12:00:00Z',
220
- endTime: '2024-01-01T13:00:00Z',
221
- description: 'Travel to Livorno',
222
- }),
223
- Obj.make(CalendarEventSchema, {
224
- title: 'Travel to Siena',
225
- startTime: '2024-01-01T13:00:00Z',
226
- endTime: '2024-01-01T14:00:00Z',
227
- description: 'Travel to Siena',
228
- }),
229
- Obj.make(CalendarEventSchema, {
230
- title: 'Travel to Madrid',
231
- startTime: '2024-01-01T14:00:00Z',
232
- endTime: '2024-01-01T15:00:00Z',
233
- description: 'Travel to Madrid',
234
- }),
235
- ];
236
-
237
- // const printStreamEvent = (event: GenerationStreamEvent) => {
238
- // switch (event.type) {
239
- // case 'message_start': {
240
- // process.stdout.write(`${event.message.role.toUpperCase()}\n\n`);
241
- // for (const content of event.message.content) {
242
- // printContentBlock(content);
243
- // }
244
- // break;
245
- // }
246
- // case 'content_block_start': {
247
- // printContentBlock(event.content);
248
- // break;
249
- // }
250
- // case 'content_block_delta': {
251
- // switch (event.delta.type) {
252
- // case 'text_delta': {
253
- // process.stdout.write(event.delta.text);
254
- // break;
255
- // }
256
- // case 'input_json_delta': {
257
- // process.stdout.write(event.delta.partial_json);
258
- // break;
259
- // }
260
- // }
261
- // break;
262
- // }
263
- // case 'content_block_stop': {
264
- // process.stdout.write('\n');
265
- // break;
266
- // }
267
- // case 'message_delta': {
268
- // break;
269
- // }
270
- // case 'message_stop': {
271
- // process.stdout.write('\n\n');
272
- // break;
273
- // }
274
- // }
275
- // };