@dxos/assistant 0.8.4-main.ead640a → 0.8.4-main.ef1bc66f44
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/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-ZPC54VRM.mjs +596 -0
- package/dist/lib/neutral/chunk-ZPC54VRM.mjs.map +7 -0
- package/dist/lib/neutral/extraction/index.mjs +225 -0
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +346 -350
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +38 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/conversation/context.d.ts +97 -62
- 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 +41 -16
- 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 +22 -30
- 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-llm-function/extraction-llm-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +254 -248
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +344 -303
- package/dist/types/src/extraction/extraction.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 +6 -6
- 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/session/GenericToolkit.d.ts +107 -0
- package/dist/types/src/session/GenericToolkit.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 +4 -176
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +2 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +6 -5
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +16 -11
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +5 -6
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +3 -3
- package/dist/types/src/session/version-pin.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 +22 -0
- package/dist/types/src/testing/layer.d.ts.map +1 -0
- package/dist/types/src/types/artifact.d.ts +14 -2
- package/dist/types/src/types/artifact.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +40 -31
- package/src/conversation/context.test.ts +46 -0
- package/src/conversation/context.ts +211 -67
- package/src/conversation/conversation.test.ts +65 -0
- package/src/conversation/conversation.ts +128 -53
- 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 +45 -43
- package/src/execution-graph.ts +23 -14
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +2 -2
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +44 -54
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +15 -14
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +36 -44
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
- package/src/extraction/extraction.ts +9 -8
- package/src/extraction/quotes.ts +4 -5
- package/src/functions/services.ts +66 -37
- package/src/functions.conversations.json +1 -0
- package/src/functions.test.ts +74 -0
- package/src/session/GenericToolkit.ts +160 -0
- package/src/session/artifact-diff.ts +1 -1
- package/src/session/format.test.ts +103 -39
- package/src/session/format.ts +17 -16
- package/src/session/index.ts +3 -0
- package/src/session/observer.ts +5 -3
- package/src/session/session.conversations.json +1 -1
- package/src/session/session.test.ts +28 -15
- package/src/session/session.ts +44 -21
- package/src/session/toolkit.ts +13 -22
- package/src/session/version-pin.ts +6 -6
- package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
- package/src/templates/system.ts +2 -2
- package/src/testing/index.ts +5 -0
- package/src/testing/layer.ts +84 -0
- package/src/types/artifact.ts +43 -6
- package/dist/lib/browser/chunk-CWGVG235.mjs +0 -380
- package/dist/lib/browser/chunk-CWGVG235.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.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OV5PMQPB.mjs +0 -382
- package/dist/lib/node-esm/chunk-OV5PMQPB.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 -934
- 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/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/src/summarization/summarization.test.ts +0 -202
- /package/dist/lib/{browser/named-entity-recognition-QPYHML66.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
- /package/src/templates/{system.tpl → instructions/system.tpl} +0 -0
|
@@ -9,13 +9,12 @@ import * as Effect from 'effect/Effect';
|
|
|
9
9
|
import * as Layer from 'effect/Layer';
|
|
10
10
|
import * as Schema from 'effect/Schema';
|
|
11
11
|
|
|
12
|
-
import { AiService, MemoizedAiService, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
13
|
-
import { AiServiceTestingPreset } from '@dxos/ai/testing';
|
|
14
12
|
import { Obj, Type } from '@dxos/echo';
|
|
15
|
-
import { TestHelpers } from '@dxos/effect';
|
|
16
|
-
import { TracingService } from '@dxos/functions';
|
|
13
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
17
14
|
import { log } from '@dxos/log';
|
|
18
15
|
|
|
16
|
+
import { AssistantTestLayer } from '../testing';
|
|
17
|
+
|
|
19
18
|
import { AiSession } from './session';
|
|
20
19
|
|
|
21
20
|
// Define a calendar event artifact schema.
|
|
@@ -25,7 +24,7 @@ const CalendarEventSchema = Schema.Struct({
|
|
|
25
24
|
endTime: Schema.String,
|
|
26
25
|
description: Schema.String,
|
|
27
26
|
}).pipe(
|
|
28
|
-
Type.
|
|
27
|
+
Type.object({
|
|
29
28
|
typename: 'example.com/type/CalendarEvent',
|
|
30
29
|
version: '0.1.0',
|
|
31
30
|
}),
|
|
@@ -33,7 +32,7 @@ const CalendarEventSchema = Schema.Struct({
|
|
|
33
32
|
|
|
34
33
|
type CalendarEvent = Schema.Schema.Type<typeof CalendarEventSchema>;
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
const TestToolkit = Toolkit.make(
|
|
37
36
|
Tool.make('Calculator', {
|
|
38
37
|
description: 'Basic calculator tool',
|
|
39
38
|
parameters: {
|
|
@@ -46,7 +45,7 @@ class TestToolkit extends Toolkit.make(
|
|
|
46
45
|
}),
|
|
47
46
|
failure: Schema.Never,
|
|
48
47
|
}),
|
|
49
|
-
)
|
|
48
|
+
);
|
|
50
49
|
|
|
51
50
|
// Tool handlers.
|
|
52
51
|
const toolkitLayer = TestToolkit.toLayer({
|
|
@@ -66,15 +65,10 @@ const toolkitLayer = TestToolkit.toLayer({
|
|
|
66
65
|
});
|
|
67
66
|
|
|
68
67
|
const TestLayer = Layer.mergeAll(
|
|
68
|
+
AssistantTestLayer({
|
|
69
|
+
types: [CalendarEventSchema],
|
|
70
|
+
}),
|
|
69
71
|
toolkitLayer,
|
|
70
|
-
AiService.model('@anthropic/claude-3-5-sonnet-20241022'),
|
|
71
|
-
TracingService.layerNoop,
|
|
72
|
-
ToolResolverService.layerEmpty,
|
|
73
|
-
ToolExecutionService.layerEmpty,
|
|
74
|
-
).pipe(
|
|
75
|
-
//
|
|
76
|
-
Layer.provideMerge(MemoizedAiService.layerTest()),
|
|
77
|
-
Layer.provide(AiServiceTestingPreset('direct')),
|
|
78
72
|
);
|
|
79
73
|
|
|
80
74
|
describe('AiSession', () => {
|
|
@@ -111,6 +105,25 @@ describe('AiSession', () => {
|
|
|
111
105
|
TestHelpers.provideTestContext,
|
|
112
106
|
),
|
|
113
107
|
);
|
|
108
|
+
|
|
109
|
+
it.effect(
|
|
110
|
+
'tool schema error',
|
|
111
|
+
Effect.fnUntraced(
|
|
112
|
+
function* (_) {
|
|
113
|
+
const session = new AiSession({ operationModel: 'configured' });
|
|
114
|
+
const toolkit = yield* TestToolkit;
|
|
115
|
+
const response = yield* session.run({
|
|
116
|
+
toolkit,
|
|
117
|
+
prompt:
|
|
118
|
+
'I am testing error handling in tool paramter parsing. I want you to call the calculator tool but omit the input parameter to intentionally differ from the tool schema.',
|
|
119
|
+
history: [],
|
|
120
|
+
});
|
|
121
|
+
log.info('response', { response });
|
|
122
|
+
},
|
|
123
|
+
Effect.provide(TestLayer),
|
|
124
|
+
TestHelpers.provideTestContext,
|
|
125
|
+
),
|
|
126
|
+
);
|
|
114
127
|
});
|
|
115
128
|
|
|
116
129
|
// Travel to rome, florence, livorno, siena, madrid for conferences
|
package/src/session/session.ts
CHANGED
|
@@ -20,13 +20,14 @@ import {
|
|
|
20
20
|
type ToolResolverService,
|
|
21
21
|
callTool,
|
|
22
22
|
getToolCalls,
|
|
23
|
+
withoutToolCallParising,
|
|
23
24
|
} from '@dxos/ai';
|
|
24
25
|
import { type Blueprint } from '@dxos/blueprints';
|
|
25
26
|
import { todo } from '@dxos/debug';
|
|
26
27
|
import { Obj } from '@dxos/echo';
|
|
27
|
-
import { TracingService } from '@dxos/functions';
|
|
28
|
+
import { type FunctionInvocationService, TracingService } from '@dxos/functions';
|
|
28
29
|
import { log } from '@dxos/log';
|
|
29
|
-
import {
|
|
30
|
+
import { Message } from '@dxos/types';
|
|
30
31
|
|
|
31
32
|
import { type AiAssistantError } from '../errors';
|
|
32
33
|
|
|
@@ -39,20 +40,22 @@ export type AiSessionRunRequirements =
|
|
|
39
40
|
| LanguageModel.LanguageModel
|
|
40
41
|
| ToolExecutionService
|
|
41
42
|
| ToolResolverService
|
|
42
|
-
| TracingService
|
|
43
|
+
| TracingService
|
|
44
|
+
| FunctionInvocationService;
|
|
43
45
|
|
|
44
|
-
export type
|
|
46
|
+
export type AiSessionOptions = {};
|
|
47
|
+
|
|
48
|
+
export type AiSessionRunProps<Tools extends Record<string, Tool.Any>> = {
|
|
45
49
|
prompt: string;
|
|
50
|
+
// TODO(wittjosiah): Rename to systemPrompt.
|
|
46
51
|
system?: string;
|
|
47
|
-
history?:
|
|
48
|
-
objects?: Obj.
|
|
49
|
-
blueprints?: Blueprint.Blueprint[];
|
|
52
|
+
history?: Message.Message[];
|
|
53
|
+
objects?: Obj.Unknown[];
|
|
54
|
+
blueprints?: readonly Blueprint.Blueprint[];
|
|
50
55
|
toolkit?: Toolkit.WithHandler<Tools>;
|
|
51
|
-
observer?: GenerationObserver
|
|
56
|
+
observer?: GenerationObserver<Tools>;
|
|
52
57
|
};
|
|
53
58
|
|
|
54
|
-
export type AiSessionOptions = {};
|
|
55
|
-
|
|
56
59
|
/**
|
|
57
60
|
* Contains message history, tools, current context.
|
|
58
61
|
* Current context means the state of the app, time of day, and other contextual information.
|
|
@@ -69,13 +72,25 @@ export class AiSession {
|
|
|
69
72
|
|
|
70
73
|
/** Message history from queue. */
|
|
71
74
|
// TODO(burdon): Evolve into supporting a git-like graph of messages.
|
|
72
|
-
private _history:
|
|
75
|
+
private _history: Message.Message[] = [];
|
|
73
76
|
|
|
74
77
|
/** Pending messages for this session (incl. the current prompt). */
|
|
75
|
-
private _pending:
|
|
78
|
+
private _pending: Message.Message[] = [];
|
|
79
|
+
|
|
80
|
+
private _started = 0;
|
|
81
|
+
private _ended = 0;
|
|
82
|
+
private _toolCalls = 0;
|
|
76
83
|
|
|
77
84
|
constructor(private readonly _options: AiSessionOptions = {}) {}
|
|
78
85
|
|
|
86
|
+
get duration(): number {
|
|
87
|
+
return this._ended - this._started;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get toolCalls(): number {
|
|
91
|
+
return this._toolCalls;
|
|
92
|
+
}
|
|
93
|
+
|
|
79
94
|
run = <Tools extends Record<string, Tool.Any>>({
|
|
80
95
|
prompt,
|
|
81
96
|
system: systemTemplate,
|
|
@@ -84,13 +99,14 @@ export class AiSession {
|
|
|
84
99
|
blueprints = [],
|
|
85
100
|
toolkit,
|
|
86
101
|
observer = GenerationObserver.noop(),
|
|
87
|
-
}:
|
|
102
|
+
}: AiSessionRunProps<Tools>): Effect.Effect<Message.Message[], AiSessionRunError, AiSessionRunRequirements> =>
|
|
88
103
|
Effect.gen(this, function* () {
|
|
104
|
+
this._started = Date.now();
|
|
89
105
|
this._history = [...history];
|
|
90
106
|
this._pending = [];
|
|
91
107
|
const pending = this._pending;
|
|
92
108
|
|
|
93
|
-
const submitMessage = Effect.fnUntraced(function* (message:
|
|
109
|
+
const submitMessage = Effect.fnUntraced(function* (message: Message.Message) {
|
|
94
110
|
pending.push(message);
|
|
95
111
|
yield* observer.onMessage(message);
|
|
96
112
|
yield* TracingService.emitConverationMessage(message);
|
|
@@ -102,7 +118,7 @@ export class AiSession {
|
|
|
102
118
|
const promptMessage = yield* submitMessage(yield* formatUserPrompt({ prompt, history }));
|
|
103
119
|
|
|
104
120
|
// Generate system and prompt messages.
|
|
105
|
-
const system = yield* formatSystemPrompt({ system: systemTemplate, blueprints, objects });
|
|
121
|
+
const system = yield* formatSystemPrompt({ system: systemTemplate, blueprints, objects }).pipe(Effect.orDie);
|
|
106
122
|
|
|
107
123
|
// Tool call loop.
|
|
108
124
|
do {
|
|
@@ -114,15 +130,19 @@ export class AiSession {
|
|
|
114
130
|
objects: objects?.length ?? 0,
|
|
115
131
|
});
|
|
116
132
|
|
|
117
|
-
const prompt = yield* AiPreprocessor.preprocessPrompt([...this._history, ...this._pending], {
|
|
133
|
+
const prompt = yield* AiPreprocessor.preprocessPrompt([...this._history, ...this._pending], {
|
|
134
|
+
system,
|
|
135
|
+
cacheControl: 'ephemeral',
|
|
136
|
+
});
|
|
118
137
|
|
|
119
138
|
// Execute the stream request.
|
|
120
|
-
// logDump('prompt', Prompt.Prompt.pipe(Schema.encodeSync)(prompt));
|
|
121
139
|
const blocks = yield* LanguageModel.streamText({
|
|
122
140
|
prompt,
|
|
123
141
|
toolkit,
|
|
124
142
|
disableToolCallResolution: true,
|
|
125
143
|
}).pipe(
|
|
144
|
+
// Disable tool call parsing so that we can handle parameter schema errors on a per-tool call basis.
|
|
145
|
+
withoutToolCallParising,
|
|
126
146
|
// TOOD(dmaretskyi): Error mapping.
|
|
127
147
|
AiParser.parseResponse({
|
|
128
148
|
onBegin: () => observer.onBegin(),
|
|
@@ -136,7 +156,7 @@ export class AiSession {
|
|
|
136
156
|
|
|
137
157
|
// Create the response message.
|
|
138
158
|
const response = yield* submitMessage(
|
|
139
|
-
Obj.make(
|
|
159
|
+
Obj.make(Message.Message, {
|
|
140
160
|
created: new Date().toISOString(),
|
|
141
161
|
sender: { role: 'assistant' },
|
|
142
162
|
blocks,
|
|
@@ -169,15 +189,18 @@ export class AiSession {
|
|
|
169
189
|
// TODO(wittjosiah): Sometimes tool error results are added to the queue before the tool agent statuses.
|
|
170
190
|
// This results in a broken execution graph.
|
|
171
191
|
yield* submitMessage(
|
|
172
|
-
Obj.make(
|
|
192
|
+
Obj.make(Message.Message, {
|
|
173
193
|
created: new Date().toISOString(),
|
|
174
194
|
sender: { role: 'tool' },
|
|
175
195
|
blocks: toolResults,
|
|
176
196
|
}),
|
|
177
197
|
);
|
|
198
|
+
|
|
199
|
+
this._toolCalls++;
|
|
178
200
|
} while (true);
|
|
179
201
|
|
|
180
|
-
|
|
202
|
+
this._ended = Date.now();
|
|
203
|
+
log('done', { pending: this._pending.length, duration: this.duration, tools: this._toolCalls });
|
|
181
204
|
return this._pending;
|
|
182
205
|
}).pipe(this._semaphore.withPermits(1), Effect.withSpan('AiSession.run'));
|
|
183
206
|
|
|
@@ -187,7 +210,7 @@ export class AiSession {
|
|
|
187
210
|
// TODO(burdon): Implement or remove.
|
|
188
211
|
async runStructured<S extends Schema.Schema.AnyNoContext>(
|
|
189
212
|
_schema: S,
|
|
190
|
-
_options:
|
|
213
|
+
_options: AiSessionRunProps<any>,
|
|
191
214
|
): Promise<Schema.Schema.Type<S>> {
|
|
192
215
|
return todo();
|
|
193
216
|
// const parser = structuredOutputParser(schema);
|
package/src/session/toolkit.ts
CHANGED
|
@@ -4,45 +4,36 @@
|
|
|
4
4
|
|
|
5
5
|
import type * as Tool from '@effect/ai/Tool';
|
|
6
6
|
import * as Toolkit from '@effect/ai/Toolkit';
|
|
7
|
-
import type * as Context from 'effect/Context';
|
|
8
7
|
import * as Effect from 'effect/Effect';
|
|
9
8
|
|
|
10
|
-
import { type AiToolNotFoundError, ToolExecutionService,
|
|
9
|
+
import { type AiToolNotFoundError, ToolExecutionService, ToolResolverService } from '@dxos/ai';
|
|
11
10
|
import { type Blueprint } from '@dxos/blueprints';
|
|
12
11
|
import { isTruthy } from '@dxos/util';
|
|
13
12
|
|
|
14
|
-
export type
|
|
15
|
-
toolkit?: Toolkit.
|
|
16
|
-
|
|
17
|
-
blueprints?: Blueprint.Blueprint[];
|
|
13
|
+
export type CreateToolkitProps = {
|
|
14
|
+
toolkit?: Toolkit.Any;
|
|
15
|
+
blueprints?: readonly Blueprint.Blueprint[];
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
19
|
* Build a combined toolkit from the blueprint tools and the provided toolkit.
|
|
22
20
|
*/
|
|
23
|
-
export const createToolkit =
|
|
24
|
-
toolkit:
|
|
25
|
-
toolIds = [],
|
|
21
|
+
export const createToolkit = ({
|
|
22
|
+
toolkit: toolkitProp,
|
|
26
23
|
blueprints = [],
|
|
27
|
-
}:
|
|
24
|
+
}: CreateToolkitProps): Effect.Effect<
|
|
28
25
|
Toolkit.WithHandler<any>,
|
|
29
26
|
AiToolNotFoundError,
|
|
30
|
-
ToolResolverService | ToolExecutionService | Tool.HandlersFor<
|
|
27
|
+
ToolResolverService | ToolExecutionService | Tool.HandlersFor<any>
|
|
31
28
|
> =>
|
|
32
29
|
Effect.gen(function* () {
|
|
33
|
-
const blueprintToolkit = yield* ToolResolverService.resolveToolkit(
|
|
34
|
-
|
|
35
|
-
...toolIds,
|
|
36
|
-
]);
|
|
30
|
+
const blueprintToolkit = yield* ToolResolverService.resolveToolkit(blueprints.flatMap(({ tools }) => tools));
|
|
31
|
+
const blueprintToolHandler = yield* blueprintToolkit.toContext(ToolExecutionService.handlersFor(blueprintToolkit));
|
|
37
32
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const toolkit = Toolkit.merge(...[toolkitParam, blueprintToolkit].filter(isTruthy));
|
|
43
|
-
return yield* toolkit.pipe(Effect.provide(blueprintToolkitHandler)) as any as Effect.Effect<
|
|
33
|
+
const toolkit = Toolkit.merge(...[toolkitProp, blueprintToolkit].filter(isTruthy));
|
|
34
|
+
return yield* toolkit.pipe(Effect.provide(blueprintToolHandler)) as any as Effect.Effect<
|
|
44
35
|
Toolkit.WithHandler<any>,
|
|
45
36
|
never,
|
|
46
|
-
Tool.HandlersFor<
|
|
37
|
+
Tool.HandlersFor<any>
|
|
47
38
|
>;
|
|
48
39
|
});
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
8
|
-
import { type ObjectVersion } from '@dxos/echo-db';
|
|
9
|
-
import {
|
|
10
|
-
import { type ContentBlock } from '@dxos/
|
|
7
|
+
import { type Obj } from '@dxos/echo';
|
|
8
|
+
import { type ObjectVersion, getVersion } from '@dxos/echo-db';
|
|
9
|
+
import { ObjectId } from '@dxos/keys';
|
|
10
|
+
import { type ContentBlock } from '@dxos/types';
|
|
11
11
|
|
|
12
12
|
// TODO(dmaretskyi): Extract.
|
|
13
13
|
const ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;
|
|
@@ -27,11 +27,11 @@ export interface VersionPin extends Schema.Schema.Type<typeof VersionPinSchema>
|
|
|
27
27
|
|
|
28
28
|
export const VersionPin: typeof VersionPinSchema & {
|
|
29
29
|
DISPOSITION: 'version-pin';
|
|
30
|
-
fromObject: (object:
|
|
30
|
+
fromObject: (object: Obj.Unknown) => VersionPin;
|
|
31
31
|
createBlock: (pin: VersionPin) => ContentBlock.Any;
|
|
32
32
|
} = class extends VersionPinSchema {
|
|
33
33
|
static readonly DISPOSITION = 'version-pin';
|
|
34
|
-
static fromObject(object:
|
|
34
|
+
static fromObject(object: Obj.Unknown): VersionPin {
|
|
35
35
|
return VersionPin.make({
|
|
36
36
|
objectId: object.id,
|
|
37
37
|
version: getVersion(object),
|
|
@@ -45,16 +45,13 @@ You can reply with a block reference for objects if you have the DXN. For exampl
|
|
|
45
45
|
|
|
46
46
|
Each suggestion must in the form of a proposed action enclosed in a <suggestion> tag.
|
|
47
47
|
Example: <suggestion>Show on a map</suggestion>
|
|
48
|
+
Do not use bullets when listing suggestions.
|
|
48
49
|
|
|
49
50
|
### Multiple choice questions
|
|
50
51
|
|
|
51
52
|
You may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.
|
|
52
53
|
Example: <select><option>Yes</option><option>No</option></select>
|
|
53
54
|
|
|
54
|
-
## Toolkit
|
|
55
|
-
|
|
56
|
-
If the user asks for a list of tools, then just emit a single self-closing <toolkit/> tag instead of listing the tools.
|
|
57
|
-
|
|
58
55
|
## Context
|
|
59
56
|
|
|
60
57
|
The current date and time is {{DATETIME}}.
|
package/src/templates/system.ts
CHANGED
|
@@ -7,8 +7,8 @@ import defaultsDeep from 'lodash.defaultsdeep';
|
|
|
7
7
|
import { type ModelCapabilities } from '@dxos/ai';
|
|
8
8
|
import { Template } from '@dxos/blueprints';
|
|
9
9
|
|
|
10
|
-
import FORMAT from './format.tpl?raw';
|
|
11
|
-
import SYSTEM from './system.tpl?raw';
|
|
10
|
+
import FORMAT from './instructions/format.tpl?raw';
|
|
11
|
+
import SYSTEM from './instructions/system.tpl?raw';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* System template variables.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Registry } from '@effect-atom/atom';
|
|
6
|
+
import * as Layer from 'effect/Layer';
|
|
7
|
+
import * as Match from 'effect/Match';
|
|
8
|
+
|
|
9
|
+
import { AiService, type ModelName } from '@dxos/ai';
|
|
10
|
+
import { TestAiService } from '@dxos/ai/testing';
|
|
11
|
+
import type { Type } from '@dxos/echo';
|
|
12
|
+
import { CredentialsService, type FunctionDefinition, type ServiceCredential, TracingService } from '@dxos/functions';
|
|
13
|
+
import { TracingServiceExt, TriggerDispatcher, TriggerStateStore } from '@dxos/functions-runtime';
|
|
14
|
+
import { FunctionInvocationServiceLayerTest, TestDatabaseLayer } from '@dxos/functions-runtime/testing';
|
|
15
|
+
|
|
16
|
+
import { ToolExecutionServices } from '../functions';
|
|
17
|
+
import { GenericToolkit } from '../session';
|
|
18
|
+
|
|
19
|
+
interface TestLayerOptions {
|
|
20
|
+
aiServicePreset?: 'direct' | 'edge-local' | 'edge-remote';
|
|
21
|
+
model?: ModelName;
|
|
22
|
+
functions?: FunctionDefinition.Any[];
|
|
23
|
+
toolkits?: GenericToolkit.GenericToolkit[];
|
|
24
|
+
types?: Type.Entity.Any[];
|
|
25
|
+
credentials?: ServiceCredential[];
|
|
26
|
+
/*
|
|
27
|
+
* Tracing configuration.
|
|
28
|
+
* @default 'noop'
|
|
29
|
+
*/
|
|
30
|
+
tracing?: 'noop' | 'console' | 'pretty';
|
|
31
|
+
|
|
32
|
+
disableLlmMemoization?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const AssistantTestLayer = ({
|
|
36
|
+
aiServicePreset = 'direct',
|
|
37
|
+
model = '@anthropic/claude-opus-4-0',
|
|
38
|
+
functions = [],
|
|
39
|
+
toolkits = [],
|
|
40
|
+
types = [],
|
|
41
|
+
credentials = [],
|
|
42
|
+
tracing = 'noop',
|
|
43
|
+
disableLlmMemoization = false,
|
|
44
|
+
}: TestLayerOptions = {}) => {
|
|
45
|
+
const toolkit = GenericToolkit.merge(...toolkits);
|
|
46
|
+
return Layer.mergeAll(AiService.model(model), ToolExecutionServices).pipe(
|
|
47
|
+
Layer.provideMerge(
|
|
48
|
+
FunctionInvocationServiceLayerTest({
|
|
49
|
+
functions,
|
|
50
|
+
}),
|
|
51
|
+
),
|
|
52
|
+
Layer.provideMerge(
|
|
53
|
+
Layer.mergeAll(
|
|
54
|
+
TestAiService({ preset: aiServicePreset, disableMemoization: disableLlmMemoization }),
|
|
55
|
+
TestDatabaseLayer({
|
|
56
|
+
spaceKey: 'fixed',
|
|
57
|
+
types,
|
|
58
|
+
}),
|
|
59
|
+
CredentialsService.configuredLayer(credentials),
|
|
60
|
+
Match.value(tracing).pipe(
|
|
61
|
+
Match.when('noop', () => TracingService.layerNoop),
|
|
62
|
+
Match.when('console', () => TracingServiceExt.layerLogInfo()),
|
|
63
|
+
Match.when('pretty', () =>
|
|
64
|
+
TracingServiceExt.layerConsolePrettyPrint({
|
|
65
|
+
toolkit: (toolkits.length > 0 ? GenericToolkit.merge(...toolkits) : GenericToolkit.empty).toolkit as any,
|
|
66
|
+
}),
|
|
67
|
+
),
|
|
68
|
+
Match.exhaustive,
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
Layer.provideMerge(GenericToolkit.providerLayer(toolkit)),
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
interface TestLayerWithTriggersOptions extends TestLayerOptions {}
|
|
77
|
+
|
|
78
|
+
export const AssistantTestLayerWithTriggers = (options: TestLayerWithTriggersOptions) =>
|
|
79
|
+
Layer.mergeAll(
|
|
80
|
+
AssistantTestLayer(options),
|
|
81
|
+
TriggerDispatcher.layer({ timeControl: 'manual', startingTime: new Date('2025-09-05T15:01:00.000Z') }).pipe(
|
|
82
|
+
Layer.provide(Registry.layer),
|
|
83
|
+
),
|
|
84
|
+
).pipe(Layer.provideMerge(TriggerStateStore.layerMemory));
|
package/src/types/artifact.ts
CHANGED
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type * as Effect from 'effect/Effect';
|
|
5
6
|
import * as Schema from 'effect/Schema';
|
|
6
7
|
|
|
7
|
-
import { type
|
|
8
|
-
import {
|
|
8
|
+
import { type Err, Type } from '@dxos/echo';
|
|
9
|
+
import { Database } from '@dxos/echo';
|
|
10
|
+
import { EncodedReference } from '@dxos/echo-protocol';
|
|
11
|
+
import { DXN, LOCAL_SPACE_TAG, type ObjectId, type SpaceId } from '@dxos/keys';
|
|
9
12
|
import { trim } from '@dxos/util';
|
|
10
13
|
|
|
11
14
|
/**
|
|
@@ -13,21 +16,33 @@ import { trim } from '@dxos/util';
|
|
|
13
16
|
*/
|
|
14
17
|
export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
|
|
15
18
|
|
|
19
|
+
// TODO(burdon): Rename RefFromLLM? -- yes -dm
|
|
16
20
|
/**
|
|
17
21
|
* A model-friendly way to reference an object.
|
|
18
22
|
* Supports vairous formats that will be normalized to a DXN.
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Use `Type.Ref(XXX)` instead.
|
|
19
25
|
*/
|
|
20
|
-
// TODO(burdon): Rename ObjectReference?
|
|
21
26
|
export const ArtifactId: Schema.Schema<string> & {
|
|
22
27
|
toDXN: (reference: ArtifactId, owningSpaceId?: SpaceId) => DXN;
|
|
28
|
+
resolve: <S extends Type.Entity.Any>(
|
|
29
|
+
schema: S,
|
|
30
|
+
ref: ArtifactId,
|
|
31
|
+
) => Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Database.Service>;
|
|
23
32
|
} = class extends Schema.String.annotations({
|
|
33
|
+
// TODO(dmaretskyi): This section gets overriden.
|
|
24
34
|
description: trim`
|
|
25
35
|
The ID of the referenced object. Formats accepted:
|
|
26
|
-
- DXN (dxn:echo:@:
|
|
36
|
+
- DXN (dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4). DXNs can be prepended with an @ symbol for compatibility with in-text references.
|
|
27
37
|
- space ID, object ID tuple (spaceID:objectID)
|
|
28
|
-
- Only object ID that is assumed to be in the current space (
|
|
38
|
+
- Only object ID that is assumed to be in the current space (01KG7R1ZXWFMWQ4DA1Q6TN1DG4)
|
|
29
39
|
`,
|
|
30
|
-
examples: [
|
|
40
|
+
examples: [
|
|
41
|
+
'dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
|
|
42
|
+
'@dxn:echo:@:01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
|
|
43
|
+
'BM3FSHFOMJCHCG5QW7JTVKGYABD2GAA7G:01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
|
|
44
|
+
'01KG7R1ZXWFMWQ4DA1Q6TN1DG4',
|
|
45
|
+
],
|
|
31
46
|
}) {
|
|
32
47
|
static toDXN(reference: ArtifactId, owningSpaceId?: SpaceId): DXN {
|
|
33
48
|
// Allow @dxn: prefix for compatibility with in-text references.
|
|
@@ -47,6 +62,28 @@ export const ArtifactId: Schema.Schema<string> & {
|
|
|
47
62
|
throw new Error(`Unable to parse object reference: ${reference}`);
|
|
48
63
|
}
|
|
49
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Resolves an artifact ID to an object.
|
|
68
|
+
*/
|
|
69
|
+
static resolve<S extends Type.Entity.Any>(
|
|
70
|
+
schema: S,
|
|
71
|
+
ref: ArtifactId,
|
|
72
|
+
): Effect.Effect<Schema.Schema.Type<S>, Err.ObjectNotFoundError, Database.Service> {
|
|
73
|
+
const dxn = ArtifactId.toDXN(ref);
|
|
74
|
+
return Database.resolve(dxn, schema);
|
|
75
|
+
}
|
|
50
76
|
};
|
|
51
77
|
|
|
52
78
|
export type ArtifactId = Schema.Schema.Type<typeof ArtifactId>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Schema that decodes ECHO reference object from an LLM-friendly input.
|
|
82
|
+
*/
|
|
83
|
+
export const RefFromLLM = Schema.transform(ArtifactId, Type.Ref(Type.Obj), {
|
|
84
|
+
decode: (fromA, fromI) => EncodedReference.fromDXN(ArtifactId.toDXN(fromA)),
|
|
85
|
+
encode: (toI, toA) => EncodedReference.toDXN(toI).toString(),
|
|
86
|
+
strict: false,
|
|
87
|
+
}).annotations({
|
|
88
|
+
description: ArtifactId.ast.annotations.description as string,
|
|
89
|
+
});
|