@dxos/assistant 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0
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/README.md +1 -0
- package/dist/lib/neutral/chunk-UAWIXKF6.mjs +1875 -0
- package/dist/lib/neutral/chunk-UAWIXKF6.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/extraction/index.mjs +29 -35
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +551 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +114 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/conversation/context.d.ts +116 -64
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/context.test.d.ts +2 -0
- package/dist/types/src/conversation/context.test.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +45 -18
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.test.d.ts +2 -0
- package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
- package/dist/types/src/diff.d.ts +3 -1
- package/dist/types/src/diff.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +12 -16
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts +2 -2
- package/dist/types/src/execution-graph.d.ts.map +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.d.ts +1059 -313
- 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 +28 -9
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/functions.test.d.ts +2 -0
- package/dist/types/src/functions.test.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/service/AgentService.d.ts +61 -0
- package/dist/types/src/service/AgentService.d.ts.map +1 -0
- package/dist/types/src/service/AgentService.test.d.ts +2 -0
- package/dist/types/src/service/AgentService.test.d.ts.map +1 -0
- package/dist/types/src/service/agent-process.d.ts +17 -0
- package/dist/types/src/service/agent-process.d.ts.map +1 -0
- package/dist/types/src/service/index.d.ts +3 -0
- package/dist/types/src/service/index.d.ts.map +1 -0
- package/dist/types/src/session/artifact-diff.d.ts +1 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +3 -3
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +1 -1
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +4 -3
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +72 -11
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +9 -6
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +2 -2
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/templates/system.d.ts +0 -1
- package/dist/types/src/templates/system.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/layer.d.ts +35 -0
- package/dist/types/src/testing/layer.d.ts.map +1 -0
- package/dist/types/src/tracing.d.ts +264 -0
- package/dist/types/src/tracing.d.ts.map +1 -0
- package/dist/types/src/types/artifact.d.ts +13 -5
- package/dist/types/src/types/artifact.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +42 -33
- package/src/conversation/context.test.ts +52 -0
- package/src/conversation/context.ts +307 -90
- package/src/conversation/conversation.test.ts +58 -0
- package/src/conversation/conversation.ts +209 -62
- package/src/diff.test.ts +36 -5
- package/src/diff.ts +13 -4
- package/src/errors.ts +2 -2
- package/src/execution-graph.test.ts +3 -3
- package/src/execution-graph.ts +6 -6
- package/src/extraction/extraction-ner-function/index.ts +0 -1
- package/src/extraction/extraction.ts +40 -12
- package/src/extraction/index.ts +0 -1
- package/src/extraction/quotes.ts +4 -5
- package/src/functions/services.ts +217 -50
- package/src/functions.conversations.json +1 -0
- package/src/functions.test.ts +82 -0
- package/src/index.ts +2 -0
- package/src/service/AgentService.conversations.json +1 -0
- package/src/service/AgentService.test.ts +169 -0
- package/src/service/AgentService.ts +165 -0
- package/src/service/agent-process.ts +359 -0
- package/src/service/index.ts +6 -0
- package/src/session/artifact-diff.ts +1 -1
- package/src/session/format.test.ts +110 -39
- package/src/session/format.ts +12 -14
- package/src/session/index.ts +1 -2
- package/src/session/observer.ts +4 -1
- package/src/session/session.conversations.json +1 -1
- package/src/session/session.test.ts +58 -17
- package/src/session/session.ts +249 -113
- package/src/session/toolkit.ts +21 -25
- package/src/session/version-pin.ts +4 -3
- package/src/templates/instructions/format.tpl +0 -4
- package/src/templates/instructions/system.tpl +11 -2
- package/src/templates/system.ts +6 -5
- package/src/testing/index.ts +5 -0
- package/src/testing/layer.ts +258 -0
- package/src/tracing.ts +113 -0
- package/src/types/artifact.ts +31 -13
- 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/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/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/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
- /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
|
@@ -4,16 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { Expando } from '@dxos/echo/internal';
|
|
9
|
-
import { type FunctionDefinition } from '@dxos/functions';
|
|
10
|
-
import { type FunctionExecutor } from '@dxos/functions-runtime';
|
|
7
|
+
import { Obj } from '@dxos/echo';
|
|
11
8
|
import { log } from '@dxos/log';
|
|
9
|
+
import { Operation } from '@dxos/operation';
|
|
12
10
|
import { Message } from '@dxos/types';
|
|
13
11
|
|
|
14
12
|
export const ExtractionInput = Schema.Struct({
|
|
15
13
|
message: Message.Message,
|
|
16
|
-
objects: Schema.optional(Schema.Array(
|
|
14
|
+
objects: Schema.optional(Schema.Array(Obj.Unknown)),
|
|
17
15
|
options: Schema.optional(
|
|
18
16
|
Schema.Struct({
|
|
19
17
|
timeout: Schema.optional(Schema.Number),
|
|
@@ -29,10 +27,9 @@ export const ExtractionOutput = Schema.Struct({
|
|
|
29
27
|
});
|
|
30
28
|
export interface ExtractionOutput extends Schema.Schema.Type<typeof ExtractionOutput> {}
|
|
31
29
|
|
|
32
|
-
export type
|
|
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,18 +46,46 @@ export type ProcessTranscriptMessageParams = {
|
|
|
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.
|
|
56
81
|
*/
|
|
57
82
|
// TODO(dmaretskyi): Move context to a vector search index.
|
|
58
|
-
export const processTranscriptMessage = async (params:
|
|
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
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,70 +7,78 @@ 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 { GenericToolkit } from '@dxos/ai';
|
|
14
17
|
import { todo } from '@dxos/debug';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { Function, FunctionDefinition, FunctionInvocationService } from '@dxos/functions';
|
|
18
|
+
import { Ref } from '@dxos/echo';
|
|
19
|
+
import { FunctionInvocationService, FunctionNotFoundError } from '@dxos/functions';
|
|
18
20
|
import { invariant } from '@dxos/invariant';
|
|
21
|
+
import { Operation, OperationRegistry } from '@dxos/operation';
|
|
22
|
+
|
|
23
|
+
import { RefFromLLM } from '../types';
|
|
19
24
|
|
|
20
25
|
/**
|
|
21
26
|
* Constructs a `ToolResolverService` whose `resolve(id)` looks up tools in the following order:
|
|
22
27
|
* 1. Toolkit: return an existing tool from the provided `toolkit` if one is present under `id`.
|
|
23
|
-
* 2.
|
|
24
|
-
*
|
|
25
|
-
* 3. Functions passed in: fall back to a matching `FunctionDefinition` from the `functions` array.
|
|
28
|
+
* 2. Operations in DB: query by `key=id`; if found, deserialize and project to a tool.
|
|
29
|
+
* 3. Registered operations: fall back to a matching `Operation.Definition` from the handler set.
|
|
26
30
|
*
|
|
27
31
|
* If none of the above yield a match, the effect fails with `AiToolNotFoundError`.
|
|
28
32
|
*
|
|
29
|
-
* Requires `
|
|
33
|
+
* Requires `Database.Service` in the environment.
|
|
34
|
+
*
|
|
35
|
+
* @deprecated Moving to operation-based services.
|
|
30
36
|
*/
|
|
31
|
-
export const makeToolResolverFromFunctions = (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
export const makeToolResolverFromFunctions = (): Layer.Layer<
|
|
38
|
+
ToolResolverService,
|
|
39
|
+
never,
|
|
40
|
+
GenericToolkit.GenericToolkitProvider | FunctionInvocationService
|
|
41
|
+
> => {
|
|
35
42
|
return Layer.effect(
|
|
36
43
|
ToolResolverService,
|
|
37
44
|
Effect.gen(function* () {
|
|
38
|
-
const
|
|
45
|
+
const toolkitProvider = yield* GenericToolkit.GenericToolkitProvider;
|
|
46
|
+
const functionInvocationService = yield* FunctionInvocationService;
|
|
39
47
|
return {
|
|
40
48
|
resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
|
|
41
49
|
Effect.gen(function* () {
|
|
42
|
-
const
|
|
50
|
+
const toolkit = toolkitProvider.getToolkit();
|
|
51
|
+
|
|
52
|
+
const tool = toolkit.toolkit.tools[id];
|
|
43
53
|
if (tool) {
|
|
44
54
|
return tool;
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
? FunctionDefinition.deserialize(dbFunction)
|
|
53
|
-
: functions.find((fn) => fn.key === id);
|
|
54
|
-
|
|
55
|
-
if (!functionDef) {
|
|
56
|
-
return yield* Effect.fail(new AiToolNotFoundError(id));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return projectFunctionToTool(functionDef);
|
|
60
|
-
}).pipe(Effect.provideService(DatabaseService, dbService)),
|
|
57
|
+
return yield* functionInvocationService.resolveFunction(id).pipe(
|
|
58
|
+
Effect.map(projectFunctionToTool),
|
|
59
|
+
Effect.catchTag('FunctionNotFound', () => Effect.fail(new AiToolNotFoundError(id))),
|
|
60
|
+
);
|
|
61
|
+
}),
|
|
61
62
|
} satisfies Context.Tag.Service<ToolResolverService>;
|
|
62
63
|
}),
|
|
63
64
|
);
|
|
64
65
|
};
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
): Layer.Layer<
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Moving to operation-based services.
|
|
69
|
+
*/
|
|
70
|
+
export const makeToolExecutionServiceFromFunctions = (): Layer.Layer<
|
|
71
|
+
ToolExecutionService,
|
|
72
|
+
never,
|
|
73
|
+
FunctionInvocationService | GenericToolkit.GenericToolkitProvider
|
|
74
|
+
> => {
|
|
70
75
|
return Layer.effect(
|
|
71
76
|
ToolExecutionService,
|
|
72
77
|
Effect.gen(function* () {
|
|
73
|
-
const
|
|
78
|
+
const toolkitProvider = yield* GenericToolkit.GenericToolkitProvider;
|
|
79
|
+
const toolkit = toolkitProvider.getToolkit();
|
|
80
|
+
|
|
81
|
+
const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
|
|
74
82
|
invariant(isHandlerLike(toolkitHandler));
|
|
75
83
|
const functionInvocationService = yield* FunctionInvocationService;
|
|
76
84
|
|
|
@@ -82,12 +90,13 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
82
90
|
if (Tool.isProviderDefined(tool)) {
|
|
83
91
|
throw new Error('Attempted to call a provider-defined tool');
|
|
84
92
|
}
|
|
93
|
+
|
|
85
94
|
// TODO(wittjosiah): Everything is `never` here.
|
|
86
95
|
const { result } = yield* (toolkitHandler.handle as any)(tool.name, input);
|
|
87
96
|
return result;
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
const
|
|
99
|
+
const functionDef = getOperationFromTool(tool).pipe(Option.getOrThrow);
|
|
91
100
|
|
|
92
101
|
return yield* functionInvocationService
|
|
93
102
|
.invokeFunction(functionDef, input as any)
|
|
@@ -104,33 +113,152 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
104
113
|
);
|
|
105
114
|
};
|
|
106
115
|
|
|
116
|
+
export const makeToolResolverFromOperations = <R = never>({
|
|
117
|
+
toolkit: extraToolkit = GenericToolkit.empty,
|
|
118
|
+
}: { toolkit?: GenericToolkit.GenericToolkit<never, never, R> } = {}): Layer.Layer<
|
|
119
|
+
ToolResolverService,
|
|
120
|
+
never,
|
|
121
|
+
GenericToolkit.GenericToolkitProvider | OperationRegistry.Service | R
|
|
122
|
+
> => {
|
|
123
|
+
return Layer.effect(
|
|
124
|
+
ToolResolverService,
|
|
125
|
+
Effect.gen(function* () {
|
|
126
|
+
const toolkitProvider = yield* GenericToolkit.GenericToolkitProvider;
|
|
127
|
+
const operationRegistry = yield* OperationRegistry.Service;
|
|
128
|
+
return {
|
|
129
|
+
resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
|
|
130
|
+
Effect.gen(function* () {
|
|
131
|
+
const toolkit = GenericToolkit.merge(extraToolkit, toolkitProvider.getToolkit());
|
|
132
|
+
|
|
133
|
+
const tool = toolkit.toolkit.tools[id];
|
|
134
|
+
if (tool) {
|
|
135
|
+
return tool;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return yield* operationRegistry.resolve(id).pipe(
|
|
139
|
+
Effect.flatMap(
|
|
140
|
+
Option.match({
|
|
141
|
+
onSome: (_) => Effect.succeed(projectFunctionToTool(_)),
|
|
142
|
+
onNone: () => Effect.fail(new AiToolNotFoundError(id)),
|
|
143
|
+
}),
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
}),
|
|
147
|
+
} satisfies Context.Tag.Service<ToolResolverService>;
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const makeToolExecutionService = <E, R>(opts: {
|
|
153
|
+
invoke: (tool: Tool.Any, input: unknown) => Effect.Effect<unknown>;
|
|
154
|
+
}): Layer.Layer<ToolExecutionService, never, GenericToolkit.GenericToolkitProvider> =>
|
|
155
|
+
Layer.effect(
|
|
156
|
+
ToolExecutionService,
|
|
157
|
+
Effect.gen(function* () {
|
|
158
|
+
const toolkitProvider = yield* GenericToolkit.GenericToolkitProvider;
|
|
159
|
+
const toolkit = toolkitProvider.getToolkit();
|
|
160
|
+
|
|
161
|
+
const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
|
|
162
|
+
invariant(isHandlerLike(toolkitHandler));
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
handlersFor: (toolkit) => {
|
|
166
|
+
const makeHandler = (tool: Tool.Any): ((params: unknown) => Effect.Effect<unknown, any, any>) => {
|
|
167
|
+
return Effect.fn(`toolFunctionHandler ${tool.name}`)(function* (input: any) {
|
|
168
|
+
if (toolkitHandler.tools[tool.name]) {
|
|
169
|
+
if (Tool.isProviderDefined(tool)) {
|
|
170
|
+
throw new Error('Attempted to call a provider-defined tool');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// TODO(wittjosiah): Everything is `never` here.
|
|
174
|
+
const { result } = yield* (toolkitHandler.handle as any)(tool.name, input);
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return yield* opts.invoke(tool, input).pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
return toolkit.of(
|
|
183
|
+
Record.map(toolkit.tools, (tool, _name) => (Tool.isUserDefined(tool) ? makeHandler(tool) : null)) as any,
|
|
184
|
+
) as any;
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
export const makeToolExecutionServiceFromOperationInvoker = (): Layer.Layer<
|
|
191
|
+
ToolExecutionService,
|
|
192
|
+
never,
|
|
193
|
+
Operation.Service | GenericToolkit.GenericToolkitProvider
|
|
194
|
+
> => {
|
|
195
|
+
return Layer.unwrapEffect(
|
|
196
|
+
Effect.gen(function* () {
|
|
197
|
+
const operationInvoker = yield* Operation.Service;
|
|
198
|
+
|
|
199
|
+
return makeToolExecutionService({
|
|
200
|
+
invoke: (tool, input) =>
|
|
201
|
+
Effect.gen(function* () {
|
|
202
|
+
const operationDef = getOperationFromTool(tool).pipe(Option.getOrThrow);
|
|
203
|
+
|
|
204
|
+
return yield* operationInvoker.invoke(operationDef, input).pipe(Effect.orDie);
|
|
205
|
+
}),
|
|
206
|
+
});
|
|
207
|
+
}),
|
|
208
|
+
);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @deprecated Bridge beetwen deprecated function invocataion service and operation services until we remove function invocation service.
|
|
213
|
+
*/
|
|
214
|
+
export const functionInvocationServiceFromOperations: Layer.Layer<
|
|
215
|
+
FunctionInvocationService,
|
|
216
|
+
never,
|
|
217
|
+
OperationRegistry.Service | Operation.Service
|
|
218
|
+
> = Layer.effect(
|
|
219
|
+
FunctionInvocationService,
|
|
220
|
+
Effect.gen(function* () {
|
|
221
|
+
const operationRegistry = yield* OperationRegistry.Service;
|
|
222
|
+
const operationInvoker = yield* Operation.Service;
|
|
223
|
+
return {
|
|
224
|
+
invokeFunction: (operationDef, input) => operationInvoker.invoke(operationDef, input).pipe(Effect.orDie),
|
|
225
|
+
resolveFunction: (key) =>
|
|
226
|
+
operationRegistry.resolve(key).pipe(
|
|
227
|
+
Effect.flatten,
|
|
228
|
+
Effect.catchTag('NoSuchElementException', () => Effect.fail(new FunctionNotFoundError(key))),
|
|
229
|
+
),
|
|
230
|
+
} satisfies Context.Tag.Service<FunctionInvocationService>;
|
|
231
|
+
}),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
export const ToolExecutionServices = Layer.mergeAll(
|
|
235
|
+
makeToolResolverFromFunctions(),
|
|
236
|
+
makeToolExecutionServiceFromFunctions(),
|
|
237
|
+
);
|
|
238
|
+
|
|
107
239
|
class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
|
|
108
240
|
FunctionToolAnnotation,
|
|
109
|
-
{ definition:
|
|
241
|
+
{ definition: Operation.Definition.Any }
|
|
110
242
|
>() {}
|
|
111
243
|
|
|
112
|
-
const
|
|
244
|
+
export const getOperationFromTool = (tool: Tool.Any): Option.Option<Operation.Definition.Any> => {
|
|
245
|
+
return Context.getOption(FunctionToolAnnotation)(tool.annotations).pipe(Option.map(({ definition }) => definition));
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const toolCache = new WeakMap<Operation.Definition.Any, Tool.Any>();
|
|
113
249
|
|
|
114
250
|
/**
|
|
115
|
-
* Projects
|
|
116
|
-
*
|
|
117
|
-
* @param fn The function definition to project into a tool.
|
|
118
|
-
* @param meta Optional projection metadata.
|
|
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`).
|
|
251
|
+
* Projects an `Operation.Definition` into an `AiTool`.
|
|
121
252
|
*/
|
|
122
|
-
const projectFunctionToTool = (fn:
|
|
253
|
+
const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
|
|
123
254
|
if (toolCache.has(fn)) {
|
|
124
255
|
return toolCache.get(fn)!;
|
|
125
256
|
}
|
|
126
257
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
parameters: createStructFieldsFromSchema(fn.inputSchema),
|
|
132
|
-
// TODO(dmaretskyi): Include output schema.
|
|
133
|
-
failure: Schema.Any, // TODO(dmaretskyi): Better type for the failure?
|
|
258
|
+
const tool = Tool.make(makeToolName(fn.meta.name ?? fn.meta.key), {
|
|
259
|
+
description: fn.meta.description,
|
|
260
|
+
parameters: createStructFieldsFromSchema(fn.input),
|
|
261
|
+
failure: Schema.Any,
|
|
134
262
|
}).annotate(FunctionToolAnnotation, { definition: fn });
|
|
135
263
|
toolCache.set(fn, tool);
|
|
136
264
|
return tool;
|
|
@@ -149,7 +277,9 @@ const makeToolName = (name: string) => {
|
|
|
149
277
|
const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<string, Schema.Schema<any, any>> => {
|
|
150
278
|
switch (schema.ast._tag) {
|
|
151
279
|
case 'TypeLiteral':
|
|
152
|
-
return Object.fromEntries(
|
|
280
|
+
return Object.fromEntries(
|
|
281
|
+
schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(mapSchemaTypeForLLM(prop.type))]),
|
|
282
|
+
);
|
|
153
283
|
case 'VoidKeyword':
|
|
154
284
|
return {};
|
|
155
285
|
default:
|
|
@@ -157,6 +287,43 @@ const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<s
|
|
|
157
287
|
}
|
|
158
288
|
};
|
|
159
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Picks an LLM-friendly schema type for the given schema AST.
|
|
292
|
+
* The picked schema type decodes to the original schema type.
|
|
293
|
+
*/
|
|
294
|
+
const mapSchemaTypeForLLM = (ast: SchemaAST.AST): SchemaAST.AST => {
|
|
295
|
+
if (Ref.isRefType(ast)) {
|
|
296
|
+
const description = ast.annotations.description
|
|
297
|
+
? ast.annotations.description + '\n' + RefFromLLM.ast.annotations.description
|
|
298
|
+
: (RefFromLLM.ast.annotations.description as string);
|
|
299
|
+
return RefFromLLM.annotations({ description }).ast;
|
|
300
|
+
} else if (SchemaAST.isTupleType(ast)) {
|
|
301
|
+
return new SchemaAST.TupleType(
|
|
302
|
+
ast.elements.map((t) => new SchemaAST.OptionalType(mapSchemaTypeForLLM(t.type), t.isOptional, t.annotations)),
|
|
303
|
+
ast.rest.map((t) => new SchemaAST.Type(mapSchemaTypeForLLM(t.type), t.annotations)),
|
|
304
|
+
ast.isReadonly,
|
|
305
|
+
ast.annotations,
|
|
306
|
+
);
|
|
307
|
+
} else if (SchemaAST.isTypeLiteral(ast)) {
|
|
308
|
+
return new SchemaAST.TypeLiteral(
|
|
309
|
+
ast.propertySignatures.map(
|
|
310
|
+
(p) =>
|
|
311
|
+
new SchemaAST.PropertySignature(
|
|
312
|
+
p.name,
|
|
313
|
+
mapSchemaTypeForLLM(p.type),
|
|
314
|
+
p.isOptional,
|
|
315
|
+
p.isReadonly,
|
|
316
|
+
p.annotations,
|
|
317
|
+
),
|
|
318
|
+
),
|
|
319
|
+
ast.indexSignatures,
|
|
320
|
+
ast.annotations,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return ast;
|
|
325
|
+
};
|
|
326
|
+
|
|
160
327
|
const isHandlerLike = (value: unknown): value is Toolkit.WithHandler<Record<string, Tool.Any>> => {
|
|
161
328
|
return typeof (value as any).tools === 'object' && typeof (value as any).handle === 'function';
|
|
162
329
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"conversations":[{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"read-name","description":"Reads the name of an organization.","inputSchema":{"type":"object","required":["org"],"properties":{"org":{"type":"string","description":"The ID of the referenced object. Formats accepted:\n- DXN (dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4). DXNs can be prepended with an @ symbol for compatibility with in-text references.\n- space ID, object ID tuple (spaceID:objectID)\n- Only object ID that is assumed to be in the current space (01KG7R1ZXWFMWQ4DA1Q6TN1DG4)","examples":["dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","@dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","BM3FSHFOMJCHCG5QW7JTVKGYABD2GAA7G:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","01KG7R1ZXWFMWQ4DA1Q6TN1DG4"]}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"What is the name of the organization? 01JGFJJZ00G0WKQSJGMAKCNT89","options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01FqHQGxFVdQKeMXjodHavsF","modelId":"claude-opus-4-20250514","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The user is asking for the name of","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" an organization an","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"d has provided what","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" appears to be an","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" object","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" ID: 01JGFJ","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"JZ00G0WK","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"QSJGMAKCNT89","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"\n\nI","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" need to use the read-name function","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" to get the name of this organization.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" According","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" to the function description, I can","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" pass","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" just","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" the object","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" ID if","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" it's assume","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"d to be in the current space.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"\n\nLet me call","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" the function with this","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" ID.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EokECkYICxgCKkDkOVtqWk3+YJ1nk31yy/hYUygSTbpQxoD7UKl2RqwyS+tJSV2rou35JEFIl30ogJZiohCBXqY0IZ3YO1SwhWq1EgztHHPI5rGjH4gehN8aDBh3BbEfM6OCraoAQiIwDSGtzFCbT7K+yTBtmtri6uuGvPwNGmRshKURPnFRCjdAf0gj1Jwge4pmIYnlGpRGKvACF4kjtsTHsn8f7ktuuzSEpVNaC6d5VYA6/Fm5ZFaiQPn0/F4fQXy1PNEyo4007gP21Ate8+98CCtlfkOnEE53hElq58doXrVOzpL+uH5b6PBPtM9f1+L9cKjhTPV6djIcewwHTTSJDTM6fr9c82f9u5EDvzNe1QODqlqCiVtNsjWCYOWNZUqILdl0TQ43Hzjf2T+WN6ARHfd3mGVsAtg8vcBM8D4mPvThsTnoswYIeB6Y5aDAA+Xu32jGRmJGclevuy25lJFZG8lAhOXJOdiP88zTG5XCN5ED3GLo2rjKBnQzwGpzg1M0ARKkrNzuLbNZ31uk36ayo+1T381Ld0yIQAX/ZUrLNZ8ovJ1sIHW18hmnyec69+4qWuy//NBWlAfyFOQnQfXM1f2XO5AFBrSILGtHxWM1+KINm1Xh68gHZpjjpyM5g8zl61nDLGxNq3OBugM7NSghygmGPmy2DlxU147cVzOHh7ZXh8fFxBfZlW0YAQ=="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"text-start","id":"1","metadata":{}},{"type":"text-delta","id":"1","delta":"I","metadata":{}},{"type":"text-delta","id":"1","delta":"'ll look","metadata":{}},{"type":"text-delta","id":"1","delta":" up the name of that","metadata":{}},{"type":"text-delta","id":"1","delta":" organization for you.","metadata":{}},{"type":"text-end","id":"1","metadata":{}},{"type":"tool-params-start","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","name":"read-name","providerExecuted":false,"metadata":{}},{"type":"tool-params-delta","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","delta":"","metadata":{}},{"type":"tool-params-delta","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","delta":"{\"or","metadata":{}},{"type":"tool-params-delta","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","delta":"g\": \"01JGFJJ","metadata":{}},{"type":"tool-params-delta","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","delta":"Z00G0WKQ","metadata":{}},{"type":"tool-params-delta","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","delta":"SJGM","metadata":{}},{"type":"tool-params-delta","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","delta":"AKCNT89\"}","metadata":{}},{"type":"tool-params-end","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","metadata":{}},{"type":"tool-call","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","name":"read-name","providerExecuted":false,"metadata":{},"params":{"org":"dxn:echo:@:01JGFJJZ00G0WKQSJGMAKCNT89"}},{"type":"finish","reason":"tool-calls","usage":{"inputTokens":729,"outputTokens":187,"totalTokens":916},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":729,"output_tokens":8,"server_tool_use":null,"service_tier":"standard"}}}}]},{"parameters":{"model":"@anthropic/claude-opus-4-6","stream":true,"tools":[{"name":"read-name","description":"Reads the name of an organization.","inputSchema":{"type":"object","required":["org"],"properties":{"org":{"type":"string","description":"The ID of the referenced object. Formats accepted:\n- DXN (dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4). DXNs can be prepended with an @ symbol for compatibility with in-text references.\n- space ID, object ID tuple (spaceID:objectID)\n- Only object ID that is assumed to be in the current space (01KG7R1ZXWFMWQ4DA1Q6TN1DG4)","examples":["dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","@dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","BM3FSHFOMJCHCG5QW7JTVKGYABD2GAA7G:01KG7R1ZXWFMWQ4DA1Q6TN1DG4","01KG7R1ZXWFMWQ4DA1Q6TN1DG4"]}},"additionalProperties":false}}]},"prompt":{"content":[{"role":"user","content":"What is the name of the organization? 01JGFJJZ00G0WKQSJGMAKCNT89","options":{}},{"role":"assistant","content":[{"type":"reasoning","text":"The user is asking for the name of an organization and has provided what appears to be an object ID: 01JGFJJZ00G0WKQSJGMAKCNT89\n\nI need to use the read-name function to get the name of this organization. According to the function description, I can pass just the object ID if it's assumed to be in the current space.\n\nLet me call the function with this ID.","options":{}},{"type":"text","text":"I'll look up the name of that organization for you.","options":{}},{"type":"tool-call","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","name":"read-name","params":{"org":"01JGFJJZ00G0WKQSJGMAKCNT89"},"providerExecuted":false,"options":{}}],"options":{}},{"role":"tool","content":[{"type":"tool-result","id":"toolu_01DdHbHNejZJC4CEjngmNLCf","name":"read-name","isFailure":false,"result":"BlueYard","providerExecuted":false,"options":{}}],"options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_01X5xvtDymPG7tTUMLZz3eAD","modelId":"claude-opus-4-20250514","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"text-start","id":"0","metadata":{}},{"type":"text-delta","id":"0","delta":"The name of the organization with","metadata":{}},{"type":"text-delta","id":"0","delta":" ID 01JGFJJ","metadata":{}},{"type":"text-delta","id":"0","delta":"Z00G0WKQ","metadata":{}},{"type":"text-delta","id":"0","delta":"SJGMAKCNT89 is","metadata":{}},{"type":"text-delta","id":"0","delta":" **BlueYard**.","metadata":{}},{"type":"text-end","id":"0","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":801,"outputTokens":39,"totalTokens":840},"metadata":{"anthropic":{"usage":{"cache_creation":{"ephemeral_1h_input_tokens":0,"ephemeral_5m_input_tokens":0},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"input_tokens":801,"output_tokens":6,"server_tool_use":null,"service_tier":"standard"}}}}]}]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, it } from '@effect/vitest';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
|
|
9
|
+
import { ConsolePrinter } from '@dxos/ai';
|
|
10
|
+
import { MemoizedAiService } from '@dxos/ai/testing';
|
|
11
|
+
import { AiSession, GenerationObserver, createToolkit } from '@dxos/assistant';
|
|
12
|
+
import { Blueprint } from '@dxos/blueprints';
|
|
13
|
+
import { Database, Obj, Ref } from '@dxos/echo';
|
|
14
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
15
|
+
import { ObjectId } from '@dxos/keys';
|
|
16
|
+
import { Operation, OperationHandlerSet } from '@dxos/operation';
|
|
17
|
+
import { Organization } from '@dxos/types';
|
|
18
|
+
|
|
19
|
+
import { AssistantTestLayer } from './testing';
|
|
20
|
+
|
|
21
|
+
ObjectId.dangerouslyDisableRandomness();
|
|
22
|
+
|
|
23
|
+
const ReadName = Operation.make({
|
|
24
|
+
meta: {
|
|
25
|
+
key: 'org.dxos.function.read-name',
|
|
26
|
+
name: 'Read Name',
|
|
27
|
+
description: 'Reads the name of an organization.',
|
|
28
|
+
},
|
|
29
|
+
input: Schema.Struct({
|
|
30
|
+
org: Ref.Ref(Organization.Organization),
|
|
31
|
+
}),
|
|
32
|
+
output: Schema.String,
|
|
33
|
+
services: [Database.Service],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const Handlers = OperationHandlerSet.make(
|
|
37
|
+
Operation.withHandler(
|
|
38
|
+
ReadName,
|
|
39
|
+
Effect.fnUntraced(function* ({ org }) {
|
|
40
|
+
const resolved = yield* Database.load(org);
|
|
41
|
+
return resolved.name ?? '<no org>';
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const blueprint = Blueprint.make({
|
|
47
|
+
key: 'org.dxos.blueprint.test',
|
|
48
|
+
name: 'Test blueprint',
|
|
49
|
+
tools: Blueprint.toolDefinitions({ operations: [ReadName] }),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const TestLayer = AssistantTestLayer({
|
|
53
|
+
aiServicePreset: 'edge-remote',
|
|
54
|
+
operationHandlers: Handlers,
|
|
55
|
+
types: [Organization.Organization],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('Research', () => {
|
|
59
|
+
it.effect(
|
|
60
|
+
'call a function with a ref input',
|
|
61
|
+
Effect.fnUntraced(
|
|
62
|
+
function* (_) {
|
|
63
|
+
const org = yield* Database.add(
|
|
64
|
+
Obj.make(Organization.Organization, {
|
|
65
|
+
name: 'BlueYard',
|
|
66
|
+
website: 'https://blueyard.com',
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
yield* Database.flush();
|
|
70
|
+
yield* new AiSession({ observer: GenerationObserver.fromPrinter(new ConsolePrinter()) }).run({
|
|
71
|
+
prompt: `What is the name of the organization? ${org.id}`,
|
|
72
|
+
toolkit: yield* createToolkit({
|
|
73
|
+
blueprints: [blueprint],
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
Effect.provide(TestLayer),
|
|
78
|
+
TestHelpers.provideTestContext,
|
|
79
|
+
),
|
|
80
|
+
MemoizedAiService.isGenerationEnabled() ? 240_000 : 30_000,
|
|
81
|
+
);
|
|
82
|
+
});
|