@ai-setting/roy-agent-core 1.5.13-test → 1.5.15-test

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.
Files changed (141) hide show
  1. package/package.json +1 -1
  2. package/dist/config/index.d.ts +0 -1250
  3. package/dist/config/index.js +0 -32
  4. package/dist/env/agent/index.d.ts +0 -2279
  5. package/dist/env/agent/index.js +0 -24
  6. package/dist/env/commands/index.d.ts +0 -1131
  7. package/dist/env/commands/index.js +0 -14
  8. package/dist/env/debug/formatters/index.d.ts +0 -236
  9. package/dist/env/debug/formatters/index.js +0 -11
  10. package/dist/env/debug/index.d.ts +0 -1652
  11. package/dist/env/debug/index.js +0 -26
  12. package/dist/env/hook/index.d.ts +0 -279
  13. package/dist/env/hook/index.js +0 -29
  14. package/dist/env/index.d.ts +0 -3481
  15. package/dist/env/index.js +0 -82
  16. package/dist/env/llm/index.d.ts +0 -1760
  17. package/dist/env/llm/index.js +0 -40
  18. package/dist/env/log-trace/index.d.ts +0 -1574
  19. package/dist/env/log-trace/index.js +0 -83
  20. package/dist/env/mcp/index.d.ts +0 -1331
  21. package/dist/env/mcp/index.js +0 -39
  22. package/dist/env/mcp/tool/index.d.ts +0 -183
  23. package/dist/env/mcp/tool/index.js +0 -14
  24. package/dist/env/memory/built-in/index.d.ts +0 -232
  25. package/dist/env/memory/built-in/index.js +0 -11
  26. package/dist/env/memory/index.d.ts +0 -1799
  27. package/dist/env/memory/index.js +0 -56
  28. package/dist/env/memory/plugin/index.d.ts +0 -747
  29. package/dist/env/memory/plugin/index.js +0 -36
  30. package/dist/env/prompt/index.d.ts +0 -1164
  31. package/dist/env/prompt/index.js +0 -20
  32. package/dist/env/session/index.d.ts +0 -1908
  33. package/dist/env/session/index.js +0 -25
  34. package/dist/env/session/storage/index.d.ts +0 -564
  35. package/dist/env/session/storage/index.js +0 -18
  36. package/dist/env/skill/index.d.ts +0 -1266
  37. package/dist/env/skill/index.js +0 -34
  38. package/dist/env/skill/tool/index.d.ts +0 -193
  39. package/dist/env/skill/tool/index.js +0 -9
  40. package/dist/env/task/delegate/index.d.ts +0 -1612
  41. package/dist/env/task/delegate/index.js +0 -18
  42. package/dist/env/task/events/index.d.ts +0 -171
  43. package/dist/env/task/events/index.js +0 -7
  44. package/dist/env/task/hooks/index.d.ts +0 -624
  45. package/dist/env/task/hooks/index.js +0 -7
  46. package/dist/env/task/index.d.ts +0 -1553
  47. package/dist/env/task/index.js +0 -34
  48. package/dist/env/task/plugins/index.d.ts +0 -466
  49. package/dist/env/task/plugins/index.js +0 -23
  50. package/dist/env/task/storage/index.d.ts +0 -241
  51. package/dist/env/task/storage/index.js +0 -14
  52. package/dist/env/task/tools/index.d.ts +0 -1485
  53. package/dist/env/task/tools/index.js +0 -17
  54. package/dist/env/task/tools/operation/index.d.ts +0 -1484
  55. package/dist/env/task/tools/operation/index.js +0 -15
  56. package/dist/env/tool/built-in/index.d.ts +0 -218
  57. package/dist/env/tool/built-in/index.js +0 -25
  58. package/dist/env/tool/index.d.ts +0 -1396
  59. package/dist/env/tool/index.js +0 -39
  60. package/dist/env/workflow/decorators/index.d.ts +0 -2161
  61. package/dist/env/workflow/decorators/index.js +0 -27
  62. package/dist/env/workflow/engine/index.d.ts +0 -3453
  63. package/dist/env/workflow/engine/index.js +0 -28
  64. package/dist/env/workflow/index.d.ts +0 -3546
  65. package/dist/env/workflow/index.js +0 -136
  66. package/dist/env/workflow/nodes/index.d.ts +0 -2092
  67. package/dist/env/workflow/nodes/index.js +0 -19
  68. package/dist/env/workflow/service/index.d.ts +0 -227
  69. package/dist/env/workflow/service/index.js +0 -13
  70. package/dist/env/workflow/storage/index.d.ts +0 -165
  71. package/dist/env/workflow/storage/index.js +0 -27
  72. package/dist/env/workflow/tools/index.d.ts +0 -416
  73. package/dist/env/workflow/tools/index.js +0 -159
  74. package/dist/env/workflow/types/index.d.ts +0 -2255
  75. package/dist/env/workflow/types/index.js +0 -98
  76. package/dist/env/workflow/utils/index.d.ts +0 -2031
  77. package/dist/env/workflow/utils/index.js +0 -637
  78. package/dist/index.d.ts +0 -7858
  79. package/dist/index.js +0 -399
  80. package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +0 -258
  81. package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +0 -36
  82. package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +0 -349
  83. package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +0 -117
  84. package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +0 -11
  85. package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +0 -393
  86. package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +0 -200
  87. package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +0 -299
  88. package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +0 -206
  89. package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +0 -393
  90. package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +0 -350
  91. package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +0 -180
  92. package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +0 -408
  93. package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +0 -284
  94. package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +0 -762
  95. package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +0 -10
  96. package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +0 -14
  97. package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +0 -922
  98. package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +0 -15
  99. package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +0 -1130
  100. package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +0 -14
  101. package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +0 -653
  102. package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +0 -93
  103. package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +0 -872
  104. package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +0 -11
  105. package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +0 -64
  106. package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +0 -378
  107. package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +0 -492
  108. package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +0 -52
  109. package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +0 -171
  110. package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +0 -862
  111. package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +0 -1387
  112. package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +0 -208
  113. package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +0 -139
  114. package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +0 -534
  115. package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +0 -204
  116. package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +0 -603
  117. package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +0 -97
  118. package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +0 -587
  119. package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +0 -176
  120. package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +0 -60
  121. package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +0 -442
  122. package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +0 -57
  123. package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +0 -66
  124. package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +0 -10
  125. package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +0 -267
  126. package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +0 -584
  127. package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +0 -102
  128. package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +0 -549
  129. package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +0 -15
  130. package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +0 -213
  131. package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +0 -812
  132. package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +0 -1316
  133. package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +0 -1205
  134. package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +0 -328
  135. package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +0 -20
  136. package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +0 -2098
  137. package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +0 -419
  138. package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +0 -368
  139. package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +0 -377
  140. package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +0 -172
  141. package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +0 -103
@@ -1,299 +0,0 @@
1
- import {
2
- getTracerProvider,
3
- init_tracer_provider
4
- } from "./roy-agent-core-xs5rsgat.js";
5
- import {
6
- __esm,
7
- __require
8
- } from "./roy-agent-core-fs0mn2jk.js";
9
-
10
- // src/env/log-trace/logger.ts
11
- import { appendFileSync, existsSync, mkdirSync } from "fs";
12
- import { join } from "path";
13
- function simplifyFilePath(fullPath) {
14
- let path = fullPath.replace(/\\/g, "/");
15
- const bunfsMatch = path.match(/\/\$bunfs\/root\/(.+)$/);
16
- if (bunfsMatch) {
17
- const virtualPath = bunfsMatch[1];
18
- const packagesMatch = virtualPath.match(/(packages\/[^/]+\/src\/[^/]+\/.+)$/);
19
- if (packagesMatch) {
20
- return packagesMatch[1];
21
- }
22
- return virtualPath;
23
- }
24
- const fileProtocolMatch = path.match(/@roy-agent\+core@file\+([^/]+)\/node_modules\/@roy-agent\/core\/(.+)$/);
25
- if (fileProtocolMatch) {
26
- const rootPkg = fileProtocolMatch[1].replace(/\+/g, "/");
27
- const remaining = fileProtocolMatch[2];
28
- const prefix = rootPkg;
29
- const suffix = remaining.startsWith("src/") ? remaining : `src/${remaining}`;
30
- return `${prefix}/${suffix}`;
31
- }
32
- const packagesRootMatch = path.match(/(packages\/[^/]+\/src\/[^/]+\/.+)$/);
33
- if (packagesRootMatch) {
34
- return packagesRootMatch[1];
35
- }
36
- const rootMarkers = ["packages/core/src", "packages/core", "packages"];
37
- for (const marker of rootMarkers) {
38
- const idx = path.indexOf(marker);
39
- if (idx !== -1) {
40
- return path.substring(idx);
41
- }
42
- }
43
- return path;
44
- }
45
- function getDefaultLogDir() {
46
- const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
47
- try {
48
- const xdg = __require("xdg-basedir");
49
- if (xdg.xdgData) {
50
- return join(xdg.xdgData, "roy-agent", "logs");
51
- }
52
- } catch {}
53
- return join(home, ".local", "share", "roy-agent", "logs");
54
- }
55
- function isQuietMode() {
56
- return quietMode;
57
- }
58
- function setQuietMode(enabled) {
59
- quietMode = enabled;
60
- }
61
- function setConfigComponent(component) {
62
- configComponentInstance = component;
63
- }
64
- function getLogLevel() {
65
- if (configComponentInstance) {
66
- const level = configComponentInstance.get("log_trace.logging.level");
67
- if (level && ["debug", "info", "warn", "error"].includes(level)) {
68
- return level;
69
- }
70
- }
71
- const envLevel = process.env.LOG_LEVEL;
72
- if (envLevel && ["debug", "info", "warn", "error"].includes(envLevel)) {
73
- return envLevel;
74
- }
75
- return "info";
76
- }
77
- function getCategoryLogLevel(category) {
78
- if (configComponentInstance) {
79
- const levels = configComponentInstance.get("log_trace.logging.levels");
80
- if (levels && typeof levels === "object") {
81
- const categoryLevel = levels[category];
82
- if (categoryLevel && ["debug", "info", "warn", "error"].includes(categoryLevel)) {
83
- return categoryLevel;
84
- }
85
- }
86
- const directLevel = configComponentInstance.get(`log_trace.logging.levels.${category}`);
87
- if (directLevel && ["debug", "info", "warn", "error"].includes(directLevel)) {
88
- return directLevel;
89
- }
90
- }
91
- const envKey = `LOG_LEVEL_${category.toUpperCase().replace(/:/g, "_")}`;
92
- const envLevel = process.env[envKey];
93
- if (envLevel && ["debug", "info", "warn", "error"].includes(envLevel)) {
94
- return envLevel;
95
- }
96
- return getLogLevel();
97
- }
98
- function isAbsolutePath(path) {
99
- if (path.startsWith("/")) {
100
- return true;
101
- }
102
- if (/^[a-zA-Z]:[/\\]/.test(path)) {
103
- return true;
104
- }
105
- return false;
106
- }
107
- function expandHomeDir(path) {
108
- if (path.startsWith("~")) {
109
- const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
110
- return join(home, path.slice(1));
111
- }
112
- return path;
113
- }
114
- function getLogFile() {
115
- if (configComponentInstance) {
116
- const file = configComponentInstance.get("log_trace.logging.file");
117
- if (file) {
118
- return file;
119
- }
120
- }
121
- return "app.log";
122
- }
123
- function getLogDir() {
124
- if (configComponentInstance) {
125
- const dir = configComponentInstance.get("log_trace.logging.dir");
126
- if (dir) {
127
- return dir;
128
- }
129
- }
130
- return getDefaultLogDir();
131
- }
132
- function getMaxOutput() {
133
- if (configComponentInstance) {
134
- const maxOutput = configComponentInstance.get("log-trace.logging.maxOutput");
135
- if (typeof maxOutput === "number") {
136
- return maxOutput;
137
- }
138
- }
139
- return;
140
- }
141
- function setLogDirOverride(dir) {
142
- logDirOverride = dir;
143
- }
144
- function getLogDirOverride() {
145
- return logDirOverride;
146
- }
147
-
148
- class Logger {
149
- prefix;
150
- constructor(prefix) {
151
- this.prefix = prefix;
152
- }
153
- shouldLog(level) {
154
- const categoryLevel = getCategoryLogLevel(this.prefix);
155
- return levelPriority[level] >= levelPriority[categoryLevel];
156
- }
157
- ensureLogDirectory(dir) {
158
- if (!existsSync(dir)) {
159
- try {
160
- mkdirSync(dir, { recursive: true });
161
- } catch (err) {
162
- console.error("[Logger] Failed to create log directory:", dir, err);
163
- }
164
- }
165
- }
166
- getCallerLocation() {
167
- const originalLimit = Error.stackTraceLimit;
168
- Error.stackTraceLimit = 10;
169
- const err = new Error;
170
- Error.captureStackTrace(err, this.formatMessage);
171
- const stack = err.stack?.split(`
172
- `) || [];
173
- Error.stackTraceLimit = originalLimit;
174
- for (let i = 1;i < stack.length; i++) {
175
- const line = stack[i];
176
- if (line.includes("at ") && !line.includes("logger.ts") && !line.includes("formatMessage")) {
177
- const match = line.match(/at\s+.+\s+\((.+):(\d+):\d+\)/) || line.match(/at\s+(.+):(\d+):\d+/);
178
- if (match) {
179
- const filePath = match[1];
180
- const relativePath = this.getRelativePath(filePath);
181
- return {
182
- file: relativePath,
183
- line: parseInt(match[2], 10)
184
- };
185
- }
186
- }
187
- }
188
- return null;
189
- }
190
- getRelativePath(fullPath) {
191
- return simplifyFilePath(fullPath);
192
- }
193
- formatMessage(level, message, data) {
194
- const now = new Date;
195
- const timestamp = now.toLocaleString("zh-CN", {
196
- timeZone: "Asia/Shanghai",
197
- year: "numeric",
198
- month: "2-digit",
199
- day: "2-digit",
200
- hour: "2-digit",
201
- minute: "2-digit",
202
- second: "2-digit",
203
- hour12: false
204
- }).replace(/\//g, "-") + "." + String(now.getMilliseconds()).padStart(3, "0");
205
- const prefix = this.prefix ? `[${this.prefix}]` : "";
206
- let traceIdStr = "";
207
- try {
208
- const provider = getTracerProvider();
209
- const tracer = provider.getTracer("roy-tracer");
210
- const context = tracer.getCurrentContext();
211
- if (context?.traceId) {
212
- traceIdStr = `[traceId=${context.traceId}]`;
213
- }
214
- } catch {}
215
- let locationStr = "";
216
- if (data && typeof data === "object" && "callerLocation" in data) {
217
- const logData = data;
218
- locationStr = logData.callerLocation ? ` [${logData.callerLocation}]` : "";
219
- const { callerLocation: _callerLocation, ...rest } = logData;
220
- data = Object.keys(rest).length > 0 ? rest : undefined;
221
- } else {
222
- const location = this.getCallerLocation();
223
- if (location) {
224
- locationStr = ` [${location.file}:${location.line}]`;
225
- }
226
- }
227
- let formatted = `${timestamp} [${level.toUpperCase()}]${traceIdStr}${locationStr}${prefix} ${message}`;
228
- if (data !== undefined) {
229
- if (typeof data === "object") {
230
- formatted += " " + JSON.stringify(data).replace(/\n/g, "");
231
- } else {
232
- formatted += " " + String(data);
233
- }
234
- }
235
- const maxOutput = getMaxOutput();
236
- if (maxOutput && maxOutput > 0 && formatted.length > maxOutput) {
237
- formatted = formatted.substring(0, maxOutput) + " [TRUNCATED]";
238
- }
239
- return formatted;
240
- }
241
- writeToFile(message) {
242
- try {
243
- const dir = getLogDir();
244
- const filename = getLogFile();
245
- const expandedDir = expandHomeDir(dir);
246
- const resolvedDir = isAbsolutePath(expandedDir) ? expandedDir : join(process.cwd(), expandedDir);
247
- this.ensureLogDirectory(resolvedDir);
248
- const logFile = join(resolvedDir, filename);
249
- appendFileSync(logFile, message + `
250
- `, "utf-8");
251
- } catch (err) {
252
- console.error("[Logger] Failed to write to log file:", err);
253
- }
254
- }
255
- log(level, message, data) {
256
- if (!this.shouldLog(level))
257
- return;
258
- const formatted = this.formatMessage(level, message, data);
259
- this.writeToFile(formatted);
260
- if (!isQuietMode()) {
261
- const consoleMethod = level === "error" ? console.error : level === "warn" ? console.warn : level === "info" ? console.log : console.debug;
262
- consoleMethod(formatted);
263
- }
264
- }
265
- debug(message, data) {
266
- this.log("debug", message, data);
267
- }
268
- info(message, data) {
269
- this.log("info", message, data);
270
- }
271
- warn(message, data) {
272
- this.log("warn", message, data);
273
- }
274
- error(message, data) {
275
- this.log("error", message, data);
276
- }
277
- }
278
- function createLogger(prefix) {
279
- if (!loggerCache.has(prefix)) {
280
- loggerCache.set(prefix, new Logger(prefix));
281
- }
282
- return loggerCache.get(prefix);
283
- }
284
- function getLogLevels() {
285
- return ["debug", "info", "warn", "error"];
286
- }
287
- var configComponentInstance = null, quietMode = false, logDirOverride, levelPriority, loggerCache;
288
- var init_logger = __esm(() => {
289
- init_tracer_provider();
290
- levelPriority = {
291
- debug: 0,
292
- info: 1,
293
- warn: 2,
294
- error: 3
295
- };
296
- loggerCache = new Map;
297
- });
298
-
299
- export { simplifyFilePath, isQuietMode, setQuietMode, setConfigComponent, getLogLevel, getLogFile, getLogDir, getMaxOutput, setLogDirOverride, getLogDirOverride, createLogger, getLogLevels, init_logger };
@@ -1,206 +0,0 @@
1
- // src/env/workflow/service/workflow-service.ts
2
- class WorkflowService {
3
- workflowRepository;
4
- engineFactory;
5
- sessionComponent;
6
- constructor(workflowRepository, engineFactory, sessionComponent) {
7
- this.workflowRepository = workflowRepository;
8
- this.engineFactory = engineFactory;
9
- this.sessionComponent = sessionComponent;
10
- }
11
- async createWorkflow(definition, options) {
12
- const existing = this.workflowRepository.getByName(definition.name);
13
- if (existing) {
14
- if (options?.force !== true) {
15
- throw new Error(`Workflow already exists: ${definition.name}`);
16
- }
17
- return this.workflowRepository.update(existing.id, {
18
- name: definition.name,
19
- version: definition.version,
20
- description: definition.description || existing.description,
21
- definition,
22
- config: definition.config || {},
23
- metadata: {
24
- ...options.metadata || definition.metadata || existing.metadata || {},
25
- taskId: options.taskId || definition.metadata?.taskId || existing.metadata?.taskId
26
- },
27
- tags: options.tags || definition.metadata?.tags || []
28
- });
29
- }
30
- const workflow = {
31
- name: definition.name,
32
- version: definition.version,
33
- description: definition.description,
34
- definition,
35
- config: definition.config || {},
36
- metadata: {
37
- ...options?.metadata || definition.metadata || {},
38
- taskId: options?.taskId || definition.metadata?.taskId
39
- },
40
- tags: options?.tags || definition.metadata?.tags || []
41
- };
42
- return this.workflowRepository.create(workflow);
43
- }
44
- getWorkflow(idOrName) {
45
- let workflow = this.workflowRepository.getById(idOrName);
46
- if (workflow)
47
- return workflow;
48
- return this.workflowRepository.getByName(idOrName);
49
- }
50
- getWorkflowById(id) {
51
- return this.workflowRepository.getById(id);
52
- }
53
- getWorkflowByName(name) {
54
- return this.workflowRepository.getByName(name);
55
- }
56
- listWorkflows(options) {
57
- return this.workflowRepository.list(options);
58
- }
59
- async updateWorkflow(idOrName, updates, options) {
60
- let workflow = this.workflowRepository.getByName(idOrName);
61
- if (!workflow) {
62
- workflow = this.workflowRepository.getById(idOrName);
63
- }
64
- if (!workflow) {
65
- throw new Error(`Workflow not found: ${idOrName}`);
66
- }
67
- const updateData = {
68
- ...updates
69
- };
70
- if (options?.tags !== undefined) {
71
- updateData.tags = options.tags;
72
- }
73
- const updated = this.workflowRepository.update(workflow.id, updateData);
74
- if (!updated) {
75
- throw new Error(`Failed to update workflow: ${idOrName}`);
76
- }
77
- return updated;
78
- }
79
- async deleteWorkflow(idOrName) {
80
- let workflow = this.workflowRepository.getByName(idOrName);
81
- if (!workflow) {
82
- workflow = this.workflowRepository.getById(idOrName);
83
- }
84
- if (!workflow) {
85
- return false;
86
- }
87
- return this.workflowRepository.delete(workflow.id);
88
- }
89
- async runWorkflow(idOrNameOrDefinition, input, options) {
90
- let workflow = null;
91
- let definition = null;
92
- if (typeof idOrNameOrDefinition === "string") {
93
- workflow = this.getWorkflow(idOrNameOrDefinition);
94
- if (!workflow) {
95
- throw new Error(`Workflow not found: ${idOrNameOrDefinition}`);
96
- }
97
- definition = workflow.definition;
98
- } else {
99
- definition = idOrNameOrDefinition;
100
- workflow = this.getWorkflowByName(definition.name);
101
- if (!workflow) {
102
- workflow = {
103
- id: `wf_inline_${definition.name}`,
104
- name: definition.name,
105
- version: definition.version,
106
- description: definition.description,
107
- definition,
108
- config: definition.config || {},
109
- metadata: definition.metadata || {},
110
- tags: definition.metadata?.tags || [],
111
- createdAt: new Date,
112
- updatedAt: new Date
113
- };
114
- }
115
- }
116
- const engine = this.engineFactory(workflow, {
117
- ...options,
118
- input
119
- });
120
- const result = await engine.runWorkflow(workflow, {
121
- ...options,
122
- input
123
- });
124
- return {
125
- ...result,
126
- runId: result.runId || result.sessionId || "",
127
- sessionId: result.sessionId || result.runId || ""
128
- };
129
- }
130
- async runWorkflowByName(name, input, options) {
131
- const workflow = this.getWorkflowByName(name);
132
- if (!workflow) {
133
- throw new Error(`Workflow not found: ${name}`);
134
- }
135
- return this.runWorkflow(name, input, options);
136
- }
137
- async stopRun(sessionId, reason) {
138
- const session = await this.sessionComponent?.get(sessionId);
139
- if (!session) {
140
- throw new Error(`Session not found: ${sessionId}`);
141
- }
142
- const metadata = session.metadata;
143
- if (metadata.type !== "workflow") {
144
- throw new Error(`Session is not a workflow session: ${sessionId}`);
145
- }
146
- const workflow = this.getWorkflowByName(metadata.workflowName);
147
- if (!workflow) {
148
- throw new Error(`Workflow not found: ${metadata.workflowName}`);
149
- }
150
- const engine = this.engineFactory(workflow);
151
- await engine.stop(sessionId, reason);
152
- }
153
- async getSession(sessionId) {
154
- if (!this.sessionComponent) {
155
- return null;
156
- }
157
- const session = await this.sessionComponent.get(sessionId);
158
- return session ?? null;
159
- }
160
- async listSessions(options) {
161
- if (!this.sessionComponent?.list) {
162
- return [];
163
- }
164
- return this.sessionComponent.list(options);
165
- }
166
- async getSessionMessages(sessionId) {
167
- if (!this.sessionComponent) {
168
- return [];
169
- }
170
- return this.sessionComponent.getMessages(sessionId);
171
- }
172
- }
173
- // src/env/workflow/service/registry.ts
174
- class WorkflowServiceRegistry {
175
- static instance;
176
- service = null;
177
- constructor() {}
178
- static getInstance() {
179
- if (!WorkflowServiceRegistry.instance) {
180
- WorkflowServiceRegistry.instance = new WorkflowServiceRegistry;
181
- }
182
- return WorkflowServiceRegistry.instance;
183
- }
184
- register(service) {
185
- this.service = service;
186
- }
187
- get() {
188
- if (!this.service) {
189
- throw new Error("WorkflowService is not registered. Call register() first.");
190
- }
191
- return this.service;
192
- }
193
- isRegistered() {
194
- return this.service !== null;
195
- }
196
- reset() {
197
- this.service = null;
198
- }
199
- }
200
- function getWorkflowService() {
201
- return WorkflowServiceRegistry.getInstance().get();
202
- }
203
- function registerWorkflowService(service) {
204
- WorkflowServiceRegistry.getInstance().register(service);
205
- }
206
- export { WorkflowService, WorkflowServiceRegistry, getWorkflowService, registerWorkflowService };