@dxos/assistant 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8

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 (174) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +2 -1
  3. package/dist/lib/{browser → neutral}/extraction/index.mjs +42 -59
  4. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  5. package/dist/lib/neutral/index.mjs +1886 -0
  6. package/dist/lib/neutral/index.mjs.map +7 -0
  7. package/dist/lib/neutral/meta.json +1 -0
  8. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  9. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  10. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  11. package/dist/types/src/extraction/extraction.d.ts +1649 -317
  12. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  13. package/dist/types/src/extraction/index.d.ts +0 -1
  14. package/dist/types/src/extraction/index.d.ts.map +1 -1
  15. package/dist/types/src/extraction/quotes.d.ts +2 -2
  16. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  17. package/dist/types/src/functions/services.d.ts +14 -16
  18. package/dist/types/src/functions/services.d.ts.map +1 -1
  19. package/dist/types/src/index.d.ts +2 -5
  20. package/dist/types/src/index.d.ts.map +1 -1
  21. package/dist/types/src/request/AiRequest.d.ts +308 -0
  22. package/dist/types/src/request/AiRequest.d.ts.map +1 -0
  23. package/dist/types/src/{session → request}/artifact-diff.d.ts +4 -4
  24. package/dist/types/src/request/artifact-diff.d.ts.map +1 -0
  25. package/dist/types/src/request/format.d.ts +15 -0
  26. package/dist/types/src/request/format.d.ts.map +1 -0
  27. package/dist/types/src/request/index.d.ts +4 -0
  28. package/dist/types/src/request/index.d.ts.map +1 -0
  29. package/dist/types/src/{session → request}/observer.d.ts +4 -3
  30. package/dist/types/src/request/observer.d.ts.map +1 -0
  31. package/dist/types/src/{session → request}/version-pin.d.ts +4 -4
  32. package/dist/types/src/request/version-pin.d.ts.map +1 -0
  33. package/dist/types/src/session/AiContext.d.ts +178 -0
  34. package/dist/types/src/session/AiContext.d.ts.map +1 -0
  35. package/dist/types/src/session/AiContext.test.d.ts +2 -0
  36. package/dist/types/src/session/AiContext.test.d.ts.map +1 -0
  37. package/dist/types/src/session/AiSession.d.ts +79 -0
  38. package/dist/types/src/session/AiSession.d.ts.map +1 -0
  39. package/dist/types/src/session/AiSession.test.d.ts +2 -0
  40. package/dist/types/src/session/AiSession.test.d.ts.map +1 -0
  41. package/dist/types/src/session/SessionLink.d.ts +17 -0
  42. package/dist/types/src/session/SessionLink.d.ts.map +1 -0
  43. package/dist/types/src/session/SessionLoader.d.ts +15 -0
  44. package/dist/types/src/session/SessionLoader.d.ts.map +1 -0
  45. package/dist/types/src/session/SessionLoader.test.d.ts +2 -0
  46. package/dist/types/src/session/SessionLoader.test.d.ts.map +1 -0
  47. package/dist/types/src/session/index.d.ts +4 -5
  48. package/dist/types/src/session/index.d.ts.map +1 -1
  49. package/dist/types/src/session/toolkit.d.ts +10 -9
  50. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  51. package/dist/types/src/templates/system.d.ts +12 -3
  52. package/dist/types/src/templates/system.d.ts.map +1 -1
  53. package/dist/types/src/util/artifact.d.ts +18 -0
  54. package/dist/types/src/util/artifact.d.ts.map +1 -0
  55. package/dist/types/src/{diff.d.ts → util/diff.d.ts} +4 -2
  56. package/dist/types/src/util/diff.d.ts.map +1 -0
  57. package/dist/types/src/{diff.test.d.ts.map → util/diff.test.d.ts.map} +1 -1
  58. package/dist/types/src/util/error-handling.d.ts.map +1 -0
  59. package/dist/types/src/{errors.d.ts → util/errors.d.ts} +24 -28
  60. package/dist/types/src/util/errors.d.ts.map +1 -0
  61. package/dist/types/src/{execution-graph.d.ts → util/execution-graph.d.ts} +2 -2
  62. package/dist/types/src/util/execution-graph.d.ts.map +1 -0
  63. package/dist/types/src/util/execution-graph.test.d.ts.map +1 -0
  64. package/dist/types/src/util/index.d.ts +7 -0
  65. package/dist/types/src/util/index.d.ts.map +1 -0
  66. package/dist/types/src/util/tracing.d.ts +296 -0
  67. package/dist/types/src/util/tracing.d.ts.map +1 -0
  68. package/dist/types/tsconfig.tsbuildinfo +1 -1
  69. package/package.json +36 -44
  70. package/src/extraction/extraction-ner-function/index.ts +0 -1
  71. package/src/extraction/extraction.ts +47 -18
  72. package/src/extraction/index.ts +0 -1
  73. package/src/extraction/quotes.test.ts +2 -2
  74. package/src/extraction/quotes.ts +6 -8
  75. package/src/functions/services.ts +129 -63
  76. package/src/index.ts +2 -5
  77. package/src/request/AiRequest.ts +387 -0
  78. package/src/{session → request}/artifact-diff.ts +4 -4
  79. package/src/{session → request}/format.ts +28 -25
  80. package/src/request/index.ts +8 -0
  81. package/src/{session → request}/observer.ts +4 -1
  82. package/src/{session → request}/version-pin.ts +6 -5
  83. package/src/session/AiContext.test.ts +49 -0
  84. package/src/session/AiContext.ts +420 -0
  85. package/src/session/AiSession.test.ts +111 -0
  86. package/src/session/AiSession.ts +328 -0
  87. package/src/session/SessionLink.ts +23 -0
  88. package/src/session/SessionLoader.test.ts +115 -0
  89. package/src/session/SessionLoader.ts +55 -0
  90. package/src/session/index.ts +4 -5
  91. package/src/session/toolkit.ts +27 -28
  92. package/src/templates/instructions/format.tpl +0 -4
  93. package/src/templates/instructions/system.tpl +50 -2
  94. package/src/templates/system.ts +7 -6
  95. package/src/util/artifact.ts +96 -0
  96. package/src/util/diff.test.ts +74 -0
  97. package/src/{diff.ts → util/diff.ts} +14 -5
  98. package/src/{session → util}/error-handling.ts +3 -2
  99. package/src/util/errors.ts +15 -0
  100. package/src/{execution-graph.test.ts → util/execution-graph.test.ts} +4 -4
  101. package/src/{execution-graph.ts → util/execution-graph.ts} +30 -19
  102. package/src/util/index.ts +10 -0
  103. package/src/util/tracing.ts +60 -0
  104. package/dist/lib/browser/extraction/index.mjs.map +0 -7
  105. package/dist/lib/browser/index.mjs +0 -1290
  106. package/dist/lib/browser/index.mjs.map +0 -7
  107. package/dist/lib/browser/meta.json +0 -1
  108. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  109. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  110. package/dist/lib/node-esm/extraction/index.mjs +0 -226
  111. package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
  112. package/dist/lib/node-esm/index.mjs +0 -1291
  113. package/dist/lib/node-esm/index.mjs.map +0 -7
  114. package/dist/lib/node-esm/meta.json +0 -1
  115. package/dist/types/src/conversation/context.d.ts +0 -103
  116. package/dist/types/src/conversation/context.d.ts.map +0 -1
  117. package/dist/types/src/conversation/conversation.d.ts +0 -41
  118. package/dist/types/src/conversation/conversation.d.ts.map +0 -1
  119. package/dist/types/src/conversation/index.d.ts +0 -3
  120. package/dist/types/src/conversation/index.d.ts.map +0 -1
  121. package/dist/types/src/diff.d.ts.map +0 -1
  122. package/dist/types/src/errors.d.ts.map +0 -1
  123. package/dist/types/src/execution-graph.d.ts.map +0 -1
  124. package/dist/types/src/execution-graph.test.d.ts.map +0 -1
  125. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  126. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  127. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  128. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  129. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  130. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  131. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -345
  132. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  133. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  134. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  135. package/dist/types/src/session/GenericToolkit.d.ts +0 -84
  136. package/dist/types/src/session/GenericToolkit.d.ts.map +0 -1
  137. package/dist/types/src/session/artifact-diff.d.ts.map +0 -1
  138. package/dist/types/src/session/error-handling.d.ts.map +0 -1
  139. package/dist/types/src/session/format.d.ts +0 -12
  140. package/dist/types/src/session/format.d.ts.map +0 -1
  141. package/dist/types/src/session/format.test.d.ts +0 -2
  142. package/dist/types/src/session/format.test.d.ts.map +0 -1
  143. package/dist/types/src/session/observer.d.ts.map +0 -1
  144. package/dist/types/src/session/session.d.ts +0 -51
  145. package/dist/types/src/session/session.d.ts.map +0 -1
  146. package/dist/types/src/session/session.test.d.ts +0 -2
  147. package/dist/types/src/session/session.test.d.ts.map +0 -1
  148. package/dist/types/src/session/version-pin.d.ts.map +0 -1
  149. package/dist/types/src/types/artifact.d.ts +0 -20
  150. package/dist/types/src/types/artifact.d.ts.map +0 -1
  151. package/dist/types/src/types/index.d.ts +0 -2
  152. package/dist/types/src/types/index.d.ts.map +0 -1
  153. package/src/conversation/context.ts +0 -186
  154. package/src/conversation/conversation.ts +0 -128
  155. package/src/conversation/index.ts +0 -6
  156. package/src/diff.test.ts +0 -43
  157. package/src/errors.ts +0 -15
  158. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
  159. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -62
  160. package/src/extraction/extraction-llm-function/index.ts +0 -5
  161. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -116
  162. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -56
  163. package/src/session/GenericToolkit.ts +0 -130
  164. package/src/session/format.test.ts +0 -61
  165. package/src/session/session.conversations.json +0 -1
  166. package/src/session/session.test.ts +0 -149
  167. package/src/session/session.ts +0 -213
  168. package/src/types/artifact.ts +0 -71
  169. package/src/types/index.ts +0 -5
  170. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
  171. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
  172. /package/dist/types/src/{diff.test.d.ts → util/diff.test.d.ts} +0 -0
  173. /package/dist/types/src/{session → util}/error-handling.d.ts +0 -0
  174. /package/dist/types/src/{execution-graph.test.d.ts → util/execution-graph.test.d.ts} +0 -0
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # @dxos/assistant
2
+
2
3
  Natural language interface to DXOS.
3
4
 
4
5
  Communicate with your DXOS applications through conversations using advanced LLM capabilities. This package provides a flexible system for building AI assistants that can help users interact with and control DXOS apps.
@@ -21,4 +22,4 @@ pnpm i @dxos/assistant
21
22
 
22
23
  Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
23
24
 
24
- License: [MIT](./LICENSE) Copyright 2022 © DXOS
25
+ License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
@@ -2,40 +2,54 @@ import "../chunk-J5LGTIGS.mjs";
2
2
 
3
3
  // src/extraction/extraction.ts
4
4
  import * as Schema from "effect/Schema";
5
- import { asyncTimeout } from "@dxos/async";
6
- import { Expando } from "@dxos/echo/internal";
5
+ import { Operation } from "@dxos/compute";
6
+ import { Obj, Type } from "@dxos/echo";
7
+ import { DXN } from "@dxos/keys";
7
8
  import { log } from "@dxos/log";
8
9
  import { Message } from "@dxos/types";
9
- var __dxlog_file = "/__w/dxos/dxos/packages/core/assistant/src/extraction/extraction.ts";
10
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/extraction.ts";
10
11
  var ExtractionInput = Schema.Struct({
11
- message: Message.Message,
12
- objects: Schema.optional(Schema.Array(Expando)),
12
+ message: Type.getSchema(Message.Message),
13
+ objects: Schema.optional(Schema.Array(Obj.Unknown)),
13
14
  options: Schema.optional(Schema.Struct({
14
15
  timeout: Schema.optional(Schema.Number),
15
16
  fallbackToRaw: Schema.optional(Schema.Boolean)
16
17
  }))
17
18
  });
18
19
  var ExtractionOutput = Schema.Struct({
19
- message: Message.Message,
20
+ message: Type.getSchema(Message.Message),
20
21
  timeElapsed: Schema.Number
21
22
  });
23
+ var extractionAnthropicFunction = Operation.make({
24
+ meta: {
25
+ key: DXN.make("org.dxos.function.extraction.anthropic"),
26
+ name: "Entity Extraction (Anthropic)",
27
+ description: "Extract entities from transcript using Anthropic LLM.",
28
+ icon: "ph--text-t--regular"
29
+ },
30
+ input: ExtractionInput,
31
+ output: ExtractionOutput
32
+ });
33
+ var extractionNerFunction = Operation.make({
34
+ meta: {
35
+ key: DXN.make("org.dxos.function.extraction.ner"),
36
+ name: "Entity Extraction (NER)",
37
+ description: "Extract entities from transcript using Named Entity Recognition.",
38
+ icon: "ph--text-t--regular"
39
+ },
40
+ input: ExtractionInput,
41
+ output: ExtractionOutput
42
+ });
22
43
  var processTranscriptMessage = async (params) => {
23
44
  try {
24
45
  if (params.options?.timeout && params.options.timeout > 0) {
25
- return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
26
46
  } else {
27
- return await params.executor.invoke(params.function, params.input);
28
47
  }
29
48
  } catch (error) {
30
49
  if (params.options?.fallbackToRaw) {
31
50
  log.warn("failed to process message, falling back to raw text", {
32
51
  error
33
- }, {
34
- F: __dxlog_file,
35
- L: 67,
36
- S: void 0,
37
- C: (f, a) => f(...a)
38
- });
52
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 60, S: void 0 });
39
53
  return {
40
54
  message: params.input.message,
41
55
  timeElapsed: 0
@@ -44,48 +58,21 @@ var processTranscriptMessage = async (params) => {
44
58
  throw error;
45
59
  }
46
60
  }
61
+ return {
62
+ message: params.input.message,
63
+ timeElapsed: 0
64
+ };
47
65
  };
48
66
 
49
- // src/extraction/extraction-llm-function/extraction-llm-function.ts
50
- import { defineFunction } from "@dxos/functions";
51
- var extractionAnthropicFunction = defineFunction({
52
- key: "dxos.org/function/extraction/extract-entities",
53
- name: "Extract Entities",
54
- description: "Extract entities from the transcript message and add them to the message.",
55
- inputSchema: ExtractionInput,
56
- outputSchema: ExtractionOutput,
57
- handler: async ({ data: { message, objects }, context }) => {
58
- throw new Error("not implemented");
59
- }
60
- });
61
-
62
- // src/extraction/extraction-ner-function/extraction-ner-function.ts
63
- import { defineFunction as defineFunction2 } from "@dxos/functions";
64
- var extractionNerFunction = defineFunction2({
65
- key: "dxos.org/function/extraction/extract-entities",
66
- name: "Extract Entities",
67
- description: "Extracts named entities from a text",
68
- inputSchema: ExtractionInput,
69
- outputSchema: ExtractionOutput,
70
- handler: async ({ data: { message, options }, context }) => {
71
- throw new Error("not implemented");
72
- }
73
- });
74
-
75
67
  // src/extraction/extraction-ner-function/named-entity-recognition.ts
76
68
  import { pipeline } from "@xenova/transformers";
77
69
  import { log as log2 } from "@dxos/log";
78
- var __dxlog_file2 = "/__w/dxos/dxos/packages/core/assistant/src/extraction/extraction-ner-function/named-entity-recognition.ts";
70
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/extraction-ner-function/named-entity-recognition.ts";
79
71
  var _ner;
80
72
  var getNer = () => {
81
73
  if (!_ner) {
82
74
  _ner = pipeline("ner", "Xenova/bert-base-NER").then((ner) => {
83
- log2.info("NER model is ready", void 0, {
84
- F: __dxlog_file2,
85
- L: 24,
86
- S: void 0,
87
- C: (f, a) => f(...a)
88
- });
75
+ log2.info("NER model is ready", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 14, S: void 0 });
89
76
  return ner;
90
77
  });
91
78
  }
@@ -157,10 +144,9 @@ var combineNerTokens = (group) => {
157
144
  // src/extraction/quotes.ts
158
145
  import * as Schema2 from "effect/Schema";
159
146
  import { Filter, Query } from "@dxos/echo";
160
- import { ObjectId } from "@dxos/echo/internal";
161
- import { DXN } from "@dxos/keys";
147
+ import { EID, EntityId } from "@dxos/keys";
162
148
  import { log as log3 } from "@dxos/log";
163
- var __dxlog_file3 = "/__w/dxos/dxos/packages/core/assistant/src/extraction/quotes.ts";
149
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/quotes.ts";
164
150
  var ReferencedQuotes = Schema2.Struct({
165
151
  references: Schema2.Array(Schema2.Struct({
166
152
  id: Schema2.String,
@@ -175,18 +161,13 @@ var ReferencedQuotes = Schema2.Struct({
175
161
  });
176
162
  var findQuotes = async (quotes, db) => {
177
163
  const references = await Promise.all(quotes.map(async (quote) => {
178
- const { objects } = await db.query(Query.select(Filter.text(quote, {
164
+ const objects = await db.query(Query.select(Filter.text(quote, {
179
165
  type: "vector"
180
166
  }))).run();
181
167
  log3.info("found quotes in vector index", {
182
168
  objects,
183
169
  quote
184
- }, {
185
- F: __dxlog_file3,
186
- L: 35,
187
- S: void 0,
188
- C: (f, a) => f(...a)
189
- });
170
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 25, S: void 0 });
190
171
  return objects.length > 0 ? [
191
172
  {
192
173
  id: objects[0].id.toString(),
@@ -200,11 +181,13 @@ var findQuotes = async (quotes, db) => {
200
181
  };
201
182
  var insertReferences = (text, quotes) => {
202
183
  for (const quote of quotes.references) {
203
- if (!ObjectId.isValid(quote.id)) {
184
+ if (!EntityId.isValid(quote.id)) {
204
185
  continue;
205
186
  }
206
187
  const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
207
- text = text.replace(regex, `[${quote.quote}](${DXN.fromLocalObjectId(quote.id).toString()})`);
188
+ text = text.replace(regex, `[${quote.quote}](${EID.make({
189
+ entityId: quote.id
190
+ })})`);
208
191
  }
209
192
  return text;
210
193
  };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/extraction/extraction.ts", "../../../../src/extraction/extraction-ner-function/named-entity-recognition.ts", "../../../../src/extraction/quotes.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { Operation } from '@dxos/compute';\nimport { Obj, Type } from '@dxos/echo';\nimport { DXN } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { Message } from '@dxos/types';\n\nexport const ExtractionInput = Schema.Struct({\n message: Type.getSchema(Message.Message),\n objects: Schema.optional(Schema.Array(Obj.Unknown)),\n options: Schema.optional(\n Schema.Struct({\n timeout: Schema.optional(Schema.Number),\n fallbackToRaw: Schema.optional(Schema.Boolean),\n }),\n ),\n});\nexport type ExtractionInput = Schema.Schema.Type<typeof ExtractionInput>;\nexport const ExtractionOutput = Schema.Struct({\n message: Type.getSchema(Message.Message),\n timeElapsed: Schema.Number,\n});\nexport type ExtractionOutput = Schema.Schema.Type<typeof ExtractionOutput>;\nexport type ProcessTranscriptMessageProps = {\n input: ExtractionInput;\n function: Operation.Definition<ExtractionInput, ExtractionOutput>;\n\n options?: {\n /**\n * Timeout for the entity extraction.\n */\n timeout?: number;\n\n /**\n * Fallback to raw text if the entity extraction fails.\n * Otherwise the function will throw an error.\n * @default false\n */\n fallbackToRaw?: boolean;\n };\n};\n\nexport type ExtractionFunction = Operation.Definition<ExtractionInput, ExtractionOutput>;\n\n/**\n * Placeholder for Anthropic-based entity extraction.\n * Implementation is currently disabled pending restoration of extraction logic.\n */\nexport const extractionAnthropicFunction = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.extraction.anthropic'),\n name: 'Entity Extraction (Anthropic)',\n description: 'Extract entities from transcript using Anthropic LLM.',\n icon: 'ph--text-t--regular',\n },\n input: ExtractionInput,\n output: ExtractionOutput,\n});\n\n/**\n * Placeholder for NER-based entity extraction.\n * Implementation is currently disabled pending restoration of extraction logic.\n */\nexport const extractionNerFunction = Operation.make({\n meta: {\n key: DXN.make('org.dxos.function.extraction.ner'),\n name: 'Entity Extraction (NER)',\n description: 'Extract entities from transcript using Named Entity Recognition.',\n icon: 'ph--text-t--regular',\n },\n input: ExtractionInput,\n output: ExtractionOutput,\n});\n\n/**\n * Extract entities from the transcript message and add them to the message.\n */\n// TODO(dmaretskyi): Move context to a vector search index.\nexport const processTranscriptMessage = async (params: ProcessTranscriptMessageProps): Promise<ExtractionOutput> => {\n try {\n if (params.options?.timeout && params.options.timeout > 0) {\n // return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);\n } else {\n // return await params.executor.invoke(params.function, params.input);\n }\n } catch (error) {\n if (params.options?.fallbackToRaw) {\n log.warn('failed to process message, falling back to raw text', { error });\n return {\n message: params.input.message,\n timeElapsed: 0,\n };\n } else {\n throw error;\n }\n }\n\n // TODO(dmaretskyi): Restore extraction logic.\n return { message: params.input.message, timeElapsed: 0 };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport {\n type TokenClassificationOutput,\n type TokenClassificationPipelineType,\n type TokenClassificationSingle,\n pipeline,\n} from '@xenova/transformers';\n\nimport { log } from '@dxos/log';\n\nlet _ner: Promise<TokenClassificationPipelineType>;\n\n/**\n * Named Entity Recognition pipeline.\n * Initializes the pipeline on first call.\n * @returns The singleton promise that resolves to a token classification pipeline.\n */\nexport const getNer = () => {\n if (!_ner) {\n _ner = pipeline('ner', 'Xenova/bert-base-NER').then((ner) => {\n log.info('NER model is ready');\n return ner;\n });\n }\n\n return _ner;\n};\n\n/**\n * Extracts entities from text using the named entity recognition pipeline and does simple grouping of tokens.\n */\nexport const extractFullEntities = async (text: string): Promise<TokenClassificationSingle[]> => {\n const ner = await getNer();\n const entities = (await ner(text)) as TokenClassificationOutput;\n const tokenGroups = createTokenGroups(entities);\n const combinedEntities = tokenGroups.map(combineNerTokens);\n return combinedEntities;\n};\n\nexport const createTokenGroups = (tokens: TokenClassificationSingle[]): TokenClassificationSingle[][] => {\n const tokenGroups: TokenClassificationSingle[][] = [];\n\n const canBeCombined = (prevToken: TokenClassificationSingle, currentToken: TokenClassificationSingle) => {\n const [currentState, currentEntity] = currentToken.entity.split('-'); // B, I, O\n const [prevState, prevEntity] = prevToken.entity.split('-'); // B, I, O\n if (prevEntity !== currentEntity) {\n return false;\n }\n if (prevState === 'O') {\n return false;\n }\n if (currentState === 'I') {\n return true;\n }\n if ((prevState === 'B' || prevState === 'I') && currentState === 'B') {\n return currentToken.word.startsWith('#');\n }\n return false;\n };\n\n for (const token of tokens) {\n if (tokenGroups.length === 0) {\n tokenGroups.push([token]);\n continue;\n }\n const lastTokenGroup = tokenGroups.at(-1)!;\n if (canBeCombined(lastTokenGroup.at(-1)!, token)) {\n lastTokenGroup.push(token);\n continue;\n }\n tokenGroups.push([token]);\n }\n\n return tokenGroups;\n};\n\nexport const combineNerTokens = (group: TokenClassificationSingle[]): TokenClassificationSingle => {\n const combinedToken: TokenClassificationSingle = {\n entity: group.at(0)!.entity.split('-')[1],\n score: group.reduce((acc, token) => acc + token.score, 0) / group.length,\n index: group.at(0)!.index,\n word: group.at(0)!.word,\n start: group.at(0)!.start,\n end: group.at(-1)!.end,\n };\n\n for (const token of group.slice(1)) {\n if (token.word.startsWith('#')) {\n combinedToken.word += token.word.replace(/^#+/, '');\n } else {\n combinedToken.word += ' ' + token.word;\n }\n }\n\n return combinedToken;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport { type Database, Filter, Query } from '@dxos/echo';\nimport { EID, EntityId } from '@dxos/keys';\nimport { log } from '@dxos/log';\n\nexport const ReferencedQuotes = Schema.Struct({\n references: Schema.Array(\n Schema.Struct({\n id: Schema.String,\n quote: Schema.String, // TODO(burdon): Quote?\n }),\n )\n .pipe(Schema.mutable)\n .annotations({\n // TODO(burdon): Does this description make sense?\n description: `\n The references to the context objects that are mentioned in the transcript. \n Quote should match the original transcript text exactly, while id is the id of the context object.\n `,\n }),\n});\nexport type ReferencedQuotes = Schema.Schema.Type<typeof ReferencedQuotes>;\n\nexport const findQuotes = async (quotes: string[], db: Database.Database): Promise<ReferencedQuotes> => {\n const references = await Promise.all(\n quotes.map(async (quote) => {\n const objects = await db.query(Query.select(Filter.text(quote, { type: 'vector' }))).run();\n log.info('found quotes in vector index', { objects, quote });\n return objects.length > 0 ? [{ id: objects[0].id.toString(), quote }] : [];\n }),\n );\n return { references: references.flat() };\n};\n\n/**\n * Finds and replaces all quotes with DXNs references.\n */\n// TODO(dmaretskyi): Lookup and verifiy ids from provided context.\nexport const insertReferences = (text: string, quotes: ReferencedQuotes) => {\n for (const quote of quotes.references) {\n if (!EntityId.isValid(quote.id)) {\n continue;\n }\n\n // Use a case-insensitive regular expression to replace the quote.\n const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&'), 'gi');\n text = text.replace(regex, `[${quote.quote}](${EID.make({ entityId: quote.id })})`);\n }\n\n return text;\n};\n"],
5
+ "mappings": ";;;AAIA,YAAYA,YAAY;AAExB,SAASC,iBAAiB;AAC1B,SAASC,KAAKC,YAAY;AAC1B,SAASC,WAAW;AACpB,SAASC,WAAW;AACpB,SAASC,eAAe;AAExB,IAAA,eAAaC;AAEXC,IAASR,kBAAuBS,cAAMP;EACtCQ,SAASV,KAAAA,UAAe,QACfW,OAAO;WACHX,gBAAgBA,aAAOY,IAAM,OAAA,CAAA;WACtCC,gBAAsBC,cAASd;IACjC,SAAA,gBAAA,aAAA;IAED,eAAA,gBAAA,cAAA;EAEH,CAAA,CAAA;;AAEEe,IAAAA,mBAA0B,cAAA;EACzB,SAAA,KAAA,UAAA,QAAA,OAAA;EAuBH,aAAA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AAC9B,SAASC,OAAAA,YAAW;AAEpB,IAAAC,gBAAaC;IAGHP,mBAAa,eAAA;cACHQ,cAAM,eAAA;IAGrBC,IAAKT;IAEJ,OAAA;MACAU,KAAAA,eAAc,EAAA,YAAA;;;;;;EAQpB,CAAA;;IAGM,aAAgB,OAASC,QAAMT,OAAMU;qBAAkC,MAAA,QAAA,IAAA,OAAA,IAAA,OAAA,UAAA;AAAS,UAAKC,UAAG,MAAA,GAAA,MAAA,MAAA,OAAA,OAAA,KAAA,OAAA;MACpFC,MAAK;SAAkCC,IAAAA;SAASC,KAAAA,gCAAAA;MAAM;MAC1D;qBAA6B,YAAA,GAAAV,eAAA,GAAA,IAAA,GAAA,OAAA,CAAA;mBAAMS,SAAWE,IAAGC;;QAAkB,IAAA,QAAA,CAAA,EAAA,GAAA,SAAA;QAAO;MAC5E;IAEF,IAAO,CAAA;;AAAgC,SAAA;IACvC,YAAA,WAAA,KAAA;EAEF;;IAMSd,mBAAiBY,CAAAA,MAAQ,WAAG;aAC/B,SAAA,OAAA,YAAA;AACF,QAAA,CAAA,SAAA,QAAA,MAAA,EAAA,GAAA;AAEA;IACA;UAC0DG,QAAUH,IAAAA,OAAQ,MAAA,MAAA,QAAA,uBAAA,MAAA,GAAA,IAAA;AAAC,WAAK,KAAA,QAAA,OAAA,IAAA,MAAA,KAAA,KAAA,IAAA,KAAA;MACpF,UAAA,MAAA;IAEA,CAAA,CAAA,GAAOI;EACP;;;",
6
+ "names": ["Schema", "Operation", "Obj", "Type", "DXN", "log", "Message", "ExtractionInput", "objects", "Array", "options", "Struct", "Number", "fallbackToRaw", "optional", "timeElapsed", "key", "make", "name", "description", "icon", "input", "output", "params", "timeout", "error", "message", "pipeline", "log", "_ner", "ner", "__dxlog_file", "entities", "text", "tokenGroups", "createTokenGroups", "combinedEntities", "canBeCombined", "prevToken", "currentToken", "currentState", "prevEntity", "entity", "currentEntity", "prevState", "token", "push", "lastTokenGroup", "score", "reduce", "index", "group", "at", "word", "start", "end", "combinedToken", "Schema", "Filter", "Query", "EID", "EntityId", "log", "__dxlog_file", "ReferencedQuotes", "String", "pipe", "description", "query", "select", "run", "info", "objects", "quote", "id", "toString", "entityId", "text"]
7
+ }