@ai-setting/roy-agent-core 1.4.12 → 1.4.14
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/packages/core/src/config/index.js +32 -0
- package/dist/packages/core/src/env/agent/index.js +24 -0
- package/dist/packages/core/src/env/commands/index.js +14 -0
- package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
- package/dist/packages/core/src/env/debug/index.js +26 -0
- package/dist/packages/core/src/env/hook/index.js +29 -0
- package/dist/packages/core/src/env/index.js +81 -0
- package/dist/packages/core/src/env/llm/index.js +40 -0
- package/dist/packages/core/src/env/log-trace/index.js +83 -0
- package/dist/packages/core/src/env/mcp/index.js +39 -0
- package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
- package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
- package/dist/packages/core/src/env/memory/index.js +56 -0
- package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
- package/dist/packages/core/src/env/prompt/index.js +20 -0
- package/dist/packages/core/src/env/session/index.js +25 -0
- package/dist/packages/core/src/env/session/storage/index.js +18 -0
- package/dist/packages/core/src/env/skill/index.js +34 -0
- package/dist/packages/core/src/env/skill/tool/index.js +9 -0
- package/dist/packages/core/src/env/task/delegate/index.js +18 -0
- package/dist/packages/core/src/env/task/hooks/index.js +7 -0
- package/dist/packages/core/src/env/task/index.js +30 -0
- package/dist/packages/core/src/env/task/plugins/index.js +23 -0
- package/dist/packages/core/src/env/task/storage/index.js +14 -0
- package/dist/packages/core/src/env/task/tools/index.js +17 -0
- package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
- package/dist/packages/core/src/env/tool/built-in/index.js +25 -0
- package/dist/packages/core/src/env/tool/index.js +39 -0
- package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
- package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
- package/dist/packages/core/src/env/workflow/index.js +132 -0
- package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
- package/dist/packages/core/src/env/workflow/service/index.js +13 -0
- package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
- package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
- package/dist/packages/core/src/env/workflow/types/index.js +94 -0
- package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
- package/dist/packages/core/src/index.js +398 -0
- package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
- package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
- package/dist/shared/@ai-setting/roy-agent-core-0sgn3de4.js +102 -0
- package/dist/{env/task/tools/index.js → shared/@ai-setting/roy-agent-core-12x57kf1.js} +1 -59
- package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-1k28kg7h.js +368 -0
- package/dist/shared/@ai-setting/roy-agent-core-1z1zv5g8.js +258 -0
- package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
- package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-4ws8atva.js +107 -0
- package/dist/{env/workflow/nodes/index.js → shared/@ai-setting/roy-agent-core-5fbp24se.js} +8 -55
- package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
- package/dist/shared/@ai-setting/roy-agent-core-6j0zcmwk.js +2146 -0
- package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
- package/dist/shared/@ai-setting/roy-agent-core-7vrk3add.js +10 -0
- package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
- package/dist/{env/memory/built-in/index.js → shared/@ai-setting/roy-agent-core-8mbmrwzs.js} +22 -76
- package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
- package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
- package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
- package/dist/{env/workflow/types/index.js → shared/@ai-setting/roy-agent-core-fq5mtxsy.js} +16 -154
- package/dist/{env/task/hooks/index.js → shared/@ai-setting/roy-agent-core-fs0mn2jk.js} +3 -18
- package/dist/{config/index.js → shared/@ai-setting/roy-agent-core-fvd9g6k8.js} +140 -605
- package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
- package/dist/{env/task/tools/operation/index.js → shared/@ai-setting/roy-agent-core-gy0wp5h7.js} +1 -58
- package/dist/shared/@ai-setting/roy-agent-core-hyza1gm7.js +15 -0
- package/dist/shared/@ai-setting/roy-agent-core-j8zx62zr.js +154 -0
- package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
- package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
- package/dist/shared/@ai-setting/roy-agent-core-nczzf0ms.js +15 -0
- package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
- package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
- package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
- package/dist/shared/@ai-setting/roy-agent-core-qg9tcaph.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-qhyerewk.js +20 -0
- package/dist/shared/@ai-setting/roy-agent-core-qxybm159.js +82 -0
- package/dist/shared/@ai-setting/roy-agent-core-rh9dpkpw.js +549 -0
- package/dist/shared/@ai-setting/roy-agent-core-rr9p1g43.js +205 -0
- package/dist/{env/workflow/decorators/index.js → shared/@ai-setting/roy-agent-core-sbzvpfn7.js} +8 -173
- package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
- package/dist/shared/@ai-setting/roy-agent-core-tkr5ynkh.js +200 -0
- package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
- package/dist/{env/hook/index.js → shared/@ai-setting/roy-agent-core-w75rafhy.js} +3 -74
- package/dist/{env/debug/formatters/index.js → shared/@ai-setting/roy-agent-core-w76hqkmg.js} +11 -66
- package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
- package/dist/shared/@ai-setting/roy-agent-core-yn761yve.js +299 -0
- package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
- package/dist/{env/workflow/service/index.js → shared/@ai-setting/roy-agent-core-yt8wdh2w.js} +1 -57
- package/package.json +3 -2
- package/dist/env/agent/index.js +0 -3035
- package/dist/env/commands/index.js +0 -1685
- package/dist/env/debug/index.js +0 -2300
- package/dist/env/index.js +0 -12591
- package/dist/env/llm/index.js +0 -2736
- package/dist/env/log-trace/index.js +0 -1779
- package/dist/env/mcp/index.js +0 -2173
- package/dist/env/mcp/tool/index.js +0 -1149
- package/dist/env/memory/index.js +0 -2171
- package/dist/env/memory/plugin/index.js +0 -1263
- package/dist/env/prompt/index.js +0 -2107
- package/dist/env/session/index.js +0 -3594
- package/dist/env/session/storage/index.js +0 -2049
- package/dist/env/skill/index.js +0 -1635
- package/dist/env/skill/tool/index.js +0 -114
- package/dist/env/task/delegate/index.js +0 -1844
- package/dist/env/task/index.js +0 -3578
- package/dist/env/task/plugins/index.js +0 -1626
- package/dist/env/task/storage/index.js +0 -1464
- package/dist/env/tool/built-in/index.js +0 -1151
- package/dist/env/tool/index.js +0 -2284
- package/dist/env/workflow/engine/index.js +0 -4391
- package/dist/env/workflow/index.js +0 -6214
- package/dist/env/workflow/storage/index.js +0 -1236
- package/dist/env/workflow/tools/index.js +0 -1081
- package/dist/env/workflow/utils/index.js +0 -1631
- package/dist/index.js +0 -22778
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDatabase
|
|
3
|
+
} from "./roy-agent-core-qxybm159.js";
|
|
4
|
+
import {
|
|
5
|
+
exports_search_query_parser,
|
|
6
|
+
init_search_query_parser
|
|
7
|
+
} from "./roy-agent-core-0sgn3de4.js";
|
|
8
|
+
import {
|
|
9
|
+
__toCommonJS
|
|
10
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
11
|
+
|
|
12
|
+
// packages/core/src/env/workflow/storage/workflow-repo.ts
|
|
13
|
+
import { randomUUID } from "crypto";
|
|
14
|
+
function rowToWorkflow(row) {
|
|
15
|
+
const metadata = JSON.parse(row.metadata);
|
|
16
|
+
if (row.task_id !== null) {
|
|
17
|
+
metadata.taskId = row.task_id;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
id: row.id,
|
|
21
|
+
name: row.name,
|
|
22
|
+
version: row.version,
|
|
23
|
+
description: row.description || undefined,
|
|
24
|
+
definition: JSON.parse(row.definition),
|
|
25
|
+
config: JSON.parse(row.config),
|
|
26
|
+
metadata,
|
|
27
|
+
tags: JSON.parse(row.tags),
|
|
28
|
+
createdAt: new Date(row.created_at),
|
|
29
|
+
updatedAt: new Date(row.updated_at)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class WorkflowRepository {
|
|
34
|
+
db;
|
|
35
|
+
constructor(db) {
|
|
36
|
+
this.db = db || getDatabase();
|
|
37
|
+
}
|
|
38
|
+
create(workflow) {
|
|
39
|
+
const id = randomUUID();
|
|
40
|
+
const now = new Date().toISOString();
|
|
41
|
+
const stmt = this.db.prepare(`
|
|
42
|
+
INSERT INTO workflows (id, name, version, description, definition, config, metadata, tags, task_id, created_at, updated_at)
|
|
43
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
44
|
+
`);
|
|
45
|
+
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);
|
|
46
|
+
return {
|
|
47
|
+
...workflow,
|
|
48
|
+
id,
|
|
49
|
+
createdAt: new Date(now),
|
|
50
|
+
updatedAt: new Date(now)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
createFromDefinition(definition, options) {
|
|
54
|
+
const workflow = {
|
|
55
|
+
name: definition.name,
|
|
56
|
+
version: definition.version,
|
|
57
|
+
description: definition.description,
|
|
58
|
+
definition,
|
|
59
|
+
config: options?.config || definition.config || {},
|
|
60
|
+
metadata: options?.metadata || definition.metadata || {},
|
|
61
|
+
tags: options?.tags || definition.metadata?.tags || []
|
|
62
|
+
};
|
|
63
|
+
return this.create(workflow);
|
|
64
|
+
}
|
|
65
|
+
getById(id) {
|
|
66
|
+
const row = this.db.prepare("SELECT * FROM workflows WHERE id = ?").get(id);
|
|
67
|
+
if (!row)
|
|
68
|
+
return;
|
|
69
|
+
return rowToWorkflow(row);
|
|
70
|
+
}
|
|
71
|
+
getByName(name) {
|
|
72
|
+
const row = this.db.prepare("SELECT * FROM workflows WHERE name = ? ORDER BY updated_at DESC LIMIT 1").get(name);
|
|
73
|
+
if (!row)
|
|
74
|
+
return;
|
|
75
|
+
return rowToWorkflow(row);
|
|
76
|
+
}
|
|
77
|
+
getByNameAndVersion(name, version) {
|
|
78
|
+
const row = this.db.prepare("SELECT * FROM workflows WHERE name = ? AND version = ?").get(name, version);
|
|
79
|
+
if (!row)
|
|
80
|
+
return;
|
|
81
|
+
return rowToWorkflow(row);
|
|
82
|
+
}
|
|
83
|
+
list(options) {
|
|
84
|
+
let sql = "SELECT * FROM workflows";
|
|
85
|
+
const params = [];
|
|
86
|
+
const conditions = [];
|
|
87
|
+
if (options?.tag) {
|
|
88
|
+
conditions.push("tags LIKE ?");
|
|
89
|
+
params.push(`%${options.tag}%`);
|
|
90
|
+
}
|
|
91
|
+
if (options?.taskId !== undefined) {
|
|
92
|
+
conditions.push("task_id = ?");
|
|
93
|
+
params.push(options.taskId);
|
|
94
|
+
}
|
|
95
|
+
if (conditions.length > 0) {
|
|
96
|
+
sql += " WHERE " + conditions.join(" AND ");
|
|
97
|
+
}
|
|
98
|
+
const orderBy = options?.orderBy || "updated_at";
|
|
99
|
+
const order = options?.order || "desc";
|
|
100
|
+
sql += ` ORDER BY ${orderBy} ${order.toUpperCase()}`;
|
|
101
|
+
if (options?.limit !== undefined) {
|
|
102
|
+
sql += " LIMIT ?";
|
|
103
|
+
params.push(options.limit);
|
|
104
|
+
}
|
|
105
|
+
if (options?.offset !== undefined) {
|
|
106
|
+
sql += " OFFSET ?";
|
|
107
|
+
params.push(options.offset);
|
|
108
|
+
}
|
|
109
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
110
|
+
let workflows = rows.map(rowToWorkflow);
|
|
111
|
+
if (options?.search) {
|
|
112
|
+
const { parseSearchQuery, matchesQuery } = (init_search_query_parser(), __toCommonJS(exports_search_query_parser));
|
|
113
|
+
const query = parseSearchQuery(options.search);
|
|
114
|
+
workflows = workflows.filter((w) => {
|
|
115
|
+
const descMatch = w.description ? matchesQuery(w.description, query) : false;
|
|
116
|
+
const tagsMatch = w.tags.some((tag) => matchesQuery(tag, query));
|
|
117
|
+
return descMatch || tagsMatch;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return workflows;
|
|
121
|
+
}
|
|
122
|
+
listVersions(name) {
|
|
123
|
+
const rows = this.db.prepare("SELECT * FROM workflows WHERE name = ? ORDER BY version DESC").all(name);
|
|
124
|
+
return rows.map(rowToWorkflow);
|
|
125
|
+
}
|
|
126
|
+
update(id, updates) {
|
|
127
|
+
const existing = this.getById(id);
|
|
128
|
+
if (!existing)
|
|
129
|
+
return;
|
|
130
|
+
const now = new Date().toISOString();
|
|
131
|
+
const setClauses = ["updated_at = ?"];
|
|
132
|
+
const params = [now];
|
|
133
|
+
if (updates.name !== undefined) {
|
|
134
|
+
setClauses.push("name = ?");
|
|
135
|
+
params.push(updates.name);
|
|
136
|
+
}
|
|
137
|
+
if (updates.version !== undefined) {
|
|
138
|
+
setClauses.push("version = ?");
|
|
139
|
+
params.push(updates.version);
|
|
140
|
+
}
|
|
141
|
+
if (updates.description !== undefined) {
|
|
142
|
+
setClauses.push("description = ?");
|
|
143
|
+
params.push(updates.description);
|
|
144
|
+
}
|
|
145
|
+
if (updates.definition !== undefined) {
|
|
146
|
+
setClauses.push("definition = ?");
|
|
147
|
+
params.push(JSON.stringify(updates.definition));
|
|
148
|
+
}
|
|
149
|
+
if (updates.config !== undefined) {
|
|
150
|
+
setClauses.push("config = ?");
|
|
151
|
+
params.push(JSON.stringify(updates.config));
|
|
152
|
+
}
|
|
153
|
+
if (updates.metadata !== undefined) {
|
|
154
|
+
setClauses.push("metadata = ?");
|
|
155
|
+
params.push(JSON.stringify(updates.metadata));
|
|
156
|
+
if (updates.metadata.taskId !== undefined) {
|
|
157
|
+
setClauses.push("task_id = ?");
|
|
158
|
+
params.push(updates.metadata.taskId);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (updates.tags !== undefined) {
|
|
162
|
+
setClauses.push("tags = ?");
|
|
163
|
+
params.push(JSON.stringify(updates.tags));
|
|
164
|
+
}
|
|
165
|
+
params.push(id);
|
|
166
|
+
this.db.prepare(`UPDATE workflows SET ${setClauses.join(", ")} WHERE id = ?`).run(...params);
|
|
167
|
+
return this.getById(id);
|
|
168
|
+
}
|
|
169
|
+
delete(id) {
|
|
170
|
+
const existing = this.getById(id);
|
|
171
|
+
if (!existing)
|
|
172
|
+
return false;
|
|
173
|
+
this.db.prepare("DELETE FROM workflows WHERE id = ?").run(id);
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
exists(id) {
|
|
177
|
+
const result = this.db.prepare("SELECT 1 FROM workflows WHERE id = ?").get(id);
|
|
178
|
+
return result !== undefined;
|
|
179
|
+
}
|
|
180
|
+
existsByNameAndVersion(name, version) {
|
|
181
|
+
const result = this.db.prepare("SELECT 1 FROM workflows WHERE name = ? AND version = ?").get(name, version);
|
|
182
|
+
return result !== undefined;
|
|
183
|
+
}
|
|
184
|
+
count() {
|
|
185
|
+
const result = this.db.prepare("SELECT COUNT(*) as count FROM workflows").get();
|
|
186
|
+
return result.count;
|
|
187
|
+
}
|
|
188
|
+
search(query, limit) {
|
|
189
|
+
let sql = "SELECT * FROM workflows WHERE name LIKE ? ORDER BY updated_at DESC";
|
|
190
|
+
const params = [`%${query}%`];
|
|
191
|
+
if (limit !== undefined) {
|
|
192
|
+
sql += " LIMIT ?";
|
|
193
|
+
params.push(limit);
|
|
194
|
+
}
|
|
195
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
196
|
+
return rows.map(rowToWorkflow);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export { rowToWorkflow, WorkflowRepository };
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLogger,
|
|
3
|
+
init_logger
|
|
4
|
+
} from "./roy-agent-core-yn761yve.js";
|
|
5
|
+
|
|
6
|
+
// packages/core/src/env/mcp/tool/adapter.ts
|
|
7
|
+
init_logger();
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
var logger = createLogger("mcp-adapter");
|
|
10
|
+
function adaptMcpTool(mcpTool, mcpClient, serverName) {
|
|
11
|
+
const toolName = `mcp_${serverName}_${mcpTool.name}`;
|
|
12
|
+
const description = `MCP tool [${serverName}/${mcpTool.name}]: ${mcpTool.description ?? ""}`;
|
|
13
|
+
const paramsSchema = convertInputSchemaToZod(mcpTool.inputSchema);
|
|
14
|
+
return {
|
|
15
|
+
name: toolName,
|
|
16
|
+
description,
|
|
17
|
+
parameters: paramsSchema,
|
|
18
|
+
execute: async (args, _ctx) => {
|
|
19
|
+
try {
|
|
20
|
+
const result = await mcpClient.callTool({
|
|
21
|
+
name: mcpTool.name,
|
|
22
|
+
arguments: args ?? {}
|
|
23
|
+
});
|
|
24
|
+
return convertMcpCallResult(result);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
logger.error(`[McpAdapter] Tool call failed: ${toolName}`, {
|
|
27
|
+
error: error instanceof Error ? error.message : String(error)
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
success: false,
|
|
31
|
+
output: "",
|
|
32
|
+
error: error instanceof Error ? error.message : String(error)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
metadata: {
|
|
37
|
+
category: "mcp",
|
|
38
|
+
tags: ["mcp", serverName],
|
|
39
|
+
mcpTool: {
|
|
40
|
+
originalName: mcpTool.name,
|
|
41
|
+
originalDescription: mcpTool.description || "",
|
|
42
|
+
inputSchema: mcpTool.inputSchema
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function convertInputSchemaToZod(inputSchema) {
|
|
48
|
+
if (!inputSchema) {
|
|
49
|
+
return z.unknown();
|
|
50
|
+
}
|
|
51
|
+
const schema = inputSchema;
|
|
52
|
+
const properties = schema.properties ?? {};
|
|
53
|
+
const required = schema.required ?? [];
|
|
54
|
+
if (schema.anyOf || schema.oneOf) {
|
|
55
|
+
const unions = schema.anyOf || schema.oneOf || [];
|
|
56
|
+
const zodUnions = unions.map((s) => jsonSchemaToZod(s, false)).filter((t) => t);
|
|
57
|
+
if (zodUnions.length > 0) {
|
|
58
|
+
return z.union(zodUnions);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (schema.allOf) {
|
|
62
|
+
const schemas = [];
|
|
63
|
+
for (const subSchema of schema.allOf) {
|
|
64
|
+
const sub = jsonSchemaToZod(subSchema, false);
|
|
65
|
+
schemas.push(sub);
|
|
66
|
+
}
|
|
67
|
+
if (schemas.length === 1) {
|
|
68
|
+
return schemas[0];
|
|
69
|
+
}
|
|
70
|
+
let combined = schemas[0];
|
|
71
|
+
for (let i = 1;i < schemas.length; i++) {
|
|
72
|
+
combined = z.intersection(combined, schemas[i]);
|
|
73
|
+
}
|
|
74
|
+
return combined;
|
|
75
|
+
}
|
|
76
|
+
const zodFields = {};
|
|
77
|
+
const fieldDescriptions = {};
|
|
78
|
+
for (const [key, prop] of Object.entries(properties)) {
|
|
79
|
+
const isRequired = required.includes(key);
|
|
80
|
+
const fieldResult = jsonSchemaToZod(prop, !isRequired);
|
|
81
|
+
const propSchema = prop;
|
|
82
|
+
if (propSchema.description) {
|
|
83
|
+
fieldDescriptions[key] = propSchema.description;
|
|
84
|
+
}
|
|
85
|
+
if (!isRequired) {
|
|
86
|
+
zodFields[key] = fieldResult.optional();
|
|
87
|
+
} else {
|
|
88
|
+
zodFields[key] = fieldResult;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (Object.keys(zodFields).length === 0) {
|
|
92
|
+
return schema.description ? z.unknown().describe(schema.description) : z.unknown();
|
|
93
|
+
}
|
|
94
|
+
const result = z.object(zodFields);
|
|
95
|
+
if (schema.description) {
|
|
96
|
+
return result.describe(schema.description);
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
function jsonSchemaToZod(prop, isOptional) {
|
|
101
|
+
const description = prop.description;
|
|
102
|
+
let baseType;
|
|
103
|
+
if (prop.nullable === true) {
|
|
104
|
+
const innerType = jsonSchemaToZod({ ...prop, nullable: undefined }, isOptional);
|
|
105
|
+
baseType = z.union([innerType, z.null()]);
|
|
106
|
+
if (description) {
|
|
107
|
+
return baseType.describe(description);
|
|
108
|
+
}
|
|
109
|
+
return baseType;
|
|
110
|
+
}
|
|
111
|
+
if (prop.anyOf || prop.oneOf) {
|
|
112
|
+
const unions = prop.anyOf || prop.oneOf || [];
|
|
113
|
+
const zodUnions = unions.map((s) => jsonSchemaToZod(s, false)).filter((t) => t);
|
|
114
|
+
if (zodUnions.length > 0) {
|
|
115
|
+
baseType = z.union(zodUnions);
|
|
116
|
+
if (description) {
|
|
117
|
+
return baseType.describe(description);
|
|
118
|
+
}
|
|
119
|
+
return baseType;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (prop.allOf) {
|
|
123
|
+
const schemas = [];
|
|
124
|
+
for (const subSchema of prop.allOf) {
|
|
125
|
+
const sub = jsonSchemaToZod(subSchema, false);
|
|
126
|
+
schemas.push(sub);
|
|
127
|
+
}
|
|
128
|
+
if (schemas.length === 1) {
|
|
129
|
+
baseType = schemas[0];
|
|
130
|
+
} else {
|
|
131
|
+
baseType = z.intersection(schemas[0], schemas[1]);
|
|
132
|
+
for (let i = 2;i < schemas.length; i++) {
|
|
133
|
+
baseType = z.intersection(baseType, schemas[i]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (description) {
|
|
137
|
+
return baseType.describe(description);
|
|
138
|
+
}
|
|
139
|
+
return baseType;
|
|
140
|
+
}
|
|
141
|
+
const types = prop.types || (prop.type ? [prop.type] : []);
|
|
142
|
+
if (types.length > 1) {
|
|
143
|
+
const zodTypes = types.map((t) => getZodTypeForBasicType(t, prop)).filter((t) => t);
|
|
144
|
+
if (zodTypes.length > 0) {
|
|
145
|
+
baseType = z.union(zodTypes);
|
|
146
|
+
if (description) {
|
|
147
|
+
return baseType.describe(description);
|
|
148
|
+
}
|
|
149
|
+
return baseType;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const type = types[0];
|
|
153
|
+
if (!type) {
|
|
154
|
+
if (prop.enum) {
|
|
155
|
+
return handleEnum(prop, description);
|
|
156
|
+
}
|
|
157
|
+
baseType = z.unknown();
|
|
158
|
+
if (description) {
|
|
159
|
+
return baseType.describe(description);
|
|
160
|
+
}
|
|
161
|
+
return baseType;
|
|
162
|
+
}
|
|
163
|
+
baseType = getZodTypeForBasicType(type, prop);
|
|
164
|
+
if (description) {
|
|
165
|
+
const schemaDescription = baseType._def?.description;
|
|
166
|
+
if (schemaDescription) {
|
|
167
|
+
return baseType.describe(`${schemaDescription}. ${description}`);
|
|
168
|
+
}
|
|
169
|
+
return baseType.describe(description);
|
|
170
|
+
}
|
|
171
|
+
return baseType;
|
|
172
|
+
}
|
|
173
|
+
function getZodTypeForBasicType(type, prop) {
|
|
174
|
+
switch (type) {
|
|
175
|
+
case "string": {
|
|
176
|
+
if (prop.enum && prop.enum.length > 0 && prop.enum.every((v) => typeof v === "string")) {
|
|
177
|
+
return handleEnum(prop, prop.description);
|
|
178
|
+
}
|
|
179
|
+
let schema = z.string();
|
|
180
|
+
if (typeof prop.minLength === "number") {
|
|
181
|
+
schema = schema.min(prop.minLength);
|
|
182
|
+
}
|
|
183
|
+
if (typeof prop.maxLength === "number") {
|
|
184
|
+
schema = schema.max(prop.maxLength);
|
|
185
|
+
}
|
|
186
|
+
if (prop.pattern) {
|
|
187
|
+
try {
|
|
188
|
+
schema = schema.regex(new RegExp(prop.pattern));
|
|
189
|
+
} catch {}
|
|
190
|
+
}
|
|
191
|
+
if (prop.format) {
|
|
192
|
+
schema = schema.describe(`Format: ${prop.format}`);
|
|
193
|
+
}
|
|
194
|
+
if (prop.default !== undefined) {
|
|
195
|
+
schema = schema.default(prop.default);
|
|
196
|
+
}
|
|
197
|
+
return schema;
|
|
198
|
+
}
|
|
199
|
+
case "number":
|
|
200
|
+
case "integer": {
|
|
201
|
+
let schema = type === "integer" ? z.number().int() : z.number();
|
|
202
|
+
if (typeof prop.minimum === "number") {
|
|
203
|
+
schema = schema.min(prop.minimum);
|
|
204
|
+
}
|
|
205
|
+
if (typeof prop.maximum === "number") {
|
|
206
|
+
schema = schema.max(prop.maximum);
|
|
207
|
+
}
|
|
208
|
+
if (prop.default !== undefined) {
|
|
209
|
+
schema = schema.default(prop.default);
|
|
210
|
+
}
|
|
211
|
+
return schema;
|
|
212
|
+
}
|
|
213
|
+
case "boolean": {
|
|
214
|
+
let schema = z.boolean();
|
|
215
|
+
if (prop.default !== undefined) {
|
|
216
|
+
schema = schema.default(prop.default);
|
|
217
|
+
}
|
|
218
|
+
return schema;
|
|
219
|
+
}
|
|
220
|
+
case "array": {
|
|
221
|
+
let itemSchema = z.unknown();
|
|
222
|
+
if (prop.items) {
|
|
223
|
+
itemSchema = jsonSchemaToZod(prop.items, false);
|
|
224
|
+
}
|
|
225
|
+
let schema = z.array(itemSchema);
|
|
226
|
+
if (prop.additionalProperties && typeof prop.additionalProperties !== "boolean") {
|
|
227
|
+
const additionalItems = jsonSchemaToZod(prop.additionalProperties, false);
|
|
228
|
+
schema = z.array(z.union([itemSchema, additionalItems]));
|
|
229
|
+
}
|
|
230
|
+
return schema;
|
|
231
|
+
}
|
|
232
|
+
case "object": {
|
|
233
|
+
if (prop.properties) {
|
|
234
|
+
const fields = {};
|
|
235
|
+
const required = prop.required ?? [];
|
|
236
|
+
for (const [key, value] of Object.entries(prop.properties)) {
|
|
237
|
+
const isRequired = required.includes(key);
|
|
238
|
+
fields[key] = isRequired ? jsonSchemaToZod(value, false) : jsonSchemaToZod(value, true).optional();
|
|
239
|
+
}
|
|
240
|
+
return z.object(fields);
|
|
241
|
+
}
|
|
242
|
+
if (prop.additionalProperties) {
|
|
243
|
+
if (typeof prop.additionalProperties === "boolean") {
|
|
244
|
+
return z.record(z.string(), z.unknown());
|
|
245
|
+
}
|
|
246
|
+
return z.record(z.string(), jsonSchemaToZod(prop.additionalProperties, false));
|
|
247
|
+
}
|
|
248
|
+
return z.record(z.string(), z.unknown());
|
|
249
|
+
}
|
|
250
|
+
case "null":
|
|
251
|
+
return z.null();
|
|
252
|
+
case "null | string":
|
|
253
|
+
case "string | null":
|
|
254
|
+
return z.union([z.string(), z.null()]);
|
|
255
|
+
case "null | number":
|
|
256
|
+
case "number | null":
|
|
257
|
+
return z.union([z.number(), z.null()]);
|
|
258
|
+
default:
|
|
259
|
+
if (prop.enum) {
|
|
260
|
+
return handleEnum(prop);
|
|
261
|
+
}
|
|
262
|
+
return z.unknown();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function handleEnum(prop, existingDescription) {
|
|
266
|
+
if (!prop.enum || prop.enum.length === 0) {
|
|
267
|
+
return z.unknown();
|
|
268
|
+
}
|
|
269
|
+
const stringValues = prop.enum.filter((v) => typeof v === "string");
|
|
270
|
+
if (stringValues.length === 0) {
|
|
271
|
+
return z.any();
|
|
272
|
+
}
|
|
273
|
+
let schema;
|
|
274
|
+
if (stringValues.length === 1) {
|
|
275
|
+
schema = z.literal(stringValues[0]);
|
|
276
|
+
} else {
|
|
277
|
+
schema = z.enum([stringValues[0], ...stringValues.slice(1)]);
|
|
278
|
+
}
|
|
279
|
+
const valuesList = stringValues.map((v) => `"${v}"`).join(", ");
|
|
280
|
+
const valuesDescription = `Valid values: ${valuesList}`;
|
|
281
|
+
if (existingDescription) {
|
|
282
|
+
return schema.describe(`${existingDescription}. ${valuesDescription}`);
|
|
283
|
+
}
|
|
284
|
+
return schema.describe(valuesDescription);
|
|
285
|
+
}
|
|
286
|
+
function convertMcpCallResult(result) {
|
|
287
|
+
const content = result.content;
|
|
288
|
+
const textContent = content?.filter((c) => c.type === "text")?.map((c) => c.text)?.join("") ?? "";
|
|
289
|
+
return {
|
|
290
|
+
success: !result.isError,
|
|
291
|
+
output: textContent,
|
|
292
|
+
error: result.isError ? textContent : undefined
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
function createMcpToolsDescription(tools) {
|
|
296
|
+
if (tools.length === 0) {
|
|
297
|
+
return " No MCP tools currently available.";
|
|
298
|
+
}
|
|
299
|
+
return tools.map((t) => ` - ${t.name}: ${t.description}`).join(`
|
|
300
|
+
`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export { adaptMcpTool, convertInputSchemaToZod, createMcpToolsDescription };
|
|
@@ -1,64 +1,3 @@
|
|
|
1
|
-
// @bun
|
|
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 = import.meta.require;
|
|
51
|
-
|
|
52
|
-
// packages/core/src/env/hook/types.ts
|
|
53
|
-
function createHook(meta, fn) {
|
|
54
|
-
return {
|
|
55
|
-
...meta,
|
|
56
|
-
execute: fn
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function createPriorityHook(name, fn, priority) {
|
|
60
|
-
return createHook({ name, priority }, fn);
|
|
61
|
-
}
|
|
62
1
|
// packages/core/src/env/hook/hook-manager.ts
|
|
63
2
|
class HookManager {
|
|
64
3
|
_hooks = new Map;
|
|
@@ -203,6 +142,7 @@ class HookManager {
|
|
|
203
142
|
}
|
|
204
143
|
}
|
|
205
144
|
}
|
|
145
|
+
|
|
206
146
|
// packages/core/src/env/hook/global-hook-manager.ts
|
|
207
147
|
var globalHookManager = new HookManager;
|
|
208
148
|
var AgentHookPoints = {
|
|
@@ -258,16 +198,5 @@ async function executeLLMHook(hookPoint, data, metadata = {}) {
|
|
|
258
198
|
async function executeToolHook(hookPoint, data, metadata = {}) {
|
|
259
199
|
await globalHookManager.execute(hookPoint, data, metadata);
|
|
260
200
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
executeToolHook,
|
|
264
|
-
executeLLMHook,
|
|
265
|
-
executeAgentHookWithIntervention,
|
|
266
|
-
executeAgentHook,
|
|
267
|
-
createPriorityHook,
|
|
268
|
-
createHook,
|
|
269
|
-
ToolHookPoints,
|
|
270
|
-
LLMHookPoints,
|
|
271
|
-
HookManager,
|
|
272
|
-
AgentHookPoints
|
|
273
|
-
};
|
|
201
|
+
|
|
202
|
+
export { HookManager, globalHookManager, AgentHookPoints, LLMHookPoints, ToolHookPoints, executeAgentHook, executeAgentHookWithIntervention, executeLLMHook, executeToolHook };
|
package/dist/{env/debug/formatters/index.js → shared/@ai-setting/roy-agent-core-w76hqkmg.js}
RENAMED
|
@@ -1,54 +1,3 @@
|
|
|
1
|
-
// @bun
|
|
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 = import.meta.require;
|
|
51
|
-
|
|
52
1
|
// packages/core/src/env/debug/formatters/trace-formatter.ts
|
|
53
2
|
class TraceFormatter {
|
|
54
3
|
formatEntry(entry, options = {}) {
|
|
@@ -201,13 +150,13 @@ function color(text, colorCode) {
|
|
|
201
150
|
return `${colorCode}${text}${Colors.reset}`;
|
|
202
151
|
}
|
|
203
152
|
var CHARS = {
|
|
204
|
-
VERTICAL: "
|
|
205
|
-
VERTICAL_CONNECTOR: "
|
|
206
|
-
LAST_CONNECTOR: "
|
|
153
|
+
VERTICAL: "│",
|
|
154
|
+
VERTICAL_CONNECTOR: "├──",
|
|
155
|
+
LAST_CONNECTOR: "└──",
|
|
207
156
|
SPACE: " ",
|
|
208
|
-
BAR: "
|
|
209
|
-
EMPTY: "
|
|
210
|
-
DASH: "
|
|
157
|
+
BAR: "█",
|
|
158
|
+
EMPTY: "░",
|
|
159
|
+
DASH: "─"
|
|
211
160
|
};
|
|
212
161
|
|
|
213
162
|
class TreeFormatter {
|
|
@@ -321,12 +270,12 @@ class TreeFormatter {
|
|
|
321
270
|
=== Duration Summary ===`, Colors.bold));
|
|
322
271
|
lines.push(color(`(sorted by time consumption)
|
|
323
272
|
`, Colors.dim));
|
|
324
|
-
lines.push(color(` ${"
|
|
273
|
+
lines.push(color(` ${"─".repeat(65)}`, Colors.dim));
|
|
325
274
|
lines.push(color(` ${"FUNCTION".padEnd(35)} ${"TIME".padEnd(12)} %`, Colors.dim));
|
|
326
|
-
lines.push(color(` ${"
|
|
275
|
+
lines.push(color(` ${"─".repeat(65)}`, Colors.dim));
|
|
327
276
|
for (const row of rows) {
|
|
328
277
|
const indent = " ".repeat(row.depth);
|
|
329
|
-
const funcDisplay = row.depth > 0 ? "
|
|
278
|
+
const funcDisplay = row.depth > 0 ? "└─ ".repeat(row.depth) + row.func : row.func;
|
|
330
279
|
const percentStr = String(row.percent).padStart(3) + "%";
|
|
331
280
|
const percentColor = row.percent >= 50 ? Colors.red : row.percent >= 20 ? Colors.yellow : Colors.dim;
|
|
332
281
|
lines.push(` ${indent}${funcDisplay.substring(0, 35).padEnd(35)}${this.formatDuration(row.duration).padEnd(12)} ${color(percentStr, percentColor)}`);
|
|
@@ -507,7 +456,7 @@ exit - Exit REPL
|
|
|
507
456
|
const childPrefix = prefix + " ";
|
|
508
457
|
for (let i = 0;i < node.children.length; i++) {
|
|
509
458
|
const isLast = i === node.children.length - 1;
|
|
510
|
-
const connector = isLast ? "
|
|
459
|
+
const connector = isLast ? "└── " : "├── ";
|
|
511
460
|
output += this.formatTreeNode(node.children[i], childPrefix + connector);
|
|
512
461
|
}
|
|
513
462
|
return output;
|
|
@@ -632,8 +581,4 @@ exit - Exit REPL
|
|
|
632
581
|
return [...this.history];
|
|
633
582
|
}
|
|
634
583
|
}
|
|
635
|
-
export {
|
|
636
|
-
TreeFormatter,
|
|
637
|
-
TraceFormatter,
|
|
638
|
-
ReplFormatter
|
|
639
|
-
};
|
|
584
|
+
export { TraceFormatter, TreeFormatter, ReplFormatter };
|