@dxos/assistant 0.8.4-main.ead640a → 0.8.4-main.effb148878

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/neutral/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/neutral/extraction/index.mjs +207 -0
  5. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  6. package/dist/lib/neutral/index.mjs +1803 -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 +1425 -310
  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 +279 -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 +177 -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 +77 -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 +12 -3
  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 +237 -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 +47 -18
  66. package/src/extraction/index.ts +0 -1
  67. package/src/extraction/quotes.test.ts +2 -2
  68. package/src/extraction/quotes.ts +5 -7
  69. package/src/functions/services.ts +119 -63
  70. package/src/index.ts +2 -5
  71. package/src/request/AiRequest.ts +386 -0
  72. package/src/{session → request}/artifact-diff.ts +1 -1
  73. package/src/{session → request}/format.ts +30 -25
  74. package/src/request/index.ts +8 -0
  75. package/src/{session → request}/observer.ts +6 -3
  76. package/src/{session → request}/version-pin.ts +6 -6
  77. package/src/session/AiContext.test.ts +49 -0
  78. package/src/session/AiContext.ts +416 -0
  79. package/src/session/AiSession.ts +324 -0
  80. package/src/session/index.ts +3 -4
  81. package/src/session/toolkit.ts +27 -28
  82. package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
  83. package/src/templates/{system.tpl → instructions/system.tpl} +50 -2
  84. package/src/templates/system.ts +9 -8
  85. package/src/util/artifact.ts +92 -0
  86. package/src/util/diff.test.ts +74 -0
  87. package/src/{diff.ts → util/diff.ts} +18 -4
  88. package/src/{session → util}/error-handling.ts +3 -2
  89. package/src/util/errors.ts +15 -0
  90. package/src/{execution-graph.test.ts → util/execution-graph.test.ts} +47 -45
  91. package/src/{execution-graph.ts → util/execution-graph.ts} +44 -24
  92. package/src/util/index.ts +10 -0
  93. package/src/util/tracing.ts +57 -0
  94. package/dist/lib/browser/chunk-CWGVG235.mjs +0 -380
  95. package/dist/lib/browser/chunk-CWGVG235.mjs.map +0 -7
  96. package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
  97. package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
  98. package/dist/lib/browser/extraction/index.mjs +0 -272
  99. package/dist/lib/browser/extraction/index.mjs.map +0 -7
  100. package/dist/lib/browser/index.mjs +0 -933
  101. package/dist/lib/browser/index.mjs.map +0 -7
  102. package/dist/lib/browser/meta.json +0 -1
  103. package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
  104. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
  105. package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
  106. package/dist/lib/node-esm/chunk-OV5PMQPB.mjs +0 -382
  107. package/dist/lib/node-esm/chunk-OV5PMQPB.mjs.map +0 -7
  108. package/dist/lib/node-esm/extraction/index.mjs +0 -273
  109. package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
  110. package/dist/lib/node-esm/index.mjs +0 -934
  111. package/dist/lib/node-esm/index.mjs.map +0 -7
  112. package/dist/lib/node-esm/meta.json +0 -1
  113. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
  114. package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
  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 -341
  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/artifact-diff.d.ts.map +0 -1
  136. package/dist/types/src/session/error-handling.d.ts.map +0 -1
  137. package/dist/types/src/session/format.d.ts +0 -184
  138. package/dist/types/src/session/format.d.ts.map +0 -1
  139. package/dist/types/src/session/format.test.d.ts +0 -2
  140. package/dist/types/src/session/format.test.d.ts.map +0 -1
  141. package/dist/types/src/session/observer.d.ts.map +0 -1
  142. package/dist/types/src/session/session.d.ts +0 -51
  143. package/dist/types/src/session/session.d.ts.map +0 -1
  144. package/dist/types/src/session/session.test.d.ts +0 -2
  145. package/dist/types/src/session/session.test.d.ts.map +0 -1
  146. package/dist/types/src/session/version-pin.d.ts.map +0 -1
  147. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  148. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  149. package/dist/types/src/types/artifact.d.ts +0 -16
  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 -72
  160. package/src/extraction/extraction-llm-function/index.ts +0 -5
  161. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
  162. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -64
  163. package/src/session/format.test.ts +0 -60
  164. package/src/session/session.conversations.json +0 -1
  165. package/src/session/session.test.ts +0 -149
  166. package/src/session/session.ts +0 -212
  167. package/src/summarization/summarization.test.ts +0 -202
  168. package/src/types/artifact.ts +0 -52
  169. package/src/types/index.ts +0 -5
  170. /package/dist/lib/{browser/named-entity-recognition-QPYHML66.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
  171. /package/dist/types/src/{diff.test.d.ts → util/diff.test.d.ts} +0 -0
  172. /package/dist/types/src/{session → util}/error-handling.d.ts +0 -0
  173. /package/dist/types/src/{execution-graph.test.d.ts → util/execution-graph.test.d.ts} +0 -0
  174. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +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
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
10
+ //# sourceMappingURL=chunk-J5LGTIGS.mjs.map
@@ -0,0 +1,207 @@
1
+ import "../chunk-J5LGTIGS.mjs";
2
+
3
+ // src/extraction/extraction.ts
4
+ import * as Schema from "effect/Schema";
5
+ import { Operation } from "@dxos/compute";
6
+ import { Obj, Type } from "@dxos/echo";
7
+ import { log } from "@dxos/log";
8
+ import { Message } from "@dxos/types";
9
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/extraction.ts";
10
+ var ExtractionInput = Schema.Struct({
11
+ message: Type.getSchema(Message.Message),
12
+ objects: Schema.optional(Schema.Array(Obj.Unknown)),
13
+ options: Schema.optional(Schema.Struct({
14
+ timeout: Schema.optional(Schema.Number),
15
+ fallbackToRaw: Schema.optional(Schema.Boolean)
16
+ }))
17
+ });
18
+ var ExtractionOutput = Schema.Struct({
19
+ message: Type.getSchema(Message.Message),
20
+ timeElapsed: Schema.Number
21
+ });
22
+ var extractionAnthropicFunction = Operation.make({
23
+ meta: {
24
+ key: "org.dxos.function.extraction.anthropic",
25
+ name: "Entity Extraction (Anthropic)",
26
+ description: "Extract entities from transcript using Anthropic LLM.",
27
+ icon: "ph--text-t--regular"
28
+ },
29
+ input: ExtractionInput,
30
+ output: ExtractionOutput
31
+ });
32
+ var extractionNerFunction = Operation.make({
33
+ meta: {
34
+ key: "org.dxos.function.extraction.ner",
35
+ name: "Entity Extraction (NER)",
36
+ description: "Extract entities from transcript using Named Entity Recognition.",
37
+ icon: "ph--text-t--regular"
38
+ },
39
+ input: ExtractionInput,
40
+ output: ExtractionOutput
41
+ });
42
+ var processTranscriptMessage = async (params) => {
43
+ try {
44
+ if (params.options?.timeout && params.options.timeout > 0) {
45
+ } else {
46
+ }
47
+ } catch (error) {
48
+ if (params.options?.fallbackToRaw) {
49
+ log.warn("failed to process message, falling back to raw text", {
50
+ error
51
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 59, S: void 0 });
52
+ return {
53
+ message: params.input.message,
54
+ timeElapsed: 0
55
+ };
56
+ } else {
57
+ throw error;
58
+ }
59
+ }
60
+ return {
61
+ message: params.input.message,
62
+ timeElapsed: 0
63
+ };
64
+ };
65
+
66
+ // src/extraction/extraction-ner-function/named-entity-recognition.ts
67
+ import { pipeline } from "@xenova/transformers";
68
+ import { log as log2 } from "@dxos/log";
69
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/extraction-ner-function/named-entity-recognition.ts";
70
+ var _ner;
71
+ var getNer = () => {
72
+ if (!_ner) {
73
+ _ner = pipeline("ner", "Xenova/bert-base-NER").then((ner) => {
74
+ log2.info("NER model is ready", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 14, S: void 0 });
75
+ return ner;
76
+ });
77
+ }
78
+ return _ner;
79
+ };
80
+ var extractFullEntities = async (text) => {
81
+ const ner = await getNer();
82
+ const entities = await ner(text);
83
+ const tokenGroups = createTokenGroups(entities);
84
+ const combinedEntities = tokenGroups.map(combineNerTokens);
85
+ return combinedEntities;
86
+ };
87
+ var createTokenGroups = (tokens) => {
88
+ const tokenGroups = [];
89
+ const canBeCombined = (prevToken, currentToken) => {
90
+ const [currentState, currentEntity] = currentToken.entity.split("-");
91
+ const [prevState, prevEntity] = prevToken.entity.split("-");
92
+ if (prevEntity !== currentEntity) {
93
+ return false;
94
+ }
95
+ if (prevState === "O") {
96
+ return false;
97
+ }
98
+ if (currentState === "I") {
99
+ return true;
100
+ }
101
+ if ((prevState === "B" || prevState === "I") && currentState === "B") {
102
+ return currentToken.word.startsWith("#");
103
+ }
104
+ return false;
105
+ };
106
+ for (const token of tokens) {
107
+ if (tokenGroups.length === 0) {
108
+ tokenGroups.push([
109
+ token
110
+ ]);
111
+ continue;
112
+ }
113
+ const lastTokenGroup = tokenGroups.at(-1);
114
+ if (canBeCombined(lastTokenGroup.at(-1), token)) {
115
+ lastTokenGroup.push(token);
116
+ continue;
117
+ }
118
+ tokenGroups.push([
119
+ token
120
+ ]);
121
+ }
122
+ return tokenGroups;
123
+ };
124
+ var combineNerTokens = (group) => {
125
+ const combinedToken = {
126
+ entity: group.at(0).entity.split("-")[1],
127
+ score: group.reduce((acc, token) => acc + token.score, 0) / group.length,
128
+ index: group.at(0).index,
129
+ word: group.at(0).word,
130
+ start: group.at(0).start,
131
+ end: group.at(-1).end
132
+ };
133
+ for (const token of group.slice(1)) {
134
+ if (token.word.startsWith("#")) {
135
+ combinedToken.word += token.word.replace(/^#+/, "");
136
+ } else {
137
+ combinedToken.word += " " + token.word;
138
+ }
139
+ }
140
+ return combinedToken;
141
+ };
142
+
143
+ // src/extraction/quotes.ts
144
+ import * as Schema2 from "effect/Schema";
145
+ import { Filter, Query } from "@dxos/echo";
146
+ import { EchoURI, ObjectId } from "@dxos/keys";
147
+ import { log as log3 } from "@dxos/log";
148
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/assistant/src/extraction/quotes.ts";
149
+ var ReferencedQuotes = Schema2.Struct({
150
+ references: Schema2.Array(Schema2.Struct({
151
+ id: Schema2.String,
152
+ quote: Schema2.String
153
+ })).pipe(Schema2.mutable).annotations({
154
+ // TODO(burdon): Does this description make sense?
155
+ description: `
156
+ The references to the context objects that are mentioned in the transcript.
157
+ Quote should match the original transcript text exactly, while id is the id of the context object.
158
+ `
159
+ })
160
+ });
161
+ var findQuotes = async (quotes, db) => {
162
+ const references = await Promise.all(quotes.map(async (quote) => {
163
+ const objects = await db.query(Query.select(Filter.text(quote, {
164
+ type: "vector"
165
+ }))).run();
166
+ log3.info("found quotes in vector index", {
167
+ objects,
168
+ quote
169
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 25, S: void 0 });
170
+ return objects.length > 0 ? [
171
+ {
172
+ id: objects[0].id.toString(),
173
+ quote
174
+ }
175
+ ] : [];
176
+ }));
177
+ return {
178
+ references: references.flat()
179
+ };
180
+ };
181
+ var insertReferences = (text, quotes) => {
182
+ for (const quote of quotes.references) {
183
+ if (!ObjectId.isValid(quote.id)) {
184
+ continue;
185
+ }
186
+ const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
187
+ text = text.replace(regex, `[${quote.quote}](${EchoURI.make({
188
+ objectId: quote.id
189
+ })})`);
190
+ }
191
+ return text;
192
+ };
193
+ export {
194
+ ExtractionInput,
195
+ ExtractionOutput,
196
+ ReferencedQuotes,
197
+ combineNerTokens,
198
+ createTokenGroups,
199
+ extractFullEntities,
200
+ extractionAnthropicFunction,
201
+ extractionNerFunction,
202
+ findQuotes,
203
+ getNer,
204
+ insertReferences,
205
+ processTranscriptMessage
206
+ };
207
+ //# sourceMappingURL=index.mjs.map
@@ -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 { 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: '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: '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 { EchoURI, ObjectId } 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 (!ObjectId.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}](${EchoURI.make({ objectId: 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,eAAe;AAExB,IAAA,eAAaC;AAEXC,IAASP,kBAAuBQ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AO,KAAA,WAAA,GAAA,GAAA;AACLW,oBAAcH,QAAQ,MAAMR,KAAAA,QAAU,OAAA,EAAA;IACxC,OAAA;AACF,oBAAA,QAAA,MAAA,MAAA;IAEA;EACA;;;;;AC9FF,YAAYY,aAAY;AAExB,SAAwBC,QAAQC,aAAa;AAC7C,SAASC,SAASC,gBAAgB;AAClC,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;UAC8DG,QAAUH,IAAAA,OAAQ,MAAA,MAAA,QAAA,uBAAA,MAAA,GAAA,IAAA;AAAC,WAAK,KAAA,QAAA,OAAA,IAAA,MAAA,KAAA,KAAA,QAAA,KAAA;MACxF,UAAA,MAAA;IAEA,CAAA,CAAA,GAAOI;EACP;;;",
6
+ "names": ["Schema", "Operation", "Obj", "Type", "log", "Message", "ExtractionInput", "objects", "Array", "options", "Struct", "Number", "fallbackToRaw", "optional", "timeElapsed", "key", "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", "EchoURI", "ObjectId", "log", "__dxlog_file", "ReferencedQuotes", "String", "pipe", "description", "query", "select", "run", "info", "objects", "quote", "id", "toString", "objectId", "text"]
7
+ }