niceeval 0.6.1 → 0.6.2

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 (296) hide show
  1. package/dist/agents/types.d.ts +67 -5
  2. package/dist/context/types.d.ts +32 -12
  3. package/dist/i18n/en.d.ts +54 -0
  4. package/dist/i18n/zh-CN.d.ts +55 -1
  5. package/dist/o11y/types.d.ts +16 -2
  6. package/dist/report/aggregate.d.ts +5 -3
  7. package/dist/report/aggregate.js +32 -5
  8. package/dist/report/built-ins/experiment-comparison.d.ts +39 -1
  9. package/dist/report/built-ins/experiment-comparison.js +116 -10
  10. package/dist/report/built-ins/index.d.ts +1 -0
  11. package/dist/report/built-ins/index.js +1 -1
  12. package/dist/report/components.d.ts +8 -2
  13. package/dist/report/components.js +3 -3
  14. package/dist/report/compute.d.ts +11 -18
  15. package/dist/report/compute.js +54 -34
  16. package/dist/report/flag.d.ts +16 -1
  17. package/dist/report/flag.js +19 -1
  18. package/dist/report/format.d.ts +16 -8
  19. package/dist/report/format.js +27 -12
  20. package/dist/report/index.d.ts +4 -3
  21. package/dist/report/index.js +5 -4
  22. package/dist/report/locale.d.ts +11 -2
  23. package/dist/report/locale.js +23 -5
  24. package/dist/report/metrics.d.ts +13 -1
  25. package/dist/report/metrics.js +65 -14
  26. package/dist/report/primitives.d.ts +6 -0
  27. package/dist/report/react/AttemptList.d.ts +2 -2
  28. package/dist/report/react/AttemptList.js +5 -6
  29. package/dist/report/react/EvalList.d.ts +1 -1
  30. package/dist/report/react/EvalList.js +0 -0
  31. package/dist/report/react/ExperimentComparison.d.ts +8 -0
  32. package/dist/report/react/ExperimentComparison.js +11 -0
  33. package/dist/report/react/ExperimentList.d.ts +2 -1
  34. package/dist/report/react/ExperimentList.js +8 -10
  35. package/dist/report/react/MetricScatter.js +5 -11
  36. package/dist/report/react/chart-math.d.ts +23 -6
  37. package/dist/report/react/chart-math.js +71 -19
  38. package/dist/report/react/fixtures.d.ts +3 -3
  39. package/dist/report/react/fixtures.js +21 -14
  40. package/dist/report/report.d.ts +5 -1
  41. package/dist/report/report.js +6 -2
  42. package/dist/report/text/faces.d.ts +1 -1
  43. package/dist/report/text/faces.js +42 -41
  44. package/dist/report/text/table.js +36 -5
  45. package/dist/report/types.d.ts +39 -21
  46. package/dist/results/types.d.ts +11 -0
  47. package/dist/runner/feedback/sink.d.ts +110 -0
  48. package/dist/runner/types.d.ts +513 -22
  49. package/dist/sandbox/docker.d.ts +23 -2
  50. package/dist/sandbox/e2b.d.ts +15 -1
  51. package/dist/sandbox/errors.d.ts +30 -3
  52. package/dist/sandbox/io-retry.d.ts +17 -0
  53. package/dist/sandbox/registry.d.ts +2 -0
  54. package/dist/sandbox/resolve.d.ts +18 -5
  55. package/dist/sandbox/retry.d.ts +11 -1
  56. package/dist/sandbox/types.d.ts +39 -5
  57. package/dist/sandbox/vercel.d.ts +7 -1
  58. package/dist/scoring/coverage.d.ts +30 -0
  59. package/dist/scoring/display.d.ts +21 -0
  60. package/dist/scoring/display.js +120 -0
  61. package/dist/scoring/types.d.ts +103 -20
  62. package/dist/shared/aggregate.d.ts +1 -0
  63. package/dist/shared/aggregate.js +3 -3
  64. package/dist/shared/types.d.ts +28 -0
  65. package/dist/tty-line.d.ts +0 -4
  66. package/dist/util.d.ts +23 -0
  67. package/docs-site/zh/concepts/adapter.mdx +22 -4
  68. package/docs-site/zh/concepts/experiment.mdx +1 -1
  69. package/docs-site/zh/concepts/overview.mdx +6 -6
  70. package/docs-site/zh/guides/agent-feedback-loop.mdx +28 -26
  71. package/docs-site/zh/guides/authoring.mdx +33 -0
  72. package/docs-site/zh/guides/ci-integration.mdx +23 -12
  73. package/docs-site/zh/guides/connect-your-agent.mdx +29 -3
  74. package/docs-site/zh/guides/custom-reports.mdx +29 -34
  75. package/docs-site/zh/guides/dataset-fanout.mdx +25 -3
  76. package/docs-site/zh/guides/debug-sandbox.mdx +57 -0
  77. package/docs-site/zh/guides/debugging.mdx +210 -0
  78. package/docs-site/zh/guides/experiments.mdx +10 -3
  79. package/docs-site/zh/guides/official-adapters.mdx +26 -2
  80. package/docs-site/zh/guides/publish-report.mdx +30 -16
  81. package/docs-site/zh/guides/report-components.mdx +42 -30
  82. package/docs-site/zh/guides/reporters.mdx +2 -2
  83. package/docs-site/zh/guides/results-data.mdx +17 -9
  84. package/docs-site/zh/guides/runner.mdx +17 -7
  85. package/docs-site/zh/guides/sandbox-agent.mdx +56 -7
  86. package/docs-site/zh/guides/sandbox-providers.mdx +257 -9
  87. package/docs-site/zh/guides/scoring-guide.mdx +4 -4
  88. package/docs-site/zh/guides/viewing-results.mdx +79 -36
  89. package/docs-site/zh/guides/write-experiment.mdx +5 -3
  90. package/docs-site/zh/guides/write-send.mdx +17 -1
  91. package/docs-site/zh/index.mdx +1 -1
  92. package/docs-site/zh/reference/builtin-agents.mdx +27 -0
  93. package/docs-site/zh/reference/capabilities.mdx +2 -2
  94. package/docs-site/zh/reference/cli.mdx +33 -7
  95. package/docs-site/zh/reference/define-agent.mdx +57 -4
  96. package/docs-site/zh/reference/define-config.mdx +1 -1
  97. package/docs-site/zh/reference/define-eval.mdx +42 -9
  98. package/docs-site/zh/reference/expect.mdx +26 -1
  99. package/package.json +5 -1
  100. package/src/agents/ai-sdk-otel.test.ts +1 -0
  101. package/src/agents/ai-sdk.test.ts +3 -0
  102. package/src/agents/ai-sdk.ts +3 -0
  103. package/src/agents/bub-install-spec.test.ts +34 -0
  104. package/src/agents/bub-install-spec.ts +32 -0
  105. package/src/agents/bub.ts +31 -32
  106. package/src/agents/claude-code.test.ts +130 -9
  107. package/src/agents/claude-code.ts +76 -4
  108. package/src/agents/codex.test.ts +189 -40
  109. package/src/agents/codex.ts +155 -14
  110. package/src/agents/coding-cli-versions.test.ts +15 -0
  111. package/src/agents/coding-cli-versions.ts +3 -0
  112. package/src/agents/index.ts +11 -0
  113. package/src/agents/langgraph.test.ts +204 -0
  114. package/src/agents/langgraph.ts +495 -0
  115. package/src/agents/marketplace.ts +85 -0
  116. package/src/agents/native-config.test.ts +179 -0
  117. package/src/agents/native-config.ts +267 -0
  118. package/src/agents/openai-compat.test.ts +1 -0
  119. package/src/agents/openclaw.test.ts +31 -0
  120. package/src/agents/openclaw.ts +171 -0
  121. package/src/agents/plugin-config.test.ts +1 -0
  122. package/src/agents/sdk-streams.test.ts +79 -0
  123. package/src/agents/sdk-streams.ts +55 -10
  124. package/src/agents/skills.test.ts +1 -0
  125. package/src/agents/streaming.test.ts +3 -9
  126. package/src/agents/types.ts +68 -5
  127. package/src/agents/ui-message-stream.test.ts +3 -0
  128. package/src/cli.ts +411 -108
  129. package/src/context/context.test.ts +51 -12
  130. package/src/context/context.ts +161 -29
  131. package/src/context/session.test.ts +1 -0
  132. package/src/context/session.ts +114 -6
  133. package/src/context/types.ts +30 -12
  134. package/src/define.test.ts +13 -8
  135. package/src/define.ts +25 -4
  136. package/src/expect/index.ts +53 -23
  137. package/src/i18n/en.ts +64 -2
  138. package/src/i18n/zh-CN.ts +65 -3
  139. package/src/o11y/cost.test.ts +1 -0
  140. package/src/o11y/execution-tree.test.ts +1 -20
  141. package/src/o11y/otlp/mappers/claude-code.test.ts +1 -0
  142. package/src/o11y/otlp/parse.test.ts +1 -0
  143. package/src/o11y/otlp/turn-otel.test.ts +1 -0
  144. package/src/o11y/parsers/bub.test.ts +1 -0
  145. package/src/o11y/parsers/claude-code.test.ts +1 -34
  146. package/src/o11y/parsers/openclaw.test.ts +154 -0
  147. package/src/o11y/parsers/openclaw.ts +310 -0
  148. package/src/o11y/prices.json +746 -311
  149. package/src/o11y/tool-names.test.ts +1 -0
  150. package/src/o11y/types.ts +16 -2
  151. package/src/report/aggregate.ts +34 -5
  152. package/src/report/built-in-user-parity.test.tsx +110 -153
  153. package/src/report/built-ins/experiment-comparison.tsx +173 -13
  154. package/src/report/built-ins/index.ts +6 -1
  155. package/src/report/components.tsx +9 -3
  156. package/src/report/compute.ts +70 -40
  157. package/src/report/dual-render.test.tsx +194 -67
  158. package/src/report/flag.ts +30 -2
  159. package/src/report/format.ts +35 -11
  160. package/src/report/index.ts +22 -4
  161. package/src/report/locale.ts +25 -5
  162. package/src/report/metrics.ts +67 -14
  163. package/src/report/primitives.tsx +6 -0
  164. package/src/report/react/AttemptList.tsx +6 -31
  165. package/src/report/react/EvalList.tsx +0 -0
  166. package/src/report/react/ExperimentComparison.tsx +68 -0
  167. package/src/report/react/ExperimentList.tsx +15 -9
  168. package/src/report/react/MetricScatter.tsx +12 -14
  169. package/src/report/react/chart-math.test.ts +85 -0
  170. package/src/report/react/chart-math.ts +101 -22
  171. package/src/report/react/enhance.js +33 -1
  172. package/src/report/react/fixtures.ts +24 -17
  173. package/src/report/react/render.test.tsx +9 -64
  174. package/src/report/react/styles.css +73 -2
  175. package/src/report/report.test.ts +306 -98
  176. package/src/report/report.ts +6 -2
  177. package/src/report/text/faces.ts +47 -43
  178. package/src/report/text/table.ts +42 -5
  179. package/src/report/types.ts +41 -21
  180. package/src/results/annotated-source.test.ts +62 -9
  181. package/src/results/annotated-source.ts +64 -6
  182. package/src/results/attempt-evidence.test.ts +9 -7
  183. package/src/results/attempt-evidence.ts +15 -8
  184. package/src/results/attempt-source.ts +6 -3
  185. package/src/results/copy.ts +145 -55
  186. package/src/results/host-equivalence.test.ts +8 -6
  187. package/src/results/index.ts +2 -0
  188. package/src/results/locator.test.ts +1 -22
  189. package/src/results/open.ts +7 -1
  190. package/src/results/publish.ts +149 -0
  191. package/src/results/results.test.ts +85 -51
  192. package/src/results/truncate.ts +90 -0
  193. package/src/results/types.ts +7 -0
  194. package/src/results/writer.ts +31 -13
  195. package/src/runner/attempt.test.ts +138 -7
  196. package/src/runner/attempt.ts +603 -104
  197. package/src/runner/discover.test.ts +47 -0
  198. package/src/runner/discover.ts +36 -2
  199. package/src/runner/eval-source.test.ts +1 -27
  200. package/src/runner/feedback/agent.test.ts +504 -0
  201. package/src/runner/feedback/agent.ts +409 -0
  202. package/src/runner/feedback/ci.test.ts +562 -0
  203. package/src/runner/feedback/ci.ts +401 -0
  204. package/src/runner/feedback/coordinator.test.ts +317 -0
  205. package/src/runner/feedback/coordinator.ts +397 -0
  206. package/src/runner/feedback/failure.ts +40 -0
  207. package/src/runner/feedback/human.test.ts +616 -0
  208. package/src/runner/feedback/human.ts +535 -0
  209. package/src/runner/feedback/index.ts +66 -0
  210. package/src/runner/feedback/io.ts +78 -0
  211. package/src/runner/feedback/profile.test.ts +50 -0
  212. package/src/runner/feedback/profile.ts +58 -0
  213. package/src/runner/feedback/reducer.test.ts +395 -0
  214. package/src/runner/feedback/reducer.ts +260 -0
  215. package/src/runner/feedback/renderer.ts +82 -0
  216. package/src/runner/feedback/sink.ts +203 -0
  217. package/src/runner/feedback/testing.ts +106 -0
  218. package/src/runner/ledger.test.ts +230 -0
  219. package/src/runner/ledger.ts +329 -0
  220. package/src/runner/report.test.ts +128 -3
  221. package/src/runner/report.ts +33 -9
  222. package/src/runner/reporters/artifacts.ts +8 -2
  223. package/src/runner/reporters/braintrust.test.ts +8 -7
  224. package/src/runner/reporters/braintrust.ts +9 -2
  225. package/src/runner/reporters/index.ts +2 -2
  226. package/src/runner/reporters/json.test.ts +162 -0
  227. package/src/runner/reporters/json.ts +35 -8
  228. package/src/runner/reporters/shared.ts +1 -5
  229. package/src/runner/run.test.ts +760 -3
  230. package/src/runner/run.ts +242 -36
  231. package/src/runner/sandbox-prep.ts +3 -42
  232. package/src/runner/timing.ts +158 -0
  233. package/src/runner/types.ts +518 -22
  234. package/src/sandbox/checkpoint.test.ts +55 -0
  235. package/src/sandbox/checkpoint.ts +29 -8
  236. package/src/sandbox/cli-commands.ts +407 -0
  237. package/src/sandbox/docker.ts +115 -16
  238. package/src/sandbox/e2b-agent-template.test.ts +56 -0
  239. package/src/sandbox/e2b-agent-template.ts +94 -0
  240. package/src/sandbox/e2b.ts +74 -9
  241. package/src/sandbox/errors.ts +111 -4
  242. package/src/sandbox/index.ts +2 -0
  243. package/src/sandbox/io-retry.test.ts +58 -0
  244. package/src/sandbox/io-retry.ts +45 -0
  245. package/src/sandbox/keep-registry.test.ts +86 -0
  246. package/src/sandbox/keep-registry.ts +142 -0
  247. package/src/sandbox/keep.ts +178 -0
  248. package/src/sandbox/paths.test.ts +1 -0
  249. package/src/sandbox/paths.ts +19 -8
  250. package/src/sandbox/registry.ts +20 -3
  251. package/src/sandbox/resolve.ts +76 -11
  252. package/src/sandbox/retry.test.ts +70 -0
  253. package/src/sandbox/retry.ts +46 -4
  254. package/src/sandbox/types.ts +44 -6
  255. package/src/sandbox/vercel.ts +43 -20
  256. package/src/scoring/collector.ts +60 -17
  257. package/src/scoring/coverage.ts +95 -0
  258. package/src/scoring/diff.ts +81 -0
  259. package/src/scoring/display.test.ts +121 -0
  260. package/src/scoring/display.ts +133 -0
  261. package/src/scoring/evidence.test.ts +189 -0
  262. package/src/scoring/judge.test.ts +142 -0
  263. package/src/scoring/judge.ts +15 -18
  264. package/src/scoring/scoped.ts +217 -50
  265. package/src/scoring/types.ts +117 -20
  266. package/src/scoring/verdict.ts +16 -4
  267. package/src/shared/aggregate.ts +3 -2
  268. package/src/shared/types.ts +31 -0
  269. package/src/show/compose.ts +2 -2
  270. package/src/show/index.ts +21 -1
  271. package/src/show/render.ts +619 -104
  272. package/src/show/show.test.ts +235 -19
  273. package/src/tty-line.ts +8 -26
  274. package/src/util.test.ts +1 -0
  275. package/src/util.ts +41 -0
  276. package/src/view/app/components/AttemptModal.tsx +153 -2
  277. package/src/view/app/components/CodeView.tsx +32 -11
  278. package/src/view/app/components/CopyControls.tsx +2 -2
  279. package/src/view/app/i18n.ts +6 -0
  280. package/src/view/app/lib/attempt-route.test.ts +1 -0
  281. package/src/view/app/lib/verdict.ts +7 -9
  282. package/src/view/artifact-serving.test.ts +2 -1
  283. package/src/view/client-dist/app.css +1 -1
  284. package/src/view/client-dist/app.js +17 -17
  285. package/src/view/data.test.ts +1 -0
  286. package/src/view/data.ts +11 -1
  287. package/src/view/index.ts +11 -0
  288. package/src/view/server.ts +2 -0
  289. package/src/view/styles.css +3 -0
  290. package/src/view/view-report.test.ts +6 -5
  291. package/src/runner/reporters/console.ts +0 -70
  292. package/src/runner/reporters/live.test.ts +0 -56
  293. package/src/runner/reporters/live.ts +0 -247
  294. package/src/runner/reporters/quiet.test.ts +0 -66
  295. package/src/runner/reporters/quiet.ts +0 -49
  296. package/src/runner/reporters/table.ts +0 -277
@@ -0,0 +1,15 @@
1
+ // cases: docs/engineering/unit-tests/adapters/cases.md
2
+ import { readFile } from "node:fs/promises";
3
+ import { describe, expect, it } from "vitest";
4
+ import {
5
+ DEFAULT_CLAUDE_CODE_CLI_VERSION,
6
+ DEFAULT_CODEX_CLI_VERSION,
7
+ } from "./coding-cli-versions.ts";
8
+
9
+ describe("official coding-agent versions", () => {
10
+ it("keeps the non-TypeScript Docker recipe in sync", async () => {
11
+ const dockerfile = await readFile(new URL("../../sandbox/docker/Dockerfile", import.meta.url), "utf8");
12
+ expect(dockerfile).toContain(`ARG CODEX_VERSION=${DEFAULT_CODEX_CLI_VERSION}`);
13
+ expect(dockerfile).toContain(`ARG CLAUDE_CODE_VERSION=${DEFAULT_CLAUDE_CODE_CLI_VERSION}`);
14
+ });
15
+ });
@@ -0,0 +1,3 @@
1
+ /** Coding-agent CLI versions used by runtime fallback installs and official sandbox recipes. */
2
+ export const DEFAULT_CODEX_CLI_VERSION = "0.144.1";
3
+ export const DEFAULT_CLAUDE_CODE_CLI_VERSION = "2.1.207";
@@ -4,6 +4,11 @@ export { defineAgent, defineSandboxAgent } from "../define.ts";
4
4
  export { shared } from "./shared.ts";
5
5
  export type { Shared } from "./shared.ts";
6
6
 
7
+ // 证据覆盖声明:官方 SDK 适配器声明全通道 complete 用 completeCoverage;
8
+ // 手写映射按实际情况声明(见 docs/feature/adapters/architecture/evidence.md)。
9
+ export { completeCoverage } from "../scoring/coverage.ts";
10
+ export type { CoverageStatus, CoverageDeclaration, EvidenceCoverage } from "../types.ts";
11
+
7
12
  // span → canonical GenAI 归一(只服务瀑布图,不喂断言)。私有埋点写自己的 spanMapper 时用:
8
13
  // tagSpan 把判定写回 span(原属性只增不改),heuristicTag 是通用兜底判定;mapCodexSpans 是
9
14
  // 现成的参考实现(无侵入接 codex 后端时直接声明 `spanMapper: mapCodexSpans`)。
@@ -43,6 +48,10 @@ export type {
43
48
  CodexThreadStream,
44
49
  } from "./sdk-streams.ts";
45
50
 
51
+ // LangGraph 官方事件流转换器(不绑定 transport,不提供 langGraphAgent 工厂)。
52
+ export { fromLangGraphEvents } from "./langgraph.ts";
53
+ export type { LangGraphEventLike, LangGraphContentBlockLike, LangGraphStream } from "./langgraph.ts";
54
+
46
55
  // 通用「拼装方式」件:逐帧驱动循环、逐 token/参数增量累加器。见 docs-site/zh/guides/write-send.mdx——
47
56
  // 这些和任何具体协议无关,自己写 adapter 时优先拿这些拼,只有 transport(怎么发)与
48
57
  // 「帧类型 → 操作」这张映射表才是真正要手写的。会话续接与 HITL 停轮现场不再是可选件,
@@ -71,9 +80,11 @@ export { BUILTIN_AGENTS } from "./builtin.ts";
71
80
  export { claudeCodeAgent } from "./claude-code.ts";
72
81
  export { codexAgent } from "./codex.ts";
73
82
  export { bubAgent } from "./bub.ts";
83
+ export { openClawAgent } from "./openclaw.ts";
74
84
  export type { ClaudeCodeConfig, ClaudeCodePluginSpec } from "./claude-code.ts";
75
85
  export type { CodexConfig, CodexPluginSpec } from "./codex.ts";
76
86
  export type { BubConfig, PythonPluginSpec } from "./bub.ts";
87
+ export type { OpenClawConfig } from "./openclaw.ts";
77
88
 
78
89
  // 安装 manifest 的落点:adapter 写(shared.writeAgentSetup),运行器读并抬成 attempt artifact。
79
90
  export { AGENT_SETUP_MANIFEST_PATH } from "./manifest.ts";
@@ -0,0 +1,204 @@
1
+ // cases: docs/engineering/unit-tests/adapters/cases.md
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ import { fromLangGraphEvents } from "./langgraph.ts";
5
+
6
+ describe("fromLangGraphEvents", () => {
7
+ it("messages+tools 全链:content blocks → 事件,tools started/finished 按 call id 配对,usage 在 finish 上", () => {
8
+ const s = fromLangGraphEvents();
9
+
10
+ // messages finish:reasoning / text / tool_call blocks 按原始顺序落事件
11
+ expect(
12
+ s.add({
13
+ channel: "messages",
14
+ event: "finish",
15
+ data: {
16
+ message: {
17
+ role: "assistant",
18
+ content: [
19
+ { type: "reasoning", reasoning: "先查天气" },
20
+ { type: "text", text: "我来查一下" },
21
+ { type: "tool_call", id: "call_1", name: "get_weather", args: { city: "北京" } },
22
+ ],
23
+ usage_metadata: { input_tokens: 100, output_tokens: 20 },
24
+ },
25
+ },
26
+ }),
27
+ ).toEqual([
28
+ { type: "thinking", text: "先查天气" },
29
+ { type: "message", role: "assistant", text: "我来查一下" },
30
+ { type: "action.called", callId: "call_1", name: "get_weather", input: { city: "北京" }, tool: "unknown" },
31
+ ]);
32
+ expect(s.usage).toEqual({ inputTokens: 100, outputTokens: 20, requests: 1 });
33
+
34
+ // tools/started 描述同一次调用:按 call ID 去重,不重发 action.called
35
+ expect(
36
+ s.add({ channel: "tools", event: "started", data: { id: "call_1", name: "get_weather", input: { city: "北京" } } }),
37
+ ).toEqual([]);
38
+
39
+ expect(s.add({ channel: "tools", event: "finished", data: { id: "call_1", output: { temp: 21 } } })).toEqual([
40
+ { type: "action.result", callId: "call_1", output: { temp: 21 }, status: "completed" },
41
+ ]);
42
+
43
+ expect(s.add({ channel: "lifecycle", event: "completed" })).toEqual([]);
44
+ expect(s.status).toBe("completed");
45
+ });
46
+
47
+ it("messages partial(逐 token 增量)整个忽略;user 消息也落 message 事件", () => {
48
+ const s = fromLangGraphEvents();
49
+ expect(s.add({ channel: "messages", event: "partial", data: { message: { role: "assistant", content: "我" } } })).toEqual([]);
50
+ expect(s.add({ channel: "messages", event: "finish", data: { message: { role: "user", content: "东京天气" } } })).toEqual([
51
+ { type: "message", role: "user", text: "东京天气" },
52
+ ]);
53
+ expect(s.usage).toBeUndefined(); // 协议没报 usage 就不编造
54
+ });
55
+
56
+ it("tools/started 单独出现也成对;error → failed,markRejected 后 → rejected", () => {
57
+ const s = fromLangGraphEvents();
58
+ expect(s.add({ channel: "tools", event: "started", data: { id: "c1", name: "search_docs", input: { q: "x" } } })).toEqual([
59
+ { type: "action.called", callId: "c1", name: "search_docs", input: { q: "x" }, tool: "unknown" },
60
+ ]);
61
+ expect(s.add({ channel: "tools", event: "error", data: { id: "c1", error: "boom" } })).toEqual([
62
+ { type: "action.result", callId: "c1", output: "boom", status: "failed" },
63
+ ]);
64
+
65
+ s.add({ channel: "tools", event: "started", data: { id: "c2", name: "send_email", input: {} } });
66
+ s.markRejected("c2");
67
+ expect(s.add({ channel: "tools", event: "error", data: { id: "c2", error: "denied" } })).toEqual([
68
+ { type: "action.result", callId: "c2", output: "denied", status: "rejected" },
69
+ ]);
70
+ });
71
+
72
+ it("interrupt → input.requested + waiting;HITL 请求形状映射 action/input/display/options", () => {
73
+ const s = fromLangGraphEvents();
74
+ const events = s.add({
75
+ channel: "lifecycle",
76
+ event: "interrupted",
77
+ data: {
78
+ interrupts: [
79
+ {
80
+ id: "int_1",
81
+ value: {
82
+ action_request: { action: "send_email", args: { to: "a@b.c" } },
83
+ description: "需要人工批准发送邮件",
84
+ config: { allow_accept: true, allow_ignore: true },
85
+ },
86
+ },
87
+ ],
88
+ },
89
+ });
90
+ expect(events).toEqual([
91
+ {
92
+ type: "input.requested",
93
+ request: {
94
+ id: "int_1",
95
+ action: "send_email",
96
+ input: { to: "a@b.c" },
97
+ display: "需要人工批准发送邮件",
98
+ options: [{ id: "accept" }, { id: "ignore" }],
99
+ },
100
+ },
101
+ ]);
102
+ expect(s.status).toBe("waiting");
103
+
104
+ // 同一 interrupt 也从 input 通道到达:按 id 去重,只产一条请求事件
105
+ expect(s.add({ channel: "input", data: { id: "int_1", value: "approve?" } })).toEqual([]);
106
+ });
107
+
108
+ it("input 通道的字符串 interrupt value → prompt", () => {
109
+ const s = fromLangGraphEvents();
110
+ expect(s.add({ channel: "input", data: { id: "q1", value: "要继续吗?" } })).toEqual([
111
+ { type: "input.requested", request: { id: "q1", prompt: "要继续吗?" } },
112
+ ]);
113
+ });
114
+
115
+ it("lifecycle failed → status failed + error 事件", () => {
116
+ const s = fromLangGraphEvents();
117
+ expect(s.add({ channel: "lifecycle", event: "failed", data: { error: { message: "graph exploded" } } })).toEqual([
118
+ { type: "error", message: "graph exploded" },
119
+ ]);
120
+ expect(s.status).toBe("failed");
121
+ });
122
+
123
+ it("subgraph namespace → subagent 层级:首见补 called,该层 lifecycle 闭合成 completed", () => {
124
+ const s = fromLangGraphEvents();
125
+
126
+ // 嵌套 namespace 的首个事件:自外向内逐级补 subagent.called(段内 : 后缀不进展示名)
127
+ const events = s.add({
128
+ channel: "tools",
129
+ event: "started",
130
+ namespace: ["research:ckpt-1", "web:ckpt-2"],
131
+ data: { id: "t1", name: "fetch_page", input: { url: "https://x" } },
132
+ });
133
+ expect(events).toEqual([
134
+ { type: "subagent.called", callId: "research:ckpt-1", name: "research" },
135
+ { type: "subagent.called", callId: "research:ckpt-1/web:ckpt-2", name: "web" },
136
+ { type: "action.called", callId: "t1", name: "fetch_page", input: { url: "https://x" }, tool: "unknown" },
137
+ ]);
138
+
139
+ // 内层 lifecycle completed 只闭合内层
140
+ expect(s.add({ channel: "lifecycle", event: "completed", namespace: ["research:ckpt-1", "web:ckpt-2"] })).toEqual([
141
+ { type: "subagent.completed", callId: "research:ckpt-1/web:ckpt-2", status: "completed" },
142
+ ]);
143
+
144
+ // 根图 completed:仍未闭合的层级一起闭合
145
+ expect(s.add({ channel: "lifecycle", event: "completed" })).toEqual([
146
+ { type: "subagent.completed", callId: "research:ckpt-1", status: "completed" },
147
+ ]);
148
+ expect(s.status).toBe("completed");
149
+ });
150
+
151
+ it("subgraph lifecycle failed 闭合成 failed,并先闭合更深的打开层级", () => {
152
+ const s = fromLangGraphEvents();
153
+ s.add({ channel: "messages", event: "finish", namespace: ["a", "b"], data: { message: { role: "assistant", content: "hi" } } });
154
+ expect(s.add({ channel: "lifecycle", event: "failed", namespace: ["a"], data: { error: "sub failed" } })).toEqual([
155
+ { type: "subagent.completed", callId: "a/b", status: "failed" },
156
+ { type: "subagent.completed", callId: "a", status: "failed" },
157
+ ]);
158
+ });
159
+
160
+ it("seq 乱序帧:超前暂存,缺口补齐按 seq 顺序放出;落后的重复帧丢弃", () => {
161
+ const s = fromLangGraphEvents();
162
+ const msg = (seq: number, text: string) => ({
163
+ seq,
164
+ channel: "messages" as const,
165
+ event: "finish",
166
+ data: { message: { role: "assistant", content: text } },
167
+ });
168
+
169
+ expect(s.add(msg(1, "一"))).toEqual([{ type: "message", role: "assistant", text: "一" }]);
170
+ // seq 3 超前:暂存
171
+ expect(s.add(msg(3, "三"))).toEqual([]);
172
+ // seq 2 补上缺口:2、3 按协议顺序一起放出
173
+ expect(s.add(msg(2, "二"))).toEqual([
174
+ { type: "message", role: "assistant", text: "二" },
175
+ { type: "message", role: "assistant", text: "三" },
176
+ ]);
177
+ // 重连补发的旧帧(seq 已消费):丢弃
178
+ expect(s.add(msg(2, "二"))).toEqual([]);
179
+ });
180
+
181
+ it("end() 放出 seq 缺口后仍压着的乱序帧", () => {
182
+ const s = fromLangGraphEvents();
183
+ const msg = (seq: number, text: string) => ({
184
+ seq,
185
+ channel: "messages" as const,
186
+ event: "finish",
187
+ data: { message: { role: "assistant", content: text } },
188
+ });
189
+ s.add(msg(1, "一"));
190
+ expect(s.add(msg(4, "四"))).toEqual([]); // seq 2、3 永远没来
191
+ expect(s.add(msg(3, "三"))).toEqual([]);
192
+ expect(s.end()).toEqual([
193
+ { type: "message", role: "assistant", text: "三" },
194
+ { type: "message", role: "assistant", text: "四" },
195
+ ]);
196
+ });
197
+
198
+ it("values / updates 等其它通道与无 channel 帧返回 []", () => {
199
+ const s = fromLangGraphEvents();
200
+ expect(s.add({ channel: "values", data: { messages: [] } })).toEqual([]);
201
+ expect(s.add({ channel: "updates", data: {} })).toEqual([]);
202
+ expect(s.add({ data: {} })).toEqual([]);
203
+ });
204
+ });