@ai-setting/roy-agent-core 1.7.55 → 1.7.57

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 (117) hide show
  1. package/dist/config/index.js +8 -8
  2. package/dist/env/agent/agent-component.d.ts +41 -0
  3. package/dist/env/agent/index.js +15 -14
  4. package/dist/env/commands/index.js +8 -8
  5. package/dist/env/context/index.js +4 -4
  6. package/dist/env/debug/index.js +8 -8
  7. package/dist/env/environment.d.ts +7 -0
  8. package/dist/env/event-source/event-source-handlers.d.ts +28 -0
  9. package/dist/env/event-source/index.js +18 -17
  10. package/dist/env/hook/index.js +6 -6
  11. package/dist/env/index.js +45 -43
  12. package/dist/env/llm/adapter-ai-sdk.d.ts +6 -0
  13. package/dist/env/llm/adapter-pi-ai.d.ts +5 -0
  14. package/dist/env/llm/index.js +11 -11
  15. package/dist/env/llm/invoke.d.ts +33 -1
  16. package/dist/env/llm/llm.d.ts +13 -0
  17. package/dist/env/llm/outbound-defense.d.ts +140 -0
  18. package/dist/env/log-trace/decorator.d.ts +46 -3
  19. package/dist/env/log-trace/index.d.ts +1 -0
  20. package/dist/env/log-trace/index.js +34 -8
  21. package/dist/env/log-trace/opentelemetry/tracer-provider.d.ts +86 -1
  22. package/dist/env/log-trace/trace-filters.d.ts +127 -0
  23. package/dist/env/mcp/index.js +9 -9
  24. package/dist/env/mcp/tool/index.js +2 -2
  25. package/dist/env/memory/index.js +9 -9
  26. package/dist/env/memory/plugin/index.js +2 -2
  27. package/dist/env/plugin/index.js +8 -8
  28. package/dist/env/prompt/index.js +8 -8
  29. package/dist/env/session/index.js +12 -11
  30. package/dist/env/session/session-component.d.ts +4 -0
  31. package/dist/env/session/storage/index.js +6 -4
  32. package/dist/env/skill/index.js +8 -8
  33. package/dist/env/task/delegate/index.js +9 -9
  34. package/dist/env/task/index.js +18 -17
  35. package/dist/env/task/plugins/index.js +11 -10
  36. package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +109 -2
  37. package/dist/env/task/plugins/lark-card-state-store.d.ts +137 -0
  38. package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +154 -2
  39. package/dist/env/task/storage/index.js +4 -3
  40. package/dist/env/task/tools/index.js +4 -4
  41. package/dist/env/tool/built-in/index.js +5 -5
  42. package/dist/env/tool/index.js +12 -12
  43. package/dist/env/workflow/engine/index.js +13 -13
  44. package/dist/env/workflow/hooks/index.js +8 -8
  45. package/dist/env/workflow/index.js +24 -23
  46. package/dist/env/workflow/nodes/index.js +3 -3
  47. package/dist/env/workflow/plugins/index.js +9 -9
  48. package/dist/env/workflow/service/index.js +3 -3
  49. package/dist/env/workflow/storage/index.js +4 -4
  50. package/dist/env/workflow/tools/index.js +16 -15
  51. package/dist/env/workflow/utils/index.js +6 -6
  52. package/dist/index.d.ts +1 -1
  53. package/dist/index.js +90 -63
  54. package/dist/shared/@ai-setting/{roy-agent-core-k25gv86p.js → roy-agent-core-029r8kdw.js} +4 -4
  55. package/dist/shared/@ai-setting/{roy-agent-core-8s9jd2qy.js → roy-agent-core-08njdcpj.js} +1 -1
  56. package/dist/shared/@ai-setting/{roy-agent-core-tdbv7ff4.js → roy-agent-core-0kn3zt1t.js} +2 -2
  57. package/dist/shared/@ai-setting/{roy-agent-core-8eqngasy.js → roy-agent-core-0yn7a78e.js} +14 -14
  58. package/dist/shared/@ai-setting/{roy-agent-core-tbrn9wdm.js → roy-agent-core-14bq77wr.js} +1 -1
  59. package/dist/shared/@ai-setting/{roy-agent-core-mxdc756a.js → roy-agent-core-1sfbs57v.js} +9 -9
  60. package/dist/shared/@ai-setting/{roy-agent-core-qamktze3.js → roy-agent-core-20m8je6e.js} +1 -1
  61. package/dist/shared/@ai-setting/{roy-agent-core-yhsssn86.js → roy-agent-core-2ctyjy62.js} +1 -1
  62. package/dist/shared/@ai-setting/{roy-agent-core-9jzysq50.js → roy-agent-core-2fk8c9ax.js} +3 -3
  63. package/dist/shared/@ai-setting/{roy-agent-core-2k4xffaa.js → roy-agent-core-4096f575.js} +4 -4
  64. package/dist/shared/@ai-setting/{roy-agent-core-2gay3sjt.js → roy-agent-core-47s81t6g.js} +2 -2
  65. package/dist/shared/@ai-setting/{roy-agent-core-w527pcpe.js → roy-agent-core-5f7myqnb.js} +45 -494
  66. package/dist/shared/@ai-setting/{roy-agent-core-zjttt2y4.js → roy-agent-core-7nb23tdd.js} +1 -1
  67. package/dist/shared/@ai-setting/roy-agent-core-7q4wdze2.js +7 -0
  68. package/dist/shared/@ai-setting/{roy-agent-core-cd62e9p1.js → roy-agent-core-84rs0c8d.js} +23 -10
  69. package/dist/shared/@ai-setting/{roy-agent-core-dwx9hjwx.js → roy-agent-core-84xtww7d.js} +3 -3
  70. package/dist/shared/@ai-setting/{roy-agent-core-a4vzsn0g.js → roy-agent-core-89sxsrc7.js} +1 -1
  71. package/dist/shared/@ai-setting/{roy-agent-core-g36jevrk.js → roy-agent-core-8bngppw0.js} +580 -83
  72. package/dist/shared/@ai-setting/roy-agent-core-8p63s836.js +578 -0
  73. package/dist/shared/@ai-setting/{roy-agent-core-7evvpfwc.js → roy-agent-core-9zhkdg6w.js} +2 -2
  74. package/dist/shared/@ai-setting/{roy-agent-core-ak4dc3kg.js → roy-agent-core-baaa4wtp.js} +2 -2
  75. package/dist/shared/@ai-setting/{roy-agent-core-b5ew8t0k.js → roy-agent-core-c36335nw.js} +146 -8
  76. package/dist/shared/@ai-setting/{roy-agent-core-7qy3nffr.js → roy-agent-core-c7w2h47a.js} +3 -3
  77. package/dist/shared/@ai-setting/{roy-agent-core-j5c3chtn.js → roy-agent-core-cyefe8z5.js} +1 -1
  78. package/dist/shared/@ai-setting/{roy-agent-core-2bscfrr1.js → roy-agent-core-d75t8gea.js} +1 -1
  79. package/dist/shared/@ai-setting/{roy-agent-core-0hq21px2.js → roy-agent-core-e1w17tht.js} +632 -36
  80. package/dist/shared/@ai-setting/{roy-agent-core-ne2t1pay.js → roy-agent-core-e250355z.js} +3 -3
  81. package/dist/shared/@ai-setting/{roy-agent-core-ytr2w0vb.js → roy-agent-core-eanq305k.js} +69 -25
  82. package/dist/shared/@ai-setting/{roy-agent-core-12d2xap8.js → roy-agent-core-em4hks9t.js} +4 -4
  83. package/dist/shared/@ai-setting/{roy-agent-core-6qxh4xrm.js → roy-agent-core-en2xqxs9.js} +7 -7
  84. package/dist/shared/@ai-setting/{roy-agent-core-e2z1etk4.js → roy-agent-core-ewcc5qdt.js} +11 -11
  85. package/dist/shared/@ai-setting/{roy-agent-core-qm9jda8p.js → roy-agent-core-fbjd7bt6.js} +3 -7
  86. package/dist/shared/@ai-setting/{roy-agent-core-fvs48d38.js → roy-agent-core-fw6k4w1h.js} +14 -9
  87. package/dist/shared/@ai-setting/{roy-agent-core-2b8jtv7m.js → roy-agent-core-ge87xbas.js} +1 -1
  88. package/dist/shared/@ai-setting/{roy-agent-core-9csa89jx.js → roy-agent-core-geh6j7bw.js} +2 -2
  89. package/dist/shared/@ai-setting/{roy-agent-core-dv714bqh.js → roy-agent-core-gksw1gjb.js} +1 -1
  90. package/dist/shared/@ai-setting/{roy-agent-core-fs36xgcs.js → roy-agent-core-hefarcp0.js} +1 -1
  91. package/dist/shared/@ai-setting/{roy-agent-core-t37wbysj.js → roy-agent-core-hs41gx9w.js} +5 -5
  92. package/dist/shared/@ai-setting/{roy-agent-core-1cv9j4dg.js → roy-agent-core-jjhw9am6.js} +4 -4
  93. package/dist/shared/@ai-setting/{roy-agent-core-978b6wfx.js → roy-agent-core-jjxdmedn.js} +2 -2
  94. package/dist/shared/@ai-setting/{roy-agent-core-j2nvedt6.js → roy-agent-core-jw5ar4p0.js} +33 -38
  95. package/dist/shared/@ai-setting/{roy-agent-core-zvemdfx5.js → roy-agent-core-kq9pz2a7.js} +13 -6
  96. package/dist/shared/@ai-setting/{roy-agent-core-8t7wny6v.js → roy-agent-core-m68z3pw1.js} +1 -1
  97. package/dist/shared/@ai-setting/{roy-agent-core-k8b440n3.js → roy-agent-core-m97jn2ra.js} +1 -1
  98. package/dist/shared/@ai-setting/{roy-agent-core-kzg1jwt8.js → roy-agent-core-n0p0hwgd.js} +1 -1
  99. package/dist/shared/@ai-setting/{roy-agent-core-9h72sk1n.js → roy-agent-core-psg6f1v6.js} +6 -6
  100. package/dist/shared/@ai-setting/{roy-agent-core-athdr2m0.js → roy-agent-core-q4gdfypk.js} +12 -4
  101. package/dist/shared/@ai-setting/{roy-agent-core-nde5gzta.js → roy-agent-core-rcgvmtms.js} +1 -1
  102. package/dist/shared/@ai-setting/{roy-agent-core-8seq65bp.js → roy-agent-core-rt115qfc.js} +44 -1
  103. package/dist/shared/@ai-setting/{roy-agent-core-5apmk4qw.js → roy-agent-core-syyw58p9.js} +2 -2
  104. package/dist/shared/@ai-setting/{roy-agent-core-tjg71zqp.js → roy-agent-core-t4x089js.js} +1 -1
  105. package/dist/shared/@ai-setting/{roy-agent-core-zd3ddm4k.js → roy-agent-core-t64nmayv.js} +2 -2
  106. package/dist/shared/@ai-setting/{roy-agent-core-6167phd4.js → roy-agent-core-txwptxk1.js} +4 -4
  107. package/dist/shared/@ai-setting/{roy-agent-core-rnwr39b0.js → roy-agent-core-tze5596n.js} +6 -4
  108. package/dist/shared/@ai-setting/{roy-agent-core-skzjs973.js → roy-agent-core-vath15kt.js} +6 -6
  109. package/dist/shared/@ai-setting/{roy-agent-core-vrsxhw9e.js → roy-agent-core-vgdhxbx3.js} +2 -2
  110. package/dist/shared/@ai-setting/{roy-agent-core-7g03zkkb.js → roy-agent-core-vh0qzb24.js} +2 -2
  111. package/dist/shared/@ai-setting/{roy-agent-core-aer5kw1j.js → roy-agent-core-w93z6a42.js} +17 -17
  112. package/dist/shared/@ai-setting/{roy-agent-core-rx16h2m1.js → roy-agent-core-ygn5tzt1.js} +3 -3
  113. package/dist/shared/@ai-setting/{roy-agent-core-4z3rq5gw.js → roy-agent-core-yphwdm9x.js} +2 -2
  114. package/dist/shared/@ai-setting/{roy-agent-core-qcspfszy.js → roy-agent-core-ytd5eztz.js} +1 -1
  115. package/dist/utils/temp-file-manager/index.js +2 -2
  116. package/package.json +1 -1
  117. package/dist/shared/@ai-setting/roy-agent-core-dsevjbck.js +0 -245
@@ -0,0 +1,578 @@
1
+ import {
2
+ createLogger,
3
+ getMaxOutput,
4
+ getTracerProvider,
5
+ init_logger,
6
+ init_tracer_provider,
7
+ simplifyFilePath
8
+ } from "./roy-agent-core-rt115qfc.js";
9
+ import {
10
+ __esm
11
+ } from "./roy-agent-core-fs0mn2jk.js";
12
+
13
+ // src/env/log-trace/trace-filters.ts
14
+ function resetTraceFullModeCache() {
15
+ traceFullModeCache = undefined;
16
+ }
17
+ function isTraceFullMode() {
18
+ if (traceFullModeCache !== undefined)
19
+ return traceFullModeCache;
20
+ const raw = process.env.ROY_TRACE_FULL?.trim().toLowerCase();
21
+ traceFullModeCache = raw === "1" || raw === "true" || raw === "yes";
22
+ return traceFullModeCache;
23
+ }
24
+ function safeLen(value) {
25
+ if (typeof value === "string")
26
+ return value.length;
27
+ if (value === null || value === undefined)
28
+ return 0;
29
+ if (Array.isArray(value))
30
+ return value.length;
31
+ return 0;
32
+ }
33
+ function totalMessageChars(messages) {
34
+ let n = 0;
35
+ for (const m of messages) {
36
+ if (!m)
37
+ continue;
38
+ const c = m.content;
39
+ if (typeof c === "string") {
40
+ n += c.length;
41
+ } else if (Array.isArray(c)) {
42
+ for (const part of c) {
43
+ if (typeof part === "string")
44
+ n += part.length;
45
+ else if (part && typeof part.text === "string")
46
+ n += part.text.length;
47
+ }
48
+ }
49
+ }
50
+ return n;
51
+ }
52
+ function safeJsonLen(value) {
53
+ if (value === null || value === undefined)
54
+ return 0;
55
+ if (typeof value === "string")
56
+ return value.length;
57
+ try {
58
+ return JSON.stringify(value)?.length ?? 0;
59
+ } catch {
60
+ return 0;
61
+ }
62
+ }
63
+ function llmInvokeParamFilter(args) {
64
+ if (isTraceFullMode()) {
65
+ return { args };
66
+ }
67
+ const p = (args ?? [])[0];
68
+ const ctx = p?.context ?? p?.ctx ?? null;
69
+ const msgs = Array.isArray(p?.messages) ? p.messages : [];
70
+ return {
71
+ model: p?.model ?? p?.modelId ?? ctx?.model ?? null,
72
+ provider: p?.provider ?? p?.providerId ?? null,
73
+ sessionId: ctx?.sessionId ?? p?.sessionId ?? null,
74
+ messageCount: msgs.length,
75
+ totalChars: totalMessageChars(msgs),
76
+ tools: Array.isArray(p?.tools) ? p.tools.length : 0,
77
+ maxTokens: p?.maxTokens ?? null,
78
+ temperature: p?.temperature ?? null
79
+ };
80
+ }
81
+ function llmInvokeResultFilter(r) {
82
+ if (isTraceFullMode()) {
83
+ return { result: r };
84
+ }
85
+ const output = r?.output ?? r;
86
+ const text = typeof output?.content === "string" ? output.content : "";
87
+ const toolCalls = Array.isArray(output?.toolCalls) ? output.toolCalls : [];
88
+ return {
89
+ finishReason: output?.finishReason ?? r?.finishReason ?? null,
90
+ outputChars: text.length || safeLen(output?.content),
91
+ reasoningChars: typeof output?.reasoning === "string" ? output.reasoning.length : 0,
92
+ toolCallCount: toolCalls.length,
93
+ usage: output?.usage ?? r?.usage ?? null,
94
+ providerId: r?.providerId ?? null,
95
+ model: r?.model ?? output?.model ?? null,
96
+ latencyMs: r?.latencyMs ?? null
97
+ };
98
+ }
99
+ function messagesParamFilter(args) {
100
+ if (isTraceFullMode()) {
101
+ return { args };
102
+ }
103
+ const a0 = (args ?? [])[0];
104
+ const msgs = Array.isArray(a0) ? a0 : Array.isArray(a0?.messages) ? a0.messages : [];
105
+ return {
106
+ messageCount: msgs.length,
107
+ totalChars: totalMessageChars(msgs),
108
+ roles: msgs.length ? String(msgs[0]?.role ?? "") : null
109
+ };
110
+ }
111
+ function toolExecParamFilter(args) {
112
+ if (isTraceFullMode()) {
113
+ return { args };
114
+ }
115
+ const ctx = (args ?? [])[0];
116
+ const toolCall = ctx?.currentToolCall ?? ctx?.toolCall ?? ctx;
117
+ const toolName = toolCall?.toolName ?? toolCall?.name ?? toolCall?.tool ?? null;
118
+ const rawArgs = readToolArgs(toolCall);
119
+ let argKeys = [];
120
+ if (rawArgs && typeof rawArgs === "object" && !Array.isArray(rawArgs)) {
121
+ argKeys = Object.keys(rawArgs);
122
+ }
123
+ return {
124
+ tool: toolName,
125
+ toolCallId: toolCall?.toolCallId ?? toolCall?.id ?? null,
126
+ argKeys,
127
+ argCount: argKeys.length
128
+ };
129
+ }
130
+ function readToolArgs(toolCall) {
131
+ if (!toolCall || typeof toolCall !== "object")
132
+ return;
133
+ for (const key of ["args", "arguments", "input", "parameters"]) {
134
+ try {
135
+ const v = toolCall[key];
136
+ if (v !== undefined && v !== null)
137
+ return v;
138
+ } catch {}
139
+ }
140
+ return;
141
+ }
142
+ function embedParamFilter(args) {
143
+ if (isTraceFullMode()) {
144
+ return { args };
145
+ }
146
+ const req = (args ?? [])[0];
147
+ const input = req?.input ?? req?.texts ?? req?.value;
148
+ const arr = Array.isArray(input) ? input : input === undefined ? [] : [input];
149
+ let chars = 0;
150
+ for (const s of arr)
151
+ if (typeof s === "string")
152
+ chars += s.length;
153
+ return {
154
+ provider: req?.provider ?? null,
155
+ modelId: req?.modelId ?? req?.model ?? null,
156
+ inputCount: arr.length,
157
+ totalChars: chars
158
+ };
159
+ }
160
+ function embedResultFilter(r) {
161
+ if (isTraceFullMode()) {
162
+ return { result: r };
163
+ }
164
+ const embs = Array.isArray(r?.embeddings) ? r.embeddings : [];
165
+ const dims = embs.length && Array.isArray(embs[0]) ? embs[0].length : 0;
166
+ return {
167
+ embeddingCount: embs.length,
168
+ dimensions: dims,
169
+ usage: r?.usage ?? null
170
+ };
171
+ }
172
+ function toolExecResultFilter(r) {
173
+ if (isTraceFullMode()) {
174
+ return { result: r };
175
+ }
176
+ const inner = r && typeof r === "object" && r.result && typeof r.result === "object" ? r.result : r;
177
+ const output = inner?.output ?? inner?.content ?? inner?.text;
178
+ const text = typeof output === "string" ? output : "";
179
+ const outputJsonChars = output && typeof output === "object" ? safeJsonLen(output) : 0;
180
+ const metadata = inner?.metadata ?? r?.metadata;
181
+ const stdout = typeof metadata?.stdout === "string" ? metadata.stdout : "";
182
+ const stderr = typeof metadata?.stderr === "string" ? metadata.stderr : "";
183
+ const error = inner?.error ?? r?.error;
184
+ return {
185
+ success: r?.success ?? inner?.success ?? null,
186
+ tool: r?.name ?? r?.toolName ?? null,
187
+ outputChars: text.length || outputJsonChars,
188
+ outputHead: text.slice(0, 500),
189
+ stdoutChars: stdout.length,
190
+ stderrChars: stderr.length,
191
+ exitCode: metadata?.exit_code ?? null,
192
+ timedOut: metadata?.timed_out ?? null,
193
+ executionTimeMs: metadata?.execution_time_ms ?? null,
194
+ error: error ? String(error).slice(0, 500) : null
195
+ };
196
+ }
197
+ function toolInvokeParamFilter(args) {
198
+ if (isTraceFullMode()) {
199
+ return { args };
200
+ }
201
+ const a0 = (args ?? [])[0];
202
+ const command = typeof a0?.command === "string" ? a0.command : null;
203
+ const toolName = a0?.name ?? a0?.toolName ?? null;
204
+ const rawArgs = a0?.args;
205
+ let argKeys = [];
206
+ if (rawArgs && typeof rawArgs === "object" && !Array.isArray(rawArgs)) {
207
+ argKeys = Object.keys(rawArgs);
208
+ }
209
+ return {
210
+ tool: toolName,
211
+ command: command === null ? null : command.slice(0, MAX_COMMAND_CHARS),
212
+ commandChars: command === null ? null : command.length,
213
+ commandTruncated: command !== null && command.length > MAX_COMMAND_CHARS,
214
+ argKeys,
215
+ argCount: argKeys.length,
216
+ timeout: a0?.timeout ?? null
217
+ };
218
+ }
219
+ function envQueryParamFilter(args) {
220
+ if (isTraceFullMode()) {
221
+ return { args };
222
+ }
223
+ const a = args ?? [];
224
+ const isWorkflowEntry = a.length >= 3 && typeof a[0] === "string";
225
+ const agentName = isWorkflowEntry ? a[0] : null;
226
+ const query = isWorkflowEntry ? a[1] : a[0];
227
+ const context = isWorkflowEntry ? a[3] : a[1];
228
+ const isArray = Array.isArray(query);
229
+ const parts = isArray ? query : [];
230
+ let chars = 0;
231
+ if (typeof query === "string") {
232
+ chars = query.length;
233
+ } else {
234
+ for (const p of parts) {
235
+ if (typeof p === "string")
236
+ chars += p.length;
237
+ else if (typeof p?.text === "string")
238
+ chars += p.text.length;
239
+ }
240
+ }
241
+ return {
242
+ agentName,
243
+ queryChars: chars,
244
+ queryParts: isArray ? parts.length : 0,
245
+ isMultimodal: isArray,
246
+ contextKeys: context && typeof context === "object" ? Object.keys(context) : []
247
+ };
248
+ }
249
+ function agentRunParamFilter(args) {
250
+ if (isTraceFullMode()) {
251
+ return { args };
252
+ }
253
+ const a = args ?? [];
254
+ const agentName = typeof a[0] === "string" ? a[0] : null;
255
+ const query = a[1];
256
+ const isArray = Array.isArray(query);
257
+ let chars = 0;
258
+ if (typeof query === "string")
259
+ chars = query.length;
260
+ else if (isArray) {
261
+ for (const p of query) {
262
+ if (typeof p === "string")
263
+ chars += p.length;
264
+ else if (typeof p?.text === "string")
265
+ chars += p.text.length;
266
+ }
267
+ }
268
+ const ctx = a[2];
269
+ return {
270
+ agentName,
271
+ queryChars: chars,
272
+ queryParts: isArray ? query.length : 0,
273
+ isMultimodal: isArray,
274
+ contextKeys: ctx && typeof ctx === "object" ? Object.keys(ctx) : []
275
+ };
276
+ }
277
+ function recordSessionMessagesParamFilter(args) {
278
+ if (isTraceFullMode()) {
279
+ return { args };
280
+ }
281
+ const a = args ?? [];
282
+ const sessionId = typeof a[0] === "string" ? a[0] : null;
283
+ const msgs = Array.isArray(a[1]) ? a[1] : [];
284
+ let chars = 0;
285
+ for (const m of msgs) {
286
+ if (typeof m?.content === "string")
287
+ chars += m.content.length;
288
+ }
289
+ return {
290
+ sessionId,
291
+ messageCount: msgs.length,
292
+ totalChars: chars
293
+ };
294
+ }
295
+ var traceFullModeCache, MAX_COMMAND_CHARS = 2000;
296
+ var init_trace_filters = () => {};
297
+
298
+ // src/env/log-trace/decorator.ts
299
+ function Traced(options) {
300
+ const buildOptions = () => ({
301
+ recordParams: options?.recordParams ?? true,
302
+ recordResult: options?.recordResult ?? false,
303
+ recordResultToDb: options?.recordResultToDb ?? false,
304
+ logResult: options?.logResult,
305
+ recordError: options?.recordError ?? true,
306
+ log: options?.log ?? false,
307
+ maxLogSize: options?.maxLogSize,
308
+ paramFilter: options?.paramFilter,
309
+ resultFilter: options?.resultFilter,
310
+ flattenParamFilter: options?.flattenParamFilter,
311
+ errorIf: options?.errorIf
312
+ });
313
+ return function(target, propertyKey, descriptor) {
314
+ if (descriptor !== undefined && descriptor !== null && typeof descriptor === "object" && "value" in descriptor) {
315
+ const originalFn = descriptor.value;
316
+ const spanName = options?.name || String(propertyKey);
317
+ descriptor.value = wrapFunction(originalFn, spanName, buildOptions());
318
+ return descriptor;
319
+ }
320
+ const value = target;
321
+ const context = propertyKey || {};
322
+ if (typeof value === "function") {
323
+ const spanName = options?.name || (context?.name ? String(context.name) : "anonymous");
324
+ return wrapFunction(value, spanName, buildOptions());
325
+ }
326
+ return value;
327
+ };
328
+ }
329
+ function TracedAs(name, options) {
330
+ return Traced({ name, ...options });
331
+ }
332
+ function TracedLightweight(options) {
333
+ return Traced({ recordParams: false, recordResult: false, log: options?.log ?? false, maxLogSize: options?.maxLogSize });
334
+ }
335
+ function wrapFunction(fn, name, options) {
336
+ const opts = {
337
+ recordParams: options?.recordParams ?? true,
338
+ recordResult: options?.recordResult ?? true,
339
+ recordResultToDb: options?.recordResultToDb ?? false,
340
+ logResult: options?.logResult,
341
+ recordError: options?.recordError ?? true,
342
+ log: options?.log ?? false,
343
+ maxLogSize: options?.maxLogSize,
344
+ paramFilter: options?.paramFilter,
345
+ resultFilter: options?.resultFilter,
346
+ flattenParamFilter: options?.flattenParamFilter ?? false,
347
+ errorIf: options?.errorIf
348
+ };
349
+ const shouldLog = opts.log;
350
+ const getMaxLogSize = () => {
351
+ if (opts.maxLogSize !== undefined) {
352
+ return opts.maxLogSize;
353
+ }
354
+ const configMaxOutput = getMaxOutput();
355
+ return configMaxOutput !== undefined ? configMaxOutput : 500;
356
+ };
357
+ const truncate = (obj) => {
358
+ if (obj === undefined)
359
+ return;
360
+ if (obj === null)
361
+ return null;
362
+ const maxLogSize = getMaxLogSize();
363
+ let str;
364
+ try {
365
+ str = typeof obj === "string" ? obj : JSON.stringify(obj, null, 0).replace(/\n/g, "");
366
+ } catch (e) {
367
+ str = `[Object with circular reference: ${e instanceof Error ? e.message : String(e)}]`;
368
+ }
369
+ if (maxLogSize > 0 && str.length > maxLogSize) {
370
+ return str.slice(0, maxLogSize) + " [TRUNCATED]";
371
+ }
372
+ try {
373
+ return JSON.parse(str);
374
+ } catch {
375
+ return str;
376
+ }
377
+ };
378
+ const truncateString = (obj) => {
379
+ if (obj === undefined)
380
+ return "undefined";
381
+ if (obj === null)
382
+ return "null";
383
+ const maxLogSize = getMaxLogSize();
384
+ let str;
385
+ try {
386
+ str = typeof obj === "string" ? obj : JSON.stringify(obj, null, 0).replace(/\n/g, "");
387
+ } catch (e) {
388
+ str = `[Object with circular reference: ${e instanceof Error ? e.message : String(e)}]`;
389
+ }
390
+ return maxLogSize > 0 && str.length > maxLogSize ? str.slice(0, maxLogSize) + " [TRUNCATED]" : str;
391
+ };
392
+ const toDbValue = (obj) => {
393
+ if (obj === undefined)
394
+ return;
395
+ if (obj === null)
396
+ return null;
397
+ if (typeof obj === "string")
398
+ return obj;
399
+ try {
400
+ return JSON.parse(JSON.stringify(obj));
401
+ } catch (e) {
402
+ return `[Object with circular reference: ${e instanceof Error ? e.message : String(e)}]`;
403
+ }
404
+ };
405
+ const TRACE_LOG_PREFIX = "[TRACE]";
406
+ const safeRunFilter = (fn2) => {
407
+ try {
408
+ return fn2();
409
+ } catch (e) {
410
+ try {
411
+ createLogger("traced:" + name).warn(`[trace] filter threw, ignoring: ${e instanceof Error ? e.message : String(e)}`);
412
+ } catch {}
413
+ return;
414
+ }
415
+ };
416
+ const resolveDbResult = (result, precomputedFiltered) => {
417
+ if (opts.recordResultToDb === true) {
418
+ return { value: result, store: true };
419
+ }
420
+ if (isTraceFullMode()) {
421
+ return { value: result, store: true };
422
+ }
423
+ if (opts.resultFilter) {
424
+ const filtered = precomputedFiltered?.ran ? precomputedFiltered.value : safeRunFilter(() => opts.resultFilter(result));
425
+ if (filtered && typeof filtered === "object" && !Array.isArray(filtered)) {
426
+ return { value: filtered, store: true };
427
+ }
428
+ }
429
+ if (opts.recordResult === false) {
430
+ return { value: undefined, store: false };
431
+ }
432
+ return { value: result, store: true };
433
+ };
434
+ const getCallerLocation = () => {
435
+ const originalLimit = Error.stackTraceLimit;
436
+ Error.stackTraceLimit = 15;
437
+ const err = new Error;
438
+ Error.captureStackTrace(err, getCallerLocation);
439
+ const stack = err.stack?.split(`
440
+ `) || [];
441
+ Error.stackTraceLimit = originalLimit;
442
+ for (let i = 1;i < stack.length; i++) {
443
+ const line = stack[i];
444
+ if (line.includes("decorator.ts") || line.includes("decorator.js") || line.includes("logFn") || line.includes("getCallerLocation"))
445
+ continue;
446
+ const match = line.match(/at\s+.+\s+\((.+):(\d+):\d+\)/) || line.match(/at\s+(.+):(\d+):\d+/);
447
+ if (match) {
448
+ const filePath = match[1];
449
+ if (!filePath || filePath === "native")
450
+ continue;
451
+ const relativePath = simplifyFilePath(filePath);
452
+ return `${relativePath}:${match[2]}`;
453
+ }
454
+ }
455
+ return "";
456
+ };
457
+ const logFn = (event, argsOrData, callerLocation) => {
458
+ if (!shouldLog)
459
+ return;
460
+ const logger = createLogger("traced:" + name);
461
+ const tag = event === "enter" ? ">>>" : event === "quit" ? "<<<" : "!!!";
462
+ const prefix = `${TRACE_LOG_PREFIX} ${tag} ${name}`;
463
+ const originalFnLocation = callerLocation || getCallerLocation();
464
+ const logMessage = (msg, data) => {
465
+ if (data !== undefined) {
466
+ logger.info(`${prefix} ${msg}: ${truncateString(data)}`, { callerLocation: originalFnLocation });
467
+ } else {
468
+ logger.info(`${prefix} ${msg}`, { callerLocation: originalFnLocation });
469
+ }
470
+ };
471
+ if (event === "enter") {
472
+ logMessage("enter", argsOrData);
473
+ } else if (event === "quit") {
474
+ logMessage("quit", opts.logResult ?? opts.recordResult ? argsOrData : undefined);
475
+ } else {
476
+ logMessage("error", argsOrData);
477
+ }
478
+ };
479
+ return function(...args) {
480
+ const tracer = getTracerProvider().getTracer("roy-tracer");
481
+ const attributes = {};
482
+ if (opts.recordParams !== false) {
483
+ if (opts.paramFilter) {
484
+ const filtered = safeRunFilter(() => opts.paramFilter(args));
485
+ attributes["params"] = toDbValue(filtered);
486
+ if (opts.flattenParamFilter && filtered && typeof filtered === "object" && !Array.isArray(filtered)) {
487
+ for (const [key, value] of Object.entries(filtered)) {
488
+ if (!(key in attributes)) {
489
+ attributes[key] = toDbValue(value);
490
+ }
491
+ }
492
+ }
493
+ } else {
494
+ attributes["params"] = toDbValue(args);
495
+ }
496
+ }
497
+ const callerLocation = getCallerLocation();
498
+ let span;
499
+ try {
500
+ span = tracer.startSpan(name, { attributes });
501
+ } catch {}
502
+ logFn("enter", args, callerLocation);
503
+ try {
504
+ const result = fn.call(this, ...args);
505
+ if (result && typeof result === "object" && typeof result.then === "function") {
506
+ return result.then((resolved) => {
507
+ if (span) {
508
+ const filterRan = opts.resultFilter !== undefined;
509
+ const filteredResult = opts.resultFilter ? safeRunFilter(() => opts.resultFilter(resolved)) : undefined;
510
+ if (filteredResult && typeof filteredResult === "object" && !Array.isArray(filteredResult)) {
511
+ for (const [key, value] of Object.entries(filteredResult)) {
512
+ span.setAttribute(key, toDbValue(value));
513
+ }
514
+ }
515
+ const dbResult = resolveDbResult(resolved, { ran: filterRan, value: filteredResult });
516
+ if (dbResult.store) {
517
+ span.setAttribute("result", JSON.stringify(toDbValue(dbResult.value)));
518
+ }
519
+ const resultError = opts.errorIf ? safeRunFilter(() => opts.errorIf(resolved)) : undefined;
520
+ if (resultError) {
521
+ const err = resultError instanceof Error ? resultError : new Error(String(resultError));
522
+ span.setAttribute("error", err.message);
523
+ span.end(undefined, err);
524
+ } else {
525
+ span.end(dbResult.store ? dbResult.value : undefined);
526
+ }
527
+ }
528
+ logFn("quit", opts.logResult ?? opts.recordResult ? resolved : undefined, callerLocation);
529
+ return resolved;
530
+ }, (rejected) => {
531
+ if (span) {
532
+ span.setAttribute("error", String(rejected));
533
+ span.end(undefined, rejected instanceof Error ? rejected : new Error(String(rejected)));
534
+ }
535
+ logFn("error", rejected.message, callerLocation);
536
+ throw rejected;
537
+ });
538
+ }
539
+ if (span) {
540
+ const syncFilterRan = opts.resultFilter !== undefined;
541
+ const syncFilteredResult = opts.resultFilter ? safeRunFilter(() => opts.resultFilter(result)) : undefined;
542
+ if (syncFilteredResult && typeof syncFilteredResult === "object" && !Array.isArray(syncFilteredResult)) {
543
+ for (const [key, value] of Object.entries(syncFilteredResult)) {
544
+ span.setAttribute(key, toDbValue(value));
545
+ }
546
+ }
547
+ const syncDbResult = resolveDbResult(result, { ran: syncFilterRan, value: syncFilteredResult });
548
+ if (syncDbResult.store) {
549
+ span.setAttribute("result", JSON.stringify(toDbValue(syncDbResult.value)));
550
+ }
551
+ const syncResultError = opts.errorIf ? safeRunFilter(() => opts.errorIf(result)) : undefined;
552
+ if (syncResultError) {
553
+ const err = syncResultError instanceof Error ? syncResultError : new Error(String(syncResultError));
554
+ span.setAttribute("error", err.message);
555
+ span.end(undefined, err);
556
+ } else {
557
+ span.end(syncDbResult.store ? syncDbResult.value : undefined);
558
+ }
559
+ }
560
+ logFn("quit", opts.logResult ?? opts.recordResult ? result : undefined, callerLocation);
561
+ return result;
562
+ } catch (error) {
563
+ if (span) {
564
+ span.setAttribute("error", String(error));
565
+ span.end(undefined, error instanceof Error ? error : new Error(String(error)));
566
+ }
567
+ logFn("error", error.message, callerLocation);
568
+ throw error;
569
+ }
570
+ };
571
+ }
572
+ var init_decorator = __esm(() => {
573
+ init_tracer_provider();
574
+ init_logger();
575
+ init_trace_filters();
576
+ });
577
+
578
+ export { resetTraceFullModeCache, isTraceFullMode, llmInvokeParamFilter, llmInvokeResultFilter, messagesParamFilter, toolExecParamFilter, embedParamFilter, embedResultFilter, toolExecResultFilter, toolInvokeParamFilter, envQueryParamFilter, agentRunParamFilter, recordSessionMessagesParamFilter, init_trace_filters, Traced, TracedAs, TracedLightweight, wrapFunction, init_decorator };
@@ -4,11 +4,11 @@ import {
4
4
  import {
5
5
  TracedAs,
6
6
  init_decorator
7
- } from "./roy-agent-core-dsevjbck.js";
7
+ } from "./roy-agent-core-8p63s836.js";
8
8
  import {
9
9
  createLogger,
10
10
  init_logger
11
- } from "./roy-agent-core-8seq65bp.js";
11
+ } from "./roy-agent-core-rt115qfc.js";
12
12
  import {
13
13
  __legacyDecorateClassTS
14
14
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -6,11 +6,11 @@ import {
6
6
  } from "./roy-agent-core-7hh0brvs.js";
7
7
  import {
8
8
  BaseComponent
9
- } from "./roy-agent-core-tdbv7ff4.js";
9
+ } from "./roy-agent-core-0kn3zt1t.js";
10
10
  import {
11
11
  createLogger,
12
12
  init_logger
13
- } from "./roy-agent-core-8seq65bp.js";
13
+ } from "./roy-agent-core-rt115qfc.js";
14
14
 
15
15
  // src/env/memory/types.ts
16
16
  import { z } from "zod";