@dxos/assistant 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc

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 (172) 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/extraction/index.mjs +204 -0
  5. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  6. package/dist/lib/neutral/index.mjs +1755 -0
  7. package/dist/lib/neutral/index.mjs.map +7 -0
  8. package/dist/lib/neutral/meta.json +1 -0
  9. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  10. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  11. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  12. package/dist/types/src/extraction/extraction.d.ts +1065 -312
  13. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  14. package/dist/types/src/extraction/index.d.ts +0 -1
  15. package/dist/types/src/extraction/index.d.ts.map +1 -1
  16. package/dist/types/src/extraction/quotes.d.ts +2 -2
  17. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  18. package/dist/types/src/functions/services.d.ts +13 -15
  19. package/dist/types/src/functions/services.d.ts.map +1 -1
  20. package/dist/types/src/index.d.ts +2 -5
  21. package/dist/types/src/index.d.ts.map +1 -1
  22. package/dist/types/src/request/AiRequest.d.ts +104 -0
  23. package/dist/types/src/request/AiRequest.d.ts.map +1 -0
  24. package/dist/types/src/{session → request}/artifact-diff.d.ts +1 -1
  25. package/dist/types/src/request/artifact-diff.d.ts.map +1 -0
  26. package/dist/types/src/request/format.d.ts +15 -0
  27. package/dist/types/src/request/format.d.ts.map +1 -0
  28. package/dist/types/src/request/index.d.ts +4 -0
  29. package/dist/types/src/request/index.d.ts.map +1 -0
  30. package/dist/types/src/{session → request}/observer.d.ts +6 -5
  31. package/dist/types/src/request/observer.d.ts.map +1 -0
  32. package/dist/types/src/{session → request}/version-pin.d.ts +3 -3
  33. package/dist/types/src/request/version-pin.d.ts.map +1 -0
  34. package/dist/types/src/session/AiContext.d.ts +154 -0
  35. package/dist/types/src/session/AiContext.d.ts.map +1 -0
  36. package/dist/types/src/session/AiContext.test.d.ts +2 -0
  37. package/dist/types/src/session/AiContext.test.d.ts.map +1 -0
  38. package/dist/types/src/session/AiSession.d.ts +73 -0
  39. package/dist/types/src/session/AiSession.d.ts.map +1 -0
  40. package/dist/types/src/session/index.d.ts +2 -4
  41. package/dist/types/src/session/index.d.ts.map +1 -1
  42. package/dist/types/src/session/toolkit.d.ts +10 -9
  43. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  44. package/dist/types/src/templates/system.d.ts +1 -2
  45. package/dist/types/src/templates/system.d.ts.map +1 -1
  46. package/dist/types/src/util/artifact.d.ts +27 -0
  47. package/dist/types/src/util/artifact.d.ts.map +1 -0
  48. package/dist/types/src/{diff.d.ts → util/diff.d.ts} +3 -1
  49. package/dist/types/src/util/diff.d.ts.map +1 -0
  50. package/dist/types/src/{diff.test.d.ts.map → util/diff.test.d.ts.map} +1 -1
  51. package/dist/types/src/util/error-handling.d.ts.map +1 -0
  52. package/dist/types/src/{errors.d.ts → util/errors.d.ts} +32 -40
  53. package/dist/types/src/util/errors.d.ts.map +1 -0
  54. package/dist/types/src/{execution-graph.d.ts → util/execution-graph.d.ts} +5 -2
  55. package/dist/types/src/util/execution-graph.d.ts.map +1 -0
  56. package/dist/types/src/util/execution-graph.test.d.ts.map +1 -0
  57. package/dist/types/src/util/index.d.ts +7 -0
  58. package/dist/types/src/util/index.d.ts.map +1 -0
  59. package/dist/types/src/util/tracing.d.ts +233 -0
  60. package/dist/types/src/util/tracing.d.ts.map +1 -0
  61. package/dist/types/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +36 -42
  63. package/src/extraction/extraction-ner-function/index.ts +0 -1
  64. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
  65. package/src/extraction/extraction.ts +43 -14
  66. package/src/extraction/index.ts +0 -1
  67. package/src/extraction/quotes.ts +4 -5
  68. package/src/functions/services.ts +119 -63
  69. package/src/index.ts +2 -5
  70. package/src/request/AiRequest.ts +348 -0
  71. package/src/{session → request}/artifact-diff.ts +1 -1
  72. package/src/{session → request}/format.ts +29 -24
  73. package/src/request/index.ts +8 -0
  74. package/src/{session → request}/observer.ts +6 -3
  75. package/src/{session → request}/version-pin.ts +6 -6
  76. package/src/session/AiContext.test.ts +53 -0
  77. package/src/session/AiContext.ts +403 -0
  78. package/src/session/AiSession.ts +324 -0
  79. package/src/session/index.ts +3 -4
  80. package/src/session/toolkit.ts +27 -28
  81. package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
  82. package/src/templates/{system.tpl → instructions/system.tpl} +50 -2
  83. package/src/templates/system.ts +9 -8
  84. package/src/{types → util}/artifact.ts +42 -6
  85. package/src/util/diff.test.ts +74 -0
  86. package/src/{diff.ts → util/diff.ts} +13 -4
  87. package/src/{session → util}/error-handling.ts +3 -2
  88. package/src/util/errors.ts +15 -0
  89. package/src/{execution-graph.test.ts → util/execution-graph.test.ts} +47 -45
  90. package/src/{execution-graph.ts → util/execution-graph.ts} +41 -22
  91. package/src/util/index.ts +10 -0
  92. package/src/util/tracing.ts +57 -0
  93. package/dist/lib/browser/chunk-4VIJTKPM.mjs +0 -354
  94. package/dist/lib/browser/chunk-4VIJTKPM.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 -272
  98. package/dist/lib/browser/extraction/index.mjs.map +0 -7
  99. package/dist/lib/browser/index.mjs +0 -900
  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/node-esm/chunk-AUUC7II4.mjs +0 -356
  104. package/dist/lib/node-esm/chunk-AUUC7II4.mjs.map +0 -7
  105. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
  106. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
  107. package/dist/lib/node-esm/extraction/index.mjs +0 -273
  108. package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
  109. package/dist/lib/node-esm/index.mjs +0 -901
  110. package/dist/lib/node-esm/index.mjs.map +0 -7
  111. package/dist/lib/node-esm/meta.json +0 -1
  112. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
  113. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
  114. package/dist/types/src/conversation/context.d.ts +0 -103
  115. package/dist/types/src/conversation/context.d.ts.map +0 -1
  116. package/dist/types/src/conversation/conversation.d.ts +0 -41
  117. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  118. package/dist/types/src/conversation/index.d.ts +0 -3
  119. package/dist/types/src/conversation/index.d.ts.map +0 -1
  120. package/dist/types/src/diff.d.ts.map +0 -1
  121. package/dist/types/src/errors.d.ts.map +0 -1
  122. package/dist/types/src/execution-graph.d.ts.map +0 -1
  123. package/dist/types/src/execution-graph.test.d.ts.map +0 -1
  124. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  125. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  126. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  127. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  128. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  129. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  130. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -345
  131. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  132. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  133. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  134. package/dist/types/src/session/artifact-diff.d.ts.map +0 -1
  135. package/dist/types/src/session/error-handling.d.ts.map +0 -1
  136. package/dist/types/src/session/format.d.ts +0 -186
  137. package/dist/types/src/session/format.d.ts.map +0 -1
  138. package/dist/types/src/session/format.test.d.ts +0 -2
  139. package/dist/types/src/session/format.test.d.ts.map +0 -1
  140. package/dist/types/src/session/observer.d.ts.map +0 -1
  141. package/dist/types/src/session/session.d.ts +0 -51
  142. package/dist/types/src/session/session.d.ts.map +0 -1
  143. package/dist/types/src/session/session.test.d.ts +0 -2
  144. package/dist/types/src/session/session.test.d.ts.map +0 -1
  145. package/dist/types/src/session/version-pin.d.ts.map +0 -1
  146. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  147. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  148. package/dist/types/src/types/artifact.d.ts +0 -16
  149. package/dist/types/src/types/artifact.d.ts.map +0 -1
  150. package/dist/types/src/types/index.d.ts +0 -2
  151. package/dist/types/src/types/index.d.ts.map +0 -1
  152. package/src/conversation/context.ts +0 -186
  153. package/src/conversation/conversation.ts +0 -128
  154. package/src/conversation/index.ts +0 -6
  155. package/src/diff.test.ts +0 -43
  156. package/src/errors.ts +0 -15
  157. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
  158. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -72
  159. package/src/extraction/extraction-llm-function/index.ts +0 -5
  160. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  161. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -64
  162. package/src/session/format.test.ts +0 -60
  163. package/src/session/session.conversations.json +0 -1
  164. package/src/session/session.test.ts +0 -149
  165. package/src/session/session.ts +0 -213
  166. package/src/summarization/summarization.test.ts +0 -202
  167. package/src/types/index.ts +0 -5
  168. /package/dist/lib/{browser/named-entity-recognition-QPYHML66.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
  169. /package/dist/types/src/{diff.test.d.ts → util/diff.test.d.ts} +0 -0
  170. /package/dist/types/src/{session → util}/error-handling.d.ts +0 -0
  171. /package/dist/types/src/{execution-graph.test.d.ts → util/execution-graph.test.d.ts} +0 -0
  172. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@dxos/assistant",
3
- "version": "0.8.4-main.ae835ea",
3
+ "version": "0.8.4-main.bc2380dfbc",
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",
@@ -12,65 +16,55 @@
12
16
  ".": {
13
17
  "source": "./src/index.ts",
14
18
  "types": "./dist/types/src/index.d.ts",
15
- "browser": "./dist/lib/browser/index.mjs",
16
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
17
20
  },
18
21
  "./extraction": {
19
22
  "source": "./src/extraction/index.ts",
20
23
  "types": "./dist/types/src/extraction/index.d.ts",
21
- "browser": "./dist/lib/browser/extraction/index.mjs",
22
- "node": "./dist/lib/node-esm/extraction/index.mjs"
24
+ "default": "./dist/lib/neutral/extraction/index.mjs"
23
25
  }
24
26
  },
25
27
  "types": "dist/types/src/index.d.ts",
26
- "typesVersions": {
27
- "*": {
28
- "types": [
29
- "dist/types/src/types/index.d.ts"
30
- ],
31
- "extraction": [
32
- "dist/types/src/extraction/index.d.ts"
33
- ]
34
- }
35
- },
36
28
  "files": [
37
29
  "dist",
38
30
  "src"
39
31
  ],
40
32
  "dependencies": {
41
- "@automerge/automerge": "3.1.2",
42
- "@effect/ai": "0.29.1",
43
- "@effect/experimental": "0.56.0",
44
- "@effect/platform": "^0.92.1",
45
- "@preact/signals-core": "^1.12.1",
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",
46
39
  "@xenova/transformers": "^2.17.2",
47
40
  "lodash.defaultsdeep": "^4.6.1",
48
- "@dxos/async": "0.8.4-main.ae835ea",
49
- "@dxos/blueprints": "0.8.4-main.ae835ea",
50
- "@dxos/context": "0.8.4-main.ae835ea",
51
- "@dxos/echo": "0.8.4-main.ae835ea",
52
- "@dxos/debug": "0.8.4-main.ae835ea",
53
- "@dxos/echo-db": "0.8.4-main.ae835ea",
54
- "@dxos/ai": "0.8.4-main.ae835ea",
55
- "@dxos/errors": "0.8.4-main.ae835ea",
56
- "@dxos/effect": "0.8.4-main.ae835ea",
57
- "@dxos/functions": "0.8.4-main.ae835ea",
58
- "@dxos/graph": "0.8.4-main.ae835ea",
59
- "@dxos/invariant": "0.8.4-main.ae835ea",
60
- "@dxos/live-object": "0.8.4-main.ae835ea",
61
- "@dxos/keys": "0.8.4-main.ae835ea",
62
- "@dxos/node-std": "0.8.4-main.ae835ea",
63
- "@dxos/log": "0.8.4-main.ae835ea",
64
- "@dxos/schema": "0.8.4-main.ae835ea",
65
- "@dxos/echo-protocol": "0.8.4-main.ae835ea",
66
- "@dxos/util": "0.8.4-main.ae835ea"
41
+ "@dxos/async": "0.8.4-main.bc2380dfbc",
42
+ "@dxos/debug": "0.8.4-main.bc2380dfbc",
43
+ "@dxos/compute": "0.8.4-main.bc2380dfbc",
44
+ "@dxos/context": "0.8.4-main.bc2380dfbc",
45
+ "@dxos/echo-db": "0.8.4-main.bc2380dfbc",
46
+ "@dxos/echo-protocol": "0.8.4-main.bc2380dfbc",
47
+ "@dxos/effect": "0.8.4-main.bc2380dfbc",
48
+ "@dxos/echo": "0.8.4-main.bc2380dfbc",
49
+ "@dxos/errors": "0.8.4-main.bc2380dfbc",
50
+ "@dxos/functions": "0.8.4-main.bc2380dfbc",
51
+ "@dxos/graph": "0.8.4-main.bc2380dfbc",
52
+ "@dxos/keys": "0.8.4-main.bc2380dfbc",
53
+ "@dxos/log": "0.8.4-main.bc2380dfbc",
54
+ "@dxos/node-std": "0.8.4-main.bc2380dfbc",
55
+ "@dxos/mcp-client": "0.8.4-main.bc2380dfbc",
56
+ "@dxos/schema": "0.8.4-main.bc2380dfbc",
57
+ "@dxos/invariant": "0.8.4-main.bc2380dfbc",
58
+ "@dxos/types": "0.8.4-main.bc2380dfbc",
59
+ "@dxos/util": "0.8.4-main.bc2380dfbc",
60
+ "@dxos/ai": "0.8.4-main.bc2380dfbc"
67
61
  },
68
62
  "devDependencies": {
69
63
  "@types/lodash.defaultsdeep": "^4.6.6",
70
- "effect": "3.18.3"
64
+ "effect": "3.20.0"
71
65
  },
72
66
  "peerDependencies": {
73
- "effect": "^3.13.3"
67
+ "effect": "3.20.0"
74
68
  },
75
69
  "publishConfig": {
76
70
  "access": "public"
@@ -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,7 +6,8 @@ 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
 
@@ -57,8 +58,10 @@ describe.skip('NamedEntityRecognition', () => {
57
58
  test('own data', async () => {
58
59
  const { transcriptWoflram, transcriptJosiah } = await createTestData();
59
60
 
60
- const blocks = [...transcriptWoflram, ...transcriptJosiah].flatMap((message) =>
61
- message.blocks.flatMap((block) => (block._tag === 'transcript' ? [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
+ ),
62
65
  );
63
66
 
64
67
  for (const block of blocks) {
@@ -70,8 +73,10 @@ describe.skip('NamedEntityRecognition', () => {
70
73
  test('more own data', async () => {
71
74
  const { transcriptMessages } = await createTestData();
72
75
 
73
- const blocks = transcriptMessages.flatMap((message) =>
74
- message.blocks.flatMap((block) => (block._tag === 'transcript' ? [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
+ ),
75
80
  );
76
81
 
77
82
  for (const block of blocks) {
@@ -4,15 +4,14 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { asyncTimeout } from '@dxos/async';
8
- import { Expando } from '@dxos/echo/internal';
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';
@@ -4,9 +4,8 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { Filter, Query } from '@dxos/echo';
8
- import { ObjectId } from '@dxos/echo/internal';
9
- import { type EchoDatabase } from '@dxos/echo-db';
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
  }),
@@ -7,71 +7,67 @@ import type * as Toolkit from '@effect/ai/Toolkit';
7
7
  import * as Context from 'effect/Context';
8
8
  import * as Effect from 'effect/Effect';
9
9
  import * as Layer from 'effect/Layer';
10
+ import * as Option from 'effect/Option';
10
11
  import * as Record from 'effect/Record';
11
12
  import * as Schema from 'effect/Schema';
13
+ import * as SchemaAST from 'effect/SchemaAST';
12
14
 
13
15
  import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
16
+ import { OpaqueToolkit } from '@dxos/ai';
17
+ import { Operation, OperationRegistry } from '@dxos/compute';
14
18
  import { todo } from '@dxos/debug';
15
- import { Query } from '@dxos/echo';
16
- import { DatabaseService, Function, FunctionDefinition, FunctionInvocationService } from '@dxos/functions';
19
+ import { Ref } from '@dxos/echo';
17
20
  import { invariant } from '@dxos/invariant';
18
21
 
19
- /**
20
- * Constructs a `ToolResolverService` whose `resolve(id)` looks up tools in the following order:
21
- * 1. Toolkit: return an existing tool from the provided `toolkit` if one is present under `id`.
22
- * 2. Functions in DB: query `FunctionType` by `key=id`; if found, deserialize and project to a tool
23
- * (propagating any `deployedFunctionId` discovered in the object's metadata).
24
- * 3. Functions passed in: fall back to a matching `FunctionDefinition` from the `functions` array.
25
- *
26
- * If none of the above yield a match, the effect fails with `AiToolNotFoundError`.
27
- *
28
- * Requires `DatabaseService` in the environment.
29
- */
30
- export const makeToolResolverFromFunctions = (
31
- functions: FunctionDefinition<any, any>[],
32
- toolkit: Toolkit.Toolkit<any>,
33
- ): Layer.Layer<ToolResolverService, never, DatabaseService> => {
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
+ > => {
34
31
  return Layer.effect(
35
32
  ToolResolverService,
36
33
  Effect.gen(function* () {
37
- const dbService = yield* DatabaseService;
34
+ const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
35
+ const operationRegistry = yield* OperationRegistry.Service;
38
36
  return {
39
37
  resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
40
38
  Effect.gen(function* () {
41
- const tool = toolkit.tools[id];
39
+ const toolkit = OpaqueToolkit.merge(extraToolkit, toolkitProvider.getToolkit());
40
+
41
+ const tool = toolkit.toolkit.tools[id];
42
42
  if (tool) {
43
43
  return tool;
44
44
  }
45
45
 
46
- const {
47
- objects: [dbFunction],
48
- } = yield* DatabaseService.runQuery(Query.type(Function.Function, { key: id }));
49
-
50
- const functionDef = dbFunction
51
- ? FunctionDefinition.deserialize(dbFunction)
52
- : functions.find((fn) => fn.key === id);
53
-
54
- if (!functionDef) {
55
- return yield* Effect.fail(new AiToolNotFoundError(id));
56
- }
57
-
58
- return projectFunctionToTool(functionDef);
59
- }).pipe(Effect.provideService(DatabaseService, dbService)),
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
+ }),
60
55
  } satisfies Context.Tag.Service<ToolResolverService>;
61
56
  }),
62
57
  );
63
58
  };
64
59
 
65
- export const makeToolExecutionServiceFromFunctions = (
66
- toolkit: Toolkit.Toolkit<any>,
67
- handlersLayer: Layer.Layer<Tool.Handler<any>, never, never>,
68
- ): Layer.Layer<ToolExecutionService, never, FunctionInvocationService> => {
69
- return Layer.effect(
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(
70
64
  ToolExecutionService,
71
65
  Effect.gen(function* () {
72
- const toolkitHandler = yield* toolkit.pipe(Effect.provide(handlersLayer));
66
+ const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
67
+ const toolkit = toolkitProvider.getToolkit();
68
+
69
+ const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
73
70
  invariant(isHandlerLike(toolkitHandler));
74
- const functionInvocationService = yield* FunctionInvocationService;
75
71
 
76
72
  return {
77
73
  handlersFor: (toolkit) => {
@@ -81,15 +77,13 @@ export const makeToolExecutionServiceFromFunctions = (
81
77
  if (Tool.isProviderDefined(tool)) {
82
78
  throw new Error('Attempted to call a provider-defined tool');
83
79
  }
80
+
84
81
  // TODO(wittjosiah): Everything is `never` here.
85
- return yield* (toolkitHandler.handle as any)(tool.name, input);
82
+ const { result } = yield* (toolkitHandler.handle as any)(tool.name, input);
83
+ return result;
86
84
  }
87
85
 
88
- const { definition: functionDef } = Context.get(FunctionToolAnnotation)(tool.annotations as any);
89
-
90
- return yield* functionInvocationService
91
- .invokeFunction(functionDef, input as any)
92
- .pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
86
+ return yield* opts.invoke(tool, input).pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
93
87
  });
94
88
  };
95
89
 
@@ -100,33 +94,56 @@ export const makeToolExecutionServiceFromFunctions = (
100
94
  };
101
95
  }),
102
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
+ );
103
117
  };
104
118
 
119
+ export const ToolExecutionServices = Layer.mergeAll(
120
+ makeToolResolverFromOperations(),
121
+ makeToolExecutionServiceFromOperationInvoker(),
122
+ );
123
+
105
124
  class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
106
125
  FunctionToolAnnotation,
107
- { definition: FunctionDefinition<any, any> }
126
+ { definition: Operation.Definition.Any }
108
127
  >() {}
109
128
 
110
- const toolCache = new WeakMap<FunctionDefinition<any, any>, Tool.Any>();
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>();
111
134
 
112
135
  /**
113
- * Projects a `FunctionDefinition` into an `AiTool`.
114
- *
115
- * @param fn The function definition to project into a tool.
116
- * @param meta Optional projection metadata.
117
- * @param meta.deployedFunctionId Backend deployment ID used for remote invocation when present. This is the
118
- * EDGE service's function deployment identifier (not the ECHO object ID/DXN and not `FunctionDefinition.key`).
136
+ * Projects an `Operation.Definition` into an `AiTool`.
119
137
  */
120
- const projectFunctionToTool = (fn: FunctionDefinition<any, any>): Tool.Any => {
138
+ const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
121
139
  if (toolCache.has(fn)) {
122
140
  return toolCache.get(fn)!;
123
141
  }
124
142
 
125
- const tool = Tool.make(makeToolName(fn.name), {
126
- description: fn.description,
127
- parameters: createStructFieldsFromSchema(fn.inputSchema),
128
- // TODO(dmaretskyi): Include output schema.
129
- failure: Schema.Any, // TODO(dmaretskyi): Better type for the failure?
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,
130
147
  }).annotate(FunctionToolAnnotation, { definition: fn });
131
148
  toolCache.set(fn, tool);
132
149
  return tool;
@@ -136,8 +153,8 @@ const projectFunctionToTool = (fn: FunctionDefinition<any, any>): Tool.Any => {
136
153
  * @returns Tool name produced from function name by escaping invalid characters.
137
154
  */
138
155
  const makeToolName = (name: string) => {
139
- const toolName = name.replace(/[^a-zA-Z0-9]/g, '_');
140
- invariant(toolName.match(/^[a-zA-Z_][a-zA-Z0-9-_]*$/));
156
+ const toolName = name.toLowerCase().replace(/[^a-zA-Z0-9]/g, '-');
157
+ invariant(toolName.match(/^[a-z_][a-z0-9-_]*$/));
141
158
  return toolName;
142
159
  };
143
160
 
@@ -145,7 +162,9 @@ const makeToolName = (name: string) => {
145
162
  const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<string, Schema.Schema<any, any>> => {
146
163
  switch (schema.ast._tag) {
147
164
  case 'TypeLiteral':
148
- return Object.fromEntries(schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(prop.type)]));
165
+ return Object.fromEntries(
166
+ schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(mapSchemaTypeForLLM(prop.type))]),
167
+ );
149
168
  case 'VoidKeyword':
150
169
  return {};
151
170
  default:
@@ -153,6 +172,43 @@ const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<s
153
172
  }
154
173
  };
155
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
+
156
212
  const isHandlerLike = (value: unknown): value is Toolkit.WithHandler<Record<string, Tool.Any>> => {
157
213
  return typeof (value as any).tools === 'object' && typeof (value as any).handle === 'function';
158
214
  };
package/src/index.ts CHANGED
@@ -2,11 +2,8 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './conversation';
6
- export * from './diff';
7
- export * from './errors';
8
- export * from './execution-graph';
9
5
  export * from './functions';
6
+ export * from './request';
10
7
  export * from './session';
11
8
  export * from './templates';
12
- export * from './types';
9
+ export * from './util';