@ai-setting/roy-agent-core 1.4.13 → 1.4.15
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/config/index.js +32 -0
- package/dist/env/agent/index.js +24 -0
- package/dist/env/commands/index.js +14 -0
- package/dist/env/debug/formatters/index.js +11 -0
- package/dist/env/debug/index.js +26 -0
- package/dist/env/hook/index.js +29 -0
- package/dist/env/index.js +81 -0
- package/dist/env/llm/index.js +40 -0
- package/dist/env/log-trace/index.js +83 -0
- package/dist/env/mcp/index.js +39 -0
- package/dist/env/mcp/tool/index.js +14 -0
- package/dist/env/memory/built-in/index.js +11 -0
- package/dist/env/memory/index.js +56 -0
- package/dist/env/memory/plugin/index.js +36 -0
- package/dist/env/prompt/index.js +20 -0
- package/dist/env/session/index.js +25 -0
- package/dist/env/session/storage/index.js +18 -0
- package/dist/env/skill/index.js +34 -0
- package/dist/env/skill/tool/index.js +9 -0
- package/dist/env/task/delegate/index.js +18 -0
- package/dist/env/task/hooks/index.js +7 -0
- package/dist/env/task/index.js +30 -0
- package/dist/env/task/plugins/index.js +23 -0
- package/dist/env/task/storage/index.js +14 -0
- package/dist/env/task/tools/index.js +17 -0
- package/dist/env/task/tools/operation/index.js +15 -0
- package/dist/{shared/chunk-1d4rwms4.js → env/tool/built-in/index.js} +4 -4
- package/dist/env/tool/index.js +39 -0
- package/dist/env/workflow/decorators/index.js +27 -0
- package/dist/env/workflow/engine/index.js +28 -0
- package/dist/env/workflow/index.js +132 -0
- package/dist/env/workflow/nodes/index.js +19 -0
- package/dist/env/workflow/service/index.js +13 -0
- package/dist/env/workflow/storage/index.js +27 -0
- package/dist/env/workflow/tools/index.js +159 -0
- package/dist/env/workflow/types/index.js +94 -0
- package/dist/env/workflow/utils/index.js +637 -0
- package/dist/index.js +233 -16386
- package/dist/shared/{chunk-2b5kbhx3.js → @ai-setting/roy-agent-core-0rtxwr28.js} +6 -114
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-12zkpda2.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-2kg2wma8.js +620 -0
- package/dist/shared/@ai-setting/roy-agent-core-2x0m2p66.js +851 -0
- package/dist/shared/@ai-setting/roy-agent-core-35x0wrtt.js +172 -0
- package/dist/shared/{chunk-1pf5mfgd.js → @ai-setting/roy-agent-core-37e4tep3.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-3agad0d9.js +603 -0
- package/dist/shared/@ai-setting/roy-agent-core-4arba14a.js +419 -0
- package/dist/shared/@ai-setting/roy-agent-core-4rqmfr7t.js +266 -0
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +206 -0
- package/dist/shared/@ai-setting/roy-agent-core-561b1c4p.js +377 -0
- package/dist/shared/@ai-setting/roy-agent-core-5xf65pz6.js +1305 -0
- package/dist/shared/@ai-setting/roy-agent-core-6a72jfdy.js +303 -0
- package/dist/shared/{chunk-1aakcfp1.js → @ai-setting/roy-agent-core-7f303ffd.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +284 -0
- package/dist/shared/{chunk-t1rh6jtm.js → @ai-setting/roy-agent-core-7n436rb4.js} +7 -12
- package/dist/shared/@ai-setting/roy-agent-core-7r85t0qn.js +492 -0
- package/dist/shared/@ai-setting/roy-agent-core-7rewcey6.js +862 -0
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-9qwp5qkz.js +1387 -0
- package/dist/shared/{chunk-mf5xqbdh.js → @ai-setting/roy-agent-core-9yxb3ty9.js} +3 -2
- package/dist/shared/@ai-setting/roy-agent-core-anwsxdds.js +1205 -0
- package/dist/shared/{chunk-1qwabsm0.js → @ai-setting/roy-agent-core-bncgx3gb.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-cd00w5mb.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-cgs0j60t.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-dbsk841j.js +286 -0
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +64 -0
- package/dist/shared/{chunk-yqmx37vm.js → @ai-setting/roy-agent-core-e5jcp24a.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-e62e2a5a.js +204 -0
- package/dist/shared/{chunk-g6j5n3gv.js → @ai-setting/roy-agent-core-ewrj1c4k.js} +2 -2
- package/dist/shared/{chunk-rncy3rtd.js → @ai-setting/roy-agent-core-fdb6m4e4.js} +119 -1113
- package/dist/shared/{chunk-q9j99fsm.js → @ai-setting/roy-agent-core-fv32jaa8.js} +3 -3
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +171 -0
- package/dist/shared/@ai-setting/roy-agent-core-gmnkza34.js +202 -0
- package/dist/shared/@ai-setting/roy-agent-core-hz7rr4yx.js +513 -0
- package/dist/shared/@ai-setting/roy-agent-core-j3bbr2n0.js +378 -0
- package/dist/shared/{chunk-a9qmy3sc.js → @ai-setting/roy-agent-core-j3wc4465.js} +6 -3
- package/dist/shared/@ai-setting/roy-agent-core-jj79gszx.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-mwwk6req.js +913 -0
- package/dist/shared/{chunk-0q6s9wm6.js → @ai-setting/roy-agent-core-pc9g3962.js} +6 -50
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-pzsg9pvf.js +393 -0
- package/dist/shared/{chunk-91bas8w5.js → @ai-setting/roy-agent-core-q779wnwm.js} +5 -5
- package/dist/shared/{chunk-25x2pdtp.js → @ai-setting/roy-agent-core-qw0ebh1d.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +66 -0
- package/dist/shared/@ai-setting/roy-agent-core-qya7seh6.js +408 -0
- package/dist/shared/@ai-setting/roy-agent-core-rbetrphj.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-re1wjfw7.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-rft3fmp0.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +584 -0
- package/dist/shared/{chunk-ze20rksg.js → @ai-setting/roy-agent-core-rvxg1wps.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-rzp9kxne.js +341 -0
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +213 -0
- package/dist/shared/@ai-setting/roy-agent-core-w78syn7w.js +788 -0
- package/dist/shared/{chunk-9qzt1v1p.js → @ai-setting/roy-agent-core-z2t8hse8.js} +3 -2
- package/package.json +8 -7
- package/dist/index.d.ts +0 -7825
- package/dist/shared/chunk-hs7tbmje.js +0 -24
- /package/dist/shared/{chunk-wbkh7wat.js → @ai-setting/roy-agent-core-fs0mn2jk.js} +0 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLogger,
|
|
3
|
+
init_logger
|
|
4
|
+
} from "./roy-agent-core-j3wc4465.js";
|
|
5
|
+
|
|
6
|
+
// 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 };
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
getTracerProvider,
|
|
4
4
|
init_tracer_provider,
|
|
5
5
|
resetTracerProvider
|
|
6
|
-
} from "./
|
|
7
|
-
import"./
|
|
8
|
-
import"./
|
|
6
|
+
} from "./roy-agent-core-fv32jaa8.js";
|
|
7
|
+
import"./roy-agent-core-bncgx3gb.js";
|
|
8
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
9
9
|
init_tracer_provider();
|
|
10
10
|
|
|
11
11
|
export {
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_decorator_node
|
|
3
|
+
} from "./roy-agent-core-1ce3fqrk.js";
|
|
4
|
+
|
|
5
|
+
// src/env/workflow/decorators/workflow.ts
|
|
6
|
+
import"reflect-metadata";
|
|
7
|
+
|
|
8
|
+
// src/env/workflow/metadata/keys.ts
|
|
9
|
+
var WORKFLOW_METADATA_KEY = Symbol("workflow:metadata");
|
|
10
|
+
var NODE_METADATA_KEY = Symbol("workflow:node");
|
|
11
|
+
var EDGE_METADATA_KEY = Symbol("workflow:edges");
|
|
12
|
+
|
|
13
|
+
// src/env/workflow/decorators/workflow.ts
|
|
14
|
+
function Workflow(options) {
|
|
15
|
+
return function(target) {
|
|
16
|
+
const metadata = {
|
|
17
|
+
name: options.name,
|
|
18
|
+
version: options.version || "1.0",
|
|
19
|
+
description: options.description,
|
|
20
|
+
entry: options.entry,
|
|
21
|
+
config: options.config,
|
|
22
|
+
tags: options.tags || [],
|
|
23
|
+
author: options.author
|
|
24
|
+
};
|
|
25
|
+
Reflect.defineMetadata(WORKFLOW_METADATA_KEY, metadata, target);
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function getWorkflowMetadata(target) {
|
|
30
|
+
return Reflect.getMetadata(WORKFLOW_METADATA_KEY, target);
|
|
31
|
+
}
|
|
32
|
+
// src/env/workflow/decorators/node-as.ts
|
|
33
|
+
import"reflect-metadata";
|
|
34
|
+
function NodeAs(options = {}) {
|
|
35
|
+
return function(target, propertyKey, descriptor) {
|
|
36
|
+
const methodName = String(propertyKey);
|
|
37
|
+
const nodeMetadata = {
|
|
38
|
+
nodeId: options.nodeId || methodName,
|
|
39
|
+
nodeType: options.nodeType || "tool",
|
|
40
|
+
name: options.name,
|
|
41
|
+
dependsOn: normalizeDependsOn(options.dependsOn),
|
|
42
|
+
condition: options.condition,
|
|
43
|
+
retry: options.retry,
|
|
44
|
+
timeout: options.timeout,
|
|
45
|
+
config: options.config || {},
|
|
46
|
+
methodName,
|
|
47
|
+
method: descriptor.value
|
|
48
|
+
};
|
|
49
|
+
const existingNodes = Reflect.getMetadata(NODE_METADATA_KEY, target) || [];
|
|
50
|
+
const existingIndex = existingNodes.findIndex((n) => n.methodName === methodName);
|
|
51
|
+
if (existingIndex >= 0) {
|
|
52
|
+
existingNodes[existingIndex] = nodeMetadata;
|
|
53
|
+
} else {
|
|
54
|
+
existingNodes.push(nodeMetadata);
|
|
55
|
+
}
|
|
56
|
+
Reflect.defineMetadata(NODE_METADATA_KEY, existingNodes, target);
|
|
57
|
+
return descriptor;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function normalizeDependsOn(dependsOn) {
|
|
61
|
+
if (!dependsOn) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return Array.isArray(dependsOn) ? dependsOn : [dependsOn];
|
|
65
|
+
}
|
|
66
|
+
function getNodeMetadatas(target) {
|
|
67
|
+
return Reflect.getMetadata(NODE_METADATA_KEY, target) || [];
|
|
68
|
+
}
|
|
69
|
+
// src/env/workflow/decorators/edge.ts
|
|
70
|
+
import"reflect-metadata";
|
|
71
|
+
function Edge(from, to) {
|
|
72
|
+
return function(target, propertyKey, descriptor) {
|
|
73
|
+
const edge = { from, to };
|
|
74
|
+
const existingEdges = Reflect.getMetadata(EDGE_METADATA_KEY, target) || [];
|
|
75
|
+
existingEdges.push(edge);
|
|
76
|
+
Reflect.defineMetadata(EDGE_METADATA_KEY, existingEdges, target);
|
|
77
|
+
return descriptor;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function WorkflowEdges(edges) {
|
|
81
|
+
return function(target) {
|
|
82
|
+
const edgeMetadatas = edges.map((edge) => ({
|
|
83
|
+
from: edge.from,
|
|
84
|
+
to: edge.to,
|
|
85
|
+
condition: edge.condition
|
|
86
|
+
}));
|
|
87
|
+
Reflect.defineMetadata(EDGE_METADATA_KEY, edgeMetadatas, target);
|
|
88
|
+
return target;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function getEdgeMetadatas(target) {
|
|
92
|
+
return Reflect.getMetadata(EDGE_METADATA_KEY, target) || [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/env/workflow/decorators/index.ts
|
|
96
|
+
init_decorator_node();
|
|
97
|
+
|
|
98
|
+
// src/env/workflow/extractor/workflow-converter.ts
|
|
99
|
+
import"reflect-metadata";
|
|
100
|
+
class WorkflowConverter {
|
|
101
|
+
static extractWorkflowMetadata(targetClass) {
|
|
102
|
+
return getWorkflowMetadata(targetClass);
|
|
103
|
+
}
|
|
104
|
+
static extractNodeMetadatas(targetClass) {
|
|
105
|
+
return getNodeMetadatas(targetClass.prototype);
|
|
106
|
+
}
|
|
107
|
+
static extractEdgeMetadatas(targetClass) {
|
|
108
|
+
return getEdgeMetadatas(targetClass);
|
|
109
|
+
}
|
|
110
|
+
static fromClass(targetClass, instance) {
|
|
111
|
+
const workflowMeta = this.extractWorkflowMetadata(targetClass);
|
|
112
|
+
if (!workflowMeta) {
|
|
113
|
+
throw new Error("Class must be decorated with @Workflow");
|
|
114
|
+
}
|
|
115
|
+
const nodeMetadatas = this.extractNodeMetadatas(targetClass);
|
|
116
|
+
if (nodeMetadatas.length === 0) {
|
|
117
|
+
throw new Error("At least one method must be decorated with @NodeAs");
|
|
118
|
+
}
|
|
119
|
+
const edgeMetadatas = this.extractEdgeMetadatas(targetClass);
|
|
120
|
+
const nodeMap = this.buildNodeMap(nodeMetadatas, edgeMetadatas);
|
|
121
|
+
const nodes = Array.from(nodeMap.values()).map((meta) => ({
|
|
122
|
+
id: meta.nodeId,
|
|
123
|
+
type: meta.nodeType,
|
|
124
|
+
name: meta.name,
|
|
125
|
+
config: {
|
|
126
|
+
...meta.config,
|
|
127
|
+
_methodName: meta.methodName,
|
|
128
|
+
_instance: instance
|
|
129
|
+
},
|
|
130
|
+
depends_on: meta.dependsOn,
|
|
131
|
+
condition: meta.condition,
|
|
132
|
+
retry: meta.retry,
|
|
133
|
+
timeout: meta.timeout
|
|
134
|
+
}));
|
|
135
|
+
const entry = workflowMeta.entry || nodeMetadatas[0]?.nodeId || "unknown";
|
|
136
|
+
return {
|
|
137
|
+
name: workflowMeta.name,
|
|
138
|
+
version: workflowMeta.version || "1.0",
|
|
139
|
+
description: workflowMeta.description,
|
|
140
|
+
config: workflowMeta.config || {},
|
|
141
|
+
nodes,
|
|
142
|
+
entry,
|
|
143
|
+
outputs: [],
|
|
144
|
+
metadata: {
|
|
145
|
+
tags: workflowMeta.tags || [],
|
|
146
|
+
author: workflowMeta.author
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
static buildNodeMap(nodeMetadatas, edgeMetadatas) {
|
|
151
|
+
const nodeMap = new Map;
|
|
152
|
+
for (const nodeMeta of nodeMetadatas) {
|
|
153
|
+
nodeMap.set(nodeMeta.nodeId, { ...nodeMeta });
|
|
154
|
+
}
|
|
155
|
+
for (const edge of edgeMetadatas) {
|
|
156
|
+
const targetNode = nodeMap.get(edge.to);
|
|
157
|
+
if (targetNode) {
|
|
158
|
+
if (!targetNode.dependsOn.includes(edge.from)) {
|
|
159
|
+
targetNode.dependsOn = [...targetNode.dependsOn, edge.from];
|
|
160
|
+
}
|
|
161
|
+
if (edge.condition) {
|
|
162
|
+
if (targetNode.condition) {
|
|
163
|
+
targetNode.condition = `(${targetNode.condition}) AND (${edge.condition})`;
|
|
164
|
+
} else {
|
|
165
|
+
targetNode.condition = edge.condition;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return nodeMap;
|
|
171
|
+
}
|
|
172
|
+
static validateWorkflowClass(targetClass) {
|
|
173
|
+
const errors = [];
|
|
174
|
+
const warnings = [];
|
|
175
|
+
const workflowMeta = this.extractWorkflowMetadata(targetClass);
|
|
176
|
+
if (!workflowMeta) {
|
|
177
|
+
errors.push("Class must be decorated with @Workflow");
|
|
178
|
+
return { valid: false, errors, warnings };
|
|
179
|
+
}
|
|
180
|
+
const nodeMetadatas = this.extractNodeMetadatas(targetClass);
|
|
181
|
+
if (nodeMetadatas.length === 0) {
|
|
182
|
+
errors.push("At least one method must be decorated with @NodeAs");
|
|
183
|
+
return { valid: false, errors, warnings };
|
|
184
|
+
}
|
|
185
|
+
const entry = workflowMeta.entry;
|
|
186
|
+
if (entry) {
|
|
187
|
+
const entries = Array.isArray(entry) ? entry : [entry];
|
|
188
|
+
for (const e of entries) {
|
|
189
|
+
if (!nodeMetadatas.find((n) => n.nodeId === e)) {
|
|
190
|
+
errors.push(`Entry node '${e}' not found`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (const node of nodeMetadatas) {
|
|
195
|
+
for (const dep of node.dependsOn) {
|
|
196
|
+
if (!nodeMetadatas.find((n) => n.nodeId === dep)) {
|
|
197
|
+
errors.push(`Node '${node.nodeId}' depends on non-existent node '${dep}'`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (this.hasCycle(nodeMetadatas)) {
|
|
202
|
+
errors.push("Workflow contains a cycle");
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
valid: errors.length === 0,
|
|
206
|
+
errors,
|
|
207
|
+
warnings
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
static hasCycle(nodeMetadatas) {
|
|
211
|
+
const visited = new Set;
|
|
212
|
+
const recStack = new Set;
|
|
213
|
+
const adjList = new Map;
|
|
214
|
+
for (const node of nodeMetadatas) {
|
|
215
|
+
adjList.set(node.nodeId, []);
|
|
216
|
+
}
|
|
217
|
+
for (const node of nodeMetadatas) {
|
|
218
|
+
for (const dep of node.dependsOn) {
|
|
219
|
+
const deps = adjList.get(dep);
|
|
220
|
+
if (deps) {
|
|
221
|
+
deps.push(node.nodeId);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const dfs = (nodeId) => {
|
|
226
|
+
visited.add(nodeId);
|
|
227
|
+
recStack.add(nodeId);
|
|
228
|
+
const neighbors = adjList.get(nodeId) || [];
|
|
229
|
+
for (const neighbor of neighbors) {
|
|
230
|
+
if (!visited.has(neighbor)) {
|
|
231
|
+
if (dfs(neighbor)) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
} else if (recStack.has(neighbor)) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
recStack.delete(nodeId);
|
|
239
|
+
return false;
|
|
240
|
+
};
|
|
241
|
+
for (const node of nodeMetadatas) {
|
|
242
|
+
if (!visited.has(node.nodeId)) {
|
|
243
|
+
if (dfs(node.nodeId)) {
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
static async executeNode(nodeDef, context) {
|
|
251
|
+
const instance = nodeDef.config._instance;
|
|
252
|
+
const methodName = nodeDef.config._methodName;
|
|
253
|
+
if (!instance || !methodName) {
|
|
254
|
+
return { output: undefined, error: new Error("Missing method information") };
|
|
255
|
+
}
|
|
256
|
+
const method = instance[methodName];
|
|
257
|
+
if (typeof method !== "function") {
|
|
258
|
+
return { output: undefined, error: new Error(`Method ${methodName} is not a function`) };
|
|
259
|
+
}
|
|
260
|
+
const deps = nodeDef.depends_on || [];
|
|
261
|
+
let input = context.input;
|
|
262
|
+
if (deps.length > 0) {
|
|
263
|
+
input = {};
|
|
264
|
+
for (const depId of deps) {
|
|
265
|
+
input[depId] = context.previousOutputs.get(depId);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
const result = await method.call(instance, input);
|
|
270
|
+
return { output: result };
|
|
271
|
+
} catch (error) {
|
|
272
|
+
return {
|
|
273
|
+
output: undefined,
|
|
274
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// src/env/workflow/utils/create-workflow.ts
|
|
280
|
+
function createWorkflowFromClass(targetClass, options) {
|
|
281
|
+
const instance = options?.instance ?? new targetClass(...options?.constructorArgs ?? []);
|
|
282
|
+
return WorkflowConverter.fromClass(targetClass, instance);
|
|
283
|
+
}
|
|
284
|
+
export { Workflow, getWorkflowMetadata, NodeAs, getNodeMetadatas, Edge, WorkflowEdges, getEdgeMetadatas, WorkflowConverter, createWorkflowFromClass };
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDatabase
|
|
3
|
+
} from "./roy-agent-core-37e4tep3.js";
|
|
1
4
|
import {
|
|
2
5
|
exports_search_query_parser,
|
|
3
6
|
init_search_query_parser
|
|
4
|
-
} from "./
|
|
5
|
-
import {
|
|
6
|
-
getDatabase
|
|
7
|
-
} from "./chunk-1pf5mfgd.js";
|
|
8
|
-
import"./chunk-a9qmy3sc.js";
|
|
9
|
-
import"./chunk-q9j99fsm.js";
|
|
10
|
-
import"./chunk-1qwabsm0.js";
|
|
7
|
+
} from "./roy-agent-core-rvxg1wps.js";
|
|
11
8
|
import {
|
|
12
9
|
__toCommonJS
|
|
13
|
-
} from "./
|
|
10
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
14
11
|
|
|
15
12
|
// src/env/workflow/storage/workflow-repo.ts
|
|
16
13
|
import { randomUUID } from "crypto";
|
|
@@ -199,7 +196,5 @@ class WorkflowRepository {
|
|
|
199
196
|
return rows.map(rowToWorkflow);
|
|
200
197
|
}
|
|
201
198
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
WorkflowRepository
|
|
205
|
-
};
|
|
199
|
+
|
|
200
|
+
export { rowToWorkflow, WorkflowRepository };
|