@dxos/assistant 0.8.2-main.f081794 → 0.8.2-main.f11618f
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 +270 -150
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +7 -7
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +266 -149
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +8 -8
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +270 -150
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +7 -7
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/session/index.d.ts +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +29 -4
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +17 -0
- package/dist/types/src/session/version-pin.d.ts.map +1 -0
- package/dist/types/src/session/version-pin.test.d.ts +2 -0
- package/dist/types/src/session/version-pin.test.d.ts.map +1 -0
- package/dist/types/src/testing/test-schema.d.ts +2 -2
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/bin/chat.ts +2 -2
- package/src/cypher/combinators.test.ts +4 -4
- package/src/cypher/execution-plan.test.ts +1 -1
- package/src/cypher/query-executor.test.ts +1 -1
- package/src/cypher/schema.test.ts +3 -3
- package/src/session/index.ts +1 -0
- package/src/session/session.test.ts +2 -1
- package/src/session/session.ts +283 -147
- package/src/session/version-pin.test.ts +26 -0
- package/src/session/version-pin.ts +43 -0
- package/src/testing/query.test.ts +3 -3
- package/src/testing/test-data.ts +5 -5
- package/src/testing/test-schema.ts +3 -3
package/dist/lib/node/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(node_exports, {
|
|
|
36
36
|
OllamaClient: () => import_chunk_7VH7NMIM.OllamaClient,
|
|
37
37
|
StreamTransform: () => import_chunk_7VH7NMIM.StreamTransform,
|
|
38
38
|
ToolTypes: () => import_chunk_7VH7NMIM.ToolTypes,
|
|
39
|
+
VersionPin: () => VersionPin,
|
|
39
40
|
createArtifactElement: () => import_chunk_7VH7NMIM.createArtifactElement,
|
|
40
41
|
createGenerationStream: () => import_chunk_7VH7NMIM.createGenerationStream,
|
|
41
42
|
emitMessageAsEvents: () => import_chunk_7VH7NMIM.emitMessageAsEvents,
|
|
@@ -56,9 +57,38 @@ var import_chunk_7VH7NMIM = require("./chunk-7VH7NMIM.cjs");
|
|
|
56
57
|
var import_effect = require("effect");
|
|
57
58
|
var import_artifact = require("@dxos/artifact");
|
|
58
59
|
var import_async = require("@dxos/async");
|
|
60
|
+
var import_echo_db = require("@dxos/echo-db");
|
|
59
61
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
60
62
|
var import_invariant = require("@dxos/invariant");
|
|
61
63
|
var import_log = require("@dxos/log");
|
|
64
|
+
var import_effect2 = require("effect");
|
|
65
|
+
var import_echo_db2 = require("@dxos/echo-db");
|
|
66
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
67
|
+
var ObjectVersionSchema = import_effect2.Schema.Unknown;
|
|
68
|
+
var VersionPinSchema = import_effect2.Schema.Struct({
|
|
69
|
+
// TODO(dmaretskyi): Use Ref when those support encoding.
|
|
70
|
+
objectId: import_echo_schema2.ObjectId,
|
|
71
|
+
// TODO(dmaretskyi): Could be opaque
|
|
72
|
+
version: ObjectVersionSchema
|
|
73
|
+
});
|
|
74
|
+
var VersionPin = class extends VersionPinSchema {
|
|
75
|
+
static {
|
|
76
|
+
this.DISPOSITION = "version-pin";
|
|
77
|
+
}
|
|
78
|
+
static fromObject(object) {
|
|
79
|
+
return VersionPin.make({
|
|
80
|
+
objectId: object.id,
|
|
81
|
+
version: (0, import_echo_db2.getVersion)(object)
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
static createBlock(pin) {
|
|
85
|
+
return {
|
|
86
|
+
type: "json",
|
|
87
|
+
disposition: VersionPin.DISPOSITION,
|
|
88
|
+
json: JSON.stringify(pin)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
62
92
|
function _ts_decorate(decorators, target, key, desc) {
|
|
63
93
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
64
94
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -82,152 +112,28 @@ var AISession = class _AISession {
|
|
|
82
112
|
});
|
|
83
113
|
}
|
|
84
114
|
async run(options) {
|
|
85
|
-
const systemTools = [
|
|
86
|
-
(0, import_artifact.defineTool)("system", {
|
|
87
|
-
name: "query_artifact_definitions",
|
|
88
|
-
description: "Query the available artifact definitions",
|
|
89
|
-
schema: import_effect.Schema.Struct({}),
|
|
90
|
-
execute: async () => {
|
|
91
|
-
return import_artifact.ToolResult.Success({
|
|
92
|
-
artifactDefinitions: options.artifacts.map((artifact) => ({
|
|
93
|
-
id: artifact.id,
|
|
94
|
-
name: artifact.name,
|
|
95
|
-
description: artifact.description
|
|
96
|
-
}))
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
})
|
|
100
|
-
];
|
|
115
|
+
const systemTools = [];
|
|
101
116
|
switch (this._options.operationModel) {
|
|
102
117
|
case "planning":
|
|
103
|
-
systemTools.push((
|
|
104
|
-
name: "create_plan",
|
|
105
|
-
description: "Create a plan. Make sure that each step is independent and can be executed solely on the data returned by the previous step. The steps only share the data that is specified in the plan.",
|
|
106
|
-
schema: import_effect.Schema.Struct({
|
|
107
|
-
goal: import_effect.Schema.String.annotations({
|
|
108
|
-
description: "The goal that the plan will achieve."
|
|
109
|
-
}),
|
|
110
|
-
steps: import_effect.Schema.Array(import_effect.Schema.Struct({
|
|
111
|
-
action: import_effect.Schema.String.annotations({
|
|
112
|
-
description: "Complete, detailed action to perform."
|
|
113
|
-
}),
|
|
114
|
-
input: import_effect.Schema.String.annotations({
|
|
115
|
-
description: "The required input data for this step. First step must not require any data."
|
|
116
|
-
}),
|
|
117
|
-
output: import_effect.Schema.String.annotations({
|
|
118
|
-
description: "The output data from this step. This is passed to the next step as input."
|
|
119
|
-
}),
|
|
120
|
-
requiredArtifactIds: import_effect.Schema.Array(import_effect.Schema.String).annotations({
|
|
121
|
-
description: "The ids of the artifacts required to perform this step.",
|
|
122
|
-
examples: [
|
|
123
|
-
[
|
|
124
|
-
"artifact:dxos.org/example/Test"
|
|
125
|
-
]
|
|
126
|
-
]
|
|
127
|
-
})
|
|
128
|
-
})).annotations({
|
|
129
|
-
description: "Steps"
|
|
130
|
-
})
|
|
131
|
-
}),
|
|
132
|
-
execute: async ({ goal, steps }) => {
|
|
133
|
-
const missingArtifactIds = steps.flatMap((step) => step.requiredArtifactIds).filter((artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId));
|
|
134
|
-
if (missingArtifactIds.length > 0) {
|
|
135
|
-
return import_artifact.ToolResult.Error(`One or more artifact ids are invalid: ${missingArtifactIds.join(", ")}`);
|
|
136
|
-
}
|
|
137
|
-
const stepResults = [];
|
|
138
|
-
for (const step of steps) {
|
|
139
|
-
(0, import_log.log)("executing step", {
|
|
140
|
-
action: step.action
|
|
141
|
-
}, {
|
|
142
|
-
F: __dxlog_file,
|
|
143
|
-
L: 160,
|
|
144
|
-
S: this,
|
|
145
|
-
C: (f, a) => f(...a)
|
|
146
|
-
});
|
|
147
|
-
const session = new _AISession({
|
|
148
|
-
operationModel: "immediate"
|
|
149
|
-
});
|
|
150
|
-
session.message.on((ev) => this.message.emit(ev));
|
|
151
|
-
session.block.on((ev) => this.block.emit(ev));
|
|
152
|
-
session.update.on((ev) => this.update.emit(ev));
|
|
153
|
-
session.streamEvent.on((ev) => this.streamEvent.emit(ev));
|
|
154
|
-
session.userMessage.on((ev) => this.userMessage.emit(ev));
|
|
155
|
-
const messages = await session.run({
|
|
156
|
-
client: options.client,
|
|
157
|
-
artifacts: options.artifacts,
|
|
158
|
-
tools: options.tools,
|
|
159
|
-
history: options.history,
|
|
160
|
-
extensions: options.extensions,
|
|
161
|
-
generationOptions: options.generationOptions,
|
|
162
|
-
requiredArtifactIds: step.requiredArtifactIds.slice(),
|
|
163
|
-
prompt: `
|
|
164
|
-
You are an agent that executes the subtask in a plan.
|
|
165
|
-
|
|
166
|
-
While you know the plan's goal only focus on your subtask
|
|
167
|
-
Use the data from the previous step to complete your task.
|
|
168
|
-
Return all of the data from "output" in your last message.
|
|
169
|
-
|
|
170
|
-
Current step (that you need to complete):
|
|
171
|
-
${JSON.stringify({
|
|
172
|
-
goal,
|
|
173
|
-
input: step.input,
|
|
174
|
-
output: step.output,
|
|
175
|
-
yourTask: step.action
|
|
176
|
-
}, null, 2)}
|
|
177
|
-
|
|
178
|
-
Previous step results:
|
|
179
|
-
${JSON.stringify(stepResults.at(-1))}.
|
|
180
|
-
`
|
|
181
|
-
});
|
|
182
|
-
const result = messages.at(-1);
|
|
183
|
-
stepResults.push(result);
|
|
184
|
-
}
|
|
185
|
-
return import_artifact.ToolResult.Success({
|
|
186
|
-
stepResults
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}));
|
|
118
|
+
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createPlanningTool(options));
|
|
190
119
|
break;
|
|
191
|
-
case "
|
|
192
|
-
systemTools.push((
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
schema: import_effect.Schema.Struct({
|
|
196
|
-
artifactDefinitionIds: import_effect.Schema.Array(import_effect.Schema.String).annotations({
|
|
197
|
-
description: "The ids of the artifact definitions to require",
|
|
198
|
-
examples: [
|
|
199
|
-
[
|
|
200
|
-
"artifact:dxos.org/example/Test"
|
|
201
|
-
]
|
|
202
|
-
]
|
|
203
|
-
})
|
|
204
|
-
}),
|
|
205
|
-
execute: async ({ artifactDefinitionIds }) => {
|
|
206
|
-
const missingArtifactDefinitionIds = artifactDefinitionIds.filter((artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId));
|
|
207
|
-
if (missingArtifactDefinitionIds.length > 0) {
|
|
208
|
-
return import_artifact.ToolResult.Error(`One or more artifact definition ids are invalid: ${missingArtifactDefinitionIds.join(", ")}`);
|
|
209
|
-
}
|
|
210
|
-
for (const artifactDefinitionId of artifactDefinitionIds) {
|
|
211
|
-
requiredArtifactIds.add(artifactDefinitionId);
|
|
212
|
-
}
|
|
213
|
-
return import_artifact.ToolResult.Success({});
|
|
120
|
+
case "importing":
|
|
121
|
+
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createRequireTool(options.artifacts, (artifactDefinitionIds) => {
|
|
122
|
+
for (const artifactDefinitionId of artifactDefinitionIds) {
|
|
123
|
+
requiredArtifactIds.add(artifactDefinitionId);
|
|
214
124
|
}
|
|
215
125
|
}));
|
|
216
126
|
break;
|
|
127
|
+
case "configured":
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
throw new TypeError(`Invalid operation model: ${this._options.operationModel}`);
|
|
217
131
|
}
|
|
218
132
|
this._history = [
|
|
219
133
|
...options.history
|
|
220
134
|
];
|
|
221
135
|
this._pending = [
|
|
222
|
-
|
|
223
|
-
role: "user",
|
|
224
|
-
content: [
|
|
225
|
-
{
|
|
226
|
-
type: "text",
|
|
227
|
-
text: options.prompt
|
|
228
|
-
}
|
|
229
|
-
]
|
|
230
|
-
})
|
|
136
|
+
await this._formatUserPrompt(options.artifactDiffResolver, options.prompt, options.history)
|
|
231
137
|
];
|
|
232
138
|
this.userMessage.emit(this._pending.at(-1));
|
|
233
139
|
this._stream = void 0;
|
|
@@ -247,7 +153,7 @@ var AISession = class _AISession {
|
|
|
247
153
|
tools: tools.map((tool) => tool.name)
|
|
248
154
|
}, {
|
|
249
155
|
F: __dxlog_file,
|
|
250
|
-
L:
|
|
156
|
+
L: 180,
|
|
251
157
|
S: this,
|
|
252
158
|
C: (f, a) => f(...a)
|
|
253
159
|
});
|
|
@@ -270,7 +176,7 @@ var AISession = class _AISession {
|
|
|
270
176
|
pending: this._pending
|
|
271
177
|
}, {
|
|
272
178
|
F: __dxlog_file,
|
|
273
|
-
L:
|
|
179
|
+
L: 205,
|
|
274
180
|
S: this,
|
|
275
181
|
C: (f, a) => f(...a)
|
|
276
182
|
});
|
|
@@ -278,7 +184,7 @@ var AISession = class _AISession {
|
|
|
278
184
|
const message = this._pending.at(-1);
|
|
279
185
|
(0, import_invariant.invariant)(message, void 0, {
|
|
280
186
|
F: __dxlog_file,
|
|
281
|
-
L:
|
|
187
|
+
L: 210,
|
|
282
188
|
S: this,
|
|
283
189
|
A: [
|
|
284
190
|
"message",
|
|
@@ -288,7 +194,7 @@ var AISession = class _AISession {
|
|
|
288
194
|
if ((0, import_chunk_7VH7NMIM.isToolUse)(message)) {
|
|
289
195
|
(0, import_log.log)("tool request...", void 0, {
|
|
290
196
|
F: __dxlog_file,
|
|
291
|
-
L:
|
|
197
|
+
L: 212,
|
|
292
198
|
S: this,
|
|
293
199
|
C: (f, a) => f(...a)
|
|
294
200
|
});
|
|
@@ -301,7 +207,7 @@ var AISession = class _AISession {
|
|
|
301
207
|
response
|
|
302
208
|
}, {
|
|
303
209
|
F: __dxlog_file,
|
|
304
|
-
L:
|
|
210
|
+
L: 219,
|
|
305
211
|
S: this,
|
|
306
212
|
C: (f, a) => f(...a)
|
|
307
213
|
});
|
|
@@ -321,7 +227,7 @@ var AISession = class _AISession {
|
|
|
321
227
|
} catch (err) {
|
|
322
228
|
import_log.log.catch(err, void 0, {
|
|
323
229
|
F: __dxlog_file,
|
|
324
|
-
L:
|
|
230
|
+
L: 231,
|
|
325
231
|
S: this,
|
|
326
232
|
C: (f, a) => f(...a)
|
|
327
233
|
});
|
|
@@ -342,6 +248,180 @@ var AISession = class _AISession {
|
|
|
342
248
|
}
|
|
343
249
|
return this._pending;
|
|
344
250
|
}
|
|
251
|
+
async _formatUserPrompt(artifactDiffResolver, prompt, history) {
|
|
252
|
+
const prelude = [];
|
|
253
|
+
if (artifactDiffResolver) {
|
|
254
|
+
const versions = gatherObjectVersions(history);
|
|
255
|
+
const artifactDiff = await artifactDiffResolver(Array.from(versions.entries()).map(([id, version]) => ({
|
|
256
|
+
id,
|
|
257
|
+
lastVersion: version
|
|
258
|
+
})));
|
|
259
|
+
import_log.log.info("vision", {
|
|
260
|
+
artifactDiff,
|
|
261
|
+
versions
|
|
262
|
+
}, {
|
|
263
|
+
F: __dxlog_file,
|
|
264
|
+
L: 262,
|
|
265
|
+
S: this,
|
|
266
|
+
C: (f, a) => f(...a)
|
|
267
|
+
});
|
|
268
|
+
for (const [id, { version }] of [
|
|
269
|
+
...artifactDiff.entries()
|
|
270
|
+
]) {
|
|
271
|
+
if (import_echo_db.ObjectVersion.equals(version, versions.get(id))) {
|
|
272
|
+
artifactDiff.delete(id);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
prelude.push(VersionPin.createBlock(VersionPin.make({
|
|
276
|
+
objectId: id,
|
|
277
|
+
version
|
|
278
|
+
})));
|
|
279
|
+
}
|
|
280
|
+
if (artifactDiff.size > 0) {
|
|
281
|
+
prelude.push(createArtifactUpdateBlock(artifactDiff));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return (0, import_echo_schema.create)(import_artifact.Message, {
|
|
285
|
+
role: "user",
|
|
286
|
+
content: [
|
|
287
|
+
...prelude,
|
|
288
|
+
{
|
|
289
|
+
type: "text",
|
|
290
|
+
text: prompt
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
_createQueryArtifactsTool(artifacts) {
|
|
296
|
+
return (0, import_artifact.defineTool)("system", {
|
|
297
|
+
name: "query_artifact_definitions",
|
|
298
|
+
description: "Query the available artifact definitions",
|
|
299
|
+
schema: import_effect.Schema.Struct({}),
|
|
300
|
+
execute: async () => {
|
|
301
|
+
return import_artifact.ToolResult.Success({
|
|
302
|
+
artifactDefinitions: artifacts.map((artifact) => ({
|
|
303
|
+
id: artifact.id,
|
|
304
|
+
name: artifact.name,
|
|
305
|
+
description: artifact.description
|
|
306
|
+
}))
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
_createRequireTool(artifacts, onRequire) {
|
|
312
|
+
return (0, import_artifact.defineTool)("system", {
|
|
313
|
+
name: "require_artifact_definitions",
|
|
314
|
+
description: "Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.",
|
|
315
|
+
schema: import_effect.Schema.Struct({
|
|
316
|
+
artifactDefinitionIds: import_effect.Schema.Array(import_effect.Schema.String).annotations({
|
|
317
|
+
description: "The ids of the artifact definitions to require",
|
|
318
|
+
examples: [
|
|
319
|
+
[
|
|
320
|
+
"artifact:dxos.org/example/Test"
|
|
321
|
+
]
|
|
322
|
+
]
|
|
323
|
+
})
|
|
324
|
+
}),
|
|
325
|
+
execute: async ({ artifactDefinitionIds }) => {
|
|
326
|
+
const missingArtifactDefinitionIds = artifactDefinitionIds.filter((artifactId) => !artifacts.some((artifact) => artifact.id === artifactId));
|
|
327
|
+
if (missingArtifactDefinitionIds.length > 0) {
|
|
328
|
+
return import_artifact.ToolResult.Error(`One or more artifact definition ids are invalid: ${missingArtifactDefinitionIds.join(", ")}`);
|
|
329
|
+
}
|
|
330
|
+
onRequire(artifactDefinitionIds);
|
|
331
|
+
return import_artifact.ToolResult.Success({});
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
_createPlanningTool(options) {
|
|
336
|
+
return (0, import_artifact.defineTool)("system", {
|
|
337
|
+
name: "create_plan",
|
|
338
|
+
description: "Create a plan. Make sure that each step is independent and can be executed solely on the data returned by the previous step. The steps only share the data that is specified in the plan.",
|
|
339
|
+
schema: import_effect.Schema.Struct({
|
|
340
|
+
goal: import_effect.Schema.String.annotations({
|
|
341
|
+
description: "The goal that the plan will achieve."
|
|
342
|
+
}),
|
|
343
|
+
steps: import_effect.Schema.Array(import_effect.Schema.Struct({
|
|
344
|
+
action: import_effect.Schema.String.annotations({
|
|
345
|
+
description: "Complete, detailed action to perform."
|
|
346
|
+
}),
|
|
347
|
+
input: import_effect.Schema.String.annotations({
|
|
348
|
+
description: "The required input data for this step. First step must not require any data."
|
|
349
|
+
}),
|
|
350
|
+
output: import_effect.Schema.String.annotations({
|
|
351
|
+
description: "The output data from this step. This is passed to the next step as input."
|
|
352
|
+
}),
|
|
353
|
+
requiredArtifactIds: import_effect.Schema.Array(import_effect.Schema.String).annotations({
|
|
354
|
+
description: "The ids of the artifacts required to perform this step.",
|
|
355
|
+
examples: [
|
|
356
|
+
[
|
|
357
|
+
"artifact:dxos.org/example/Test"
|
|
358
|
+
]
|
|
359
|
+
]
|
|
360
|
+
})
|
|
361
|
+
})).annotations({
|
|
362
|
+
description: "Steps"
|
|
363
|
+
})
|
|
364
|
+
}),
|
|
365
|
+
execute: async ({ goal, steps }) => {
|
|
366
|
+
const missingArtifactIds = steps.flatMap((step) => step.requiredArtifactIds).filter((artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId));
|
|
367
|
+
if (missingArtifactIds.length > 0) {
|
|
368
|
+
return import_artifact.ToolResult.Error(`One or more artifact ids are invalid: ${missingArtifactIds.join(", ")}`);
|
|
369
|
+
}
|
|
370
|
+
const stepResults = [];
|
|
371
|
+
for (const step of steps) {
|
|
372
|
+
(0, import_log.log)("executing step", {
|
|
373
|
+
action: step.action
|
|
374
|
+
}, {
|
|
375
|
+
F: __dxlog_file,
|
|
376
|
+
L: 369,
|
|
377
|
+
S: this,
|
|
378
|
+
C: (f, a) => f(...a)
|
|
379
|
+
});
|
|
380
|
+
const session = new _AISession({
|
|
381
|
+
operationModel: "importing"
|
|
382
|
+
});
|
|
383
|
+
session.message.on((ev) => this.message.emit(ev));
|
|
384
|
+
session.block.on((ev) => this.block.emit(ev));
|
|
385
|
+
session.update.on((ev) => this.update.emit(ev));
|
|
386
|
+
session.streamEvent.on((ev) => this.streamEvent.emit(ev));
|
|
387
|
+
session.userMessage.on((ev) => this.userMessage.emit(ev));
|
|
388
|
+
const messages = await session.run({
|
|
389
|
+
client: options.client,
|
|
390
|
+
artifacts: options.artifacts,
|
|
391
|
+
tools: options.tools,
|
|
392
|
+
history: options.history,
|
|
393
|
+
extensions: options.extensions,
|
|
394
|
+
generationOptions: options.generationOptions,
|
|
395
|
+
requiredArtifactIds: step.requiredArtifactIds.slice(),
|
|
396
|
+
artifactDiffResolver: options.artifactDiffResolver,
|
|
397
|
+
prompt: `
|
|
398
|
+
You are an agent that executes the subtask in a plan.
|
|
399
|
+
|
|
400
|
+
While you know the plan's goal only focus on your subtask
|
|
401
|
+
Use the data from the previous step to complete your task.
|
|
402
|
+
Return all of the data from "output" in your last message.
|
|
403
|
+
|
|
404
|
+
Current step (that you need to complete):
|
|
405
|
+
${JSON.stringify({
|
|
406
|
+
goal,
|
|
407
|
+
input: step.input,
|
|
408
|
+
output: step.output,
|
|
409
|
+
yourTask: step.action
|
|
410
|
+
}, null, 2)}
|
|
411
|
+
|
|
412
|
+
Previous step results:
|
|
413
|
+
${JSON.stringify(stepResults.at(-1))}.
|
|
414
|
+
`
|
|
415
|
+
});
|
|
416
|
+
const result = messages.at(-1);
|
|
417
|
+
stepResults.push(result);
|
|
418
|
+
}
|
|
419
|
+
return import_artifact.ToolResult.Success({
|
|
420
|
+
stepResults
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
}
|
|
345
425
|
abort() {
|
|
346
426
|
this._stream?.abort();
|
|
347
427
|
}
|
|
@@ -359,21 +439,57 @@ var createBaseInstructions = ({ availableArtifacts, operationModel }) => `
|
|
|
359
439
|
Decision-making:
|
|
360
440
|
|
|
361
441
|
- Analyze the structure and type of the content in the user's message.
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
- Identify which artifacts are relevant to the user's request.
|
|
442
|
+
|
|
443
|
+
|
|
365
444
|
${operationModel === "planning" ? `
|
|
445
|
+
- Can you complete the task using the available artifacts?
|
|
446
|
+
- If you can't complete the task using the available artifacts, query the list of available artifacts using the appropriate tool.
|
|
447
|
+
- Identify which artifacts are relevant to the user's request.
|
|
366
448
|
- Break down the user's request into a step-by-step plan that you will use to execute the user's request, the plan items should include artifacts which will be used to perform the actions.
|
|
367
|
-
` :
|
|
368
|
-
|
|
369
|
-
-
|
|
370
|
-
-
|
|
371
|
-
|
|
449
|
+
` : ""}
|
|
450
|
+
${operationModel === "importing" ? `
|
|
451
|
+
- Can you complete the task using the available artifacts?
|
|
452
|
+
- If you can't complete the task using the available artifacts, query the list of available artifacts using the appropriate tool.
|
|
453
|
+
- Identify which artifacts are relevant to the user's request.
|
|
454
|
+
- Are the required artifacts already available?
|
|
455
|
+
- If not, select which artifact(s) will be the most relevant and require them using the require_artifacts tool.
|
|
456
|
+
- The require'd artifact tools will be available for use after require.
|
|
457
|
+
` : ""}
|
|
458
|
+
${operationModel === "configured" ? `
|
|
459
|
+
- Select the most relevant artifact(s) to complete the task.
|
|
460
|
+
- Call the appropriate tool to use the artifact(s).
|
|
461
|
+
` : ""}
|
|
372
462
|
|
|
373
463
|
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join("\n")}` : ""}
|
|
374
464
|
`;
|
|
375
465
|
var AIServiecOverloadedError = class extends import_effect.Schema.TaggedError()("AIServiecOverloadedError", {}) {
|
|
376
466
|
};
|
|
467
|
+
var gatherObjectVersions = (messages) => {
|
|
468
|
+
const artifactIds = /* @__PURE__ */ new Map();
|
|
469
|
+
for (const message of messages) {
|
|
470
|
+
for (const block of message.content) {
|
|
471
|
+
if (block.type === "json" && block.disposition === VersionPin.DISPOSITION) {
|
|
472
|
+
const pin = VersionPin.pipe(import_effect.Schema.decodeOption)(JSON.parse(block.json)).pipe(import_effect.Option.getOrUndefined);
|
|
473
|
+
if (!pin) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
artifactIds.set(pin.objectId, pin.version);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return artifactIds;
|
|
481
|
+
};
|
|
482
|
+
var createArtifactUpdateBlock = (artifactDiff) => {
|
|
483
|
+
return {
|
|
484
|
+
type: "text",
|
|
485
|
+
disposition: "artifact-update",
|
|
486
|
+
text: `
|
|
487
|
+
The following artifacts have been updated since the last message:
|
|
488
|
+
${Array.from(artifactDiff.entries()).map(([id, { diff }]) => `<changed-artifact id="${id}">${diff ? `
|
|
489
|
+
${diff}` : ""}</changed-artifact>`).join("\n")}
|
|
490
|
+
`
|
|
491
|
+
};
|
|
492
|
+
};
|
|
377
493
|
// Annotate the CommonJS export names for ESM import in node:
|
|
378
494
|
0 && (module.exports = {
|
|
379
495
|
AIServiceEdgeClient,
|
|
@@ -394,6 +510,7 @@ var AIServiecOverloadedError = class extends import_effect.Schema.TaggedError()(
|
|
|
394
510
|
OllamaClient,
|
|
395
511
|
StreamTransform,
|
|
396
512
|
ToolTypes,
|
|
513
|
+
VersionPin,
|
|
397
514
|
createArtifactElement,
|
|
398
515
|
createGenerationStream,
|
|
399
516
|
emitMessageAsEvents,
|