@dxos/assistant 0.8.4-main.c85a9c8dae → 0.8.4-main.d05539e30a
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 +1 -1
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/extraction/index.mjs +31 -50
- package/dist/lib/neutral/extraction/index.mjs.map +4 -4
- package/dist/lib/neutral/index.mjs +1531 -1080
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- 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 +879 -153
- 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.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 +106 -0
- package/dist/types/src/request/AiRequest.d.ts.map +1 -0
- 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.map +1 -1
- package/dist/types/src/{session → request}/version-pin.d.ts.map +1 -1
- package/dist/types/src/{conversation/context.d.ts → session/AiContext.d.ts} +41 -33
- 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 -5
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +5 -7
- 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/{types → util}/artifact.d.ts +1 -2
- package/dist/types/src/util/artifact.d.ts.map +1 -0
- 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} +12 -12
- package/dist/types/src/util/errors.d.ts.map +1 -0
- 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 +237 -0
- package/dist/types/src/util/tracing.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -41
- package/src/extraction/extraction-ner-function/index.ts +0 -1
- package/src/extraction/extraction.ts +36 -8
- package/src/extraction/index.ts +0 -1
- package/src/functions/services.ts +58 -53
- package/src/index.ts +2 -5
- package/src/request/AiRequest.ts +386 -0
- package/src/{session → request}/format.ts +15 -11
- package/src/request/index.ts +8 -0
- package/src/session/AiContext.test.ts +53 -0
- package/src/{conversation/context.ts → session/AiContext.ts} +145 -72
- package/src/session/AiSession.ts +324 -0
- package/src/session/index.ts +3 -5
- package/src/session/toolkit.ts +18 -15
- package/src/templates/instructions/system.tpl +50 -2
- package/src/templates/system.ts +7 -6
- package/src/{types → util}/artifact.ts +2 -3
- package/src/{diff.test.ts → util/diff.test.ts} +3 -3
- package/src/{session → util}/error-handling.ts +3 -2
- package/src/{execution-graph.test.ts → util/execution-graph.test.ts} +1 -1
- package/src/{execution-graph.ts → util/execution-graph.ts} +16 -6
- package/src/util/index.ts +10 -0
- package/src/util/tracing.ts +57 -0
- package/dist/lib/neutral/chunk-BE6SRJ4N.mjs +0 -193
- package/dist/lib/neutral/chunk-BE6SRJ4N.mjs.map +0 -7
- package/dist/lib/neutral/testing/index.mjs +0 -38
- package/dist/lib/neutral/testing/index.mjs.map +0 -7
- package/dist/types/src/conversation/context.d.ts.map +0 -1
- package/dist/types/src/conversation/context.test.d.ts +0 -2
- package/dist/types/src/conversation/context.test.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.d.ts +0 -66
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/conversation/conversation.test.d.ts +0 -2
- package/dist/types/src/conversation/conversation.test.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 -355
- 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/functions.test.d.ts +0 -2
- package/dist/types/src/functions.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 -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/session.d.ts +0 -61
- 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/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -22
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- 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.test.ts +0 -46
- package/src/conversation/conversation.test.ts +0 -65
- package/src/conversation/conversation.ts +0 -247
- package/src/conversation/index.ts +0 -6
- 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/functions.conversations.json +0 -1
- package/src/functions.test.ts +0 -74
- package/src/session/format.test.ts +0 -124
- package/src/session/session.conversations.json +0 -1
- package/src/session/session.test.ts +0 -191
- package/src/session/session.ts +0 -251
- package/src/testing/index.ts +0 -5
- package/src/testing/layer.ts +0 -85
- package/src/types/index.ts +0 -5
- /package/dist/types/src/{session → request}/artifact-diff.d.ts +0 -0
- /package/dist/types/src/{session → request}/observer.d.ts +0 -0
- /package/dist/types/src/{session → request}/version-pin.d.ts +0 -0
- /package/dist/types/src/{diff.d.ts → util/diff.d.ts} +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.d.ts → util/execution-graph.d.ts} +0 -0
- /package/dist/types/src/{execution-graph.test.d.ts → util/execution-graph.test.d.ts} +0 -0
- /package/src/{session → request}/artifact-diff.ts +0 -0
- /package/src/{session → request}/observer.ts +0 -0
- /package/src/{session → request}/version-pin.ts +0 -0
- /package/src/{diff.ts → util/diff.ts} +0 -0
- /package/src/{errors.ts → util/errors.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/assistant",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.d05539e30a",
|
|
4
4
|
"description": "Natural language interface to DXOS",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "info@dxos.org",
|
|
13
13
|
"sideEffects": true,
|
|
14
14
|
"type": "module",
|
|
@@ -22,30 +22,15 @@
|
|
|
22
22
|
"source": "./src/extraction/index.ts",
|
|
23
23
|
"types": "./dist/types/src/extraction/index.d.ts",
|
|
24
24
|
"default": "./dist/lib/neutral/extraction/index.mjs"
|
|
25
|
-
},
|
|
26
|
-
"./testing": {
|
|
27
|
-
"source": "./src/testing/index.ts",
|
|
28
|
-
"types": "./dist/types/src/testing/index.d.ts",
|
|
29
|
-
"default": "./dist/lib/neutral/testing/index.mjs"
|
|
30
25
|
}
|
|
31
26
|
},
|
|
32
27
|
"types": "dist/types/src/index.d.ts",
|
|
33
|
-
"typesVersions": {
|
|
34
|
-
"*": {
|
|
35
|
-
"types": [
|
|
36
|
-
"dist/types/src/types/index.d.ts"
|
|
37
|
-
],
|
|
38
|
-
"extraction": [
|
|
39
|
-
"dist/types/src/extraction/index.d.ts"
|
|
40
|
-
]
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
28
|
"files": [
|
|
44
29
|
"dist",
|
|
45
30
|
"src"
|
|
46
31
|
],
|
|
47
32
|
"dependencies": {
|
|
48
|
-
"@automerge/automerge": "3.2.
|
|
33
|
+
"@automerge/automerge": "3.2.6",
|
|
49
34
|
"@effect-atom/atom": "^0.5.1",
|
|
50
35
|
"@effect-atom/atom-react": "^0.5.0",
|
|
51
36
|
"@effect/ai": "0.33.2",
|
|
@@ -53,34 +38,33 @@
|
|
|
53
38
|
"@effect/platform": "0.94.4",
|
|
54
39
|
"@xenova/transformers": "^2.17.2",
|
|
55
40
|
"lodash.defaultsdeep": "^4.6.1",
|
|
56
|
-
"@dxos/ai": "0.8.4-main.
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/echo-
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/log": "0.8.4-main.
|
|
71
|
-
"@dxos/mcp-client": "0.8.4-main.
|
|
72
|
-
"@dxos/schema": "0.8.4-main.
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/util": "0.8.4-main.c85a9c8dae"
|
|
41
|
+
"@dxos/ai": "0.8.4-main.d05539e30a",
|
|
42
|
+
"@dxos/async": "0.8.4-main.d05539e30a",
|
|
43
|
+
"@dxos/compute": "0.8.4-main.d05539e30a",
|
|
44
|
+
"@dxos/context": "0.8.4-main.d05539e30a",
|
|
45
|
+
"@dxos/debug": "0.8.4-main.d05539e30a",
|
|
46
|
+
"@dxos/echo": "0.8.4-main.d05539e30a",
|
|
47
|
+
"@dxos/echo-db": "0.8.4-main.d05539e30a",
|
|
48
|
+
"@dxos/echo-protocol": "0.8.4-main.d05539e30a",
|
|
49
|
+
"@dxos/effect": "0.8.4-main.d05539e30a",
|
|
50
|
+
"@dxos/errors": "0.8.4-main.d05539e30a",
|
|
51
|
+
"@dxos/functions": "0.8.4-main.d05539e30a",
|
|
52
|
+
"@dxos/graph": "0.8.4-main.d05539e30a",
|
|
53
|
+
"@dxos/keys": "0.8.4-main.d05539e30a",
|
|
54
|
+
"@dxos/invariant": "0.8.4-main.d05539e30a",
|
|
55
|
+
"@dxos/log": "0.8.4-main.d05539e30a",
|
|
56
|
+
"@dxos/mcp-client": "0.8.4-main.d05539e30a",
|
|
57
|
+
"@dxos/schema": "0.8.4-main.d05539e30a",
|
|
58
|
+
"@dxos/util": "0.8.4-main.d05539e30a",
|
|
59
|
+
"@dxos/types": "0.8.4-main.d05539e30a",
|
|
60
|
+
"@dxos/node-std": "0.8.4-main.d05539e30a"
|
|
77
61
|
},
|
|
78
62
|
"devDependencies": {
|
|
79
63
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
80
|
-
"effect": "3.
|
|
64
|
+
"effect": "3.20.0"
|
|
81
65
|
},
|
|
82
66
|
"peerDependencies": {
|
|
83
|
-
"effect": "3.
|
|
67
|
+
"effect": "3.20.0"
|
|
84
68
|
},
|
|
85
69
|
"publishConfig": {
|
|
86
70
|
"access": "public"
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { type FunctionDefinition } from '@dxos/functions';
|
|
10
|
-
import { type FunctionExecutor } from '@dxos/functions-runtime';
|
|
11
9
|
import { log } from '@dxos/log';
|
|
12
10
|
import { Message } from '@dxos/types';
|
|
13
11
|
|
|
@@ -31,8 +29,7 @@ export interface ExtractionOutput extends Schema.Schema.Type<typeof ExtractionOu
|
|
|
31
29
|
|
|
32
30
|
export type ProcessTranscriptMessageProps = {
|
|
33
31
|
input: ExtractionInput;
|
|
34
|
-
function:
|
|
35
|
-
executor: FunctionExecutor;
|
|
32
|
+
function: Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
36
33
|
|
|
37
34
|
options?: {
|
|
38
35
|
/**
|
|
@@ -49,7 +46,35 @@ export type ProcessTranscriptMessageProps = {
|
|
|
49
46
|
};
|
|
50
47
|
};
|
|
51
48
|
|
|
52
|
-
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
|
+
});
|
|
53
78
|
|
|
54
79
|
/**
|
|
55
80
|
* Extract entities from the transcript message and add them to the message.
|
|
@@ -58,9 +83,9 @@ export type ExtractionFunction = FunctionDefinition<ExtractionInput, ExtractionO
|
|
|
58
83
|
export const processTranscriptMessage = async (params: ProcessTranscriptMessageProps): Promise<ExtractionOutput> => {
|
|
59
84
|
try {
|
|
60
85
|
if (params.options?.timeout && params.options.timeout > 0) {
|
|
61
|
-
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);
|
|
62
87
|
} else {
|
|
63
|
-
return await params.executor.invoke(params.function, params.input);
|
|
88
|
+
// return await params.executor.invoke(params.function, params.input);
|
|
64
89
|
}
|
|
65
90
|
} catch (error) {
|
|
66
91
|
if (params.options?.fallbackToRaw) {
|
|
@@ -73,4 +98,7 @@ export const processTranscriptMessage = async (params: ProcessTranscriptMessageP
|
|
|
73
98
|
throw error;
|
|
74
99
|
}
|
|
75
100
|
}
|
|
101
|
+
|
|
102
|
+
// TODO(dmaretskyi): Restore extraction logic.
|
|
103
|
+
return { message: params.input.message, timeElapsed: 0 };
|
|
76
104
|
};
|
package/src/extraction/index.ts
CHANGED
|
@@ -7,53 +7,49 @@ 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';
|
|
12
13
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
13
14
|
|
|
14
15
|
import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
15
|
-
import {
|
|
16
|
+
import { OpaqueToolkit } from '@dxos/ai';
|
|
17
|
+
import { Operation, OperationRegistry } from '@dxos/compute';
|
|
16
18
|
import { todo } from '@dxos/debug';
|
|
17
19
|
import { Ref } from '@dxos/echo';
|
|
18
|
-
import { type FunctionDefinition, FunctionInvocationService } from '@dxos/functions';
|
|
19
20
|
import { invariant } from '@dxos/invariant';
|
|
20
21
|
|
|
21
|
-
import { RefFromLLM } from '../
|
|
22
|
+
import { RefFromLLM } from '../util';
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* 2. Functions in DB: query `FunctionType` by `key=id`; if found, deserialize and project to a tool
|
|
27
|
-
* (propagating any `deployedFunctionId` discovered in the object's metadata).
|
|
28
|
-
* 3. Functions passed in: fall back to a matching `FunctionDefinition` from the `functions` array.
|
|
29
|
-
*
|
|
30
|
-
* If none of the above yield a match, the effect fails with `AiToolNotFoundError`.
|
|
31
|
-
*
|
|
32
|
-
* Requires `Database.Service` in the environment.
|
|
33
|
-
*/
|
|
34
|
-
export const makeToolResolverFromFunctions = (): Layer.Layer<
|
|
24
|
+
export const makeToolResolverFromOperations = <R = never>({
|
|
25
|
+
toolkit: extraToolkit = OpaqueToolkit.empty,
|
|
26
|
+
}: { toolkit?: OpaqueToolkit.OpaqueToolkit<never, never, R> } = {}): Layer.Layer<
|
|
35
27
|
ToolResolverService,
|
|
36
28
|
never,
|
|
37
|
-
|
|
29
|
+
OpaqueToolkit.OpaqueToolkitProvider | OperationRegistry.Service | R
|
|
38
30
|
> => {
|
|
39
31
|
return Layer.effect(
|
|
40
32
|
ToolResolverService,
|
|
41
33
|
Effect.gen(function* () {
|
|
42
|
-
const toolkitProvider = yield*
|
|
43
|
-
const
|
|
34
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
35
|
+
const operationRegistry = yield* OperationRegistry.Service;
|
|
44
36
|
return {
|
|
45
37
|
resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
|
|
46
38
|
Effect.gen(function* () {
|
|
47
|
-
const toolkit = toolkitProvider.getToolkit();
|
|
39
|
+
const toolkit = OpaqueToolkit.merge(extraToolkit, toolkitProvider.getToolkit());
|
|
48
40
|
|
|
49
41
|
const tool = toolkit.toolkit.tools[id];
|
|
50
42
|
if (tool) {
|
|
51
43
|
return tool;
|
|
52
44
|
}
|
|
53
45
|
|
|
54
|
-
return yield*
|
|
55
|
-
Effect.
|
|
56
|
-
|
|
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
|
+
),
|
|
57
53
|
);
|
|
58
54
|
}),
|
|
59
55
|
} satisfies Context.Tag.Service<ToolResolverService>;
|
|
@@ -61,20 +57,17 @@ export const makeToolResolverFromFunctions = (): Layer.Layer<
|
|
|
61
57
|
);
|
|
62
58
|
};
|
|
63
59
|
|
|
64
|
-
export const
|
|
65
|
-
|
|
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 toolkitProvider = yield*
|
|
66
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
73
67
|
const toolkit = toolkitProvider.getToolkit();
|
|
74
68
|
|
|
75
69
|
const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
|
|
76
70
|
invariant(isHandlerLike(toolkitHandler));
|
|
77
|
-
const functionInvocationService = yield* FunctionInvocationService;
|
|
78
71
|
|
|
79
72
|
return {
|
|
80
73
|
handlersFor: (toolkit) => {
|
|
@@ -90,11 +83,7 @@ export const makeToolExecutionServiceFromFunctions = (): Layer.Layer<
|
|
|
90
83
|
return result;
|
|
91
84
|
}
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return yield* functionInvocationService
|
|
96
|
-
.invokeFunction(functionDef, input as any)
|
|
97
|
-
.pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
86
|
+
return yield* opts.invoke(tool, input).pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
98
87
|
});
|
|
99
88
|
};
|
|
100
89
|
|
|
@@ -105,40 +94,56 @@ export const makeToolExecutionServiceFromFunctions = (): Layer.Layer<
|
|
|
105
94
|
};
|
|
106
95
|
}),
|
|
107
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
|
+
);
|
|
108
117
|
};
|
|
109
118
|
|
|
110
119
|
export const ToolExecutionServices = Layer.mergeAll(
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
makeToolResolverFromOperations(),
|
|
121
|
+
makeToolExecutionServiceFromOperationInvoker(),
|
|
113
122
|
);
|
|
114
123
|
|
|
115
124
|
class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
|
|
116
125
|
FunctionToolAnnotation,
|
|
117
|
-
{ definition:
|
|
126
|
+
{ definition: Operation.Definition.Any }
|
|
118
127
|
>() {}
|
|
119
128
|
|
|
120
|
-
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>();
|
|
121
134
|
|
|
122
135
|
/**
|
|
123
|
-
* Projects
|
|
124
|
-
*
|
|
125
|
-
* @param fn The function definition to project into a tool.
|
|
126
|
-
* @param meta Optional projection metadata.
|
|
127
|
-
* @param meta.deployedFunctionId Backend deployment ID used for remote invocation when present.
|
|
128
|
-
* This is the EDGE service's function deployment identifier (not the ECHO object ID/DXN and not `FunctionDefinition.key`).
|
|
136
|
+
* Projects an `Operation.Definition` into an `AiTool`.
|
|
129
137
|
*/
|
|
130
|
-
const projectFunctionToTool = (fn:
|
|
138
|
+
const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
|
|
131
139
|
if (toolCache.has(fn)) {
|
|
132
140
|
return toolCache.get(fn)!;
|
|
133
141
|
}
|
|
134
142
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
parameters: createStructFieldsFromSchema(fn.inputSchema),
|
|
140
|
-
// TODO(dmaretskyi): Include output schema.
|
|
141
|
-
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,
|
|
142
147
|
}).annotate(FunctionToolAnnotation, { definition: fn });
|
|
143
148
|
toolCache.set(fn, tool);
|
|
144
149
|
return tool;
|
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';
|