@ai-setting/roy-agent-core 1.7.59 → 1.7.62
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.
- package/dist/config/index.js +8 -8
- package/dist/env/agent/agent-component.js +41 -0
- package/dist/env/agent/index.js +18 -16
- package/dist/env/commands/index.js +8 -8
- package/dist/env/context/index.js +4 -4
- package/dist/env/debug/index.js +8 -8
- package/dist/env/error-reply.js +18 -0
- package/dist/env/event-source/cli-command-handler.d.ts +90 -0
- package/dist/env/event-source/cli-command-handler.js +17 -0
- package/dist/env/event-source/event-source-handlers.d.ts +1 -0
- package/dist/env/event-source/event-source-handlers.js +58 -0
- package/dist/env/event-source/event-store.js +18 -0
- package/dist/env/event-source/idempotency-key.js +20 -0
- package/dist/env/event-source/index.d.ts +3 -1
- package/dist/env/event-source/index.js +37 -22
- package/dist/env/event-source/types.d.ts +21 -1
- package/dist/env/hook/index.js +6 -6
- package/dist/env/index.js +54 -48
- package/dist/env/lark-mention-utils.js +9 -0
- package/dist/env/llm/index.js +9 -9
- package/dist/env/log-trace/index.d.ts +1 -1
- package/dist/env/log-trace/index.js +12 -8
- package/dist/env/log-trace/logger.d.ts +2 -0
- package/dist/env/log-trace/logger.js +39 -0
- package/dist/env/mcp/index.js +9 -9
- package/dist/env/mcp/tool/index.js +2 -2
- package/dist/env/memory/index.js +9 -9
- package/dist/env/memory/plugin/index.js +2 -2
- package/dist/env/plugin/index.js +9 -9
- package/dist/env/prompt/index.js +8 -8
- package/dist/env/session/index.js +11 -11
- package/dist/env/session/storage/index.js +5 -5
- package/dist/env/skill/index.js +8 -8
- package/dist/env/task/delegate/delegate-tool.js +42 -0
- package/dist/env/task/delegate/index.js +13 -11
- package/dist/env/task/index.js +17 -16
- package/dist/env/task/mcp/index.d.ts +16 -0
- package/dist/env/task/mcp/index.js +222 -0
- package/dist/env/task/mcp/task-mcp-server.d.ts +142 -0
- package/dist/env/task/plugins/index.d.ts +1 -0
- package/dist/env/task/plugins/index.js +47 -12
- package/dist/env/task/plugins/lark-card-patch-notifier.js +42 -0
- package/dist/env/task/storage/index.js +4 -4
- package/dist/env/task/storage/migrations/log-migration.d.ts +19 -0
- package/dist/env/task/storage/sqlite-task-store.d.ts +29 -0
- package/dist/env/task/task-component.d.ts +48 -3
- package/dist/env/task/tools/index.js +4 -4
- package/dist/env/task/tools/task-types.d.ts +60 -11
- package/dist/env/tool/built-in/index.js +4 -4
- package/dist/env/tool/index.js +12 -11
- package/dist/env/tool/types.js +1 -0
- package/dist/env/workflow/engine/index.js +13 -13
- package/dist/env/workflow/hooks/index.js +8 -8
- package/dist/env/workflow/index.js +23 -23
- package/dist/env/workflow/nodes/index.js +3 -3
- package/dist/env/workflow/plugins/index.js +9 -9
- package/dist/env/workflow/service/index.js +3 -3
- package/dist/env/workflow/storage/index.js +4 -4
- package/dist/env/workflow/tools/index.js +15 -15
- package/dist/env/workflow/tools/run-workflow.d.ts +30 -0
- package/dist/env/workflow/utils/index.js +5 -5
- package/dist/env/workflow/utils/session-recovery.d.ts +27 -0
- package/dist/index.js +91 -73
- package/dist/shared/@ai-setting/{roy-agent-core-ygn5tzt1.js → roy-agent-core-06jakebr.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-m68z3pw1.js → roy-agent-core-084zthqx.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-cyefe8z5.js → roy-agent-core-2hkyp51n.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-029r8kdw.js → roy-agent-core-2pma868e.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-c7w2h47a.js → roy-agent-core-2veqhrxa.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-t64nmayv.js → roy-agent-core-32ck9rqt.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-m97jn2ra.js → roy-agent-core-33hn1beg.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-8p63s836.js → roy-agent-core-386wa4wy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-kq9pz2a7.js → roy-agent-core-48h4zh60.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-eanq305k.js → roy-agent-core-5bj0xfjk.js} +13 -27
- package/dist/shared/@ai-setting/{roy-agent-core-7q4wdze2.js → roy-agent-core-5mrynf9g.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-rt115qfc.js → roy-agent-core-6awgfh3x.js} +14 -4
- package/dist/shared/@ai-setting/{roy-agent-core-9zhkdg6w.js → roy-agent-core-6wxww10t.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-baaa4wtp.js → roy-agent-core-79gyka2q.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-ytd5eztz.js → roy-agent-core-7tce05jt.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-x6c45yqd.js → roy-agent-core-99nwgj84.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-9nvyffxg.js +414 -0
- package/dist/shared/@ai-setting/{roy-agent-core-e1w17tht.js → roy-agent-core-9qgrc9dy.js} +158 -158
- package/dist/shared/@ai-setting/{roy-agent-core-2ctyjy62.js → roy-agent-core-a08dpf71.js} +17 -2
- package/dist/shared/@ai-setting/{roy-agent-core-e250355z.js → roy-agent-core-a6cz4d23.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-tze5596n.js → roy-agent-core-anb53t3v.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-caevk7xd.js → roy-agent-core-arx535cs.js} +30 -8
- package/dist/shared/@ai-setting/{roy-agent-core-vh0qzb24.js → roy-agent-core-as0dd70m.js} +36 -15
- package/dist/shared/@ai-setting/{roy-agent-core-w93z6a42.js → roy-agent-core-bpvz1dqr.js} +12 -12
- package/dist/shared/@ai-setting/{roy-agent-core-ck60j1q9.js → roy-agent-core-bxkjk7zx.js} +2 -1
- package/dist/shared/@ai-setting/{roy-agent-core-hs41gx9w.js → roy-agent-core-c4t4y18j.js} +5 -5
- package/dist/shared/@ai-setting/{roy-agent-core-t4x089js.js → roy-agent-core-c57278kx.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-em4hks9t.js → roy-agent-core-c8xvy6hj.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-991pk4ss.js → roy-agent-core-cqpd41gf.js} +18 -16
- package/dist/shared/@ai-setting/{roy-agent-core-psg6f1v6.js → roy-agent-core-cxpgd415.js} +6 -6
- package/dist/shared/@ai-setting/{roy-agent-core-vgdhxbx3.js → roy-agent-core-dfqhc9ey.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-6bradb0j.js → roy-agent-core-fqandv0a.js} +9 -107
- package/dist/shared/@ai-setting/{roy-agent-core-en2xqxs9.js → roy-agent-core-fr296a53.js} +39 -14
- package/dist/shared/@ai-setting/{roy-agent-core-rcgvmtms.js → roy-agent-core-gc6wcd7z.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-7nb23tdd.js → roy-agent-core-gjsvehfs.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-0kn3zt1t.js → roy-agent-core-gtdtzbs7.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-84rs0c8d.js → roy-agent-core-gz2jnaan.js} +7 -7
- package/dist/shared/@ai-setting/{roy-agent-core-0yn7a78e.js → roy-agent-core-h3fwjbhp.js} +14 -14
- package/dist/shared/@ai-setting/{roy-agent-core-4096f575.js → roy-agent-core-hczj1ryh.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-syyw58p9.js → roy-agent-core-hfyxv2kx.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-d75t8gea.js → roy-agent-core-hwkc0bg2.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-vath15kt.js → roy-agent-core-ja4sr63d.js} +6 -6
- package/dist/shared/@ai-setting/roy-agent-core-jagkferh.js +16 -0
- package/dist/shared/@ai-setting/roy-agent-core-jm136jzh.js +99 -0
- package/dist/shared/@ai-setting/{roy-agent-core-14bq77wr.js → roy-agent-core-jw63js86.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-89sxsrc7.js → roy-agent-core-kmvw6b4v.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-47s81t6g.js → roy-agent-core-kvq4a4p6.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-c36335nw.js → roy-agent-core-m3w3ytxt.js} +15 -3
- package/dist/shared/@ai-setting/{roy-agent-core-64f22h1g.js → roy-agent-core-m880qz3y.js} +7 -1
- package/dist/shared/@ai-setting/{roy-agent-core-2fk8c9ax.js → roy-agent-core-mbwaxqs0.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-jjhw9am6.js → roy-agent-core-mkpsz128.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-20m8je6e.js → roy-agent-core-mrrv80jy.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-6q5m1qk5.js → roy-agent-core-nmn853z0.js} +333 -1183
- package/dist/shared/@ai-setting/roy-agent-core-p37kh0kt.js +155 -0
- package/dist/shared/@ai-setting/{roy-agent-core-08njdcpj.js → roy-agent-core-p6a4v4fq.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-gksw1gjb.js → roy-agent-core-p8rf4z89.js} +1 -1
- package/dist/shared/@ai-setting/roy-agent-core-pnj0zh25.js +0 -0
- package/dist/shared/@ai-setting/{roy-agent-core-q4gdfypk.js → roy-agent-core-prnry2mw.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-84xtww7d.js → roy-agent-core-qmqe8ds3.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-txwptxk1.js → roy-agent-core-sj4y3wdm.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-fbjd7bt6.js → roy-agent-core-th92f833.js} +64 -29
- package/dist/shared/@ai-setting/{roy-agent-core-yphwdm9x.js → roy-agent-core-v7mwj8eq.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-5f7myqnb.js → roy-agent-core-vvb4cyyy.js} +11 -5
- package/dist/shared/@ai-setting/{roy-agent-core-jjxdmedn.js → roy-agent-core-vwzan9v0.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-fw6k4w1h.js → roy-agent-core-w2ev3z5q.js} +12 -14
- package/dist/shared/@ai-setting/roy-agent-core-w2h6xt6k.js +473 -0
- package/dist/shared/@ai-setting/{roy-agent-core-n0p0hwgd.js → roy-agent-core-wzp4tbsn.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-ge87xbas.js → roy-agent-core-x1d6edkh.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-8bngppw0.js → roy-agent-core-ye4bfzqg.js} +13 -13
- package/dist/shared/@ai-setting/{roy-agent-core-geh6j7bw.js → roy-agent-core-zjgckbdd.js} +2 -2
- package/dist/shared/@ai-setting/{roy-agent-core-hefarcp0.js → roy-agent-core-zy8vkbnk.js} +1 -1
- package/dist/test-utils/child-process-mock.js +23 -0
- package/dist/utils/temp-file-manager/index.js +2 -2
- package/package.json +76 -1
- /package/dist/shared/@ai-setting/{roy-agent-core-3ztzc83c.js → roy-agent-core-5enxfga2.js} +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isToolUnavailableError,
|
|
3
3
|
truncateOutputInline
|
|
4
|
-
} from "./roy-agent-core-
|
|
4
|
+
} from "./roy-agent-core-w2ev3z5q.js";
|
|
5
5
|
import {
|
|
6
6
|
AgentRegistry
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-06jakebr.js";
|
|
8
8
|
import {
|
|
9
9
|
enqueueToAddFakeUserMessage
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-p8rf4z89.js";
|
|
11
11
|
import {
|
|
12
12
|
SessionMessageConverter
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-x1d6edkh.js";
|
|
14
14
|
import {
|
|
15
15
|
parseToolArgsStrict,
|
|
16
16
|
safeParseToolArgs,
|
|
17
17
|
withTimeout
|
|
18
|
-
} from "./roy-agent-core-
|
|
18
|
+
} from "./roy-agent-core-9qgrc9dy.js";
|
|
19
19
|
import {
|
|
20
20
|
getCurrentBgTaskId
|
|
21
21
|
} from "./roy-agent-core-c1v263jn.js";
|
|
@@ -31,20 +31,20 @@ import {
|
|
|
31
31
|
} from "./roy-agent-core-7hh0brvs.js";
|
|
32
32
|
import {
|
|
33
33
|
BaseComponent
|
|
34
|
-
} from "./roy-agent-core-
|
|
34
|
+
} from "./roy-agent-core-gtdtzbs7.js";
|
|
35
35
|
import {
|
|
36
36
|
globalHookManager,
|
|
37
37
|
init_global_hook_manager
|
|
38
|
-
} from "./roy-agent-core-
|
|
38
|
+
} from "./roy-agent-core-v7mwj8eq.js";
|
|
39
39
|
import {
|
|
40
40
|
init_context
|
|
41
|
-
} from "./roy-agent-core-
|
|
41
|
+
} from "./roy-agent-core-33hn1beg.js";
|
|
42
42
|
import {
|
|
43
43
|
getCurrentTaskId,
|
|
44
44
|
getEnvContext,
|
|
45
45
|
resolveEnvParentTaskId,
|
|
46
46
|
runWithEnvContextAsync
|
|
47
|
-
} from "./roy-agent-core-
|
|
47
|
+
} from "./roy-agent-core-hfyxv2kx.js";
|
|
48
48
|
import {
|
|
49
49
|
TracedAs,
|
|
50
50
|
agentRunParamFilter,
|
|
@@ -56,11 +56,11 @@ import {
|
|
|
56
56
|
recordSessionMessagesParamFilter,
|
|
57
57
|
toolExecParamFilter,
|
|
58
58
|
toolExecResultFilter
|
|
59
|
-
} from "./roy-agent-core-
|
|
59
|
+
} from "./roy-agent-core-386wa4wy.js";
|
|
60
60
|
import {
|
|
61
61
|
createLogger,
|
|
62
62
|
init_logger
|
|
63
|
-
} from "./roy-agent-core-
|
|
63
|
+
} from "./roy-agent-core-6awgfh3x.js";
|
|
64
64
|
import {
|
|
65
65
|
__legacyDecorateClassTS,
|
|
66
66
|
__require
|
|
@@ -1949,19 +1949,5 @@ function buildMultiBlockSystem(ctx) {
|
|
|
1949
1949
|
}
|
|
1950
1950
|
return messages;
|
|
1951
1951
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
llmComponent;
|
|
1955
|
-
config;
|
|
1956
|
-
constructor(_promptComponent, llmComponent, config) {
|
|
1957
|
-
this.llmComponent = llmComponent;
|
|
1958
|
-
this.config = {
|
|
1959
|
-
type: "summary",
|
|
1960
|
-
promptName: "session/compact",
|
|
1961
|
-
maxIterations: 1,
|
|
1962
|
-
model: undefined,
|
|
1963
|
-
...config
|
|
1964
|
-
};
|
|
1965
|
-
}
|
|
1966
|
-
}
|
|
1967
|
-
export { AgentComponentConfigSchema, AgentComponent, SummaryAgent };
|
|
1952
|
+
|
|
1953
|
+
export { parseToolList, composeToolOutputForLLM, toLLMMessage, AgentComponentConfigSchema, filterToolsByAgent, buildRunEnvContext, AgentComponent, buildMultiBlockSystem };
|
|
@@ -139,6 +139,12 @@ function isQuietMode() {
|
|
|
139
139
|
function setQuietMode(enabled) {
|
|
140
140
|
quietMode = enabled;
|
|
141
141
|
}
|
|
142
|
+
function isStdoutStrictMode() {
|
|
143
|
+
return stdoutStrictMode;
|
|
144
|
+
}
|
|
145
|
+
function setStdoutStrictMode(enabled) {
|
|
146
|
+
stdoutStrictMode = enabled;
|
|
147
|
+
}
|
|
142
148
|
function setConfigComponent(component) {
|
|
143
149
|
configComponentInstance = component;
|
|
144
150
|
}
|
|
@@ -339,8 +345,12 @@ class Logger {
|
|
|
339
345
|
const formatted = this.formatMessage(level, message, data);
|
|
340
346
|
this.writeToFile(formatted);
|
|
341
347
|
if (!isQuietMode()) {
|
|
342
|
-
|
|
343
|
-
|
|
348
|
+
if (stdoutStrictMode) {
|
|
349
|
+
console.error(formatted);
|
|
350
|
+
} else {
|
|
351
|
+
const consoleMethod = level === "error" ? console.error : level === "warn" ? console.warn : level === "info" ? console.log : console.debug;
|
|
352
|
+
consoleMethod(formatted);
|
|
353
|
+
}
|
|
344
354
|
}
|
|
345
355
|
}
|
|
346
356
|
debug(message, data) {
|
|
@@ -365,7 +375,7 @@ function createLogger(prefix) {
|
|
|
365
375
|
function getLogLevels() {
|
|
366
376
|
return ["debug", "info", "warn", "error"];
|
|
367
377
|
}
|
|
368
|
-
var configComponentInstance = null, quietMode = false, logDirOverride, levelPriority, loggerCache;
|
|
378
|
+
var configComponentInstance = null, quietMode = false, stdoutStrictMode = false, logDirOverride, levelPriority, loggerCache;
|
|
369
379
|
var init_logger = __esm(() => {
|
|
370
380
|
init_tracer_provider();
|
|
371
381
|
levelPriority = {
|
|
@@ -806,4 +816,4 @@ var init_tracer_provider = __esm(() => {
|
|
|
806
816
|
init_logger();
|
|
807
817
|
});
|
|
808
818
|
|
|
809
|
-
export { serialize, parse, propagation, init_propagation, SpanKind, SpanStatus, init_types, OTelTracerProvider, getTracerProvider, resetTracerProvider, setTracerProvider, exports_tracer_provider, init_tracer_provider, simplifyFilePath, isQuietMode, setQuietMode, setConfigComponent, getLogLevel, getLogFile, getLogDir, getMaxOutput, setLogDirOverride, getLogDirOverride, createLogger, getLogLevels, init_logger };
|
|
819
|
+
export { serialize, parse, propagation, init_propagation, SpanKind, SpanStatus, init_types, OTelTracerProvider, getTracerProvider, resetTracerProvider, setTracerProvider, exports_tracer_provider, init_tracer_provider, simplifyFilePath, isQuietMode, setQuietMode, isStdoutStrictMode, setStdoutStrictMode, setConfigComponent, getLogLevel, getCategoryLogLevel, getLogFile, getLogDir, getMaxOutput, setLogDirOverride, getLogDirOverride, createLogger, getLogLevels, init_logger };
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
TracedAs,
|
|
6
6
|
init_decorator
|
|
7
|
-
} from "./roy-agent-core-
|
|
7
|
+
} from "./roy-agent-core-386wa4wy.js";
|
|
8
8
|
import {
|
|
9
9
|
createLogger,
|
|
10
10
|
init_logger
|
|
11
|
-
} from "./roy-agent-core-
|
|
11
|
+
} from "./roy-agent-core-6awgfh3x.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-
|
|
9
|
+
} from "./roy-agent-core-gtdtzbs7.js";
|
|
10
10
|
import {
|
|
11
11
|
createLogger,
|
|
12
12
|
init_logger
|
|
13
|
-
} from "./roy-agent-core-
|
|
13
|
+
} from "./roy-agent-core-6awgfh3x.js";
|
|
14
14
|
|
|
15
15
|
// src/env/memory/types.ts
|
|
16
16
|
import { z } from "zod";
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeLarkAtMentions
|
|
3
|
+
} from "./roy-agent-core-m880qz3y.js";
|
|
4
|
+
import {
|
|
5
|
+
createLogger,
|
|
6
|
+
init_logger
|
|
7
|
+
} from "./roy-agent-core-6awgfh3x.js";
|
|
8
|
+
|
|
9
|
+
// src/env/error-reply.ts
|
|
10
|
+
init_logger();
|
|
11
|
+
import { spawn } from "node:child_process";
|
|
12
|
+
var logger = createLogger("env:error-reply");
|
|
13
|
+
var UPSTREAM_RETRY_PATTERNS = [
|
|
14
|
+
/failed after \d+ attempts/i,
|
|
15
|
+
/endpoint is unavailable/i,
|
|
16
|
+
/upstream request failed/i,
|
|
17
|
+
/rate.?limit/i,
|
|
18
|
+
/\b429\b/,
|
|
19
|
+
/\b50[0234]\b/,
|
|
20
|
+
/service (is )?(temporarily )?unavailable/i,
|
|
21
|
+
/\beconn(reset|refused|aborted)\b/i,
|
|
22
|
+
/socket hang up/i,
|
|
23
|
+
/fetch failed/i,
|
|
24
|
+
/network error/i,
|
|
25
|
+
/overloaded/i
|
|
26
|
+
];
|
|
27
|
+
var TIMEOUT_PATTERNS = [
|
|
28
|
+
/timeout/i,
|
|
29
|
+
/timed out/i,
|
|
30
|
+
/deadline exceeded/i,
|
|
31
|
+
/etimedout/i,
|
|
32
|
+
/aborted due to timeout/i
|
|
33
|
+
];
|
|
34
|
+
var TRANSPORT_ABORT_PATTERNS = [
|
|
35
|
+
/requestabortederror/i,
|
|
36
|
+
/econnaborted/i,
|
|
37
|
+
/connection (was )?(aborted|reset|closed)/i,
|
|
38
|
+
/premature close/i
|
|
39
|
+
];
|
|
40
|
+
var ABORT_PATTERNS = [
|
|
41
|
+
/\babort(?:ed|ing)?\b/i,
|
|
42
|
+
/operation was cancelled/i,
|
|
43
|
+
/operation was canceled/i,
|
|
44
|
+
/sigint/i,
|
|
45
|
+
/\binterrupted\b/i,
|
|
46
|
+
/exiting due to (signal|shutdown)/i
|
|
47
|
+
];
|
|
48
|
+
var CONTEXT_PATTERNS = [
|
|
49
|
+
/context threshold/i,
|
|
50
|
+
/context (window|length|limit)/i,
|
|
51
|
+
/token limit/i,
|
|
52
|
+
/maximum context/i,
|
|
53
|
+
/ctrieve\b/,
|
|
54
|
+
/CTX_001/
|
|
55
|
+
];
|
|
56
|
+
var ASK_USER_PATTERNS = [/__ASK_USER_ERROR__/];
|
|
57
|
+
function collectErrorText(error, depth = 0) {
|
|
58
|
+
const parts = [];
|
|
59
|
+
const push = (v) => {
|
|
60
|
+
if (typeof v === "string" && v.length > 0)
|
|
61
|
+
parts.push(v);
|
|
62
|
+
};
|
|
63
|
+
if (error === null || error === undefined)
|
|
64
|
+
return "";
|
|
65
|
+
if (typeof error === "string") {
|
|
66
|
+
push(error);
|
|
67
|
+
return parts.join(`
|
|
68
|
+
`);
|
|
69
|
+
}
|
|
70
|
+
if (typeof error !== "object") {
|
|
71
|
+
push(String(error));
|
|
72
|
+
return parts.join(`
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
const e = error;
|
|
76
|
+
push(e.name);
|
|
77
|
+
push(e.message);
|
|
78
|
+
for (const key of ["statusCode", "status", "code"]) {
|
|
79
|
+
const v = e[key];
|
|
80
|
+
if (typeof v === "number" || typeof v === "string")
|
|
81
|
+
push(String(v));
|
|
82
|
+
}
|
|
83
|
+
if (depth < 3) {
|
|
84
|
+
const nested = collectErrorText(e.lastError, depth + 1);
|
|
85
|
+
if (nested)
|
|
86
|
+
parts.push(nested);
|
|
87
|
+
if (Array.isArray(e.errors)) {
|
|
88
|
+
for (const inner of e.errors.slice(-3)) {
|
|
89
|
+
const s = collectErrorText(inner, depth + 1);
|
|
90
|
+
if (s)
|
|
91
|
+
parts.push(s);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const cause = collectErrorText(e.cause, depth + 1);
|
|
95
|
+
if (cause)
|
|
96
|
+
parts.push(cause);
|
|
97
|
+
}
|
|
98
|
+
return parts.join(`
|
|
99
|
+
`);
|
|
100
|
+
}
|
|
101
|
+
function truncate(text, max) {
|
|
102
|
+
if (text.length <= max)
|
|
103
|
+
return text;
|
|
104
|
+
return text.slice(0, max) + "…";
|
|
105
|
+
}
|
|
106
|
+
var FAILURE_RULES = [
|
|
107
|
+
{
|
|
108
|
+
id: "ask_user",
|
|
109
|
+
kind: "ask_user",
|
|
110
|
+
names: ["AskUserError"],
|
|
111
|
+
patterns: ASK_USER_PATTERNS,
|
|
112
|
+
notify: false,
|
|
113
|
+
title: "等待用户回答",
|
|
114
|
+
reason: "agent 正在等待用户回答,不是失败。",
|
|
115
|
+
retryable: false
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: "context_overflow",
|
|
119
|
+
kind: "context_overflow",
|
|
120
|
+
names: ["ContextError"],
|
|
121
|
+
patterns: CONTEXT_PATTERNS,
|
|
122
|
+
notify: true,
|
|
123
|
+
title: "上下文超出限制",
|
|
124
|
+
reason: "这次对话的上下文超出模型窗口,自动压缩也未能恢复。建议新开一个会话继续,或先让我压缩当前会话。",
|
|
125
|
+
retryable: false
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "timeout",
|
|
129
|
+
kind: "timeout",
|
|
130
|
+
names: ["TimeoutError"],
|
|
131
|
+
patterns: TIMEOUT_PATTERNS,
|
|
132
|
+
notify: true,
|
|
133
|
+
title: "执行超时",
|
|
134
|
+
reason: "本次执行等待响应超时(上游长时间未返回或网络卡住)。建议稍后重试,或把任务拆小一些。",
|
|
135
|
+
retryable: true
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "upstream_retry",
|
|
139
|
+
kind: "upstream_retry",
|
|
140
|
+
names: ["AI_RetryError", "RetryError", "APICallError", "AI_APICallError"],
|
|
141
|
+
patterns: UPSTREAM_RETRY_PATTERNS,
|
|
142
|
+
notify: true,
|
|
143
|
+
title: "模型服务暂时不可用(重试已用尽)",
|
|
144
|
+
reason: "调用模型时上游持续返回错误(如 429 限流 / 503 不可用),自动重试多次后仍未成功。" + "这不是你的操作问题,也不是仓库代码的问题 —— 稍后重发一次即可。",
|
|
145
|
+
retryable: true
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "upstream_aborted",
|
|
149
|
+
kind: "upstream_aborted",
|
|
150
|
+
names: ["RequestAbortedError"],
|
|
151
|
+
patterns: TRANSPORT_ABORT_PATTERNS,
|
|
152
|
+
unless: TIMEOUT_PATTERNS,
|
|
153
|
+
notify: true,
|
|
154
|
+
title: "与模型服务的连接中断",
|
|
155
|
+
reason: "请求在传输过程中被中断(连接被重置 / 代理提前关闭),不是你的操作问题。稍后重发一次即可。",
|
|
156
|
+
retryable: true
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: "aborted",
|
|
160
|
+
kind: "aborted",
|
|
161
|
+
names: ["AbortError", "AbortSignal"],
|
|
162
|
+
patterns: ABORT_PATTERNS,
|
|
163
|
+
unless: [...TIMEOUT_PATTERNS, ...TRANSPORT_ABORT_PATTERNS],
|
|
164
|
+
notify: true,
|
|
165
|
+
title: "执行被中断",
|
|
166
|
+
reason: "本次执行在完成前被中断(可能你手动取消了,或进程收到了停止信号)。你可以直接让我重新执行。",
|
|
167
|
+
retryable: true
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
var UNKNOWN_RULE = {
|
|
171
|
+
id: "unknown",
|
|
172
|
+
kind: "unknown",
|
|
173
|
+
notify: true,
|
|
174
|
+
title: "执行异常失败",
|
|
175
|
+
reason: "本次执行遇到了未预期的异常,已中止。你可以重试;如果持续失败,请把这条消息里的技术细节发我。",
|
|
176
|
+
retryable: true
|
|
177
|
+
};
|
|
178
|
+
function ruleMatches(rule, name, text) {
|
|
179
|
+
const lowered = name.toLowerCase();
|
|
180
|
+
const nameHit = rule.names?.some((n) => n.toLowerCase() === lowered) ?? false;
|
|
181
|
+
const patternHit = rule.patterns?.some((p) => p.test(text)) ?? false;
|
|
182
|
+
if (!nameHit && !patternHit)
|
|
183
|
+
return false;
|
|
184
|
+
if (rule.unless?.some((p) => p.test(text)))
|
|
185
|
+
return false;
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
function getFailureRuleIds() {
|
|
189
|
+
return [...FAILURE_RULES.map((r) => r.id), UNKNOWN_RULE.id];
|
|
190
|
+
}
|
|
191
|
+
function classifyReactFailure(error) {
|
|
192
|
+
const text = collectErrorText(error);
|
|
193
|
+
const name = error && typeof error === "object" ? String(error.name ?? "") : "";
|
|
194
|
+
const technical = text ? truncate(text.replace(/\s*\n\s*/g, " | "), 400) : undefined;
|
|
195
|
+
const rule = FAILURE_RULES.find((r) => ruleMatches(r, name, text)) ?? UNKNOWN_RULE;
|
|
196
|
+
return {
|
|
197
|
+
kind: rule.kind,
|
|
198
|
+
ruleId: rule.id,
|
|
199
|
+
title: rule.title,
|
|
200
|
+
reason: rule.reason,
|
|
201
|
+
retryable: rule.retryable,
|
|
202
|
+
notify: rule.notify,
|
|
203
|
+
technical
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
var MAX_QUERY_PREVIEW = 200;
|
|
207
|
+
function buildFailureReplyMarkdown(info, opts) {
|
|
208
|
+
const lines = [];
|
|
209
|
+
lines.push(`❌ **${info.title}**`);
|
|
210
|
+
lines.push("");
|
|
211
|
+
lines.push(info.reason);
|
|
212
|
+
const query = opts?.query?.trim();
|
|
213
|
+
if (query) {
|
|
214
|
+
lines.push("");
|
|
215
|
+
lines.push(`> 原始请求:${truncate(query.replace(/\s+/g, " "), MAX_QUERY_PREVIEW)}`);
|
|
216
|
+
}
|
|
217
|
+
if (info.retryable) {
|
|
218
|
+
lines.push("");
|
|
219
|
+
lines.push("**你可以:** 直接再发一次(重发即可,无需额外操作)。");
|
|
220
|
+
} else {
|
|
221
|
+
lines.push("");
|
|
222
|
+
lines.push("**你可以:** 新开一个会话,或先让我压缩当前会话。");
|
|
223
|
+
}
|
|
224
|
+
const technical = info.technical;
|
|
225
|
+
if (technical) {
|
|
226
|
+
lines.push("");
|
|
227
|
+
lines.push(`> 技术细节:${truncate(technical, 300)}`);
|
|
228
|
+
}
|
|
229
|
+
return lines.join(`
|
|
230
|
+
`);
|
|
231
|
+
}
|
|
232
|
+
function extractReplyChannelFromEvent(envEvent) {
|
|
233
|
+
if (!envEvent || typeof envEvent !== "object")
|
|
234
|
+
return;
|
|
235
|
+
const e = envEvent;
|
|
236
|
+
const candidates = [
|
|
237
|
+
e.metadata?.replyChannel,
|
|
238
|
+
e.payload?.replyChannel
|
|
239
|
+
];
|
|
240
|
+
for (const c of candidates) {
|
|
241
|
+
if (c && typeof c === "object") {
|
|
242
|
+
const ch = c;
|
|
243
|
+
if (ch.chatId || ch.messageId)
|
|
244
|
+
return ch;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
function isUsableChannel(ch) {
|
|
250
|
+
if (!ch)
|
|
251
|
+
return false;
|
|
252
|
+
if (!ch.chatId && !ch.messageId)
|
|
253
|
+
return false;
|
|
254
|
+
if (ch.type && !ch.type.toLowerCase().includes("lark"))
|
|
255
|
+
return false;
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
var repliedTriggers = new Map;
|
|
259
|
+
var CHAT_DEDUP_WINDOW_MS = 5 * 60000;
|
|
260
|
+
var MAX_DEDUP_ENTRIES = 1000;
|
|
261
|
+
function makeDedupKey(channel, info, explicit, now = Date.now()) {
|
|
262
|
+
if (explicit)
|
|
263
|
+
return explicit;
|
|
264
|
+
if (channel.messageId)
|
|
265
|
+
return `msg:${channel.messageId}`;
|
|
266
|
+
if (channel.chatId) {
|
|
267
|
+
const bucket = Math.floor(now / CHAT_DEDUP_WINDOW_MS);
|
|
268
|
+
return `chat:${channel.chatId}:${info.kind}:${bucket}`;
|
|
269
|
+
}
|
|
270
|
+
return "unknown";
|
|
271
|
+
}
|
|
272
|
+
function isDuplicate(key, now = Date.now()) {
|
|
273
|
+
const at = repliedTriggers.get(key);
|
|
274
|
+
if (at === undefined)
|
|
275
|
+
return false;
|
|
276
|
+
if (key.startsWith("chat:") && now - at >= CHAT_DEDUP_WINDOW_MS) {
|
|
277
|
+
repliedTriggers.delete(key);
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
function rememberTrigger(key, now = Date.now()) {
|
|
283
|
+
if (repliedTriggers.size >= MAX_DEDUP_ENTRIES) {
|
|
284
|
+
const oldest = repliedTriggers.keys().next().value;
|
|
285
|
+
if (oldest !== undefined)
|
|
286
|
+
repliedTriggers.delete(oldest);
|
|
287
|
+
}
|
|
288
|
+
repliedTriggers.set(key, now);
|
|
289
|
+
}
|
|
290
|
+
function __resetFailureReplyDedupForTest() {
|
|
291
|
+
repliedTriggers.clear();
|
|
292
|
+
}
|
|
293
|
+
var DEFAULT_REPLY_TIMEOUT_MS = 5000;
|
|
294
|
+
function spawnLarkReply(options) {
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
const { chatId, messageId, content, profile } = options;
|
|
297
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_REPLY_TIMEOUT_MS;
|
|
298
|
+
let settled = false;
|
|
299
|
+
let timer;
|
|
300
|
+
const finish = (err) => {
|
|
301
|
+
if (settled)
|
|
302
|
+
return;
|
|
303
|
+
settled = true;
|
|
304
|
+
if (timer)
|
|
305
|
+
clearTimeout(timer);
|
|
306
|
+
if (err)
|
|
307
|
+
reject(err);
|
|
308
|
+
else
|
|
309
|
+
resolve();
|
|
310
|
+
};
|
|
311
|
+
const normalizedContent = normalizeLarkAtMentions(content);
|
|
312
|
+
let args;
|
|
313
|
+
if (messageId) {
|
|
314
|
+
args = [
|
|
315
|
+
"im",
|
|
316
|
+
"+messages-reply",
|
|
317
|
+
"--message-id",
|
|
318
|
+
messageId,
|
|
319
|
+
"--markdown",
|
|
320
|
+
normalizedContent,
|
|
321
|
+
"--as",
|
|
322
|
+
"bot"
|
|
323
|
+
];
|
|
324
|
+
} else if (chatId) {
|
|
325
|
+
args = [
|
|
326
|
+
"im",
|
|
327
|
+
"+messages-send",
|
|
328
|
+
"--chat-id",
|
|
329
|
+
chatId,
|
|
330
|
+
"--markdown",
|
|
331
|
+
normalizedContent,
|
|
332
|
+
"--as",
|
|
333
|
+
"bot"
|
|
334
|
+
];
|
|
335
|
+
} else {
|
|
336
|
+
finish(new Error("No target specified for failure reply"));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (profile) {
|
|
340
|
+
args.unshift("--profile", profile);
|
|
341
|
+
}
|
|
342
|
+
let proc;
|
|
343
|
+
try {
|
|
344
|
+
proc = spawn("lark-cli", args, {
|
|
345
|
+
shell: false,
|
|
346
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
347
|
+
});
|
|
348
|
+
} catch (err) {
|
|
349
|
+
finish(err instanceof Error ? err : new Error(String(err)));
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
timer = setTimeout(() => {
|
|
353
|
+
try {
|
|
354
|
+
proc.kill("SIGKILL");
|
|
355
|
+
} catch {}
|
|
356
|
+
finish(new Error(`lark-cli timed out after ${timeoutMs}ms`));
|
|
357
|
+
}, timeoutMs);
|
|
358
|
+
timer.unref?.();
|
|
359
|
+
let stderr = "";
|
|
360
|
+
proc.stdout?.on("data", () => {});
|
|
361
|
+
proc.stderr?.on("data", (data) => {
|
|
362
|
+
stderr += data.toString();
|
|
363
|
+
});
|
|
364
|
+
proc.on("close", (code) => {
|
|
365
|
+
if (code === 0)
|
|
366
|
+
finish();
|
|
367
|
+
else
|
|
368
|
+
finish(new Error(`lark-cli exited with code ${code}: ${stderr}`));
|
|
369
|
+
});
|
|
370
|
+
proc.on("error", (err) => finish(err));
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
async function notifyReactFailure(options) {
|
|
374
|
+
const info = classifyReactFailure(options.error);
|
|
375
|
+
if (!info.notify) {
|
|
376
|
+
logger.debug(`[#4418] 命中规则 ${info.ruleId}(非失败),不发失败说明` + (options.sessionId ? ` (session=${options.sessionId})` : ""));
|
|
377
|
+
return { sent: false, kind: info.kind, info, skipped: "not_a_failure" };
|
|
378
|
+
}
|
|
379
|
+
const channel = (isUsableChannel(options.replyChannel) ? options.replyChannel : undefined) ?? extractReplyChannelFromEvent(options.envEvent);
|
|
380
|
+
if (!isUsableChannel(channel)) {
|
|
381
|
+
const hasTrigger = Boolean(options.envEvent);
|
|
382
|
+
const noChannelMsg = `[#4418] React 中断(${info.kind}/${info.ruleId})无法定位 replyChannel,` + `飞书端收不到失败说明` + (hasTrigger ? " —— triggerEvent 存在但缺少 metadata.replyChannel" : "(本地执行,无 triggerEvent)") + (options.sessionId ? ` (session=${options.sessionId})` : "");
|
|
383
|
+
if (hasTrigger)
|
|
384
|
+
logger.warn(noChannelMsg);
|
|
385
|
+
else
|
|
386
|
+
logger.debug(noChannelMsg);
|
|
387
|
+
return { sent: false, kind: info.kind, info, skipped: "no_channel" };
|
|
388
|
+
}
|
|
389
|
+
const dedupKey = makeDedupKey(channel, info, options.dedupKey);
|
|
390
|
+
if (isDuplicate(dedupKey)) {
|
|
391
|
+
logger.info(`[#4418] React 中断(${info.kind})已回复过 ${dedupKey},跳过`);
|
|
392
|
+
return { sent: false, kind: info.kind, info, skipped: "duplicate" };
|
|
393
|
+
}
|
|
394
|
+
rememberTrigger(dedupKey);
|
|
395
|
+
const content = buildFailureReplyMarkdown(info, { query: options.query });
|
|
396
|
+
try {
|
|
397
|
+
await spawnLarkReply({
|
|
398
|
+
chatId: channel.chatId,
|
|
399
|
+
messageId: channel.messageId,
|
|
400
|
+
content,
|
|
401
|
+
profile: channel.profile,
|
|
402
|
+
timeoutMs: options.replyTimeoutMs
|
|
403
|
+
});
|
|
404
|
+
logger.info(`[#4418] React 中断(${info.kind}/${info.ruleId})已回飞书 ` + `(${channel.messageId ?? channel.chatId})`);
|
|
405
|
+
return { sent: true, kind: info.kind, info };
|
|
406
|
+
} catch (err) {
|
|
407
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
408
|
+
repliedTriggers.delete(dedupKey);
|
|
409
|
+
logger.warn(`[#4418] React 中断(${info.kind}/${info.ruleId})回飞书失败(已忽略): ${errorMsg}`);
|
|
410
|
+
return { sent: false, kind: info.kind, info, error: errorMsg };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export { getFailureRuleIds, classifyReactFailure, buildFailureReplyMarkdown, __resetFailureReplyDedupForTest, notifyReactFailure };
|