@dxos/assistant 0.8.4-main.406dc2a → 0.8.4-main.43cb759274
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.
- package/LICENSE +102 -5
- package/README.md +2 -1
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/extraction/index.mjs +208 -0
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1820 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
- package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +1649 -310
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/index.d.ts +0 -1
- package/dist/types/src/extraction/index.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +2 -2
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +13 -15
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/request/AiRequest.d.ts +308 -0
- package/dist/types/src/request/AiRequest.d.ts.map +1 -0
- package/dist/types/src/{session → request}/artifact-diff.d.ts +3 -3
- package/dist/types/src/request/artifact-diff.d.ts.map +1 -0
- package/dist/types/src/request/format.d.ts +15 -0
- package/dist/types/src/request/format.d.ts.map +1 -0
- package/dist/types/src/request/index.d.ts +4 -0
- package/dist/types/src/request/index.d.ts.map +1 -0
- package/dist/types/src/{session → request}/observer.d.ts +6 -5
- package/dist/types/src/request/observer.d.ts.map +1 -0
- package/dist/types/src/{session → request}/version-pin.d.ts +4 -4
- package/dist/types/src/request/version-pin.d.ts.map +1 -0
- package/dist/types/src/session/AiContext.d.ts +178 -0
- package/dist/types/src/session/AiContext.d.ts.map +1 -0
- package/dist/types/src/session/AiContext.test.d.ts +2 -0
- package/dist/types/src/session/AiContext.test.d.ts.map +1 -0
- package/dist/types/src/session/AiSession.d.ts +78 -0
- package/dist/types/src/session/AiSession.d.ts.map +1 -0
- package/dist/types/src/session/index.d.ts +2 -4
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +10 -9
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/templates/system.d.ts +12 -3
- package/dist/types/src/templates/system.d.ts.map +1 -1
- package/dist/types/src/util/artifact.d.ts +18 -0
- package/dist/types/src/util/artifact.d.ts.map +1 -0
- package/dist/types/src/{diff.d.ts → util/diff.d.ts} +3 -1
- package/dist/types/src/util/diff.d.ts.map +1 -0
- package/dist/types/src/{diff.test.d.ts.map → util/diff.test.d.ts.map} +1 -1
- package/dist/types/src/util/error-handling.d.ts.map +1 -0
- package/dist/types/src/{errors.d.ts → util/errors.d.ts} +32 -40
- package/dist/types/src/util/errors.d.ts.map +1 -0
- package/dist/types/src/{execution-graph.d.ts → util/execution-graph.d.ts} +5 -2
- package/dist/types/src/util/execution-graph.d.ts.map +1 -0
- package/dist/types/src/util/execution-graph.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +7 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/src/util/tracing.d.ts +293 -0
- package/dist/types/src/util/tracing.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -42
- package/src/extraction/extraction-ner-function/index.ts +0 -1
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
- package/src/extraction/extraction.ts +48 -18
- package/src/extraction/index.ts +0 -1
- package/src/extraction/quotes.test.ts +2 -2
- package/src/extraction/quotes.ts +6 -8
- package/src/functions/services.ts +133 -64
- package/src/index.ts +2 -5
- package/src/request/AiRequest.ts +387 -0
- package/src/{session → request}/artifact-diff.ts +3 -3
- package/src/{session → request}/format.ts +32 -27
- package/src/request/index.ts +8 -0
- package/src/{session → request}/observer.ts +6 -3
- package/src/{session → request}/version-pin.ts +7 -7
- package/src/session/AiContext.test.ts +49 -0
- package/src/session/AiContext.ts +420 -0
- package/src/session/AiSession.ts +325 -0
- package/src/session/index.ts +3 -4
- package/src/session/toolkit.ts +27 -28
- package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
- package/src/templates/{system.tpl → instructions/system.tpl} +50 -2
- package/src/templates/system.ts +9 -8
- package/src/util/artifact.ts +96 -0
- package/src/util/diff.test.ts +74 -0
- package/src/{diff.ts → util/diff.ts} +18 -4
- package/src/{session → util}/error-handling.ts +3 -2
- package/src/util/errors.ts +15 -0
- package/src/{execution-graph.test.ts → util/execution-graph.test.ts} +48 -46
- package/src/{execution-graph.ts → util/execution-graph.ts} +49 -29
- package/src/util/index.ts +10 -0
- package/src/util/tracing.ts +57 -0
- package/dist/lib/browser/chunk-CWGVG235.mjs +0 -380
- package/dist/lib/browser/chunk-CWGVG235.mjs.map +0 -7
- package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
- package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
- package/dist/lib/browser/extraction/index.mjs +0 -272
- package/dist/lib/browser/extraction/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -933
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OV5PMQPB.mjs +0 -382
- package/dist/lib/node-esm/chunk-OV5PMQPB.mjs.map +0 -7
- package/dist/lib/node-esm/extraction/index.mjs +0 -273
- package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -934
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
- package/dist/types/src/conversation/context.d.ts +0 -103
- package/dist/types/src/conversation/context.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.d.ts +0 -44
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/conversation/index.d.ts +0 -3
- package/dist/types/src/conversation/index.d.ts.map +0 -1
- package/dist/types/src/diff.d.ts.map +0 -1
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/execution-graph.d.ts.map +0 -1
- package/dist/types/src/execution-graph.test.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -341
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +0 -1
- package/dist/types/src/session/error-handling.d.ts.map +0 -1
- package/dist/types/src/session/format.d.ts +0 -184
- package/dist/types/src/session/format.d.ts.map +0 -1
- package/dist/types/src/session/format.test.d.ts +0 -2
- package/dist/types/src/session/format.test.d.ts.map +0 -1
- package/dist/types/src/session/observer.d.ts.map +0 -1
- package/dist/types/src/session/session.d.ts +0 -51
- package/dist/types/src/session/session.d.ts.map +0 -1
- package/dist/types/src/session/session.test.d.ts +0 -2
- package/dist/types/src/session/session.test.d.ts.map +0 -1
- package/dist/types/src/session/version-pin.d.ts.map +0 -1
- package/dist/types/src/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/dist/types/src/types/artifact.d.ts +0 -16
- package/dist/types/src/types/artifact.d.ts.map +0 -1
- package/dist/types/src/types/index.d.ts +0 -2
- package/dist/types/src/types/index.d.ts.map +0 -1
- package/src/conversation/context.ts +0 -186
- package/src/conversation/conversation.ts +0 -132
- package/src/conversation/index.ts +0 -6
- package/src/diff.test.ts +0 -43
- package/src/errors.ts +0 -15
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -72
- package/src/extraction/extraction-llm-function/index.ts +0 -5
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -64
- package/src/session/format.test.ts +0 -60
- package/src/session/session.conversations.json +0 -1
- package/src/session/session.test.ts +0 -149
- package/src/session/session.ts +0 -212
- package/src/summarization/summarization.test.ts +0 -202
- package/src/types/artifact.ts +0 -52
- package/src/types/index.ts +0 -5
- /package/dist/lib/{browser/named-entity-recognition-QPYHML66.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/types/src/{diff.test.d.ts → util/diff.test.d.ts} +0 -0
- /package/dist/types/src/{session → util}/error-handling.d.ts +0 -0
- /package/dist/types/src/{execution-graph.test.d.ts → util/execution-graph.test.d.ts} +0 -0
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/assistant",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.43cb759274",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
-
"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
8
12
|
"author": "info@dxos.org",
|
|
9
13
|
"sideEffects": true,
|
|
10
14
|
"type": "module",
|
|
@@ -12,65 +16,55 @@
|
|
|
12
16
|
".": {
|
|
13
17
|
"source": "./src/index.ts",
|
|
14
18
|
"types": "./dist/types/src/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
19
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
17
20
|
},
|
|
18
21
|
"./extraction": {
|
|
19
22
|
"source": "./src/extraction/index.ts",
|
|
20
23
|
"types": "./dist/types/src/extraction/index.d.ts",
|
|
21
|
-
"
|
|
22
|
-
"node": "./dist/lib/node-esm/extraction/index.mjs"
|
|
24
|
+
"default": "./dist/lib/neutral/extraction/index.mjs"
|
|
23
25
|
}
|
|
24
26
|
},
|
|
25
27
|
"types": "dist/types/src/index.d.ts",
|
|
26
|
-
"typesVersions": {
|
|
27
|
-
"*": {
|
|
28
|
-
"types": [
|
|
29
|
-
"dist/types/src/types/index.d.ts"
|
|
30
|
-
],
|
|
31
|
-
"extraction": [
|
|
32
|
-
"dist/types/src/extraction/index.d.ts"
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
28
|
"files": [
|
|
37
29
|
"dist",
|
|
38
30
|
"src"
|
|
39
31
|
],
|
|
40
32
|
"dependencies": {
|
|
41
|
-
"@automerge/automerge": "3.1
|
|
42
|
-
"@effect/
|
|
43
|
-
"@effect/
|
|
44
|
-
"@effect/
|
|
45
|
-
"@
|
|
33
|
+
"@automerge/automerge": "3.3.0-fragments.1",
|
|
34
|
+
"@effect-atom/atom": "^0.5.3",
|
|
35
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
36
|
+
"@effect/ai": "0.35.0",
|
|
37
|
+
"@effect/experimental": "0.60.0",
|
|
38
|
+
"@effect/platform": "0.96.1",
|
|
46
39
|
"@xenova/transformers": "^2.17.2",
|
|
47
40
|
"lodash.defaultsdeep": "^4.6.1",
|
|
48
|
-
"@dxos/ai": "0.8.4-main.
|
|
49
|
-
"@dxos/async": "0.8.4-main.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/context": "0.8.4-main.
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/echo-protocol": "0.8.4-main.
|
|
56
|
-
"@dxos/effect": "0.8.4-main.
|
|
57
|
-
"@dxos/errors": "0.8.4-main.
|
|
58
|
-
"@dxos/functions": "0.8.4-main.
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/schema": "0.8.4-main.
|
|
66
|
-
"@dxos/util": "0.8.4-main.
|
|
41
|
+
"@dxos/ai": "0.8.4-main.43cb759274",
|
|
42
|
+
"@dxos/async": "0.8.4-main.43cb759274",
|
|
43
|
+
"@dxos/compute": "0.8.4-main.43cb759274",
|
|
44
|
+
"@dxos/context": "0.8.4-main.43cb759274",
|
|
45
|
+
"@dxos/echo": "0.8.4-main.43cb759274",
|
|
46
|
+
"@dxos/echo-db": "0.8.4-main.43cb759274",
|
|
47
|
+
"@dxos/debug": "0.8.4-main.43cb759274",
|
|
48
|
+
"@dxos/echo-protocol": "0.8.4-main.43cb759274",
|
|
49
|
+
"@dxos/effect": "0.8.4-main.43cb759274",
|
|
50
|
+
"@dxos/errors": "0.8.4-main.43cb759274",
|
|
51
|
+
"@dxos/functions": "0.8.4-main.43cb759274",
|
|
52
|
+
"@dxos/graph": "0.8.4-main.43cb759274",
|
|
53
|
+
"@dxos/invariant": "0.8.4-main.43cb759274",
|
|
54
|
+
"@dxos/log": "0.8.4-main.43cb759274",
|
|
55
|
+
"@dxos/keys": "0.8.4-main.43cb759274",
|
|
56
|
+
"@dxos/mcp-client": "0.8.4-main.43cb759274",
|
|
57
|
+
"@dxos/node-std": "0.8.4-main.43cb759274",
|
|
58
|
+
"@dxos/schema": "0.8.4-main.43cb759274",
|
|
59
|
+
"@dxos/util": "0.8.4-main.43cb759274",
|
|
60
|
+
"@dxos/types": "0.8.4-main.43cb759274"
|
|
67
61
|
},
|
|
68
62
|
"devDependencies": {
|
|
69
63
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
70
|
-
"effect": "3.
|
|
64
|
+
"effect": "3.21.2"
|
|
71
65
|
},
|
|
72
66
|
"peerDependencies": {
|
|
73
|
-
"effect": "
|
|
67
|
+
"effect": "3.21.2"
|
|
74
68
|
},
|
|
75
69
|
"publishConfig": {
|
|
76
70
|
"access": "public"
|
|
@@ -6,7 +6,8 @@ import { type TokenClassificationOutput, type TokenClassificationPipelineType }
|
|
|
6
6
|
import { beforeAll, describe, expect, test } from 'vitest';
|
|
7
7
|
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
-
import {
|
|
9
|
+
import { type ContentBlock, type Message } from '@dxos/types';
|
|
10
|
+
import { createTestData } from '@dxos/types/testing';
|
|
10
11
|
|
|
11
12
|
import { combineNerTokens, createTokenGroups, extractFullEntities, getNer } from './named-entity-recognition';
|
|
12
13
|
|
|
@@ -57,8 +58,10 @@ describe.skip('NamedEntityRecognition', () => {
|
|
|
57
58
|
test('own data', async () => {
|
|
58
59
|
const { transcriptWoflram, transcriptJosiah } = await createTestData();
|
|
59
60
|
|
|
60
|
-
const blocks = [...transcriptWoflram, ...transcriptJosiah].flatMap((message) =>
|
|
61
|
-
message.blocks.flatMap((block) =>
|
|
61
|
+
const blocks = [...transcriptWoflram, ...transcriptJosiah].flatMap((message: Message.Message) =>
|
|
62
|
+
message.blocks.flatMap((block: ContentBlock.Any) =>
|
|
63
|
+
block._tag === 'transcript' ? [(block as ContentBlock.Transcript).text] : [],
|
|
64
|
+
),
|
|
62
65
|
);
|
|
63
66
|
|
|
64
67
|
for (const block of blocks) {
|
|
@@ -70,8 +73,10 @@ describe.skip('NamedEntityRecognition', () => {
|
|
|
70
73
|
test('more own data', async () => {
|
|
71
74
|
const { transcriptMessages } = await createTestData();
|
|
72
75
|
|
|
73
|
-
const blocks = transcriptMessages.flatMap((message) =>
|
|
74
|
-
message.blocks.flatMap((block) =>
|
|
76
|
+
const blocks = transcriptMessages.flatMap((message: Message.Message) =>
|
|
77
|
+
message.blocks.flatMap((block: ContentBlock.Any) =>
|
|
78
|
+
block._tag === 'transcript' ? [(block as ContentBlock.Transcript).text] : [],
|
|
79
|
+
),
|
|
75
80
|
);
|
|
76
81
|
|
|
77
82
|
for (const block of blocks) {
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
import { Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
|
-
import {
|
|
11
|
+
import { Message } from '@dxos/types';
|
|
12
12
|
|
|
13
13
|
export const ExtractionInput = Schema.Struct({
|
|
14
|
-
message:
|
|
15
|
-
objects: Schema.optional(Schema.Array(
|
|
14
|
+
message: Type.getSchema(Message.Message),
|
|
15
|
+
objects: Schema.optional(Schema.Array(Obj.Unknown)),
|
|
16
16
|
options: Schema.optional(
|
|
17
17
|
Schema.Struct({
|
|
18
18
|
timeout: Schema.optional(Schema.Number),
|
|
@@ -20,18 +20,15 @@ export const ExtractionInput = Schema.Struct({
|
|
|
20
20
|
}),
|
|
21
21
|
),
|
|
22
22
|
});
|
|
23
|
-
export
|
|
24
|
-
|
|
23
|
+
export type ExtractionInput = Schema.Schema.Type<typeof ExtractionInput>;
|
|
25
24
|
export const ExtractionOutput = Schema.Struct({
|
|
26
|
-
message:
|
|
25
|
+
message: Type.getSchema(Message.Message),
|
|
27
26
|
timeElapsed: Schema.Number,
|
|
28
27
|
});
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
export type ProcessTranscriptMessageParams = {
|
|
28
|
+
export type ExtractionOutput = Schema.Schema.Type<typeof ExtractionOutput>;
|
|
29
|
+
export type ProcessTranscriptMessageProps = {
|
|
32
30
|
input: ExtractionInput;
|
|
33
|
-
function:
|
|
34
|
-
executor: FunctionExecutor;
|
|
31
|
+
function: Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
35
32
|
|
|
36
33
|
options?: {
|
|
37
34
|
/**
|
|
@@ -48,18 +45,48 @@ export type ProcessTranscriptMessageParams = {
|
|
|
48
45
|
};
|
|
49
46
|
};
|
|
50
47
|
|
|
51
|
-
export type ExtractionFunction =
|
|
48
|
+
export type ExtractionFunction = Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Placeholder for Anthropic-based entity extraction.
|
|
52
|
+
* Implementation is currently disabled pending restoration of extraction logic.
|
|
53
|
+
*/
|
|
54
|
+
export const extractionAnthropicFunction = Operation.make({
|
|
55
|
+
meta: {
|
|
56
|
+
key: DXN.make('org.dxos.function.extraction.anthropic'),
|
|
57
|
+
name: 'Entity Extraction (Anthropic)',
|
|
58
|
+
description: 'Extract entities from transcript using Anthropic LLM.',
|
|
59
|
+
icon: 'ph--text-t--regular',
|
|
60
|
+
},
|
|
61
|
+
input: ExtractionInput,
|
|
62
|
+
output: ExtractionOutput,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Placeholder for NER-based entity extraction.
|
|
67
|
+
* Implementation is currently disabled pending restoration of extraction logic.
|
|
68
|
+
*/
|
|
69
|
+
export const extractionNerFunction = Operation.make({
|
|
70
|
+
meta: {
|
|
71
|
+
key: DXN.make('org.dxos.function.extraction.ner'),
|
|
72
|
+
name: 'Entity Extraction (NER)',
|
|
73
|
+
description: 'Extract entities from transcript using Named Entity Recognition.',
|
|
74
|
+
icon: 'ph--text-t--regular',
|
|
75
|
+
},
|
|
76
|
+
input: ExtractionInput,
|
|
77
|
+
output: ExtractionOutput,
|
|
78
|
+
});
|
|
52
79
|
|
|
53
80
|
/**
|
|
54
81
|
* Extract entities from the transcript message and add them to the message.
|
|
55
82
|
*/
|
|
56
83
|
// TODO(dmaretskyi): Move context to a vector search index.
|
|
57
|
-
export const processTranscriptMessage = async (params:
|
|
84
|
+
export const processTranscriptMessage = async (params: ProcessTranscriptMessageProps): Promise<ExtractionOutput> => {
|
|
58
85
|
try {
|
|
59
86
|
if (params.options?.timeout && params.options.timeout > 0) {
|
|
60
|
-
return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
|
|
87
|
+
// return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
|
|
61
88
|
} else {
|
|
62
|
-
return await params.executor.invoke(params.function, params.input);
|
|
89
|
+
// return await params.executor.invoke(params.function, params.input);
|
|
63
90
|
}
|
|
64
91
|
} catch (error) {
|
|
65
92
|
if (params.options?.fallbackToRaw) {
|
|
@@ -72,4 +99,7 @@ export const processTranscriptMessage = async (params: ProcessTranscriptMessageP
|
|
|
72
99
|
throw error;
|
|
73
100
|
}
|
|
74
101
|
}
|
|
102
|
+
|
|
103
|
+
// TODO(dmaretskyi): Restore extraction logic.
|
|
104
|
+
return { message: params.input.message, timeElapsed: 0 };
|
|
75
105
|
};
|
package/src/extraction/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ describe('insertReferences', () => {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
expect(insertReferences('This is a computational irreducibility test.', quotes)).toBe(
|
|
16
|
-
'This is a [computational irreducibility](
|
|
16
|
+
'This is a [computational irreducibility](echo:/01JTG9JW11XGWJZ32AW8ET93D1) test.',
|
|
17
17
|
);
|
|
18
18
|
expect(
|
|
19
19
|
insertReferences(
|
|
@@ -21,7 +21,7 @@ describe('insertReferences', () => {
|
|
|
21
21
|
quotes,
|
|
22
22
|
),
|
|
23
23
|
).toBe(
|
|
24
|
-
"And what I'd like to talk today about is Steven Wolfram's concept of a [computational irreducibility](
|
|
24
|
+
"And what I'd like to talk today about is Steven Wolfram's concept of a [computational irreducibility](echo:/01JTG9JW11XGWJZ32AW8ET93D1).",
|
|
25
25
|
);
|
|
26
26
|
});
|
|
27
27
|
});
|
package/src/extraction/quotes.ts
CHANGED
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Filter, Query } from '@dxos/echo';
|
|
8
|
-
import {
|
|
9
|
-
import { type EchoDatabase } from '@dxos/echo-db';
|
|
10
|
-
import { DXN } from '@dxos/keys';
|
|
7
|
+
import { type Database, Filter, Query } from '@dxos/echo';
|
|
8
|
+
import { EID, EntityId } from '@dxos/keys';
|
|
11
9
|
import { log } from '@dxos/log';
|
|
12
10
|
|
|
13
11
|
export const ReferencedQuotes = Schema.Struct({
|
|
@@ -28,10 +26,10 @@ export const ReferencedQuotes = Schema.Struct({
|
|
|
28
26
|
});
|
|
29
27
|
export type ReferencedQuotes = Schema.Schema.Type<typeof ReferencedQuotes>;
|
|
30
28
|
|
|
31
|
-
export const findQuotes = async (quotes: string[], db:
|
|
29
|
+
export const findQuotes = async (quotes: string[], db: Database.Database): Promise<ReferencedQuotes> => {
|
|
32
30
|
const references = await Promise.all(
|
|
33
31
|
quotes.map(async (quote) => {
|
|
34
|
-
const
|
|
32
|
+
const objects = await db.query(Query.select(Filter.text(quote, { type: 'vector' }))).run();
|
|
35
33
|
log.info('found quotes in vector index', { objects, quote });
|
|
36
34
|
return objects.length > 0 ? [{ id: objects[0].id.toString(), quote }] : [];
|
|
37
35
|
}),
|
|
@@ -45,13 +43,13 @@ export const findQuotes = async (quotes: string[], db: EchoDatabase): Promise<Re
|
|
|
45
43
|
// TODO(dmaretskyi): Lookup and verifiy ids from provided context.
|
|
46
44
|
export const insertReferences = (text: string, quotes: ReferencedQuotes) => {
|
|
47
45
|
for (const quote of quotes.references) {
|
|
48
|
-
if (!
|
|
46
|
+
if (!EntityId.isValid(quote.id)) {
|
|
49
47
|
continue;
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
// Use a case-insensitive regular expression to replace the quote.
|
|
53
51
|
const regex = new RegExp(quote.quote.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
|
|
54
|
-
text = text.replace(regex, `[${quote.quote}](${
|
|
52
|
+
text = text.replace(regex, `[${quote.quote}](${EID.make({ entityId: quote.id })})`);
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
return text;
|
|
@@ -7,71 +7,67 @@ import type * as Toolkit from '@effect/ai/Toolkit';
|
|
|
7
7
|
import * as Context from 'effect/Context';
|
|
8
8
|
import * as Effect from 'effect/Effect';
|
|
9
9
|
import * as Layer from 'effect/Layer';
|
|
10
|
+
import * as Option from 'effect/Option';
|
|
10
11
|
import * as Record from 'effect/Record';
|
|
11
12
|
import * as Schema from 'effect/Schema';
|
|
13
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
12
14
|
|
|
13
15
|
import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
16
|
+
import { OpaqueToolkit } from '@dxos/ai';
|
|
17
|
+
import { Operation, OperationRegistry } from '@dxos/compute';
|
|
14
18
|
import { todo } from '@dxos/debug';
|
|
15
|
-
import {
|
|
16
|
-
import { DatabaseService, FunctionDefinition, FunctionInvocationService, FunctionType } from '@dxos/functions';
|
|
19
|
+
import { Ref } from '@dxos/echo';
|
|
17
20
|
import { invariant } from '@dxos/invariant';
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* Requires `DatabaseService` in the environment.
|
|
29
|
-
*/
|
|
30
|
-
export const makeToolResolverFromFunctions = (
|
|
31
|
-
functions: FunctionDefinition<any, any>[],
|
|
32
|
-
toolkit: Toolkit.Toolkit<any>,
|
|
33
|
-
): Layer.Layer<ToolResolverService, never, DatabaseService> => {
|
|
22
|
+
import { RefFromLLM } from '../util';
|
|
23
|
+
|
|
24
|
+
export const makeToolResolverFromOperations = <R = never>({
|
|
25
|
+
toolkit: extraToolkit = OpaqueToolkit.empty,
|
|
26
|
+
}: { toolkit?: OpaqueToolkit.OpaqueToolkit<never, never, R> } = {}): Layer.Layer<
|
|
27
|
+
ToolResolverService,
|
|
28
|
+
never,
|
|
29
|
+
OpaqueToolkit.OpaqueToolkitProvider | OperationRegistry.Service | R
|
|
30
|
+
> => {
|
|
34
31
|
return Layer.effect(
|
|
35
32
|
ToolResolverService,
|
|
36
33
|
Effect.gen(function* () {
|
|
37
|
-
const
|
|
34
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
35
|
+
const operationRegistry = yield* OperationRegistry.Service;
|
|
38
36
|
return {
|
|
39
37
|
resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
|
|
40
38
|
Effect.gen(function* () {
|
|
41
|
-
const
|
|
39
|
+
const toolkit = OpaqueToolkit.merge(extraToolkit, toolkitProvider.getToolkit());
|
|
40
|
+
|
|
41
|
+
const tool = toolkit.toolkit.tools[id];
|
|
42
42
|
if (tool) {
|
|
43
43
|
return tool;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return yield* Effect.fail(new AiToolNotFoundError(id));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return projectFunctionToTool(functionDef);
|
|
59
|
-
}).pipe(Effect.provideService(DatabaseService, dbService)),
|
|
46
|
+
return yield* operationRegistry.resolve(id).pipe(
|
|
47
|
+
Effect.flatMap(
|
|
48
|
+
Option.match({
|
|
49
|
+
onSome: (_) => Effect.succeed(projectFunctionToTool(_)),
|
|
50
|
+
onNone: () => Effect.fail(new AiToolNotFoundError(id)),
|
|
51
|
+
}),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
}),
|
|
60
55
|
} satisfies Context.Tag.Service<ToolResolverService>;
|
|
61
56
|
}),
|
|
62
57
|
);
|
|
63
58
|
};
|
|
64
59
|
|
|
65
|
-
export const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return Layer.effect(
|
|
60
|
+
export const makeToolExecutionService = <E, R>(opts: {
|
|
61
|
+
invoke: (tool: Tool.Any, input: unknown) => Effect.Effect<unknown>;
|
|
62
|
+
}): Layer.Layer<ToolExecutionService, never, OpaqueToolkit.OpaqueToolkitProvider> =>
|
|
63
|
+
Layer.effect(
|
|
70
64
|
ToolExecutionService,
|
|
71
65
|
Effect.gen(function* () {
|
|
72
|
-
const
|
|
66
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
67
|
+
const toolkit = toolkitProvider.getToolkit();
|
|
68
|
+
|
|
69
|
+
const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
|
|
73
70
|
invariant(isHandlerLike(toolkitHandler));
|
|
74
|
-
const functionInvocationService = yield* FunctionInvocationService;
|
|
75
71
|
|
|
76
72
|
return {
|
|
77
73
|
handlersFor: (toolkit) => {
|
|
@@ -81,15 +77,13 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
81
77
|
if (Tool.isProviderDefined(tool)) {
|
|
82
78
|
throw new Error('Attempted to call a provider-defined tool');
|
|
83
79
|
}
|
|
80
|
+
|
|
84
81
|
// TODO(wittjosiah): Everything is `never` here.
|
|
85
|
-
|
|
82
|
+
const { result } = yield* (toolkitHandler.handle as any)(tool.name, input);
|
|
83
|
+
return result;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return yield* functionInvocationService
|
|
91
|
-
.invokeFunction(functionDef, input as any)
|
|
92
|
-
.pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
86
|
+
return yield* opts.invoke(tool, input).pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
93
87
|
});
|
|
94
88
|
};
|
|
95
89
|
|
|
@@ -100,34 +94,70 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
100
94
|
};
|
|
101
95
|
}),
|
|
102
96
|
);
|
|
97
|
+
|
|
98
|
+
export const makeToolExecutionServiceFromOperationInvoker = (): Layer.Layer<
|
|
99
|
+
ToolExecutionService,
|
|
100
|
+
never,
|
|
101
|
+
Operation.Service | OpaqueToolkit.OpaqueToolkitProvider
|
|
102
|
+
> => {
|
|
103
|
+
return Layer.unwrapEffect(
|
|
104
|
+
Effect.gen(function* () {
|
|
105
|
+
const operationInvoker = yield* Operation.Service;
|
|
106
|
+
|
|
107
|
+
return makeToolExecutionService({
|
|
108
|
+
invoke: (tool, input) =>
|
|
109
|
+
Effect.gen(function* () {
|
|
110
|
+
const operationDef = getOperationFromTool(tool).pipe(Option.getOrThrow);
|
|
111
|
+
|
|
112
|
+
return yield* operationInvoker.invoke(operationDef, input).pipe(Effect.orDie);
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
103
117
|
};
|
|
104
118
|
|
|
119
|
+
export const ToolExecutionServices = Layer.mergeAll(
|
|
120
|
+
makeToolResolverFromOperations(),
|
|
121
|
+
makeToolExecutionServiceFromOperationInvoker(),
|
|
122
|
+
);
|
|
123
|
+
|
|
105
124
|
class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
|
|
106
125
|
FunctionToolAnnotation,
|
|
107
|
-
{ definition:
|
|
126
|
+
{ definition: Operation.Definition.Any }
|
|
108
127
|
>() {}
|
|
109
128
|
|
|
110
|
-
const
|
|
129
|
+
export const getOperationFromTool = (tool: Tool.Any): Option.Option<Operation.Definition.Any> => {
|
|
130
|
+
return Context.getOption(FunctionToolAnnotation)(tool.annotations).pipe(Option.map(({ definition }) => definition));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const toolCache = new WeakMap<Operation.Definition.Any, Tool.Any>();
|
|
111
134
|
|
|
112
135
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @param meta.deployedFunctionId Backend deployment ID used for remote invocation when present. This is the
|
|
118
|
-
* EDGE service's function deployment identifier (not the ECHO object ID/DXN and not `FunctionDefinition.key`).
|
|
136
|
+
* Empty parameters schema annotated with an explicit JSON schema so that
|
|
137
|
+
* @effect/ai versions that call JSONSchema.fromAST directly (≥0.35.0) still
|
|
138
|
+
* produce a valid `{type: "object"}` for the Anthropic API instead of the
|
|
139
|
+
* constEmptyStruct `{anyOf: [{type:"object"},{type:"array"}]}`.
|
|
119
140
|
*/
|
|
120
|
-
const
|
|
141
|
+
const EMPTY_PARAMETERS_SCHEMA = Schema.Struct({}).annotations({
|
|
142
|
+
[SchemaAST.JSONSchemaAnnotationId]: { type: 'object', properties: {}, required: [], additionalProperties: false },
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Projects an `Operation.Definition` into an `AiTool`.
|
|
147
|
+
*/
|
|
148
|
+
const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
|
|
121
149
|
if (toolCache.has(fn)) {
|
|
122
150
|
return toolCache.get(fn)!;
|
|
123
151
|
}
|
|
124
152
|
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
failure: Schema.Any,
|
|
130
|
-
})
|
|
153
|
+
const fields = createStructFieldsFromSchema(fn.input);
|
|
154
|
+
const parametersSchema = Object.keys(fields).length === 0 ? EMPTY_PARAMETERS_SCHEMA : Schema.Struct(fields);
|
|
155
|
+
const tool = Tool.make(makeToolName(fn.meta.name ?? fn.meta.key), {
|
|
156
|
+
description: fn.meta.description,
|
|
157
|
+
failure: Schema.Any,
|
|
158
|
+
})
|
|
159
|
+
.setParameters(parametersSchema)
|
|
160
|
+
.annotate(FunctionToolAnnotation, { definition: fn });
|
|
131
161
|
toolCache.set(fn, tool);
|
|
132
162
|
return tool;
|
|
133
163
|
};
|
|
@@ -136,8 +166,8 @@ const projectFunctionToTool = (fn: FunctionDefinition<any, any>): Tool.Any => {
|
|
|
136
166
|
* @returns Tool name produced from function name by escaping invalid characters.
|
|
137
167
|
*/
|
|
138
168
|
const makeToolName = (name: string) => {
|
|
139
|
-
const toolName = name.replace(/[^a-zA-Z0-9]/g, '
|
|
140
|
-
invariant(toolName.match(/^[a-
|
|
169
|
+
const toolName = name.toLowerCase().replace(/[^a-zA-Z0-9]/g, '-');
|
|
170
|
+
invariant(toolName.match(/^[a-z_][a-z0-9-_]*$/));
|
|
141
171
|
return toolName;
|
|
142
172
|
};
|
|
143
173
|
|
|
@@ -145,7 +175,9 @@ const makeToolName = (name: string) => {
|
|
|
145
175
|
const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<string, Schema.Schema<any, any>> => {
|
|
146
176
|
switch (schema.ast._tag) {
|
|
147
177
|
case 'TypeLiteral':
|
|
148
|
-
return Object.fromEntries(
|
|
178
|
+
return Object.fromEntries(
|
|
179
|
+
schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(mapSchemaTypeForLLM(prop.type))]),
|
|
180
|
+
);
|
|
149
181
|
case 'VoidKeyword':
|
|
150
182
|
return {};
|
|
151
183
|
default:
|
|
@@ -153,6 +185,43 @@ const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<s
|
|
|
153
185
|
}
|
|
154
186
|
};
|
|
155
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Picks an LLM-friendly schema type for the given schema AST.
|
|
190
|
+
* The picked schema type decodes to the original schema type.
|
|
191
|
+
*/
|
|
192
|
+
const mapSchemaTypeForLLM = (ast: SchemaAST.AST): SchemaAST.AST => {
|
|
193
|
+
if (Ref.isRefType(ast)) {
|
|
194
|
+
const description = ast.annotations.description
|
|
195
|
+
? ast.annotations.description + '\n' + RefFromLLM.ast.annotations.description
|
|
196
|
+
: (RefFromLLM.ast.annotations.description as string);
|
|
197
|
+
return RefFromLLM.annotations({ description }).ast;
|
|
198
|
+
} else if (SchemaAST.isTupleType(ast)) {
|
|
199
|
+
return new SchemaAST.TupleType(
|
|
200
|
+
ast.elements.map((t) => new SchemaAST.OptionalType(mapSchemaTypeForLLM(t.type), t.isOptional, t.annotations)),
|
|
201
|
+
ast.rest.map((t) => new SchemaAST.Type(mapSchemaTypeForLLM(t.type), t.annotations)),
|
|
202
|
+
ast.isReadonly,
|
|
203
|
+
ast.annotations,
|
|
204
|
+
);
|
|
205
|
+
} else if (SchemaAST.isTypeLiteral(ast)) {
|
|
206
|
+
return new SchemaAST.TypeLiteral(
|
|
207
|
+
ast.propertySignatures.map(
|
|
208
|
+
(p) =>
|
|
209
|
+
new SchemaAST.PropertySignature(
|
|
210
|
+
p.name,
|
|
211
|
+
mapSchemaTypeForLLM(p.type),
|
|
212
|
+
p.isOptional,
|
|
213
|
+
p.isReadonly,
|
|
214
|
+
p.annotations,
|
|
215
|
+
),
|
|
216
|
+
),
|
|
217
|
+
ast.indexSignatures,
|
|
218
|
+
ast.annotations,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return ast;
|
|
223
|
+
};
|
|
224
|
+
|
|
156
225
|
const isHandlerLike = (value: unknown): value is Toolkit.WithHandler<Record<string, Tool.Any>> => {
|
|
157
226
|
return typeof (value as any).tools === 'object' && typeof (value as any).handle === 'function';
|
|
158
227
|
};
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './conversation';
|
|
6
|
-
export * from './diff';
|
|
7
|
-
export * from './errors';
|
|
8
|
-
export * from './execution-graph';
|
|
9
5
|
export * from './functions';
|
|
6
|
+
export * from './request';
|
|
10
7
|
export * from './session';
|
|
11
8
|
export * from './templates';
|
|
12
|
-
export * from './
|
|
9
|
+
export * from './util';
|