@dxos/assistant 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +204 -0
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1755 -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 +1065 -312
- 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 +104 -0
- package/dist/types/src/request/AiRequest.d.ts.map +1 -0
- package/dist/types/src/{session → request}/artifact-diff.d.ts +1 -1
- 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 +3 -3
- package/dist/types/src/request/version-pin.d.ts.map +1 -0
- package/dist/types/src/session/AiContext.d.ts +154 -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 +73 -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 +1 -2
- package/dist/types/src/templates/system.d.ts.map +1 -1
- package/dist/types/src/util/artifact.d.ts +27 -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 +233 -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 +43 -14
- package/src/extraction/index.ts +0 -1
- package/src/extraction/quotes.ts +4 -5
- package/src/functions/services.ts +119 -63
- package/src/index.ts +2 -5
- package/src/request/AiRequest.ts +348 -0
- package/src/{session → request}/artifact-diff.ts +1 -1
- package/src/{session → request}/format.ts +29 -24
- package/src/request/index.ts +8 -0
- package/src/{session → request}/observer.ts +6 -3
- package/src/{session → request}/version-pin.ts +6 -6
- package/src/session/AiContext.test.ts +53 -0
- package/src/session/AiContext.ts +403 -0
- package/src/session/AiSession.ts +324 -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/{types → util}/artifact.ts +42 -6
- package/src/util/diff.test.ts +74 -0
- package/src/{diff.ts → util/diff.ts} +13 -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} +47 -45
- package/src/{execution-graph.ts → util/execution-graph.ts} +41 -22
- package/src/util/index.ts +10 -0
- package/src/util/tracing.ts +57 -0
- package/dist/lib/browser/chunk-4VIJTKPM.mjs +0 -354
- package/dist/lib/browser/chunk-4VIJTKPM.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 -900
- 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-AUUC7II4.mjs +0 -356
- package/dist/lib/node-esm/chunk-AUUC7II4.mjs.map +0 -7
- 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/extraction/index.mjs +0 -273
- package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -901
- 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 -41
- 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 -345
- 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 -186
- 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 -128
- 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 -213
- package/src/summarization/summarization.test.ts +0 -202
- 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.bc2380dfbc",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
-
"
|
|
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.
|
|
42
|
-
"@effect/
|
|
43
|
-
"@effect/
|
|
44
|
-
"@effect/
|
|
45
|
-
"@
|
|
33
|
+
"@automerge/automerge": "3.2.6",
|
|
34
|
+
"@effect-atom/atom": "^0.5.1",
|
|
35
|
+
"@effect-atom/atom-react": "^0.5.0",
|
|
36
|
+
"@effect/ai": "0.33.2",
|
|
37
|
+
"@effect/experimental": "0.58.0",
|
|
38
|
+
"@effect/platform": "0.94.4",
|
|
46
39
|
"@xenova/transformers": "^2.17.2",
|
|
47
40
|
"lodash.defaultsdeep": "^4.6.1",
|
|
48
|
-
"@dxos/async": "0.8.4-main.
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/echo-
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/functions": "0.8.4-main.
|
|
58
|
-
"@dxos/graph": "0.8.4-main.
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/util": "0.8.4-main.
|
|
41
|
+
"@dxos/async": "0.8.4-main.bc2380dfbc",
|
|
42
|
+
"@dxos/debug": "0.8.4-main.bc2380dfbc",
|
|
43
|
+
"@dxos/compute": "0.8.4-main.bc2380dfbc",
|
|
44
|
+
"@dxos/context": "0.8.4-main.bc2380dfbc",
|
|
45
|
+
"@dxos/echo-db": "0.8.4-main.bc2380dfbc",
|
|
46
|
+
"@dxos/echo-protocol": "0.8.4-main.bc2380dfbc",
|
|
47
|
+
"@dxos/effect": "0.8.4-main.bc2380dfbc",
|
|
48
|
+
"@dxos/echo": "0.8.4-main.bc2380dfbc",
|
|
49
|
+
"@dxos/errors": "0.8.4-main.bc2380dfbc",
|
|
50
|
+
"@dxos/functions": "0.8.4-main.bc2380dfbc",
|
|
51
|
+
"@dxos/graph": "0.8.4-main.bc2380dfbc",
|
|
52
|
+
"@dxos/keys": "0.8.4-main.bc2380dfbc",
|
|
53
|
+
"@dxos/log": "0.8.4-main.bc2380dfbc",
|
|
54
|
+
"@dxos/node-std": "0.8.4-main.bc2380dfbc",
|
|
55
|
+
"@dxos/mcp-client": "0.8.4-main.bc2380dfbc",
|
|
56
|
+
"@dxos/schema": "0.8.4-main.bc2380dfbc",
|
|
57
|
+
"@dxos/invariant": "0.8.4-main.bc2380dfbc",
|
|
58
|
+
"@dxos/types": "0.8.4-main.bc2380dfbc",
|
|
59
|
+
"@dxos/util": "0.8.4-main.bc2380dfbc",
|
|
60
|
+
"@dxos/ai": "0.8.4-main.bc2380dfbc"
|
|
67
61
|
},
|
|
68
62
|
"devDependencies": {
|
|
69
63
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
70
|
-
"effect": "3.
|
|
64
|
+
"effect": "3.20.0"
|
|
71
65
|
},
|
|
72
66
|
"peerDependencies": {
|
|
73
|
-
"effect": "
|
|
67
|
+
"effect": "3.20.0"
|
|
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,14 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { type FunctionDefinition, type FunctionExecutor } from '@dxos/functions';
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
|
-
import {
|
|
10
|
+
import { Message } from '@dxos/types';
|
|
12
11
|
|
|
13
12
|
export const ExtractionInput = Schema.Struct({
|
|
14
|
-
message:
|
|
15
|
-
objects: Schema.optional(Schema.Array(
|
|
13
|
+
message: Message.Message,
|
|
14
|
+
objects: Schema.optional(Schema.Array(Obj.Unknown)),
|
|
16
15
|
options: Schema.optional(
|
|
17
16
|
Schema.Struct({
|
|
18
17
|
timeout: Schema.optional(Schema.Number),
|
|
@@ -23,15 +22,14 @@ export const ExtractionInput = Schema.Struct({
|
|
|
23
22
|
export interface ExtractionInput extends Schema.Schema.Type<typeof ExtractionInput> {}
|
|
24
23
|
|
|
25
24
|
export const ExtractionOutput = Schema.Struct({
|
|
26
|
-
message:
|
|
25
|
+
message: Message.Message,
|
|
27
26
|
timeElapsed: Schema.Number,
|
|
28
27
|
});
|
|
29
28
|
export interface ExtractionOutput extends Schema.Schema.Type<typeof ExtractionOutput> {}
|
|
30
29
|
|
|
31
|
-
export type
|
|
30
|
+
export type ProcessTranscriptMessageProps = {
|
|
32
31
|
input: ExtractionInput;
|
|
33
|
-
function:
|
|
34
|
-
executor: FunctionExecutor;
|
|
32
|
+
function: Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
35
33
|
|
|
36
34
|
options?: {
|
|
37
35
|
/**
|
|
@@ -48,18 +46,46 @@ export type ProcessTranscriptMessageParams = {
|
|
|
48
46
|
};
|
|
49
47
|
};
|
|
50
48
|
|
|
51
|
-
export type ExtractionFunction =
|
|
49
|
+
export type ExtractionFunction = Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Placeholder for Anthropic-based entity extraction.
|
|
53
|
+
* Implementation is currently disabled pending restoration of extraction logic.
|
|
54
|
+
*/
|
|
55
|
+
export const extractionAnthropicFunction = Operation.make({
|
|
56
|
+
meta: {
|
|
57
|
+
key: 'org.dxos.function.extraction.anthropic',
|
|
58
|
+
name: 'Entity Extraction (Anthropic)',
|
|
59
|
+
description: 'Extract entities from transcript using Anthropic LLM.',
|
|
60
|
+
},
|
|
61
|
+
input: ExtractionInput,
|
|
62
|
+
output: ExtractionOutput,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Placeholder for NER-based entity extraction.
|
|
67
|
+
* Implementation is currently disabled pending restoration of extraction logic.
|
|
68
|
+
*/
|
|
69
|
+
export const extractionNerFunction = Operation.make({
|
|
70
|
+
meta: {
|
|
71
|
+
key: 'org.dxos.function.extraction.ner',
|
|
72
|
+
name: 'Entity Extraction (NER)',
|
|
73
|
+
description: 'Extract entities from transcript using Named Entity Recognition.',
|
|
74
|
+
},
|
|
75
|
+
input: ExtractionInput,
|
|
76
|
+
output: ExtractionOutput,
|
|
77
|
+
});
|
|
52
78
|
|
|
53
79
|
/**
|
|
54
80
|
* Extract entities from the transcript message and add them to the message.
|
|
55
81
|
*/
|
|
56
82
|
// TODO(dmaretskyi): Move context to a vector search index.
|
|
57
|
-
export const processTranscriptMessage = async (params:
|
|
83
|
+
export const processTranscriptMessage = async (params: ProcessTranscriptMessageProps): Promise<ExtractionOutput> => {
|
|
58
84
|
try {
|
|
59
85
|
if (params.options?.timeout && params.options.timeout > 0) {
|
|
60
|
-
return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
|
|
86
|
+
// return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
|
|
61
87
|
} else {
|
|
62
|
-
return await params.executor.invoke(params.function, params.input);
|
|
88
|
+
// return await params.executor.invoke(params.function, params.input);
|
|
63
89
|
}
|
|
64
90
|
} catch (error) {
|
|
65
91
|
if (params.options?.fallbackToRaw) {
|
|
@@ -72,4 +98,7 @@ export const processTranscriptMessage = async (params: ProcessTranscriptMessageP
|
|
|
72
98
|
throw error;
|
|
73
99
|
}
|
|
74
100
|
}
|
|
101
|
+
|
|
102
|
+
// TODO(dmaretskyi): Restore extraction logic.
|
|
103
|
+
return { message: params.input.message, timeElapsed: 0 };
|
|
75
104
|
};
|
package/src/extraction/index.ts
CHANGED
package/src/extraction/quotes.ts
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Filter, Query } from '@dxos/echo';
|
|
8
|
-
import { ObjectId } from '@dxos/
|
|
9
|
-
import { type EchoDatabase } from '@dxos/echo-db';
|
|
7
|
+
import { type Database, Filter, Query } from '@dxos/echo';
|
|
8
|
+
import { ObjectId } from '@dxos/keys';
|
|
10
9
|
import { DXN } from '@dxos/keys';
|
|
11
10
|
import { log } from '@dxos/log';
|
|
12
11
|
|
|
@@ -28,10 +27,10 @@ export const ReferencedQuotes = Schema.Struct({
|
|
|
28
27
|
});
|
|
29
28
|
export type ReferencedQuotes = Schema.Schema.Type<typeof ReferencedQuotes>;
|
|
30
29
|
|
|
31
|
-
export const findQuotes = async (quotes: string[], db:
|
|
30
|
+
export const findQuotes = async (quotes: string[], db: Database.Database): Promise<ReferencedQuotes> => {
|
|
32
31
|
const references = await Promise.all(
|
|
33
32
|
quotes.map(async (quote) => {
|
|
34
|
-
const
|
|
33
|
+
const objects = await db.query(Query.select(Filter.text(quote, { type: 'vector' }))).run();
|
|
35
34
|
log.info('found quotes in vector index', { objects, quote });
|
|
36
35
|
return objects.length > 0 ? [{ id: objects[0].id.toString(), quote }] : [];
|
|
37
36
|
}),
|
|
@@ -7,71 +7,67 @@ import type * as Toolkit from '@effect/ai/Toolkit';
|
|
|
7
7
|
import * as Context from 'effect/Context';
|
|
8
8
|
import * as Effect from 'effect/Effect';
|
|
9
9
|
import * as Layer from 'effect/Layer';
|
|
10
|
+
import * as Option from 'effect/Option';
|
|
10
11
|
import * as Record from 'effect/Record';
|
|
11
12
|
import * as Schema from 'effect/Schema';
|
|
13
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
12
14
|
|
|
13
15
|
import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
16
|
+
import { OpaqueToolkit } from '@dxos/ai';
|
|
17
|
+
import { Operation, OperationRegistry } from '@dxos/compute';
|
|
14
18
|
import { todo } from '@dxos/debug';
|
|
15
|
-
import {
|
|
16
|
-
import { DatabaseService, Function, FunctionDefinition, FunctionInvocationService } from '@dxos/functions';
|
|
19
|
+
import { Ref } from '@dxos/echo';
|
|
17
20
|
import { invariant } from '@dxos/invariant';
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
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,33 +94,56 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
100
94
|
};
|
|
101
95
|
}),
|
|
102
96
|
);
|
|
97
|
+
|
|
98
|
+
export const makeToolExecutionServiceFromOperationInvoker = (): Layer.Layer<
|
|
99
|
+
ToolExecutionService,
|
|
100
|
+
never,
|
|
101
|
+
Operation.Service | OpaqueToolkit.OpaqueToolkitProvider
|
|
102
|
+
> => {
|
|
103
|
+
return Layer.unwrapEffect(
|
|
104
|
+
Effect.gen(function* () {
|
|
105
|
+
const operationInvoker = yield* Operation.Service;
|
|
106
|
+
|
|
107
|
+
return makeToolExecutionService({
|
|
108
|
+
invoke: (tool, input) =>
|
|
109
|
+
Effect.gen(function* () {
|
|
110
|
+
const operationDef = getOperationFromTool(tool).pipe(Option.getOrThrow);
|
|
111
|
+
|
|
112
|
+
return yield* operationInvoker.invoke(operationDef, input).pipe(Effect.orDie);
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
103
117
|
};
|
|
104
118
|
|
|
119
|
+
export const ToolExecutionServices = Layer.mergeAll(
|
|
120
|
+
makeToolResolverFromOperations(),
|
|
121
|
+
makeToolExecutionServiceFromOperationInvoker(),
|
|
122
|
+
);
|
|
123
|
+
|
|
105
124
|
class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
|
|
106
125
|
FunctionToolAnnotation,
|
|
107
|
-
{ definition:
|
|
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
|
-
* Projects
|
|
114
|
-
*
|
|
115
|
-
* @param fn The function definition to project into a tool.
|
|
116
|
-
* @param meta Optional projection metadata.
|
|
117
|
-
* @param meta.deployedFunctionId Backend deployment ID used for remote invocation when present. This is the
|
|
118
|
-
* EDGE service's function deployment identifier (not the ECHO object ID/DXN and not `FunctionDefinition.key`).
|
|
136
|
+
* Projects an `Operation.Definition` into an `AiTool`.
|
|
119
137
|
*/
|
|
120
|
-
const projectFunctionToTool = (fn:
|
|
138
|
+
const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
|
|
121
139
|
if (toolCache.has(fn)) {
|
|
122
140
|
return toolCache.get(fn)!;
|
|
123
141
|
}
|
|
124
142
|
|
|
125
|
-
const tool = Tool.make(makeToolName(fn.name), {
|
|
126
|
-
description: fn.description,
|
|
127
|
-
parameters: createStructFieldsFromSchema(fn.
|
|
128
|
-
|
|
129
|
-
failure: Schema.Any, // TODO(dmaretskyi): Better type for the failure?
|
|
143
|
+
const tool = Tool.make(makeToolName(fn.meta.name ?? fn.meta.key), {
|
|
144
|
+
description: fn.meta.description,
|
|
145
|
+
parameters: createStructFieldsFromSchema(fn.input),
|
|
146
|
+
failure: Schema.Any,
|
|
130
147
|
}).annotate(FunctionToolAnnotation, { definition: fn });
|
|
131
148
|
toolCache.set(fn, tool);
|
|
132
149
|
return tool;
|
|
@@ -136,8 +153,8 @@ const projectFunctionToTool = (fn: FunctionDefinition<any, any>): Tool.Any => {
|
|
|
136
153
|
* @returns Tool name produced from function name by escaping invalid characters.
|
|
137
154
|
*/
|
|
138
155
|
const makeToolName = (name: string) => {
|
|
139
|
-
const toolName = name.replace(/[^a-zA-Z0-9]/g, '
|
|
140
|
-
invariant(toolName.match(/^[a-
|
|
156
|
+
const toolName = name.toLowerCase().replace(/[^a-zA-Z0-9]/g, '-');
|
|
157
|
+
invariant(toolName.match(/^[a-z_][a-z0-9-_]*$/));
|
|
141
158
|
return toolName;
|
|
142
159
|
};
|
|
143
160
|
|
|
@@ -145,7 +162,9 @@ const makeToolName = (name: string) => {
|
|
|
145
162
|
const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<string, Schema.Schema<any, any>> => {
|
|
146
163
|
switch (schema.ast._tag) {
|
|
147
164
|
case 'TypeLiteral':
|
|
148
|
-
return Object.fromEntries(
|
|
165
|
+
return Object.fromEntries(
|
|
166
|
+
schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(mapSchemaTypeForLLM(prop.type))]),
|
|
167
|
+
);
|
|
149
168
|
case 'VoidKeyword':
|
|
150
169
|
return {};
|
|
151
170
|
default:
|
|
@@ -153,6 +172,43 @@ const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<s
|
|
|
153
172
|
}
|
|
154
173
|
};
|
|
155
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Picks an LLM-friendly schema type for the given schema AST.
|
|
177
|
+
* The picked schema type decodes to the original schema type.
|
|
178
|
+
*/
|
|
179
|
+
const mapSchemaTypeForLLM = (ast: SchemaAST.AST): SchemaAST.AST => {
|
|
180
|
+
if (Ref.isRefType(ast)) {
|
|
181
|
+
const description = ast.annotations.description
|
|
182
|
+
? ast.annotations.description + '\n' + RefFromLLM.ast.annotations.description
|
|
183
|
+
: (RefFromLLM.ast.annotations.description as string);
|
|
184
|
+
return RefFromLLM.annotations({ description }).ast;
|
|
185
|
+
} else if (SchemaAST.isTupleType(ast)) {
|
|
186
|
+
return new SchemaAST.TupleType(
|
|
187
|
+
ast.elements.map((t) => new SchemaAST.OptionalType(mapSchemaTypeForLLM(t.type), t.isOptional, t.annotations)),
|
|
188
|
+
ast.rest.map((t) => new SchemaAST.Type(mapSchemaTypeForLLM(t.type), t.annotations)),
|
|
189
|
+
ast.isReadonly,
|
|
190
|
+
ast.annotations,
|
|
191
|
+
);
|
|
192
|
+
} else if (SchemaAST.isTypeLiteral(ast)) {
|
|
193
|
+
return new SchemaAST.TypeLiteral(
|
|
194
|
+
ast.propertySignatures.map(
|
|
195
|
+
(p) =>
|
|
196
|
+
new SchemaAST.PropertySignature(
|
|
197
|
+
p.name,
|
|
198
|
+
mapSchemaTypeForLLM(p.type),
|
|
199
|
+
p.isOptional,
|
|
200
|
+
p.isReadonly,
|
|
201
|
+
p.annotations,
|
|
202
|
+
),
|
|
203
|
+
),
|
|
204
|
+
ast.indexSignatures,
|
|
205
|
+
ast.annotations,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return ast;
|
|
210
|
+
};
|
|
211
|
+
|
|
156
212
|
const isHandlerLike = (value: unknown): value is Toolkit.WithHandler<Record<string, Tool.Any>> => {
|
|
157
213
|
return typeof (value as any).tools === 'object' && typeof (value as any).handle === 'function';
|
|
158
214
|
};
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
export * from './conversation';
|
|
6
|
-
export * from './diff';
|
|
7
|
-
export * from './errors';
|
|
8
|
-
export * from './execution-graph';
|
|
9
5
|
export * from './functions';
|
|
6
|
+
export * from './request';
|
|
10
7
|
export * from './session';
|
|
11
8
|
export * from './templates';
|
|
12
|
-
export * from './
|
|
9
|
+
export * from './util';
|