@ai-setting/roy-agent-core 1.4.11 → 1.4.13

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.
@@ -0,0 +1,205 @@
1
+ import {
2
+ exports_search_query_parser,
3
+ init_search_query_parser
4
+ } from "./chunk-ze20rksg.js";
5
+ import {
6
+ getDatabase
7
+ } from "./chunk-1pf5mfgd.js";
8
+ import"./chunk-a9qmy3sc.js";
9
+ import"./chunk-q9j99fsm.js";
10
+ import"./chunk-1qwabsm0.js";
11
+ import {
12
+ __toCommonJS
13
+ } from "./chunk-wbkh7wat.js";
14
+
15
+ // src/env/workflow/storage/workflow-repo.ts
16
+ import { randomUUID } from "crypto";
17
+ function rowToWorkflow(row) {
18
+ const metadata = JSON.parse(row.metadata);
19
+ if (row.task_id !== null) {
20
+ metadata.taskId = row.task_id;
21
+ }
22
+ return {
23
+ id: row.id,
24
+ name: row.name,
25
+ version: row.version,
26
+ description: row.description || undefined,
27
+ definition: JSON.parse(row.definition),
28
+ config: JSON.parse(row.config),
29
+ metadata,
30
+ tags: JSON.parse(row.tags),
31
+ createdAt: new Date(row.created_at),
32
+ updatedAt: new Date(row.updated_at)
33
+ };
34
+ }
35
+
36
+ class WorkflowRepository {
37
+ db;
38
+ constructor(db) {
39
+ this.db = db || getDatabase();
40
+ }
41
+ create(workflow) {
42
+ const id = randomUUID();
43
+ const now = new Date().toISOString();
44
+ const stmt = this.db.prepare(`
45
+ INSERT INTO workflows (id, name, version, description, definition, config, metadata, tags, task_id, created_at, updated_at)
46
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
47
+ `);
48
+ stmt.run(id, workflow.name, workflow.version, workflow.description || null, JSON.stringify(workflow.definition), JSON.stringify(workflow.config), JSON.stringify(workflow.metadata), JSON.stringify(workflow.tags), workflow.metadata?.taskId || null, now, now);
49
+ return {
50
+ ...workflow,
51
+ id,
52
+ createdAt: new Date(now),
53
+ updatedAt: new Date(now)
54
+ };
55
+ }
56
+ createFromDefinition(definition, options) {
57
+ const workflow = {
58
+ name: definition.name,
59
+ version: definition.version,
60
+ description: definition.description,
61
+ definition,
62
+ config: options?.config || definition.config || {},
63
+ metadata: options?.metadata || definition.metadata || {},
64
+ tags: options?.tags || definition.metadata?.tags || []
65
+ };
66
+ return this.create(workflow);
67
+ }
68
+ getById(id) {
69
+ const row = this.db.prepare("SELECT * FROM workflows WHERE id = ?").get(id);
70
+ if (!row)
71
+ return;
72
+ return rowToWorkflow(row);
73
+ }
74
+ getByName(name) {
75
+ const row = this.db.prepare("SELECT * FROM workflows WHERE name = ? ORDER BY updated_at DESC LIMIT 1").get(name);
76
+ if (!row)
77
+ return;
78
+ return rowToWorkflow(row);
79
+ }
80
+ getByNameAndVersion(name, version) {
81
+ const row = this.db.prepare("SELECT * FROM workflows WHERE name = ? AND version = ?").get(name, version);
82
+ if (!row)
83
+ return;
84
+ return rowToWorkflow(row);
85
+ }
86
+ list(options) {
87
+ let sql = "SELECT * FROM workflows";
88
+ const params = [];
89
+ const conditions = [];
90
+ if (options?.tag) {
91
+ conditions.push("tags LIKE ?");
92
+ params.push(`%${options.tag}%`);
93
+ }
94
+ if (options?.taskId !== undefined) {
95
+ conditions.push("task_id = ?");
96
+ params.push(options.taskId);
97
+ }
98
+ if (conditions.length > 0) {
99
+ sql += " WHERE " + conditions.join(" AND ");
100
+ }
101
+ const orderBy = options?.orderBy || "updated_at";
102
+ const order = options?.order || "desc";
103
+ sql += ` ORDER BY ${orderBy} ${order.toUpperCase()}`;
104
+ if (options?.limit !== undefined) {
105
+ sql += " LIMIT ?";
106
+ params.push(options.limit);
107
+ }
108
+ if (options?.offset !== undefined) {
109
+ sql += " OFFSET ?";
110
+ params.push(options.offset);
111
+ }
112
+ const rows = this.db.prepare(sql).all(...params);
113
+ let workflows = rows.map(rowToWorkflow);
114
+ if (options?.search) {
115
+ const { parseSearchQuery, matchesQuery } = (init_search_query_parser(), __toCommonJS(exports_search_query_parser));
116
+ const query = parseSearchQuery(options.search);
117
+ workflows = workflows.filter((w) => {
118
+ const descMatch = w.description ? matchesQuery(w.description, query) : false;
119
+ const tagsMatch = w.tags.some((tag) => matchesQuery(tag, query));
120
+ return descMatch || tagsMatch;
121
+ });
122
+ }
123
+ return workflows;
124
+ }
125
+ listVersions(name) {
126
+ const rows = this.db.prepare("SELECT * FROM workflows WHERE name = ? ORDER BY version DESC").all(name);
127
+ return rows.map(rowToWorkflow);
128
+ }
129
+ update(id, updates) {
130
+ const existing = this.getById(id);
131
+ if (!existing)
132
+ return;
133
+ const now = new Date().toISOString();
134
+ const setClauses = ["updated_at = ?"];
135
+ const params = [now];
136
+ if (updates.name !== undefined) {
137
+ setClauses.push("name = ?");
138
+ params.push(updates.name);
139
+ }
140
+ if (updates.version !== undefined) {
141
+ setClauses.push("version = ?");
142
+ params.push(updates.version);
143
+ }
144
+ if (updates.description !== undefined) {
145
+ setClauses.push("description = ?");
146
+ params.push(updates.description);
147
+ }
148
+ if (updates.definition !== undefined) {
149
+ setClauses.push("definition = ?");
150
+ params.push(JSON.stringify(updates.definition));
151
+ }
152
+ if (updates.config !== undefined) {
153
+ setClauses.push("config = ?");
154
+ params.push(JSON.stringify(updates.config));
155
+ }
156
+ if (updates.metadata !== undefined) {
157
+ setClauses.push("metadata = ?");
158
+ params.push(JSON.stringify(updates.metadata));
159
+ if (updates.metadata.taskId !== undefined) {
160
+ setClauses.push("task_id = ?");
161
+ params.push(updates.metadata.taskId);
162
+ }
163
+ }
164
+ if (updates.tags !== undefined) {
165
+ setClauses.push("tags = ?");
166
+ params.push(JSON.stringify(updates.tags));
167
+ }
168
+ params.push(id);
169
+ this.db.prepare(`UPDATE workflows SET ${setClauses.join(", ")} WHERE id = ?`).run(...params);
170
+ return this.getById(id);
171
+ }
172
+ delete(id) {
173
+ const existing = this.getById(id);
174
+ if (!existing)
175
+ return false;
176
+ this.db.prepare("DELETE FROM workflows WHERE id = ?").run(id);
177
+ return true;
178
+ }
179
+ exists(id) {
180
+ const result = this.db.prepare("SELECT 1 FROM workflows WHERE id = ?").get(id);
181
+ return result !== undefined;
182
+ }
183
+ existsByNameAndVersion(name, version) {
184
+ const result = this.db.prepare("SELECT 1 FROM workflows WHERE name = ? AND version = ?").get(name, version);
185
+ return result !== undefined;
186
+ }
187
+ count() {
188
+ const result = this.db.prepare("SELECT COUNT(*) as count FROM workflows").get();
189
+ return result.count;
190
+ }
191
+ search(query, limit) {
192
+ let sql = "SELECT * FROM workflows WHERE name LIKE ? ORDER BY updated_at DESC";
193
+ const params = [`%${query}%`];
194
+ if (limit !== undefined) {
195
+ sql += " LIMIT ?";
196
+ params.push(limit);
197
+ }
198
+ const rows = this.db.prepare(sql).all(...params);
199
+ return rows.map(rowToWorkflow);
200
+ }
201
+ }
202
+ export {
203
+ rowToWorkflow,
204
+ WorkflowRepository
205
+ };
@@ -0,0 +1,52 @@
1
+ import { createRequire } from "node:module";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+ var __legacyDecorateClassTS = function(decorators, target, key, desc) {
40
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
41
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
42
+ r = Reflect.decorate(decorators, target, key, desc);
43
+ else
44
+ for (var i = decorators.length - 1;i >= 0; i--)
45
+ if (d = decorators[i])
46
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
47
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
48
+ };
49
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
50
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
51
+
52
+ export { __toCommonJS, __export, __legacyDecorateClassTS, __esm, __require };
@@ -0,0 +1,10 @@
1
+ import {
2
+ SQLiteSpanStorage,
3
+ init_span_storage
4
+ } from "./chunk-1qwabsm0.js";
5
+ import"./chunk-wbkh7wat.js";
6
+ init_span_storage();
7
+
8
+ export {
9
+ SQLiteSpanStorage
10
+ };
@@ -0,0 +1,102 @@
1
+ import {
2
+ __esm,
3
+ __export
4
+ } from "./chunk-wbkh7wat.js";
5
+
6
+ // src/env/session/search-query-parser.ts
7
+ var exports_search_query_parser = {};
8
+ __export(exports_search_query_parser, {
9
+ parseSearchQuery: () => parseSearchQuery,
10
+ matchesQuery: () => matchesQuery
11
+ });
12
+ function parseSearchQuery(query) {
13
+ const result = {
14
+ required: [],
15
+ excluded: [],
16
+ phrases: []
17
+ };
18
+ if (!query || !query.trim()) {
19
+ return result;
20
+ }
21
+ const phraseRegex = /"([^"]+)"/g;
22
+ let match;
23
+ while ((match = phraseRegex.exec(query)) !== null) {
24
+ result.phrases.push(match[1].toLowerCase());
25
+ }
26
+ query = query.replace(phraseRegex, "");
27
+ query = query.replace(/\s+/g, " ").trim();
28
+ if (!query) {
29
+ return result;
30
+ }
31
+ const parts = [];
32
+ let remaining = query;
33
+ const singleOpRegex = /\s+(AND|OR|NOT)\s+/gi;
34
+ let opMatch;
35
+ while ((opMatch = singleOpRegex.exec(remaining)) !== null) {
36
+ const op = opMatch[1].toUpperCase();
37
+ const beforeText = remaining.slice(0, opMatch.index).trim();
38
+ if (beforeText) {
39
+ parts.push({ text: beforeText, operator: undefined });
40
+ }
41
+ parts.push({ text: op, operator: op });
42
+ remaining = remaining.slice(opMatch.index + opMatch[0].length);
43
+ singleOpRegex.lastIndex = 0;
44
+ }
45
+ if (remaining.trim()) {
46
+ parts.push({ text: remaining.trim(), operator: undefined });
47
+ }
48
+ let currentOperator = "AND";
49
+ for (const part of parts) {
50
+ if (part.operator) {
51
+ currentOperator = part.operator;
52
+ } else {
53
+ const wordRegex = /[\w\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff]+/gu;
54
+ const words = part.text.match(wordRegex) || [];
55
+ for (const word of words) {
56
+ const lowerWord = word.toLowerCase();
57
+ if (lowerWord === "and" || lowerWord === "or" || lowerWord === "not") {
58
+ currentOperator = lowerWord.toUpperCase();
59
+ continue;
60
+ }
61
+ if (currentOperator === "NOT") {
62
+ if (!result.excluded.includes(lowerWord)) {
63
+ result.excluded.push(lowerWord);
64
+ }
65
+ } else {
66
+ if (!result.required.includes(lowerWord)) {
67
+ result.required.push(lowerWord);
68
+ }
69
+ }
70
+ currentOperator = "AND";
71
+ }
72
+ }
73
+ }
74
+ return result;
75
+ }
76
+ function matchesQuery(content, query) {
77
+ if (!content) {
78
+ return query.required.length === 0 && query.phrases.length === 0;
79
+ }
80
+ const lowerContent = content.toLowerCase();
81
+ for (const term of query.excluded) {
82
+ if (lowerContent.includes(term.toLowerCase())) {
83
+ return false;
84
+ }
85
+ }
86
+ for (const phrase of query.phrases) {
87
+ if (!lowerContent.includes(phrase)) {
88
+ return false;
89
+ }
90
+ }
91
+ if (query.required.length > 0) {
92
+ for (const term of query.required) {
93
+ if (!lowerContent.includes(term)) {
94
+ return false;
95
+ }
96
+ }
97
+ }
98
+ return true;
99
+ }
100
+ var init_search_query_parser = () => {};
101
+
102
+ export { parseSearchQuery, matchesQuery, exports_search_query_parser, init_search_query_parser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.4.11",
3
+ "version": "1.4.13",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",
@@ -22,9 +22,14 @@
22
22
  "./package.json": "./package.json"
23
23
  },
24
24
  "files": [
25
- "dist/**/*",
25
+ "dist",
26
26
  "README.md"
27
27
  ],
28
+ "scripts": {
29
+ "build": "bun run bunup",
30
+ "clean": "rm -rf dist",
31
+ "typecheck": "npx tsc --noEmit --skipLibCheck --project tsconfig.json"
32
+ },
28
33
  "dependencies": {
29
34
  "@ai-sdk/anthropic": "^3.0.0",
30
35
  "@ai-sdk/google": "^3.0.0",
@@ -70,10 +75,5 @@
70
75
  "license": "MIT",
71
76
  "bugs": {
72
77
  "url": "https://github.com/ai-setting/roy-agent/issues"
73
- },
74
- "scripts": {
75
- "build": "bun run bunup",
76
- "clean": "rm -rf dist",
77
- "typecheck": "npx tsc --noEmit --skipLibCheck --project tsconfig.json"
78
78
  }
79
- }
79
+ }