@ai-setting/roy-agent-core 1.5.81 → 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/agent/index.js +1 -1
- package/dist/env/event-source/index.js +2 -2
- package/dist/env/index.js +11 -10
- package/dist/env/prompt/index.js +1 -1
- package/dist/env/task/index.js +3 -3
- package/dist/env/task/plugins/index.js +1 -1
- package/dist/env/task/storage/index.js +1 -1
- package/dist/env/task/tools/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 +14 -12
- package/dist/shared/@ai-setting/{roy-agent-core-qbgd7bp6.js → roy-agent-core-015vw11k.js} +27 -1
- package/dist/shared/@ai-setting/{roy-agent-core-t2q0rwt7.js → roy-agent-core-29fh9mxg.js} +4 -7
- package/dist/shared/@ai-setting/roy-agent-core-3sv590cv.js +132 -0
- package/dist/shared/@ai-setting/{roy-agent-core-w83v54mj.js → roy-agent-core-7fdzfsm6.js} +42 -135
- package/dist/shared/@ai-setting/{roy-agent-core-df3ng0pz.js → roy-agent-core-7nh5h9fn.js} +31 -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-vgyj2rq9.js → roy-agent-core-akepggsr.js} +150 -6
- 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-r9y8ct0w.js → roy-agent-core-pcdzfwdv.js} +4 -0
- package/dist/shared/@ai-setting/{roy-agent-core-p8jv13bm.js → roy-agent-core-qjv8537d.js} +2 -2
- 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-j8q8119y.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
|
@@ -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 };
|
|
@@ -287,6 +287,10 @@ class SQLiteTaskStore {
|
|
|
287
287
|
updates.push("context = ?");
|
|
288
288
|
values.push(options.context);
|
|
289
289
|
}
|
|
290
|
+
if (options.parent_task_id !== undefined) {
|
|
291
|
+
updates.push("parent_task_id = ?");
|
|
292
|
+
values.push(options.parent_task_id);
|
|
293
|
+
}
|
|
290
294
|
if (updates.length === 0)
|
|
291
295
|
return task;
|
|
292
296
|
updates.push("updated_at = ?");
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
SQLiteTaskStore,
|
|
11
11
|
getDefaultTaskDbPath
|
|
12
|
-
} from "./roy-agent-core-
|
|
12
|
+
} from "./roy-agent-core-pcdzfwdv.js";
|
|
13
13
|
import {
|
|
14
14
|
batchArchiveTaskTool,
|
|
15
15
|
batchDeleteTaskTool,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
listTasksTool,
|
|
21
21
|
searchTasksTool,
|
|
22
22
|
updateTaskTool
|
|
23
|
-
} from "./roy-agent-core-
|
|
23
|
+
} from "./roy-agent-core-7nh5h9fn.js";
|
|
24
24
|
import {
|
|
25
25
|
createOperationTool,
|
|
26
26
|
deleteOperationTool,
|