@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
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,77 +18,46 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var node_exports = {};
|
|
20
20
|
__export(node_exports, {
|
|
21
|
-
AIServiceEdgeClient: () =>
|
|
21
|
+
AIServiceEdgeClient: () => import_chunk_IBOBRBDF.AIServiceEdgeClient,
|
|
22
22
|
AIServiecOverloadedError: () => AIServiecOverloadedError,
|
|
23
23
|
AISession: () => AISession,
|
|
24
|
-
DEFAULT_EDGE_MODEL: () =>
|
|
25
|
-
DEFAULT_EDGE_MODELS: () =>
|
|
26
|
-
DEFAULT_OLLAMA_ENDPOINT: () =>
|
|
27
|
-
DEFAULT_OLLAMA_MODEL: () =>
|
|
28
|
-
DEFAULT_OLLAMA_MODELS: () =>
|
|
29
|
-
EchoDataSource: () =>
|
|
30
|
-
GenerateRequest: () =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
runLLM: () => import_chunk_7VH7NMIM.runLLM,
|
|
53
|
-
runTools: () => import_chunk_7VH7NMIM.runTools
|
|
24
|
+
DEFAULT_EDGE_MODEL: () => import_chunk_IBOBRBDF.DEFAULT_EDGE_MODEL,
|
|
25
|
+
DEFAULT_EDGE_MODELS: () => import_chunk_IBOBRBDF.DEFAULT_EDGE_MODELS,
|
|
26
|
+
DEFAULT_OLLAMA_ENDPOINT: () => import_chunk_IBOBRBDF.DEFAULT_OLLAMA_ENDPOINT,
|
|
27
|
+
DEFAULT_OLLAMA_MODEL: () => import_chunk_IBOBRBDF.DEFAULT_OLLAMA_MODEL,
|
|
28
|
+
DEFAULT_OLLAMA_MODELS: () => import_chunk_IBOBRBDF.DEFAULT_OLLAMA_MODELS,
|
|
29
|
+
EchoDataSource: () => import_chunk_IBOBRBDF.EchoDataSource,
|
|
30
|
+
GenerateRequest: () => import_chunk_IBOBRBDF.GenerateRequest,
|
|
31
|
+
GenerationStreamImpl: () => import_chunk_IBOBRBDF.GenerationStreamImpl,
|
|
32
|
+
LLMModel: () => import_chunk_IBOBRBDF.LLMModel,
|
|
33
|
+
MessageCollector: () => import_chunk_IBOBRBDF.MessageCollector,
|
|
34
|
+
MixedStreamParser: () => import_chunk_IBOBRBDF.MixedStreamParser,
|
|
35
|
+
OllamaClient: () => import_chunk_IBOBRBDF.OllamaClient,
|
|
36
|
+
StreamTransform: () => import_chunk_IBOBRBDF.StreamTransform,
|
|
37
|
+
ToolTypes: () => import_chunk_IBOBRBDF.ToolTypes,
|
|
38
|
+
createArtifactElement: () => import_chunk_IBOBRBDF.createArtifactElement,
|
|
39
|
+
createGenerationStream: () => import_chunk_IBOBRBDF.createGenerationStream,
|
|
40
|
+
emitMessageAsEvents: () => import_chunk_IBOBRBDF.emitMessageAsEvents,
|
|
41
|
+
executeQuery: () => import_chunk_IBOBRBDF.executeQuery,
|
|
42
|
+
executeQueryPlan: () => import_chunk_IBOBRBDF.executeQueryPlan,
|
|
43
|
+
formatInferredRelationshipLabel: () => import_chunk_IBOBRBDF.formatInferredRelationshipLabel,
|
|
44
|
+
formatJsonSchemaForLLM: () => import_chunk_IBOBRBDF.formatJsonSchemaForLLM,
|
|
45
|
+
formatNodeLabel: () => import_chunk_IBOBRBDF.formatNodeLabel,
|
|
46
|
+
isReference: () => import_chunk_IBOBRBDF.isReference,
|
|
47
|
+
isToolUse: () => import_chunk_IBOBRBDF.isToolUse,
|
|
48
|
+
mergeMessageBlock: () => import_chunk_IBOBRBDF.mergeMessageBlock,
|
|
49
|
+
parseCypherQuery: () => import_chunk_IBOBRBDF.parseCypherQuery,
|
|
50
|
+
runLLM: () => import_chunk_IBOBRBDF.runLLM,
|
|
51
|
+
runTools: () => import_chunk_IBOBRBDF.runTools
|
|
54
52
|
});
|
|
55
53
|
module.exports = __toCommonJS(node_exports);
|
|
56
|
-
var
|
|
54
|
+
var import_chunk_IBOBRBDF = require("./chunk-IBOBRBDF.cjs");
|
|
57
55
|
var import_effect = require("effect");
|
|
58
56
|
var import_artifact = require("@dxos/artifact");
|
|
59
57
|
var import_async = require("@dxos/async");
|
|
60
|
-
var import_echo_db = require("@dxos/echo-db");
|
|
61
58
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
62
59
|
var import_invariant = require("@dxos/invariant");
|
|
63
60
|
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
|
-
};
|
|
92
61
|
function _ts_decorate(decorators, target, key, desc) {
|
|
93
62
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
94
63
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -99,7 +68,7 @@ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/experimental/assistant/
|
|
|
99
68
|
var AISession = class _AISession {
|
|
100
69
|
constructor(_options) {
|
|
101
70
|
this._options = _options;
|
|
102
|
-
this._parser = new
|
|
71
|
+
this._parser = new import_chunk_IBOBRBDF.MixedStreamParser();
|
|
103
72
|
this._pending = [];
|
|
104
73
|
this._history = [];
|
|
105
74
|
this.message = this._parser.message;
|
|
@@ -112,28 +81,152 @@ var AISession = class _AISession {
|
|
|
112
81
|
});
|
|
113
82
|
}
|
|
114
83
|
async run(options) {
|
|
115
|
-
const systemTools = [
|
|
84
|
+
const systemTools = [
|
|
85
|
+
(0, import_artifact.defineTool)("system", {
|
|
86
|
+
name: "query_artifact_definitions",
|
|
87
|
+
description: "Query the available artifact definitions",
|
|
88
|
+
schema: import_effect.Schema.Struct({}),
|
|
89
|
+
execute: async () => {
|
|
90
|
+
return import_artifact.ToolResult.Success({
|
|
91
|
+
artifactDefinitions: options.artifacts.map((artifact) => ({
|
|
92
|
+
id: artifact.id,
|
|
93
|
+
name: artifact.name,
|
|
94
|
+
description: artifact.description
|
|
95
|
+
}))
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
];
|
|
116
100
|
switch (this._options.operationModel) {
|
|
117
101
|
case "planning":
|
|
118
|
-
systemTools.push(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
102
|
+
systemTools.push((0, import_artifact.defineTool)("system", {
|
|
103
|
+
name: "create_plan",
|
|
104
|
+
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.",
|
|
105
|
+
schema: import_effect.Schema.Struct({
|
|
106
|
+
goal: import_effect.Schema.String.annotations({
|
|
107
|
+
description: "The goal that the plan will achieve."
|
|
108
|
+
}),
|
|
109
|
+
steps: import_effect.Schema.Array(import_effect.Schema.Struct({
|
|
110
|
+
action: import_effect.Schema.String.annotations({
|
|
111
|
+
description: "Complete, detailed action to perform."
|
|
112
|
+
}),
|
|
113
|
+
input: import_effect.Schema.String.annotations({
|
|
114
|
+
description: "The required input data for this step. First step must not require any data."
|
|
115
|
+
}),
|
|
116
|
+
output: import_effect.Schema.String.annotations({
|
|
117
|
+
description: "The output data from this step. This is passed to the next step as input."
|
|
118
|
+
}),
|
|
119
|
+
requiredArtifactIds: import_effect.Schema.Array(import_effect.Schema.String).annotations({
|
|
120
|
+
description: "The ids of the artifacts required to perform this step.",
|
|
121
|
+
examples: [
|
|
122
|
+
[
|
|
123
|
+
"artifact:dxos.org/example/Test"
|
|
124
|
+
]
|
|
125
|
+
]
|
|
126
|
+
})
|
|
127
|
+
})).annotations({
|
|
128
|
+
description: "Steps"
|
|
129
|
+
})
|
|
130
|
+
}),
|
|
131
|
+
execute: async ({ goal, steps }) => {
|
|
132
|
+
const missingArtifactIds = steps.flatMap((step) => step.requiredArtifactIds).filter((artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId));
|
|
133
|
+
if (missingArtifactIds.length > 0) {
|
|
134
|
+
return import_artifact.ToolResult.Error(`One or more artifact ids are invalid: ${missingArtifactIds.join(", ")}`);
|
|
135
|
+
}
|
|
136
|
+
const stepResults = [];
|
|
137
|
+
for (const step of steps) {
|
|
138
|
+
(0, import_log.log)("executing step", {
|
|
139
|
+
action: step.action
|
|
140
|
+
}, {
|
|
141
|
+
F: __dxlog_file,
|
|
142
|
+
L: 160,
|
|
143
|
+
S: this,
|
|
144
|
+
C: (f, a) => f(...a)
|
|
145
|
+
});
|
|
146
|
+
const session = new _AISession({
|
|
147
|
+
operationModel: "immediate"
|
|
148
|
+
});
|
|
149
|
+
session.message.on((ev) => this.message.emit(ev));
|
|
150
|
+
session.block.on((ev) => this.block.emit(ev));
|
|
151
|
+
session.update.on((ev) => this.update.emit(ev));
|
|
152
|
+
session.streamEvent.on((ev) => this.streamEvent.emit(ev));
|
|
153
|
+
session.userMessage.on((ev) => this.userMessage.emit(ev));
|
|
154
|
+
const messages = await session.run({
|
|
155
|
+
client: options.client,
|
|
156
|
+
artifacts: options.artifacts,
|
|
157
|
+
tools: options.tools,
|
|
158
|
+
history: options.history,
|
|
159
|
+
extensions: options.extensions,
|
|
160
|
+
generationOptions: options.generationOptions,
|
|
161
|
+
requiredArtifactIds: step.requiredArtifactIds.slice(),
|
|
162
|
+
prompt: `
|
|
163
|
+
You are an agent that executes the subtask in a plan.
|
|
164
|
+
|
|
165
|
+
While you know the plan's goal only focus on your subtask
|
|
166
|
+
Use the data from the previous step to complete your task.
|
|
167
|
+
Return all of the data from "output" in your last message.
|
|
168
|
+
|
|
169
|
+
Current step (that you need to complete):
|
|
170
|
+
${JSON.stringify({
|
|
171
|
+
goal,
|
|
172
|
+
input: step.input,
|
|
173
|
+
output: step.output,
|
|
174
|
+
yourTask: step.action
|
|
175
|
+
}, null, 2)}
|
|
176
|
+
|
|
177
|
+
Previous step results:
|
|
178
|
+
${JSON.stringify(stepResults.at(-1))}.
|
|
179
|
+
`
|
|
180
|
+
});
|
|
181
|
+
const result = messages.at(-1);
|
|
182
|
+
stepResults.push(result);
|
|
183
|
+
}
|
|
184
|
+
return import_artifact.ToolResult.Success({
|
|
185
|
+
stepResults
|
|
186
|
+
});
|
|
124
187
|
}
|
|
125
188
|
}));
|
|
126
189
|
break;
|
|
127
|
-
case "
|
|
190
|
+
case "immediate":
|
|
191
|
+
systemTools.push((0, import_artifact.defineTool)("system", {
|
|
192
|
+
name: "require_artifact_definitions",
|
|
193
|
+
description: "Require the use of specific artifact definitions. This will allow the model to interact with artifact definitions and use their tools.",
|
|
194
|
+
schema: import_effect.Schema.Struct({
|
|
195
|
+
artifactDefinitionIds: import_effect.Schema.Array(import_effect.Schema.String).annotations({
|
|
196
|
+
description: "The ids of the artifact definitions to require",
|
|
197
|
+
examples: [
|
|
198
|
+
[
|
|
199
|
+
"artifact:dxos.org/example/Test"
|
|
200
|
+
]
|
|
201
|
+
]
|
|
202
|
+
})
|
|
203
|
+
}),
|
|
204
|
+
execute: async ({ artifactDefinitionIds }) => {
|
|
205
|
+
const missingArtifactDefinitionIds = artifactDefinitionIds.filter((artifactId) => !options.artifacts.some((artifact) => artifact.id === artifactId));
|
|
206
|
+
if (missingArtifactDefinitionIds.length > 0) {
|
|
207
|
+
return import_artifact.ToolResult.Error(`One or more artifact definition ids are invalid: ${missingArtifactDefinitionIds.join(", ")}`);
|
|
208
|
+
}
|
|
209
|
+
for (const artifactDefinitionId of artifactDefinitionIds) {
|
|
210
|
+
requiredArtifactIds.add(artifactDefinitionId);
|
|
211
|
+
}
|
|
212
|
+
return import_artifact.ToolResult.Success({});
|
|
213
|
+
}
|
|
214
|
+
}));
|
|
128
215
|
break;
|
|
129
|
-
default:
|
|
130
|
-
throw new TypeError(`Invalid operation model: ${this._options.operationModel}`);
|
|
131
216
|
}
|
|
132
217
|
this._history = [
|
|
133
218
|
...options.history
|
|
134
219
|
];
|
|
135
220
|
this._pending = [
|
|
136
|
-
|
|
221
|
+
(0, import_echo_schema.createStatic)(import_artifact.Message, {
|
|
222
|
+
role: "user",
|
|
223
|
+
content: [
|
|
224
|
+
{
|
|
225
|
+
type: "text",
|
|
226
|
+
text: options.prompt
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
})
|
|
137
230
|
];
|
|
138
231
|
this.userMessage.emit(this._pending.at(-1));
|
|
139
232
|
this._stream = void 0;
|
|
@@ -153,11 +246,11 @@ var AISession = class _AISession {
|
|
|
153
246
|
tools: tools.map((tool) => tool.name)
|
|
154
247
|
}, {
|
|
155
248
|
F: __dxlog_file,
|
|
156
|
-
L:
|
|
249
|
+
L: 264,
|
|
157
250
|
S: this,
|
|
158
251
|
C: (f, a) => f(...a)
|
|
159
252
|
});
|
|
160
|
-
this._stream = await options.client.
|
|
253
|
+
this._stream = await options.client.exec({
|
|
161
254
|
...options.generationOptions ?? {},
|
|
162
255
|
// TODO(burdon): Rename messages or separate history/message.
|
|
163
256
|
history: [
|
|
@@ -176,7 +269,7 @@ var AISession = class _AISession {
|
|
|
176
269
|
pending: this._pending
|
|
177
270
|
}, {
|
|
178
271
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
272
|
+
L: 289,
|
|
180
273
|
S: this,
|
|
181
274
|
C: (f, a) => f(...a)
|
|
182
275
|
});
|
|
@@ -184,21 +277,21 @@ var AISession = class _AISession {
|
|
|
184
277
|
const message = this._pending.at(-1);
|
|
185
278
|
(0, import_invariant.invariant)(message, void 0, {
|
|
186
279
|
F: __dxlog_file,
|
|
187
|
-
L:
|
|
280
|
+
L: 294,
|
|
188
281
|
S: this,
|
|
189
282
|
A: [
|
|
190
283
|
"message",
|
|
191
284
|
""
|
|
192
285
|
]
|
|
193
286
|
});
|
|
194
|
-
if ((0,
|
|
287
|
+
if ((0, import_chunk_IBOBRBDF.isToolUse)(message)) {
|
|
195
288
|
(0, import_log.log)("tool request...", void 0, {
|
|
196
289
|
F: __dxlog_file,
|
|
197
|
-
L:
|
|
290
|
+
L: 296,
|
|
198
291
|
S: this,
|
|
199
292
|
C: (f, a) => f(...a)
|
|
200
293
|
});
|
|
201
|
-
const response = await (0,
|
|
294
|
+
const response = await (0, import_chunk_IBOBRBDF.runTools)({
|
|
202
295
|
message: this._pending.at(-1),
|
|
203
296
|
tools,
|
|
204
297
|
extensions: options.extensions ?? {}
|
|
@@ -207,7 +300,7 @@ var AISession = class _AISession {
|
|
|
207
300
|
response
|
|
208
301
|
}, {
|
|
209
302
|
F: __dxlog_file,
|
|
210
|
-
L:
|
|
303
|
+
L: 303,
|
|
211
304
|
S: this,
|
|
212
305
|
C: (f, a) => f(...a)
|
|
213
306
|
});
|
|
@@ -227,7 +320,7 @@ var AISession = class _AISession {
|
|
|
227
320
|
} catch (err) {
|
|
228
321
|
import_log.log.catch(err, void 0, {
|
|
229
322
|
F: __dxlog_file,
|
|
230
|
-
L:
|
|
323
|
+
L: 315,
|
|
231
324
|
S: this,
|
|
232
325
|
C: (f, a) => f(...a)
|
|
233
326
|
});
|
|
@@ -248,180 +341,6 @@ var AISession = class _AISession {
|
|
|
248
341
|
}
|
|
249
342
|
return this._pending;
|
|
250
343
|
}
|
|
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
|
-
}
|
|
425
344
|
abort() {
|
|
426
345
|
this._stream?.abort();
|
|
427
346
|
}
|
|
@@ -439,57 +358,21 @@ var createBaseInstructions = ({ availableArtifacts, operationModel }) => `
|
|
|
439
358
|
Decision-making:
|
|
440
359
|
|
|
441
360
|
- Analyze the structure and type of the content in the user's message.
|
|
442
|
-
|
|
443
|
-
|
|
361
|
+
- Can you complete the task using the available artifacts?
|
|
362
|
+
- If you can't complete the task using the available artifacts, query the list of available artifacts using the appropriate tool.
|
|
363
|
+
- Identify which artifacts are relevant to the user's request.
|
|
444
364
|
${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.
|
|
448
365
|
- 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.
|
|
449
|
-
` :
|
|
450
|
-
|
|
451
|
-
-
|
|
452
|
-
-
|
|
453
|
-
|
|
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
|
-
` : ""}
|
|
366
|
+
` : `
|
|
367
|
+
- Are the required artifacts already available?
|
|
368
|
+
- If not, select which artifact(s) will be the most relevant and require them using the require_artifacts tool.
|
|
369
|
+
- The require'd artifact tools will be available for use after require.
|
|
370
|
+
`}
|
|
462
371
|
|
|
463
372
|
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join("\n")}` : ""}
|
|
464
373
|
`;
|
|
465
374
|
var AIServiecOverloadedError = class extends import_effect.Schema.TaggedError()("AIServiecOverloadedError", {}) {
|
|
466
375
|
};
|
|
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
|
-
};
|
|
493
376
|
// Annotate the CommonJS export names for ESM import in node:
|
|
494
377
|
0 && (module.exports = {
|
|
495
378
|
AIServiceEdgeClient,
|
|
@@ -502,7 +385,6 @@ ${diff}` : ""}</changed-artifact>`).join("\n")}
|
|
|
502
385
|
DEFAULT_OLLAMA_MODELS,
|
|
503
386
|
EchoDataSource,
|
|
504
387
|
GenerateRequest,
|
|
505
|
-
GenerateResponse,
|
|
506
388
|
GenerationStreamImpl,
|
|
507
389
|
LLMModel,
|
|
508
390
|
MessageCollector,
|
|
@@ -510,7 +392,6 @@ ${diff}` : ""}</changed-artifact>`).join("\n")}
|
|
|
510
392
|
OllamaClient,
|
|
511
393
|
StreamTransform,
|
|
512
394
|
ToolTypes,
|
|
513
|
-
VersionPin,
|
|
514
395
|
createArtifactElement,
|
|
515
396
|
createGenerationStream,
|
|
516
397
|
emitMessageAsEvents,
|