@ai-setting/roy-agent-core 1.5.83 → 1.5.84
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/event-source/index.js +2 -2
- package/dist/env/index.js +7 -6
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/task/plugins/index.js +1 -1
- package/dist/env/workflow/index.js +4 -3
- 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 +15 -1
- package/dist/index.js +10 -8
- 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-78yzt2bq.js → roy-agent-core-7fdzfsm6.js} +2 -2
- 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-vcvgq9hy.js → roy-agent-core-akepggsr.js} +102 -5
- package/dist/shared/@ai-setting/{roy-agent-core-v3t28k5n.js → roy-agent-core-bt7wezvg.js} +19 -10
- package/dist/shared/@ai-setting/roy-agent-core-c67wr8sp.js +11 -0
- 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-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-67yzhmg2.js → roy-agent-core-ya1ayt1k.js} +1 -1
- 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-a6j7g1qe.js +0 -428
|
@@ -7,17 +7,20 @@ import {
|
|
|
7
7
|
exports_engine,
|
|
8
8
|
init_engine
|
|
9
9
|
} from "./roy-agent-core-6b0r2e7j.js";
|
|
10
|
-
import {
|
|
11
|
-
WorkflowService
|
|
12
|
-
} from "./roy-agent-core-4t40mkpv.js";
|
|
13
10
|
import {
|
|
14
11
|
askUserTool,
|
|
15
12
|
createRunWorkflowTool,
|
|
13
|
+
createWorkflowAddTool,
|
|
16
14
|
createWorkflowGetTool,
|
|
17
15
|
createWorkflowListTool,
|
|
18
16
|
createWorkflowRunStatusTool,
|
|
19
|
-
createWorkflowRunStopTool
|
|
20
|
-
|
|
17
|
+
createWorkflowRunStopTool,
|
|
18
|
+
createWorkflowSearchTool,
|
|
19
|
+
createWorkflowTagListTool
|
|
20
|
+
} from "./roy-agent-core-r5axf0ad.js";
|
|
21
|
+
import {
|
|
22
|
+
WorkflowService
|
|
23
|
+
} from "./roy-agent-core-tq9528d3.js";
|
|
21
24
|
import {
|
|
22
25
|
BaseComponent
|
|
23
26
|
} from "./roy-agent-core-rgckng3p.js";
|
|
@@ -128,7 +131,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
128
131
|
registerDecoratorNodeType2(registry);
|
|
129
132
|
return new WorkflowEngine2(registry, sessionComponentForEngine, options.workflowRepository);
|
|
130
133
|
};
|
|
131
|
-
this.workflowService = new WorkflowService(options.workflowRepository, engineFactory, options.sessionComponent);
|
|
134
|
+
this.workflowService = new WorkflowService(options.workflowRepository, engineFactory, options.sessionComponent, options.tagRepository);
|
|
132
135
|
return this.workflowService;
|
|
133
136
|
}
|
|
134
137
|
async runWorkflow(definition, input, options) {
|
|
@@ -164,7 +167,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
164
167
|
if (this.workflowService) {
|
|
165
168
|
this.workflowService = null;
|
|
166
169
|
try {
|
|
167
|
-
const { closeDatabase } = await import("./roy-agent-core-
|
|
170
|
+
const { closeDatabase } = await import("./roy-agent-core-taxvytzz.js");
|
|
168
171
|
closeDatabase();
|
|
169
172
|
componentLogger.info("[WorkflowComponent] SQLite database closed");
|
|
170
173
|
} catch (error) {
|
|
@@ -214,6 +217,9 @@ class WorkflowComponent extends BaseComponent {
|
|
|
214
217
|
const tools = [
|
|
215
218
|
createWorkflowGetTool(this.workflowService),
|
|
216
219
|
createWorkflowListTool(this.workflowService),
|
|
220
|
+
createWorkflowAddTool(this.workflowService),
|
|
221
|
+
createWorkflowSearchTool(this.workflowService),
|
|
222
|
+
createWorkflowTagListTool(this.workflowService),
|
|
217
223
|
createRunWorkflowTool(this.workflowService),
|
|
218
224
|
createWorkflowRunStatusTool(this.workflowService),
|
|
219
225
|
createWorkflowRunStopTool(this.workflowService)
|
|
@@ -228,11 +234,13 @@ class WorkflowComponent extends BaseComponent {
|
|
|
228
234
|
}
|
|
229
235
|
async initSqliteService() {
|
|
230
236
|
try {
|
|
231
|
-
const { getDatabase, initializeTables } = await import("./roy-agent-core-
|
|
232
|
-
const { WorkflowRepository } = await import("./roy-agent-core-
|
|
237
|
+
const { getDatabase, initializeTables } = await import("./roy-agent-core-taxvytzz.js");
|
|
238
|
+
const { WorkflowRepository } = await import("./roy-agent-core-86d4exyf.js");
|
|
239
|
+
const { TagRepository } = await import("./roy-agent-core-c67wr8sp.js");
|
|
233
240
|
const db = getDatabase();
|
|
234
241
|
initializeTables();
|
|
235
242
|
const workflowRepository = new WorkflowRepository(db);
|
|
243
|
+
const tagRepository = new TagRepository(db);
|
|
236
244
|
const toolComponent = this.toolComponent || this._workflowEnv?.getComponent("tool");
|
|
237
245
|
const llmComponent = this.llmComponent || this._workflowEnv?.getComponent("llm");
|
|
238
246
|
const agentComponent = this._workflowEnv?.getComponent("agent");
|
|
@@ -245,6 +253,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
245
253
|
}
|
|
246
254
|
this.createService({
|
|
247
255
|
workflowRepository,
|
|
256
|
+
tagRepository,
|
|
248
257
|
toolComponent,
|
|
249
258
|
llmComponent,
|
|
250
259
|
env: this._workflowEnv,
|
|
@@ -299,7 +308,7 @@ class WorkflowComponent extends BaseComponent {
|
|
|
299
308
|
this.workflowService = null;
|
|
300
309
|
this.nodeRegistry = null;
|
|
301
310
|
try {
|
|
302
|
-
const { closeDatabase } = await import("./roy-agent-core-
|
|
311
|
+
const { closeDatabase } = await import("./roy-agent-core-taxvytzz.js");
|
|
303
312
|
closeDatabase();
|
|
304
313
|
} catch {}
|
|
305
314
|
this._status = "stopped";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TagRepository
|
|
3
|
+
} from "./roy-agent-core-3sv590cv.js";
|
|
4
|
+
import"./roy-agent-core-k05v31rc.js";
|
|
5
|
+
import"./roy-agent-core-shme7set.js";
|
|
6
|
+
import"./roy-agent-core-7z9b1fm8.js";
|
|
7
|
+
import"./roy-agent-core-c6592r3c.js";
|
|
8
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
9
|
+
export {
|
|
10
|
+
TagRepository
|
|
11
|
+
};
|
|
@@ -1,16 +1,135 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./roy-agent-core-
|
|
2
|
+
TagRepository
|
|
3
|
+
} from "./roy-agent-core-3sv590cv.js";
|
|
4
4
|
import {
|
|
5
5
|
exports_search_query_parser,
|
|
6
6
|
init_search_query_parser
|
|
7
7
|
} from "./roy-agent-core-rvxg1wps.js";
|
|
8
8
|
import {
|
|
9
|
+
createLogger,
|
|
10
|
+
init_logger
|
|
11
|
+
} from "./roy-agent-core-shme7set.js";
|
|
12
|
+
import {
|
|
13
|
+
__require,
|
|
9
14
|
__toCommonJS
|
|
10
15
|
} from "./roy-agent-core-fs0mn2jk.js";
|
|
11
16
|
|
|
12
17
|
// src/env/workflow/storage/workflow-repo.ts
|
|
13
18
|
import { randomUUID } from "crypto";
|
|
19
|
+
|
|
20
|
+
// src/env/workflow/storage/sqlite.ts
|
|
21
|
+
init_logger();
|
|
22
|
+
import { join } from "path";
|
|
23
|
+
var logger = createLogger("workflow:sqlite");
|
|
24
|
+
function getDatabaseClass() {
|
|
25
|
+
if (typeof Bun !== "undefined") {
|
|
26
|
+
const { Database } = __require("bun:sqlite");
|
|
27
|
+
return Database;
|
|
28
|
+
} else {
|
|
29
|
+
return __require("better-sqlite3");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function createCompatibleDatabase(path) {
|
|
33
|
+
const Database = getDatabaseClass();
|
|
34
|
+
const db = new Database(path);
|
|
35
|
+
if (typeof db.run !== "function") {
|
|
36
|
+
db.run = function(sql, ...params) {
|
|
37
|
+
if (params.length > 0) {
|
|
38
|
+
return this.prepare(sql).run(...params);
|
|
39
|
+
} else {
|
|
40
|
+
return this.exec(sql);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return db;
|
|
45
|
+
}
|
|
46
|
+
function getDefaultDataDir() {
|
|
47
|
+
const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
48
|
+
return join(home, ".local", "share", "roy-agent");
|
|
49
|
+
}
|
|
50
|
+
function getDatabasePath() {
|
|
51
|
+
return join(getDefaultDataDir(), "workflows.db");
|
|
52
|
+
}
|
|
53
|
+
var dbInstance = null;
|
|
54
|
+
function getDatabase(path) {
|
|
55
|
+
if (!dbInstance) {
|
|
56
|
+
const dbPath = path ?? getDatabasePath();
|
|
57
|
+
const dbDir = dbPath.substring(0, dbPath.lastIndexOf("/"));
|
|
58
|
+
if (dbDir && dbDir !== "/") {
|
|
59
|
+
try {
|
|
60
|
+
const { mkdirSync } = __require("fs");
|
|
61
|
+
mkdirSync(dbDir, { recursive: true });
|
|
62
|
+
} catch {}
|
|
63
|
+
}
|
|
64
|
+
dbInstance = createCompatibleDatabase(dbPath);
|
|
65
|
+
try {
|
|
66
|
+
if (typeof dbInstance.pragma === "function") {
|
|
67
|
+
dbInstance.pragma("journal_mode = WAL");
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
logger?.debug("WAL mode not available, using default journal mode");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return dbInstance;
|
|
74
|
+
}
|
|
75
|
+
function closeDatabase() {
|
|
76
|
+
if (dbInstance) {
|
|
77
|
+
dbInstance.close();
|
|
78
|
+
dbInstance = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function initializeTables() {
|
|
82
|
+
const db = getDatabase();
|
|
83
|
+
db.exec(`
|
|
84
|
+
CREATE TABLE IF NOT EXISTS workflows (
|
|
85
|
+
id TEXT PRIMARY KEY,
|
|
86
|
+
name TEXT NOT NULL UNIQUE,
|
|
87
|
+
version TEXT NOT NULL DEFAULT '1.0',
|
|
88
|
+
description TEXT,
|
|
89
|
+
definition TEXT NOT NULL,
|
|
90
|
+
config TEXT NOT NULL DEFAULT '{}',
|
|
91
|
+
metadata TEXT NOT NULL DEFAULT '{}',
|
|
92
|
+
tags TEXT NOT NULL DEFAULT '[]',
|
|
93
|
+
task_id INTEGER,
|
|
94
|
+
created_at TEXT NOT NULL,
|
|
95
|
+
updated_at TEXT NOT NULL
|
|
96
|
+
)
|
|
97
|
+
`);
|
|
98
|
+
db.exec(`
|
|
99
|
+
CREATE INDEX IF NOT EXISTS idx_workflows_name ON workflows(name);
|
|
100
|
+
CREATE INDEX IF NOT EXISTS idx_workflows_tags ON workflows(tags);
|
|
101
|
+
CREATE INDEX IF NOT EXISTS idx_workflows_task_id ON workflows(task_id);
|
|
102
|
+
`);
|
|
103
|
+
TagRepository.createTable(db);
|
|
104
|
+
const migrated = migrateEmptyTagsToDefault(db);
|
|
105
|
+
if (migrated > 0) {
|
|
106
|
+
logger?.info?.(`[workflow:sqlite] Auto-migrated ${migrated} workflow(s) to default tag`);
|
|
107
|
+
}
|
|
108
|
+
const countRow = db.prepare("SELECT COUNT(*) as c FROM workflows WHERE tags LIKE ?").get('%"default"%');
|
|
109
|
+
const expectedDefaultCount = countRow.c;
|
|
110
|
+
if (expectedDefaultCount > 0) {
|
|
111
|
+
const tagRepo = new TagRepository(db);
|
|
112
|
+
const existing = tagRepo.get("default");
|
|
113
|
+
const now = new Date().toISOString();
|
|
114
|
+
if (!existing) {
|
|
115
|
+
db.prepare(`INSERT INTO workflow_tags (name, usage_count, created_at, updated_at)
|
|
116
|
+
VALUES ('default', ?, ?, ?)`).run(expectedDefaultCount, now, now);
|
|
117
|
+
} else if (existing.usage_count !== expectedDefaultCount) {
|
|
118
|
+
db.prepare("UPDATE workflow_tags SET usage_count = ?, updated_at = ? WHERE name = ?").run(expectedDefaultCount, now, "default");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function resetDatabase() {
|
|
123
|
+
closeDatabase();
|
|
124
|
+
dbInstance = null;
|
|
125
|
+
}
|
|
126
|
+
function initDatabase(path) {
|
|
127
|
+
const db = getDatabase(path);
|
|
128
|
+
initializeTables();
|
|
129
|
+
return db;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/env/workflow/storage/workflow-repo.ts
|
|
14
133
|
function rowToWorkflow(row) {
|
|
15
134
|
const metadata = JSON.parse(row.metadata);
|
|
16
135
|
if (row.task_id !== null) {
|
|
@@ -185,6 +304,38 @@ class WorkflowRepository {
|
|
|
185
304
|
const result = this.db.prepare("SELECT COUNT(*) as count FROM workflows").get();
|
|
186
305
|
return result.count;
|
|
187
306
|
}
|
|
307
|
+
countAll(options) {
|
|
308
|
+
let sql = "SELECT * FROM workflows";
|
|
309
|
+
const params = [];
|
|
310
|
+
const conditions = [];
|
|
311
|
+
if (options?.tag) {
|
|
312
|
+
conditions.push("tags LIKE ?");
|
|
313
|
+
params.push(`%${options.tag}%`);
|
|
314
|
+
}
|
|
315
|
+
if (options?.taskId !== undefined) {
|
|
316
|
+
conditions.push("task_id = ?");
|
|
317
|
+
params.push(options.taskId);
|
|
318
|
+
}
|
|
319
|
+
if (conditions.length > 0) {
|
|
320
|
+
sql += " WHERE " + conditions.join(" AND ");
|
|
321
|
+
}
|
|
322
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
323
|
+
let workflows = rows.map(rowToWorkflow);
|
|
324
|
+
if (options?.tags && options.tags.length > 0) {
|
|
325
|
+
const requiredTags = options.tags;
|
|
326
|
+
workflows = workflows.filter((w) => requiredTags.every((t) => w.tags.includes(t)));
|
|
327
|
+
}
|
|
328
|
+
if (options?.search) {
|
|
329
|
+
const { parseSearchQuery, matchesQuery } = (init_search_query_parser(), __toCommonJS(exports_search_query_parser));
|
|
330
|
+
const query = parseSearchQuery(options.search);
|
|
331
|
+
workflows = workflows.filter((w) => {
|
|
332
|
+
const descMatch = w.description ? matchesQuery(w.description, query) : false;
|
|
333
|
+
const tagsMatch = w.tags.some((tag) => matchesQuery(tag, query));
|
|
334
|
+
return descMatch || tagsMatch;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return workflows.length;
|
|
338
|
+
}
|
|
188
339
|
search(query, limit) {
|
|
189
340
|
let sql = "SELECT * FROM workflows WHERE name LIKE ? ORDER BY updated_at DESC";
|
|
190
341
|
const params = [`%${query}%`];
|
|
@@ -195,6 +346,35 @@ class WorkflowRepository {
|
|
|
195
346
|
const rows = this.db.prepare(sql).all(...params);
|
|
196
347
|
return rows.map(rowToWorkflow);
|
|
197
348
|
}
|
|
349
|
+
migrateEmptyTagsToDefault() {
|
|
350
|
+
return migrateEmptyTagsToDefault(this.db);
|
|
351
|
+
}
|
|
352
|
+
transaction(fn) {
|
|
353
|
+
this.db.exec("BEGIN");
|
|
354
|
+
try {
|
|
355
|
+
const result = fn();
|
|
356
|
+
this.db.exec("COMMIT");
|
|
357
|
+
return result;
|
|
358
|
+
} catch (e) {
|
|
359
|
+
try {
|
|
360
|
+
this.db.exec("ROLLBACK");
|
|
361
|
+
} catch {}
|
|
362
|
+
throw e;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function migrateEmptyTagsToDefault(db) {
|
|
367
|
+
const DEFAULT_TAG_VALUE = "default";
|
|
368
|
+
const rows = db.prepare("SELECT id FROM workflows WHERE tags IS NULL OR tags = '' OR tags = '[]'").all();
|
|
369
|
+
if (rows.length === 0)
|
|
370
|
+
return 0;
|
|
371
|
+
const updateStmt = db.prepare("UPDATE workflows SET tags = ?, updated_at = ? WHERE id = ?");
|
|
372
|
+
const now = new Date().toISOString();
|
|
373
|
+
const defaultTagsJson = JSON.stringify([DEFAULT_TAG_VALUE]);
|
|
374
|
+
for (const row of rows) {
|
|
375
|
+
updateStmt.run(defaultTagsJson, now, row.id);
|
|
376
|
+
}
|
|
377
|
+
return rows.length;
|
|
198
378
|
}
|
|
199
379
|
|
|
200
|
-
export { rowToWorkflow, WorkflowRepository };
|
|
380
|
+
export { rowToWorkflow, WorkflowRepository, migrateEmptyTagsToDefault, getDatabasePath, getDatabase, closeDatabase, initializeTables, resetDatabase, initDatabase };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/env/workflow/service/registry.ts
|
|
2
|
+
class WorkflowServiceRegistry {
|
|
3
|
+
static instance;
|
|
4
|
+
service = null;
|
|
5
|
+
constructor() {}
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!WorkflowServiceRegistry.instance) {
|
|
8
|
+
WorkflowServiceRegistry.instance = new WorkflowServiceRegistry;
|
|
9
|
+
}
|
|
10
|
+
return WorkflowServiceRegistry.instance;
|
|
11
|
+
}
|
|
12
|
+
register(service) {
|
|
13
|
+
this.service = service;
|
|
14
|
+
}
|
|
15
|
+
get() {
|
|
16
|
+
if (!this.service) {
|
|
17
|
+
throw new Error("WorkflowService is not registered. Call register() first.");
|
|
18
|
+
}
|
|
19
|
+
return this.service;
|
|
20
|
+
}
|
|
21
|
+
isRegistered() {
|
|
22
|
+
return this.service !== null;
|
|
23
|
+
}
|
|
24
|
+
reset() {
|
|
25
|
+
this.service = null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getWorkflowService() {
|
|
29
|
+
return WorkflowServiceRegistry.getInstance().get();
|
|
30
|
+
}
|
|
31
|
+
function registerWorkflowService(service) {
|
|
32
|
+
WorkflowServiceRegistry.getInstance().register(service);
|
|
33
|
+
}
|
|
34
|
+
export { WorkflowServiceRegistry, getWorkflowService, registerWorkflowService };
|