@dxos/assistant 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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 (152) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/extraction/index.mjs +202 -0
  3. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  4. package/dist/lib/neutral/index.mjs +1736 -0
  5. package/dist/lib/neutral/index.mjs.map +7 -0
  6. package/dist/lib/neutral/meta.json +1 -0
  7. package/dist/types/src/conversation/context.d.ts +124 -64
  8. package/dist/types/src/conversation/context.d.ts.map +1 -1
  9. package/dist/types/src/conversation/context.test.d.ts +2 -0
  10. package/dist/types/src/conversation/context.test.d.ts.map +1 -0
  11. package/dist/types/src/conversation/index.d.ts +1 -1
  12. package/dist/types/src/conversation/index.d.ts.map +1 -1
  13. package/dist/types/src/conversation/session.d.ts +73 -0
  14. package/dist/types/src/conversation/session.d.ts.map +1 -0
  15. package/dist/types/src/diff.d.ts +3 -1
  16. package/dist/types/src/diff.d.ts.map +1 -1
  17. package/dist/types/src/errors.d.ts +40 -48
  18. package/dist/types/src/errors.d.ts.map +1 -1
  19. package/dist/types/src/execution-graph.d.ts +85 -0
  20. package/dist/types/src/execution-graph.d.ts.map +1 -0
  21. package/dist/types/src/execution-graph.test.d.ts +2 -0
  22. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  23. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  24. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  25. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  26. package/dist/types/src/extraction/extraction.d.ts +1066 -303
  27. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  28. package/dist/types/src/extraction/index.d.ts +0 -1
  29. package/dist/types/src/extraction/index.d.ts.map +1 -1
  30. package/dist/types/src/extraction/quotes.d.ts +3 -3
  31. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  32. package/dist/types/src/functions/services.d.ts +15 -5
  33. package/dist/types/src/functions/services.d.ts.map +1 -1
  34. package/dist/types/src/index.d.ts +3 -1
  35. package/dist/types/src/index.d.ts.map +1 -1
  36. package/dist/types/src/session/artifact-diff.d.ts +2 -2
  37. package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
  38. package/dist/types/src/session/error-handling.d.ts +2 -2
  39. package/dist/types/src/session/error-handling.d.ts.map +1 -1
  40. package/dist/types/src/session/format.d.ts +8 -175
  41. package/dist/types/src/session/format.d.ts.map +1 -1
  42. package/dist/types/src/session/index.d.ts +2 -1
  43. package/dist/types/src/session/index.d.ts.map +1 -1
  44. package/dist/types/src/session/observer.d.ts +7 -6
  45. package/dist/types/src/session/observer.d.ts.map +1 -1
  46. package/dist/types/src/session/request.d.ts +104 -0
  47. package/dist/types/src/session/request.d.ts.map +1 -0
  48. package/dist/types/src/session/toolkit.d.ts +11 -9
  49. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  50. package/dist/types/src/session/version-pin.d.ts +4 -4
  51. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  52. package/dist/types/src/templates/system.d.ts +1 -2
  53. package/dist/types/src/templates/system.d.ts.map +1 -1
  54. package/dist/types/src/tracing.d.ts +233 -0
  55. package/dist/types/src/tracing.d.ts.map +1 -0
  56. package/dist/types/src/types/artifact.d.ts +28 -0
  57. package/dist/types/src/types/artifact.d.ts.map +1 -0
  58. package/dist/types/src/types/index.d.ts +2 -0
  59. package/dist/types/src/types/index.d.ts.map +1 -0
  60. package/dist/types/tsconfig.tsbuildinfo +1 -1
  61. package/package.json +35 -46
  62. package/src/conversation/context.test.ts +52 -0
  63. package/src/conversation/context.ts +324 -75
  64. package/src/conversation/index.ts +1 -1
  65. package/src/conversation/session.ts +323 -0
  66. package/src/diff.test.ts +37 -6
  67. package/src/diff.ts +18 -4
  68. package/src/errors.ts +4 -4
  69. package/src/execution-graph.test.ts +740 -0
  70. package/src/execution-graph.ts +519 -0
  71. package/src/extraction/extraction-ner-function/index.ts +0 -1
  72. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  73. package/src/extraction/extraction.ts +44 -15
  74. package/src/extraction/index.ts +0 -1
  75. package/src/extraction/quotes.test.ts +2 -2
  76. package/src/extraction/quotes.ts +6 -7
  77. package/src/functions/services.ts +156 -61
  78. package/src/index.ts +3 -1
  79. package/src/session/artifact-diff.ts +2 -2
  80. package/src/session/error-handling.ts +11 -6
  81. package/src/session/format.ts +35 -27
  82. package/src/session/index.ts +2 -1
  83. package/src/session/observer.ts +8 -4
  84. package/src/session/request.ts +347 -0
  85. package/src/session/toolkit.ts +32 -27
  86. package/src/session/version-pin.ts +7 -7
  87. package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
  88. package/src/templates/instructions/system.tpl +96 -0
  89. package/src/templates/system.ts +9 -8
  90. package/src/tracing.ts +57 -0
  91. package/src/{types.ts → types/artifact.ts} +44 -7
  92. package/src/types/index.ts +5 -0
  93. package/dist/lib/browser/chunk-5GJYG2ML.mjs +0 -396
  94. package/dist/lib/browser/chunk-5GJYG2ML.mjs.map +0 -7
  95. package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
  96. package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
  97. package/dist/lib/browser/extraction/index.mjs +0 -268
  98. package/dist/lib/browser/extraction/index.mjs.map +0 -7
  99. package/dist/lib/browser/index.mjs +0 -469
  100. package/dist/lib/browser/index.mjs.map +0 -7
  101. package/dist/lib/browser/meta.json +0 -1
  102. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
  103. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs.map +0 -7
  104. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
  105. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
  106. package/dist/lib/node-esm/chunk-FLFCEB4P.mjs +0 -398
  107. package/dist/lib/node-esm/chunk-FLFCEB4P.mjs.map +0 -7
  108. package/dist/lib/node-esm/extraction/index.mjs +0 -269
  109. package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
  110. package/dist/lib/node-esm/index.mjs +0 -470
  111. package/dist/lib/node-esm/index.mjs.map +0 -7
  112. package/dist/lib/node-esm/meta.json +0 -1
  113. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
  114. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
  115. package/dist/types/src/conversation/conversation.d.ts +0 -42
  116. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  117. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  118. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  119. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  120. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  121. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  122. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  123. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -337
  124. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  125. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  126. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  127. package/dist/types/src/session/format.test.d.ts +0 -2
  128. package/dist/types/src/session/format.test.d.ts.map +0 -1
  129. package/dist/types/src/session/session.d.ts +0 -47
  130. package/dist/types/src/session/session.d.ts.map +0 -1
  131. package/dist/types/src/session/session.test.d.ts +0 -2
  132. package/dist/types/src/session/session.test.d.ts.map +0 -1
  133. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  134. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  135. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  136. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  137. package/dist/types/src/types.d.ts +0 -16
  138. package/dist/types/src/types.d.ts.map +0 -1
  139. package/src/conversation/conversation.ts +0 -123
  140. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
  141. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -70
  142. package/src/extraction/extraction-llm-function/index.ts +0 -5
  143. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  144. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -62
  145. package/src/session/__snapshots__/session.test.ts.snap +0 -32
  146. package/src/session/format.test.ts +0 -60
  147. package/src/session/session.test.ts +0 -308
  148. package/src/session/session.ts +0 -201
  149. package/src/session/version-pin.test.ts +0 -7
  150. package/src/summarization/summarization.test.ts +0 -197
  151. package/src/templates/system.tpl +0 -50
  152. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
@@ -1,197 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- // ISSUE(burdon): defineFunction
6
- // @ts-nocheck
7
-
8
- import { Schema, pipe } 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 { FunctionExecutor, ServiceContainer, defineFunction } 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 summarizationFn = defineFunction({
21
- description: 'Summarize a document',
22
- inputSchema: Schema.Struct({
23
- document: Schema.optional(DataType.Text),
24
- transcript: Schema.Array(DataType.Message),
25
- }),
26
- outputSchema: DataType.Text,
27
- handler: async ({ data: { document, transcript }, context }) => {
28
- const ai = context.getService(AiService.AiService);
29
- const result = await new MixedStreamParser().parse(
30
- await ai.client.execStream({
31
- model: '@anthropic/claude-3-5-haiku-20241022',
32
- // TODO(burdon): Factor out and test prompts.
33
- systemPrompt: trim`
34
- Your job is to summarize a meeting transcript.
35
- Transcript Summarizer updates an existing summary within <summary> tags with a new transcript that is placed in <transcript> tags.
36
- Transcript Summarizer updates only the relevant parts of the summary.
37
- If there's no summary, create a new one.
38
- Transcript Summarizer outputs only the summary texts and nothing else.
39
- Transcript Summarizer keeps the original summary structure.
40
- Transcript Summarizer keeps the unrelated parts of the summary untouched.
41
- The Transcript Summarizer errs on the side of being too verbose.
42
- The Transcript Summarizer outputs the entire update summary.
43
- The summary is formatted as hierarchical markdown bullet points with no headings.
44
- The hierarchical structure is deeply nested.
45
- The Transcript Summarizer formats the bullets with "-" symbol as prefix and two spaces indentation.
46
- The Transcript Summarizer knows that the content of transcript will be updated solely by its output.
47
- The Transcript Summarizer outputs only the summary text.
48
- `,
49
- history: [
50
- Obj.make(DataType.Message, {
51
- created: new Date().toISOString(),
52
- sender: { role: 'user' },
53
- blocks: [
54
- {
55
- _tag: 'text',
56
- text: trim`
57
- <transcript>
58
- ${JSON.stringify(transcript, null, 2)}
59
- </transcript>
60
- `,
61
- },
62
- ...(document != null && document.content.length > 0
63
- ? [
64
- {
65
- _tag: 'text',
66
- text: trim`
67
- <summary>
68
- ${document.content}
69
- </summary>
70
- `,
71
- } satisfies ContentBlock.Text,
72
- ]
73
- : []),
74
- ],
75
- }),
76
- ],
77
- }),
78
- );
79
-
80
- return DataType.makeText(pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : '')));
81
- },
82
- });
83
-
84
- const refinementFn = defineFunction({
85
- description: 'Refine a summary',
86
- inputSchema: Schema.Struct({
87
- summaries: Schema.Array(DataType.Text),
88
- }),
89
- outputSchema: Schema.Struct({
90
- summary: DataType.Text,
91
- }),
92
- handler: async ({ data: { summaries }, context }) => {
93
- const ai = context.getService(AiService.AiService);
94
- const result = await new MixedStreamParser().parse(
95
- await ai.client.execStream({
96
- model: '@anthropic/claude-3-5-haiku-20241022',
97
- // TODO(burdon): Factor out and test prompts.
98
- systemPrompt: trim`
99
- You are a Transcript Summary Refiner.
100
- Transcript Summary Refiner works on a history of evolving summaries that were generated based on the transcript.
101
- The summaries are presented starting from the oldest to the newest.
102
- Each iteration of the summary contains a new part of the transcript.
103
- The Transcript Summary Refiner refines the summary based on the history of summaries.
104
- The Transcript Summary Refiner identifies any potential data lost between the iterations and adds its back to the output.
105
- The Transcript Summary Refiner updates the summary to be more structured.
106
- The Transcript Summary Refiner errs on the side of being too verbose.
107
- The Transcript Summary Refiner errs on keeping the original summary structure.
108
- The Transcript Summary Refiner outputs the entire update summary.
109
- The Transcript Summary is formatted as hierarchical markdown bullet points with no headings.
110
- The hierarchical structure is deeply nested.
111
- The Transcript Summary Refiner formats the bullets with "-" symbol as prefix and two spaces indentation.
112
- The Transcript Summary Refiner knows that the content of transcript will be updated solely by its output.
113
- The Transcript Summary Refiner outputs only the summary text.
114
- `,
115
- history: [
116
- Obj.make(DataType.Message, {
117
- created: new Date().toISOString(),
118
- sender: { role: 'user' },
119
- blocks: summaries.map(
120
- (summary) =>
121
- ({
122
- _tag: 'text',
123
- text: trim`
124
- <summary>
125
- ${summary.content}
126
- </summary>
127
- `,
128
- }) satisfies ContentBlock.Text,
129
- ),
130
- }),
131
- ],
132
- }),
133
- );
134
- return {
135
- summary: DataType.makeText(pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : ''))),
136
- };
137
- },
138
- });
139
-
140
- describe.skip('Summarization', () => {
141
- let builder: EchoTestBuilder;
142
- let db: EchoDatabase;
143
- let executor: FunctionExecutor;
144
-
145
- // TODO(burdon): Rewrite test.
146
- beforeAll(async () => {
147
- // TODO(dmaretskyi): Helper to scaffold this from a config.
148
- builder = await new EchoTestBuilder().open();
149
- const { db: db1 } = await builder.createDatabase({ indexing: { vector: true } });
150
- db = db1;
151
- executor = new FunctionExecutor(
152
- new ServiceContainer().setServices({
153
- ai: todo(),
154
- database: {
155
- db,
156
- },
157
- }),
158
- );
159
- });
160
-
161
- test('keeps transcript outline', { timeout: 1000_000 }, async () => {
162
- const { transcriptMessages } = createTestData();
163
-
164
- const summary = DataType.makeText();
165
-
166
- const summaries = [];
167
-
168
- for (let i = 0; i < transcriptMessages.length; i++) {
169
- const blocks = transcriptMessages.slice(Math.max(0, i - 2), i + 1);
170
- const result = await executor.invoke(summarizationFn, {
171
- document: summary,
172
- transcript: blocks,
173
- });
174
- summary.content = result.content;
175
- summaries.push(DataType.makeText(result.content));
176
-
177
- console.log(blocks.at(-1));
178
- console.log();
179
- console.log(summary.content);
180
- console.log();
181
-
182
- if (i % 3 === 0 && i > 0) {
183
- const history: any = summaries.slice(-5);
184
- const result = await executor.invoke(refinementFn, {
185
- summaries: history,
186
- });
187
- summary.content = result.summary.content;
188
- summaries.push(DataType.makeText(result.summary.content));
189
-
190
- console.log('REFINED');
191
- console.log();
192
- console.log(summary.content);
193
- console.log();
194
- }
195
- }
196
- });
197
- });
@@ -1,50 +0,0 @@
1
- {{! System Prompt }}
2
-
3
- You are a helpful assistant called Kai.
4
- Your name is Kai and you are powered by different language models.
5
- You were created by DXOS and operate in Composer and on the DXOS EDGE network.
6
- In your initial greeting state your name and make some suggestions based on the current context objects.
7
-
8
- You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.
9
- Your task is to process user commands and questions and decide how best to respond.
10
- In general be concise and direct.
11
-
12
- Follow these instructions carefully.
13
-
14
- ## Include the following steps
15
-
16
- - Analyze the structure and type of the content in the user's message.
17
- - Determine if you complete the task using the available blueprint definitions?
18
- - If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.
19
- - Identify which blueprint definitions are relevant to the user's request.
20
- - Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.
21
- - Make a final decision on whether to create an artifact and explain your reasoning.
22
- - Are the required blueprint definitions already available?
23
- - If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.
24
- - The require'd artifact tools will be available for use after require.
25
- - If creating an artifact, outline how you will structure it within the response.
26
- - Decide if the artifact needs to be shown to the user.
27
- - Call the show tool to show the artifact to the user.
28
- - 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.
29
-
30
- ## Blueprints
31
-
32
- - Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.
33
- - Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.
34
- - If it is ambiguous, query for existing artifacts first and then decide.
35
- - If you decide to create an artifact, call the associated tool to create the artifact.
36
- - Artifacts are stored in the database. Tools are used to create and query artifacts.
37
- - If you are unsure about creating an artifact ask the user for clarification.
38
- - Artifacts are mutable objects that can change over the course of the conversation.
39
- - Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.
40
- - You must never generate the id of the artifact; only recall the ids that are already in the history.
41
- - Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.
42
- - You can add suggested actions at the end of your response.
43
- - 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.
44
- - Suggested actions must be in the form of a user instruction that you can follow.
45
- - Suggested actions could include actions that create artifacts.
46
- - After creating an artifact use a tool to add it to the chat context.
47
-
48
- ## Context
49
-
50
- Today is {{DATETIME}}.