@ai-setting/roy-agent-core 1.7.61 → 1.7.63

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 (129) hide show
  1. package/dist/config/index.js +8 -8
  2. package/dist/env/agent/agent-component.d.ts +33 -0
  3. package/dist/env/agent/agent-component.js +42 -0
  4. package/dist/env/agent/index.js +19 -16
  5. package/dist/env/agent/types.d.ts +17 -0
  6. package/dist/env/commands/index.js +8 -8
  7. package/dist/env/context/index.js +4 -4
  8. package/dist/env/debug/index.js +8 -8
  9. package/dist/env/error-reply.d.ts +53 -1
  10. package/dist/env/error-reply.js +25 -0
  11. package/dist/env/event-source/cli-command-handler.js +17 -0
  12. package/dist/env/event-source/event-source-handlers.js +59 -0
  13. package/dist/env/event-source/event-store.js +18 -0
  14. package/dist/env/event-source/idempotency-key.js +20 -0
  15. package/dist/env/event-source/index.js +31 -25
  16. package/dist/env/hook/index.js +6 -6
  17. package/dist/env/index.js +53 -46
  18. package/dist/env/lark-mention-utils.js +9 -0
  19. package/dist/env/llm/adapter-pi-ai.d.ts +47 -0
  20. package/dist/env/llm/index.js +10 -9
  21. package/dist/env/llm/model-fallback.d.ts +54 -0
  22. package/dist/env/llm/redact.d.ts +39 -0
  23. package/dist/env/llm/types.d.ts +13 -0
  24. package/dist/env/log-trace/index.js +8 -8
  25. package/dist/env/log-trace/logger.js +39 -0
  26. package/dist/env/mcp/index.js +9 -9
  27. package/dist/env/mcp/tool/index.js +2 -2
  28. package/dist/env/memory/index.js +9 -9
  29. package/dist/env/memory/plugin/index.js +2 -2
  30. package/dist/env/plugin/index.js +9 -9
  31. package/dist/env/prompt/index.js +8 -8
  32. package/dist/env/session/index.js +12 -11
  33. package/dist/env/session/storage/index.js +6 -5
  34. package/dist/env/skill/index.js +8 -8
  35. package/dist/env/task/delegate/delegate-tool.d.ts +27 -1
  36. package/dist/env/task/delegate/delegate-tool.js +42 -0
  37. package/dist/env/task/delegate/index.js +13 -11
  38. package/dist/env/task/index.js +16 -15
  39. package/dist/env/task/mcp/index.js +4 -4
  40. package/dist/env/task/plugins/index.js +11 -11
  41. package/dist/env/task/plugins/lark-card-patch-notifier.js +42 -0
  42. package/dist/env/task/storage/index.js +4 -4
  43. package/dist/env/task/tools/index.js +4 -4
  44. package/dist/env/tool/built-in/index.js +4 -4
  45. package/dist/env/tool/index.js +12 -11
  46. package/dist/env/tool/types.d.ts +13 -0
  47. package/dist/env/tool/types.js +1 -0
  48. package/dist/env/workflow/engine/index.js +13 -13
  49. package/dist/env/workflow/hooks/index.js +8 -8
  50. package/dist/env/workflow/index.js +24 -23
  51. package/dist/env/workflow/nodes/index.js +3 -3
  52. package/dist/env/workflow/plugins/index.js +9 -9
  53. package/dist/env/workflow/service/index.js +3 -3
  54. package/dist/env/workflow/storage/index.js +4 -4
  55. package/dist/env/workflow/tools/index.js +16 -15
  56. package/dist/env/workflow/utils/index.js +5 -5
  57. package/dist/index.js +71 -62
  58. package/dist/shared/@ai-setting/{roy-agent-core-m2tv4pj0.js → roy-agent-core-03k5drfp.js} +212 -172
  59. package/dist/shared/@ai-setting/{roy-agent-core-dythsgkn.js → roy-agent-core-06jakebr.js} +2 -2
  60. package/dist/shared/@ai-setting/{roy-agent-core-jsn21cb9.js → roy-agent-core-084zthqx.js} +1 -1
  61. package/dist/shared/@ai-setting/{roy-agent-core-vmfk4m1v.js → roy-agent-core-1dnsk6ht.js} +3 -3
  62. package/dist/shared/@ai-setting/{roy-agent-core-5565cvw8.js → roy-agent-core-2cw72f16.js} +11 -6
  63. package/dist/shared/@ai-setting/{roy-agent-core-x1m0gs0q.js → roy-agent-core-2hkyp51n.js} +1 -1
  64. package/dist/shared/@ai-setting/{roy-agent-core-q212q0w1.js → roy-agent-core-2pma868e.js} +4 -4
  65. package/dist/shared/@ai-setting/{roy-agent-core-mw0bc9g6.js → roy-agent-core-32ck9rqt.js} +2 -2
  66. package/dist/shared/@ai-setting/{roy-agent-core-bdzdw1g3.js → roy-agent-core-33hn1beg.js} +1 -1
  67. package/dist/shared/@ai-setting/{roy-agent-core-2qkrpc7m.js → roy-agent-core-386wa4wy.js} +1 -1
  68. package/dist/shared/@ai-setting/{roy-agent-core-gtb4fj8j.js → roy-agent-core-5hq4v41q.js} +12 -10
  69. package/dist/shared/@ai-setting/{roy-agent-core-khc23qs1.js → roy-agent-core-5mrynf9g.js} +1 -1
  70. package/dist/shared/@ai-setting/{roy-agent-core-4m5spt7m.js → roy-agent-core-60f7h284.js} +5 -5
  71. package/dist/shared/@ai-setting/{roy-agent-core-y0k9kaxz.js → roy-agent-core-6awgfh3x.js} +1 -1
  72. package/dist/shared/@ai-setting/{roy-agent-core-ygfjgk9b.js → roy-agent-core-6wxww10t.js} +2 -2
  73. package/dist/shared/@ai-setting/{roy-agent-core-xc0es9zc.js → roy-agent-core-79gyka2q.js} +2 -2
  74. package/dist/shared/@ai-setting/{roy-agent-core-expvav8a.js → roy-agent-core-7tce05jt.js} +1 -1
  75. package/dist/shared/@ai-setting/{roy-agent-core-z51jktet.js → roy-agent-core-a08dpf71.js} +17 -2
  76. package/dist/shared/@ai-setting/{roy-agent-core-22r4zmkw.js → roy-agent-core-a6cz4d23.js} +3 -3
  77. package/dist/shared/@ai-setting/{roy-agent-core-0f989bnp.js → roy-agent-core-anb53t3v.js} +3 -3
  78. package/dist/shared/@ai-setting/{roy-agent-core-ymcvsdzn.js → roy-agent-core-as0dd70m.js} +2 -2
  79. package/dist/shared/@ai-setting/{roy-agent-core-jrksyqb6.js → roy-agent-core-b4zdm2n4.js} +8 -8
  80. package/dist/shared/@ai-setting/{roy-agent-core-rnzm0tpf.js → roy-agent-core-bm3gav5d.js} +4 -4
  81. package/dist/shared/@ai-setting/{roy-agent-core-nd5171pv.js → roy-agent-core-bpvz1dqr.js} +8 -8
  82. package/dist/shared/@ai-setting/{roy-agent-core-aa514zm8.js → roy-agent-core-c4t4y18j.js} +5 -5
  83. package/dist/shared/@ai-setting/{roy-agent-core-sf9tsj0g.js → roy-agent-core-c57278kx.js} +1 -1
  84. package/dist/shared/@ai-setting/{roy-agent-core-e6k448ka.js → roy-agent-core-c8xvy6hj.js} +4 -4
  85. package/dist/shared/@ai-setting/{roy-agent-core-qgapy83x.js → roy-agent-core-cxpgd415.js} +6 -6
  86. package/dist/shared/@ai-setting/{roy-agent-core-g44nbgtt.js → roy-agent-core-dfqhc9ey.js} +2 -2
  87. package/dist/shared/@ai-setting/{roy-agent-core-6cyjps72.js → roy-agent-core-ebws32tv.js} +14 -14
  88. package/dist/shared/@ai-setting/{roy-agent-core-yr5eqyhz.js → roy-agent-core-g23yp3t1.js} +309 -59
  89. package/dist/shared/@ai-setting/roy-agent-core-g6pw4esq.js +473 -0
  90. package/dist/shared/@ai-setting/{roy-agent-core-3p59ap0x.js → roy-agent-core-gc6wcd7z.js} +1 -1
  91. package/dist/shared/@ai-setting/{roy-agent-core-s7w47mnn.js → roy-agent-core-gjsvehfs.js} +1 -1
  92. package/dist/shared/@ai-setting/{roy-agent-core-cndvj1hv.js → roy-agent-core-gnt23yx0.js} +30 -118
  93. package/dist/shared/@ai-setting/{roy-agent-core-9s3payp1.js → roy-agent-core-gtdtzbs7.js} +2 -2
  94. package/dist/shared/@ai-setting/{roy-agent-core-mhppywse.js → roy-agent-core-hczj1ryh.js} +4 -4
  95. package/dist/shared/@ai-setting/{roy-agent-core-qrjs2500.js → roy-agent-core-hfyxv2kx.js} +2 -2
  96. package/dist/shared/@ai-setting/{roy-agent-core-dg286rpd.js → roy-agent-core-hwkc0bg2.js} +1 -1
  97. package/dist/shared/@ai-setting/{roy-agent-core-bc3v8pw4.js → roy-agent-core-ja4sr63d.js} +6 -6
  98. package/dist/shared/@ai-setting/roy-agent-core-jagkferh.js +16 -0
  99. package/dist/shared/@ai-setting/roy-agent-core-jm136jzh.js +99 -0
  100. package/dist/shared/@ai-setting/{roy-agent-core-g5sw19fa.js → roy-agent-core-jw63js86.js} +1 -1
  101. package/dist/shared/@ai-setting/{roy-agent-core-8fy467qs.js → roy-agent-core-kmvw6b4v.js} +1 -1
  102. package/dist/shared/@ai-setting/{roy-agent-core-3bpntd80.js → roy-agent-core-kvq4a4p6.js} +2 -2
  103. package/dist/shared/@ai-setting/{roy-agent-core-yd85623y.js → roy-agent-core-m3w3ytxt.js} +2 -2
  104. package/dist/shared/@ai-setting/{roy-agent-core-64f22h1g.js → roy-agent-core-m880qz3y.js} +7 -1
  105. package/dist/shared/@ai-setting/{roy-agent-core-5knpegzr.js → roy-agent-core-mbwaxqs0.js} +3 -3
  106. package/dist/shared/@ai-setting/{roy-agent-core-tn96n4wz.js → roy-agent-core-mkpsz128.js} +4 -4
  107. package/dist/shared/@ai-setting/{roy-agent-core-9k8ms63r.js → roy-agent-core-mrrv80jy.js} +1 -1
  108. package/dist/shared/@ai-setting/roy-agent-core-ntn32q7j.js +72 -0
  109. package/dist/shared/@ai-setting/roy-agent-core-p37kh0kt.js +155 -0
  110. package/dist/shared/@ai-setting/{roy-agent-core-60p2380d.js → roy-agent-core-p6a4v4fq.js} +1 -1
  111. package/dist/shared/@ai-setting/{roy-agent-core-hf0t8agb.js → roy-agent-core-p8rf4z89.js} +1 -1
  112. package/dist/shared/@ai-setting/roy-agent-core-pnj0zh25.js +0 -0
  113. package/dist/shared/@ai-setting/{roy-agent-core-dp1hp24k.js → roy-agent-core-prnry2mw.js} +3 -3
  114. package/dist/shared/@ai-setting/{roy-agent-core-qw5fpa24.js → roy-agent-core-qmqe8ds3.js} +3 -3
  115. package/dist/shared/@ai-setting/{roy-agent-core-jsdqzfbj.js → roy-agent-core-rfhxj8v2.js} +1 -1
  116. package/dist/shared/@ai-setting/{roy-agent-core-j0x9yf96.js → roy-agent-core-sj4y3wdm.js} +3 -3
  117. package/dist/shared/@ai-setting/{roy-agent-core-ytnedzks.js → roy-agent-core-t6nx0rsz.js} +333 -1332
  118. package/dist/shared/@ai-setting/{roy-agent-core-xeqp659x.js → roy-agent-core-th92f833.js} +2 -2
  119. package/dist/shared/@ai-setting/{roy-agent-core-ajmgyawx.js → roy-agent-core-v7mwj8eq.js} +2 -2
  120. package/dist/shared/@ai-setting/roy-agent-core-va4m04e8.js +524 -0
  121. package/dist/shared/@ai-setting/{roy-agent-core-qpqqx1wd.js → roy-agent-core-vwzan9v0.js} +2 -2
  122. package/dist/shared/@ai-setting/{roy-agent-core-pj5tfmn5.js → roy-agent-core-w2ev3z5q.js} +12 -14
  123. package/dist/shared/@ai-setting/{roy-agent-core-kfmrfaft.js → roy-agent-core-wzp4tbsn.js} +1 -1
  124. package/dist/shared/@ai-setting/{roy-agent-core-n1ck0x1r.js → roy-agent-core-ye4bfzqg.js} +11 -11
  125. package/dist/shared/@ai-setting/{roy-agent-core-p2dpcyrz.js → roy-agent-core-zjgckbdd.js} +2 -2
  126. package/dist/shared/@ai-setting/{roy-agent-core-a5nh5q6v.js → roy-agent-core-zy8vkbnk.js} +1 -1
  127. package/dist/test-utils/child-process-mock.js +23 -0
  128. package/dist/utils/temp-file-manager/index.js +2 -2
  129. package/package.json +61 -1
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-2qkrpc7m.js";
4
+ } from "./roy-agent-core-386wa4wy.js";
5
5
  import {
6
6
  createLogger,
7
7
  init_logger
8
- } from "./roy-agent-core-y0k9kaxz.js";
8
+ } from "./roy-agent-core-6awgfh3x.js";
9
9
  import {
10
10
  __esm,
11
11
  __export,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  init_context
3
- } from "./roy-agent-core-bdzdw1g3.js";
3
+ } from "./roy-agent-core-33hn1beg.js";
4
4
  import {
5
5
  getEnvContext
6
- } from "./roy-agent-core-qrjs2500.js";
6
+ } from "./roy-agent-core-hfyxv2kx.js";
7
7
  import {
8
8
  __esm
9
9
  } from "./roy-agent-core-fs0mn2jk.js";
@@ -0,0 +1,524 @@
1
+ import {
2
+ redactSecrets
3
+ } from "./roy-agent-core-ntn32q7j.js";
4
+ import {
5
+ normalizeLarkAtMentions
6
+ } from "./roy-agent-core-m880qz3y.js";
7
+ import {
8
+ createLogger,
9
+ init_logger
10
+ } from "./roy-agent-core-6awgfh3x.js";
11
+
12
+ // src/env/error-reply.ts
13
+ init_logger();
14
+ import { spawn } from "node:child_process";
15
+ var logger = createLogger("env:error-reply");
16
+ var UPSTREAM_RETRY_PATTERNS = [
17
+ /failed after \d+ attempts/i,
18
+ /endpoint is unavailable/i,
19
+ /upstream request failed/i,
20
+ /rate.?limit/i,
21
+ /\b429\b/,
22
+ /\b50[0234]\b/,
23
+ /service (is )?(temporarily )?unavailable/i,
24
+ /\beconn(reset|refused|aborted)\b/i,
25
+ /socket hang up/i,
26
+ /fetch failed/i,
27
+ /network error/i,
28
+ /overloaded/i
29
+ ];
30
+ var QUOTA_EXHAUSTED_PATTERNS = [
31
+ /free usage limit (reached|exceeded)/i,
32
+ /free (model )?(usage|quota).{0,20}(limit|exhaust)/i,
33
+ /usage limit (reached|exceeded)/i,
34
+ /quota (exceeded|exhausted|reached)/i,
35
+ /insufficient[_ ]?(quota|balance|credit)/i,
36
+ /(credit|balance) (is )?(exhausted|insufficient)/i,
37
+ /billing (hard )?limit/i
38
+ ];
39
+ var TIMEOUT_PATTERNS = [
40
+ /timeout/i,
41
+ /timed out/i,
42
+ /deadline exceeded/i,
43
+ /etimedout/i,
44
+ /aborted due to timeout/i
45
+ ];
46
+ var TRANSPORT_ABORT_PATTERNS = [
47
+ /requestabortederror/i,
48
+ /econnaborted/i,
49
+ /connection (was )?(aborted|reset|closed)/i,
50
+ /premature close/i
51
+ ];
52
+ var ABORT_PATTERNS = [
53
+ /\babort(?:ed|ing)?\b/i,
54
+ /operation was cancelled/i,
55
+ /operation was canceled/i,
56
+ /sigint/i,
57
+ /\binterrupted\b/i,
58
+ /exiting due to (signal|shutdown)/i
59
+ ];
60
+ var CONTEXT_PATTERNS = [
61
+ /context threshold/i,
62
+ /context (window|length|limit)/i,
63
+ /token limit/i,
64
+ /maximum context/i,
65
+ /ctrieve\b/,
66
+ /CTX_001/
67
+ ];
68
+ var ASK_USER_PATTERNS = [/__ASK_USER_ERROR__/];
69
+ function collectErrorText(error, depth = 0) {
70
+ const parts = [];
71
+ const push = (v) => {
72
+ if (typeof v === "string" && v.length > 0)
73
+ parts.push(v);
74
+ };
75
+ if (error === null || error === undefined)
76
+ return "";
77
+ if (typeof error === "string") {
78
+ push(error);
79
+ return parts.join(`
80
+ `);
81
+ }
82
+ if (typeof error !== "object") {
83
+ push(String(error));
84
+ return parts.join(`
85
+ `);
86
+ }
87
+ const e = error;
88
+ push(e.name);
89
+ push(e.message);
90
+ for (const key of ["statusCode", "status", "code"]) {
91
+ const v = e[key];
92
+ if (typeof v === "number" || typeof v === "string")
93
+ push(String(v));
94
+ }
95
+ if (depth < 3) {
96
+ const nested = collectErrorText(e.lastError, depth + 1);
97
+ if (nested)
98
+ parts.push(nested);
99
+ if (Array.isArray(e.errors)) {
100
+ for (const inner of e.errors.slice(-3)) {
101
+ const s = collectErrorText(inner, depth + 1);
102
+ if (s)
103
+ parts.push(s);
104
+ }
105
+ }
106
+ const cause = collectErrorText(e.cause, depth + 1);
107
+ if (cause)
108
+ parts.push(cause);
109
+ }
110
+ return parts.join(`
111
+ `);
112
+ }
113
+ function extractRetryAfterSeconds(error, depth = 0) {
114
+ if (!error || typeof error !== "object" || depth > 6)
115
+ return;
116
+ const e = error;
117
+ const candidates = [
118
+ e.retryAfter,
119
+ e.retry_after,
120
+ e.retryAfterSeconds,
121
+ e.headers?.["retry-after"],
122
+ e.headers?.["Retry-After"],
123
+ e.responseHeaders?.["retry-after"],
124
+ e.responseHeaders?.["Retry-After"],
125
+ e.headers?.get?.("retry-after"),
126
+ e.data?.error?.retry_after,
127
+ e.data?.error?.retryAfter
128
+ ];
129
+ for (const raw of candidates) {
130
+ const seconds = toSeconds(raw);
131
+ if (seconds !== undefined)
132
+ return seconds;
133
+ }
134
+ const nested = [e.lastError, e.cause];
135
+ if (Array.isArray(e.errors))
136
+ nested.push(...e.errors.slice(-2));
137
+ for (const inner of nested) {
138
+ const seconds = extractRetryAfterSeconds(inner, depth + 1);
139
+ if (seconds !== undefined)
140
+ return seconds;
141
+ }
142
+ return;
143
+ }
144
+ function toSeconds(raw) {
145
+ if (typeof raw === "number" && Number.isFinite(raw) && raw >= 0)
146
+ return raw;
147
+ if (typeof raw !== "string")
148
+ return;
149
+ const trimmed = raw.trim();
150
+ if (!trimmed)
151
+ return;
152
+ const asNumber = Number(trimmed);
153
+ if (Number.isFinite(asNumber) && asNumber >= 0)
154
+ return asNumber;
155
+ const asDate = Date.parse(trimmed);
156
+ if (!Number.isNaN(asDate)) {
157
+ const delta = Math.max(0, asDate - Date.now());
158
+ return Math.round(delta / 1000);
159
+ }
160
+ return;
161
+ }
162
+ function humanizeRetryAfter(seconds) {
163
+ if (seconds === undefined || !Number.isFinite(seconds) || seconds < 0)
164
+ return;
165
+ if (seconds < 90)
166
+ return "约 1 分钟内";
167
+ const minutes = seconds / 60;
168
+ if (minutes < 90)
169
+ return `约 ${Math.round(minutes)} 分钟后`;
170
+ const hours = minutes / 60;
171
+ if (hours < 36)
172
+ return `约 ${Math.round(hours)} 小时后`;
173
+ const days = hours / 24;
174
+ return `约 ${Math.round(days)} 天后`;
175
+ }
176
+ function truncate(text, max) {
177
+ if (text.length <= max)
178
+ return text;
179
+ return text.slice(0, max) + "…";
180
+ }
181
+ var FAILURE_RULES = [
182
+ {
183
+ id: "ask_user",
184
+ kind: "ask_user",
185
+ names: ["AskUserError"],
186
+ patterns: ASK_USER_PATTERNS,
187
+ notify: false,
188
+ title: "等待用户回答",
189
+ reason: "agent 正在等待用户回答,不是失败。",
190
+ retryable: false
191
+ },
192
+ {
193
+ id: "context_overflow",
194
+ kind: "context_overflow",
195
+ names: ["ContextError"],
196
+ patterns: CONTEXT_PATTERNS,
197
+ notify: true,
198
+ title: "上下文超出限制",
199
+ reason: "这次对话的上下文超出模型窗口,自动压缩也未能恢复。建议新开一个会话继续,或先让我压缩当前会话。",
200
+ retryable: false
201
+ },
202
+ {
203
+ id: "timeout",
204
+ kind: "timeout",
205
+ names: ["TimeoutError"],
206
+ patterns: TIMEOUT_PATTERNS,
207
+ notify: true,
208
+ title: "执行超时",
209
+ reason: "本次执行等待响应超时(上游长时间未返回或网络卡住)。建议稍后重试,或把任务拆小一些。",
210
+ retryable: true
211
+ },
212
+ {
213
+ id: "quota_exhausted",
214
+ kind: "quota_exhausted",
215
+ names: ["FreeUsageLimitError"],
216
+ patterns: QUOTA_EXHAUSTED_PATTERNS,
217
+ notify: true,
218
+ title: "模型额度已用尽",
219
+ reason: "本次调用被上游拒绝:该模型的额度(或免费额度)已经用完。这不是你的操作问题," + "也不是仓库代码的问题 —— 重发同一个模型不会恢复,需要换模型或等额度重置。",
220
+ retryable: false,
221
+ suggestion: "换一个模型(例如 `--model <provider>/<付费模型>`),或等额度重置后再试。"
222
+ },
223
+ {
224
+ id: "upstream_retry",
225
+ kind: "upstream_retry",
226
+ names: ["AI_RetryError", "RetryError", "APICallError", "AI_APICallError"],
227
+ patterns: UPSTREAM_RETRY_PATTERNS,
228
+ notify: true,
229
+ title: "模型服务暂时不可用(重试已用尽)",
230
+ reason: "调用模型时上游持续返回错误(如 429 限流 / 503 不可用),自动重试多次后仍未成功。" + "这不是你的操作问题,也不是仓库代码的问题 —— 稍后重发一次即可。",
231
+ retryable: true
232
+ },
233
+ {
234
+ id: "upstream_aborted",
235
+ kind: "upstream_aborted",
236
+ names: ["RequestAbortedError"],
237
+ patterns: TRANSPORT_ABORT_PATTERNS,
238
+ unless: TIMEOUT_PATTERNS,
239
+ notify: true,
240
+ title: "与模型服务的连接中断",
241
+ reason: "请求在传输过程中被中断(连接被重置 / 代理提前关闭),不是你的操作问题。稍后重发一次即可。",
242
+ retryable: true
243
+ },
244
+ {
245
+ id: "aborted",
246
+ kind: "aborted",
247
+ names: ["AbortError", "AbortSignal"],
248
+ patterns: ABORT_PATTERNS,
249
+ unless: [...TIMEOUT_PATTERNS, ...TRANSPORT_ABORT_PATTERNS],
250
+ notify: true,
251
+ title: "执行被中断",
252
+ reason: "本次执行在完成前被中断(可能你手动取消了,或进程收到了停止信号)。你可以直接让我重新执行。",
253
+ retryable: true
254
+ }
255
+ ];
256
+ var UNKNOWN_RULE = {
257
+ id: "unknown",
258
+ kind: "unknown",
259
+ notify: true,
260
+ title: "执行异常失败",
261
+ reason: "本次执行遇到了未预期的异常,已中止。你可以重试;如果持续失败,请把这条消息里的技术细节发我。",
262
+ retryable: true
263
+ };
264
+ function ruleMatches(rule, name, text) {
265
+ const lowered = name.toLowerCase();
266
+ const nameHit = rule.names?.some((n) => n.toLowerCase() === lowered) ?? false;
267
+ const patternHit = rule.patterns?.some((p) => p.test(text)) ?? false;
268
+ if (!nameHit && !patternHit)
269
+ return false;
270
+ if (rule.unless?.some((p) => p.test(text)))
271
+ return false;
272
+ return true;
273
+ }
274
+ function getFailureRuleIds() {
275
+ return [...FAILURE_RULES.map((r) => r.id), UNKNOWN_RULE.id];
276
+ }
277
+ function classifyReactFailure(error) {
278
+ const text = collectErrorText(error);
279
+ const name = error && typeof error === "object" ? String(error.name ?? "") : "";
280
+ const technical = text ? truncate(redactSecrets(text.replace(/\s*\n\s*/g, " | ")), 400) : undefined;
281
+ const rule = FAILURE_RULES.find((r) => ruleMatches(r, name, text)) ?? UNKNOWN_RULE;
282
+ const retryAfterSeconds = rule.kind === "quota_exhausted" ? extractRetryAfterSeconds(error) : undefined;
283
+ const window = humanizeRetryAfter(retryAfterSeconds);
284
+ return {
285
+ kind: rule.kind,
286
+ ruleId: rule.id,
287
+ title: rule.title,
288
+ reason: window ? `${rule.reason}上游提示:额度${window}恢复。` : rule.reason,
289
+ retryable: rule.retryable,
290
+ notify: rule.notify,
291
+ technical,
292
+ ...retryAfterSeconds !== undefined ? { retryAfterSeconds } : {},
293
+ ...rule.suggestion ? { suggestion: rule.suggestion } : {}
294
+ };
295
+ }
296
+ var MAX_QUERY_PREVIEW = 200;
297
+ function buildFailureReplyMarkdown(info, opts) {
298
+ const lines = [];
299
+ lines.push(`❌ **${info.title}**`);
300
+ lines.push("");
301
+ lines.push(info.reason);
302
+ const query = opts?.query?.trim();
303
+ if (query) {
304
+ lines.push("");
305
+ lines.push(`> 原始请求:${truncate(query.replace(/\s+/g, " "), MAX_QUERY_PREVIEW)}`);
306
+ }
307
+ lines.push("");
308
+ if (info.suggestion) {
309
+ lines.push(`**你可以:** ${info.suggestion}`);
310
+ } else if (info.retryable) {
311
+ lines.push("**你可以:** 直接再发一次(重发即可,无需额外操作)。");
312
+ } else {
313
+ lines.push("**你可以:** 新开一个会话,或先让我压缩当前会话。");
314
+ }
315
+ const technical = info.technical;
316
+ if (technical) {
317
+ lines.push("");
318
+ lines.push(`> 技术细节:${truncate(technical, 300)}`);
319
+ }
320
+ return lines.join(`
321
+ `);
322
+ }
323
+ function errorName(error) {
324
+ if (!error || typeof error !== "object")
325
+ return "";
326
+ const n = error.name;
327
+ return typeof n === "string" ? n : "";
328
+ }
329
+ function formatCliFailureLine(error) {
330
+ const info = classifyReactFailure(error);
331
+ if (info.kind === "quota_exhausted") {
332
+ const window = humanizeRetryAfter(info.retryAfterSeconds);
333
+ const head = `${info.title}(${window ? window.replace(/^约 /, "约 ") + "恢复" : "恢复时间未知"})`;
334
+ const advice = info.suggestion ? ` 建议:${info.suggestion}` : "";
335
+ return `${head} —— 重发同一模型无效。${advice}`.trim();
336
+ }
337
+ const segments = (info.technical ?? "").split("|").map((seg) => seg.trim()).filter((seg) => seg.length > 0 && seg.toLowerCase() !== (errorName(error) || "").toLowerCase());
338
+ const informative = segments.find((seg) => /\d/.test(seg)) ?? [...segments].sort((a, b) => b.length - a.length)[0] ?? "";
339
+ const summary = informative.slice(0, 200);
340
+ return summary ? `${info.title}:${summary}` : info.title;
341
+ }
342
+ function extractReplyChannelFromEvent(envEvent) {
343
+ if (!envEvent || typeof envEvent !== "object")
344
+ return;
345
+ const e = envEvent;
346
+ const candidates = [
347
+ e.metadata?.replyChannel,
348
+ e.payload?.replyChannel
349
+ ];
350
+ for (const c of candidates) {
351
+ if (c && typeof c === "object") {
352
+ const ch = c;
353
+ if (ch.chatId || ch.messageId)
354
+ return ch;
355
+ }
356
+ }
357
+ return;
358
+ }
359
+ function isUsableChannel(ch) {
360
+ if (!ch)
361
+ return false;
362
+ if (!ch.chatId && !ch.messageId)
363
+ return false;
364
+ if (ch.type && !ch.type.toLowerCase().includes("lark"))
365
+ return false;
366
+ return true;
367
+ }
368
+ var repliedTriggers = new Map;
369
+ var CHAT_DEDUP_WINDOW_MS = 5 * 60000;
370
+ var MAX_DEDUP_ENTRIES = 1000;
371
+ function makeDedupKey(channel, info, explicit, now = Date.now()) {
372
+ if (explicit)
373
+ return explicit;
374
+ if (channel.messageId)
375
+ return `msg:${channel.messageId}`;
376
+ if (channel.chatId) {
377
+ const bucket = Math.floor(now / CHAT_DEDUP_WINDOW_MS);
378
+ return `chat:${channel.chatId}:${info.kind}:${bucket}`;
379
+ }
380
+ return "unknown";
381
+ }
382
+ function isDuplicate(key, now = Date.now()) {
383
+ const at = repliedTriggers.get(key);
384
+ if (at === undefined)
385
+ return false;
386
+ if (key.startsWith("chat:") && now - at >= CHAT_DEDUP_WINDOW_MS) {
387
+ repliedTriggers.delete(key);
388
+ return false;
389
+ }
390
+ return true;
391
+ }
392
+ function rememberTrigger(key, now = Date.now()) {
393
+ if (repliedTriggers.size >= MAX_DEDUP_ENTRIES) {
394
+ const oldest = repliedTriggers.keys().next().value;
395
+ if (oldest !== undefined)
396
+ repliedTriggers.delete(oldest);
397
+ }
398
+ repliedTriggers.set(key, now);
399
+ }
400
+ function __resetFailureReplyDedupForTest() {
401
+ repliedTriggers.clear();
402
+ }
403
+ var DEFAULT_REPLY_TIMEOUT_MS = 5000;
404
+ function spawnLarkReply(options) {
405
+ return new Promise((resolve, reject) => {
406
+ const { chatId, messageId, content, profile } = options;
407
+ const timeoutMs = options.timeoutMs ?? DEFAULT_REPLY_TIMEOUT_MS;
408
+ let settled = false;
409
+ let timer;
410
+ const finish = (err) => {
411
+ if (settled)
412
+ return;
413
+ settled = true;
414
+ if (timer)
415
+ clearTimeout(timer);
416
+ if (err)
417
+ reject(err);
418
+ else
419
+ resolve();
420
+ };
421
+ const normalizedContent = normalizeLarkAtMentions(content);
422
+ let args;
423
+ if (messageId) {
424
+ args = [
425
+ "im",
426
+ "+messages-reply",
427
+ "--message-id",
428
+ messageId,
429
+ "--markdown",
430
+ normalizedContent,
431
+ "--as",
432
+ "bot"
433
+ ];
434
+ } else if (chatId) {
435
+ args = [
436
+ "im",
437
+ "+messages-send",
438
+ "--chat-id",
439
+ chatId,
440
+ "--markdown",
441
+ normalizedContent,
442
+ "--as",
443
+ "bot"
444
+ ];
445
+ } else {
446
+ finish(new Error("No target specified for failure reply"));
447
+ return;
448
+ }
449
+ if (profile) {
450
+ args.unshift("--profile", profile);
451
+ }
452
+ let proc;
453
+ try {
454
+ proc = spawn("lark-cli", args, {
455
+ shell: false,
456
+ stdio: ["pipe", "pipe", "pipe"]
457
+ });
458
+ } catch (err) {
459
+ finish(err instanceof Error ? err : new Error(String(err)));
460
+ return;
461
+ }
462
+ timer = setTimeout(() => {
463
+ try {
464
+ proc.kill("SIGKILL");
465
+ } catch {}
466
+ finish(new Error(`lark-cli timed out after ${timeoutMs}ms`));
467
+ }, timeoutMs);
468
+ timer.unref?.();
469
+ let stderr = "";
470
+ proc.stdout?.on("data", () => {});
471
+ proc.stderr?.on("data", (data) => {
472
+ stderr += data.toString();
473
+ });
474
+ proc.on("close", (code) => {
475
+ if (code === 0)
476
+ finish();
477
+ else
478
+ finish(new Error(`lark-cli exited with code ${code}: ${stderr}`));
479
+ });
480
+ proc.on("error", (err) => finish(err));
481
+ });
482
+ }
483
+ async function notifyReactFailure(options) {
484
+ const info = classifyReactFailure(options.error);
485
+ if (!info.notify) {
486
+ logger.debug(`[#4418] 命中规则 ${info.ruleId}(非失败),不发失败说明` + (options.sessionId ? ` (session=${options.sessionId})` : ""));
487
+ return { sent: false, kind: info.kind, info, skipped: "not_a_failure" };
488
+ }
489
+ const channel = (isUsableChannel(options.replyChannel) ? options.replyChannel : undefined) ?? extractReplyChannelFromEvent(options.envEvent);
490
+ if (!isUsableChannel(channel)) {
491
+ const hasTrigger = Boolean(options.envEvent);
492
+ const noChannelMsg = `[#4418] React 中断(${info.kind}/${info.ruleId})无法定位 replyChannel,` + `飞书端收不到失败说明` + (hasTrigger ? " —— triggerEvent 存在但缺少 metadata.replyChannel" : "(本地执行,无 triggerEvent)") + (options.sessionId ? ` (session=${options.sessionId})` : "");
493
+ if (hasTrigger)
494
+ logger.warn(noChannelMsg);
495
+ else
496
+ logger.debug(noChannelMsg);
497
+ return { sent: false, kind: info.kind, info, skipped: "no_channel" };
498
+ }
499
+ const dedupKey = makeDedupKey(channel, info, options.dedupKey);
500
+ if (isDuplicate(dedupKey)) {
501
+ logger.info(`[#4418] React 中断(${info.kind})已回复过 ${dedupKey},跳过`);
502
+ return { sent: false, kind: info.kind, info, skipped: "duplicate" };
503
+ }
504
+ rememberTrigger(dedupKey);
505
+ const content = buildFailureReplyMarkdown(info, { query: options.query });
506
+ try {
507
+ await spawnLarkReply({
508
+ chatId: channel.chatId,
509
+ messageId: channel.messageId,
510
+ content,
511
+ profile: channel.profile,
512
+ timeoutMs: options.replyTimeoutMs
513
+ });
514
+ logger.info(`[#4418] React 中断(${info.kind}/${info.ruleId})已回飞书 ` + `(${channel.messageId ?? channel.chatId})`);
515
+ return { sent: true, kind: info.kind, info };
516
+ } catch (err) {
517
+ const errorMsg = err instanceof Error ? err.message : String(err);
518
+ repliedTriggers.delete(dedupKey);
519
+ logger.warn(`[#4418] React 中断(${info.kind}/${info.ruleId})回飞书失败(已忽略): ${errorMsg}`);
520
+ return { sent: false, kind: info.kind, info, error: errorMsg };
521
+ }
522
+ }
523
+
524
+ export { extractRetryAfterSeconds, humanizeRetryAfter, getFailureRuleIds, classifyReactFailure, buildFailureReplyMarkdown, formatCliFailureLine, __resetFailureReplyDedupForTest, notifyReactFailure };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TagRepository
3
- } from "./roy-agent-core-3p59ap0x.js";
3
+ } from "./roy-agent-core-gc6wcd7z.js";
4
4
  import {
5
5
  exports_search_query_parser,
6
6
  init_search_query_parser
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  createLogger,
10
10
  init_logger
11
- } from "./roy-agent-core-y0k9kaxz.js";
11
+ } from "./roy-agent-core-6awgfh3x.js";
12
12
  import {
13
13
  __require,
14
14
  __toCommonJS
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TempFileManager
3
- } from "./roy-agent-core-kfmrfaft.js";
3
+ } from "./roy-agent-core-wzp4tbsn.js";
4
4
  import {
5
5
  AskUserError,
6
6
  init_workflow_hil
@@ -11,27 +11,27 @@ import {
11
11
  } from "./roy-agent-core-7hh0brvs.js";
12
12
  import {
13
13
  BaseComponent
14
- } from "./roy-agent-core-9s3payp1.js";
14
+ } from "./roy-agent-core-gtdtzbs7.js";
15
15
  import {
16
16
  ToolHookPoints,
17
17
  globalHookManager,
18
18
  init_global_hook_manager
19
- } from "./roy-agent-core-ajmgyawx.js";
19
+ } from "./roy-agent-core-v7mwj8eq.js";
20
20
  import {
21
21
  getCurrentTaskId,
22
22
  init_env_context
23
- } from "./roy-agent-core-qrjs2500.js";
23
+ } from "./roy-agent-core-hfyxv2kx.js";
24
24
  import {
25
25
  TracedAs,
26
26
  init_decorator,
27
27
  init_trace_filters,
28
28
  toolExecResultFilter,
29
29
  toolInvokeParamFilter
30
- } from "./roy-agent-core-2qkrpc7m.js";
30
+ } from "./roy-agent-core-386wa4wy.js";
31
31
  import {
32
32
  createLogger,
33
33
  init_logger
34
- } from "./roy-agent-core-y0k9kaxz.js";
34
+ } from "./roy-agent-core-6awgfh3x.js";
35
35
  import {
36
36
  __legacyDecorateClassTS,
37
37
  __require
@@ -161,6 +161,12 @@ class ToolValidator {
161
161
  }
162
162
  }
163
163
 
164
+ // src/env/constants.ts
165
+ var TOOL_UNAVAILABLE_ERROR_RE = /^Tool (?:not found|disabled):/;
166
+ function isToolUnavailableError(message) {
167
+ return typeof message === "string" && TOOL_UNAVAILABLE_ERROR_RE.test(message);
168
+ }
169
+
164
170
  // src/env/tool/tool-component.ts
165
171
  import { z } from "zod";
166
172
  init_logger();
@@ -198,14 +204,6 @@ var TOOL_CONFIG_REGISTRATION = {
198
204
 
199
205
  // src/env/tool/tool-component.ts
200
206
  init_workflow_hil();
201
-
202
- // src/env/constants.ts
203
- var TOOL_UNAVAILABLE_ERROR_RE = /^Tool (?:not found|disabled):/;
204
- function isToolUnavailableError(message) {
205
- return typeof message === "string" && TOOL_UNAVAILABLE_ERROR_RE.test(message);
206
- }
207
-
208
- // src/env/tool/tool-component.ts
209
207
  init_env_context();
210
208
  var logger = createLogger("tool");
211
209
  var configComponentInstance = null;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createLogger,
3
3
  init_logger
4
- } from "./roy-agent-core-y0k9kaxz.js";
4
+ } from "./roy-agent-core-6awgfh3x.js";
5
5
 
6
6
  // src/utils/temp-file-manager/index.ts
7
7
  init_logger();