@dxos/assistant 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef
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/extraction/index.mjs +202 -0
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1731 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/conversation/context.d.ts +120 -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/index.d.ts +1 -1
- package/dist/types/src/conversation/index.d.ts.map +1 -1
- package/dist/types/src/conversation/session.d.ts +78 -0
- package/dist/types/src/conversation/session.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 +32 -40
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts +5 -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-ner-function/named-entity-recognition.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +1066 -307
- 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 +3 -3
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +15 -16
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/session/artifact-diff.d.ts +2 -2
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/error-handling.d.ts +2 -2
- package/dist/types/src/session/error-handling.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +8 -177
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +2 -1
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +7 -6
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/request.d.ts +104 -0
- package/dist/types/src/session/request.d.ts.map +1 -0
- package/dist/types/src/session/toolkit.d.ts +11 -9
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +4 -4
- package/dist/types/src/session/version-pin.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/tracing.d.ts +233 -0
- package/dist/types/src/tracing.d.ts.map +1 -0
- package/dist/types/src/types/artifact.d.ts +28 -0
- package/dist/types/src/types/artifact.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +35 -47
- package/src/conversation/context.test.ts +52 -0
- package/src/conversation/context.ts +324 -75
- package/src/conversation/index.ts +1 -1
- package/src/conversation/session.ts +334 -0
- package/src/diff.test.ts +37 -6
- package/src/diff.ts +18 -4
- package/src/errors.ts +2 -2
- package/src/execution-graph.test.ts +47 -45
- package/src/execution-graph.ts +41 -22
- package/src/extraction/extraction-ner-function/index.ts +0 -1
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
- package/src/extraction/extraction.ts +44 -15
- package/src/extraction/index.ts +0 -1
- package/src/extraction/quotes.ts +5 -6
- package/src/functions/services.ts +126 -65
- package/src/functions.conversations.json +1 -0
- package/src/index.ts +1 -0
- package/src/session/artifact-diff.ts +2 -2
- package/src/session/error-handling.ts +4 -3
- package/src/session/format.ts +34 -26
- package/src/session/index.ts +2 -1
- package/src/session/observer.ts +8 -4
- package/src/session/request.conversations.json +1 -0
- package/src/session/request.ts +342 -0
- package/src/session/toolkit.ts +29 -28
- package/src/session/version-pin.ts +7 -7
- package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
- package/src/templates/{system.tpl → instructions/system.tpl} +50 -2
- package/src/templates/system.ts +9 -8
- package/src/tracing.ts +57 -0
- package/src/{types.ts → types/artifact.ts} +44 -7
- package/src/types/index.ts +5 -0
- package/dist/lib/browser/chunk-ILL2CN3G.mjs +0 -374
- package/dist/lib/browser/chunk-ILL2CN3G.mjs.map +0 -7
- package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
- package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
- package/dist/lib/browser/extraction/index.mjs +0 -272
- package/dist/lib/browser/extraction/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -861
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-GVKA7VL3.mjs +0 -376
- package/dist/lib/node-esm/chunk-GVKA7VL3.mjs.map +0 -7
- package/dist/lib/node-esm/extraction/index.mjs +0 -273
- package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -862
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
- package/dist/types/src/conversation/conversation.d.ts +0 -41
- package/dist/types/src/conversation/conversation.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
- package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -341
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
- package/dist/types/src/session/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 -47
- 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/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -16
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/conversation/conversation.ts +0 -119
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -72
- package/src/extraction/extraction-llm-function/index.ts +0 -5
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -115
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -64
- package/src/session/format.test.ts +0 -60
- package/src/session/session.conversations.json +0 -1
- package/src/session/session.test.ts +0 -146
- package/src/session/session.ts +0 -206
- package/src/summarization/summarization.test.ts +0 -201
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { type FunctionDefinition, type FunctionExecutor } from '@dxos/functions';
|
|
7
|
+
import { Operation } from '@dxos/compute';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
|
-
import {
|
|
10
|
+
import { Message } from '@dxos/types';
|
|
12
11
|
|
|
13
12
|
export const ExtractionInput = Schema.Struct({
|
|
14
|
-
message:
|
|
15
|
-
objects: Schema.optional(Schema.Array(
|
|
13
|
+
message: Message.Message,
|
|
14
|
+
objects: Schema.optional(Schema.Array(Obj.Unknown)),
|
|
16
15
|
options: Schema.optional(
|
|
17
16
|
Schema.Struct({
|
|
18
17
|
timeout: Schema.optional(Schema.Number),
|
|
@@ -23,15 +22,14 @@ export const ExtractionInput = Schema.Struct({
|
|
|
23
22
|
export interface ExtractionInput extends Schema.Schema.Type<typeof ExtractionInput> {}
|
|
24
23
|
|
|
25
24
|
export const ExtractionOutput = Schema.Struct({
|
|
26
|
-
message:
|
|
25
|
+
message: Message.Message,
|
|
27
26
|
timeElapsed: Schema.Number,
|
|
28
27
|
});
|
|
29
28
|
export interface ExtractionOutput extends Schema.Schema.Type<typeof ExtractionOutput> {}
|
|
30
29
|
|
|
31
|
-
export type
|
|
30
|
+
export type ProcessTranscriptMessageProps = {
|
|
32
31
|
input: ExtractionInput;
|
|
33
|
-
function:
|
|
34
|
-
executor: FunctionExecutor;
|
|
32
|
+
function: Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
35
33
|
|
|
36
34
|
options?: {
|
|
37
35
|
/**
|
|
@@ -48,18 +46,46 @@ export type ProcessTranscriptMessageParams = {
|
|
|
48
46
|
};
|
|
49
47
|
};
|
|
50
48
|
|
|
51
|
-
export type ExtractionFunction =
|
|
49
|
+
export type ExtractionFunction = Operation.Definition<ExtractionInput, ExtractionOutput>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Placeholder for Anthropic-based entity extraction.
|
|
53
|
+
* Implementation is currently disabled pending restoration of extraction logic.
|
|
54
|
+
*/
|
|
55
|
+
export const extractionAnthropicFunction = Operation.make({
|
|
56
|
+
meta: {
|
|
57
|
+
key: 'org.dxos.function.extraction.anthropic',
|
|
58
|
+
name: 'Entity Extraction (Anthropic)',
|
|
59
|
+
description: 'Extract entities from transcript using Anthropic LLM.',
|
|
60
|
+
},
|
|
61
|
+
input: ExtractionInput,
|
|
62
|
+
output: ExtractionOutput,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Placeholder for NER-based entity extraction.
|
|
67
|
+
* Implementation is currently disabled pending restoration of extraction logic.
|
|
68
|
+
*/
|
|
69
|
+
export const extractionNerFunction = Operation.make({
|
|
70
|
+
meta: {
|
|
71
|
+
key: 'org.dxos.function.extraction.ner',
|
|
72
|
+
name: 'Entity Extraction (NER)',
|
|
73
|
+
description: 'Extract entities from transcript using Named Entity Recognition.',
|
|
74
|
+
},
|
|
75
|
+
input: ExtractionInput,
|
|
76
|
+
output: ExtractionOutput,
|
|
77
|
+
});
|
|
52
78
|
|
|
53
79
|
/**
|
|
54
80
|
* Extract entities from the transcript message and add them to the message.
|
|
55
81
|
*/
|
|
56
82
|
// TODO(dmaretskyi): Move context to a vector search index.
|
|
57
|
-
export const processTranscriptMessage = async (params:
|
|
83
|
+
export const processTranscriptMessage = async (params: ProcessTranscriptMessageProps): Promise<ExtractionOutput> => {
|
|
58
84
|
try {
|
|
59
85
|
if (params.options?.timeout && params.options.timeout > 0) {
|
|
60
|
-
return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
|
|
86
|
+
// return await asyncTimeout(params.executor.invoke(params.function, params.input), params.options.timeout);
|
|
61
87
|
} else {
|
|
62
|
-
return await params.executor.invoke(params.function, params.input);
|
|
88
|
+
// return await params.executor.invoke(params.function, params.input);
|
|
63
89
|
}
|
|
64
90
|
} catch (error) {
|
|
65
91
|
if (params.options?.fallbackToRaw) {
|
|
@@ -72,4 +98,7 @@ export const processTranscriptMessage = async (params: ProcessTranscriptMessageP
|
|
|
72
98
|
throw error;
|
|
73
99
|
}
|
|
74
100
|
}
|
|
101
|
+
|
|
102
|
+
// TODO(dmaretskyi): Restore extraction logic.
|
|
103
|
+
return { message: params.input.message, timeElapsed: 0 };
|
|
75
104
|
};
|
package/src/extraction/index.ts
CHANGED
package/src/extraction/quotes.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { Filter, Query } from '@dxos/echo';
|
|
8
|
-
import {
|
|
9
|
-
import { ObjectId } from '@dxos/echo-schema';
|
|
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
|
}),
|
|
@@ -2,71 +2,72 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as Tool from '@effect/ai/Tool';
|
|
6
|
+
import type * as Toolkit from '@effect/ai/Toolkit';
|
|
7
|
+
import * as Context from 'effect/Context';
|
|
8
|
+
import * as Effect from 'effect/Effect';
|
|
9
|
+
import * as Layer from 'effect/Layer';
|
|
10
|
+
import * as Option from 'effect/Option';
|
|
11
|
+
import * as Record from 'effect/Record';
|
|
12
|
+
import * as Schema from 'effect/Schema';
|
|
13
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
14
|
|
|
8
15
|
import { AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
16
|
+
import { OpaqueToolkit } from '@dxos/ai';
|
|
17
|
+
import { Operation, OperationRegistry } from '@dxos/compute';
|
|
9
18
|
import { todo } from '@dxos/debug';
|
|
10
|
-
import {
|
|
11
|
-
import { DatabaseService, FunctionDefinition, FunctionInvocationService, FunctionType } from '@dxos/functions';
|
|
19
|
+
import { Ref } from '@dxos/echo';
|
|
12
20
|
import { invariant } from '@dxos/invariant';
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* Requires `DatabaseService` in the environment.
|
|
24
|
-
*/
|
|
25
|
-
export const makeToolResolverFromFunctions = (
|
|
26
|
-
functions: FunctionDefinition<any, any>[],
|
|
27
|
-
toolkit: Toolkit.Toolkit<any>,
|
|
28
|
-
): Layer.Layer<ToolResolverService, never, DatabaseService> => {
|
|
22
|
+
import { RefFromLLM } from '../types';
|
|
23
|
+
|
|
24
|
+
export const makeToolResolverFromOperations = <R = never>({
|
|
25
|
+
toolkit: extraToolkit = OpaqueToolkit.empty,
|
|
26
|
+
}: { toolkit?: OpaqueToolkit.OpaqueToolkit<never, never, R> } = {}): Layer.Layer<
|
|
27
|
+
ToolResolverService,
|
|
28
|
+
never,
|
|
29
|
+
OpaqueToolkit.OpaqueToolkitProvider | OperationRegistry.Service | R
|
|
30
|
+
> => {
|
|
29
31
|
return Layer.effect(
|
|
30
32
|
ToolResolverService,
|
|
31
33
|
Effect.gen(function* () {
|
|
32
|
-
const
|
|
34
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
35
|
+
const operationRegistry = yield* OperationRegistry.Service;
|
|
33
36
|
return {
|
|
34
37
|
resolve: (id): Effect.Effect<Tool.Any, AiToolNotFoundError> =>
|
|
35
38
|
Effect.gen(function* () {
|
|
36
|
-
const
|
|
39
|
+
const toolkit = OpaqueToolkit.merge(extraToolkit, toolkitProvider.getToolkit());
|
|
40
|
+
|
|
41
|
+
const tool = toolkit.toolkit.tools[id];
|
|
37
42
|
if (tool) {
|
|
38
43
|
return tool;
|
|
39
44
|
}
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return yield* Effect.fail(new AiToolNotFoundError(id));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return projectFunctionToTool(functionDef);
|
|
54
|
-
}).pipe(Effect.provideService(DatabaseService, dbService)),
|
|
46
|
+
return yield* operationRegistry.resolve(id).pipe(
|
|
47
|
+
Effect.flatMap(
|
|
48
|
+
Option.match({
|
|
49
|
+
onSome: (_) => Effect.succeed(projectFunctionToTool(_)),
|
|
50
|
+
onNone: () => Effect.fail(new AiToolNotFoundError(id)),
|
|
51
|
+
}),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
}),
|
|
55
55
|
} satisfies Context.Tag.Service<ToolResolverService>;
|
|
56
56
|
}),
|
|
57
57
|
);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
export const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
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(
|
|
65
64
|
ToolExecutionService,
|
|
66
65
|
Effect.gen(function* () {
|
|
67
|
-
const
|
|
66
|
+
const toolkitProvider = yield* OpaqueToolkit.OpaqueToolkitProvider;
|
|
67
|
+
const toolkit = toolkitProvider.getToolkit();
|
|
68
|
+
|
|
69
|
+
const toolkitHandler = yield* toolkit.toolkit.pipe(Effect.provide(toolkit.layer));
|
|
68
70
|
invariant(isHandlerLike(toolkitHandler));
|
|
69
|
-
const functionInvocationService = yield* FunctionInvocationService;
|
|
70
71
|
|
|
71
72
|
return {
|
|
72
73
|
handlersFor: (toolkit) => {
|
|
@@ -76,15 +77,13 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
76
77
|
if (Tool.isProviderDefined(tool)) {
|
|
77
78
|
throw new Error('Attempted to call a provider-defined tool');
|
|
78
79
|
}
|
|
80
|
+
|
|
79
81
|
// TODO(wittjosiah): Everything is `never` here.
|
|
80
|
-
|
|
82
|
+
const { result } = yield* (toolkitHandler.handle as any)(tool.name, input);
|
|
83
|
+
return result;
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return yield* functionInvocationService
|
|
86
|
-
.invokeFunction(functionDef, input as any)
|
|
87
|
-
.pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
86
|
+
return yield* opts.invoke(tool, input).pipe(Effect.catchAllDefect((defect) => Effect.fail(defect)));
|
|
88
87
|
});
|
|
89
88
|
};
|
|
90
89
|
|
|
@@ -95,33 +94,56 @@ export const makeToolExecutionServiceFromFunctions = (
|
|
|
95
94
|
};
|
|
96
95
|
}),
|
|
97
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
|
+
);
|
|
98
117
|
};
|
|
99
118
|
|
|
119
|
+
export const ToolExecutionServices = Layer.mergeAll(
|
|
120
|
+
makeToolResolverFromOperations(),
|
|
121
|
+
makeToolExecutionServiceFromOperationInvoker(),
|
|
122
|
+
);
|
|
123
|
+
|
|
100
124
|
class FunctionToolAnnotation extends Context.Tag('@dxos/assistant/FunctionToolAnnotation')<
|
|
101
125
|
FunctionToolAnnotation,
|
|
102
|
-
{ definition:
|
|
126
|
+
{ definition: Operation.Definition.Any }
|
|
103
127
|
>() {}
|
|
104
128
|
|
|
105
|
-
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>();
|
|
106
134
|
|
|
107
135
|
/**
|
|
108
|
-
* Projects
|
|
109
|
-
*
|
|
110
|
-
* @param fn The function definition to project into a tool.
|
|
111
|
-
* @param meta Optional projection metadata.
|
|
112
|
-
* @param meta.deployedFunctionId Backend deployment ID used for remote invocation when present. This is the
|
|
113
|
-
* EDGE service's function deployment identifier (not the ECHO object ID/DXN and not `FunctionDefinition.key`).
|
|
136
|
+
* Projects an `Operation.Definition` into an `AiTool`.
|
|
114
137
|
*/
|
|
115
|
-
const projectFunctionToTool = (fn:
|
|
138
|
+
const projectFunctionToTool = (fn: Operation.Definition.Any): Tool.Any => {
|
|
116
139
|
if (toolCache.has(fn)) {
|
|
117
140
|
return toolCache.get(fn)!;
|
|
118
141
|
}
|
|
119
142
|
|
|
120
|
-
const tool = Tool.make(makeToolName(fn.name), {
|
|
121
|
-
description: fn.description,
|
|
122
|
-
parameters: createStructFieldsFromSchema(fn.
|
|
123
|
-
|
|
124
|
-
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,
|
|
125
147
|
}).annotate(FunctionToolAnnotation, { definition: fn });
|
|
126
148
|
toolCache.set(fn, tool);
|
|
127
149
|
return tool;
|
|
@@ -131,8 +153,8 @@ const projectFunctionToTool = (fn: FunctionDefinition<any, any>): Tool.Any => {
|
|
|
131
153
|
* @returns Tool name produced from function name by escaping invalid characters.
|
|
132
154
|
*/
|
|
133
155
|
const makeToolName = (name: string) => {
|
|
134
|
-
const toolName = name.replace(/[^a-zA-Z0-9]/g, '
|
|
135
|
-
invariant(toolName.match(/^[a-
|
|
156
|
+
const toolName = name.toLowerCase().replace(/[^a-zA-Z0-9]/g, '-');
|
|
157
|
+
invariant(toolName.match(/^[a-z_][a-z0-9-_]*$/));
|
|
136
158
|
return toolName;
|
|
137
159
|
};
|
|
138
160
|
|
|
@@ -140,7 +162,9 @@ const makeToolName = (name: string) => {
|
|
|
140
162
|
const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<string, Schema.Schema<any, any>> => {
|
|
141
163
|
switch (schema.ast._tag) {
|
|
142
164
|
case 'TypeLiteral':
|
|
143
|
-
return Object.fromEntries(
|
|
165
|
+
return Object.fromEntries(
|
|
166
|
+
schema.ast.propertySignatures.map((prop) => [prop.name, Schema.make(mapSchemaTypeForLLM(prop.type))]),
|
|
167
|
+
);
|
|
144
168
|
case 'VoidKeyword':
|
|
145
169
|
return {};
|
|
146
170
|
default:
|
|
@@ -148,6 +172,43 @@ const createStructFieldsFromSchema = (schema: Schema.Schema<any, any>): Record<s
|
|
|
148
172
|
}
|
|
149
173
|
};
|
|
150
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Picks an LLM-friendly schema type for the given schema AST.
|
|
177
|
+
* The picked schema type decodes to the original schema type.
|
|
178
|
+
*/
|
|
179
|
+
const mapSchemaTypeForLLM = (ast: SchemaAST.AST): SchemaAST.AST => {
|
|
180
|
+
if (Ref.isRefType(ast)) {
|
|
181
|
+
const description = ast.annotations.description
|
|
182
|
+
? ast.annotations.description + '\n' + RefFromLLM.ast.annotations.description
|
|
183
|
+
: (RefFromLLM.ast.annotations.description as string);
|
|
184
|
+
return RefFromLLM.annotations({ description }).ast;
|
|
185
|
+
} else if (SchemaAST.isTupleType(ast)) {
|
|
186
|
+
return new SchemaAST.TupleType(
|
|
187
|
+
ast.elements.map((t) => new SchemaAST.OptionalType(mapSchemaTypeForLLM(t.type), t.isOptional, t.annotations)),
|
|
188
|
+
ast.rest.map((t) => new SchemaAST.Type(mapSchemaTypeForLLM(t.type), t.annotations)),
|
|
189
|
+
ast.isReadonly,
|
|
190
|
+
ast.annotations,
|
|
191
|
+
);
|
|
192
|
+
} else if (SchemaAST.isTypeLiteral(ast)) {
|
|
193
|
+
return new SchemaAST.TypeLiteral(
|
|
194
|
+
ast.propertySignatures.map(
|
|
195
|
+
(p) =>
|
|
196
|
+
new SchemaAST.PropertySignature(
|
|
197
|
+
p.name,
|
|
198
|
+
mapSchemaTypeForLLM(p.type),
|
|
199
|
+
p.isOptional,
|
|
200
|
+
p.isReadonly,
|
|
201
|
+
p.annotations,
|
|
202
|
+
),
|
|
203
|
+
),
|
|
204
|
+
ast.indexSignatures,
|
|
205
|
+
ast.annotations,
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return ast;
|
|
210
|
+
};
|
|
211
|
+
|
|
151
212
|
const isHandlerLike = (value: unknown): value is Toolkit.WithHandler<Record<string, Tool.Any>> => {
|
|
152
213
|
return typeof (value as any).tools === 'object' && typeof (value as any).handle === 'function';
|
|
153
214
|
};
|
|
@@ -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_01RTYeojYbdVe9QGkcMvKbER","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" user wants to know the name of an organization with ID 01JGFJJZ00G0WKQSJGMAKCNT89.","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EpECClkIDRgCKkBhbbtJF+Q+wsAR8giXTK13Eui/M8yFfrB46Vzozj6aWeupuZy0FCx6VSI4FmNelVTGMCsbT5apFxxgVf6A7FAJMg9jbGF1ZGUtb3B1cy00LTY4ABIMHOEtEgcKz5Wb+gpbGgxPG+AOzUXWigifeyUiML7FnkmDoz8pWD5P9R4Wul/DeoJE41ntyU/B/abCz0pQx4PHE8N4i5aoFBhUuQE5hSpmlXcA03Cj9t8LvHSOwMobEUZcnKTZn9x1upUfts+Ez+NsQBXY//niKxqt/E7yE5TKHwDO/nuZ2rteTus79EjTEkPaEUcXQso8YAbQknG7ldRd1Nd2X4D2X+bBJH2AVG7SKLSFW3QAGAE="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"tool-params-start","id":"toolu_01KM7uhfLgRWepvTtotjHME2","name":"read-name","providerExecuted":false,"metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"{\"org\": \"01","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"JGFJJZ0","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"0G0W","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"KQSJGMAKCN","metadata":{}},{"type":"tool-params-delta","id":"toolu_01KM7uhfLgRWepvTtotjHME2","delta":"T89\"}","metadata":{}},{"type":"tool-params-end","id":"toolu_01KM7uhfLgRWepvTtotjHME2","metadata":{}},{"type":"finish","reason":"tool-calls","usage":{"inputTokens":883,"outputTokens":122,"totalTokens":1005},"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":883,"output_tokens":9,"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 wants to know the name of an organization with ID 01JGFJJZ00G0WKQSJGMAKCNT89.","options":{}},{"type":"tool-call","id":"toolu_01KM7uhfLgRWepvTtotjHME2","name":"read-name","params":{"org":"01JGFJJZ00G0WKQSJGMAKCNT89"},"providerExecuted":false,"options":{}}],"options":{}},{"role":"tool","content":[{"type":"tool-result","id":"toolu_01KM7uhfLgRWepvTtotjHME2","name":"read-name","isFailure":false,"result":"BlueYard","providerExecuted":false,"options":{}}],"options":{"anthropic":{"cacheControl":{"ttl":"5m","type":"ephemeral"}}}}]},"response":[{"type":"response-metadata","id":"msg_016RCVnGrLXVf4ba4KznSHyr","modelId":"claude-opus-4-6","timestamp":"1970-01-01T00:00:00.000Z","metadata":{}},{"type":"reasoning-start","id":"0","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"The","metadata":{}},{"type":"reasoning-delta","id":"0","delta":" name of the organization is \"BlueYard\".","metadata":{}},{"type":"reasoning-delta","id":"0","delta":"","metadata":{"anthropic":{"type":"thinking","signature":"EuYBClkIDRgCKkA0n2vPrvDwpmiAgWX5raN/PW8EkSgAqlMsO4gsgxIXidyUWiozI8lhzJTYOm5D3BOTMcW+mcfUvAw1rtDVianiMg9jbGF1ZGUtb3B1cy00LTY4ABIMiAi8SSliRognm8yNGgx+gpH0kejwSoiouLAiMBy9umHrGuQCJ92KaaBqRAq50lt7WXRaCyO3vuheveWN1JDryUFhh7GUZ/pogH0m+Co7lZSQmO4ybaE4MmyYbu7S3e/upJcsrQIiMB7LByFcpfSrjsF/VSIPprW5kMMafV1yQ6U2uI+dhUTohKMYAQ=="}}},{"type":"reasoning-end","id":"0","metadata":{}},{"type":"text-start","id":"1","metadata":{}},{"type":"text-delta","id":"1","delta":"The name of the organization with ID `01JGFJJZ00G0WKQSJGMAKCNT89` is","metadata":{}},{"type":"text-delta","id":"1","delta":" **BlueYard**.","metadata":{}},{"type":"text-end","id":"1","metadata":{}},{"type":"finish","reason":"stop","usage":{"inputTokens":973,"outputTokens":66,"totalTokens":1039},"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":973,"output_tokens":8,"server_tool_use":null,"service_tier":"standard"}}}}]}]}
|
package/src/index.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Context from 'effect/Context';
|
|
6
6
|
|
|
7
7
|
import { type ObjectVersion } from '@dxos/echo-db';
|
|
8
|
-
import { type ObjectId } from '@dxos/
|
|
8
|
+
import { type ObjectId } from '@dxos/keys';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolves artifact ids to their versions.
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
5
|
+
import * as AiError from '@effect/ai/AiError';
|
|
6
|
+
import * as HttpClientError from '@effect/platform/HttpClientError';
|
|
7
|
+
import * as Effect from 'effect/Effect';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
8
9
|
|
|
9
10
|
import { AiModelError } from '../errors';
|
|
10
11
|
|
package/src/session/format.ts
CHANGED
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Effect from 'effect/Effect';
|
|
6
|
+
import * as Function from 'effect/Function';
|
|
7
|
+
import * as Option from 'effect/Option';
|
|
6
8
|
|
|
7
|
-
import { Template } from '@dxos/
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
+
import { type FunctionNotFoundError, type Operation, type OperationRegistry, Template } from '@dxos/compute';
|
|
10
|
+
import { type Database, Obj } from '@dxos/echo';
|
|
9
11
|
import { ObjectVersion } from '@dxos/echo-db';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
+
import type { ObjectNotFoundError } from '@dxos/echo/Err';
|
|
13
|
+
import { type ObjectId } from '@dxos/keys';
|
|
12
14
|
import { log } from '@dxos/log';
|
|
13
|
-
import { type ContentBlock,
|
|
15
|
+
import { type ContentBlock, Message } from '@dxos/types';
|
|
14
16
|
import { trim } from '@dxos/util';
|
|
15
17
|
|
|
16
18
|
import { AiAssistantError } from '../errors';
|
|
17
|
-
|
|
18
19
|
import { ArtifactDiffResolver } from './artifact-diff';
|
|
19
|
-
import { type
|
|
20
|
+
import { type AiRequestRunError, type AiRequestRunProps } from './request';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Formats the system prompt.
|
|
@@ -26,20 +27,24 @@ export const formatSystemPrompt = ({
|
|
|
26
27
|
system,
|
|
27
28
|
blueprints = [],
|
|
28
29
|
objects = [],
|
|
29
|
-
}: Pick<
|
|
30
|
+
}: Pick<AiRequestRunProps, 'system' | 'blueprints' | 'objects'>): Effect.Effect<
|
|
31
|
+
string,
|
|
32
|
+
FunctionNotFoundError | ObjectNotFoundError,
|
|
33
|
+
Database.Service | OperationRegistry.Service | Operation.Service
|
|
34
|
+
> =>
|
|
30
35
|
Effect.gen(function* () {
|
|
31
|
-
const blueprintDefs = yield* pipe(
|
|
36
|
+
const blueprintDefs = yield* Function.pipe(
|
|
32
37
|
blueprints,
|
|
33
38
|
Effect.forEach((blueprint) => Effect.succeed(blueprint.instructions)),
|
|
34
|
-
Effect.flatMap(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
(template) => trim`
|
|
39
|
+
Effect.flatMap(
|
|
40
|
+
Effect.forEach((template) =>
|
|
41
|
+
Effect.gen(function* () {
|
|
42
|
+
return trim`
|
|
39
43
|
<blueprint>
|
|
40
|
-
${Template.
|
|
44
|
+
${yield* Template.processTemplate(template)}
|
|
41
45
|
</blueprint>
|
|
42
|
-
|
|
46
|
+
`;
|
|
47
|
+
}),
|
|
43
48
|
),
|
|
44
49
|
),
|
|
45
50
|
Effect.map((blueprints) =>
|
|
@@ -47,7 +52,7 @@ export const formatSystemPrompt = ({
|
|
|
47
52
|
),
|
|
48
53
|
);
|
|
49
54
|
|
|
50
|
-
const objectDefs = yield* pipe(
|
|
55
|
+
const objectDefs = yield* Function.pipe(
|
|
51
56
|
objects,
|
|
52
57
|
Effect.forEach((object) =>
|
|
53
58
|
Effect.succeed(trim`
|
|
@@ -60,18 +65,21 @@ export const formatSystemPrompt = ({
|
|
|
60
65
|
Effect.map((objects) => (objects.length > 0 ? ['## Context Objects', ...objects].join('\n\n') : undefined)),
|
|
61
66
|
);
|
|
62
67
|
|
|
63
|
-
return yield* pipe(
|
|
68
|
+
return yield* Function.pipe(
|
|
64
69
|
Effect.succeed([system, blueprintDefs, objectDefs].filter((def): def is string => def !== undefined)),
|
|
65
70
|
Effect.map((parts) => parts.join('\n\n')),
|
|
66
71
|
);
|
|
67
|
-
});
|
|
72
|
+
}).pipe(Effect.withSpan('formatSystemPrompt'));
|
|
68
73
|
|
|
69
74
|
/**
|
|
70
75
|
* Formats the user prompt.
|
|
71
76
|
*/
|
|
72
77
|
// TODO(burdon): Move to AiPreprocessor.
|
|
73
78
|
// TODO(burdon): Convert util below to `Effect.fn` (to preserve stack info)
|
|
74
|
-
export const formatUserPrompt = ({
|
|
79
|
+
export const formatUserPrompt = ({
|
|
80
|
+
prompt,
|
|
81
|
+
history = [],
|
|
82
|
+
}: Pick<AiRequestRunProps, 'prompt' | 'history'>): Effect.Effect<Message.Message, AiRequestRunError> =>
|
|
75
83
|
Effect.gen(function* () {
|
|
76
84
|
const blocks: ContentBlock.Any[] = [];
|
|
77
85
|
|
|
@@ -102,14 +110,14 @@ export const formatUserPrompt = ({ prompt, history = [] }: Pick<AiSessionRunPara
|
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
return Obj.make(
|
|
113
|
+
return Obj.make(Message.Message, {
|
|
106
114
|
created: new Date().toISOString(),
|
|
107
115
|
sender: { role: 'user' },
|
|
108
|
-
blocks: [...blocks, { _tag: 'text', text: prompt }],
|
|
116
|
+
blocks: typeof prompt === 'string' ? [...blocks, { _tag: 'text', text: prompt }] : [...blocks, ...prompt],
|
|
109
117
|
});
|
|
110
|
-
});
|
|
118
|
+
}).pipe(Effect.withSpan('formatUserPrompt'));
|
|
111
119
|
|
|
112
|
-
const gatherObjectVersions = (messages:
|
|
120
|
+
const gatherObjectVersions = (messages: Message.Message[]): Map<ObjectId, ObjectVersion> => {
|
|
113
121
|
const artifactIds = new Map<ObjectId, ObjectVersion>();
|
|
114
122
|
for (const message of messages) {
|
|
115
123
|
for (const block of message.blocks) {
|
|
@@ -128,7 +136,7 @@ const createArtifactUpdateBlock = (
|
|
|
128
136
|
return {
|
|
129
137
|
_tag: 'text',
|
|
130
138
|
// TODO(dmaretskyi): Does this need to be a special content-block?
|
|
131
|
-
disposition: '
|
|
139
|
+
disposition: 'synthetic',
|
|
132
140
|
text: trim`
|
|
133
141
|
The following artifacts have been updated since the last message:
|
|
134
142
|
${[...artifactDiff.entries()]
|
package/src/session/index.ts
CHANGED
package/src/session/observer.ts
CHANGED
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import type * as Tool from '@effect/ai/Tool';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Function from 'effect/Function';
|
|
6
8
|
|
|
7
9
|
import { type AiParser, type ConsolePrinter } from '@dxos/ai';
|
|
8
|
-
import { type
|
|
10
|
+
import { type Message } from '@dxos/types';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Live observer of the generation process.
|
|
12
14
|
*/
|
|
13
|
-
export interface GenerationObserver
|
|
15
|
+
export interface GenerationObserver<
|
|
16
|
+
Tools extends Record<string, Tool.Any> = any,
|
|
17
|
+
> extends AiParser.ParseResponseCallbacks<Tools> {
|
|
14
18
|
/**
|
|
15
19
|
* Complete messages fired during the session, both from the model and from the user.
|
|
16
20
|
* This message will contain all message blocks emitted through the `onBlock` callback.
|
|
17
21
|
*/
|
|
18
|
-
onMessage: (message:
|
|
22
|
+
onMessage: (message: Message.Message) => Effect.Effect<void>;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
export const GenerationObserver = Object.freeze({
|