@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.
Files changed (127) hide show
  1. package/dist/packages/core/src/config/index.js +32 -0
  2. package/dist/packages/core/src/env/agent/index.js +24 -0
  3. package/dist/packages/core/src/env/commands/index.js +14 -0
  4. package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
  5. package/dist/packages/core/src/env/debug/index.js +26 -0
  6. package/dist/packages/core/src/env/hook/index.js +29 -0
  7. package/dist/packages/core/src/env/index.js +81 -0
  8. package/dist/packages/core/src/env/llm/index.js +40 -0
  9. package/dist/packages/core/src/env/log-trace/index.js +83 -0
  10. package/dist/packages/core/src/env/mcp/index.js +39 -0
  11. package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
  12. package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
  13. package/dist/packages/core/src/env/memory/index.js +56 -0
  14. package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
  15. package/dist/packages/core/src/env/prompt/index.js +20 -0
  16. package/dist/packages/core/src/env/session/index.js +25 -0
  17. package/dist/packages/core/src/env/session/storage/index.js +18 -0
  18. package/dist/packages/core/src/env/skill/index.js +34 -0
  19. package/dist/packages/core/src/env/skill/tool/index.js +9 -0
  20. package/dist/packages/core/src/env/task/delegate/index.js +18 -0
  21. package/dist/packages/core/src/env/task/hooks/index.js +7 -0
  22. package/dist/packages/core/src/env/task/index.js +30 -0
  23. package/dist/packages/core/src/env/task/plugins/index.js +23 -0
  24. package/dist/packages/core/src/env/task/storage/index.js +14 -0
  25. package/dist/packages/core/src/env/task/tools/index.js +17 -0
  26. package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
  27. package/dist/packages/core/src/env/tool/built-in/index.js +25 -0
  28. package/dist/packages/core/src/env/tool/index.js +39 -0
  29. package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
  30. package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
  31. package/dist/packages/core/src/env/workflow/index.js +132 -0
  32. package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
  33. package/dist/packages/core/src/env/workflow/service/index.js +13 -0
  34. package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
  35. package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
  36. package/dist/packages/core/src/env/workflow/types/index.js +94 -0
  37. package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
  38. package/dist/packages/core/src/index.js +398 -0
  39. package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
  40. package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
  41. package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
  42. package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
  43. package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
  44. package/dist/shared/@ai-setting/roy-agent-core-0sgn3de4.js +102 -0
  45. package/dist/{env/task/tools/index.js → shared/@ai-setting/roy-agent-core-12x57kf1.js} +1 -59
  46. package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
  47. package/dist/shared/@ai-setting/roy-agent-core-1k28kg7h.js +368 -0
  48. package/dist/shared/@ai-setting/roy-agent-core-1z1zv5g8.js +258 -0
  49. package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
  50. package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
  51. package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
  52. package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
  53. package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
  54. package/dist/shared/@ai-setting/roy-agent-core-4ws8atva.js +107 -0
  55. package/dist/{env/workflow/nodes/index.js → shared/@ai-setting/roy-agent-core-5fbp24se.js} +8 -55
  56. package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
  57. package/dist/shared/@ai-setting/roy-agent-core-6j0zcmwk.js +2146 -0
  58. package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
  59. package/dist/shared/@ai-setting/roy-agent-core-7vrk3add.js +10 -0
  60. package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
  61. package/dist/{env/memory/built-in/index.js → shared/@ai-setting/roy-agent-core-8mbmrwzs.js} +22 -76
  62. package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
  63. package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
  64. package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
  65. package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
  66. package/dist/{env/workflow/types/index.js → shared/@ai-setting/roy-agent-core-fq5mtxsy.js} +16 -154
  67. package/dist/{env/task/hooks/index.js → shared/@ai-setting/roy-agent-core-fs0mn2jk.js} +3 -18
  68. package/dist/{config/index.js → shared/@ai-setting/roy-agent-core-fvd9g6k8.js} +140 -605
  69. package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
  70. package/dist/{env/task/tools/operation/index.js → shared/@ai-setting/roy-agent-core-gy0wp5h7.js} +1 -58
  71. package/dist/shared/@ai-setting/roy-agent-core-hyza1gm7.js +15 -0
  72. package/dist/shared/@ai-setting/roy-agent-core-j8zx62zr.js +154 -0
  73. package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
  74. package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
  75. package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
  76. package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
  77. package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
  78. package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
  79. package/dist/shared/@ai-setting/roy-agent-core-nczzf0ms.js +15 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
  85. package/dist/shared/@ai-setting/roy-agent-core-qg9tcaph.js +11 -0
  86. package/dist/shared/@ai-setting/roy-agent-core-qhyerewk.js +20 -0
  87. package/dist/shared/@ai-setting/roy-agent-core-qxybm159.js +82 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-rh9dpkpw.js +549 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-rr9p1g43.js +205 -0
  90. package/dist/{env/workflow/decorators/index.js → shared/@ai-setting/roy-agent-core-sbzvpfn7.js} +8 -173
  91. package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-tkr5ynkh.js +200 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
  94. package/dist/{env/hook/index.js → shared/@ai-setting/roy-agent-core-w75rafhy.js} +3 -74
  95. package/dist/{env/debug/formatters/index.js → shared/@ai-setting/roy-agent-core-w76hqkmg.js} +11 -66
  96. package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-yn761yve.js +299 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
  99. package/dist/{env/workflow/service/index.js → shared/@ai-setting/roy-agent-core-yt8wdh2w.js} +1 -57
  100. package/package.json +3 -2
  101. package/dist/env/agent/index.js +0 -3035
  102. package/dist/env/commands/index.js +0 -1685
  103. package/dist/env/debug/index.js +0 -2300
  104. package/dist/env/index.js +0 -12591
  105. package/dist/env/llm/index.js +0 -2736
  106. package/dist/env/log-trace/index.js +0 -1779
  107. package/dist/env/mcp/index.js +0 -2173
  108. package/dist/env/mcp/tool/index.js +0 -1149
  109. package/dist/env/memory/index.js +0 -2171
  110. package/dist/env/memory/plugin/index.js +0 -1263
  111. package/dist/env/prompt/index.js +0 -2107
  112. package/dist/env/session/index.js +0 -3594
  113. package/dist/env/session/storage/index.js +0 -2049
  114. package/dist/env/skill/index.js +0 -1635
  115. package/dist/env/skill/tool/index.js +0 -114
  116. package/dist/env/task/delegate/index.js +0 -1844
  117. package/dist/env/task/index.js +0 -3578
  118. package/dist/env/task/plugins/index.js +0 -1626
  119. package/dist/env/task/storage/index.js +0 -1464
  120. package/dist/env/tool/built-in/index.js +0 -1151
  121. package/dist/env/tool/index.js +0 -2284
  122. package/dist/env/workflow/engine/index.js +0 -4391
  123. package/dist/env/workflow/index.js +0 -6214
  124. package/dist/env/workflow/storage/index.js +0 -1236
  125. package/dist/env/workflow/tools/index.js +0 -1081
  126. package/dist/env/workflow/utils/index.js +0 -1631
  127. package/dist/index.js +0 -22778
@@ -0,0 +1,368 @@
1
+ import {
2
+ SQLiteSpanStorage,
3
+ init_span_storage
4
+ } from "./roy-agent-core-j8zx62zr.js";
5
+ import {
6
+ __esm,
7
+ __export,
8
+ __require
9
+ } from "./roy-agent-core-fs0mn2jk.js";
10
+
11
+ // packages/core/src/env/log-trace/opentelemetry/propagation.ts
12
+ function padLeft(str, length) {
13
+ return str.padStart(length, "0");
14
+ }
15
+ function isValidHex(str) {
16
+ return /^[0-9a-f]+$/i.test(str);
17
+ }
18
+ function serialize(context) {
19
+ const traceId = padLeft(context.traceId.toLowerCase(), TRACE_ID_LENGTH);
20
+ const spanId = padLeft(context.spanId.toLowerCase(), PARENT_SPAN_ID_LENGTH);
21
+ const parts = [
22
+ TRACE_CONTEXT_VERSION,
23
+ traceId,
24
+ spanId,
25
+ TRACE_FLAGS_SAMPLED
26
+ ];
27
+ return parts.join("-");
28
+ }
29
+ function parse(traceparent) {
30
+ if (!traceparent || typeof traceparent !== "string") {
31
+ return;
32
+ }
33
+ const trimmed = traceparent.trim();
34
+ const parts = trimmed.split("-");
35
+ if (parts.length !== 4) {
36
+ return;
37
+ }
38
+ const [version, traceId, senderSpanId, flags] = parts;
39
+ if (version !== TRACE_CONTEXT_VERSION) {
40
+ if (version > TRACE_CONTEXT_VERSION) {
41
+ return;
42
+ }
43
+ }
44
+ if (traceId.length !== TRACE_ID_LENGTH || !isValidHex(traceId)) {
45
+ return;
46
+ }
47
+ if (senderSpanId.length !== PARENT_SPAN_ID_LENGTH || !isValidHex(senderSpanId)) {
48
+ return;
49
+ }
50
+ if (flags.length !== FLAGS_LENGTH || !isValidHex(flags)) {
51
+ return;
52
+ }
53
+ return {
54
+ traceId: traceId.toLowerCase(),
55
+ spanId: senderSpanId.toLowerCase()
56
+ };
57
+ }
58
+ var TRACE_CONTEXT_VERSION = "00", TRACE_FLAGS_SAMPLED = "01", TRACEPARENT_HEADER = "TRACEPARENT", TRACE_ID_LENGTH = 32, PARENT_SPAN_ID_LENGTH = 16, FLAGS_LENGTH = 2, propagation;
59
+ var init_propagation = __esm(() => {
60
+ propagation = {
61
+ inject(carrier, context) {
62
+ carrier[TRACEPARENT_HEADER] = serialize(context);
63
+ },
64
+ extract(carrier) {
65
+ const traceparent = carrier[TRACEPARENT_HEADER];
66
+ if (!traceparent) {
67
+ return;
68
+ }
69
+ return parse(traceparent);
70
+ },
71
+ getTraceparentHeader() {
72
+ return TRACEPARENT_HEADER;
73
+ }
74
+ };
75
+ });
76
+
77
+ // packages/core/src/env/log-trace/types.ts
78
+ var SpanKind, SpanStatus;
79
+ var init_types = __esm(() => {
80
+ ((SpanKind2) => {
81
+ SpanKind2["CLIENT"] = "client";
82
+ SpanKind2["SERVER"] = "server";
83
+ SpanKind2["INTERNAL"] = "internal";
84
+ })(SpanKind ||= {});
85
+ ((SpanStatus2) => {
86
+ SpanStatus2["OK"] = "ok";
87
+ SpanStatus2["ERROR"] = "error";
88
+ })(SpanStatus ||= {});
89
+ });
90
+
91
+ // packages/core/src/env/log-trace/opentelemetry/tracer-provider.ts
92
+ var exports_tracer_provider = {};
93
+ __export(exports_tracer_provider, {
94
+ resetTracerProvider: () => resetTracerProvider,
95
+ getTracerProvider: () => getTracerProvider,
96
+ OTelTracerProvider: () => OTelTracerProvider
97
+ });
98
+
99
+ class OTelSpanImpl {
100
+ name;
101
+ kind;
102
+ spanContext;
103
+ attributes = {};
104
+ startTime;
105
+ endTime;
106
+ error;
107
+ storage;
108
+ parentSpanContext;
109
+ onEnd;
110
+ constructor(name, spanContext, storage, parentSpanContext, onEnd) {
111
+ this.name = name;
112
+ this.kind = "internal";
113
+ this.spanContext = spanContext;
114
+ this.parentSpanContext = parentSpanContext;
115
+ this.startTime = Date.now();
116
+ this.storage = storage;
117
+ this.onEnd = onEnd;
118
+ }
119
+ setAttribute(key, value) {
120
+ this.attributes[key] = value;
121
+ }
122
+ addEvent(name, attributes) {
123
+ const events = this.attributes._events || [];
124
+ events.push({ name, attributes });
125
+ this.attributes._events = events;
126
+ }
127
+ end(result, error) {
128
+ this.endTime = Date.now();
129
+ if (error) {
130
+ this.error = error.message;
131
+ }
132
+ this.storage.save({
133
+ traceId: this.spanContext.traceId,
134
+ spanId: this.spanContext.spanId,
135
+ parentSpanId: this.spanContext.parentSpanId,
136
+ name: this.name,
137
+ kind: this.kind,
138
+ status: error ? "error" /* ERROR */ : "ok" /* OK */,
139
+ startTime: this.startTime,
140
+ endTime: this.endTime,
141
+ attributes: this.attributes,
142
+ result,
143
+ error: this.error
144
+ });
145
+ this.onEnd?.();
146
+ }
147
+ }
148
+
149
+ class OTelTracerImpl {
150
+ name;
151
+ version;
152
+ storage;
153
+ currentContext;
154
+ activeSpans = new Map;
155
+ onSpanEndCallback;
156
+ provider;
157
+ constructor(name, version, storage, provider) {
158
+ this.name = name;
159
+ this.version = version;
160
+ this.storage = storage;
161
+ this.provider = provider;
162
+ }
163
+ setOnSpanEndCallback(callback) {
164
+ this.onSpanEndCallback = callback;
165
+ }
166
+ getActiveSpanCount() {
167
+ return this.activeSpans.size;
168
+ }
169
+ startSpan(name, options) {
170
+ const parentFromOptions = options?.parent;
171
+ const hasExplicitParent = options && "parent" in options;
172
+ const globalContext = this.provider.getGlobalContext();
173
+ let effectiveParentContext;
174
+ if (hasExplicitParent) {
175
+ effectiveParentContext = parentFromOptions;
176
+ } else if (this.currentContext) {
177
+ effectiveParentContext = this.currentContext;
178
+ } else if (globalContext) {
179
+ effectiveParentContext = globalContext;
180
+ }
181
+ const traceId = effectiveParentContext?.traceId || this.generateTraceId();
182
+ const spanId = this.generateSpanId();
183
+ let parentSpanId;
184
+ if (hasExplicitParent && parentFromOptions) {
185
+ parentSpanId = parentFromOptions.parentSpanId || parentFromOptions.spanId;
186
+ } else if (this.currentContext) {
187
+ parentSpanId = this.currentContext.spanId;
188
+ } else if (globalContext) {
189
+ parentSpanId = globalContext.spanId;
190
+ }
191
+ const spanContext = {
192
+ traceId,
193
+ spanId,
194
+ parentSpanId
195
+ };
196
+ this.currentContext = {
197
+ traceId,
198
+ spanId,
199
+ parentSpanId
200
+ };
201
+ const span = new OTelSpanImpl(name, spanContext, this.storage, effectiveParentContext, () => this.handleSpanEnd(spanContext.spanId, effectiveParentContext?.spanId));
202
+ if (options?.attributes) {
203
+ for (const [key, value] of Object.entries(options.attributes)) {
204
+ span.setAttribute(key, value);
205
+ }
206
+ }
207
+ this.activeSpans.set(spanId, span);
208
+ return span;
209
+ }
210
+ injectToEnv(env) {
211
+ if (this.currentContext) {
212
+ propagation.inject(env, this.currentContext);
213
+ }
214
+ }
215
+ getCurrentContext() {
216
+ return this.currentContext;
217
+ }
218
+ setCurrentContext(context) {
219
+ this.currentContext = context;
220
+ }
221
+ endSpan(span) {
222
+ const spanContext = span.spanContext;
223
+ this.activeSpans.delete(spanContext.spanId);
224
+ const currentTraceId = this.currentContext?.traceId;
225
+ if (spanContext.parentSpanId) {
226
+ const parentSpan = this.activeSpans.get(spanContext.parentSpanId);
227
+ if (parentSpan) {
228
+ const parentContext = {
229
+ traceId: spanContext.traceId,
230
+ spanId: parentSpan.spanContext.spanId,
231
+ parentSpanId: parentSpan.spanContext.parentSpanId
232
+ };
233
+ this.currentContext = parentContext;
234
+ return parentContext;
235
+ }
236
+ if (currentTraceId) {
237
+ const parentContext = {
238
+ traceId: currentTraceId,
239
+ spanId: spanContext.parentSpanId,
240
+ parentSpanId: undefined
241
+ };
242
+ this.currentContext = parentContext;
243
+ return parentContext;
244
+ }
245
+ }
246
+ this.currentContext = undefined;
247
+ return;
248
+ }
249
+ generateTraceId() {
250
+ const timestamp = Date.now().toString(16).padStart(12, "0");
251
+ const random = Array.from({ length: 5 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("");
252
+ return (timestamp + random).slice(0, 32).padStart(32, "0");
253
+ }
254
+ generateSpanId() {
255
+ return Math.floor(Math.random() * 18446744073709552000).toString(16).padStart(16, "0");
256
+ }
257
+ handleSpanEnd(spanId, parentSpanId) {
258
+ this.activeSpans.delete(spanId);
259
+ const currentTraceId = this.currentContext?.traceId;
260
+ if (parentSpanId) {
261
+ const parentSpan = this.activeSpans.get(parentSpanId);
262
+ if (parentSpan) {
263
+ this.currentContext = {
264
+ traceId: parentSpan.spanContext.traceId,
265
+ spanId: parentSpan.spanContext.spanId,
266
+ parentSpanId: parentSpan.spanContext.parentSpanId
267
+ };
268
+ return;
269
+ }
270
+ if (currentTraceId) {
271
+ this.currentContext = {
272
+ traceId: currentTraceId,
273
+ spanId: parentSpanId,
274
+ parentSpanId: undefined
275
+ };
276
+ return;
277
+ }
278
+ }
279
+ this.currentContext = undefined;
280
+ }
281
+ }
282
+
283
+ class OTelTracerProvider {
284
+ tracers = new Map;
285
+ storage;
286
+ initialized = false;
287
+ globalContext;
288
+ constructor(storage, dbPath) {
289
+ this.storage = storage || new SQLiteSpanStorage(dbPath || getDefaultDbPath());
290
+ }
291
+ async initialize() {
292
+ if (this.initialized)
293
+ return;
294
+ await this.storage.initialize();
295
+ this.initialized = true;
296
+ }
297
+ isInitialized() {
298
+ return this.initialized;
299
+ }
300
+ getGlobalContext() {
301
+ return this.globalContext;
302
+ }
303
+ setGlobalContext(context) {
304
+ this.globalContext = context;
305
+ }
306
+ getTracer(name, version) {
307
+ const key = `${name}@${version || "0.0.0"}`;
308
+ let tracer = this.tracers.get(key);
309
+ if (!tracer) {
310
+ tracer = new OTelTracerImpl(name, version, this.storage, this);
311
+ this.tracers.set(key, tracer);
312
+ if (this.initialized) {
313
+ this.restoreFromEnv(tracer);
314
+ }
315
+ }
316
+ return tracer;
317
+ }
318
+ restoreFromEnv(tracer) {
319
+ const extracted = propagation.extract(process.env);
320
+ if (extracted) {
321
+ tracer.setCurrentContext({
322
+ traceId: extracted.traceId,
323
+ spanId: extracted.spanId,
324
+ parentSpanId: undefined
325
+ });
326
+ }
327
+ }
328
+ shutdown() {
329
+ for (const tracer of this.tracers.values()) {}
330
+ this.tracers.clear();
331
+ this.storage.close();
332
+ this.initialized = false;
333
+ this.globalContext = undefined;
334
+ delete process.env["TRACEPARENT"];
335
+ delete process.env["TRACE_ID"];
336
+ delete process.env["LOG_TRACE_REQUEST_ID"];
337
+ }
338
+ getStorage() {
339
+ return this.storage;
340
+ }
341
+ }
342
+ function getTracerProvider() {
343
+ if (!providerInstance) {
344
+ providerInstance = new OTelTracerProvider;
345
+ }
346
+ return providerInstance;
347
+ }
348
+ function resetTracerProvider() {
349
+ if (providerInstance) {
350
+ providerInstance.shutdown();
351
+ providerInstance = null;
352
+ }
353
+ }
354
+ function getDefaultDbPath() {
355
+ const os = __require("os");
356
+ const path = __require("path");
357
+ const home = os.homedir();
358
+ const dataHome = process.env.XDG_DATA_HOME || path.join(home, ".local", "share");
359
+ return path.join(dataHome, "roy-agent", "traces.db");
360
+ }
361
+ var providerInstance = null;
362
+ var init_tracer_provider = __esm(() => {
363
+ init_span_storage();
364
+ init_propagation();
365
+ init_types();
366
+ });
367
+
368
+ export { serialize, parse, propagation, init_propagation, SpanKind, SpanStatus, init_types, OTelTracerProvider, getTracerProvider, resetTracerProvider, exports_tracer_provider, init_tracer_provider };
@@ -0,0 +1,258 @@
1
+ import {
2
+ DecoratorNode,
3
+ init_decorator_node
4
+ } from "./roy-agent-core-3tnb2005.js";
5
+ import {
6
+ __esm,
7
+ __export
8
+ } from "./roy-agent-core-fs0mn2jk.js";
9
+
10
+ // packages/core/src/env/workflow/nodes/condition-node.ts
11
+ class ConditionNode {
12
+ definition;
13
+ type = "condition";
14
+ id;
15
+ constructor(definition) {
16
+ this.definition = definition;
17
+ this.id = definition.id;
18
+ }
19
+ async execute(context) {
20
+ const startTime = Date.now();
21
+ try {
22
+ const conditionConfig = this.definition.config?.condition;
23
+ if (conditionConfig === undefined) {
24
+ return {
25
+ output: { success: true, condition: true },
26
+ error: undefined,
27
+ durationMs: Date.now() - startTime
28
+ };
29
+ }
30
+ const resolvedCondition = this.resolveCondition(conditionConfig, context);
31
+ const result = this.evaluateCondition(resolvedCondition);
32
+ return {
33
+ output: { success: result, condition: resolvedCondition },
34
+ error: undefined,
35
+ durationMs: Date.now() - startTime
36
+ };
37
+ } catch (error) {
38
+ return {
39
+ output: undefined,
40
+ error: error instanceof Error ? error : new Error(String(error)),
41
+ durationMs: Date.now() - startTime
42
+ };
43
+ }
44
+ }
45
+ resolveCondition(condition, context) {
46
+ if (typeof condition === "string") {
47
+ const templateMatch = condition.match(/^\{\{([^}]+)\}\}$/);
48
+ if (templateMatch) {
49
+ const path = templateMatch[1].trim();
50
+ return this.resolveTemplate(path, context);
51
+ }
52
+ if (condition === "true")
53
+ return true;
54
+ if (condition === "false")
55
+ return false;
56
+ return condition;
57
+ }
58
+ return condition;
59
+ }
60
+ resolveTemplate(path, context) {
61
+ const trimmed = path.trim();
62
+ if (trimmed.startsWith("input.")) {
63
+ const key = trimmed.slice(6);
64
+ return context.input?.[key];
65
+ }
66
+ if (trimmed.startsWith("nodes.")) {
67
+ const rest = trimmed.slice(6);
68
+ const segments2 = rest.split(".");
69
+ const nodeId2 = segments2[0];
70
+ let nodeOutput2 = context.previousOutputs.get(nodeId2);
71
+ if (nodeOutput2 === undefined) {
72
+ const normalizedUnderscore = nodeId2.replace(/-/g, "_");
73
+ const normalizedHyphen = nodeId2.replace(/_/g, "-");
74
+ if (normalizedUnderscore !== nodeId2) {
75
+ nodeOutput2 = context.previousOutputs.get(normalizedUnderscore);
76
+ }
77
+ if (nodeOutput2 === undefined && normalizedHyphen !== nodeId2) {
78
+ nodeOutput2 = context.previousOutputs.get(normalizedHyphen);
79
+ }
80
+ }
81
+ if (nodeOutput2 === undefined)
82
+ return;
83
+ let value2 = nodeOutput2;
84
+ for (const segment of segments2.slice(1)) {
85
+ if (value2 && typeof value2 === "object") {
86
+ value2 = value2[segment];
87
+ } else {
88
+ return;
89
+ }
90
+ }
91
+ return value2;
92
+ }
93
+ const segments = trimmed.split(".");
94
+ const nodeId = segments[0];
95
+ let nodeOutput = context.previousOutputs.get(nodeId);
96
+ if (nodeOutput === undefined) {
97
+ const normalizedUnderscore = nodeId.replace(/-/g, "_");
98
+ const normalizedHyphen = nodeId.replace(/_/g, "-");
99
+ if (normalizedUnderscore !== nodeId) {
100
+ nodeOutput = context.previousOutputs.get(normalizedUnderscore);
101
+ }
102
+ if (nodeOutput === undefined && normalizedHyphen !== nodeId) {
103
+ nodeOutput = context.previousOutputs.get(normalizedHyphen);
104
+ }
105
+ }
106
+ if (nodeOutput === undefined)
107
+ return;
108
+ let value = nodeOutput;
109
+ for (const segment of segments.slice(1)) {
110
+ if (value && typeof value === "object") {
111
+ value = value[segment];
112
+ } else {
113
+ return;
114
+ }
115
+ }
116
+ return value;
117
+ }
118
+ evaluateCondition(value) {
119
+ if (typeof value === "boolean") {
120
+ return value;
121
+ }
122
+ if (typeof value === "string") {
123
+ return value.toLowerCase() === "true" || value === "1";
124
+ }
125
+ if (typeof value === "number") {
126
+ return value !== 0;
127
+ }
128
+ if (value === null || value === undefined) {
129
+ return false;
130
+ }
131
+ if (typeof value === "object") {
132
+ const obj = value;
133
+ if ("success" in obj) {
134
+ return Boolean(obj.success);
135
+ }
136
+ return Object.keys(obj).length > 0;
137
+ }
138
+ return Boolean(value);
139
+ }
140
+ }
141
+ var init_condition_node = () => {};
142
+
143
+ // packages/core/src/env/workflow/nodes/merge-node.ts
144
+ class MergeNode {
145
+ definition;
146
+ type = "merge";
147
+ id;
148
+ constructor(definition) {
149
+ this.definition = definition;
150
+ this.id = definition.id;
151
+ }
152
+ async execute(context) {
153
+ const startTime = Date.now();
154
+ try {
155
+ const strategy = this.definition.config?.strategy || "collect";
156
+ const deps = this.definition.depends_on || [];
157
+ const outputs = {};
158
+ for (const depId of deps) {
159
+ let output = context.previousOutputs.get(depId);
160
+ if (output === undefined) {
161
+ const normalizedUnderscore = depId.replace(/-/g, "_");
162
+ const normalizedHyphen = depId.replace(/_/g, "-");
163
+ if (normalizedUnderscore !== depId) {
164
+ output = context.previousOutputs.get(normalizedUnderscore);
165
+ }
166
+ if (output === undefined && normalizedHyphen !== depId) {
167
+ output = context.previousOutputs.get(normalizedHyphen);
168
+ }
169
+ }
170
+ if (output !== undefined) {
171
+ outputs[depId] = output;
172
+ }
173
+ }
174
+ let result;
175
+ switch (strategy) {
176
+ case "collect":
177
+ result = outputs;
178
+ break;
179
+ case "first":
180
+ const firstKey = Object.keys(outputs)[0];
181
+ result = firstKey ? outputs[firstKey] : undefined;
182
+ break;
183
+ case "last":
184
+ const lastKey = Object.keys(outputs).pop();
185
+ result = lastKey ? outputs[lastKey] : undefined;
186
+ break;
187
+ case "merge":
188
+ result = this.deepMerge(Object.values(outputs));
189
+ break;
190
+ default:
191
+ result = outputs;
192
+ }
193
+ return {
194
+ output: {
195
+ strategy,
196
+ results: result,
197
+ count: Object.keys(outputs).length
198
+ },
199
+ error: undefined,
200
+ durationMs: Date.now() - startTime
201
+ };
202
+ } catch (error) {
203
+ return {
204
+ output: undefined,
205
+ error: error instanceof Error ? error : new Error(String(error)),
206
+ durationMs: Date.now() - startTime
207
+ };
208
+ }
209
+ }
210
+ deepMerge(objects) {
211
+ const result = {};
212
+ for (const obj of objects) {
213
+ if (obj && typeof obj === "object" && !Array.isArray(obj)) {
214
+ for (const [key, value] of Object.entries(obj)) {
215
+ if (result[key] && typeof result[key] === "object" && !Array.isArray(result[key]) && value && typeof value === "object" && !Array.isArray(value)) {
216
+ result[key] = this.deepMerge([result[key], value]);
217
+ } else {
218
+ result[key] = value;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ return result;
224
+ }
225
+ }
226
+ var init_merge_node = () => {};
227
+
228
+ // packages/core/src/env/workflow/utils/node-registry-helper.ts
229
+ var exports_node_registry_helper = {};
230
+ __export(exports_node_registry_helper, {
231
+ registerDecoratorNodeType: () => registerDecoratorNodeType,
232
+ hasDecoratorNodes: () => hasDecoratorNodes,
233
+ getDecoratorNodes: () => getDecoratorNodes
234
+ });
235
+ function registerDecoratorNodeType(registry) {
236
+ registry.register("decorator", (definition) => {
237
+ return new DecoratorNode(definition);
238
+ });
239
+ registry.register("condition", (definition) => {
240
+ return new ConditionNode(definition);
241
+ });
242
+ registry.register("merge", (definition) => {
243
+ return new MergeNode(definition);
244
+ });
245
+ }
246
+ function hasDecoratorNodes(nodes) {
247
+ return nodes.some((node) => node.type === "decorator");
248
+ }
249
+ function getDecoratorNodes(nodes) {
250
+ return nodes.filter((node) => node.type === "decorator");
251
+ }
252
+ var init_node_registry_helper = __esm(() => {
253
+ init_decorator_node();
254
+ init_condition_node();
255
+ init_merge_node();
256
+ });
257
+
258
+ export { registerDecoratorNodeType, hasDecoratorNodes, getDecoratorNodes, exports_node_registry_helper, init_node_registry_helper };