@dxos/assistant 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/README.md +2 -1
- package/dist/lib/{browser → neutral}/extraction/index.mjs +42 -59
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1886 -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 -317
- 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 +14 -16
- 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 +4 -4
- 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 +4 -3
- 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 +79 -0
- package/dist/types/src/session/AiSession.d.ts.map +1 -0
- package/dist/types/src/session/AiSession.test.d.ts +2 -0
- package/dist/types/src/session/AiSession.test.d.ts.map +1 -0
- package/dist/types/src/session/SessionLink.d.ts +17 -0
- package/dist/types/src/session/SessionLink.d.ts.map +1 -0
- package/dist/types/src/session/SessionLoader.d.ts +15 -0
- package/dist/types/src/session/SessionLoader.d.ts.map +1 -0
- package/dist/types/src/session/SessionLoader.test.d.ts +2 -0
- package/dist/types/src/session/SessionLoader.test.d.ts.map +1 -0
- package/dist/types/src/session/index.d.ts +4 -5
- 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} +4 -2
- 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} +24 -28
- package/dist/types/src/util/errors.d.ts.map +1 -0
- package/dist/types/src/{execution-graph.d.ts → util/execution-graph.d.ts} +2 -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 +296 -0
- package/dist/types/src/util/tracing.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -44
- package/src/extraction/extraction-ner-function/index.ts +0 -1
- package/src/extraction/extraction.ts +47 -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 +129 -63
- package/src/index.ts +2 -5
- package/src/request/AiRequest.ts +387 -0
- package/src/{session → request}/artifact-diff.ts +4 -4
- package/src/{session → request}/format.ts +28 -25
- package/src/request/index.ts +8 -0
- package/src/{session → request}/observer.ts +4 -1
- package/src/{session → request}/version-pin.ts +6 -5
- package/src/session/AiContext.test.ts +49 -0
- package/src/session/AiContext.ts +420 -0
- package/src/session/AiSession.test.ts +111 -0
- package/src/session/AiSession.ts +328 -0
- package/src/session/SessionLink.ts +23 -0
- package/src/session/SessionLoader.test.ts +115 -0
- package/src/session/SessionLoader.ts +55 -0
- package/src/session/index.ts +4 -5
- package/src/session/toolkit.ts +27 -28
- package/src/templates/instructions/format.tpl +0 -4
- package/src/templates/instructions/system.tpl +50 -2
- package/src/templates/system.ts +7 -6
- package/src/util/artifact.ts +96 -0
- package/src/util/diff.test.ts +74 -0
- package/src/{diff.ts → util/diff.ts} +14 -5
- 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} +4 -4
- package/src/{execution-graph.ts → util/execution-graph.ts} +30 -19
- package/src/util/index.ts +10 -0
- package/src/util/tracing.ts +60 -0
- package/dist/lib/browser/extraction/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -1290
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/extraction/index.mjs +0 -226
- package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -1291
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- 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/GenericToolkit.d.ts +0 -84
- package/dist/types/src/session/GenericToolkit.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 -12
- 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/types/artifact.d.ts +0 -20
- 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 -62
- package/src/extraction/extraction-llm-function/index.ts +0 -5
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -116
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -56
- package/src/session/GenericToolkit.ts +0 -130
- package/src/session/format.test.ts +0 -61
- 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/types/artifact.ts +0 -71
- package/src/types/index.ts +0 -5
- /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
- /package/dist/lib/{browser → 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/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/assistant",
|
|
3
|
-
"version": "0.8.4-
|
|
3
|
+
"version": "0.8.4-staging.60fe92afc8",
|
|
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,67 +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.36.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-
|
|
49
|
-
"@dxos/async": "0.8.4-
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/echo
|
|
54
|
-
"@dxos/echo-
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/errors": "0.8.4-
|
|
58
|
-
"@dxos/functions": "0.8.4-
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/schema": "0.8.4-
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/util": "0.8.4-main.fffef41"
|
|
41
|
+
"@dxos/ai": "0.8.4-staging.60fe92afc8",
|
|
42
|
+
"@dxos/async": "0.8.4-staging.60fe92afc8",
|
|
43
|
+
"@dxos/compute": "0.8.4-staging.60fe92afc8",
|
|
44
|
+
"@dxos/debug": "0.8.4-staging.60fe92afc8",
|
|
45
|
+
"@dxos/context": "0.8.4-staging.60fe92afc8",
|
|
46
|
+
"@dxos/echo": "0.8.4-staging.60fe92afc8",
|
|
47
|
+
"@dxos/echo-client": "0.8.4-staging.60fe92afc8",
|
|
48
|
+
"@dxos/effect": "0.8.4-staging.60fe92afc8",
|
|
49
|
+
"@dxos/echo-protocol": "0.8.4-staging.60fe92afc8",
|
|
50
|
+
"@dxos/errors": "0.8.4-staging.60fe92afc8",
|
|
51
|
+
"@dxos/functions": "0.8.4-staging.60fe92afc8",
|
|
52
|
+
"@dxos/graph": "0.8.4-staging.60fe92afc8",
|
|
53
|
+
"@dxos/log": "0.8.4-staging.60fe92afc8",
|
|
54
|
+
"@dxos/keys": "0.8.4-staging.60fe92afc8",
|
|
55
|
+
"@dxos/mcp-client": "0.8.4-staging.60fe92afc8",
|
|
56
|
+
"@dxos/node-std": "0.8.4-staging.60fe92afc8",
|
|
57
|
+
"@dxos/types": "0.8.4-staging.60fe92afc8",
|
|
58
|
+
"@dxos/schema": "0.8.4-staging.60fe92afc8",
|
|
59
|
+
"@dxos/util": "0.8.4-staging.60fe92afc8",
|
|
60
|
+
"@dxos/invariant": "0.8.4-staging.60fe92afc8"
|
|
69
61
|
},
|
|
70
62
|
"devDependencies": {
|
|
71
63
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
72
|
-
"effect": "3.
|
|
64
|
+
"effect": "3.21.3"
|
|
73
65
|
},
|
|
74
66
|
"peerDependencies": {
|
|
75
|
-
"effect": "
|
|
67
|
+
"effect": "3.21.3"
|
|
76
68
|
},
|
|
77
69
|
"publishConfig": {
|
|
78
70
|
"access": "public"
|
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { type FunctionExecutor } from '@dxos/functions-runtime';
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
import { Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { DXN } from '@dxos/keys';
|
|
11
10
|
import { log } from '@dxos/log';
|
|
12
11
|
import { Message } from '@dxos/types';
|
|
13
12
|
|
|
14
13
|
export const ExtractionInput = Schema.Struct({
|
|
15
|
-
message: Message.Message,
|
|
16
|
-
objects: Schema.optional(Schema.Array(
|
|
14
|
+
message: Type.getSchema(Message.Message),
|
|
15
|
+
objects: Schema.optional(Schema.Array(Obj.Unknown)),
|
|
17
16
|
options: Schema.optional(
|
|
18
17
|
Schema.Struct({
|
|
19
18
|
timeout: Schema.optional(Schema.Number),
|
|
@@ -21,18 +20,15 @@ export const ExtractionInput = Schema.Struct({
|
|
|
21
20
|
}),
|
|
22
21
|
),
|
|
23
22
|
});
|
|
24
|
-
export
|
|
25
|
-
|
|
23
|
+
export type ExtractionInput = Schema.Schema.Type<typeof ExtractionInput>;
|
|
26
24
|
export const ExtractionOutput = Schema.Struct({
|
|
27
|
-
message: Message.Message,
|
|
25
|
+
message: Type.getSchema(Message.Message),
|
|
28
26
|
timeElapsed: Schema.Number,
|
|
29
27
|
});
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
export type ProcessTranscriptMessageParams = {
|
|
28
|
+
export type ExtractionOutput = Schema.Schema.Type<typeof ExtractionOutput>;
|
|
29
|
+
export type ProcessTranscriptMessageProps = {
|
|
33
30
|
input: ExtractionInput;
|
|
34
|
-
function:
|
|
35
|
-
executor: FunctionExecutor;
|
|
31
|
+
function: Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
36
32
|
|
|
37
33
|
options?: {
|
|
38
34
|
/**
|
|
@@ -49,18 +45,48 @@ export type ProcessTranscriptMessageParams = {
|
|
|
49
45
|
};
|
|
50
46
|
};
|
|
51
47
|
|
|
52
|
-
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
|
+
});
|
|
53
79
|
|
|
54
80
|
/**
|
|
55
81
|
* Extract entities from the transcript message and add them to the message.
|
|
56
82
|
*/
|
|
57
83
|
// TODO(dmaretskyi): Move context to a vector search index.
|
|
58
|
-
export const processTranscriptMessage = async (params:
|
|
84
|
+
export const processTranscriptMessage = async (params: ProcessTranscriptMessageProps): Promise<ExtractionOutput> => {
|
|
59
85
|
try {
|
|
60
86
|
if (params.options?.timeout && params.options.timeout > 0) {
|
|
61
|
-
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);
|
|
62
88
|
} else {
|
|
63
|
-
return await params.executor.invoke(params.function, params.input);
|
|
89
|
+
// return await params.executor.invoke(params.function, params.input);
|
|
64
90
|
}
|
|
65
91
|
} catch (error) {
|
|
66
92
|
if (params.options?.fallbackToRaw) {
|
|
@@ -73,4 +99,7 @@ export const processTranscriptMessage = async (params: ProcessTranscriptMessageP
|
|
|
73
99
|
throw error;
|
|
74
100
|
}
|
|
75
101
|
}
|
|
102
|
+
|
|
103
|
+
// TODO(dmaretskyi): Restore extraction logic.
|
|
104
|
+
return { message: params.input.message, timeElapsed: 0 };
|
|
76
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,72 +7,68 @@ 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 } from '@dxos/compute';
|
|
14
18
|
import { todo } from '@dxos/debug';
|
|
15
|
-
import {
|
|
16
|
-
import { DatabaseService } from '@dxos/echo-db';
|
|
17
|
-
import { Function, FunctionDefinition, FunctionInvocationService } from '@dxos/functions';
|
|
19
|
+
import { DXN, Filter, Ref, Registry } from '@dxos/echo';
|
|
18
20
|
import { invariant } from '@dxos/invariant';
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* Requires `DatabaseService` in the environment.
|
|
30
|
-
*/
|
|
31
|
-
export const makeToolResolverFromFunctions = (
|
|
32
|
-
functions: FunctionDefinition.Any[],
|
|
33
|
-
toolkit: Toolkit.Toolkit<any>,
|
|
34
|
-
): 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 | Registry.Service | R
|
|
30
|
+
> => {
|
|
35
31
|
return Layer.effect(
|
|
36
32
|
ToolResolverService,
|
|
37
33
|
Effect.gen(function* () {
|
|
38
|
-
const
|
|
34
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
35
|
+
const registry = yield* Registry.Service;
|
|
39
36
|
return {
|
|
40
37
|
resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
|
|
41
38
|
Effect.gen(function* () {
|
|
42
|
-
const
|
|
39
|
+
const toolkit = OpaqueToolkit.merge(extraToolkit, toolkitProvider.getToolkit());
|
|
40
|
+
|
|
41
|
+
const tool = toolkit.toolkit.tools[id];
|
|
43
42
|
if (tool) {
|
|
44
43
|
return tool;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!functionDef) {
|
|
56
|
-
return yield* Effect.fail(new AiToolNotFoundError(id));
|
|
46
|
+
// Normalize to a full DXN key (tool IDs are plain NSIDs, stored keys are full DXNs).
|
|
47
|
+
const key = DXN.isDXN(id) ? id : `dxn:${id}`;
|
|
48
|
+
const results = yield* Effect.promise(() =>
|
|
49
|
+
registry.query(Filter.and(Filter.type(Operation.PersistentOperation), Filter.key(key))).run(),
|
|
50
|
+
);
|
|
51
|
+
if (results.length > 0) {
|
|
52
|
+
return projectFunctionToTool(Operation.deserialize(results[0]));
|
|
57
53
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}).pipe(Effect.provideService(DatabaseService, dbService)),
|
|
54
|
+
return yield* Effect.fail(new AiToolNotFoundError(id));
|
|
55
|
+
}),
|
|
61
56
|
} satisfies Context.Tag.Service<ToolResolverService>;
|
|
62
57
|
}),
|
|
63
58
|
);
|
|
64
59
|
};
|
|
65
60
|
|
|
66
|
-
export const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return Layer.effect(
|
|
61
|
+
export const makeToolExecutionService = <E, R>(opts: {
|
|
62
|
+
invoke: (tool: Tool.Any, input: unknown) => Effect.Effect<unknown>;
|
|
63
|
+
}): Layer.Layer<ToolExecutionService, never, OpaqueToolkit.OpaqueToolkitProvider> =>
|
|
64
|
+
Layer.effect(
|
|
71
65
|
ToolExecutionService,
|
|
72
66
|
Effect.gen(function* () {
|
|
73
|
-
const
|
|
67
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
68
|
+
const toolkit = toolkitProvider.getToolkit();
|
|
69
|
+
|
|
70
|
+
const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
|
|
74
71
|
invariant(isHandlerLike(toolkitHandler));
|
|
75
|
-
const functionInvocationService = yield* FunctionInvocationService;
|
|
76
72
|
|
|
77
73
|
return {
|
|
78
74
|
handlersFor: (toolkit) => {
|
|
@@ -82,16 +78,13 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
82
78
|
if (Tool.isProviderDefined(tool)) {
|
|
83
79
|
throw new Error('Attempted to call a provider-defined tool');
|
|
84
80
|
}
|
|
81
|
+
|
|
85
82
|
// TODO(wittjosiah): Everything is `never` here.
|
|
86
83
|
const { result } = yield* (toolkitHandler.handle as any)(tool.name, input);
|
|
87
84
|
return result;
|
|
88
85
|
}
|
|
89
86
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return yield* functionInvocationService
|
|
93
|
-
.invokeFunction(functionDef, input as any)
|
|
94
|
-
.pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
87
|
+
return yield* opts.invoke(tool, input).pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
95
88
|
});
|
|
96
89
|
};
|
|
97
90
|
|
|
@@ -102,36 +95,70 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
102
95
|
};
|
|
103
96
|
}),
|
|
104
97
|
);
|
|
98
|
+
|
|
99
|
+
export const makeToolExecutionServiceFromOperationInvoker = (): Layer.Layer<
|
|
100
|
+
ToolExecutionService,
|
|
101
|
+
never,
|
|
102
|
+
Operation.Service | OpaqueToolkit.OpaqueToolkitProvider
|
|
103
|
+
> => {
|
|
104
|
+
return Layer.unwrapEffect(
|
|
105
|
+
Effect.gen(function* () {
|
|
106
|
+
const operationInvoker = yield* Operation.Service;
|
|
107
|
+
|
|
108
|
+
return makeToolExecutionService({
|
|
109
|
+
invoke: (tool, input) =>
|
|
110
|
+
Effect.gen(function* () {
|
|
111
|
+
const operationDef = getOperationFromTool(tool).pipe(Option.getOrThrow);
|
|
112
|
+
|
|
113
|
+
return yield* operationInvoker.invoke(operationDef, input).pipe(Effect.orDie);
|
|
114
|
+
}),
|
|
115
|
+
});
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
105
118
|
};
|
|
106
119
|
|
|
120
|
+
export const ToolExecutionServices = Layer.mergeAll(
|
|
121
|
+
makeToolResolverFromOperations(),
|
|
122
|
+
makeToolExecutionServiceFromOperationInvoker(),
|
|
123
|
+
);
|
|
124
|
+
|
|
107
125
|
class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
|
|
108
126
|
FunctionToolAnnotation,
|
|
109
|
-
{ definition:
|
|
127
|
+
{ definition: Operation.Definition.Any }
|
|
110
128
|
>() {}
|
|
111
129
|
|
|
112
|
-
const
|
|
130
|
+
export const getOperationFromTool = (tool: Tool.Any): Option.Option<Operation.Definition.Any> => {
|
|
131
|
+
return Context.getOption(FunctionToolAnnotation)(tool.annotations).pipe(Option.map(({ definition }) => definition));
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const toolCache = new WeakMap<Operation.Definition.Any, Tool.Any>();
|
|
113
135
|
|
|
114
136
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @param meta.deployedFunctionId Backend deployment ID used for remote invocation when present.
|
|
120
|
-
* This is the EDGE service's function deployment identifier (not the ECHO object ID/DXN and not `FunctionDefinition.key`).
|
|
137
|
+
* Empty parameters schema annotated with an explicit JSON schema so that
|
|
138
|
+
* @effect/ai versions that call JSONSchema.fromAST directly (≥0.35.0) still
|
|
139
|
+
* produce a valid `{type: "object"}` for the Anthropic API instead of the
|
|
140
|
+
* constEmptyStruct `{anyOf: [{type:"object"},{type:"array"}]}`.
|
|
121
141
|
*/
|
|
122
|
-
const
|
|
142
|
+
const EMPTY_PARAMETERS_SCHEMA = Schema.Struct({}).annotations({
|
|
143
|
+
[SchemaAST.JSONSchemaAnnotationId]: { type: 'object', properties: {}, required: [], additionalProperties: false },
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Projects an `Operation.Definition` into an `AiTool`.
|
|
148
|
+
*/
|
|
149
|
+
const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
|
|
123
150
|
if (toolCache.has(fn)) {
|
|
124
151
|
return toolCache.get(fn)!;
|
|
125
152
|
}
|
|
126
153
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const tool = Tool.make(makeToolName(fn.name), {
|
|
130
|
-
description: fn.description,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
154
|
+
const fields = createStructFieldsFromSchema(fn.input);
|
|
155
|
+
const parametersSchema = Object.keys(fields).length === 0 ? EMPTY_PARAMETERS_SCHEMA : Schema.Struct(fields);
|
|
156
|
+
const tool = Tool.make(makeToolName(fn.meta.name ?? fn.meta.key), {
|
|
157
|
+
description: fn.meta.description,
|
|
158
|
+
failure: Schema.Any,
|
|
159
|
+
})
|
|
160
|
+
.setParameters(parametersSchema)
|
|
161
|
+
.annotate(FunctionToolAnnotation, { definition: fn });
|
|
135
162
|
toolCache.set(fn, tool);
|
|
136
163
|
return tool;
|
|
137
164
|
};
|
|
@@ -149,7 +176,9 @@ const makeToolName = (name: string) => {
|
|
|
149
176
|
const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<string, Schema.Schema<any, any>> => {
|
|
150
177
|
switch (schema.ast._tag) {
|
|
151
178
|
case 'TypeLiteral':
|
|
152
|
-
return Object.fromEntries(
|
|
179
|
+
return Object.fromEntries(
|
|
180
|
+
schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(mapSchemaTypeForLLM(prop.type))]),
|
|
181
|
+
);
|
|
153
182
|
case 'VoidKeyword':
|
|
154
183
|
return {};
|
|
155
184
|
default:
|
|
@@ -157,6 +186,43 @@ const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<s
|
|
|
157
186
|
}
|
|
158
187
|
};
|
|
159
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Picks an LLM-friendly schema type for the given schema AST.
|
|
191
|
+
* The picked schema type decodes to the original schema type.
|
|
192
|
+
*/
|
|
193
|
+
const mapSchemaTypeForLLM = (ast: SchemaAST.AST): SchemaAST.AST => {
|
|
194
|
+
if (Ref.isRefType(ast)) {
|
|
195
|
+
const description = ast.annotations.description
|
|
196
|
+
? ast.annotations.description + '\n' + RefFromLLM.ast.annotations.description
|
|
197
|
+
: (RefFromLLM.ast.annotations.description as string);
|
|
198
|
+
return RefFromLLM.annotations({ description }).ast;
|
|
199
|
+
} else if (SchemaAST.isTupleType(ast)) {
|
|
200
|
+
return new SchemaAST.TupleType(
|
|
201
|
+
ast.elements.map((t) => new SchemaAST.OptionalType(mapSchemaTypeForLLM(t.type), t.isOptional, t.annotations)),
|
|
202
|
+
ast.rest.map((t) => new SchemaAST.Type(mapSchemaTypeForLLM(t.type), t.annotations)),
|
|
203
|
+
ast.isReadonly,
|
|
204
|
+
ast.annotations,
|
|
205
|
+
);
|
|
206
|
+
} else if (SchemaAST.isTypeLiteral(ast)) {
|
|
207
|
+
return new SchemaAST.TypeLiteral(
|
|
208
|
+
ast.propertySignatures.map(
|
|
209
|
+
(p) =>
|
|
210
|
+
new SchemaAST.PropertySignature(
|
|
211
|
+
p.name,
|
|
212
|
+
mapSchemaTypeForLLM(p.type),
|
|
213
|
+
p.isOptional,
|
|
214
|
+
p.isReadonly,
|
|
215
|
+
p.annotations,
|
|
216
|
+
),
|
|
217
|
+
),
|
|
218
|
+
ast.indexSignatures,
|
|
219
|
+
ast.annotations,
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return ast;
|
|
224
|
+
};
|
|
225
|
+
|
|
160
226
|
const isHandlerLike = (value: unknown): value is Toolkit.WithHandler<Record<string, Tool.Any>> => {
|
|
161
227
|
return typeof (value as any).tools === 'object' && typeof (value as any).handle === 'function';
|
|
162
228
|
};
|
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';
|