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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/chunk-2TBLG3XY.mjs +1793 -0
  3. package/dist/lib/neutral/chunk-2TBLG3XY.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  5. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  6. package/dist/lib/neutral/extraction/index.mjs +219 -0
  7. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  8. package/dist/lib/neutral/index.mjs +537 -0
  9. package/dist/lib/neutral/index.mjs.map +7 -0
  10. package/dist/lib/neutral/meta.json +1 -0
  11. package/dist/lib/neutral/testing/index.mjs +111 -0
  12. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  13. package/dist/types/src/conversation/context.d.ts +155 -0
  14. package/dist/types/src/conversation/context.d.ts.map +1 -0
  15. package/dist/types/src/conversation/context.test.d.ts +2 -0
  16. package/dist/types/src/conversation/context.test.d.ts.map +1 -0
  17. package/dist/types/src/conversation/index.d.ts +2 -1
  18. package/dist/types/src/conversation/index.d.ts.map +1 -1
  19. package/dist/types/src/conversation/session.d.ts +78 -0
  20. package/dist/types/src/conversation/session.d.ts.map +1 -0
  21. package/dist/types/src/conversation/session.test.d.ts.map +1 -0
  22. package/dist/types/src/diff.d.ts +17 -0
  23. package/dist/types/src/diff.d.ts.map +1 -0
  24. package/dist/types/src/diff.test.d.ts +2 -0
  25. package/dist/types/src/diff.test.d.ts.map +1 -0
  26. package/dist/types/src/errors.d.ts +67 -0
  27. package/dist/types/src/errors.d.ts.map +1 -0
  28. package/dist/types/src/execution-graph.d.ts +85 -0
  29. package/dist/types/src/execution-graph.d.ts.map +1 -0
  30. package/dist/types/src/execution-graph.test.d.ts +2 -0
  31. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  32. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  33. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  34. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  36. package/dist/types/src/extraction/extraction.d.ts +1066 -215
  37. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  38. package/dist/types/src/extraction/index.d.ts +0 -1
  39. package/dist/types/src/extraction/index.d.ts.map +1 -1
  40. package/dist/types/src/extraction/quotes.d.ts +3 -3
  41. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  42. package/dist/types/src/functions/index.d.ts +2 -0
  43. package/dist/types/src/functions/index.d.ts.map +1 -0
  44. package/dist/types/src/functions/services.d.ts +17 -0
  45. package/dist/types/src/functions/services.d.ts.map +1 -0
  46. package/dist/types/src/functions.test.d.ts +2 -0
  47. package/dist/types/src/functions.test.d.ts.map +1 -0
  48. package/dist/types/src/index.d.ts +7 -5
  49. package/dist/types/src/index.d.ts.map +1 -1
  50. package/dist/types/src/service/AgentService.d.ts +75 -0
  51. package/dist/types/src/service/AgentService.d.ts.map +1 -0
  52. package/dist/types/src/service/AgentService.test.d.ts +2 -0
  53. package/dist/types/src/service/AgentService.test.d.ts.map +1 -0
  54. package/dist/types/src/service/agent-process.d.ts +21 -0
  55. package/dist/types/src/service/agent-process.d.ts.map +1 -0
  56. package/dist/types/src/service/index.d.ts +3 -0
  57. package/dist/types/src/service/index.d.ts.map +1 -0
  58. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  59. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  60. package/dist/types/src/session/error-handling.d.ts +4 -0
  61. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  62. package/dist/types/src/session/format.d.ts +16 -0
  63. package/dist/types/src/session/format.d.ts.map +1 -0
  64. package/dist/types/src/session/format.test.d.ts +2 -0
  65. package/dist/types/src/session/format.test.d.ts.map +1 -0
  66. package/dist/types/src/session/index.d.ts +5 -1
  67. package/dist/types/src/session/index.d.ts.map +1 -1
  68. package/dist/types/src/session/observer.d.ts +23 -0
  69. package/dist/types/src/session/observer.d.ts.map +1 -0
  70. package/dist/types/src/session/request.d.ts +106 -0
  71. package/dist/types/src/session/request.d.ts.map +1 -0
  72. package/dist/types/src/session/request.test.d.ts +2 -0
  73. package/dist/types/src/session/request.test.d.ts.map +1 -0
  74. package/dist/types/src/session/session-ollama.test.d.ts +2 -0
  75. package/dist/types/src/session/session-ollama.test.d.ts.map +1 -0
  76. package/dist/types/src/session/toolkit.d.ts +16 -0
  77. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  78. package/dist/types/src/session/version-pin.d.ts +5 -5
  79. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  80. package/dist/types/src/templates/index.d.ts +2 -0
  81. package/dist/types/src/templates/index.d.ts.map +1 -0
  82. package/dist/types/src/templates/system.d.ts +17 -0
  83. package/dist/types/src/templates/system.d.ts.map +1 -0
  84. package/dist/types/src/testing/index.d.ts +1 -2
  85. package/dist/types/src/testing/index.d.ts.map +1 -1
  86. package/dist/types/src/testing/layer.d.ts +40 -0
  87. package/dist/types/src/testing/layer.d.ts.map +1 -0
  88. package/dist/types/src/tracing.d.ts +223 -0
  89. package/dist/types/src/tracing.d.ts.map +1 -0
  90. package/dist/types/src/types/artifact.d.ts +28 -0
  91. package/dist/types/src/types/artifact.d.ts.map +1 -0
  92. package/dist/types/src/types/index.d.ts +2 -0
  93. package/dist/types/src/types/index.d.ts.map +1 -0
  94. package/dist/types/tsconfig.tsbuildinfo +1 -1
  95. package/package.json +60 -29
  96. package/src/conversation/context.test.ts +52 -0
  97. package/src/conversation/context.ts +403 -0
  98. package/src/conversation/index.ts +2 -1
  99. package/src/conversation/session.test.ts +58 -0
  100. package/src/conversation/session.ts +300 -0
  101. package/src/diff.test.ts +74 -0
  102. package/src/diff.ts +93 -0
  103. package/src/errors.ts +15 -0
  104. package/src/execution-graph.test.ts +740 -0
  105. package/src/execution-graph.ts +509 -0
  106. package/src/extraction/extraction-ner-function/index.ts +0 -1
  107. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  108. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +3 -1
  109. package/src/extraction/extraction.ts +44 -15
  110. package/src/extraction/index.ts +0 -1
  111. package/src/extraction/quotes.test.ts +3 -3
  112. package/src/extraction/quotes.ts +6 -7
  113. package/src/functions/index.ts +5 -0
  114. package/src/functions/services.ts +214 -0
  115. package/src/functions.conversations.json +1 -0
  116. package/src/functions.test.ts +88 -0
  117. package/src/index.ts +7 -5
  118. package/src/service/AgentService.conversations.json +1 -0
  119. package/src/service/AgentService.test.ts +169 -0
  120. package/src/service/AgentService.ts +184 -0
  121. package/src/service/agent-process.ts +364 -0
  122. package/src/service/index.ts +6 -0
  123. package/src/session/artifact-diff.ts +41 -0
  124. package/src/session/error-handling.ts +41 -0
  125. package/src/session/format.test.ts +132 -0
  126. package/src/session/format.ts +149 -0
  127. package/src/session/index.ts +5 -1
  128. package/src/session/observer.ts +62 -0
  129. package/src/session/request.conversations.json +1 -0
  130. package/src/session/request.test.ts +195 -0
  131. package/src/session/request.ts +344 -0
  132. package/src/session/session-ollama.test.ts +81 -0
  133. package/src/session/toolkit.ts +47 -0
  134. package/src/session/version-pin.ts +12 -12
  135. package/src/templates/index.ts +5 -0
  136. package/src/templates/instructions/format.tpl +57 -0
  137. package/src/templates/instructions/system.tpl +85 -0
  138. package/src/templates/system.ts +42 -0
  139. package/src/testing/index.ts +2 -8
  140. package/src/testing/layer.ts +236 -0
  141. package/src/tracing.ts +43 -0
  142. package/src/types/artifact.ts +89 -0
  143. package/src/types/index.ts +5 -0
  144. package/src/typings.d.ts +5 -0
  145. package/dist/lib/browser/index.mjs +0 -2019
  146. package/dist/lib/browser/index.mjs.map +0 -7
  147. package/dist/lib/browser/meta.json +0 -1
  148. package/dist/lib/node-esm/index.mjs +0 -2021
  149. package/dist/lib/node-esm/index.mjs.map +0 -7
  150. package/dist/lib/node-esm/meta.json +0 -1
  151. package/dist/types/bin/chat.d.ts +0 -2
  152. package/dist/types/bin/chat.d.ts.map +0 -1
  153. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  154. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  155. package/dist/types/src/blueprint/index.d.ts +0 -3
  156. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  157. package/dist/types/src/blueprint/registry.d.ts +0 -7
  158. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  159. package/dist/types/src/context/binder.d.ts +0 -34
  160. package/dist/types/src/context/binder.d.ts.map +0 -1
  161. package/dist/types/src/context/binding.d.ts +0 -38
  162. package/dist/types/src/context/binding.d.ts.map +0 -1
  163. package/dist/types/src/context/index.d.ts +0 -3
  164. package/dist/types/src/context/index.d.ts.map +0 -1
  165. package/dist/types/src/conversation/conversation.d.ts +0 -44
  166. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  167. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  168. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  169. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  170. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  171. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  172. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  173. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -208
  174. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  175. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  176. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  177. package/dist/types/src/research/exa.d.ts +0 -7
  178. package/dist/types/src/research/exa.d.ts.map +0 -1
  179. package/dist/types/src/research/graph.d.ts +0 -41
  180. package/dist/types/src/research/graph.d.ts.map +0 -1
  181. package/dist/types/src/research/graph.test.d.ts +0 -2
  182. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  183. package/dist/types/src/research/index.d.ts +0 -4
  184. package/dist/types/src/research/index.d.ts.map +0 -1
  185. package/dist/types/src/research/research.d.ts +0 -10
  186. package/dist/types/src/research/research.d.ts.map +0 -1
  187. package/dist/types/src/research/research.test.d.ts +0 -2
  188. package/dist/types/src/research/research.test.d.ts.map +0 -1
  189. package/dist/types/src/session/session.d.ts +0 -283
  190. package/dist/types/src/session/session.d.ts.map +0 -1
  191. package/dist/types/src/session/session.test.d.ts.map +0 -1
  192. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  193. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  194. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  195. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  196. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  197. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  198. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  199. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  200. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  201. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  202. package/dist/types/src/types.d.ts +0 -3
  203. package/dist/types/src/types.d.ts.map +0 -1
  204. package/src/blueprint/blueprint.ts +0 -75
  205. package/src/blueprint/index.ts +0 -6
  206. package/src/blueprint/registry.ts +0 -15
  207. package/src/context/binder.ts +0 -101
  208. package/src/context/binding.ts +0 -31
  209. package/src/context/index.ts +0 -6
  210. package/src/conversation/conversation.ts +0 -103
  211. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -95
  212. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -66
  213. package/src/extraction/extraction-llm-function/index.ts +0 -5
  214. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  215. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -54
  216. package/src/research/exa.ts +0 -100
  217. package/src/research/graph.test.ts +0 -15
  218. package/src/research/graph.ts +0 -337
  219. package/src/research/index.ts +0 -7
  220. package/src/research/instructions-research.tpl +0 -97
  221. package/src/research/research.test.ts +0 -190
  222. package/src/research/research.ts +0 -90
  223. package/src/session/session.test.ts +0 -275
  224. package/src/session/session.ts +0 -582
  225. package/src/session/version-pin.test.ts +0 -26
  226. package/src/summarization/summarization.test.ts +0 -221
  227. package/src/testing/exa-search-1748337321991.ts +0 -131
  228. package/src/testing/exa-search-1748337331526.ts +0 -144
  229. package/src/testing/exa-search-1748337344119.ts +0 -133
  230. package/src/typedefs.d.ts +0 -8
  231. package/src/types.ts +0 -8
  232. /package/dist/types/src/{session → conversation}/session.test.d.ts +0 -0
  233. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
@@ -2,12 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
- import { type MessageContentBlock } from '@dxos/ai';
8
- import { type ObjectVersion } from '@dxos/echo-db';
9
- import { getVersion } from '@dxos/echo-db';
10
- import { ObjectId, type BaseEchoObject } from '@dxos/echo-schema';
7
+ import { type Obj } from '@dxos/echo';
8
+ import { type ObjectVersion, getVersion } from '@dxos/echo-db';
9
+ import { ObjectId } from '@dxos/keys';
10
+ import { type ContentBlock } from '@dxos/types';
11
11
 
12
12
  // TODO(dmaretskyi): Extract.
13
13
  const ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;
@@ -15,7 +15,7 @@ const ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;
15
15
  const VersionPinSchema = Schema.Struct({
16
16
  // TODO(dmaretskyi): Use Ref when those support encoding.
17
17
  objectId: ObjectId,
18
- // TODO(dmaretskyi): Could be opaque
18
+ // TODO(dmaretskyi): Could be opaque.
19
19
  version: ObjectVersionSchema,
20
20
  });
21
21
 
@@ -27,22 +27,22 @@ export interface VersionPin extends Schema.Schema.Type<typeof VersionPinSchema>
27
27
 
28
28
  export const VersionPin: typeof VersionPinSchema & {
29
29
  DISPOSITION: 'version-pin';
30
- fromObject: (object: BaseEchoObject) => VersionPin;
31
- createBlock: (pin: VersionPin) => MessageContentBlock;
30
+ fromObject: (object: Obj.Unknown) => VersionPin;
31
+ createBlock: (pin: VersionPin) => ContentBlock.Any;
32
32
  } = class extends VersionPinSchema {
33
33
  static readonly DISPOSITION = 'version-pin';
34
- static fromObject(object: BaseEchoObject): VersionPin {
34
+ static fromObject(object: Obj.Unknown): VersionPin {
35
35
  return VersionPin.make({
36
36
  objectId: object.id,
37
37
  version: getVersion(object),
38
38
  });
39
39
  }
40
40
 
41
- static createBlock(pin: VersionPin): MessageContentBlock {
41
+ static createBlock(pin: VersionPin): ContentBlock.Any {
42
42
  return {
43
- type: 'json',
43
+ _tag: 'json',
44
44
  disposition: VersionPin.DISPOSITION,
45
- json: JSON.stringify(pin),
45
+ data: JSON.stringify(pin),
46
46
  };
47
47
  }
48
48
  };
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './system';
@@ -0,0 +1,57 @@
1
+ {{! System Core }}
2
+
3
+ ## Input Formats
4
+
5
+ ### Blueprints
6
+
7
+ You may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.
8
+ Blue print instructions will be enclosed in a <blueprint> tag.
9
+
10
+ ### Context objects
11
+
12
+ You may be provided with references to objects that are relevant to the current prompt.
13
+ Objects will be in the form of a <object> tag with a <dxn> element that is the unique key of the object required by many tools.
14
+ The <typename> element is the type of the object.
15
+
16
+ <object>
17
+ <dxn>object-id</dxn>
18
+ <typename>example.com/type/TypeName</typename>
19
+ </object>
20
+
21
+ ## Response Formats
22
+
23
+ It is very important to respond in the correct format.
24
+ You response must be valid Markdown.
25
+ In some cases you should respond with well-formed XML tags along with the content.
26
+ Code snippets should use 2-space indents.
27
+
28
+ {{#if cot}}
29
+ Before responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.
30
+ The <cot> tag should be the first thing in your response.
31
+ {{/if}}
32
+
33
+ ## Block references
34
+
35
+ You can reply with a block reference for objects if you have the DXN. For example:
36
+
37
+ <object>
38
+ <dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>
39
+ </object>
40
+ <object>
41
+ <dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>
42
+ </object>
43
+
44
+ ### Suggestions
45
+
46
+ Each suggestion must in the form of a proposed action enclosed in a <suggestion> tag.
47
+ Example: <suggestion>Show on a map</suggestion>
48
+ Do not use bullets when listing suggestions.
49
+
50
+ ### Multiple choice questions
51
+
52
+ You may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.
53
+ Example: <select><option>Yes</option><option>No</option></select>
54
+
55
+ ## Context
56
+
57
+ The current date and time is {{DATETIME}}.
@@ -0,0 +1,85 @@
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 inside of 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
+ - You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.
8
+ - Your task is to process user commands and questions and decide how best to respond.
9
+ - In general be concise and direct.
10
+ - Follow all instructions carefully.
11
+
12
+ ## Planning
13
+
14
+ - Analyze the structure and type of the content in the user's message.
15
+ - Determine if you complete the task using the available blueprint definitions?
16
+ - If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.
17
+ - Identify which blueprint definitions are relevant to the user's request.
18
+ - Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.
19
+ - Make a final decision on whether to create an artifact and explain your reasoning.
20
+ - Are the required blueprint definitions already available?
21
+ - If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.
22
+ - The require'd artifact tools will be available for use after require.
23
+ - If creating an artifact, outline how you will structure it within the response.
24
+ - Decide if the artifact needs to be shown to the user.
25
+ - Call the show tool to show the artifact to the user.
26
+ - 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.
27
+
28
+ ## Blueprints and Artifacts
29
+
30
+ - Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.
31
+ - Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.
32
+ - If it is ambiguous, query for existing artifacts first and then decide.
33
+ - If you decide to create an artifact, call the associated tool to create the artifact.
34
+ - Artifacts are stored in the database. Tools are used to create and query artifacts.
35
+ - If you are unsure about creating an artifact ask the user for clarification.
36
+ - Artifacts are mutable objects that can change over the course of the conversation.
37
+ - Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.
38
+ - You must never generate the id of the artifact; only recall the ids that are already in the history.
39
+ - Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.
40
+ - You can add suggested actions at the end of your response.
41
+ - 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.
42
+ - Suggested actions must be in the form of a user instruction that you can follow.
43
+ - Suggested actions could include actions that create artifacts.
44
+ - After creating an artifact use a tool to add it to the chat context.
45
+
46
+ ## Navigation
47
+
48
+ - When the user asks to open, go to, navigate to, or show a specific document, page, or object, use the navigation tools instead of loading content inline.
49
+ - First, call the Resolve navigation targets tool to find the navigation path for the requested item.
50
+ - Without arguments, it returns available pages that can be navigated to.
51
+ - With a DXN in the query, it resolves that specific object to a navigation path.
52
+ - If you know the object's DXN (e.g. from a database query or context objects), pass it in the query to get the exact navigation path.
53
+ - Then, call the Open tool with the resolved navigation path(s) in the subject array to navigate the user to that item.
54
+ - Do not respond with the document's content when the user asks to open it — open it in the main content area instead.
55
+ - If multiple targets match, present the options to the user and let them choose which to open.
56
+
57
+ ## Response format
58
+
59
+ - When updating the user about the progress of the work you are doing, put the update in a <status> XML tag.
60
+ - Only when you need to show the result to the user or ask a question use a text block without status tags.
61
+
62
+ <example>
63
+ // reasoning...
64
+ <status>Looking for emails from Depot</status>
65
+ // tool call..
66
+ <status>Found 2 emails from Depot.</status>
67
+ <status>Loading email details</status>
68
+ // tool call
69
+ <status>Located mailbox</status>
70
+ I found **2 emails from Depot**:
71
+ </example>
72
+
73
+ Do not do (no status tags):
74
+
75
+ <incorrect_example>
76
+ // reasoning...
77
+ // tool call..
78
+ I found 2 emails from Depot. Let me load their details:
79
+ // tool call
80
+ I found **2 emails from Depot**:
81
+ </incorrect_example>
82
+
83
+ - Avoid using plain text to tell the user what you are about to do; instead, use status blocks.
84
+ - WRONG: Let me get...
85
+ - CORRECT: <status>Getting...</status>
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import defaultsDeep from 'lodash.defaultsdeep';
6
+
7
+ import { type ModelCapabilities } from '@dxos/ai';
8
+ import { Template } from '@dxos/blueprints';
9
+
10
+ import FORMAT from './instructions/format.tpl?raw';
11
+ import SYSTEM from './instructions/system.tpl?raw';
12
+
13
+ /**
14
+ * System template variables.
15
+ */
16
+ export type SystemPromptOptions = ModelCapabilities & {
17
+ DATETIME: string;
18
+ };
19
+
20
+ /**
21
+ * Base system prompt.
22
+ * NOTE: This contains protocol instructions that can not be dynamically edited.
23
+ */
24
+ export const createSystemPrompt = (options: Partial<SystemPromptOptions> = {}) =>
25
+ Template.process<SystemPromptOptions>(
26
+ FORMAT,
27
+ defaultsDeep(options, {
28
+ DATETIME: new Date().toISOString(),
29
+ }),
30
+ );
31
+
32
+ /**
33
+ * NOTE: We are forbidden from accessing randomness at model level in cloudflare, so we have to have pre-generated ids.
34
+ */
35
+ const SYSTEM_ID = '01K2J2FZWH39F55CS7B26GP1Q3';
36
+
37
+ export const templates = {
38
+ system: Template.make({
39
+ id: SYSTEM_ID,
40
+ source: SYSTEM,
41
+ }),
42
+ };
@@ -1,11 +1,5 @@
1
1
  //
2
- // Copyright 2025 DXOS.org
2
+ // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
- import type { SearchResponse } from 'exa-js';
6
-
7
- import Search1 from './exa-search-1748337321991';
8
- import Search2 from './exa-search-1748337331526';
9
- import Search3 from './exa-search-1748337344119';
10
-
11
- export const SEARCH_RESULTS: SearchResponse<any>[] = [Search1, Search2, Search3];
5
+ export * from './layer';
@@ -0,0 +1,236 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { Registry } from '@effect-atom/atom';
6
+ import * as LanguageModel from '@effect/ai/LanguageModel';
7
+ import * as KeyValueStore from '@effect/platform/KeyValueStore';
8
+ import * as Array from 'effect/Array';
9
+ import * as Context from 'effect/Context';
10
+ import * as Effect from 'effect/Effect';
11
+ import * as Layer from 'effect/Layer';
12
+ import * as Match from 'effect/Match';
13
+
14
+ import { AiService, ConsolePrinter, OpaqueToolkit, type ModelName } from '@dxos/ai';
15
+ import { TestAiService } from '@dxos/ai/testing';
16
+ import { Blueprint, Prompt } from '@dxos/blueprints';
17
+ import { Database, DXN, Feed, Tag, Type } from '@dxos/echo';
18
+ import { acquireReleaseResource } from '@dxos/effect';
19
+ import type { TestContextService } from '@dxos/effect/testing';
20
+ import {
21
+ CredentialsService,
22
+ QueueService,
23
+ type ServiceCredential,
24
+ ServiceNotAvailableError,
25
+ Trace,
26
+ Trigger,
27
+ } from '@dxos/functions';
28
+ import {
29
+ FeedTraceSink,
30
+ Process,
31
+ ProcessManager,
32
+ ServiceResolver,
33
+ TriggerDispatcher,
34
+ TriggerStateStore,
35
+ } from '@dxos/functions-runtime';
36
+ import { TestDatabaseLayer } from '@dxos/functions-runtime/testing';
37
+ import { Operation, OperationHandlerSet, OperationRegistry } from '@dxos/operation';
38
+
39
+ import { AiContextBinder, AiContextService, AiSession, AiSessionService } from '../conversation';
40
+ import { AgentService } from '../service';
41
+ import { CompleteBlock } from '../tracing';
42
+
43
+ interface TestLayerOptions {
44
+ aiServicePreset?: 'direct' | 'edge-local' | 'edge-remote' | 'ollama';
45
+ model?: ModelName;
46
+ operationHandlers?: OperationHandlerSet.OperationHandlerSet | OperationHandlerSet.OperationHandlerSet[];
47
+ toolkits?: OpaqueToolkit.OpaqueToolkit[];
48
+ types?: Type.AnyEntity[];
49
+ blueprints?: Blueprint.Blueprint[];
50
+ credentials?: ServiceCredential[];
51
+ /**
52
+ * Tracing configuration.
53
+ * - `'feed'` persists trace events to a FeedTraceSink (queryable from the database).
54
+ * @default 'noop'
55
+ */
56
+ tracing?: 'noop' | 'console' | 'pretty' | 'feed';
57
+
58
+ disableLlmMemoization?: boolean;
59
+
60
+ /**
61
+ * Core system prompt for the agent.
62
+ */
63
+ systemPrompt?: string;
64
+ }
65
+
66
+ export type AssistantTestServices =
67
+ // Convinience
68
+ | LanguageModel.LanguageModel
69
+ | Feed.FeedService
70
+ | CredentialsService
71
+ | AgentService.AgentService
72
+ | AiService.AiService
73
+ | Database.Service
74
+ | QueueService
75
+ // Registries
76
+ | Blueprint.RegistryService
77
+ | OperationRegistry.Service
78
+ | OpaqueToolkit.OpaqueToolkitProvider
79
+ | Operation.Service
80
+ // Core
81
+ | ProcessManager.ProcessManagerService
82
+ | Process.ProcessMonitorService
83
+ | Registry.AtomRegistry
84
+ // Should those be here?
85
+ | OperationHandlerSet.OperationHandlerProvider
86
+ | KeyValueStore.KeyValueStore
87
+ | ServiceResolver.ServiceResolver
88
+ | Trace.TraceService
89
+ | Trace.TraceSink
90
+ | FeedTraceSink.FeedTraceSink;
91
+
92
+ export const AssistantTestLayer = ({
93
+ aiServicePreset = 'direct',
94
+ model,
95
+ operationHandlers = [],
96
+ toolkits = [],
97
+ types = [],
98
+ credentials = [],
99
+ tracing = 'noop',
100
+ disableLlmMemoization = false,
101
+ blueprints = [],
102
+ systemPrompt,
103
+ }: TestLayerOptions = {}): Layer.Layer<AssistantTestServices, never, TestContextService> => {
104
+ const resolvedModel: ModelName =
105
+ model ?? (aiServicePreset === 'ollama' ? 'gpt-oss:20b' : '@anthropic/claude-opus-4-6');
106
+ const toolkit = OpaqueToolkit.merge(...toolkits);
107
+ const operationHandlersSet = Array.isArray(operationHandlers)
108
+ ? OperationHandlerSet.merge(...operationHandlers)
109
+ : operationHandlers;
110
+ types.push(Blueprint.Blueprint, Prompt.Prompt, Operation.PersistentOperation, Feed.Feed, Trigger.Trigger, Tag.Tag);
111
+ types = Array.dedupeWith(types, (a, b) => Type.getTypename(a) === Type.getTypename(b));
112
+
113
+ return Layer.empty.pipe(
114
+ Layer.provideMerge(ProcessManager.ProcessOperationInvoker.layer),
115
+ Layer.provideMerge(Trace.testTraceService({ meta: { processName: 'test' } })),
116
+ Layer.provideMerge(AgentService.layer({ systemPrompt, model: resolvedModel })),
117
+ Layer.provideMerge(ProcessManager.layer({ idGenerator: ProcessManager.SequentialProcessIdGenerator })),
118
+ Layer.provideMerge(
119
+ // TODO(dmaretskyi): Refactor to be able to merge resovler layers, also consider service mesh achitecture.
120
+ Layer.effect(
121
+ ServiceResolver.ServiceResolver,
122
+ Effect.gen(function* () {
123
+ const services = yield* Effect.context<Database.Service | Feed.FeedService>().pipe(
124
+ Effect.map(Context.pick(Database.Service, Feed.FeedService)),
125
+ Effect.map(Layer.succeedContext),
126
+ );
127
+ // AiContextBinder.
128
+ return ServiceResolver.compose(
129
+ ServiceResolver.succeed(AiContextService, (context) =>
130
+ Effect.gen(function* () {
131
+ if (!context.conversation) {
132
+ return yield* Effect.fail(new ServiceNotAvailableError(AiContextService.key));
133
+ }
134
+ const feed = yield* Database.resolve(DXN.parse(context.conversation), Feed.Feed).pipe(Effect.orDie);
135
+ const runtime = yield* Effect.runtime<Feed.FeedService>();
136
+ const binder = yield* acquireReleaseResource(
137
+ () =>
138
+ new AiContextBinder({
139
+ feed,
140
+ runtime,
141
+ }),
142
+ );
143
+ return { binder };
144
+ }).pipe(Effect.provide(services)),
145
+ ),
146
+ // AiSessionService.
147
+ ServiceResolver.succeed(AiSessionService, (context) =>
148
+ Effect.gen(function* () {
149
+ if (!context.conversation) {
150
+ return yield* Effect.fail(new ServiceNotAvailableError(AiSessionService.key));
151
+ }
152
+ const feed = yield* Database.resolve(DXN.parse(context.conversation), Feed.Feed).pipe(Effect.orDie);
153
+ const runtime = yield* Effect.runtime<Feed.FeedService>();
154
+ const session = yield* acquireReleaseResource(
155
+ () =>
156
+ new AiSession({
157
+ feed,
158
+ runtime,
159
+ }),
160
+ );
161
+ return session;
162
+ }).pipe(Effect.provide(services)),
163
+ ),
164
+ yield* ServiceResolver.fromRequirements(
165
+ Database.Service,
166
+ OpaqueToolkit.OpaqueToolkitProvider,
167
+ Feed.FeedService,
168
+ AiService.AiService,
169
+ OperationRegistry.Service,
170
+ Blueprint.RegistryService,
171
+ QueueService,
172
+ ),
173
+ );
174
+ }),
175
+ ),
176
+ ),
177
+ Layer.provideMerge(Layer.mergeAll(OperationRegistry.layer, AiService.model(resolvedModel))),
178
+ Layer.provideMerge(
179
+ Match.value(tracing).pipe(
180
+ Match.when('noop', () => Layer.mergeAll(Trace.layerNoop, FeedTraceSink.layerNoop)),
181
+ Match.when('console', () => Layer.mergeAll(Trace.layerConsole, FeedTraceSink.layerNoop)),
182
+ Match.when('pretty', () => Layer.mergeAll(TraceSinkPretty(), FeedTraceSink.layerNoop)),
183
+ Match.when('feed', () => FeedTraceSink.layerLive),
184
+ Match.exhaustive,
185
+ ) as Layer.Layer<Trace.TraceSink | FeedTraceSink.FeedTraceSink>,
186
+ ),
187
+ Layer.provideMerge(
188
+ Layer.mergeAll(
189
+ TestAiService({ preset: aiServicePreset, disableMemoization: disableLlmMemoization }),
190
+ TestDatabaseLayer({
191
+ spaceKey: 'fixed',
192
+ types,
193
+ }),
194
+ CredentialsService.configuredLayer(credentials),
195
+ ),
196
+ ),
197
+ Layer.provideMerge(Layer.succeed(Blueprint.RegistryService, new Blueprint.Registry(blueprints))),
198
+ Layer.provideMerge(OpaqueToolkit.providerLayer(toolkit)),
199
+ Layer.provideMerge(OperationHandlerSet.provide(operationHandlersSet)),
200
+ Layer.provideMerge(KeyValueStore.layerMemory),
201
+ Layer.provideMerge(Registry.layer),
202
+ Layer.orDie,
203
+ );
204
+ };
205
+
206
+ interface TestLayerWithTriggersOptions extends TestLayerOptions {}
207
+
208
+ export type AssistantTestServicesWithTriggers = AssistantTestServices | TriggerDispatcher | TriggerStateStore;
209
+
210
+ export const AssistantTestLayerWithTriggers = (
211
+ options: TestLayerWithTriggersOptions,
212
+ ): Layer.Layer<AssistantTestServicesWithTriggers, never, TestContextService> =>
213
+ Layer.mergeAll(
214
+ AssistantTestLayer(options),
215
+ TriggerDispatcher.layer({ timeControl: 'manual', startingTime: new Date('2025-09-05T15:01:00.000Z') }).pipe(
216
+ Layer.provide(Registry.layer),
217
+ ),
218
+ TriggerStateStore.layerMemory,
219
+ ) as any;
220
+
221
+ const TraceSinkPretty = () =>
222
+ Layer.succeed(Trace.TraceSink, {
223
+ write: (message) => {
224
+ for (const event of message.events) {
225
+ if (Trace.isOfType(CompleteBlock, event)) {
226
+ const tag = message.meta.processName ?? `[${message.meta.pid ?? 'unknown'}]`;
227
+ console.log(`[${tag}] ${event.data.role.toUpperCase()}`);
228
+ new ConsolePrinter({ tag }).printContentBlock(event.data.block);
229
+ } else if (Trace.isOfType(Process.SpawnedEvent, event)) {
230
+ console.log(`[${message.meta.pid}] Process spawned: ${message.meta.processName}`);
231
+ } else if (Trace.isOfType(Process.ExitedEvent, event)) {
232
+ console.log(`[${message.meta.pid}] Process exited: ${event.data.outcome}`);
233
+ }
234
+ }
235
+ },
236
+ });
package/src/tracing.ts ADDED
@@ -0,0 +1,43 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { Obj } from '@dxos/echo';
8
+ import { Trace } from '@dxos/functions';
9
+ import { ContentBlock, Actor } from '@dxos/types';
10
+
11
+ /**
12
+ * Partial content block emitted.
13
+ */
14
+ export const PartialBlock = Trace.EventType('assistant.partialBlock', {
15
+ schema: Schema.Struct({
16
+ messageId: Obj.ID,
17
+ role: Actor.Role,
18
+ block: ContentBlock.Any,
19
+ }),
20
+ isEphemeral: true,
21
+ });
22
+
23
+ /**
24
+ * Complete content block emitted.
25
+ */
26
+ export const CompleteBlock = Trace.EventType('assistant.completeBlock', {
27
+ schema: Schema.Struct({
28
+ messageId: Obj.ID,
29
+ role: Actor.Role,
30
+ block: ContentBlock.Any,
31
+ }),
32
+ isEphemeral: false,
33
+ });
34
+
35
+ export const AgentRequestBegin = Trace.EventType('assistant.agentRequestBegin', {
36
+ schema: Schema.Struct({}),
37
+ isEphemeral: false,
38
+ });
39
+
40
+ export const AgentRequestEnd = Trace.EventType('assistant.agentRequestEnd', {
41
+ schema: Schema.Struct({}),
42
+ isEphemeral: false,
43
+ });
@@ -0,0 +1,89 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import type * as Effect from 'effect/Effect';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ import { type Err, Obj, Ref, type Type } from '@dxos/echo';
9
+ import { Database } from '@dxos/echo';
10
+ import { EncodedReference } from '@dxos/echo-protocol';
11
+ import { DXN, LOCAL_SPACE_TAG, type ObjectId, type SpaceId } from '@dxos/keys';
12
+ import { trim } from '@dxos/util';
13
+
14
+ /**
15
+ * @deprecated
16
+ */
17
+ export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
18
+
19
+ // TODO(burdon): Rename RefFromLLM? -- yes -dm
20
+ /**
21
+ * A model-friendly way to reference an object.
22
+ * Supports vairous formats that will be normalized to a DXN.
23
+ *
24
+ * @deprecated Use `Ref.Ref(XXX)` instead.
25
+ */
26
+ export const ArtifactId: Schema.Schema<string> & {
27
+ toDXN: (reference: ArtifactId, owningSpaceId?: SpaceId) => DXN;
28
+ resolve: <S extends Type.AnyEntity>(
29
+ schema: S,
30
+ ref: ArtifactId,
31
+ ) => Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Database.Service>;
32
+ } = class extends Schema.String.annotations({
33
+ // TODO(dmaretskyi): This section gets overriden.
34
+ description: trim`
35
+ The ID of the referenced object. Formats accepted:
36
+ - DXN (dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4). DXNs can be prepended with an @ symbol for compatibility with in-text references.
37
+ - space ID, object ID tuple (spaceID:objectID)
38
+ - Only object ID that is assumed to be in the current space (01KG7R1ZXWFMWQ4DA1Q6TN1DG4)
39
+ `,
40
+ examples: [
41
+ 'dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
42
+ '@dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
43
+ 'BM3FSHFOMJCHCG5QW7JTVKGYABD2GAA7G:01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
44
+ '01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
45
+ ],
46
+ }) {
47
+ static toDXN(reference: ArtifactId, owningSpaceId?: SpaceId): DXN {
48
+ // Allow @dxn: prefix for compatibility with in-text references.
49
+ if (reference.startsWith('@dxn:')) {
50
+ return DXN.parse(reference.slice(1));
51
+ } else if (reference.startsWith('dxn:')) {
52
+ return DXN.parse(reference);
53
+ } else if (/^[A-Z0-9]+:[A-Z0-9]+$/.test(reference)) {
54
+ const [spaceId, objectId] = reference.split(':');
55
+ // This is a workaround because the current Filter API doesn't work with fully qualified Echo DXNs.
56
+ // We check if the space ID is the same as the owning space and then use LOCAL_SPACE_TAG for local references.
57
+ // TODO(dmaretskyi): Fix this in the Echo and Filter API to properly handle fully qualified DXNs.
58
+ return new DXN(DXN.kind.ECHO, [spaceId === owningSpaceId ? LOCAL_SPACE_TAG : spaceId, objectId]);
59
+ } else if (/^[A-Z0-9]+$/.test(reference)) {
60
+ return DXN.fromLocalObjectId(reference);
61
+ } else {
62
+ throw new Error(`Unable to parse object reference: ${reference}`);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Resolves an artifact ID to an object.
68
+ */
69
+ static resolve<S extends Type.AnyEntity>(
70
+ schema: S,
71
+ ref: ArtifactId,
72
+ ): Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Database.Service> {
73
+ const dxn = ArtifactId.toDXN(ref);
74
+ return Database.resolve(dxn, schema);
75
+ }
76
+ };
77
+
78
+ export type ArtifactId = Schema.Schema.Type<typeof ArtifactId>;
79
+
80
+ /**
81
+ * Schema that decodes ECHO reference object from an LLM-friendly input.
82
+ */
83
+ export const RefFromLLM = Schema.transform(ArtifactId, Ref.Ref(Obj.Unknown), {
84
+ decode: (fromA, fromI) => EncodedReference.fromDXN(ArtifactId.toDXN(fromA)),
85
+ encode: (toI, toA) => EncodedReference.toDXN(toI).toString(),
86
+ strict: false,
87
+ }).annotations({
88
+ description: ArtifactId.ast.annotations.description as string,
89
+ });
@@ -0,0 +1,5 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ export * from './artifact';
package/src/typings.d.ts CHANGED
@@ -2,6 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ declare module '*?raw' {
6
+ const content: string;
7
+ export default content;
8
+ }
9
+
5
10
  declare module '*.tpl?raw' {
6
11
  const content: string;
7
12
  export default content;