@dxos/assistant 0.8.1 → 0.8.2-main.2f9c567
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-PND5VR6D.mjs → chunk-OLO6SVOL.mjs} +91 -84
- package/dist/lib/browser/chunk-OLO6SVOL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +276 -154
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +98 -102
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-IBOBRBDF.cjs → chunk-CI5Q7FBG.cjs} +106 -98
- package/dist/lib/node/chunk-CI5Q7FBG.cjs.map +7 -0
- package/dist/lib/node/index.cjs +302 -183
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +88 -93
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-DCQJOLSR.mjs → chunk-Y3SYOFFJ.mjs} +91 -84
- package/dist/lib/node-esm/chunk-Y3SYOFFJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +276 -154
- 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 +98 -102
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/ai-service/edge-client.d.ts +4 -5
- package/dist/types/src/ai-service/edge-client.d.ts.map +1 -1
- package/dist/types/src/ai-service/message-collector.d.ts +0 -6
- package/dist/types/src/ai-service/message-collector.d.ts.map +1 -1
- package/dist/types/src/ai-service/ollama-client.d.ts +6 -2
- package/dist/types/src/ai-service/ollama-client.d.ts.map +1 -1
- package/dist/types/src/ai-service/parser.d.ts +0 -3
- package/dist/types/src/ai-service/parser.d.ts.map +1 -1
- package/dist/types/src/ai-service/service.d.ts +18 -2
- package/dist/types/src/ai-service/service.d.ts.map +1 -1
- package/dist/types/src/ai-service/testing/mock.d.ts +6 -2
- package/dist/types/src/ai-service/testing/mock.d.ts.map +1 -1
- package/dist/types/src/ai-service/types.d.ts +144 -101
- package/dist/types/src/ai-service/types.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.d.ts +0 -3
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/types.d.ts +11 -12
- 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 +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +32 -13
- 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/query-promts.d.ts +3 -3
- package/dist/types/src/testing/query-promts.d.ts.map +1 -1
- package/dist/types/src/testing/test-data.d.ts +4 -4
- package/dist/types/src/testing/test-data.d.ts.map +1 -1
- package/dist/types/src/testing/test-schema.d.ts +25 -23
- package/dist/types/src/testing/test-schema.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/ai-service/client.test.ts +55 -73
- package/src/ai-service/edge-client.ts +13 -20
- package/src/ai-service/ollama-client.ts +16 -9
- package/src/ai-service/parser.ts +13 -2
- package/src/ai-service/service.ts +19 -3
- package/src/ai-service/testing/mock.ts +9 -1
- package/src/ai-service/types.ts +24 -15
- package/src/bin/chat.ts +3 -3
- package/src/conversation/conversation.test.ts +3 -3
- package/src/conversation/conversation.ts +5 -11
- package/src/conversation/types.ts +11 -14
- package/src/cypher/combinators.test.ts +4 -4
- package/src/cypher/echo-data-source.ts +7 -6
- 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 +29 -22
- package/src/session/session.ts +286 -150
- package/src/session/version-pin.test.ts +26 -0
- package/src/session/version-pin.ts +43 -0
- package/src/testing/artifacts.test.ts +22 -22
- package/src/testing/query-promts.ts +5 -5
- package/src/testing/query.test.ts +17 -19
- package/src/testing/test-data.ts +78 -71
- package/src/testing/test-schema.ts +28 -29
- package/dist/lib/browser/chunk-PND5VR6D.mjs.map +0 -7
- package/dist/lib/node/chunk-IBOBRBDF.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-DCQJOLSR.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -18,46 +18,77 @@ 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_CI5Q7FBG.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
|
-
|
|
24
|
+
DEFAULT_EDGE_MODEL: () => import_chunk_CI5Q7FBG.DEFAULT_EDGE_MODEL,
|
|
25
|
+
DEFAULT_EDGE_MODELS: () => import_chunk_CI5Q7FBG.DEFAULT_EDGE_MODELS,
|
|
26
|
+
DEFAULT_OLLAMA_ENDPOINT: () => import_chunk_CI5Q7FBG.DEFAULT_OLLAMA_ENDPOINT,
|
|
27
|
+
DEFAULT_OLLAMA_MODEL: () => import_chunk_CI5Q7FBG.DEFAULT_OLLAMA_MODEL,
|
|
28
|
+
DEFAULT_OLLAMA_MODELS: () => import_chunk_CI5Q7FBG.DEFAULT_OLLAMA_MODELS,
|
|
29
|
+
EchoDataSource: () => import_chunk_CI5Q7FBG.EchoDataSource,
|
|
30
|
+
GenerateRequest: () => import_chunk_CI5Q7FBG.GenerateRequest,
|
|
31
|
+
GenerateResponse: () => import_chunk_CI5Q7FBG.GenerateResponse,
|
|
32
|
+
GenerationStreamImpl: () => import_chunk_CI5Q7FBG.GenerationStreamImpl,
|
|
33
|
+
LLMModel: () => import_chunk_CI5Q7FBG.LLMModel,
|
|
34
|
+
MessageCollector: () => import_chunk_CI5Q7FBG.MessageCollector,
|
|
35
|
+
MixedStreamParser: () => import_chunk_CI5Q7FBG.MixedStreamParser,
|
|
36
|
+
OllamaClient: () => import_chunk_CI5Q7FBG.OllamaClient,
|
|
37
|
+
StreamTransform: () => import_chunk_CI5Q7FBG.StreamTransform,
|
|
38
|
+
ToolTypes: () => import_chunk_CI5Q7FBG.ToolTypes,
|
|
39
|
+
VersionPin: () => VersionPin,
|
|
40
|
+
createArtifactElement: () => import_chunk_CI5Q7FBG.createArtifactElement,
|
|
41
|
+
createGenerationStream: () => import_chunk_CI5Q7FBG.createGenerationStream,
|
|
42
|
+
emitMessageAsEvents: () => import_chunk_CI5Q7FBG.emitMessageAsEvents,
|
|
43
|
+
executeQuery: () => import_chunk_CI5Q7FBG.executeQuery,
|
|
44
|
+
executeQueryPlan: () => import_chunk_CI5Q7FBG.executeQueryPlan,
|
|
45
|
+
formatInferredRelationshipLabel: () => import_chunk_CI5Q7FBG.formatInferredRelationshipLabel,
|
|
46
|
+
formatJsonSchemaForLLM: () => import_chunk_CI5Q7FBG.formatJsonSchemaForLLM,
|
|
47
|
+
formatNodeLabel: () => import_chunk_CI5Q7FBG.formatNodeLabel,
|
|
48
|
+
isReference: () => import_chunk_CI5Q7FBG.isReference,
|
|
49
|
+
isToolUse: () => import_chunk_CI5Q7FBG.isToolUse,
|
|
50
|
+
mergeMessageBlock: () => import_chunk_CI5Q7FBG.mergeMessageBlock,
|
|
51
|
+
parseCypherQuery: () => import_chunk_CI5Q7FBG.parseCypherQuery,
|
|
52
|
+
runLLM: () => import_chunk_CI5Q7FBG.runLLM,
|
|
53
|
+
runTools: () => import_chunk_CI5Q7FBG.runTools
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(node_exports);
|
|
54
|
-
var
|
|
56
|
+
var import_chunk_CI5Q7FBG = require("./chunk-CI5Q7FBG.cjs");
|
|
55
57
|
var import_effect = require("effect");
|
|
56
58
|
var import_artifact = require("@dxos/artifact");
|
|
57
59
|
var import_async = require("@dxos/async");
|
|
60
|
+
var import_echo_db = require("@dxos/echo-db");
|
|
58
61
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
59
62
|
var import_invariant = require("@dxos/invariant");
|
|
60
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
|
+
};
|
|
61
92
|
function _ts_decorate(decorators, target, key, desc) {
|
|
62
93
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
63
94
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -68,7 +99,7 @@ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/experimental/assistant/
|
|
|
68
99
|
var AISession = class _AISession {
|
|
69
100
|
constructor(_options) {
|
|
70
101
|
this._options = _options;
|
|
71
|
-
this._parser = new
|
|
102
|
+
this._parser = new import_chunk_CI5Q7FBG.MixedStreamParser();
|
|
72
103
|
this._pending = [];
|
|
73
104
|
this._history = [];
|
|
74
105
|
this.message = this._parser.message;
|
|
@@ -81,152 +112,28 @@ var AISession = class _AISession {
|
|
|
81
112
|
});
|
|
82
113
|
}
|
|
83
114
|
async run(options) {
|
|
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
|
-
];
|
|
115
|
+
const systemTools = [];
|
|
100
116
|
switch (this._options.operationModel) {
|
|
101
117
|
case "planning":
|
|
102
|
-
systemTools.push((
|
|
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
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}));
|
|
118
|
+
systemTools.push(this._createQueryArtifactsTool(options.artifacts), this._createPlanningTool(options));
|
|
189
119
|
break;
|
|
190
|
-
case "
|
|
191
|
-
systemTools.push((
|
|
192
|
-
|
|
193
|
-
|
|
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({});
|
|
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);
|
|
213
124
|
}
|
|
214
125
|
}));
|
|
215
126
|
break;
|
|
127
|
+
case "configured":
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
throw new TypeError(`Invalid operation model: ${this._options.operationModel}`);
|
|
216
131
|
}
|
|
217
132
|
this._history = [
|
|
218
133
|
...options.history
|
|
219
134
|
];
|
|
220
135
|
this._pending = [
|
|
221
|
-
|
|
222
|
-
role: "user",
|
|
223
|
-
content: [
|
|
224
|
-
{
|
|
225
|
-
type: "text",
|
|
226
|
-
text: options.prompt
|
|
227
|
-
}
|
|
228
|
-
]
|
|
229
|
-
})
|
|
136
|
+
await this._formatUserPrompt(options.artifactDiffResolver, options.prompt, options.history)
|
|
230
137
|
];
|
|
231
138
|
this.userMessage.emit(this._pending.at(-1));
|
|
232
139
|
this._stream = void 0;
|
|
@@ -246,11 +153,11 @@ var AISession = class _AISession {
|
|
|
246
153
|
tools: tools.map((tool) => tool.name)
|
|
247
154
|
}, {
|
|
248
155
|
F: __dxlog_file,
|
|
249
|
-
L:
|
|
156
|
+
L: 180,
|
|
250
157
|
S: this,
|
|
251
158
|
C: (f, a) => f(...a)
|
|
252
159
|
});
|
|
253
|
-
this._stream = await options.client.
|
|
160
|
+
this._stream = await options.client.execStream({
|
|
254
161
|
...options.generationOptions ?? {},
|
|
255
162
|
// TODO(burdon): Rename messages or separate history/message.
|
|
256
163
|
history: [
|
|
@@ -269,7 +176,7 @@ var AISession = class _AISession {
|
|
|
269
176
|
pending: this._pending
|
|
270
177
|
}, {
|
|
271
178
|
F: __dxlog_file,
|
|
272
|
-
L:
|
|
179
|
+
L: 205,
|
|
273
180
|
S: this,
|
|
274
181
|
C: (f, a) => f(...a)
|
|
275
182
|
});
|
|
@@ -277,21 +184,21 @@ var AISession = class _AISession {
|
|
|
277
184
|
const message = this._pending.at(-1);
|
|
278
185
|
(0, import_invariant.invariant)(message, void 0, {
|
|
279
186
|
F: __dxlog_file,
|
|
280
|
-
L:
|
|
187
|
+
L: 210,
|
|
281
188
|
S: this,
|
|
282
189
|
A: [
|
|
283
190
|
"message",
|
|
284
191
|
""
|
|
285
192
|
]
|
|
286
193
|
});
|
|
287
|
-
if ((0,
|
|
194
|
+
if ((0, import_chunk_CI5Q7FBG.isToolUse)(message)) {
|
|
288
195
|
(0, import_log.log)("tool request...", void 0, {
|
|
289
196
|
F: __dxlog_file,
|
|
290
|
-
L:
|
|
197
|
+
L: 212,
|
|
291
198
|
S: this,
|
|
292
199
|
C: (f, a) => f(...a)
|
|
293
200
|
});
|
|
294
|
-
const response = await (0,
|
|
201
|
+
const response = await (0, import_chunk_CI5Q7FBG.runTools)({
|
|
295
202
|
message: this._pending.at(-1),
|
|
296
203
|
tools,
|
|
297
204
|
extensions: options.extensions ?? {}
|
|
@@ -300,7 +207,7 @@ var AISession = class _AISession {
|
|
|
300
207
|
response
|
|
301
208
|
}, {
|
|
302
209
|
F: __dxlog_file,
|
|
303
|
-
L:
|
|
210
|
+
L: 219,
|
|
304
211
|
S: this,
|
|
305
212
|
C: (f, a) => f(...a)
|
|
306
213
|
});
|
|
@@ -320,7 +227,7 @@ var AISession = class _AISession {
|
|
|
320
227
|
} catch (err) {
|
|
321
228
|
import_log.log.catch(err, void 0, {
|
|
322
229
|
F: __dxlog_file,
|
|
323
|
-
L:
|
|
230
|
+
L: 231,
|
|
324
231
|
S: this,
|
|
325
232
|
C: (f, a) => f(...a)
|
|
326
233
|
});
|
|
@@ -341,6 +248,180 @@ var AISession = class _AISession {
|
|
|
341
248
|
}
|
|
342
249
|
return this._pending;
|
|
343
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
|
+
}
|
|
344
425
|
abort() {
|
|
345
426
|
this._stream?.abort();
|
|
346
427
|
}
|
|
@@ -358,21 +439,57 @@ var createBaseInstructions = ({ availableArtifacts, operationModel }) => `
|
|
|
358
439
|
Decision-making:
|
|
359
440
|
|
|
360
441
|
- Analyze the structure and type of the content in the user's message.
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
- Identify which artifacts are relevant to the user's request.
|
|
442
|
+
|
|
443
|
+
|
|
364
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.
|
|
365
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.
|
|
366
|
-
` :
|
|
367
|
-
|
|
368
|
-
-
|
|
369
|
-
-
|
|
370
|
-
|
|
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
|
+
` : ""}
|
|
371
462
|
|
|
372
463
|
${availableArtifacts.length > 0 ? `Artifacts already in context: ${availableArtifacts.join("\n")}` : ""}
|
|
373
464
|
`;
|
|
374
465
|
var AIServiecOverloadedError = class extends import_effect.Schema.TaggedError()("AIServiecOverloadedError", {}) {
|
|
375
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
|
+
};
|
|
376
493
|
// Annotate the CommonJS export names for ESM import in node:
|
|
377
494
|
0 && (module.exports = {
|
|
378
495
|
AIServiceEdgeClient,
|
|
@@ -385,6 +502,7 @@ var AIServiecOverloadedError = class extends import_effect.Schema.TaggedError()(
|
|
|
385
502
|
DEFAULT_OLLAMA_MODELS,
|
|
386
503
|
EchoDataSource,
|
|
387
504
|
GenerateRequest,
|
|
505
|
+
GenerateResponse,
|
|
388
506
|
GenerationStreamImpl,
|
|
389
507
|
LLMModel,
|
|
390
508
|
MessageCollector,
|
|
@@ -392,6 +510,7 @@ var AIServiecOverloadedError = class extends import_effect.Schema.TaggedError()(
|
|
|
392
510
|
OllamaClient,
|
|
393
511
|
StreamTransform,
|
|
394
512
|
ToolTypes,
|
|
513
|
+
VersionPin,
|
|
395
514
|
createArtifactElement,
|
|
396
515
|
createGenerationStream,
|
|
397
516
|
emitMessageAsEvents,
|