@ai-setting/roy-agent-core 1.7.53 → 1.7.56

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 (124) hide show
  1. package/dist/config/index.js +7 -7
  2. package/dist/env/agent/agent-component.d.ts +30 -0
  3. package/dist/env/agent/index.js +13 -12
  4. package/dist/env/commands/index.js +7 -7
  5. package/dist/env/context/index.js +3 -3
  6. package/dist/env/debug/index.js +7 -7
  7. package/dist/env/environment.d.ts +7 -0
  8. package/dist/env/error-reply.d.ts +184 -0
  9. package/dist/env/event-source/event-source-handlers.d.ts +9 -23
  10. package/dist/env/event-source/index.js +17 -17
  11. package/dist/env/hook/index.js +5 -5
  12. package/dist/env/index.js +41 -40
  13. package/dist/env/llm/adapter-ai-sdk.d.ts +6 -0
  14. package/dist/env/llm/adapter-pi-ai.d.ts +152 -2
  15. package/dist/env/llm/adapter.d.ts +21 -1
  16. package/dist/env/llm/index.js +10 -10
  17. package/dist/env/llm/invoke.d.ts +74 -2
  18. package/dist/env/llm/llm.d.ts +38 -0
  19. package/dist/env/llm/outbound-defense.d.ts +140 -0
  20. package/dist/env/llm/reasoning-defense.d.ts +104 -0
  21. package/dist/env/llm/types.d.ts +26 -0
  22. package/dist/env/log-trace/decorator.d.ts +46 -3
  23. package/dist/env/log-trace/index.d.ts +1 -0
  24. package/dist/env/log-trace/index.js +33 -7
  25. package/dist/env/log-trace/trace-filters.d.ts +127 -0
  26. package/dist/env/mcp/index.js +7 -7
  27. package/dist/env/memory/index.js +7 -7
  28. package/dist/env/plugin/index.js +7 -7
  29. package/dist/env/prompt/index.js +8 -8
  30. package/dist/env/prompt/prompts-index.d.ts +1 -1
  31. package/dist/env/session/index.js +11 -10
  32. package/dist/env/session/session-component.d.ts +4 -0
  33. package/dist/env/session/storage/index.js +5 -3
  34. package/dist/env/skill/index.js +7 -7
  35. package/dist/env/task/backend/index.js +0 -2
  36. package/dist/env/task/backend/types.d.ts +0 -11
  37. package/dist/env/task/delegate/index.js +8 -8
  38. package/dist/env/task/index.js +13 -13
  39. package/dist/env/task/plugins/card-chat-routing.d.ts +42 -89
  40. package/dist/env/task/plugins/index.js +10 -10
  41. package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +0 -51
  42. package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +14 -31
  43. package/dist/env/task/plugins/per-task-group-chat-plugin.d.ts +4 -4
  44. package/dist/env/task/storage/index.js +2 -2
  45. package/dist/env/task/tools/index.js +3 -3
  46. package/dist/env/tool/built-in/index.js +3 -3
  47. package/dist/env/tool/index.js +9 -9
  48. package/dist/env/workflow/engine/engine.d.ts +65 -0
  49. package/dist/env/workflow/engine/index.js +12 -12
  50. package/dist/env/workflow/hooks/index.js +7 -7
  51. package/dist/env/workflow/index.js +23 -22
  52. package/dist/env/workflow/nodes/index.js +2 -2
  53. package/dist/env/workflow/nodes/tool-node.d.ts +6 -0
  54. package/dist/env/workflow/plugins/index.js +8 -8
  55. package/dist/env/workflow/service/index.js +2 -2
  56. package/dist/env/workflow/storage/index.js +3 -3
  57. package/dist/env/workflow/tools/index.js +15 -14
  58. package/dist/env/workflow/tools/workflow-validate-tool.d.ts +11 -2
  59. package/dist/env/workflow/types/run.d.ts +19 -0
  60. package/dist/env/workflow/utils/agent-session-metadata.d.ts +13 -0
  61. package/dist/env/workflow/utils/index.js +5 -5
  62. package/dist/env/workflow/utils/redact-command-secrets.d.ts +70 -0
  63. package/dist/env/workflow/utils/shell-dialect-lint.d.ts +75 -0
  64. package/dist/env/workflow/utils/validate-workflow-definition.d.ts +22 -0
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +82 -56
  67. package/dist/shared/@ai-setting/{roy-agent-core-k25gv86p.js → roy-agent-core-0b3fdnn3.js} +1 -1
  68. package/dist/shared/@ai-setting/{roy-agent-core-vvxb9522.js → roy-agent-core-0bmk44ye.js} +71 -10
  69. package/dist/shared/@ai-setting/{roy-agent-core-k8b440n3.js → roy-agent-core-16t0zfbk.js} +1 -1
  70. package/dist/shared/@ai-setting/{roy-agent-core-4z3rq5gw.js → roy-agent-core-1pnfkspm.js} +2 -2
  71. package/dist/shared/@ai-setting/{roy-agent-core-na73mym1.js → roy-agent-core-202v00x4.js} +213 -2
  72. package/dist/shared/@ai-setting/{roy-agent-core-ph5qbqcx.js → roy-agent-core-2044fbsd.js} +471 -134
  73. package/dist/shared/@ai-setting/{roy-agent-core-fs36xgcs.js → roy-agent-core-3dkzqqsd.js} +1 -1
  74. package/dist/shared/@ai-setting/{roy-agent-core-qm9jda8p.js → roy-agent-core-3kz6934b.js} +1 -1
  75. package/dist/shared/@ai-setting/{roy-agent-core-tjg71zqp.js → roy-agent-core-3mc6vmvj.js} +1 -1
  76. package/dist/shared/@ai-setting/{roy-agent-core-tdbv7ff4.js → roy-agent-core-40xzbjtm.js} +2 -2
  77. package/dist/shared/@ai-setting/{roy-agent-core-athdr2m0.js → roy-agent-core-4zy2v3br.js} +10 -2
  78. package/dist/shared/@ai-setting/{roy-agent-core-t37wbysj.js → roy-agent-core-5gw6w424.js} +4 -4
  79. package/dist/shared/@ai-setting/{roy-agent-core-978b6wfx.js → roy-agent-core-5psjwd08.js} +1 -1
  80. package/dist/shared/@ai-setting/{roy-agent-core-7evvpfwc.js → roy-agent-core-5rxs0ra3.js} +1 -1
  81. package/dist/shared/@ai-setting/{roy-agent-core-gdsqp6j8.js → roy-agent-core-6masakz4.js} +45 -0
  82. package/dist/shared/@ai-setting/{roy-agent-core-stnddvx9.js → roy-agent-core-6qgq7h1g.js} +4 -4
  83. package/dist/shared/@ai-setting/{roy-agent-core-6167phd4.js → roy-agent-core-833t16n1.js} +3 -3
  84. package/dist/shared/@ai-setting/{roy-agent-core-2k4xffaa.js → roy-agent-core-8cgtwytv.js} +3 -3
  85. package/dist/shared/@ai-setting/{roy-agent-core-rx16h2m1.js → roy-agent-core-97eyghsp.js} +2 -2
  86. package/dist/shared/@ai-setting/{roy-agent-core-fvs48d38.js → roy-agent-core-98aa9r0x.js} +12 -7
  87. package/dist/shared/@ai-setting/{roy-agent-core-3tv1q6f2.js → roy-agent-core-9nv586rw.js} +57 -19
  88. package/dist/shared/@ai-setting/roy-agent-core-b599jgyd.js +578 -0
  89. package/dist/shared/@ai-setting/{roy-agent-core-yd21n6c7.js → roy-agent-core-bwzy00t2.js} +12 -5
  90. package/dist/shared/@ai-setting/{roy-agent-core-dwx9hjwx.js → roy-agent-core-c6at31ra.js} +1 -1
  91. package/dist/shared/@ai-setting/{roy-agent-core-1cv9j4dg.js → roy-agent-core-d14h726p.js} +3 -3
  92. package/dist/shared/@ai-setting/{roy-agent-core-4sx6sdb2.js → roy-agent-core-d4jpn06f.js} +22 -9
  93. package/dist/shared/@ai-setting/{roy-agent-core-39xejr39.js → roy-agent-core-e0wbq0qq.js} +7 -7
  94. package/dist/shared/@ai-setting/{roy-agent-core-vrsxhw9e.js → roy-agent-core-e677am8e.js} +1 -1
  95. package/dist/shared/@ai-setting/{roy-agent-core-hch2geta.js → roy-agent-core-ezsyyjxw.js} +21 -190
  96. package/dist/shared/@ai-setting/{roy-agent-core-ne2t1pay.js → roy-agent-core-f8sp1txg.js} +2 -2
  97. package/dist/shared/@ai-setting/{roy-agent-core-ak4dc3kg.js → roy-agent-core-gn8f4rhs.js} +1 -1
  98. package/dist/shared/@ai-setting/{roy-agent-core-qcspfszy.js → roy-agent-core-gngjkw3b.js} +1 -1
  99. package/dist/shared/@ai-setting/{roy-agent-core-9jzysq50.js → roy-agent-core-heft3j4c.js} +2 -2
  100. package/dist/shared/@ai-setting/{roy-agent-core-5apmk4qw.js → roy-agent-core-jszgaevt.js} +1 -1
  101. package/dist/shared/@ai-setting/{roy-agent-core-nde5gzta.js → roy-agent-core-m8n0dffe.js} +1 -1
  102. package/dist/shared/@ai-setting/{roy-agent-core-x8n1r7h4.js → roy-agent-core-n3b7ztms.js} +189 -8
  103. package/dist/shared/@ai-setting/{roy-agent-core-4vpk40ss.js → roy-agent-core-nhk0dsxr.js} +13 -13
  104. package/dist/shared/@ai-setting/{roy-agent-core-j8e92gj8.js → roy-agent-core-nntphgww.js} +1 -60
  105. package/dist/shared/@ai-setting/{roy-agent-core-8s9jd2qy.js → roy-agent-core-nra8vfrs.js} +1 -1
  106. package/dist/shared/@ai-setting/{roy-agent-core-pk1b3kvf.js → roy-agent-core-ns3pbyz4.js} +1 -1
  107. package/dist/shared/@ai-setting/{roy-agent-core-7g03zkkb.js → roy-agent-core-pemxr5n4.js} +1 -1
  108. package/dist/shared/@ai-setting/{roy-agent-core-skzjs973.js → roy-agent-core-pjxa78mp.js} +5 -5
  109. package/dist/shared/@ai-setting/{roy-agent-core-p8ak03s0.js → roy-agent-core-q7zksbw0.js} +117 -315
  110. package/dist/shared/@ai-setting/{roy-agent-core-zd3ddm4k.js → roy-agent-core-qjjf4tjb.js} +1 -1
  111. package/dist/shared/@ai-setting/{roy-agent-core-qamktze3.js → roy-agent-core-qyqnmz8c.js} +1 -1
  112. package/dist/shared/@ai-setting/{roy-agent-core-9csa89jx.js → roy-agent-core-r9qe0ghe.js} +2 -2
  113. package/dist/shared/@ai-setting/{roy-agent-core-h93v6p6y.js → roy-agent-core-tc7gw38m.js} +2 -2
  114. package/dist/shared/@ai-setting/{roy-agent-core-35s1w7tc.js → roy-agent-core-v2188rnk.js} +157 -85
  115. package/dist/shared/@ai-setting/{roy-agent-core-p2r27era.js → roy-agent-core-vmg30n5x.js} +8 -8
  116. package/dist/shared/@ai-setting/{roy-agent-core-rnwr39b0.js → roy-agent-core-w7hnjhvx.js} +5 -3
  117. package/dist/shared/@ai-setting/{roy-agent-core-dv714bqh.js → roy-agent-core-wafk25ff.js} +1 -1
  118. package/dist/shared/@ai-setting/{roy-agent-core-brwzs8wf.js → roy-agent-core-xcq04fq0.js} +5 -5
  119. package/dist/shared/@ai-setting/{roy-agent-core-2gay3sjt.js → roy-agent-core-yg247mk4.js} +1 -1
  120. package/dist/shared/@ai-setting/{roy-agent-core-zy3hqfwg.js → roy-agent-core-yv9x4wmg.js} +631 -35
  121. package/dist/shared/@ai-setting/{roy-agent-core-yhsssn86.js → roy-agent-core-zmeka63k.js} +1 -1
  122. package/dist/test-utils/child-process-mock.d.ts +73 -0
  123. package/package.json +2 -2
  124. 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-8seq65bp.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 };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  MemorySessionStore,
3
3
  SQLiteSessionStore
4
- } from "./roy-agent-core-h93v6p6y.js";
4
+ } from "./roy-agent-core-tc7gw38m.js";
5
5
  import {
6
6
  init_loose_json,
7
7
  tryParseJsonFromText
@@ -16,11 +16,13 @@ import {
16
16
  } from "./roy-agent-core-7hh0brvs.js";
17
17
  import {
18
18
  BaseComponent
19
- } from "./roy-agent-core-tdbv7ff4.js";
19
+ } from "./roy-agent-core-40xzbjtm.js";
20
20
  import {
21
21
  TracedAs,
22
- init_decorator
23
- } from "./roy-agent-core-dsevjbck.js";
22
+ init_decorator,
23
+ init_trace_filters,
24
+ messagesParamFilter
25
+ } from "./roy-agent-core-b599jgyd.js";
24
26
  import {
25
27
  createLogger,
26
28
  init_logger
@@ -32,6 +34,7 @@ import {
32
34
  // src/env/session/session-component.ts
33
35
  init_logger();
34
36
  init_decorator();
37
+ init_trace_filters();
35
38
 
36
39
  // src/env/session/session-config-registration.ts
37
40
  var SESSION_DEFAULTS = {
@@ -1070,7 +1073,11 @@ __legacyDecorateClassTS([
1070
1073
  TracedAs("session.compact", { recordParams: true, recordResult: true })
1071
1074
  ], SessionComponent.prototype, "compact", null);
1072
1075
  __legacyDecorateClassTS([
1073
- TracedAs("session.extractRecentMessages")
1076
+ TracedAs("session.extractRecentMessages", {
1077
+ paramFilter: messagesParamFilter,
1078
+ recordResult: false,
1079
+ logResult: true
1080
+ })
1074
1081
  ], SessionComponent.prototype, "extractRecentMessages", null);
1075
1082
  // src/env/session/session-id.ts
1076
1083
  var MIN_SESSION_ID_LENGTH = 8;
@@ -10,7 +10,7 @@ import {
10
10
  } from "./roy-agent-core-7hh0brvs.js";
11
11
  import {
12
12
  BaseComponent
13
- } from "./roy-agent-core-tdbv7ff4.js";
13
+ } from "./roy-agent-core-40xzbjtm.js";
14
14
  import {
15
15
  createLogger,
16
16
  init_logger
@@ -2,10 +2,10 @@ import {
2
2
  WorkflowRepository,
3
3
  migrateEmptyTagsToDefault,
4
4
  rowToWorkflow
5
- } from "./roy-agent-core-978b6wfx.js";
6
- import"./roy-agent-core-nde5gzta.js";
5
+ } from "./roy-agent-core-5psjwd08.js";
6
+ import"./roy-agent-core-m8n0dffe.js";
7
7
  import"./roy-agent-core-rvxg1wps.js";
8
- import"./roy-agent-core-dsevjbck.js";
8
+ import"./roy-agent-core-b599jgyd.js";
9
9
  import"./roy-agent-core-8seq65bp.js";
10
10
  import"./roy-agent-core-jnszp0jq.js";
11
11
  import"./roy-agent-core-fs0mn2jk.js";