@dxos/assistant 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced

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 (201) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +2 -1
  3. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/neutral/extraction/index.mjs +204 -0
  6. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  7. package/dist/lib/neutral/index.mjs +1779 -0
  8. package/dist/lib/neutral/index.mjs.map +7 -0
  9. package/dist/lib/neutral/meta.json +1 -0
  10. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  11. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  12. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  13. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  14. package/dist/types/src/extraction/extraction.d.ts +1078 -215
  15. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  16. package/dist/types/src/extraction/index.d.ts +0 -1
  17. package/dist/types/src/extraction/index.d.ts.map +1 -1
  18. package/dist/types/src/extraction/quotes.d.ts +3 -3
  19. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  20. package/dist/types/src/functions/index.d.ts +2 -0
  21. package/dist/types/src/functions/index.d.ts.map +1 -0
  22. package/dist/types/src/functions/services.d.ts +17 -0
  23. package/dist/types/src/functions/services.d.ts.map +1 -0
  24. package/dist/types/src/index.d.ts +4 -7
  25. package/dist/types/src/index.d.ts.map +1 -1
  26. package/dist/types/src/request/AiRequest.d.ts +106 -0
  27. package/dist/types/src/request/AiRequest.d.ts.map +1 -0
  28. package/dist/types/src/request/artifact-diff.d.ts +27 -0
  29. package/dist/types/src/request/artifact-diff.d.ts.map +1 -0
  30. package/dist/types/src/request/format.d.ts +15 -0
  31. package/dist/types/src/request/format.d.ts.map +1 -0
  32. package/dist/types/src/request/index.d.ts +4 -0
  33. package/dist/types/src/request/index.d.ts.map +1 -0
  34. package/dist/types/src/request/observer.d.ts +23 -0
  35. package/dist/types/src/request/observer.d.ts.map +1 -0
  36. package/dist/types/src/{session → request}/version-pin.d.ts +5 -5
  37. package/dist/types/src/request/version-pin.d.ts.map +1 -0
  38. package/dist/types/src/session/AiContext.d.ts +154 -0
  39. package/dist/types/src/session/AiContext.d.ts.map +1 -0
  40. package/dist/types/src/session/AiContext.test.d.ts +2 -0
  41. package/dist/types/src/session/AiContext.test.d.ts.map +1 -0
  42. package/dist/types/src/session/AiSession.d.ts +73 -0
  43. package/dist/types/src/session/AiSession.d.ts.map +1 -0
  44. package/dist/types/src/session/index.d.ts +3 -2
  45. package/dist/types/src/session/index.d.ts.map +1 -1
  46. package/dist/types/src/session/toolkit.d.ts +16 -0
  47. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  48. package/dist/types/src/templates/index.d.ts +2 -0
  49. package/dist/types/src/templates/index.d.ts.map +1 -0
  50. package/dist/types/src/templates/system.d.ts +17 -0
  51. package/dist/types/src/templates/system.d.ts.map +1 -0
  52. package/dist/types/src/util/artifact.d.ts +27 -0
  53. package/dist/types/src/util/artifact.d.ts.map +1 -0
  54. package/dist/types/src/util/diff.d.ts +17 -0
  55. package/dist/types/src/util/diff.d.ts.map +1 -0
  56. package/dist/types/src/util/diff.test.d.ts +2 -0
  57. package/dist/types/src/util/diff.test.d.ts.map +1 -0
  58. package/dist/types/src/util/error-handling.d.ts +4 -0
  59. package/dist/types/src/util/error-handling.d.ts.map +1 -0
  60. package/dist/types/src/util/errors.d.ts +67 -0
  61. package/dist/types/src/util/errors.d.ts.map +1 -0
  62. package/dist/types/src/util/execution-graph.d.ts +85 -0
  63. package/dist/types/src/util/execution-graph.d.ts.map +1 -0
  64. package/dist/types/src/util/execution-graph.test.d.ts +2 -0
  65. package/dist/types/src/util/execution-graph.test.d.ts.map +1 -0
  66. package/dist/types/src/util/index.d.ts +7 -0
  67. package/dist/types/src/util/index.d.ts.map +1 -0
  68. package/dist/types/src/util/tracing.d.ts +237 -0
  69. package/dist/types/src/util/tracing.d.ts.map +1 -0
  70. package/dist/types/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +44 -30
  72. package/src/extraction/extraction-ner-function/index.ts +0 -1
  73. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  74. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +3 -1
  75. package/src/extraction/extraction.ts +44 -15
  76. package/src/extraction/index.ts +0 -1
  77. package/src/extraction/quotes.test.ts +3 -3
  78. package/src/extraction/quotes.ts +6 -7
  79. package/src/{conversation → functions}/index.ts +1 -1
  80. package/src/functions/services.ts +214 -0
  81. package/src/index.ts +4 -7
  82. package/src/request/AiRequest.ts +386 -0
  83. package/src/request/artifact-diff.ts +41 -0
  84. package/src/request/format.ts +147 -0
  85. package/src/request/index.ts +8 -0
  86. package/src/request/observer.ts +62 -0
  87. package/src/{session → request}/version-pin.ts +12 -12
  88. package/src/session/AiContext.test.ts +53 -0
  89. package/src/session/AiContext.ts +403 -0
  90. package/src/session/AiSession.ts +324 -0
  91. package/src/session/index.ts +4 -2
  92. package/src/session/toolkit.ts +47 -0
  93. package/src/templates/index.ts +5 -0
  94. package/src/templates/instructions/format.tpl +57 -0
  95. package/src/templates/instructions/system.tpl +96 -0
  96. package/src/templates/system.ts +42 -0
  97. package/src/typings.d.ts +5 -0
  98. package/src/util/artifact.ts +88 -0
  99. package/src/util/diff.test.ts +74 -0
  100. package/src/util/diff.ts +93 -0
  101. package/src/util/error-handling.ts +42 -0
  102. package/src/util/errors.ts +15 -0
  103. package/src/util/execution-graph.test.ts +740 -0
  104. package/src/util/execution-graph.ts +519 -0
  105. package/src/util/index.ts +10 -0
  106. package/src/util/tracing.ts +57 -0
  107. package/dist/lib/browser/index.mjs +0 -2019
  108. package/dist/lib/browser/index.mjs.map +0 -7
  109. package/dist/lib/browser/meta.json +0 -1
  110. package/dist/lib/node-esm/index.mjs +0 -2021
  111. package/dist/lib/node-esm/index.mjs.map +0 -7
  112. package/dist/lib/node-esm/meta.json +0 -1
  113. package/dist/types/bin/chat.d.ts +0 -2
  114. package/dist/types/bin/chat.d.ts.map +0 -1
  115. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  116. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  117. package/dist/types/src/blueprint/index.d.ts +0 -3
  118. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  119. package/dist/types/src/blueprint/registry.d.ts +0 -7
  120. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  121. package/dist/types/src/context/binder.d.ts +0 -34
  122. package/dist/types/src/context/binder.d.ts.map +0 -1
  123. package/dist/types/src/context/binding.d.ts +0 -38
  124. package/dist/types/src/context/binding.d.ts.map +0 -1
  125. package/dist/types/src/context/index.d.ts +0 -3
  126. package/dist/types/src/context/index.d.ts.map +0 -1
  127. package/dist/types/src/conversation/conversation.d.ts +0 -44
  128. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  129. package/dist/types/src/conversation/index.d.ts +0 -2
  130. package/dist/types/src/conversation/index.d.ts.map +0 -1
  131. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  132. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  133. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  134. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  135. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  136. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  137. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -208
  138. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  139. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  140. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  141. package/dist/types/src/research/exa.d.ts +0 -7
  142. package/dist/types/src/research/exa.d.ts.map +0 -1
  143. package/dist/types/src/research/graph.d.ts +0 -41
  144. package/dist/types/src/research/graph.d.ts.map +0 -1
  145. package/dist/types/src/research/graph.test.d.ts +0 -2
  146. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  147. package/dist/types/src/research/index.d.ts +0 -4
  148. package/dist/types/src/research/index.d.ts.map +0 -1
  149. package/dist/types/src/research/research.d.ts +0 -10
  150. package/dist/types/src/research/research.d.ts.map +0 -1
  151. package/dist/types/src/research/research.test.d.ts +0 -2
  152. package/dist/types/src/research/research.test.d.ts.map +0 -1
  153. package/dist/types/src/session/session.d.ts +0 -283
  154. package/dist/types/src/session/session.d.ts.map +0 -1
  155. package/dist/types/src/session/session.test.d.ts +0 -2
  156. package/dist/types/src/session/session.test.d.ts.map +0 -1
  157. package/dist/types/src/session/version-pin.d.ts.map +0 -1
  158. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  159. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  160. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  161. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  162. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  163. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  164. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  165. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  166. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  167. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  168. package/dist/types/src/testing/index.d.ts +0 -3
  169. package/dist/types/src/testing/index.d.ts.map +0 -1
  170. package/dist/types/src/types.d.ts +0 -3
  171. package/dist/types/src/types.d.ts.map +0 -1
  172. package/src/blueprint/blueprint.ts +0 -75
  173. package/src/blueprint/index.ts +0 -6
  174. package/src/blueprint/registry.ts +0 -15
  175. package/src/context/binder.ts +0 -101
  176. package/src/context/binding.ts +0 -31
  177. package/src/context/index.ts +0 -6
  178. package/src/conversation/conversation.ts +0 -103
  179. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -95
  180. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -66
  181. package/src/extraction/extraction-llm-function/index.ts +0 -5
  182. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  183. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -54
  184. package/src/research/exa.ts +0 -100
  185. package/src/research/graph.test.ts +0 -15
  186. package/src/research/graph.ts +0 -337
  187. package/src/research/index.ts +0 -7
  188. package/src/research/instructions-research.tpl +0 -97
  189. package/src/research/research.test.ts +0 -190
  190. package/src/research/research.ts +0 -90
  191. package/src/session/session.test.ts +0 -275
  192. package/src/session/session.ts +0 -582
  193. package/src/session/version-pin.test.ts +0 -26
  194. package/src/summarization/summarization.test.ts +0 -221
  195. package/src/testing/exa-search-1748337321991.ts +0 -131
  196. package/src/testing/exa-search-1748337331526.ts +0 -144
  197. package/src/testing/exa-search-1748337344119.ts +0 -133
  198. package/src/testing/index.ts +0 -11
  199. package/src/typedefs.d.ts +0 -8
  200. package/src/types.ts +0 -8
  201. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
package/package.json CHANGED
@@ -1,18 +1,27 @@
1
1
  {
2
2
  "name": "@dxos/assistant",
3
- "version": "0.8.4-main.84f28bd",
3
+ "version": "0.8.4-main.8baae0fced",
4
4
  "description": "Natural language interface to DXOS",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
- "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
11
+ "license": "FSL-1.1-Apache-2.0",
8
12
  "author": "info@dxos.org",
9
13
  "sideEffects": true,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
17
+ "source": "./src/index.ts",
13
18
  "types": "./dist/types/src/index.d.ts",
14
- "browser": "./dist/lib/browser/index.mjs",
15
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
20
+ },
21
+ "./extraction": {
22
+ "source": "./src/extraction/index.ts",
23
+ "types": "./dist/types/src/extraction/index.d.ts",
24
+ "default": "./dist/lib/neutral/extraction/index.mjs"
16
25
  }
17
26
  },
18
27
  "types": "dist/types/src/index.d.ts",
@@ -21,42 +30,47 @@
21
30
  "src"
22
31
  ],
23
32
  "dependencies": {
24
- "@preact/signals-core": "^1.9.0",
33
+ "@automerge/automerge": "3.2.6",
34
+ "@effect-atom/atom": "^0.5.1",
35
+ "@effect-atom/atom-react": "^0.5.0",
36
+ "@effect/ai": "0.33.2",
37
+ "@effect/experimental": "0.58.0",
38
+ "@effect/platform": "0.94.4",
25
39
  "@xenova/transformers": "^2.17.2",
26
- "chalk": "^4.1.0",
27
- "exa-js": "^1.5.12",
28
- "@dxos/ai": "0.8.4-main.84f28bd",
29
- "@dxos/artifact": "0.8.4-main.84f28bd",
30
- "@dxos/async": "0.8.4-main.84f28bd",
31
- "@dxos/debug": "0.8.4-main.84f28bd",
32
- "@dxos/echo": "0.8.4-main.84f28bd",
33
- "@dxos/context": "0.8.4-main.84f28bd",
34
- "@dxos/echo-db": "0.8.4-main.84f28bd",
35
- "@dxos/echo-protocol": "0.8.4-main.84f28bd",
36
- "@dxos/echo-schema": "0.8.4-main.84f28bd",
37
- "@dxos/effect": "0.8.4-main.84f28bd",
38
- "@dxos/functions": "0.8.4-main.84f28bd",
39
- "@dxos/graph": "0.8.4-main.84f28bd",
40
- "@dxos/invariant": "0.8.4-main.84f28bd",
41
- "@dxos/keys": "0.8.4-main.84f28bd",
42
- "@dxos/live-object": "0.8.4-main.84f28bd",
43
- "@dxos/log": "0.8.4-main.84f28bd",
44
- "@dxos/node-std": "0.8.4-main.84f28bd",
45
- "@dxos/schema": "0.8.4-main.84f28bd",
46
- "@dxos/util": "0.8.4-main.84f28bd"
40
+ "lodash.defaultsdeep": "^4.6.1",
41
+ "@dxos/ai": "0.8.4-main.8baae0fced",
42
+ "@dxos/compute": "0.8.4-main.8baae0fced",
43
+ "@dxos/context": "0.8.4-main.8baae0fced",
44
+ "@dxos/async": "0.8.4-main.8baae0fced",
45
+ "@dxos/debug": "0.8.4-main.8baae0fced",
46
+ "@dxos/echo-db": "0.8.4-main.8baae0fced",
47
+ "@dxos/echo": "0.8.4-main.8baae0fced",
48
+ "@dxos/echo-protocol": "0.8.4-main.8baae0fced",
49
+ "@dxos/errors": "0.8.4-main.8baae0fced",
50
+ "@dxos/invariant": "0.8.4-main.8baae0fced",
51
+ "@dxos/graph": "0.8.4-main.8baae0fced",
52
+ "@dxos/keys": "0.8.4-main.8baae0fced",
53
+ "@dxos/effect": "0.8.4-main.8baae0fced",
54
+ "@dxos/mcp-client": "0.8.4-main.8baae0fced",
55
+ "@dxos/log": "0.8.4-main.8baae0fced",
56
+ "@dxos/node-std": "0.8.4-main.8baae0fced",
57
+ "@dxos/types": "0.8.4-main.8baae0fced",
58
+ "@dxos/schema": "0.8.4-main.8baae0fced",
59
+ "@dxos/util": "0.8.4-main.8baae0fced",
60
+ "@dxos/functions": "0.8.4-main.8baae0fced"
47
61
  },
48
62
  "devDependencies": {
49
- "effect": "3.16.13",
50
- "inquirer": "^12.0.0"
63
+ "@types/lodash.defaultsdeep": "^4.6.6",
64
+ "effect": "3.20.0"
51
65
  },
52
66
  "peerDependencies": {
53
- "effect": "^3.13.3"
67
+ "effect": "3.20.0"
54
68
  },
55
69
  "publishConfig": {
56
70
  "access": "public"
57
71
  },
58
72
  "beast": {},
59
73
  "scripts": {
60
- "run:chat": "tsx ./bin/chat.ts"
74
+ "run:chat": "vite-node ./bin/chat.ts"
61
75
  }
62
76
  }
@@ -2,5 +2,4 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './extraction-ner-function';
6
5
  export * from './named-entity-recognition';
@@ -6,11 +6,13 @@ import { type TokenClassificationOutput, type TokenClassificationPipelineType }
6
6
  import { beforeAll, describe, expect, test } from 'vitest';
7
7
 
8
8
  import { log } from '@dxos/log';
9
- import { createTestData } from '@dxos/schema/testing';
9
+ import { type ContentBlock, type Message } from '@dxos/types';
10
+ import { createTestData } from '@dxos/types/testing';
10
11
 
11
12
  import { combineNerTokens, createTokenGroups, extractFullEntities, getNer } from './named-entity-recognition';
12
13
 
13
- describe('NamedEntityRecognition', () => {
14
+ // TODO(mykola): This should not run on CI.
15
+ describe.skip('NamedEntityRecognition', () => {
14
16
  let ner: TokenClassificationPipelineType;
15
17
 
16
18
  beforeAll(async () => {
@@ -56,8 +58,10 @@ describe('NamedEntityRecognition', () => {
56
58
  test('own data', async () => {
57
59
  const { transcriptWoflram, transcriptJosiah } = await createTestData();
58
60
 
59
- const blocks = [...transcriptWoflram, ...transcriptJosiah].flatMap((message) =>
60
- message.blocks.flatMap((block) => (block.type === 'transcription' ? [block.text] : [])),
61
+ const blocks = [...transcriptWoflram, ...transcriptJosiah].flatMap((message: Message.Message) =>
62
+ message.blocks.flatMap((block: ContentBlock.Any) =>
63
+ block._tag === 'transcript' ? [(block as ContentBlock.Transcript).text] : [],
64
+ ),
61
65
  );
62
66
 
63
67
  for (const block of blocks) {
@@ -69,8 +73,10 @@ describe('NamedEntityRecognition', () => {
69
73
  test('more own data', async () => {
70
74
  const { transcriptMessages } = await createTestData();
71
75
 
72
- const blocks = transcriptMessages.flatMap((message) =>
73
- message.blocks.flatMap((block) => (block.type === 'transcription' ? [block.text] : [])),
76
+ const blocks = transcriptMessages.flatMap((message: Message.Message) =>
77
+ message.blocks.flatMap((block: ContentBlock.Any) =>
78
+ block._tag === 'transcript' ? [(block as ContentBlock.Transcript).text] : [],
79
+ ),
74
80
  );
75
81
 
76
82
  for (const block of blocks) {
@@ -4,14 +4,15 @@
4
4
 
5
5
  import {
6
6
  type TokenClassificationOutput,
7
+ type TokenClassificationPipelineType,
7
8
  type TokenClassificationSingle,
8
9
  pipeline,
9
- type TokenClassificationPipelineType,
10
10
  } from '@xenova/transformers';
11
11
 
12
12
  import { log } from '@dxos/log';
13
13
 
14
14
  let _ner: Promise<TokenClassificationPipelineType>;
15
+
15
16
  /**
16
17
  * Named Entity Recognition pipeline.
17
18
  * Initializes the pipeline on first call.
@@ -24,6 +25,7 @@ export const getNer = () => {
24
25
  return ner;
25
26
  });
26
27
  }
28
+
27
29
  return _ner;
28
30
  };
29
31
 
@@ -2,17 +2,16 @@
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 { asyncTimeout } from '@dxos/async';
8
- import { Expando } from '@dxos/echo-schema';
9
- import { type FunctionDefinition, type FunctionExecutor } from '@dxos/functions';
7
+ import { Operation } from '@dxos/compute';
8
+ import { Obj } from '@dxos/echo';
10
9
  import { log } from '@dxos/log';
11
- import { DataType } from '@dxos/schema';
10
+ import { Message } from '@dxos/types';
12
11
 
13
12
  export const ExtractionInput = Schema.Struct({
14
- message: DataType.Message,
15
- objects: Schema.optional(Schema.Array(Expando)),
13
+ message: Message.Message,
14
+ objects: Schema.optional(Schema.Array(Obj.Unknown)),
16
15
  options: Schema.optional(
17
16
  Schema.Struct({
18
17
  timeout: Schema.optional(Schema.Number),
@@ -23,15 +22,14 @@ export const ExtractionInput = Schema.Struct({
23
22
  export interface ExtractionInput extends Schema.Schema.Type<typeof ExtractionInput> {}
24
23
 
25
24
  export const ExtractionOutput = Schema.Struct({
26
- message: DataType.Message,
25
+ message: Message.Message,
27
26
  timeElapsed: Schema.Number,
28
27
  });
29
28
  export interface ExtractionOutput extends Schema.Schema.Type<typeof ExtractionOutput> {}
30
29
 
31
- export type ProcessTranscriptMessageParams = {
30
+ export type ProcessTranscriptMessageProps = {
32
31
  input: ExtractionInput;
33
- function: FunctionDefinition<ExtractionInput, ExtractionOutput>;
34
- executor: FunctionExecutor;
32
+ function: Operation.Definition<ExtractionInput, ExtractionOutput>;
35
33
 
36
34
  options?: {
37
35
  /**
@@ -48,18 +46,46 @@ export type ProcessTranscriptMessageParams = {
48
46
  };
49
47
  };
50
48
 
51
- export type ExtractionFunction = FunctionDefinition<ExtractionInput, ExtractionOutput>;
49
+ export type ExtractionFunction = Operation.Definition<ExtractionInput, ExtractionOutput>;
50
+
51
+ /**
52
+ * Placeholder for Anthropic-based entity extraction.
53
+ * Implementation is currently disabled pending restoration of extraction logic.
54
+ */
55
+ export const extractionAnthropicFunction = Operation.make({
56
+ meta: {
57
+ key: 'org.dxos.function.extraction.anthropic',
58
+ name: 'Entity Extraction (Anthropic)',
59
+ description: 'Extract entities from transcript using Anthropic LLM.',
60
+ },
61
+ input: ExtractionInput,
62
+ output: ExtractionOutput,
63
+ });
64
+
65
+ /**
66
+ * Placeholder for NER-based entity extraction.
67
+ * Implementation is currently disabled pending restoration of extraction logic.
68
+ */
69
+ export const extractionNerFunction = Operation.make({
70
+ meta: {
71
+ key: 'org.dxos.function.extraction.ner',
72
+ name: 'Entity Extraction (NER)',
73
+ description: 'Extract entities from transcript using Named Entity Recognition.',
74
+ },
75
+ input: ExtractionInput,
76
+ output: ExtractionOutput,
77
+ });
52
78
 
53
79
  /**
54
80
  * Extract entities from the transcript message and add them to the message.
55
81
  */
56
82
  // TODO(dmaretskyi): Move context to a vector search index.
57
- export const processTranscriptMessage = async (params: ProcessTranscriptMessageParams): Promise<ExtractionOutput> => {
83
+ export const processTranscriptMessage = async (params: ProcessTranscriptMessageProps): Promise<ExtractionOutput> => {
58
84
  try {
59
85
  if (params.options?.timeout && params.options.timeout > 0) {
60
- return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
86
+ // return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
61
87
  } else {
62
- return await params.executor.invoke(params.function, params.input);
88
+ // return await params.executor.invoke(params.function, params.input);
63
89
  }
64
90
  } catch (error) {
65
91
  if (params.options?.fallbackToRaw) {
@@ -72,4 +98,7 @@ export const processTranscriptMessage = async (params: ProcessTranscriptMessageP
72
98
  throw error;
73
99
  }
74
100
  }
101
+
102
+ // TODO(dmaretskyi): Restore extraction logic.
103
+ return { message: params.input.message, timeElapsed: 0 };
75
104
  };
@@ -3,6 +3,5 @@
3
3
  //
4
4
 
5
5
  export * from './extraction';
6
- export * from './extraction-llm-function';
7
6
  export * from './extraction-ner-function';
8
7
  export * from './quotes';
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { describe, test, expect } from 'vitest';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { insertReferences } from './quotes';
8
8
 
@@ -13,7 +13,7 @@ describe('insertReferences', () => {
13
13
  };
14
14
 
15
15
  expect(insertReferences('This is a computational irreducibility test.', quotes)).toBe(
16
- 'This is a [computational irreducibility][dxn:echo:@:01JTG9JW11XGWJZ32AW8ET93D1] test.',
16
+ 'This is a [computational irreducibility](dxn:echo:@:01JTG9JW11XGWJZ32AW8ET93D1) test.',
17
17
  );
18
18
  expect(
19
19
  insertReferences(
@@ -21,7 +21,7 @@ describe('insertReferences', () => {
21
21
  quotes,
22
22
  ),
23
23
  ).toBe(
24
- "And what I'd like to talk today about is Steven Wolfram's concept of a [computational irreducibility][dxn:echo:@:01JTG9JW11XGWJZ32AW8ET93D1].",
24
+ "And what I'd like to talk today about is Steven Wolfram's concept of a [computational irreducibility](dxn:echo:@:01JTG9JW11XGWJZ32AW8ET93D1).",
25
25
  );
26
26
  });
27
27
  });
@@ -2,11 +2,10 @@
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 { Query, Filter } from '@dxos/echo';
8
- import { type EchoDatabase } from '@dxos/echo-db';
9
- import { ObjectId } from '@dxos/echo-schema';
7
+ import { type Database, Filter, Query } from '@dxos/echo';
8
+ import { ObjectId } from '@dxos/keys';
10
9
  import { DXN } from '@dxos/keys';
11
10
  import { log } from '@dxos/log';
12
11
 
@@ -28,10 +27,10 @@ export const ReferencedQuotes = Schema.Struct({
28
27
  });
29
28
  export type ReferencedQuotes = Schema.Schema.Type<typeof ReferencedQuotes>;
30
29
 
31
- export const findQuotes = async (quotes: string[], db: EchoDatabase): Promise<ReferencedQuotes> => {
30
+ export const findQuotes = async (quotes: string[], db: Database.Database): Promise<ReferencedQuotes> => {
32
31
  const references = await Promise.all(
33
32
  quotes.map(async (quote) => {
34
- const { objects } = await db.query(Query.select(Filter.text(quote, { type: 'vector' }))).run();
33
+ const objects = await db.query(Query.select(Filter.text(quote, { type: 'vector' }))).run();
35
34
  log.info('found quotes in vector index', { objects, quote });
36
35
  return objects.length > 0 ? [{ id: objects[0].id.toString(), quote }] : [];
37
36
  }),
@@ -51,7 +50,7 @@ export const insertReferences = (text: string, quotes: ReferencedQuotes) => {
51
50
 
52
51
  // Use a case-insensitive regular expression to replace the quote.
53
52
  const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
54
- text = text.replace(regex, `[${quote.quote}][${DXN.fromLocalObjectId(quote.id).toString()}]`);
53
+ text = text.replace(regex, `[${quote.quote}](${DXN.fromLocalObjectId(quote.id).toString()})`);
55
54
  }
56
55
 
57
56
  return text;
@@ -2,4 +2,4 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './conversation';
5
+ export * from './services';
@@ -0,0 +1,214 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Tool from '@effect/ai/Tool';
6
+ import type * as Toolkit from '@effect/ai/Toolkit';
7
+ import * as Context from 'effect/Context';
8
+ import * as Effect from 'effect/Effect';
9
+ import * as Layer from 'effect/Layer';
10
+ import * as Option from 'effect/Option';
11
+ import * as Record from 'effect/Record';
12
+ import * as Schema from 'effect/Schema';
13
+ import * as SchemaAST from 'effect/SchemaAST';
14
+
15
+ import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
16
+ import { OpaqueToolkit } from '@dxos/ai';
17
+ import { Operation, OperationRegistry } from '@dxos/compute';
18
+ import { todo } from '@dxos/debug';
19
+ import { Ref } from '@dxos/echo';
20
+ import { invariant } from '@dxos/invariant';
21
+
22
+ import { RefFromLLM } from '../util';
23
+
24
+ export const makeToolResolverFromOperations = <R = never>({
25
+ toolkit: extraToolkit = OpaqueToolkit.empty,
26
+ }: { toolkit?: OpaqueToolkit.OpaqueToolkit<never, never, R> } = {}): Layer.Layer<
27
+ ToolResolverService,
28
+ never,
29
+ OpaqueToolkit.OpaqueToolkitProvider | OperationRegistry.Service | R
30
+ > => {
31
+ return Layer.effect(
32
+ ToolResolverService,
33
+ Effect.gen(function* () {
34
+ const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
35
+ const operationRegistry = yield* OperationRegistry.Service;
36
+ return {
37
+ resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
38
+ Effect.gen(function* () {
39
+ const toolkit = OpaqueToolkit.merge(extraToolkit, toolkitProvider.getToolkit());
40
+
41
+ const tool = toolkit.toolkit.tools[id];
42
+ if (tool) {
43
+ return tool;
44
+ }
45
+
46
+ return yield* operationRegistry.resolve(id).pipe(
47
+ Effect.flatMap(
48
+ Option.match({
49
+ onSome: (_) => Effect.succeed(projectFunctionToTool(_)),
50
+ onNone: () => Effect.fail(new AiToolNotFoundError(id)),
51
+ }),
52
+ ),
53
+ );
54
+ }),
55
+ } satisfies Context.Tag.Service<ToolResolverService>;
56
+ }),
57
+ );
58
+ };
59
+
60
+ export const makeToolExecutionService = <E, R>(opts: {
61
+ invoke: (tool: Tool.Any, input: unknown) => Effect.Effect<unknown>;
62
+ }): Layer.Layer<ToolExecutionService, never, OpaqueToolkit.OpaqueToolkitProvider> =>
63
+ Layer.effect(
64
+ ToolExecutionService,
65
+ Effect.gen(function* () {
66
+ const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
67
+ const toolkit = toolkitProvider.getToolkit();
68
+
69
+ const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
70
+ invariant(isHandlerLike(toolkitHandler));
71
+
72
+ return {
73
+ handlersFor: (toolkit) => {
74
+ const makeHandler = (tool: Tool.Any): ((params: unknown) => Effect.Effect<unknown, any, any>) => {
75
+ return Effect.fn(`toolFunctionHandler ${tool.name}`)(function* (input: any) {
76
+ if (toolkitHandler.tools[tool.name]) {
77
+ if (Tool.isProviderDefined(tool)) {
78
+ throw new Error('Attempted to call a provider-defined tool');
79
+ }
80
+
81
+ // TODO(wittjosiah): Everything is `never` here.
82
+ const { result } = yield* (toolkitHandler.handle as any)(tool.name, input);
83
+ return result;
84
+ }
85
+
86
+ return yield* opts.invoke(tool, input).pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
87
+ });
88
+ };
89
+
90
+ return toolkit.of(
91
+ Record.map(toolkit.tools, (tool, _name) => (Tool.isUserDefined(tool) ? makeHandler(tool) : null)) as any,
92
+ ) as any;
93
+ },
94
+ };
95
+ }),
96
+ );
97
+
98
+ export const makeToolExecutionServiceFromOperationInvoker = (): Layer.Layer<
99
+ ToolExecutionService,
100
+ never,
101
+ Operation.Service | OpaqueToolkit.OpaqueToolkitProvider
102
+ > => {
103
+ return Layer.unwrapEffect(
104
+ Effect.gen(function* () {
105
+ const operationInvoker = yield* Operation.Service;
106
+
107
+ return makeToolExecutionService({
108
+ invoke: (tool, input) =>
109
+ Effect.gen(function* () {
110
+ const operationDef = getOperationFromTool(tool).pipe(Option.getOrThrow);
111
+
112
+ return yield* operationInvoker.invoke(operationDef, input).pipe(Effect.orDie);
113
+ }),
114
+ });
115
+ }),
116
+ );
117
+ };
118
+
119
+ export const ToolExecutionServices = Layer.mergeAll(
120
+ makeToolResolverFromOperations(),
121
+ makeToolExecutionServiceFromOperationInvoker(),
122
+ );
123
+
124
+ class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
125
+ FunctionToolAnnotation,
126
+ { definition: Operation.Definition.Any }
127
+ >() {}
128
+
129
+ export const getOperationFromTool = (tool: Tool.Any): Option.Option<Operation.Definition.Any> => {
130
+ return Context.getOption(FunctionToolAnnotation)(tool.annotations).pipe(Option.map(({ definition }) => definition));
131
+ };
132
+
133
+ const toolCache = new WeakMap<Operation.Definition.Any, Tool.Any>();
134
+
135
+ /**
136
+ * Projects an `Operation.Definition` into an `AiTool`.
137
+ */
138
+ const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
139
+ if (toolCache.has(fn)) {
140
+ return toolCache.get(fn)!;
141
+ }
142
+
143
+ const tool = Tool.make(makeToolName(fn.meta.name ?? fn.meta.key), {
144
+ description: fn.meta.description,
145
+ parameters: createStructFieldsFromSchema(fn.input),
146
+ failure: Schema.Any,
147
+ }).annotate(FunctionToolAnnotation, { definition: fn });
148
+ toolCache.set(fn, tool);
149
+ return tool;
150
+ };
151
+
152
+ /**
153
+ * @returns Tool name produced from function name by escaping invalid characters.
154
+ */
155
+ const makeToolName = (name: string) => {
156
+ const toolName = name.toLowerCase().replace(/[^a-zA-Z0-9]/g, '-');
157
+ invariant(toolName.match(/^[a-z_][a-z0-9-_]*$/));
158
+ return toolName;
159
+ };
160
+
161
+ // TODO(dmaretskyi): Factor out.
162
+ const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<string, Schema.Schema<any, any>> => {
163
+ switch (schema.ast._tag) {
164
+ case 'TypeLiteral':
165
+ return Object.fromEntries(
166
+ schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(mapSchemaTypeForLLM(prop.type))]),
167
+ );
168
+ case 'VoidKeyword':
169
+ return {};
170
+ default:
171
+ return todo(`Unsupported schema AST: ${schema.ast._tag}`);
172
+ }
173
+ };
174
+
175
+ /**
176
+ * Picks an LLM-friendly schema type for the given schema AST.
177
+ * The picked schema type decodes to the original schema type.
178
+ */
179
+ const mapSchemaTypeForLLM = (ast: SchemaAST.AST): SchemaAST.AST => {
180
+ if (Ref.isRefType(ast)) {
181
+ const description = ast.annotations.description
182
+ ? ast.annotations.description + '\n' + RefFromLLM.ast.annotations.description
183
+ : (RefFromLLM.ast.annotations.description as string);
184
+ return RefFromLLM.annotations({ description }).ast;
185
+ } else if (SchemaAST.isTupleType(ast)) {
186
+ return new SchemaAST.TupleType(
187
+ ast.elements.map((t) => new SchemaAST.OptionalType(mapSchemaTypeForLLM(t.type), t.isOptional, t.annotations)),
188
+ ast.rest.map((t) => new SchemaAST.Type(mapSchemaTypeForLLM(t.type), t.annotations)),
189
+ ast.isReadonly,
190
+ ast.annotations,
191
+ );
192
+ } else if (SchemaAST.isTypeLiteral(ast)) {
193
+ return new SchemaAST.TypeLiteral(
194
+ ast.propertySignatures.map(
195
+ (p) =>
196
+ new SchemaAST.PropertySignature(
197
+ p.name,
198
+ mapSchemaTypeForLLM(p.type),
199
+ p.isOptional,
200
+ p.isReadonly,
201
+ p.annotations,
202
+ ),
203
+ ),
204
+ ast.indexSignatures,
205
+ ast.annotations,
206
+ );
207
+ }
208
+
209
+ return ast;
210
+ };
211
+
212
+ const isHandlerLike = (value: unknown): value is Toolkit.WithHandler<Record<string, Tool.Any>> => {
213
+ return typeof (value as any).tools === 'object' && typeof (value as any).handle === 'function';
214
+ };
package/src/index.ts CHANGED
@@ -2,11 +2,8 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './blueprint';
6
- export * from './context';
7
- export * from './conversation';
8
- export * from './extraction';
9
- export * from './research';
5
+ export * from './functions';
6
+ export * from './request';
10
7
  export * from './session';
11
- export * from './types';
12
- export * from './conversation';
8
+ export * from './templates';
9
+ export * from './util';