@dxos/assistant 0.8.3 → 0.8.4-main.f9ba587
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/browser/index.mjs +456 -595
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +456 -595
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/blueprint/blueprint.d.ts +33 -47
- package/dist/types/src/blueprint/blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprint/index.d.ts +1 -2
- package/dist/types/src/blueprint/index.d.ts.map +1 -1
- package/dist/types/src/blueprint/registry.d.ts +7 -0
- package/dist/types/src/blueprint/registry.d.ts.map +1 -0
- package/dist/types/src/context/binder.d.ts +34 -0
- package/dist/types/src/context/binder.d.ts.map +1 -0
- package/dist/types/src/context/binding.d.ts +38 -0
- package/dist/types/src/context/binding.d.ts.map +1 -0
- package/dist/types/src/context/index.d.ts +3 -0
- package/dist/types/src/context/index.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +44 -0
- package/dist/types/src/conversation/conversation.d.ts.map +1 -0
- package/dist/types/src/conversation/index.d.ts +2 -0
- package/dist/types/src/conversation/index.d.ts.map +1 -0
- 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 +10 -10
- package/dist/types/src/index.d.ts +4 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/research/research.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +25 -3
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -30
- package/src/blueprint/blueprint.ts +57 -57
- package/src/blueprint/index.ts +1 -2
- package/src/blueprint/registry.ts +15 -0
- package/src/context/binder.ts +101 -0
- package/src/context/binding.ts +31 -0
- package/src/context/index.ts +6 -0
- package/src/conversation/conversation.ts +103 -0
- package/src/conversation/index.ts +5 -0
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +2 -1
- package/src/index.ts +4 -1
- package/src/research/research.ts +3 -2
- package/src/session/session.test.ts +48 -2
- package/src/session/session.ts +51 -18
- package/dist/lib/node/index.cjs +0 -2178
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/types/src/blueprint/ai.test.d.ts +0 -2
- package/dist/types/src/blueprint/ai.test.d.ts.map +0 -1
- package/dist/types/src/blueprint/blueprint.test.d.ts +0 -2
- package/dist/types/src/blueprint/blueprint.test.d.ts.map +0 -1
- package/dist/types/src/blueprint/logger.d.ts +0 -25
- package/dist/types/src/blueprint/logger.d.ts.map +0 -1
- package/dist/types/src/blueprint/machine.d.ts +0 -143
- package/dist/types/src/blueprint/machine.d.ts.map +0 -1
- package/dist/types/src/blueprint/test-data.d.ts +0 -3
- package/dist/types/src/blueprint/test-data.d.ts.map +0 -1
- package/src/blueprint/ai.test.ts +0 -156
- package/src/blueprint/blueprint.test.ts +0 -151
- package/src/blueprint/logger.ts +0 -155
- package/src/blueprint/machine.ts +0 -251
- package/src/blueprint/test-data.ts +0 -55
package/src/session/session.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Option, Schema } from 'effect';
|
|
5
|
+
import { Array, Option, pipe, Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
AgentStatusReport,
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
ToolResult,
|
|
20
20
|
createTool,
|
|
21
21
|
type ExecutableTool,
|
|
22
|
+
type ToolId,
|
|
23
|
+
type ToolResolver,
|
|
22
24
|
} from '@dxos/ai';
|
|
23
25
|
import { type ArtifactDefinition } from '@dxos/artifact';
|
|
24
26
|
import { Event, synchronized } from '@dxos/async';
|
|
@@ -58,14 +60,12 @@ export type ArtifactDiffResolver = (artifacts: { id: ObjectId; lastVersion: Obje
|
|
|
58
60
|
>;
|
|
59
61
|
|
|
60
62
|
export type SessionRunOptions = {
|
|
61
|
-
client: AiServiceClient;
|
|
62
|
-
|
|
63
63
|
artifacts: ArtifactDefinition[];
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Non-artifact specific tools.
|
|
67
67
|
*/
|
|
68
|
-
tools:
|
|
68
|
+
tools: ToolId[];
|
|
69
69
|
|
|
70
70
|
history: Message[];
|
|
71
71
|
|
|
@@ -82,6 +82,14 @@ export type SessionRunOptions = {
|
|
|
82
82
|
*/
|
|
83
83
|
requiredArtifactIds?: string[];
|
|
84
84
|
|
|
85
|
+
client: AiServiceClient;
|
|
86
|
+
toolResolver: ToolResolver;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Executable tools that do not go through the tool resolver.
|
|
90
|
+
*/
|
|
91
|
+
executableTools?: ExecutableTool[];
|
|
92
|
+
|
|
85
93
|
/**
|
|
86
94
|
* @see ArtifactDiffResolver
|
|
87
95
|
*/
|
|
@@ -129,6 +137,9 @@ export class AISession {
|
|
|
129
137
|
*/
|
|
130
138
|
public readonly update = this._parser.update;
|
|
131
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Unparsed events from the underlying generation stream.
|
|
142
|
+
*/
|
|
132
143
|
public readonly streamEvent = this._parser.streamEvent;
|
|
133
144
|
|
|
134
145
|
/**
|
|
@@ -138,9 +149,19 @@ export class AISession {
|
|
|
138
149
|
|
|
139
150
|
/**
|
|
140
151
|
* Agent self-reporting its status.
|
|
152
|
+
* Triggered by the model.
|
|
141
153
|
*/
|
|
142
154
|
public readonly statusReport = new Event<AgentStatus>();
|
|
143
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Emits when the session is done.
|
|
158
|
+
*/
|
|
159
|
+
public readonly done = new Event<void>();
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Emits when the tool reports its status.
|
|
163
|
+
* Triggered by the tool execution function.
|
|
164
|
+
*/
|
|
144
165
|
public readonly toolStatusReport = new Event<{ message: Message; status: AgentStatus }>();
|
|
145
166
|
|
|
146
167
|
constructor(private readonly _options: AiSessionOptions) {
|
|
@@ -155,6 +176,11 @@ export class AISession {
|
|
|
155
176
|
});
|
|
156
177
|
}
|
|
157
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Runs the AI model loop interacting with tools and artifacts.
|
|
181
|
+
* @param options - The session options.
|
|
182
|
+
* @returns The messages generated by the session, including the user's prompt.
|
|
183
|
+
*/
|
|
158
184
|
@synchronized
|
|
159
185
|
async run(options: SessionRunOptions): Promise<Message[]> {
|
|
160
186
|
const systemTools: ExecutableTool[] = [];
|
|
@@ -190,13 +216,17 @@ export class AISession {
|
|
|
190
216
|
try {
|
|
191
217
|
let more = false;
|
|
192
218
|
do {
|
|
193
|
-
const tools: ExecutableTool[] =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
.
|
|
198
|
-
.
|
|
199
|
-
|
|
219
|
+
const tools: ExecutableTool[] = pipe(
|
|
220
|
+
[
|
|
221
|
+
...systemTools,
|
|
222
|
+
...(await Promise.all(options.tools.map((toolId) => options.toolResolver.resolve(toolId)))),
|
|
223
|
+
...(options.executableTools ?? []),
|
|
224
|
+
...options.artifacts
|
|
225
|
+
.filter((artifact) => requiredArtifactIds.has(artifact.id))
|
|
226
|
+
.flatMap((artifact) => artifact.tools),
|
|
227
|
+
],
|
|
228
|
+
Array.dedupeWith((a, b) => a.id === b.id),
|
|
229
|
+
);
|
|
200
230
|
|
|
201
231
|
log('request', {
|
|
202
232
|
pending: this._pending.length,
|
|
@@ -213,7 +243,7 @@ export class AISession {
|
|
|
213
243
|
systemPrompt:
|
|
214
244
|
options.systemPrompt ??
|
|
215
245
|
createBaseInstructions({
|
|
216
|
-
availableArtifacts:
|
|
246
|
+
availableArtifacts: [...requiredArtifactIds],
|
|
217
247
|
operationModel: this._options.operationModel,
|
|
218
248
|
}),
|
|
219
249
|
});
|
|
@@ -258,6 +288,7 @@ export class AISession {
|
|
|
258
288
|
}
|
|
259
289
|
} finally {
|
|
260
290
|
this._stream = undefined;
|
|
291
|
+
this.done.emit();
|
|
261
292
|
}
|
|
262
293
|
|
|
263
294
|
if (error) {
|
|
@@ -274,7 +305,7 @@ export class AISession {
|
|
|
274
305
|
const parser = structuredOutputParser(schema);
|
|
275
306
|
const result = await this.run({
|
|
276
307
|
...options,
|
|
277
|
-
|
|
308
|
+
executableTools: [...(options.executableTools ?? []), parser.tool],
|
|
278
309
|
});
|
|
279
310
|
return parser.getResult(result);
|
|
280
311
|
}
|
|
@@ -290,7 +321,7 @@ export class AISession {
|
|
|
290
321
|
const versions = gatherObjectVersions(history);
|
|
291
322
|
|
|
292
323
|
const artifactDiff = await artifactDiffResolver(
|
|
293
|
-
|
|
324
|
+
[...versions.entries()].map(([id, version]) => ({ id, lastVersion: version })),
|
|
294
325
|
);
|
|
295
326
|
|
|
296
327
|
log.info('vision', {
|
|
@@ -409,14 +440,11 @@ export class AISession {
|
|
|
409
440
|
session.userMessage.on((ev) => this.userMessage.emit(ev));
|
|
410
441
|
|
|
411
442
|
const messages = await session.run({
|
|
412
|
-
client: options.client,
|
|
413
443
|
artifacts: options.artifacts,
|
|
414
444
|
tools: options.tools,
|
|
415
445
|
history: options.history,
|
|
416
446
|
extensions: options.extensions,
|
|
417
|
-
generationOptions: options.generationOptions,
|
|
418
447
|
requiredArtifactIds: step.requiredArtifactIds.slice(),
|
|
419
|
-
artifactDiffResolver: options.artifactDiffResolver,
|
|
420
448
|
prompt: `
|
|
421
449
|
You are an agent that executes the subtask in a plan.
|
|
422
450
|
|
|
@@ -439,6 +467,11 @@ export class AISession {
|
|
|
439
467
|
Previous step results:
|
|
440
468
|
${JSON.stringify(stepResults.at(-1))}.
|
|
441
469
|
`,
|
|
470
|
+
|
|
471
|
+
generationOptions: options.generationOptions,
|
|
472
|
+
client: options.client,
|
|
473
|
+
toolResolver: options.toolResolver,
|
|
474
|
+
artifactDiffResolver: options.artifactDiffResolver,
|
|
442
475
|
});
|
|
443
476
|
const result = messages.at(-1);
|
|
444
477
|
stepResults.push(result);
|
|
@@ -541,7 +574,7 @@ const createArtifactUpdateBlock = (
|
|
|
541
574
|
disposition: 'artifact-update',
|
|
542
575
|
text: `
|
|
543
576
|
The following artifacts have been updated since the last message:
|
|
544
|
-
${
|
|
577
|
+
${[...artifactDiff.entries()]
|
|
545
578
|
.map(([id, { diff }]) => `<changed-artifact id="${id}">${diff ? `\n${diff}` : ''}</changed-artifact>`)
|
|
546
579
|
.join('\n')}
|
|
547
580
|
`,
|