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