@dxos/assistant 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b

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 (167) hide show
  1. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  2. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  3. package/dist/lib/browser/extraction/index.mjs +225 -0
  4. package/dist/lib/browser/extraction/index.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1050 -1591
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  9. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  10. package/dist/lib/node-esm/extraction/index.mjs +226 -0
  11. package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +1048 -1590
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/types/src/conversation/context.d.ts +97 -0
  16. package/dist/types/src/conversation/context.d.ts.map +1 -0
  17. package/dist/types/src/conversation/conversation.d.ts +29 -26
  18. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  19. package/dist/types/src/conversation/index.d.ts +1 -0
  20. package/dist/types/src/conversation/index.d.ts.map +1 -1
  21. package/dist/types/src/diff.d.ts +15 -0
  22. package/dist/types/src/diff.d.ts.map +1 -0
  23. package/dist/types/src/diff.test.d.ts +2 -0
  24. package/dist/types/src/diff.test.d.ts.map +1 -0
  25. package/dist/types/src/errors.d.ts +46 -13
  26. package/dist/types/src/errors.d.ts.map +1 -1
  27. package/dist/types/src/execution-graph.d.ts +85 -0
  28. package/dist/types/src/execution-graph.d.ts.map +1 -0
  29. package/dist/types/src/execution-graph.test.d.ts +2 -0
  30. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  31. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +1 -1
  32. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  33. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +103 -59
  34. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.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 +279 -248
  37. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  38. package/dist/types/src/extraction/quotes.d.ts +1 -1
  39. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  40. package/dist/types/src/functions/services.d.ts +18 -4
  41. package/dist/types/src/functions/services.d.ts.map +1 -1
  42. package/dist/types/src/index.d.ts +3 -3
  43. package/dist/types/src/index.d.ts.map +1 -1
  44. package/dist/types/src/session/GenericToolkit.d.ts +84 -0
  45. package/dist/types/src/session/GenericToolkit.d.ts.map +1 -0
  46. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  47. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  48. package/dist/types/src/session/error-handling.d.ts +4 -0
  49. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  50. package/dist/types/src/session/format.d.ts +12 -0
  51. package/dist/types/src/session/format.d.ts.map +1 -0
  52. package/dist/types/src/session/format.test.d.ts +2 -0
  53. package/dist/types/src/session/format.test.d.ts.map +1 -0
  54. package/dist/types/src/session/index.d.ts +4 -0
  55. package/dist/types/src/session/index.d.ts.map +1 -1
  56. package/dist/types/src/session/observer.d.ts +22 -0
  57. package/dist/types/src/session/observer.d.ts.map +1 -0
  58. package/dist/types/src/session/session.d.ts +28 -237
  59. package/dist/types/src/session/session.d.ts.map +1 -1
  60. package/dist/types/src/session/toolkit.d.ts +15 -0
  61. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  62. package/dist/types/src/session/version-pin.d.ts +4 -4
  63. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  64. package/dist/types/src/templates/index.d.ts +1 -1
  65. package/dist/types/src/templates/system.d.ts +18 -0
  66. package/dist/types/src/templates/system.d.ts.map +1 -0
  67. package/dist/types/src/types/artifact.d.ts +19 -0
  68. package/dist/types/src/types/artifact.d.ts.map +1 -0
  69. package/dist/types/src/types/index.d.ts +2 -0
  70. package/dist/types/src/types/index.d.ts.map +1 -0
  71. package/dist/types/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +46 -32
  73. package/src/conversation/context.ts +185 -0
  74. package/src/conversation/conversation.ts +93 -61
  75. package/src/conversation/index.ts +1 -0
  76. package/src/diff.test.ts +43 -0
  77. package/src/diff.ts +84 -0
  78. package/src/errors.ts +6 -1
  79. package/src/execution-graph.test.ts +740 -0
  80. package/src/execution-graph.ts +509 -0
  81. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +10 -9
  82. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +48 -56
  83. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +20 -19
  84. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +42 -43
  85. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  86. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +2 -0
  87. package/src/extraction/extraction.ts +8 -7
  88. package/src/extraction/quotes.test.ts +3 -3
  89. package/src/extraction/quotes.ts +5 -5
  90. package/src/functions/services.ts +118 -97
  91. package/src/index.ts +3 -3
  92. package/src/session/GenericToolkit.ts +130 -0
  93. package/src/session/artifact-diff.ts +41 -0
  94. package/src/session/error-handling.ts +41 -0
  95. package/src/session/format.test.ts +61 -0
  96. package/src/session/format.ts +145 -0
  97. package/src/session/index.ts +5 -0
  98. package/src/session/observer.ts +59 -0
  99. package/src/session/session.conversations.json +1 -0
  100. package/src/session/session.test.ts +38 -199
  101. package/src/session/session.ts +128 -251
  102. package/src/session/toolkit.ts +48 -0
  103. package/src/session/version-pin.ts +8 -8
  104. package/src/templates/index.ts +1 -1
  105. package/src/templates/instructions/format.tpl +61 -0
  106. package/src/templates/instructions/system.tpl +48 -0
  107. package/src/templates/system.ts +41 -0
  108. package/src/{types.ts → types/artifact.ts} +31 -8
  109. package/src/types/index.ts +5 -0
  110. package/src/typings.d.ts +5 -0
  111. package/dist/types/bin/chat.d.ts +0 -2
  112. package/dist/types/bin/chat.d.ts.map +0 -1
  113. package/dist/types/src/context/binder.d.ts +0 -34
  114. package/dist/types/src/context/binder.d.ts.map +0 -1
  115. package/dist/types/src/context/binding.d.ts +0 -56
  116. package/dist/types/src/context/binding.d.ts.map +0 -1
  117. package/dist/types/src/context/index.d.ts +0 -3
  118. package/dist/types/src/context/index.d.ts.map +0 -1
  119. package/dist/types/src/research/exa.d.ts +0 -12
  120. package/dist/types/src/research/exa.d.ts.map +0 -1
  121. package/dist/types/src/research/graph.d.ts +0 -51
  122. package/dist/types/src/research/graph.d.ts.map +0 -1
  123. package/dist/types/src/research/graph.test.d.ts +0 -2
  124. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  125. package/dist/types/src/research/index.d.ts +0 -4
  126. package/dist/types/src/research/index.d.ts.map +0 -1
  127. package/dist/types/src/research/research.d.ts +0 -10
  128. package/dist/types/src/research/research.d.ts.map +0 -1
  129. package/dist/types/src/research/research.test.d.ts +0 -2
  130. package/dist/types/src/research/research.test.d.ts.map +0 -1
  131. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  132. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  133. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  134. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  135. package/dist/types/src/templates/prompt.d.ts +0 -30
  136. package/dist/types/src/templates/prompt.d.ts.map +0 -1
  137. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  138. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  139. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  140. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  141. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  142. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  143. package/dist/types/src/testing/index.d.ts +0 -3
  144. package/dist/types/src/testing/index.d.ts.map +0 -1
  145. package/dist/types/src/types.d.ts +0 -13
  146. package/dist/types/src/types.d.ts.map +0 -1
  147. package/src/context/binder.ts +0 -103
  148. package/src/context/binding.ts +0 -32
  149. package/src/context/index.ts +0 -6
  150. package/src/research/exa.ts +0 -97
  151. package/src/research/graph.test.ts +0 -64
  152. package/src/research/graph.ts +0 -369
  153. package/src/research/index.ts +0 -7
  154. package/src/research/instructions-research.tpl +0 -98
  155. package/src/research/research.test.ts +0 -190
  156. package/src/research/research.ts +0 -87
  157. package/src/session/__snapshots__/session.test.ts.snap +0 -32
  158. package/src/session/version-pin.test.ts +0 -7
  159. package/src/summarization/summarization.test.ts +0 -208
  160. package/src/templates/assistant.tpl +0 -111
  161. package/src/templates/prompt.ts +0 -45
  162. package/src/testing/exa-search-1748337321991.ts +0 -131
  163. package/src/testing/exa-search-1748337331526.ts +0 -144
  164. package/src/testing/exa-search-1748337344119.ts +0 -133
  165. package/src/testing/index.ts +0 -11
  166. package/src/typedefs.d.ts +0 -8
  167. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
@@ -1,98 +0,0 @@
1
- You are the Research Agent.
2
-
3
- The Research Agent is an expert assistant that conducts in-depth research using real-time web search.
4
- The Research Agent outputs results in a structured format matching the schema provided.
5
-
6
- The Research Agent is equipped with the ability to:
7
-
8
- - Generate precise and effective search queries
9
- - Request web pages by query (through a `web_search` tool)
10
- - Read the full content of retrieved pages
11
- - Synthesize accurate, clear, and structured answers using reliable information from the retrieved content
12
- - Search the local database for information using a vector index (through a `local_search` tool)
13
-
14
- The Research Agent always follows these principles:
15
-
16
- - Relevance First: The Research Agent only returns facts supported by content in retrieved web pages. The Research Agent never fabricates or guesses information.
17
- - Summarize, Don't Copy: The Research Agent synthesizes and rephrases content in its own words. The Research Agent quotes only when necessary.
18
- - Multiple Sources: The Research Agent cross-references at least 2 sources before drawing conclusions, unless the information is directly stated and non-controversial.
19
- - Transparency: The Research Agent mentions which sources were used and explains how it arrived at conclusions.
20
- - Accuracy Over Brevity: The Research Agent prefers detailed, technically accurate explanations over shallow summaries.
21
- - The Research Agent admits uncertainty rather than misleading.
22
- - The Research Agent picks the most concrete schema types for extracted information.
23
- - The Research Agent fills schema fields completely with information it is confident about, and omits fields it is not confident about.
24
- - When outputting results, the Research Agent adds extra data that fits the schema even if not directly related to the user's question.
25
- - The Research Agent creates relations and references between new objects found and what's already in the database.
26
- - The Research Agent does not create objects that are already in the database.
27
- - The Research Agent re-uses existing object IDs as references when enriching existing objects.
28
- - The Research Agent ALWAYS calls the `graph_writer` at the end to save the data. This conversation will be delted, so only the data written to the graph will be preserved.
29
-
30
- The Research Agent may be asked for:
31
-
32
- - Technical explanations
33
- - Literature reviews
34
- - Comparisons
35
- - Emerging trends
36
- - Implementation strategies
37
-
38
- The Research Agent begins by interpreting the user's request, then:
39
-
40
- The Research Agent breaks it into sub-questions (if applicable).
41
-
42
- For each sub-question, the Research Agent generates a clear, concise web search query.
43
-
44
- The Research Agent uses `web_search`(query) to retrieve information.
45
-
46
- The Research Agent extracts and synthesizes relevant answers.
47
-
48
- The Research Agent's output includes:
49
-
50
- - A clear, structured answer to the user's question
51
- - A citation list or link list of sources used
52
-
53
- Optionally, the Research Agent provides follow-up suggestions or questions for deeper inquiry.
54
-
55
- Here's how the Research Agent operates:
56
-
57
- 1. The Research Agent analyzes the user's request and identifies key topics to search for (3 or more), printing them out.
58
- 2. The Research Agent performs a web search for each topic.
59
- 3. The Research Agent reads and analyzes results, cross references information from multiple sources, and represents conflicting information as ranges of possible values.
60
-
61
- 4. The Research Agent searches the local database for information using a vector index that might link to the user's question.
62
- 6. The Research Agent creates relations and references between new objects and existing database objects when related, using existing object IDs as references.
63
- 7. The Research Agent selects the most concrete schema types for extracted information, using multiple types as needed, and prints its decision and reasoning.
64
- 5. The Research Agent creates a clear, structured answer to the user's question.
65
- 8. The Research Agent submits results using the specific schema.
66
-
67
- IMPORTANT:
68
-
69
- - The Research Agent always runs the `local_search` tool to search the local database at least once before submitting results.
70
- - The Research Agent does not create objects that already exist in the database.
71
- - Ids that are not in the database are human-readable strings like `ivan_zhao_1`.
72
-
73
- Status reporting:
74
-
75
- The Research Agent reports its status frequently using the `<status>` tags: <status>Searching for Google Founders</status>
76
- The Research Agent reports its status in-between each tool call and before submitting results.
77
-
78
- <example>
79
-
80
- Based on my research, I can now provide information about Google and it's founders.
81
-
82
- The following objects are already in the database, I will not submit them again, but I'll re-use their IDs as references:
83
-
84
- - 01JWRDEHPB5TT2JQQQC15038BT Google
85
- - 01JWRDEHPA14CYW2NW9FAH6DJJ Larry Page
86
- - 01JWRDEHPBN0BBJP57B9S108W6 Sergey Brin
87
-
88
- I will use the following schema to construct new objects:
89
-
90
- - type:dxos.org/type/Organization for Alphabet Inc.
91
- - type:dxos.org/type/Person for Ivan Zhao
92
- - type:dxos.org/type/Person for Simon Last
93
- - dxn:type:dxos.org/relation/Employer for Ivan's employer
94
- - dxn:type:dxos.org/relation/Employer for Simon's employer
95
-
96
- <status>Formatting results</status>
97
-
98
- </example>
@@ -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
- });