@dxos/assistant 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6

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 (211) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  3. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-KVYJFFLF.mjs +1805 -0
  5. package/dist/lib/neutral/chunk-KVYJFFLF.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 +551 -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 +112 -0
  12. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  13. package/dist/types/src/conversation/context.d.ts +148 -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/conversation.d.ts +53 -25
  18. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  19. package/dist/types/src/conversation/conversation.test.d.ts +2 -0
  20. package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
  21. package/dist/types/src/conversation/index.d.ts +1 -0
  22. package/dist/types/src/conversation/index.d.ts.map +1 -1
  23. package/dist/types/src/diff.d.ts +17 -0
  24. package/dist/types/src/diff.d.ts.map +1 -0
  25. package/dist/types/src/diff.test.d.ts +2 -0
  26. package/dist/types/src/diff.test.d.ts.map +1 -0
  27. package/dist/types/src/errors.d.ts +47 -18
  28. package/dist/types/src/errors.d.ts.map +1 -1
  29. package/dist/types/src/execution-graph.d.ts +85 -0
  30. package/dist/types/src/execution-graph.d.ts.map +1 -0
  31. package/dist/types/src/execution-graph.test.d.ts +2 -0
  32. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  33. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  34. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  36. package/dist/types/src/extraction/extraction.d.ts +1060 -273
  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/services.d.ts +37 -4
  43. package/dist/types/src/functions/services.d.ts.map +1 -1
  44. package/dist/types/src/functions.test.d.ts +2 -0
  45. package/dist/types/src/functions.test.d.ts.map +1 -0
  46. package/dist/types/src/index.d.ts +5 -3
  47. package/dist/types/src/index.d.ts.map +1 -1
  48. package/dist/types/src/service/AgentService.d.ts +62 -0
  49. package/dist/types/src/service/AgentService.d.ts.map +1 -0
  50. package/dist/types/src/service/AgentService.test.d.ts +2 -0
  51. package/dist/types/src/service/AgentService.test.d.ts.map +1 -0
  52. package/dist/types/src/service/agent-process.d.ts +17 -0
  53. package/dist/types/src/service/agent-process.d.ts.map +1 -0
  54. package/dist/types/src/service/index.d.ts +3 -0
  55. package/dist/types/src/service/index.d.ts.map +1 -0
  56. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  57. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  58. package/dist/types/src/session/error-handling.d.ts +4 -0
  59. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  60. package/dist/types/src/session/format.d.ts +12 -0
  61. package/dist/types/src/session/format.d.ts.map +1 -0
  62. package/dist/types/src/session/format.test.d.ts +2 -0
  63. package/dist/types/src/session/format.test.d.ts.map +1 -0
  64. package/dist/types/src/session/index.d.ts +4 -0
  65. package/dist/types/src/session/index.d.ts.map +1 -1
  66. package/dist/types/src/session/observer.d.ts +23 -0
  67. package/dist/types/src/session/observer.d.ts.map +1 -0
  68. package/dist/types/src/session/session.d.ts +87 -235
  69. package/dist/types/src/session/session.d.ts.map +1 -1
  70. package/dist/types/src/session/toolkit.d.ts +18 -0
  71. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  72. package/dist/types/src/session/version-pin.d.ts +4 -4
  73. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  74. package/dist/types/src/templates/index.d.ts +1 -1
  75. package/dist/types/src/templates/system.d.ts +17 -0
  76. package/dist/types/src/templates/system.d.ts.map +1 -0
  77. package/dist/types/src/testing/index.d.ts +1 -2
  78. package/dist/types/src/testing/index.d.ts.map +1 -1
  79. package/dist/types/src/testing/layer.d.ts +35 -0
  80. package/dist/types/src/testing/layer.d.ts.map +1 -0
  81. package/dist/types/src/tracing.d.ts +264 -0
  82. package/dist/types/src/tracing.d.ts.map +1 -0
  83. package/dist/types/src/types/artifact.d.ts +28 -0
  84. package/dist/types/src/types/artifact.d.ts.map +1 -0
  85. package/dist/types/src/types/index.d.ts +2 -0
  86. package/dist/types/src/types/index.d.ts.map +1 -0
  87. package/dist/types/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +58 -35
  89. package/src/conversation/context.test.ts +46 -0
  90. package/src/conversation/context.ts +369 -0
  91. package/src/conversation/conversation.test.ts +65 -0
  92. package/src/conversation/conversation.ts +232 -62
  93. package/src/conversation/index.ts +1 -0
  94. package/src/diff.test.ts +74 -0
  95. package/src/diff.ts +93 -0
  96. package/src/errors.ts +6 -1
  97. package/src/execution-graph.test.ts +740 -0
  98. package/src/execution-graph.ts +509 -0
  99. package/src/extraction/extraction-ner-function/index.ts +0 -1
  100. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  101. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +2 -0
  102. package/src/extraction/extraction.ts +44 -15
  103. package/src/extraction/index.ts +0 -1
  104. package/src/extraction/quotes.test.ts +3 -3
  105. package/src/extraction/quotes.ts +6 -7
  106. package/src/functions/services.ts +286 -96
  107. package/src/functions.conversations.json +1 -0
  108. package/src/functions.test.ts +82 -0
  109. package/src/index.ts +5 -3
  110. package/src/service/AgentService.conversations.json +1 -0
  111. package/src/service/AgentService.test.ts +169 -0
  112. package/src/service/AgentService.ts +171 -0
  113. package/src/service/agent-process.ts +360 -0
  114. package/src/service/index.ts +6 -0
  115. package/src/session/artifact-diff.ts +41 -0
  116. package/src/session/error-handling.ts +41 -0
  117. package/src/session/format.test.ts +133 -0
  118. package/src/session/format.ts +143 -0
  119. package/src/session/index.ts +4 -0
  120. package/src/session/observer.ts +62 -0
  121. package/src/session/session.conversations.json +1 -0
  122. package/src/session/session.test.ts +82 -201
  123. package/src/session/session.ts +282 -270
  124. package/src/session/toolkit.ts +44 -0
  125. package/src/session/version-pin.ts +8 -8
  126. package/src/templates/index.ts +1 -1
  127. package/src/templates/instructions/format.tpl +57 -0
  128. package/src/templates/instructions/system.tpl +57 -0
  129. package/src/templates/system.ts +42 -0
  130. package/src/testing/index.ts +2 -8
  131. package/src/testing/layer.ts +263 -0
  132. package/src/tracing.ts +112 -0
  133. package/src/types/artifact.ts +89 -0
  134. package/src/types/index.ts +5 -0
  135. package/src/typings.d.ts +5 -0
  136. package/dist/lib/browser/index.mjs +0 -1831
  137. package/dist/lib/browser/index.mjs.map +0 -7
  138. package/dist/lib/browser/meta.json +0 -1
  139. package/dist/lib/node-esm/index.mjs +0 -1833
  140. package/dist/lib/node-esm/index.mjs.map +0 -7
  141. package/dist/lib/node-esm/meta.json +0 -1
  142. package/dist/types/bin/chat.d.ts +0 -2
  143. package/dist/types/bin/chat.d.ts.map +0 -1
  144. package/dist/types/src/context/binder.d.ts +0 -34
  145. package/dist/types/src/context/binder.d.ts.map +0 -1
  146. package/dist/types/src/context/binding.d.ts +0 -56
  147. package/dist/types/src/context/binding.d.ts.map +0 -1
  148. package/dist/types/src/context/index.d.ts +0 -3
  149. package/dist/types/src/context/index.d.ts.map +0 -1
  150. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  151. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  152. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  153. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  154. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  155. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  156. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -302
  157. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  158. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  159. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  160. package/dist/types/src/research/exa.d.ts +0 -12
  161. package/dist/types/src/research/exa.d.ts.map +0 -1
  162. package/dist/types/src/research/graph.d.ts +0 -51
  163. package/dist/types/src/research/graph.d.ts.map +0 -1
  164. package/dist/types/src/research/graph.test.d.ts +0 -2
  165. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  166. package/dist/types/src/research/index.d.ts +0 -4
  167. package/dist/types/src/research/index.d.ts.map +0 -1
  168. package/dist/types/src/research/research.d.ts +0 -10
  169. package/dist/types/src/research/research.d.ts.map +0 -1
  170. package/dist/types/src/research/research.test.d.ts +0 -2
  171. package/dist/types/src/research/research.test.d.ts.map +0 -1
  172. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  173. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  174. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  175. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  176. package/dist/types/src/templates/prompt.d.ts +0 -30
  177. package/dist/types/src/templates/prompt.d.ts.map +0 -1
  178. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  179. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  180. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  181. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  182. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  183. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  184. package/dist/types/src/types.d.ts +0 -13
  185. package/dist/types/src/types.d.ts.map +0 -1
  186. package/src/context/binder.ts +0 -103
  187. package/src/context/binding.ts +0 -32
  188. package/src/context/index.ts +0 -6
  189. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -83
  190. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -70
  191. package/src/extraction/extraction-llm-function/index.ts +0 -5
  192. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  193. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -57
  194. package/src/research/exa.ts +0 -97
  195. package/src/research/graph.test.ts +0 -64
  196. package/src/research/graph.ts +0 -369
  197. package/src/research/index.ts +0 -7
  198. package/src/research/instructions-research.tpl +0 -98
  199. package/src/research/research.test.ts +0 -190
  200. package/src/research/research.ts +0 -87
  201. package/src/session/__snapshots__/session.test.ts.snap +0 -32
  202. package/src/session/version-pin.test.ts +0 -7
  203. package/src/summarization/summarization.test.ts +0 -208
  204. package/src/templates/assistant.tpl +0 -111
  205. package/src/templates/prompt.ts +0 -45
  206. package/src/testing/exa-search-1748337321991.ts +0 -131
  207. package/src/testing/exa-search-1748337331526.ts +0 -144
  208. package/src/testing/exa-search-1748337344119.ts +0 -133
  209. package/src/typedefs.d.ts +0 -8
  210. package/src/types.ts +0 -47
  211. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"research.d.ts","sourceRoot":"","sources":["../../../../src/research/research.ts"],"names":[],"mappings":"AAqBA;;GAEG;AAEH,eAAO,MAAM,UAAU;;;;;EA6DrB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=research.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"research.test.d.ts","sourceRoot":"","sources":["../../../../src/research/research.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=version-pin.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version-pin.test.d.ts","sourceRoot":"","sources":["../../../../src/session/version-pin.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=summarization.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarization.test.d.ts","sourceRoot":"","sources":["../../../../src/summarization/summarization.test.ts"],"names":[],"mappings":""}
@@ -1,30 +0,0 @@
1
- import { type AssociatedArtifact } from '@dxos/blueprints';
2
- /**
3
- * Type for assistant prompt variables.
4
- */
5
- export type AssistantPromptOptions = {
6
- /**
7
- * Instructions for each artifact.
8
- */
9
- artifacts?: string[];
10
- /**
11
- * Associated artifact to include in the prompt.
12
- * @deprecated
13
- */
14
- artifact?: AssociatedArtifact;
15
- /**
16
- * Whether to include suggestions in the prompt.
17
- */
18
- suggestions?: boolean;
19
- /**
20
- * Additional instructions to include in the prompt.
21
- */
22
- instructions?: string;
23
- /**
24
- * Emit chain-of-thought inside <cot> tag.
25
- * Should be `false` for models with built-in reasoning: Claude, deepseek, o1.
26
- */
27
- cot?: boolean;
28
- };
29
- export declare const createSystemPrompt: (options: AssistantPromptOptions) => string;
30
- //# sourceMappingURL=prompt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../src/templates/prompt.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,kBAAkB,EAAY,MAAM,kBAAkB,CAAC;AAIrE;;GAEG;AAEH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IAEH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAE9B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,SAAS,sBAAsB,WAEjE,CAAC"}
@@ -1,38 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- autoDate: string;
5
- resolvedSearchType: string;
6
- results: ({
7
- id: string;
8
- title: string;
9
- url: string;
10
- publishedDate: string;
11
- author: string;
12
- score: number;
13
- text: string;
14
- image?: undefined;
15
- favicon?: undefined;
16
- } | {
17
- id: string;
18
- title: string;
19
- url: string;
20
- publishedDate: string;
21
- author: string;
22
- score: number;
23
- text: string;
24
- image: string;
25
- favicon: string;
26
- })[];
27
- costDollars: {
28
- total: number;
29
- search: {
30
- neural: number;
31
- };
32
- contents: {
33
- text: number;
34
- };
35
- };
36
- };
37
- export default _default;
38
- //# sourceMappingURL=exa-search-1748337321991.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337321991.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337321991.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBA8HE"}
@@ -1,37 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- resolvedSearchType: string;
5
- results: ({
6
- id: string;
7
- title: string;
8
- url: string;
9
- publishedDate: string;
10
- author: string;
11
- score: number;
12
- text: string;
13
- image: string;
14
- favicon: string;
15
- } | {
16
- id: string;
17
- title: string;
18
- url: string;
19
- publishedDate: string;
20
- author: string;
21
- text: string;
22
- image: string;
23
- favicon: string;
24
- score?: undefined;
25
- })[];
26
- costDollars: {
27
- total: number;
28
- search: {
29
- neural: number;
30
- };
31
- contents: {
32
- text: number;
33
- };
34
- };
35
- };
36
- export default _default;
37
- //# sourceMappingURL=exa-search-1748337331526.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337331526.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337331526.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBA2IE"}
@@ -1,58 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- autoDate: string;
5
- resolvedSearchType: string;
6
- results: ({
7
- id: string;
8
- title: string;
9
- url: string;
10
- publishedDate: string;
11
- author: string;
12
- score: number;
13
- text: string;
14
- favicon: string;
15
- image?: undefined;
16
- } | {
17
- id: string;
18
- title: string;
19
- url: string;
20
- publishedDate: string;
21
- author: string;
22
- score: number;
23
- text: string;
24
- favicon?: undefined;
25
- image?: undefined;
26
- } | {
27
- id: string;
28
- title: string;
29
- url: string;
30
- publishedDate: string;
31
- author: string;
32
- score: number;
33
- text: string;
34
- image: string;
35
- favicon: string;
36
- } | {
37
- id: string;
38
- title: string;
39
- url: string;
40
- author: string;
41
- text: string;
42
- image: string;
43
- favicon: string;
44
- publishedDate?: undefined;
45
- score?: undefined;
46
- })[];
47
- costDollars: {
48
- total: number;
49
- search: {
50
- neural: number;
51
- };
52
- contents: {
53
- text: number;
54
- };
55
- };
56
- };
57
- export default _default;
58
- //# sourceMappingURL=exa-search-1748337344119.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337344119.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337344119.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBAgIE"}
@@ -1,13 +0,0 @@
1
- import { Schema } from 'effect';
2
- import { type ObjectId } from '@dxos/echo-schema';
3
- import { DXN, type SpaceId } from '@dxos/keys';
4
- export declare const createArtifactElement: (id: ObjectId) => string;
5
- /**
6
- * A model-friendly way to reference an object.
7
- * Supports vairous formats that will be normalized to a DXN.
8
- */
9
- export declare const ArtifactId: Schema.Schema<string> & {
10
- toDXN: (reference: ArtifactId, owningSpaceId?: SpaceId) => DXN;
11
- };
12
- export type ArtifactId = Schema.Schema.Type<typeof ArtifactId>;
13
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAmB,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEhE,eAAO,MAAM,qBAAqB,GAAI,IAAI,QAAQ,WAA4B,CAAC;AAE/E;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG;IAC/C,KAAK,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,aAAa,CAAC,EAAE,OAAO,KAAK,GAAG,CAAC;CA4BhE,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC"}
@@ -1,103 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { computed, type ReadonlySignal } from '@preact/signals-core';
6
- import { Array, pipe } from 'effect';
7
-
8
- import { type Blueprint } from '@dxos/blueprints';
9
- import { Obj, type Type, type Ref, type Relation } from '@dxos/echo';
10
- import { type Queue } from '@dxos/echo-db';
11
- import { ComplexSet } from '@dxos/util';
12
-
13
- import { ContextBinding } from './binding';
14
-
15
- /**
16
- * Manages bindings of blueprints and objects to a conversation.
17
- */
18
- export class ContextBinder {
19
- constructor(private readonly _queue: Queue) {}
20
-
21
- /**
22
- * Reactive query of all bindings.
23
- */
24
- // TODO(burdon): Cache value?
25
- readonly bindings: ReadonlySignal<Bindings> = computed(() => this._reduce(this._queue.objects));
26
-
27
- // TODO(burdon): load refs?
28
- readonly blueprints: ReadonlySignal<Ref.Ref<Blueprint.Blueprint>[]> = computed(() => [
29
- ...this.bindings.value.blueprints,
30
- ]);
31
- readonly objects: ReadonlySignal<Ref.Ref<Type.Expando>[]> = computed(() => [...this.bindings.value.objects]);
32
-
33
- /**
34
- * Asynchronous query of all bindings.
35
- */
36
- async query(): Promise<Bindings> {
37
- const queueItems = await this._queue.queryObjects();
38
- return this._reduce(queueItems);
39
- }
40
-
41
- // TODO(burdon): Pass in Blueprint obj (from registry?) and create reference.
42
- async bind(props: BindingProps): Promise<void> {
43
- if (!props.blueprints?.length && !props.objects?.length) {
44
- return;
45
- }
46
-
47
- await this._queue.append([
48
- Obj.make(ContextBinding, {
49
- blueprints: {
50
- added: props.blueprints ?? [],
51
- removed: [],
52
- },
53
- objects: {
54
- added: props.objects ?? [],
55
- removed: [],
56
- },
57
- }),
58
- ]);
59
- }
60
-
61
- async unbind(props: BindingProps): Promise<void> {
62
- if (!props.blueprints?.length && !props.objects?.length) {
63
- return;
64
- }
65
-
66
- await this._queue.append([
67
- Obj.make(ContextBinding, {
68
- blueprints: {
69
- added: [],
70
- removed: props.blueprints ?? [],
71
- },
72
- objects: {
73
- added: [],
74
- removed: props.objects ?? [],
75
- },
76
- }),
77
- ]);
78
- }
79
-
80
- private _reduce(items: (Obj.Any | Relation.Any)[]): Bindings {
81
- return pipe(
82
- items,
83
- Array.filter(Obj.instanceOf(ContextBinding)),
84
- Array.reduce(new Bindings(), (context, item) => {
85
- item.blueprints.removed.forEach((item) => context.blueprints.delete(item));
86
- item.blueprints.added.forEach((item) => context.blueprints.add(item));
87
- item.objects.removed.forEach((item) => context.objects.delete(item));
88
- item.objects.added.forEach((item) => context.objects.add(item));
89
- return context;
90
- }),
91
- );
92
- }
93
- }
94
-
95
- export type BindingProps = Partial<{
96
- blueprints: Ref.Ref<Blueprint.Blueprint>[];
97
- objects: Ref.Ref<Type.Expando>[];
98
- }>;
99
-
100
- export class Bindings {
101
- blueprints = new ComplexSet<Ref.Ref<Blueprint.Blueprint>>((ref) => ref.dxn.toString());
102
- objects = new ComplexSet<Ref.Ref<Type.Expando>>((ref) => ref.dxn.toString());
103
- }
@@ -1,32 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { Blueprint } from '@dxos/blueprints';
8
- import { Type } from '@dxos/echo';
9
-
10
- /**
11
- * Thread message that binds or unbinds contextual objects to a conversation.
12
- */
13
- // TODO(burdon): Make ContentBlock.
14
- export const ContextBinding = Schema.Struct({
15
- blueprints: Schema.Struct({
16
- added: Schema.Array(Type.Ref(Blueprint.Blueprint)),
17
- removed: Schema.Array(Type.Ref(Blueprint.Blueprint)),
18
- }),
19
-
20
- // TODO(burdon): Type.Expando => Type.Obj (or Obj.Any?)
21
- objects: Schema.Struct({
22
- added: Schema.Array(Type.Ref(Type.Expando)),
23
- removed: Schema.Array(Type.Ref(Type.Expando)),
24
- }),
25
- }).pipe(
26
- Type.Obj({
27
- typename: 'dxos.org/type/ContextBinding',
28
- version: '0.1.0',
29
- }),
30
- );
31
-
32
- export interface ContextBinding extends Schema.Schema.Type<typeof ContextBinding> {}
@@ -1,6 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './binder';
6
- export * from './binding';
@@ -1,83 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { beforeAll, describe, test } from 'vitest';
6
-
7
- import { todo } from '@dxos/debug';
8
- import { FunctionExecutor } from '@dxos/functions';
9
- import { log } from '@dxos/log';
10
- import { createTestData } from '@dxos/schema/testing';
11
- import { range } from '@dxos/util';
12
-
13
- import { processTranscriptMessage } from '../extraction';
14
- import { extractionAnthropicFn } from './extraction-llm-function';
15
-
16
- // TODO(burdon): Rewrite test.
17
- describe.skip('LLM EntityExtraction', () => {
18
- let executor: FunctionExecutor;
19
-
20
- beforeAll(async () => {
21
- executor = new FunctionExecutor(todo());
22
- });
23
-
24
- test('should process a transcript block', async () => {
25
- const { transcriptMessages, documents, contacts } = createTestData();
26
- log.info('context', { documents, contacts });
27
-
28
- for (const message of transcriptMessages.slice(0, 1)) {
29
- log.info('input', message);
30
- const { message: enhancedMessage } = await processTranscriptMessage({
31
- input: {
32
- message,
33
- objects: [...documents, ...Object.values(contacts)],
34
- },
35
- function: extractionAnthropicFn,
36
- executor,
37
- });
38
- log.info('output', enhancedMessage);
39
- }
40
- });
41
-
42
- test('computational irreducibility', async () => {
43
- const { transcriptWoflram, documents, contacts } = createTestData();
44
-
45
- log.info('context', { documents, contacts });
46
- const message = transcriptWoflram[0];
47
- log.info('input', message);
48
-
49
- await Promise.all(
50
- range(10).map(async () => {
51
- const { message: enhancedMessage, timeElapsed } = await processTranscriptMessage({
52
- input: {
53
- message,
54
- objects: [...documents, ...Object.values(contacts)],
55
- },
56
- function: extractionAnthropicFn,
57
- executor,
58
- });
59
- log.info('output', { message: enhancedMessage.blocks[0], timeElapsed });
60
- }),
61
- );
62
- });
63
-
64
- test('org and document linking', async () => {
65
- const { transcriptJosiah, documents, contacts, organizations } = createTestData();
66
-
67
- log.info('context', { contacts, organizations, documents });
68
-
69
- for (const message of transcriptJosiah) {
70
- log.info('input', message);
71
-
72
- const { message: enhancedMessage } = await processTranscriptMessage({
73
- input: {
74
- message,
75
- objects: [...documents, ...Object.values(contacts), ...Object.values(organizations)],
76
- },
77
- function: extractionAnthropicFn,
78
- executor,
79
- });
80
- log.info('output', enhancedMessage);
81
- }
82
- });
83
- });
@@ -1,70 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- // TODO(burdon): Fix.
6
- // @ts-nocheck
7
-
8
- import { ToolRegistry, AiService } from '@dxos/ai';
9
- import { Obj } from '@dxos/echo';
10
- import { create } from '@dxos/echo-schema';
11
- import { defineFunction, type FunctionDefinition } from '@dxos/functions';
12
- import { type ContentBlock, DataType } from '@dxos/schema';
13
-
14
- import PROMPT from './instructions.tpl?raw';
15
- import { AiSession } from '../../session';
16
- import { ExtractionInput, ExtractionOutput } from '../extraction';
17
- import { insertReferences, ReferencedQuotes } from '../quotes';
18
-
19
- export const extractionAnthropicFn: FunctionDefinition<ExtractionInput, ExtractionOutput> = defineFunction({
20
- description: 'Extract entities from the transcript message and add them to the message.',
21
- inputSchema: ExtractionInput,
22
- outputSchema: ExtractionOutput,
23
- handler: async ({ data: { message, objects }, context }) => {
24
- const startTime = performance.now();
25
- const ai = context.getService(AiService);
26
- const session = new AiSession({ operationModel: 'configured' });
27
- const result = await session.runStructured(ReferencedQuotes, {
28
- generationOptions: {
29
- model: '@anthropic/claude-3-5-haiku-20241022',
30
- },
31
- client: ai.client,
32
- systemPrompt: PROMPT,
33
- history: [
34
- Obj.make(DataType.Message, {
35
- created: new Date().toISOString(),
36
- sender: { role: 'user' },
37
- blocks: [
38
- {
39
- _tag: 'text',
40
- text: `<context>${JSON.stringify(objects)}</context>`,
41
- } satisfies ContentBlock.Text,
42
- {
43
- _tag: 'text',
44
- text: `<transcript>${JSON.stringify(message.blocks)}</transcript>`,
45
- } satisfies ContentBlock.Text,
46
- ],
47
- }),
48
- ],
49
- artifacts: [],
50
- prompt: '',
51
- tools: [],
52
- toolResolver: new ToolRegistry([]),
53
- } as any); // TODO(burdon): Rewrite test.
54
-
55
- return {
56
- message: create(DataType.Message, {
57
- ...message,
58
- blocks: message.blocks.map((block, i) =>
59
- block._tag !== 'transcript'
60
- ? block
61
- : {
62
- ...block,
63
- text: insertReferences(block.text, result),
64
- },
65
- ),
66
- }),
67
- timeElapsed: performance.now() - startTime,
68
- };
69
- },
70
- });
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './extraction-llm-function';
@@ -1,115 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { describe, test, beforeAll } from 'vitest';
6
-
7
- import { type EchoDatabase } from '@dxos/echo-db';
8
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
9
- import { FunctionExecutor, ServiceContainer } from '@dxos/functions';
10
- import { log } from '@dxos/log';
11
- import { DataType } from '@dxos/schema';
12
- import { createTestData, Testing } from '@dxos/schema/testing';
13
- import { range } from '@dxos/util';
14
-
15
- import { extractionNerFn } from './extraction-ner-function';
16
- import { processTranscriptMessage } from '../extraction';
17
-
18
- describe.skip('NER EntityExtraction', () => {
19
- let builder: EchoTestBuilder;
20
- let db: EchoDatabase;
21
- let executor: FunctionExecutor;
22
- let testData: {
23
- transcriptJosiah: DataType.Message[];
24
- transcriptWoflram: DataType.Message[];
25
- transcriptMessages: DataType.Message[];
26
- documents: Testing.DocumentType[];
27
- contacts: Record<string, DataType.Person>;
28
- organizations: Record<string, DataType.Organization>;
29
- };
30
- const TYPES = [DataType.Organization, DataType.Person, Testing.Contact, Testing.DocumentType];
31
-
32
- beforeAll(async () => {
33
- // TODO(dmaretskyi): Helper to scaffold this from a config.
34
- builder = await new EchoTestBuilder().open();
35
- const { db: db1 } = await builder.createDatabase({ indexing: { vector: true } });
36
- db = db1;
37
- db.graph.schemaRegistry.addSchema(TYPES);
38
- const data = createTestData();
39
- testData = {
40
- transcriptJosiah: data.transcriptJosiah,
41
- transcriptWoflram: data.transcriptWoflram,
42
- transcriptMessages: data.transcriptMessages,
43
- documents: data.documents.map((document) => db.add(document)),
44
- contacts: Object.fromEntries(Object.entries(data.contacts).map(([key, value]) => [key, db.add(value)])),
45
- organizations: Object.fromEntries(Object.entries(data.organizations).map(([key, value]) => [key, db.add(value)])),
46
- };
47
- await db.flush();
48
-
49
- executor = new FunctionExecutor(
50
- new ServiceContainer().setServices({
51
- database: { db },
52
- }),
53
- );
54
- }, 30_000);
55
-
56
- test('should process a transcript block', async () => {
57
- const { transcriptMessages, documents, contacts } = testData;
58
- log.info('context', { documents, contacts });
59
-
60
- for (const message of transcriptMessages) {
61
- log.info('input', message);
62
- const { message: enhancedMessage } = await processTranscriptMessage({
63
- input: {
64
- message,
65
- objects: [...documents, ...Object.values(contacts)],
66
- },
67
- function: extractionNerFn,
68
- executor,
69
- });
70
- log.info('output', enhancedMessage);
71
- }
72
- });
73
-
74
- test('computational irreducibility', async () => {
75
- const { transcriptWoflram, documents, contacts } = testData;
76
-
77
- log.info('context', { documents, contacts });
78
- const message = transcriptWoflram[0];
79
- log.info('input', message);
80
-
81
- await Promise.all(
82
- range(10).map(async () => {
83
- const { message: enhancedMessage, timeElapsed } = await processTranscriptMessage({
84
- input: {
85
- message,
86
- objects: [...documents, ...Object.values(contacts)],
87
- },
88
- function: extractionNerFn,
89
- executor,
90
- });
91
- log.info('output', { message: enhancedMessage.blocks[0], timeElapsed });
92
- }),
93
- );
94
- });
95
-
96
- test('org and document linking', async () => {
97
- const { transcriptJosiah, documents, contacts, organizations } = testData;
98
-
99
- log.info('context', { contacts, organizations, documents });
100
-
101
- for (const message of transcriptJosiah) {
102
- log.info('input', message);
103
-
104
- const { message: enhancedMessage } = await processTranscriptMessage({
105
- input: {
106
- message,
107
- objects: [...documents, ...Object.values(contacts), ...Object.values(organizations)],
108
- },
109
- function: extractionNerFn,
110
- executor,
111
- });
112
- log.info('output', enhancedMessage);
113
- }
114
- });
115
- });