@dxos/assistant 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6

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 (211) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  3. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-KVYJFFLF.mjs +1805 -0
  5. package/dist/lib/neutral/chunk-KVYJFFLF.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 +551 -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 +112 -0
  12. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  13. package/dist/types/src/conversation/context.d.ts +148 -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/conversation.d.ts +53 -25
  18. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  19. package/dist/types/src/conversation/conversation.test.d.ts +2 -0
  20. package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
  21. package/dist/types/src/conversation/index.d.ts +1 -0
  22. package/dist/types/src/conversation/index.d.ts.map +1 -1
  23. package/dist/types/src/diff.d.ts +17 -0
  24. package/dist/types/src/diff.d.ts.map +1 -0
  25. package/dist/types/src/diff.test.d.ts +2 -0
  26. package/dist/types/src/diff.test.d.ts.map +1 -0
  27. package/dist/types/src/errors.d.ts +47 -18
  28. package/dist/types/src/errors.d.ts.map +1 -1
  29. package/dist/types/src/execution-graph.d.ts +85 -0
  30. package/dist/types/src/execution-graph.d.ts.map +1 -0
  31. package/dist/types/src/execution-graph.test.d.ts +2 -0
  32. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  33. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  34. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +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 +1060 -273
  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/services.d.ts +37 -4
  43. package/dist/types/src/functions/services.d.ts.map +1 -1
  44. package/dist/types/src/functions.test.d.ts +2 -0
  45. package/dist/types/src/functions.test.d.ts.map +1 -0
  46. package/dist/types/src/index.d.ts +5 -3
  47. package/dist/types/src/index.d.ts.map +1 -1
  48. package/dist/types/src/service/AgentService.d.ts +62 -0
  49. package/dist/types/src/service/AgentService.d.ts.map +1 -0
  50. package/dist/types/src/service/AgentService.test.d.ts +2 -0
  51. package/dist/types/src/service/AgentService.test.d.ts.map +1 -0
  52. package/dist/types/src/service/agent-process.d.ts +17 -0
  53. package/dist/types/src/service/agent-process.d.ts.map +1 -0
  54. package/dist/types/src/service/index.d.ts +3 -0
  55. package/dist/types/src/service/index.d.ts.map +1 -0
  56. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  57. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  58. package/dist/types/src/session/error-handling.d.ts +4 -0
  59. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  60. package/dist/types/src/session/format.d.ts +12 -0
  61. package/dist/types/src/session/format.d.ts.map +1 -0
  62. package/dist/types/src/session/format.test.d.ts +2 -0
  63. package/dist/types/src/session/format.test.d.ts.map +1 -0
  64. package/dist/types/src/session/index.d.ts +4 -0
  65. package/dist/types/src/session/index.d.ts.map +1 -1
  66. package/dist/types/src/session/observer.d.ts +23 -0
  67. package/dist/types/src/session/observer.d.ts.map +1 -0
  68. package/dist/types/src/session/session.d.ts +87 -235
  69. package/dist/types/src/session/session.d.ts.map +1 -1
  70. package/dist/types/src/session/toolkit.d.ts +18 -0
  71. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  72. package/dist/types/src/session/version-pin.d.ts +4 -4
  73. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  74. package/dist/types/src/templates/index.d.ts +1 -1
  75. package/dist/types/src/templates/system.d.ts +17 -0
  76. package/dist/types/src/templates/system.d.ts.map +1 -0
  77. package/dist/types/src/testing/index.d.ts +1 -2
  78. package/dist/types/src/testing/index.d.ts.map +1 -1
  79. package/dist/types/src/testing/layer.d.ts +35 -0
  80. package/dist/types/src/testing/layer.d.ts.map +1 -0
  81. package/dist/types/src/tracing.d.ts +264 -0
  82. package/dist/types/src/tracing.d.ts.map +1 -0
  83. package/dist/types/src/types/artifact.d.ts +28 -0
  84. package/dist/types/src/types/artifact.d.ts.map +1 -0
  85. package/dist/types/src/types/index.d.ts +2 -0
  86. package/dist/types/src/types/index.d.ts.map +1 -0
  87. package/dist/types/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +58 -35
  89. package/src/conversation/context.test.ts +46 -0
  90. package/src/conversation/context.ts +369 -0
  91. package/src/conversation/conversation.test.ts +65 -0
  92. package/src/conversation/conversation.ts +232 -62
  93. package/src/conversation/index.ts +1 -0
  94. package/src/diff.test.ts +74 -0
  95. package/src/diff.ts +93 -0
  96. package/src/errors.ts +6 -1
  97. package/src/execution-graph.test.ts +740 -0
  98. package/src/execution-graph.ts +509 -0
  99. package/src/extraction/extraction-ner-function/index.ts +0 -1
  100. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  101. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +2 -0
  102. package/src/extraction/extraction.ts +44 -15
  103. package/src/extraction/index.ts +0 -1
  104. package/src/extraction/quotes.test.ts +3 -3
  105. package/src/extraction/quotes.ts +6 -7
  106. package/src/functions/services.ts +286 -96
  107. package/src/functions.conversations.json +1 -0
  108. package/src/functions.test.ts +82 -0
  109. package/src/index.ts +5 -3
  110. package/src/service/AgentService.conversations.json +1 -0
  111. package/src/service/AgentService.test.ts +169 -0
  112. package/src/service/AgentService.ts +171 -0
  113. package/src/service/agent-process.ts +360 -0
  114. package/src/service/index.ts +6 -0
  115. package/src/session/artifact-diff.ts +41 -0
  116. package/src/session/error-handling.ts +41 -0
  117. package/src/session/format.test.ts +133 -0
  118. package/src/session/format.ts +143 -0
  119. package/src/session/index.ts +4 -0
  120. package/src/session/observer.ts +62 -0
  121. package/src/session/session.conversations.json +1 -0
  122. package/src/session/session.test.ts +82 -201
  123. package/src/session/session.ts +282 -270
  124. package/src/session/toolkit.ts +44 -0
  125. package/src/session/version-pin.ts +8 -8
  126. package/src/templates/index.ts +1 -1
  127. package/src/templates/instructions/format.tpl +57 -0
  128. package/src/templates/instructions/system.tpl +57 -0
  129. package/src/templates/system.ts +42 -0
  130. package/src/testing/index.ts +2 -8
  131. package/src/testing/layer.ts +263 -0
  132. package/src/tracing.ts +112 -0
  133. package/src/types/artifact.ts +89 -0
  134. package/src/types/index.ts +5 -0
  135. package/src/typings.d.ts +5 -0
  136. package/dist/lib/browser/index.mjs +0 -1831
  137. package/dist/lib/browser/index.mjs.map +0 -7
  138. package/dist/lib/browser/meta.json +0 -1
  139. package/dist/lib/node-esm/index.mjs +0 -1833
  140. package/dist/lib/node-esm/index.mjs.map +0 -7
  141. package/dist/lib/node-esm/meta.json +0 -1
  142. package/dist/types/bin/chat.d.ts +0 -2
  143. package/dist/types/bin/chat.d.ts.map +0 -1
  144. package/dist/types/src/context/binder.d.ts +0 -34
  145. package/dist/types/src/context/binder.d.ts.map +0 -1
  146. package/dist/types/src/context/binding.d.ts +0 -56
  147. package/dist/types/src/context/binding.d.ts.map +0 -1
  148. package/dist/types/src/context/index.d.ts +0 -3
  149. package/dist/types/src/context/index.d.ts.map +0 -1
  150. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  151. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  152. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  153. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  154. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  155. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  156. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -302
  157. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  158. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  159. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  160. package/dist/types/src/research/exa.d.ts +0 -12
  161. package/dist/types/src/research/exa.d.ts.map +0 -1
  162. package/dist/types/src/research/graph.d.ts +0 -51
  163. package/dist/types/src/research/graph.d.ts.map +0 -1
  164. package/dist/types/src/research/graph.test.d.ts +0 -2
  165. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  166. package/dist/types/src/research/index.d.ts +0 -4
  167. package/dist/types/src/research/index.d.ts.map +0 -1
  168. package/dist/types/src/research/research.d.ts +0 -10
  169. package/dist/types/src/research/research.d.ts.map +0 -1
  170. package/dist/types/src/research/research.test.d.ts +0 -2
  171. package/dist/types/src/research/research.test.d.ts.map +0 -1
  172. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  173. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  174. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  175. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  176. package/dist/types/src/templates/prompt.d.ts +0 -30
  177. package/dist/types/src/templates/prompt.d.ts.map +0 -1
  178. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  179. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  180. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  181. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  182. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  183. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  184. package/dist/types/src/types.d.ts +0 -13
  185. package/dist/types/src/types.d.ts.map +0 -1
  186. package/src/context/binder.ts +0 -103
  187. package/src/context/binding.ts +0 -32
  188. package/src/context/index.ts +0 -6
  189. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -83
  190. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -70
  191. package/src/extraction/extraction-llm-function/index.ts +0 -5
  192. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  193. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -57
  194. package/src/research/exa.ts +0 -97
  195. package/src/research/graph.test.ts +0 -64
  196. package/src/research/graph.ts +0 -369
  197. package/src/research/index.ts +0 -7
  198. package/src/research/instructions-research.tpl +0 -98
  199. package/src/research/research.test.ts +0 -190
  200. package/src/research/research.ts +0 -87
  201. package/src/session/__snapshots__/session.test.ts.snap +0 -32
  202. package/src/session/version-pin.test.ts +0 -7
  203. package/src/summarization/summarization.test.ts +0 -208
  204. package/src/templates/assistant.tpl +0 -111
  205. package/src/templates/prompt.ts +0 -45
  206. package/src/testing/exa-search-1748337321991.ts +0 -131
  207. package/src/testing/exa-search-1748337331526.ts +0 -144
  208. package/src/testing/exa-search-1748337344119.ts +0 -133
  209. package/src/typedefs.d.ts +0 -8
  210. package/src/types.ts +0 -47
  211. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
@@ -1,190 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { AnthropicClient } from '@effect/ai-anthropic';
6
- import { FetchHttpClient } from '@effect/platform';
7
- import { Config, Layer, ManagedRuntime } from 'effect';
8
- import { inspect } from 'node:util';
9
- import { afterAll, beforeAll, describe, test } from 'vitest';
10
-
11
- import { AiService, AiServiceRouter, structuredOutputParser } from '@dxos/ai';
12
- import { EXA_API_KEY, tapHttpErrors } from '@dxos/ai/testing';
13
- import { Obj } from '@dxos/echo';
14
- import { type EchoDatabase } from '@dxos/echo-db';
15
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
16
- import { getSchemaDXN } from '@dxos/echo-schema';
17
- import { ConfiguredCredentialsService, FunctionExecutor, ServiceContainer, TracingService } from '@dxos/functions';
18
- import { DataType, DataTypes } from '@dxos/schema';
19
-
20
- import { createExtractionSchema, getSanitizedSchemaName } from './graph';
21
- import { researchFn } from './research';
22
-
23
- const MOCK_SEARCH = false;
24
-
25
- const AnthropicLayer = AnthropicClient.layerConfig({
26
- apiKey: Config.redacted('ANTHROPIC_API_KEY'),
27
- transformClient: tapHttpErrors,
28
- });
29
-
30
- const AiServiceLayer = AiServiceRouter.AiServiceRouter.pipe(
31
- Layer.provide(AnthropicLayer),
32
- Layer.provide(FetchHttpClient.layer),
33
- );
34
-
35
- describe.skip('Research', () => {
36
- let runtime: ManagedRuntime.ManagedRuntime<AiService, any>;
37
- let builder: EchoTestBuilder;
38
- let db: EchoDatabase;
39
- let executor: FunctionExecutor;
40
-
41
- beforeAll(async () => {
42
- runtime = ManagedRuntime.make(AiServiceLayer);
43
-
44
- // TODO(dmaretskyi): Helper to scaffold this from a config.
45
- builder = await new EchoTestBuilder().open();
46
-
47
- db = (await builder.createDatabase({ indexing: { vector: true } })).db;
48
-
49
- executor = new FunctionExecutor(
50
- new ServiceContainer().setServices({
51
- ai: await runtime.runPromise(AiService),
52
- credentials: new ConfiguredCredentialsService([{ service: 'exa.ai', apiKey: EXA_API_KEY }]),
53
- database: { db },
54
- tracing: TracingService.console,
55
- }),
56
- );
57
- });
58
-
59
- afterAll(async () => {
60
- await runtime.dispose();
61
- });
62
-
63
- // TODO(dmaretskyi): Refactor using effect.
64
- test.only('should generate a research report', { timeout: 300_000 }, async () => {
65
- db.add(Obj.make(DataType.Organization, { name: 'Notion', website: 'https://www.notion.com' }));
66
- await db.flush({ indexes: true });
67
-
68
- const result = await executor.invoke(researchFn, {
69
- query: 'Who are the founders of Notion?',
70
- mockSearch: MOCK_SEARCH,
71
- });
72
-
73
- console.log(inspect(result, { depth: null, colors: true }));
74
- console.log(JSON.stringify(result, null, 2));
75
- });
76
- });
77
-
78
- describe('misc', () => {
79
- test('createExtractionSchema', () => {
80
- const _schema = createExtractionSchema(DataTypes);
81
- // log.info('schema', { schema });
82
- });
83
-
84
- test('extract schema json schema', () => {
85
- const schema = createExtractionSchema(DataTypes);
86
- const _parser = structuredOutputParser(schema);
87
- // log.info('schema', { json: parser.tool.parameters });
88
- });
89
-
90
- test('getSanitizedSchemaName', () => {
91
- const _names = DataTypes.map(getSanitizedSchemaName);
92
- // log.info('names', { names });
93
- });
94
-
95
- test('getTypeAnnotation', () => {
96
- for (const schema of DataTypes) {
97
- const _dxn = getSchemaDXN(schema);
98
- // log.info('dxn', { schema, dxn });
99
- }
100
- });
101
-
102
- test.skip('sanitizeObjects', () => {
103
- const _TEST_DATA = {
104
- objects_dxos_org_type_Project: [
105
- {
106
- name: 'Reor',
107
- description:
108
- 'A private & local AI personal knowledge management app focused on high entropy thinkers. Features include Q&A chat with full context of notes, automatic connection of ideas, semantic search, and local-first architecture with LLMs and vector databases.',
109
- image: 'https://reorhomepage-2-cwy0zagzg-reor-team.vercel.app/opengraph-image.jpg',
110
- id: 'reor-project-01',
111
- },
112
- {
113
- name: 'Personal AI',
114
- description:
115
- 'A platform for creating personal AI models with unlimited memory capabilities. Features include memory stacking, data uploads, and personalized language models that can be trained on individual knowledge bases.',
116
- image: 'https://cdn.prod.website-files.com/5ff65c460ce39f5ec5681c6a/663d12aab1b425e1ad40d3a6_Memory-min.jpg',
117
- id: 'personal-ai-project-01',
118
- },
119
- {
120
- name: 'IKI AI',
121
- description:
122
- 'An AI-native workspace for research, strategy, and creative work. Offers features like AI summarization, content analysis, and team knowledge sharing capabilities.',
123
- image: 'https://framerusercontent.com/assets/cI6Uo7x4q0W3uxzOt2preXjv6aE.jpg',
124
- id: 'iki-ai-project-01',
125
- },
126
- {
127
- name: 'Forethink',
128
- description:
129
- 'A privacy-first, on-device AI system that proactively links current activities to relevant knowledge. Features real-time learning across teams and local data processing.',
130
- image: 'https://framerusercontent.com/assets/XDhN6tICnlElB134JWcWXOuXc.jpeg',
131
- id: 'forethink-project-01',
132
- },
133
- {
134
- name: 'Amurex',
135
- description:
136
- 'An invisible AI companion that handles tasks, remembers important information, and supports workflow. Includes features for meeting automation, email categorization, and cross-platform search.',
137
- image: 'https://amurex.ai/ogimages/og_amurex.jpg',
138
- id: 'amurex-project-01',
139
- },
140
- ],
141
- objects_dxos_org_type_Organization: [
142
- {
143
- name: 'Reor',
144
- description:
145
- 'A technology company focused on developing local-first AI solutions for personal knowledge management.',
146
- status: 'active',
147
- website: 'https://www.reorproject.org',
148
- id: 'reor-org-01',
149
- },
150
- {
151
- name: 'Personal.ai',
152
- description: 'A company specializing in personal AI development and memory management solutions.',
153
- status: 'active',
154
- website: 'https://www.personal.ai',
155
- id: 'personal-ai-org-01',
156
- },
157
- {
158
- name: 'IKI AI',
159
- description: 'A startup backed by 500 Global, developing AI-native workspaces for knowledge workers.',
160
- status: 'active',
161
- website: 'https://iki.ai',
162
- id: 'iki-ai-org-01',
163
- },
164
- {
165
- name: 'Forethink.ai',
166
- description:
167
- 'A company focused on privacy-first AI solutions for knowledge management and team collaboration.',
168
- status: 'active',
169
- website: 'https://www.forethink.ai',
170
- id: 'forethink-org-01',
171
- },
172
- ],
173
- objects_dxos_org_type_Text: [
174
- {
175
- content:
176
- 'Current trends in AI-powered Personal Knowledge Management (PKM) systems include: 1) Shift from document-based to graph-based systems for better knowledge connection, 2) Integration of large language models for enhanced content understanding and retrieval, 3) Focus on privacy-first and local-first architectures, 4) Emphasis on automatic knowledge connection and discovery, 5) Implementation of semantic search capabilities.',
177
- id: 'pkm-trends-text-01',
178
- },
179
- {
180
- content:
181
- 'Key features emerging across modern PKM tools include: automated content categorization, semantic analysis and linking, personalized AI models that learn from user interaction, integration with existing workflows, and robust privacy protection. These tools are increasingly focusing on proactive knowledge surfacing rather than passive storage.',
182
- id: 'pkm-features-text-01',
183
- },
184
- ],
185
- };
186
-
187
- // const data = await sanitizeObjects(TYPES, TEST_DATA, db);
188
- // log.info('data', { data });
189
- });
190
- });
@@ -1,87 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- // TODO(burdon): Fix.
6
- // @ts-nocheck
7
-
8
- import { AiToolkit } from '@effect/ai';
9
- import { Effect, Layer, Schema } from 'effect';
10
-
11
- import { AiService, ConsolePrinter } from '@dxos/ai';
12
- import { defineFunction, TracingService } from '@dxos/functions';
13
- import { log } from '@dxos/log';
14
- import { DataTypes } from '@dxos/schema';
15
-
16
- import { ExaToolkit, LiveExaHandler, MockExaHandler } from './exa';
17
- import { LocalSearchHandler, LocalSearchToolkit, makeGraphWriterHandler, makeGraphWriterToolkit } from './graph';
18
- // TODO(dmaretskyi): Vite build bug with instruction files with the same filename getting mixed-up
19
- import PROMPT from './instructions-research.tpl?raw';
20
- import { AiSession } from '../session';
21
-
22
- /**
23
- * Exec external service and return the results as a Subgraph.
24
- */
25
- // TODO(burdon): Rename.
26
- export const researchFn = defineFunction({
27
- description: 'Research the web for information',
28
- inputSchema: Schema.Struct({
29
- query: Schema.String.annotations({
30
- description: 'The query to search for.',
31
- }),
32
-
33
- // TOOD(burdon): Move to context.
34
- mockSearch: Schema.optional(Schema.Boolean).annotations({
35
- description: 'Whether to use the mock search tool.',
36
- default: false,
37
- }),
38
- }),
39
- outputSchema: Schema.Struct({
40
- result: Schema.Unknown,
41
- }),
42
- handler: Effect.fnUntraced(
43
- function* ({ data: { query, mockSearch } }) {
44
- yield* TracingService.emitStatus({ message: 'Researching...' });
45
-
46
- const graphWriteToolkit = makeGraphWriterToolkit({ schema: DataTypes });
47
- const toolkit = yield* AiToolkit.merge(ExaToolkit, LocalSearchToolkit, graphWriteToolkit).pipe(
48
- Effect.provide(
49
- Layer.mergeAll(
50
- mockSearch ? MockExaHandler : LiveExaHandler,
51
- LocalSearchHandler,
52
- makeGraphWriterHandler(graphWriteToolkit),
53
- ),
54
- ),
55
- );
56
-
57
- const printer = new ConsolePrinter();
58
- const session = new AiSession();
59
- session.message.on((message) => printer.printMessage(message));
60
- session.userMessage.on((message) => printer.printMessage(message));
61
- session.block.on((block) => printer.printContentBlock(block));
62
- session.streamEvent.on((event) => log('stream', { event }));
63
-
64
- // TODO(dmaretskyi): Consider adding this pattern as the "Graph" output mode for the session.
65
- const result = yield* session.run({
66
- prompt: query,
67
- history: [],
68
- systemPrompt: PROMPT,
69
- toolkit,
70
- });
71
-
72
- return {
73
- result,
74
- };
75
-
76
- // queues.contextQueue!.append(data);
77
-
78
- // return {
79
- // result: `
80
- // The research results are placed in the following objects:
81
- // ${data.map((object, id) => `[obj_${id}][dxn:echo:@:${object.id}]`).join('\n')}
82
- // `,
83
- // };
84
- },
85
- Effect.provide(AiService.model('@anthropic/claude-3-5-sonnet-20241022')),
86
- ),
87
- });
@@ -1,32 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`AiSession > no tools 1`] = `
4
- [
5
- {
6
- "blocks": ReactiveArray [
7
- {
8
- "_tag": "text",
9
- "text": "Hello world!",
10
- },
11
- ],
12
- "created": "Sun, 20 Jul 2025 10:54:08 GMT",
13
- "id": "01K0KQGFTFV3GBKGEWZW67K8HK",
14
- "sender": {
15
- "role": "user",
16
- },
17
- },
18
- {
19
- "blocks": ReactiveArray [
20
- {
21
- "_tag": "text",
22
- "text": "Hi there! How can I help you today?",
23
- },
24
- ],
25
- "created": "2025-07-20T10:54:10.801Z",
26
- "id": "01K0KQGHVHJ37D4YG45WG090WV",
27
- "sender": {
28
- "role": "assistant",
29
- },
30
- },
31
- ]
32
- `;
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { describe } from 'vitest';
6
-
7
- describe('VersionPin', () => {});
@@ -1,208 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- // TODO(burdon): Fix.
6
- // @ts-nocheck
7
-
8
- import { pipe, Schema } from 'effect';
9
- import { beforeAll, describe, test } from 'vitest';
10
-
11
- import { AiService, MixedStreamParser } from '@dxos/ai';
12
- import { Obj } from '@dxos/echo';
13
- import { type EchoDatabase } from '@dxos/echo-db';
14
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
15
- import { defineFunction, FunctionExecutor, ServiceContainer } from '@dxos/functions';
16
- import { type ContentBlock, DataType } from '@dxos/schema';
17
- import { createTestData } from '@dxos/schema/testing';
18
- import { trim } from '@dxos/util';
19
-
20
- const REMOTE_AI = true;
21
-
22
- const summarizationFn = defineFunction({
23
- description: 'Summarize a document',
24
- inputSchema: Schema.Struct({
25
- document: Schema.optional(DataType.Text),
26
- transcript: Schema.Array(DataType.Message),
27
- }),
28
- outputSchema: DataType.Text,
29
- handler: async ({ data: { document, transcript }, context }) => {
30
- const ai = context.getService(AiService);
31
- const result = await new MixedStreamParser().parse(
32
- await ai.client.execStream({
33
- model: '@anthropic/claude-3-5-haiku-20241022',
34
- // TODO(burdon): Factor out and test prompts.
35
- systemPrompt: trim`
36
- Your job is to summarize a meeting transcript.
37
- Transcript Summarizer updates an existing summary within <summary> tags with a new transcript that is placed in <transcript> tags.
38
- Transcript Summarizer updates only the relevant parts of the summary.
39
- If there's no summary, create a new one.
40
- Transcript Summarizer outputs only the summary texts and nothing else.
41
- Transcript Summarizer keeps the original summary structure.
42
- Transcript Summarizer keeps the unrelated parts of the summary untouched.
43
- The Transcript Summarizer errs on the side of being too verbose.
44
- The Transcript Summarizer outputs the entire update summary.
45
- The summary is formatted as hierarchical markdown bullet points with no headings.
46
- The hierarchical structure is deeply nested.
47
- The Transcript Summarizer formats the bullets with "-" symbol as prefix and two spaces indentation.
48
- The Transcript Summarizer knows that the content of transcript will be updated solely by its output.
49
- The Transcript Summarizer outputs only the summary text.
50
- `,
51
- history: [
52
- Obj.make(DataType.Message, {
53
- created: new Date().toISOString(),
54
- sender: { role: 'user' },
55
- blocks: [
56
- {
57
- _tag: 'text',
58
- text: trim`
59
- <transcript>
60
- ${JSON.stringify(transcript, null, 2)}
61
- </transcript>
62
- `,
63
- },
64
- ...(document != null && document.content.length > 0
65
- ? [
66
- {
67
- _tag: 'text',
68
- text: trim`
69
- <summary>
70
- ${document.content}
71
- </summary>
72
- `,
73
- } satisfies ContentBlock.Text,
74
- ]
75
- : []),
76
- ],
77
- }),
78
- ],
79
- }),
80
- );
81
- return Obj.make(DataType.Text, {
82
- content: pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : '')),
83
- });
84
- },
85
- });
86
-
87
- const refinementFn = defineFunction({
88
- description: 'Refine a summary',
89
- inputSchema: Schema.Struct({
90
- summaries: Schema.Array(DataType.Text),
91
- }),
92
- outputSchema: Schema.Struct({
93
- summary: DataType.Text,
94
- }),
95
- handler: async ({ data: { summaries }, context }) => {
96
- const ai = context.getService(AiService);
97
- const result = await new MixedStreamParser().parse(
98
- await ai.client.execStream({
99
- model: '@anthropic/claude-3-5-haiku-20241022',
100
- // TODO(burdon): Factor out and test prompts.
101
- systemPrompt: trim`
102
- You are a Transcript Summary Refiner.
103
- Transcript Summary Refiner works on a history of evolving summaries that were generated based on the transcript.
104
- The summaries are presented starting from the oldest to the newest.
105
- Each iteration of the summary contains a new part of the transcript.
106
- The Transcript Summary Refiner refines the summary based on the history of summaries.
107
- The Transcript Summary Refiner identifies any potential data lost between the iterations and adds its back to the output.
108
- The Transcript Summary Refiner updates the summary to be more structured.
109
- The Transcript Summary Refiner errs on the side of being too verbose.
110
- The Transcript Summary Refiner errs on keeping the original summary structure.
111
- The Transcript Summary Refiner outputs the entire update summary.
112
- The Transcript Summary is formatted as hierarchical markdown bullet points with no headings.
113
- The hierarchical structure is deeply nested.
114
- The Transcript Summary Refiner formats the bullets with "-" symbol as prefix and two spaces indentation.
115
- The Transcript Summary Refiner knows that the content of transcript will be updated solely by its output.
116
- The Transcript Summary Refiner outputs only the summary text.
117
- `,
118
- history: [
119
- Obj.make(DataType.Message, {
120
- created: new Date().toISOString(),
121
- sender: { role: 'user' },
122
- blocks: summaries.map(
123
- (summary) =>
124
- ({
125
- _tag: 'text',
126
- text: trim`
127
- <summary>
128
- ${summary.content}
129
- </summary>
130
- `,
131
- }) satisfies ContentBlock.Text,
132
- ),
133
- }),
134
- ],
135
- }),
136
- );
137
- return {
138
- summary: Obj.make(DataType.Text, {
139
- content: pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : '')),
140
- }),
141
- };
142
- },
143
- });
144
-
145
- describe.skip('Summarization', () => {
146
- let builder: EchoTestBuilder;
147
- let db: EchoDatabase;
148
- let executor: FunctionExecutor;
149
-
150
- // TODO(burdon): Rewrite test.
151
- beforeAll(async () => {
152
- // TODO(dmaretskyi): Helper to scaffold this from a config.
153
- builder = await new EchoTestBuilder().open();
154
- const { db: db1 } = await builder.createDatabase({ indexing: { vector: true } });
155
- db = db1;
156
- executor = new FunctionExecutor(
157
- new ServiceContainer().setServices({
158
- ai: todo(),
159
- database: {
160
- db,
161
- },
162
- }),
163
- );
164
- });
165
-
166
- test('keeps transcript outline', { timeout: 1000_000 }, async () => {
167
- const { transcriptMessages } = createTestData();
168
-
169
- const summary = Obj.make(DataType.Text, {
170
- content: '',
171
- });
172
-
173
- const summaries = [];
174
-
175
- for (let i = 0; i < transcriptMessages.length; i++) {
176
- const blocks = transcriptMessages.slice(Math.max(0, i - 2), i + 1);
177
- const result = await executor.invoke(summarizationFn, {
178
- document: summary,
179
- transcript: blocks,
180
- });
181
- summary.content = result.content;
182
- summaries.push(Obj.make(DataType.Text, { content: result.content }));
183
-
184
- console.log(blocks.at(-1));
185
- console.log();
186
- console.log('--------------------------------');
187
- console.log();
188
- console.log(summary.content);
189
- console.log();
190
-
191
- if (i % 3 === 0 && i > 0) {
192
- const history: any = summaries.slice(-5);
193
- const result = await executor.invoke(refinementFn, {
194
- summaries: history,
195
- });
196
- summary.content = result.summary.content;
197
- summaries.push(Obj.make(DataType.Text, { content: result.summary.content }));
198
-
199
- console.log('REFINED');
200
- console.log();
201
- console.log('--------------------------------');
202
- console.log();
203
- console.log(summary.content);
204
- console.log();
205
- }
206
- }
207
- });
208
- });
@@ -1,111 +0,0 @@
1
- {{! System Prompt }}
2
-
3
- You are a friendly, advanced AI assistant capable of creating and managing artifacts from available data and tools.
4
- Your task is to process user commands and questions and decide how best to respond.
5
- In some cases, you will need to create or reference data objects called artifacts.
6
-
7
- Follow these guidelines carefully:
8
-
9
- {{section}}. Decision-making:
10
-
11
- {{#if cot}}
12
- Before responding, explain your reasoning and include your detailed chain-of-thought in a <cot> tag.
13
- {{/if}}
14
-
15
- Include the following steps:
16
-
17
- - Analyze the structure and type of the content in the user's message.
18
- - Can you complete the task using the available artifact definitions?
19
- - If you can't complete the task using the available artifact definitions, query the list of available artifact definitions using the appropriate tool.
20
- - Identify which artifact definitions are relevant to the user's request.
21
- - Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.
22
- - Make a final decision on whether to create an artifact and explain your reasoning.
23
- - Are the required artifact definitions already available?
24
- - If not, select which artifact definition(s) will be the most relevant and require them using the require_artifact_definitions tool.
25
- - The require'd artifact tools will be available for use after require.
26
- - If creating an artifact, outline how you will structure it within the response.
27
- - Decide if the artifact needs to be shown to the user.
28
- - Call the show tool to show the artifact to the user.
29
- - If you ask the user a multiple choice question, then present each of the possible answers as concise text inside <option> tags inside a well formed <select> tag.
30
- - If you have suggestions for follow-up actions then present each action as text within a <suggest> tag.
31
- - Your reasoning must include: whether to use artifacts or not, to create one or query, whether to show the artifact to the user, and how to structure the response.
32
-
33
- If the user asks for a list of tools, then just emit a single self-closing <tool-list/> tag instead of listing the tools.The tag will be replaced with the list of tools when the response is rendered.
34
- Do not list the tools or artifacts in your response, only emit the tag.
35
- Do not mention the tag anywhere else in your response unless you are rendering a tool list.
36
-
37
- {{section}}. Artifacts:
38
-
39
- - Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.
40
- - Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.
41
- - If it is ambiguous, query for existing artifacts first and then decide.
42
- - If you decide to create an artifact, call the associated tool to create the artifact.
43
- - Artifacts are stored in the database. Tools are used to create and query artifacts.
44
- - If you are unsure about creating an artifact ask the user for clarification.
45
-
46
- {{#if artifacts}}
47
- {{section}}. Artifact Rules:
48
-
49
- - Artifacts are mutable objects that can change over the course of the conversation.
50
- - Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.
51
- - You must never generate the id of the artifact; only recall the ids that are already in the history.
52
- - Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.
53
-
54
- {{section}}. Artifact Providers:
55
-
56
- {{#each artifacts}}
57
- - {{this}}
58
- {{/each}}
59
- {{/if}}
60
-
61
- {{#if associatedArtifact}}
62
- {{section}}. Associated artifact:
63
-
64
- The following ID and typename identify the artifact associated with this conversation.
65
- This conversation appears alongside the associated artifact as a peer, and the user is likely to make reference to and requests about it.
66
- You can interact with this artifact using tools.
67
-
68
- ID: {{associatedArtifact.id}}
69
- Typename: {{associatedArtifact.typename}}
70
- {{/if}}
71
-
72
- {{#if suggestions}}
73
- {{section}}. Suggested actions:
74
-
75
- - You can add suggested actions at the end of your response.
76
- - Suggested actions should be very concise and start with a verb and be phrased as a command to an agent -- not a question to the user.
77
- - Suggested actions must be in the form of a user instruction that you can follow.
78
- - Suggested actions could include actions that create artifacts.
79
- - Suggested actions must be enclosed in a <suggest> tag and on a separate line.
80
- Examples:
81
- <suggest>Show the data on a map.</suggest>
82
- <suggest>Create a kanban from the table.</suggest>
83
-
84
- - If you have asked a multiple choice question, then present each of the possible answers as concise text inside <option> tags inside a well formed <select> tag.
85
- Example:
86
- <select><option>Yes</option><option>No</option></select>
87
- {{/if}}
88
-
89
- {{section}}. Content proposals:
90
-
91
- You can propose content to add to associated artifacts. Enclose the content you are proposing to add in a <proposal> tag on a separate line.
92
- For example:
93
- <proposal>Apples add a delightful crunch and natural sweetness to salads</proposal>
94
-
95
- {{section}}. Output Formats:
96
-
97
- It is very important to respond in the correct format.
98
-
99
- {{#if cot}}
100
- - Your detailed chain-of-thought must be in the form of a markdown list enclosed in <cot> tags.
101
- - The <cot> tag should be the first thing in your response.
102
- {{/if}}
103
- - Suggested actions must be enclosed in a <suggest> tag and on a separate line.
104
- - Content proposals must be enclosed in a <proposal> tag and on a separate line.
105
-
106
- References:
107
-
108
- - Both user and you can reference external data in the markdown format: [label][URI].
109
- - If you get references back from a tool call, you can render them as is by preserving the ID literally.
110
-
111
- {{instructions}}
@@ -1,45 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type AssociatedArtifact, Template } from '@dxos/blueprints';
6
-
7
- import ASSISTANT from './assistant.tpl?raw';
8
-
9
- /**
10
- * Type for assistant prompt variables.
11
- */
12
- // TODO(burdon): Replace with builder?
13
- export type AssistantPromptOptions = {
14
- /**
15
- * Instructions for each artifact.
16
- */
17
- // TODO(burdon): Change to blueprint.
18
- artifacts?: string[];
19
-
20
- /**
21
- * Associated artifact to include in the prompt.
22
- * @deprecated
23
- */
24
- artifact?: AssociatedArtifact;
25
-
26
- /**
27
- * Whether to include suggestions in the prompt.
28
- */
29
- suggestions?: boolean;
30
-
31
- /**
32
- * Additional instructions to include in the prompt.
33
- */
34
- instructions?: string;
35
-
36
- /**
37
- * Emit chain-of-thought inside <cot> tag.
38
- * Should be `false` for models with built-in reasoning: Claude, deepseek, o1.
39
- */
40
- cot?: boolean;
41
- };
42
-
43
- export const createSystemPrompt = (options: AssistantPromptOptions) => {
44
- return Template.createPrompt(ASSISTANT, options);
45
- };