@ai-setting/roy-agent-core 1.5.83 → 1.5.85
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/env/agent/index.js +2 -2
- package/dist/env/event-source/index.js +2 -2
- package/dist/env/index.js +14 -14
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/task/delegate/index.js +2 -2
- package/dist/env/task/index.js +3 -3
- package/dist/env/task/plugins/index.js +1 -1
- package/dist/env/workflow/engine/index.js +3 -4
- package/dist/env/workflow/index.js +7 -7
- package/dist/env/workflow/service/index.js +8 -2
- package/dist/env/workflow/storage/index.js +11 -6
- package/dist/env/workflow/tools/index.js +16 -2
- package/dist/index.js +17 -16
- package/dist/shared/@ai-setting/{roy-agent-core-f6p7wwpd.js → roy-agent-core-0kt57b72.js} +1 -6
- package/dist/shared/@ai-setting/{roy-agent-core-whw7jap0.js → roy-agent-core-1db4vpc6.js} +3 -2
- package/dist/shared/@ai-setting/{roy-agent-core-68sef3es.js → roy-agent-core-29fh9mxg.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-3sv590cv.js +132 -0
- package/dist/shared/@ai-setting/{roy-agent-core-m4qjnhz6.js → roy-agent-core-5kdw0p98.js} +114 -68
- package/dist/shared/@ai-setting/{roy-agent-core-78yzt2bq.js → roy-agent-core-7fdzfsm6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-mbre4fxg.js → roy-agent-core-7z4xtrmw.js} +16 -0
- package/dist/shared/@ai-setting/{roy-agent-core-am646wfz.js → roy-agent-core-86d4exyf.js} +5 -2
- package/dist/shared/@ai-setting/roy-agent-core-c67wr8sp.js +11 -0
- package/dist/shared/@ai-setting/{roy-agent-core-v3t28k5n.js → roy-agent-core-dp73ghtz.js} +24 -26
- package/dist/shared/@ai-setting/{roy-agent-core-qjv8537d.js → roy-agent-core-dv12wpdv.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-6b0r2e7j.js → roy-agent-core-gttz2jpm.js} +15 -52
- package/dist/shared/@ai-setting/{roy-agent-core-496zzm5a.js → roy-agent-core-h4h55x4h.js} +183 -3
- package/dist/shared/@ai-setting/roy-agent-core-hhrg314p.js +34 -0
- package/dist/shared/@ai-setting/{roy-agent-core-vcvgq9hy.js → roy-agent-core-mmkyydw7.js} +128 -6
- package/dist/shared/@ai-setting/roy-agent-core-r5axf0ad.js +751 -0
- package/dist/shared/@ai-setting/{roy-agent-core-74cp3zp1.js → roy-agent-core-taxvytzz.js} +4 -1
- package/dist/shared/@ai-setting/roy-agent-core-tq9528d3.js +336 -0
- package/dist/shared/@ai-setting/{roy-agent-core-nc0n0bdc.js → roy-agent-core-xckhrs2p.js} +2 -3
- package/dist/shared/@ai-setting/{roy-agent-core-67yzhmg2.js → roy-agent-core-ya1ayt1k.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-015vw11k.js → roy-agent-core-yx0vw1aw.js} +8 -6
- package/package.json +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
- package/dist/shared/@ai-setting/roy-agent-core-6b57g1zk.js +0 -103
- package/dist/shared/@ai-setting/roy-agent-core-7z8fzxck.js +0 -265
- package/dist/shared/@ai-setting/roy-agent-core-a6j7g1qe.js +0 -428
- package/dist/shared/@ai-setting/roy-agent-core-qf9gvx02.js +0 -39
|
@@ -5,7 +5,10 @@ import {
|
|
|
5
5
|
initDatabase,
|
|
6
6
|
initializeTables,
|
|
7
7
|
resetDatabase
|
|
8
|
-
} from "./roy-agent-core-
|
|
8
|
+
} from "./roy-agent-core-h4h55x4h.js";
|
|
9
|
+
import"./roy-agent-core-3sv590cv.js";
|
|
10
|
+
import"./roy-agent-core-rvxg1wps.js";
|
|
11
|
+
import"./roy-agent-core-k05v31rc.js";
|
|
9
12
|
import"./roy-agent-core-shme7set.js";
|
|
10
13
|
import"./roy-agent-core-7z9b1fm8.js";
|
|
11
14
|
import"./roy-agent-core-c6592r3c.js";
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TracedAs,
|
|
3
|
+
init_decorator
|
|
4
|
+
} from "./roy-agent-core-k05v31rc.js";
|
|
5
|
+
import {
|
|
6
|
+
__legacyDecorateClassTS
|
|
7
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
8
|
+
|
|
9
|
+
// src/env/workflow/service/workflow-service.ts
|
|
10
|
+
init_decorator();
|
|
11
|
+
var TAG_MIN_COUNT = 1;
|
|
12
|
+
var TAG_MAX_COUNT = 3;
|
|
13
|
+
class TagValidationError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "TagValidationError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class WorkflowService {
|
|
21
|
+
workflowRepository;
|
|
22
|
+
engineFactory;
|
|
23
|
+
sessionComponent;
|
|
24
|
+
tagRepository;
|
|
25
|
+
constructor(workflowRepository, engineFactory, sessionComponent, tagRepository) {
|
|
26
|
+
this.workflowRepository = workflowRepository;
|
|
27
|
+
this.engineFactory = engineFactory;
|
|
28
|
+
this.sessionComponent = sessionComponent;
|
|
29
|
+
this.tagRepository = tagRepository;
|
|
30
|
+
}
|
|
31
|
+
validateTags(tags) {
|
|
32
|
+
const effective = tags ?? [];
|
|
33
|
+
if (effective.length < TAG_MIN_COUNT) {
|
|
34
|
+
throw new TagValidationError(`Workflow requires at least ${TAG_MIN_COUNT} tag (use --tags to provide 1-3 tags)`);
|
|
35
|
+
}
|
|
36
|
+
if (effective.length > TAG_MAX_COUNT) {
|
|
37
|
+
throw new TagValidationError(`Workflow supports at most ${TAG_MAX_COUNT} tags (received ${effective.length}). Please reduce to 1-${TAG_MAX_COUNT} tags.`);
|
|
38
|
+
}
|
|
39
|
+
return effective;
|
|
40
|
+
}
|
|
41
|
+
async createWorkflow(definition, options) {
|
|
42
|
+
const effectiveTags = this.validateTags(options?.tags || definition.metadata?.tags);
|
|
43
|
+
const existing = this.workflowRepository.getByName(definition.name);
|
|
44
|
+
if (existing) {
|
|
45
|
+
if (options?.force !== true) {
|
|
46
|
+
throw new Error(`Workflow already exists: ${definition.name}`);
|
|
47
|
+
}
|
|
48
|
+
const oldTags = existing.tags;
|
|
49
|
+
const updated = this.workflowRepository.update(existing.id, {
|
|
50
|
+
name: definition.name,
|
|
51
|
+
version: definition.version,
|
|
52
|
+
description: definition.description || existing.description,
|
|
53
|
+
definition,
|
|
54
|
+
config: definition.config || {},
|
|
55
|
+
metadata: {
|
|
56
|
+
...options.metadata || definition.metadata || existing.metadata || {},
|
|
57
|
+
taskId: options.taskId || definition.metadata?.taskId || existing.metadata?.taskId
|
|
58
|
+
},
|
|
59
|
+
tags: effectiveTags
|
|
60
|
+
});
|
|
61
|
+
this.syncTagsOnUpdate(oldTags, effectiveTags);
|
|
62
|
+
return updated;
|
|
63
|
+
}
|
|
64
|
+
const workflow = {
|
|
65
|
+
name: definition.name,
|
|
66
|
+
version: definition.version,
|
|
67
|
+
description: definition.description,
|
|
68
|
+
definition,
|
|
69
|
+
config: definition.config || {},
|
|
70
|
+
metadata: {
|
|
71
|
+
...options?.metadata || definition.metadata || {},
|
|
72
|
+
taskId: options?.taskId || definition.metadata?.taskId
|
|
73
|
+
},
|
|
74
|
+
tags: effectiveTags
|
|
75
|
+
};
|
|
76
|
+
return this.workflowRepository.transaction(() => {
|
|
77
|
+
const wf = this.workflowRepository.create(workflow);
|
|
78
|
+
if (this.tagRepository) {
|
|
79
|
+
this.tagRepository.upsertMany(effectiveTags);
|
|
80
|
+
}
|
|
81
|
+
return wf;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
syncTagsOnUpdate(oldTags, newTags) {
|
|
85
|
+
if (!this.tagRepository)
|
|
86
|
+
return;
|
|
87
|
+
const oldSet = new Set(oldTags);
|
|
88
|
+
const newSet = new Set(newTags);
|
|
89
|
+
const removed = oldTags.filter((t) => !newSet.has(t));
|
|
90
|
+
const added = newTags.filter((t) => !oldSet.has(t));
|
|
91
|
+
if (removed.length > 0)
|
|
92
|
+
this.tagRepository.decrementMany(removed);
|
|
93
|
+
if (added.length > 0)
|
|
94
|
+
this.tagRepository.upsertMany(added);
|
|
95
|
+
}
|
|
96
|
+
getWorkflow(idOrName) {
|
|
97
|
+
let workflow = this.workflowRepository.getById(idOrName);
|
|
98
|
+
if (workflow)
|
|
99
|
+
return workflow;
|
|
100
|
+
return this.workflowRepository.getByName(idOrName);
|
|
101
|
+
}
|
|
102
|
+
getWorkflowById(id) {
|
|
103
|
+
return this.workflowRepository.getById(id);
|
|
104
|
+
}
|
|
105
|
+
getWorkflowByName(name) {
|
|
106
|
+
return this.workflowRepository.getByName(name);
|
|
107
|
+
}
|
|
108
|
+
listWorkflows(options) {
|
|
109
|
+
return this.workflowRepository.list(options);
|
|
110
|
+
}
|
|
111
|
+
searchWorkflows(options = {}) {
|
|
112
|
+
const all = this.workflowRepository.list();
|
|
113
|
+
const keyword = options.keyword?.trim().toLowerCase();
|
|
114
|
+
const tags = options.tags ?? [];
|
|
115
|
+
let filtered = all;
|
|
116
|
+
if (tags.length > 0) {
|
|
117
|
+
filtered = filtered.filter((w) => tags.every((t) => w.tags.includes(t)));
|
|
118
|
+
}
|
|
119
|
+
if (keyword && keyword.length > 0) {
|
|
120
|
+
filtered = filtered.filter((w) => {
|
|
121
|
+
const nameMatch = w.name.toLowerCase().includes(keyword);
|
|
122
|
+
const descMatch = w.description?.toLowerCase().includes(keyword) ?? false;
|
|
123
|
+
return nameMatch || descMatch;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (options.offset !== undefined && options.offset > 0) {
|
|
127
|
+
filtered = filtered.slice(options.offset);
|
|
128
|
+
}
|
|
129
|
+
if (options.limit !== undefined && options.limit > 0) {
|
|
130
|
+
filtered = filtered.slice(0, options.limit);
|
|
131
|
+
}
|
|
132
|
+
return filtered;
|
|
133
|
+
}
|
|
134
|
+
async updateWorkflow(idOrName, updates, options) {
|
|
135
|
+
let workflow = this.workflowRepository.getByName(idOrName);
|
|
136
|
+
if (!workflow) {
|
|
137
|
+
workflow = this.workflowRepository.getById(idOrName);
|
|
138
|
+
}
|
|
139
|
+
if (!workflow) {
|
|
140
|
+
throw new Error(`Workflow not found: ${idOrName}`);
|
|
141
|
+
}
|
|
142
|
+
const updateData = {
|
|
143
|
+
...updates
|
|
144
|
+
};
|
|
145
|
+
if (options?.tags !== undefined) {
|
|
146
|
+
updateData.tags = options.tags;
|
|
147
|
+
}
|
|
148
|
+
const updated = this.workflowRepository.update(workflow.id, updateData);
|
|
149
|
+
if (!updated) {
|
|
150
|
+
throw new Error(`Failed to update workflow: ${idOrName}`);
|
|
151
|
+
}
|
|
152
|
+
return updated;
|
|
153
|
+
}
|
|
154
|
+
async deleteWorkflow(idOrName) {
|
|
155
|
+
let workflow = this.workflowRepository.getByName(idOrName);
|
|
156
|
+
if (!workflow) {
|
|
157
|
+
workflow = this.workflowRepository.getById(idOrName);
|
|
158
|
+
}
|
|
159
|
+
if (!workflow) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
const tagsToDecrement = [...workflow.tags];
|
|
163
|
+
return this.workflowRepository.transaction(() => {
|
|
164
|
+
const deleted = this.workflowRepository.delete(workflow.id);
|
|
165
|
+
if (deleted && this.tagRepository) {
|
|
166
|
+
this.tagRepository.decrementMany(tagsToDecrement);
|
|
167
|
+
}
|
|
168
|
+
return deleted;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
async listWorkflowsWithTags(options) {
|
|
172
|
+
const workflows = this.workflowRepository.list(options);
|
|
173
|
+
const availableTags = this.tagRepository ? this.tagRepository.list().map((t) => ({ name: t.name, count: t.usage_count })) : [];
|
|
174
|
+
const total = this.workflowRepository.countAll(options);
|
|
175
|
+
return {
|
|
176
|
+
workflows,
|
|
177
|
+
available_tags: availableTags,
|
|
178
|
+
total
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
async searchWorkflowsWithTags(options = {}) {
|
|
182
|
+
const workflows = this.searchWorkflows(options);
|
|
183
|
+
const availableTags = this.tagRepository ? this.tagRepository.list().map((t) => ({ name: t.name, count: t.usage_count })) : [];
|
|
184
|
+
const total = this.workflowRepository.countAll({
|
|
185
|
+
tag: options.tags?.length === 1 ? options.tags[0] : undefined,
|
|
186
|
+
tags: options.tags && options.tags.length > 1 ? options.tags : undefined,
|
|
187
|
+
search: options.keyword
|
|
188
|
+
});
|
|
189
|
+
return {
|
|
190
|
+
workflows,
|
|
191
|
+
available_tags: availableTags,
|
|
192
|
+
total,
|
|
193
|
+
keyword: options.keyword,
|
|
194
|
+
tags: options.tags
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
async listTags(options) {
|
|
198
|
+
const sortBy = options?.sortBy ?? "usage_count";
|
|
199
|
+
const order = options?.order ?? "desc";
|
|
200
|
+
const limit = options?.limit ?? 100;
|
|
201
|
+
const list = this.tagRepository ? this.tagRepository.list({ sortBy, order, limit }) : [];
|
|
202
|
+
return { tags: list, total: list.length };
|
|
203
|
+
}
|
|
204
|
+
getTag(name) {
|
|
205
|
+
if (!this.tagRepository)
|
|
206
|
+
return;
|
|
207
|
+
return this.tagRepository.get(name);
|
|
208
|
+
}
|
|
209
|
+
async runWorkflow(idOrNameOrDefinition, input, options) {
|
|
210
|
+
let workflow = null;
|
|
211
|
+
let definition = null;
|
|
212
|
+
if (typeof idOrNameOrDefinition === "string") {
|
|
213
|
+
workflow = this.getWorkflow(idOrNameOrDefinition);
|
|
214
|
+
if (!workflow) {
|
|
215
|
+
throw new Error(`Workflow not found: ${idOrNameOrDefinition}`);
|
|
216
|
+
}
|
|
217
|
+
definition = workflow.definition;
|
|
218
|
+
} else {
|
|
219
|
+
definition = idOrNameOrDefinition;
|
|
220
|
+
workflow = this.getWorkflowByName(definition.name);
|
|
221
|
+
if (!workflow) {
|
|
222
|
+
workflow = {
|
|
223
|
+
id: `wf_inline_${definition.name}`,
|
|
224
|
+
name: definition.name,
|
|
225
|
+
version: definition.version,
|
|
226
|
+
description: definition.description,
|
|
227
|
+
definition,
|
|
228
|
+
config: definition.config || {},
|
|
229
|
+
metadata: definition.metadata || {},
|
|
230
|
+
tags: definition.metadata?.tags || [],
|
|
231
|
+
createdAt: new Date,
|
|
232
|
+
updatedAt: new Date
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const engine = this.engineFactory(workflow, {
|
|
237
|
+
...options,
|
|
238
|
+
input
|
|
239
|
+
});
|
|
240
|
+
const result = await engine.runWorkflow(workflow, {
|
|
241
|
+
...options,
|
|
242
|
+
input
|
|
243
|
+
});
|
|
244
|
+
return {
|
|
245
|
+
...result,
|
|
246
|
+
runId: result.runId || result.sessionId || "",
|
|
247
|
+
sessionId: result.sessionId || result.runId || ""
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
async runWorkflowByName(name, input, options) {
|
|
251
|
+
const workflow = this.getWorkflowByName(name);
|
|
252
|
+
if (!workflow) {
|
|
253
|
+
throw new Error(`Workflow not found: ${name}`);
|
|
254
|
+
}
|
|
255
|
+
return this.runWorkflow(name, input, options);
|
|
256
|
+
}
|
|
257
|
+
async stopRun(sessionId, reason) {
|
|
258
|
+
const session = await this.sessionComponent?.get(sessionId);
|
|
259
|
+
if (!session) {
|
|
260
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
261
|
+
}
|
|
262
|
+
const metadata = session.metadata;
|
|
263
|
+
if (metadata.type !== "workflow") {
|
|
264
|
+
throw new Error(`Session is not a workflow session: ${sessionId}`);
|
|
265
|
+
}
|
|
266
|
+
const workflow = this.getWorkflowByName(metadata.workflowName);
|
|
267
|
+
if (!workflow) {
|
|
268
|
+
throw new Error(`Workflow not found: ${metadata.workflowName}`);
|
|
269
|
+
}
|
|
270
|
+
const engine = this.engineFactory(workflow);
|
|
271
|
+
await engine.stop(sessionId, reason);
|
|
272
|
+
}
|
|
273
|
+
async getSession(sessionId) {
|
|
274
|
+
if (!this.sessionComponent) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
const session = await this.sessionComponent.get(sessionId);
|
|
278
|
+
return session ?? null;
|
|
279
|
+
}
|
|
280
|
+
async listSessions(options) {
|
|
281
|
+
if (!this.sessionComponent?.list) {
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
return this.sessionComponent.list(options);
|
|
285
|
+
}
|
|
286
|
+
async getSessionMessages(sessionId) {
|
|
287
|
+
if (!this.sessionComponent) {
|
|
288
|
+
return [];
|
|
289
|
+
}
|
|
290
|
+
return this.sessionComponent.getMessages(sessionId);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
__legacyDecorateClassTS([
|
|
294
|
+
TracedAs("workflow.service.createWorkflow", {
|
|
295
|
+
recordParams: true,
|
|
296
|
+
recordResult: false,
|
|
297
|
+
log: false
|
|
298
|
+
})
|
|
299
|
+
], WorkflowService.prototype, "createWorkflow", null);
|
|
300
|
+
__legacyDecorateClassTS([
|
|
301
|
+
TracedAs("workflow.service.deleteWorkflow", {
|
|
302
|
+
recordParams: true,
|
|
303
|
+
recordResult: false,
|
|
304
|
+
log: false
|
|
305
|
+
})
|
|
306
|
+
], WorkflowService.prototype, "deleteWorkflow", null);
|
|
307
|
+
__legacyDecorateClassTS([
|
|
308
|
+
TracedAs("workflow.service.listWorkflowsWithTags", {
|
|
309
|
+
recordParams: true,
|
|
310
|
+
recordResult: false,
|
|
311
|
+
log: false
|
|
312
|
+
})
|
|
313
|
+
], WorkflowService.prototype, "listWorkflowsWithTags", null);
|
|
314
|
+
__legacyDecorateClassTS([
|
|
315
|
+
TracedAs("workflow.service.searchWorkflowsWithTags", {
|
|
316
|
+
recordParams: true,
|
|
317
|
+
recordResult: false,
|
|
318
|
+
log: false
|
|
319
|
+
})
|
|
320
|
+
], WorkflowService.prototype, "searchWorkflowsWithTags", null);
|
|
321
|
+
__legacyDecorateClassTS([
|
|
322
|
+
TracedAs("workflow.service.listTags", {
|
|
323
|
+
recordParams: true,
|
|
324
|
+
recordResult: false,
|
|
325
|
+
log: false
|
|
326
|
+
})
|
|
327
|
+
], WorkflowService.prototype, "listTags", null);
|
|
328
|
+
__legacyDecorateClassTS([
|
|
329
|
+
TracedAs("workflow.service.getTag", {
|
|
330
|
+
recordParams: true,
|
|
331
|
+
recordResult: false,
|
|
332
|
+
log: false
|
|
333
|
+
})
|
|
334
|
+
], WorkflowService.prototype, "getTag", null);
|
|
335
|
+
|
|
336
|
+
export { TAG_MIN_COUNT, TAG_MAX_COUNT, WorkflowService };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentComponentAdapter,
|
|
3
3
|
init_agent_component_adapter
|
|
4
|
-
} from "./roy-agent-core-
|
|
5
|
-
import"./roy-agent-core-
|
|
6
|
-
import"./roy-agent-core-whw7jap0.js";
|
|
4
|
+
} from "./roy-agent-core-5kdw0p98.js";
|
|
5
|
+
import"./roy-agent-core-1db4vpc6.js";
|
|
7
6
|
import"./roy-agent-core-e25xkv53.js";
|
|
8
7
|
import"./roy-agent-core-7tp56w6n.js";
|
|
9
8
|
import"./roy-agent-core-qg4rma4c.js";
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./roy-agent-core-e25xkv53.js";
|
|
8
8
|
import {
|
|
9
9
|
AgentRegistry
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-7z4xtrmw.js";
|
|
11
11
|
import {
|
|
12
12
|
ContextError
|
|
13
13
|
} from "./roy-agent-core-ctdhjv68.js";
|
|
@@ -301,6 +301,8 @@ class AgentComponent extends BaseComponent {
|
|
|
301
301
|
logger.info(`[AgentComponent] Loaded ${loadedCount} agents from config directory`);
|
|
302
302
|
this.registry.registerWorkflowAgent();
|
|
303
303
|
logger.info("[AgentComponent] Registered built-in workflow-agent");
|
|
304
|
+
this.registry.registerJsonExtractAgent();
|
|
305
|
+
logger.info("[AgentComponent] Registered built-in json-extract agent");
|
|
304
306
|
for (const agentDef of this.registry.list()) {
|
|
305
307
|
if (!this.agents.has(agentDef.name)) {
|
|
306
308
|
const systemPrompt = await this.registry.getSystemPrompt(agentDef.name);
|
|
@@ -935,6 +937,11 @@ class AgentComponent extends BaseComponent {
|
|
|
935
937
|
result.finalText = "Maximum iterations reached.";
|
|
936
938
|
}
|
|
937
939
|
const newMessages = hookCtx.messages.slice(historyMessageCount);
|
|
940
|
+
if (effectiveContext.persistSession !== false) {
|
|
941
|
+
await this.recordSessionMessages(effectiveContext.sessionId, newMessages);
|
|
942
|
+
} else {
|
|
943
|
+
logger.debug(`Skipping session message recording (persistSession=false, sessionId=${effectiveContext.sessionId})`);
|
|
944
|
+
}
|
|
938
945
|
const reactContext = {
|
|
939
946
|
messages: hookCtx.messages,
|
|
940
947
|
sessionId: effectiveContext.sessionId,
|
|
@@ -979,11 +986,6 @@ class AgentComponent extends BaseComponent {
|
|
|
979
986
|
historyMessageCount,
|
|
980
987
|
sessionId: effectiveContext.sessionId
|
|
981
988
|
});
|
|
982
|
-
if (effectiveContext.persistSession !== false) {
|
|
983
|
-
await this.recordSessionMessages(effectiveContext.sessionId, newMessages);
|
|
984
|
-
} else {
|
|
985
|
-
logger.debug(`Skipping session message recording (persistSession=false, sessionId=${effectiveContext.sessionId})`);
|
|
986
|
-
}
|
|
987
989
|
return this.finalizeResult(result, hookCtx);
|
|
988
990
|
});
|
|
989
991
|
}
|
package/package.json
CHANGED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// src/env/workflow/service/workflow-service.ts
|
|
2
|
-
class WorkflowService {
|
|
3
|
-
workflowRepository;
|
|
4
|
-
engineFactory;
|
|
5
|
-
sessionComponent;
|
|
6
|
-
constructor(workflowRepository, engineFactory, sessionComponent) {
|
|
7
|
-
this.workflowRepository = workflowRepository;
|
|
8
|
-
this.engineFactory = engineFactory;
|
|
9
|
-
this.sessionComponent = sessionComponent;
|
|
10
|
-
}
|
|
11
|
-
async createWorkflow(definition, options) {
|
|
12
|
-
const existing = this.workflowRepository.getByName(definition.name);
|
|
13
|
-
if (existing) {
|
|
14
|
-
if (options?.force !== true) {
|
|
15
|
-
throw new Error(`Workflow already exists: ${definition.name}`);
|
|
16
|
-
}
|
|
17
|
-
return this.workflowRepository.update(existing.id, {
|
|
18
|
-
name: definition.name,
|
|
19
|
-
version: definition.version,
|
|
20
|
-
description: definition.description || existing.description,
|
|
21
|
-
definition,
|
|
22
|
-
config: definition.config || {},
|
|
23
|
-
metadata: {
|
|
24
|
-
...options.metadata || definition.metadata || existing.metadata || {},
|
|
25
|
-
taskId: options.taskId || definition.metadata?.taskId || existing.metadata?.taskId
|
|
26
|
-
},
|
|
27
|
-
tags: options.tags || definition.metadata?.tags || []
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const workflow = {
|
|
31
|
-
name: definition.name,
|
|
32
|
-
version: definition.version,
|
|
33
|
-
description: definition.description,
|
|
34
|
-
definition,
|
|
35
|
-
config: definition.config || {},
|
|
36
|
-
metadata: {
|
|
37
|
-
...options?.metadata || definition.metadata || {},
|
|
38
|
-
taskId: options?.taskId || definition.metadata?.taskId
|
|
39
|
-
},
|
|
40
|
-
tags: options?.tags || definition.metadata?.tags || []
|
|
41
|
-
};
|
|
42
|
-
return this.workflowRepository.create(workflow);
|
|
43
|
-
}
|
|
44
|
-
getWorkflow(idOrName) {
|
|
45
|
-
let workflow = this.workflowRepository.getById(idOrName);
|
|
46
|
-
if (workflow)
|
|
47
|
-
return workflow;
|
|
48
|
-
return this.workflowRepository.getByName(idOrName);
|
|
49
|
-
}
|
|
50
|
-
getWorkflowById(id) {
|
|
51
|
-
return this.workflowRepository.getById(id);
|
|
52
|
-
}
|
|
53
|
-
getWorkflowByName(name) {
|
|
54
|
-
return this.workflowRepository.getByName(name);
|
|
55
|
-
}
|
|
56
|
-
listWorkflows(options) {
|
|
57
|
-
return this.workflowRepository.list(options);
|
|
58
|
-
}
|
|
59
|
-
async updateWorkflow(idOrName, updates, options) {
|
|
60
|
-
let workflow = this.workflowRepository.getByName(idOrName);
|
|
61
|
-
if (!workflow) {
|
|
62
|
-
workflow = this.workflowRepository.getById(idOrName);
|
|
63
|
-
}
|
|
64
|
-
if (!workflow) {
|
|
65
|
-
throw new Error(`Workflow not found: ${idOrName}`);
|
|
66
|
-
}
|
|
67
|
-
const updateData = {
|
|
68
|
-
...updates
|
|
69
|
-
};
|
|
70
|
-
if (options?.tags !== undefined) {
|
|
71
|
-
updateData.tags = options.tags;
|
|
72
|
-
}
|
|
73
|
-
const updated = this.workflowRepository.update(workflow.id, updateData);
|
|
74
|
-
if (!updated) {
|
|
75
|
-
throw new Error(`Failed to update workflow: ${idOrName}`);
|
|
76
|
-
}
|
|
77
|
-
return updated;
|
|
78
|
-
}
|
|
79
|
-
async deleteWorkflow(idOrName) {
|
|
80
|
-
let workflow = this.workflowRepository.getByName(idOrName);
|
|
81
|
-
if (!workflow) {
|
|
82
|
-
workflow = this.workflowRepository.getById(idOrName);
|
|
83
|
-
}
|
|
84
|
-
if (!workflow) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
return this.workflowRepository.delete(workflow.id);
|
|
88
|
-
}
|
|
89
|
-
async runWorkflow(idOrNameOrDefinition, input, options) {
|
|
90
|
-
let workflow = null;
|
|
91
|
-
let definition = null;
|
|
92
|
-
if (typeof idOrNameOrDefinition === "string") {
|
|
93
|
-
workflow = this.getWorkflow(idOrNameOrDefinition);
|
|
94
|
-
if (!workflow) {
|
|
95
|
-
throw new Error(`Workflow not found: ${idOrNameOrDefinition}`);
|
|
96
|
-
}
|
|
97
|
-
definition = workflow.definition;
|
|
98
|
-
} else {
|
|
99
|
-
definition = idOrNameOrDefinition;
|
|
100
|
-
workflow = this.getWorkflowByName(definition.name);
|
|
101
|
-
if (!workflow) {
|
|
102
|
-
workflow = {
|
|
103
|
-
id: `wf_inline_${definition.name}`,
|
|
104
|
-
name: definition.name,
|
|
105
|
-
version: definition.version,
|
|
106
|
-
description: definition.description,
|
|
107
|
-
definition,
|
|
108
|
-
config: definition.config || {},
|
|
109
|
-
metadata: definition.metadata || {},
|
|
110
|
-
tags: definition.metadata?.tags || [],
|
|
111
|
-
createdAt: new Date,
|
|
112
|
-
updatedAt: new Date
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const engine = this.engineFactory(workflow, {
|
|
117
|
-
...options,
|
|
118
|
-
input
|
|
119
|
-
});
|
|
120
|
-
const result = await engine.runWorkflow(workflow, {
|
|
121
|
-
...options,
|
|
122
|
-
input
|
|
123
|
-
});
|
|
124
|
-
return {
|
|
125
|
-
...result,
|
|
126
|
-
runId: result.runId || result.sessionId || "",
|
|
127
|
-
sessionId: result.sessionId || result.runId || ""
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
async runWorkflowByName(name, input, options) {
|
|
131
|
-
const workflow = this.getWorkflowByName(name);
|
|
132
|
-
if (!workflow) {
|
|
133
|
-
throw new Error(`Workflow not found: ${name}`);
|
|
134
|
-
}
|
|
135
|
-
return this.runWorkflow(name, input, options);
|
|
136
|
-
}
|
|
137
|
-
async stopRun(sessionId, reason) {
|
|
138
|
-
const session = await this.sessionComponent?.get(sessionId);
|
|
139
|
-
if (!session) {
|
|
140
|
-
throw new Error(`Session not found: ${sessionId}`);
|
|
141
|
-
}
|
|
142
|
-
const metadata = session.metadata;
|
|
143
|
-
if (metadata.type !== "workflow") {
|
|
144
|
-
throw new Error(`Session is not a workflow session: ${sessionId}`);
|
|
145
|
-
}
|
|
146
|
-
const workflow = this.getWorkflowByName(metadata.workflowName);
|
|
147
|
-
if (!workflow) {
|
|
148
|
-
throw new Error(`Workflow not found: ${metadata.workflowName}`);
|
|
149
|
-
}
|
|
150
|
-
const engine = this.engineFactory(workflow);
|
|
151
|
-
await engine.stop(sessionId, reason);
|
|
152
|
-
}
|
|
153
|
-
async getSession(sessionId) {
|
|
154
|
-
if (!this.sessionComponent) {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
const session = await this.sessionComponent.get(sessionId);
|
|
158
|
-
return session ?? null;
|
|
159
|
-
}
|
|
160
|
-
async listSessions(options) {
|
|
161
|
-
if (!this.sessionComponent?.list) {
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
return this.sessionComponent.list(options);
|
|
165
|
-
}
|
|
166
|
-
async getSessionMessages(sessionId) {
|
|
167
|
-
if (!this.sessionComponent) {
|
|
168
|
-
return [];
|
|
169
|
-
}
|
|
170
|
-
return this.sessionComponent.getMessages(sessionId);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// src/env/workflow/service/registry.ts
|
|
174
|
-
class WorkflowServiceRegistry {
|
|
175
|
-
static instance;
|
|
176
|
-
service = null;
|
|
177
|
-
constructor() {}
|
|
178
|
-
static getInstance() {
|
|
179
|
-
if (!WorkflowServiceRegistry.instance) {
|
|
180
|
-
WorkflowServiceRegistry.instance = new WorkflowServiceRegistry;
|
|
181
|
-
}
|
|
182
|
-
return WorkflowServiceRegistry.instance;
|
|
183
|
-
}
|
|
184
|
-
register(service) {
|
|
185
|
-
this.service = service;
|
|
186
|
-
}
|
|
187
|
-
get() {
|
|
188
|
-
if (!this.service) {
|
|
189
|
-
throw new Error("WorkflowService is not registered. Call register() first.");
|
|
190
|
-
}
|
|
191
|
-
return this.service;
|
|
192
|
-
}
|
|
193
|
-
isRegistered() {
|
|
194
|
-
return this.service !== null;
|
|
195
|
-
}
|
|
196
|
-
reset() {
|
|
197
|
-
this.service = null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
function getWorkflowService() {
|
|
201
|
-
return WorkflowServiceRegistry.getInstance().get();
|
|
202
|
-
}
|
|
203
|
-
function registerWorkflowService(service) {
|
|
204
|
-
WorkflowServiceRegistry.getInstance().register(service);
|
|
205
|
-
}
|
|
206
|
-
export { WorkflowService, WorkflowServiceRegistry, getWorkflowService, registerWorkflowService };
|