@ftai/dsh-plugin-acn 0.0.0-stage → 0.1.1

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 (276) hide show
  1. package/CHANGELOG.md +90 -0
  2. package/LICENSE-APACHE +201 -0
  3. package/LICENSE-MIT +19 -0
  4. package/README.md +82 -2
  5. package/README_EN.md +83 -0
  6. package/cordis.patch.yml +29 -0
  7. package/docs/acn-compat.md +33 -0
  8. package/docs/architecture.md +130 -0
  9. package/docs/assets/acn-claim-reuse.png +0 -0
  10. package/docs/assets/activity-view.png +0 -0
  11. package/docs/assets/install-package.png +0 -0
  12. package/docs/assets/knowledge-model.png +0 -0
  13. package/docs/assets/knowledge-view.png +0 -0
  14. package/docs/assets/personal-configuration.png +0 -0
  15. package/docs/assets/session-upstream.png +0 -0
  16. package/docs/assets/upstream-settings.png +0 -0
  17. package/docs/assets/upstream-team.png +0 -0
  18. package/docs/command-reference.md +201 -0
  19. package/docs/config.md +253 -0
  20. package/docs/development.md +197 -0
  21. package/docs/dsh-compat.md +59 -0
  22. package/docs/index.md +16 -0
  23. package/docs/outstanding-issues.md +61 -0
  24. package/docs/user_guide.md +185 -0
  25. package/icon.svg +8 -0
  26. package/lib/activities-B8U-iW4-.js +407 -0
  27. package/lib/alignment-CwH0nBf-.js +80 -0
  28. package/lib/auth-DFI9yowX.js +71 -0
  29. package/lib/checkpoint-CPFPOxBM.js +188 -0
  30. package/lib/checkpoint-c7aI4D-X.js +318 -0
  31. package/lib/claim-DOAGe8ZK.js +168 -0
  32. package/lib/client.js +18417 -0
  33. package/lib/deliver-C-dmhkfm.js +168 -0
  34. package/lib/delivery-status-M7-Rwoyj.js +89 -0
  35. package/lib/dispute-CtrInHzf.js +20 -0
  36. package/lib/disputes-ByEmi43j.js +51 -0
  37. package/lib/dream-agent-BVqxbKFc.js +249 -0
  38. package/lib/dream.js +4 -0
  39. package/lib/effects-DX1iy6FM.js +268 -0
  40. package/lib/errors-Bp_2WXBr.js +19 -0
  41. package/lib/errors-pPumDOGD.js +18 -0
  42. package/lib/evidence-store-DW7kj20i.js +1030 -0
  43. package/lib/formation-D4LO31WW.js +187 -0
  44. package/lib/formation-replay-Bf4TSBiz.js +87 -0
  45. package/lib/formation.js +9 -0
  46. package/lib/history-DPMHX3ZE.js +214 -0
  47. package/lib/inbox-2CugZZQm.js +188 -0
  48. package/lib/inbox-DFtE2fOp.js +71 -0
  49. package/lib/inbox.js +3 -0
  50. package/lib/index.js +1373 -0
  51. package/lib/lock-DbmlKOoX.js +332 -0
  52. package/lib/pages-BEWC3kmZ.js +51 -0
  53. package/lib/paths-B7NI9Ano.js +157 -0
  54. package/lib/plugins/commands.js +590 -0
  55. package/lib/plugins/dream.js +66 -0
  56. package/lib/plugins/formation.js +66 -0
  57. package/lib/plugins/inbox.js +53 -0
  58. package/lib/plugins/knowledge.js +1109 -0
  59. package/lib/plugins/prompt.js +102 -0
  60. package/lib/plugins/tools.js +280 -0
  61. package/lib/policy-DnyHh7Bl.js +16 -0
  62. package/lib/prepare-CGXwBEcu.js +134 -0
  63. package/lib/protocol.js +8 -0
  64. package/lib/queue-M917xHPS.js +153 -0
  65. package/lib/regular-file-BFpqMoub.js +136 -0
  66. package/lib/render-CJaVcKKC.js +48 -0
  67. package/lib/reported-sets-DdEKdeVb.js +122 -0
  68. package/lib/revision-DeoL_IUN.js +11 -0
  69. package/lib/scheduler-BfJSY1eq.js +64 -0
  70. package/lib/service-BPwaZzFF.js +1106 -0
  71. package/lib/service-BQaszW_v.js +344 -0
  72. package/lib/service-BhniAHLo.js +305 -0
  73. package/lib/service-C2lXoygJ.js +505 -0
  74. package/lib/session-binding-zCSuizHs.js +342 -0
  75. package/lib/session-state-CYqUhC95.js +38 -0
  76. package/lib/sessions-C2xuPFQv.js +218 -0
  77. package/lib/store.js +16 -0
  78. package/lib/structured-C9byFuzm.js +453 -0
  79. package/lib/subagent-yJsFxHmH.js +9 -0
  80. package/lib/team.js +3 -0
  81. package/lib/tool-schema-3b4gH1zf.js +28 -0
  82. package/lib/trace-Da0RnL5R.js +14 -0
  83. package/lib/traces-CHBo8y1z.js +11 -0
  84. package/lib/types/activities.d.ts +73 -0
  85. package/lib/types/advanced-configuration.d.ts +11 -0
  86. package/lib/types/client/ActivityCard.d.ts +14 -0
  87. package/lib/types/client/ActivityDetails.d.ts +18 -0
  88. package/lib/types/client/AdvancedPreferences.d.ts +8 -0
  89. package/lib/types/client/BlankCommandFeedback.d.ts +10 -0
  90. package/lib/types/client/ComposerMenu.d.ts +24 -0
  91. package/lib/types/client/ConfigurationPage.d.ts +11 -0
  92. package/lib/types/client/ConnectionCheckDialog.d.ts +12 -0
  93. package/lib/types/client/KnowledgeDetail.d.ts +6 -0
  94. package/lib/types/client/KnowledgeDirectoryField.d.ts +11 -0
  95. package/lib/types/client/KnowledgePanel.d.ts +12 -0
  96. package/lib/types/client/KnowledgeReference.d.ts +13 -0
  97. package/lib/types/client/SessionToolbar.d.ts +16 -0
  98. package/lib/types/client/SettingsToast.d.ts +3 -0
  99. package/lib/types/client/SourceSessionLink.d.ts +16 -0
  100. package/lib/types/client/TeamCredentialField.d.ts +16 -0
  101. package/lib/types/client/TeamSettingsPage.d.ts +28 -0
  102. package/lib/types/client/configuration-errors.d.ts +2 -0
  103. package/lib/types/client/interaction-styles.d.ts +1 -0
  104. package/lib/types/client/interaction-ui.d.ts +30 -0
  105. package/lib/types/client/knowledge-labels.d.ts +5 -0
  106. package/lib/types/client/locales.d.ts +51 -0
  107. package/lib/types/commands/claim.d.ts +4 -0
  108. package/lib/types/commands/import.d.ts +10 -0
  109. package/lib/types/commands/status.d.ts +5 -0
  110. package/lib/types/config.d.ts +111 -0
  111. package/lib/types/configuration.d.ts +235 -0
  112. package/lib/types/credentials.d.ts +59 -0
  113. package/lib/types/dream/audit.d.ts +4 -0
  114. package/lib/types/dream/autonomous.d.ts +185 -0
  115. package/lib/types/dream/candidates.d.ts +34 -0
  116. package/lib/types/dream/checkpoint.d.ts +35 -0
  117. package/lib/types/dream/evidence-files.d.ts +10 -0
  118. package/lib/types/dream/evidence-store.d.ts +103 -0
  119. package/lib/types/dream/evidence.d.ts +30 -0
  120. package/lib/types/dream/index.d.ts +10 -0
  121. package/lib/types/dream/plan.d.ts +18 -0
  122. package/lib/types/dream/preservation.d.ts +6 -0
  123. package/lib/types/dream/review.d.ts +10 -0
  124. package/lib/types/dream/schema.d.ts +1475 -0
  125. package/lib/types/dream/service.d.ts +56 -0
  126. package/lib/types/dream/sync.d.ts +147 -0
  127. package/lib/types/dsh-adapter/configuration-remote.d.ts +1 -0
  128. package/lib/types/dsh-adapter/configuration-service.d.ts +28 -0
  129. package/lib/types/dsh-adapter/dream-agent.d.ts +4 -0
  130. package/lib/types/dsh-adapter/dream-evidence.d.ts +3 -0
  131. package/lib/types/dsh-adapter/formation-archive.d.ts +3 -0
  132. package/lib/types/dsh-adapter/formation-replay.d.ts +5 -0
  133. package/lib/types/dsh-adapter/formation.d.ts +4 -0
  134. package/lib/types/dsh-adapter/interaction-service.d.ts +13 -0
  135. package/lib/types/dsh-adapter/knowledge-paths.d.ts +3 -0
  136. package/lib/types/dsh-adapter/llm.d.ts +10 -0
  137. package/lib/types/dsh-adapter/project-upstream.d.ts +4 -0
  138. package/lib/types/dsh-adapter/runtime-pool.d.ts +110 -0
  139. package/lib/types/dsh-adapter/session-binding.d.ts +43 -0
  140. package/lib/types/dsh-adapter/source-sessions.d.ts +3 -0
  141. package/lib/types/dsh-adapter/team-credentials.d.ts +5 -0
  142. package/lib/types/dsh-adapter/tool-schema.d.ts +4 -0
  143. package/lib/types/dsh-adapter/tools.d.ts +5 -0
  144. package/lib/types/formation/capture.d.ts +19 -0
  145. package/lib/types/formation/checkpoint.d.ts +136 -0
  146. package/lib/types/formation/index.d.ts +10 -0
  147. package/lib/types/formation/prepare.d.ts +16 -0
  148. package/lib/types/formation/schema.d.ts +45 -0
  149. package/lib/types/formation/service.d.ts +58 -0
  150. package/lib/types/formation/transcript.d.ts +75 -0
  151. package/lib/types/formation/triggers.d.ts +3 -0
  152. package/lib/types/inbox/cascade.d.ts +3 -0
  153. package/lib/types/inbox/effects.d.ts +275 -0
  154. package/lib/types/inbox/index.d.ts +5 -0
  155. package/lib/types/inbox/prepare.d.ts +380 -0
  156. package/lib/types/inbox/service.d.ts +26 -0
  157. package/lib/types/inbox/sync.d.ts +9 -0
  158. package/lib/types/index.d.ts +1 -0
  159. package/lib/types/interaction-messages.d.ts +69 -0
  160. package/lib/types/interaction.d.ts +541 -0
  161. package/lib/types/knowledge/alignment.d.ts +49 -0
  162. package/lib/types/knowledge/catalog.d.ts +5 -0
  163. package/lib/types/knowledge/changes.d.ts +32 -0
  164. package/lib/types/knowledge/disputes.d.ts +3 -0
  165. package/lib/types/knowledge/errors.d.ts +9 -0
  166. package/lib/types/knowledge/ordering.d.ts +7 -0
  167. package/lib/types/knowledge/pages.d.ts +7 -0
  168. package/lib/types/knowledge/safety.d.ts +2 -0
  169. package/lib/types/knowledge/service.d.ts +52 -0
  170. package/lib/types/knowledge/sessions.d.ts +59 -0
  171. package/lib/types/knowledge/sources.d.ts +2 -0
  172. package/lib/types/knowledge/timestamps.d.ts +1 -0
  173. package/lib/types/knowledge/types.d.ts +84 -0
  174. package/lib/types/llm/response.d.ts +1 -0
  175. package/lib/types/llm/structured.d.ts +27 -0
  176. package/lib/types/local-name.d.ts +1 -0
  177. package/lib/types/plugins/client.d.ts +9 -0
  178. package/lib/types/plugins/commands.d.ts +11 -0
  179. package/lib/types/plugins/configuration.d.ts +8 -0
  180. package/lib/types/plugins/dream.d.ts +16 -0
  181. package/lib/types/plugins/formation.d.ts +16 -0
  182. package/lib/types/plugins/inbox.d.ts +16 -0
  183. package/lib/types/plugins/knowledge.d.ts +19 -0
  184. package/lib/types/plugins/prompt.d.ts +17 -0
  185. package/lib/types/plugins/tools.d.ts +10 -0
  186. package/lib/types/prompt/render.d.ts +2 -0
  187. package/lib/types/protocol/arbitration.d.ts +154 -0
  188. package/lib/types/protocol/auth.d.ts +31 -0
  189. package/lib/types/protocol/claim.d.ts +36 -0
  190. package/lib/types/protocol/dispute.d.ts +17 -0
  191. package/lib/types/protocol/ids.d.ts +20 -0
  192. package/lib/types/protocol/inbox.d.ts +141 -0
  193. package/lib/types/protocol/index.d.ts +11 -0
  194. package/lib/types/protocol/policy.d.ts +21 -0
  195. package/lib/types/protocol/revision.d.ts +2 -0
  196. package/lib/types/protocol/router.d.ts +114 -0
  197. package/lib/types/protocol/schema.d.ts +4 -0
  198. package/lib/types/protocol/time.d.ts +5 -0
  199. package/lib/types/protocol/trace.d.ts +11 -0
  200. package/lib/types/store/atomic.d.ts +8 -0
  201. package/lib/types/store/claim-edits.d.ts +33 -0
  202. package/lib/types/store/claims.d.ts +7 -0
  203. package/lib/types/store/context.d.ts +13 -0
  204. package/lib/types/store/delivery-status.d.ts +48 -0
  205. package/lib/types/store/disputes.d.ts +6 -0
  206. package/lib/types/store/entities.d.ts +16 -0
  207. package/lib/types/store/errors.d.ts +8 -0
  208. package/lib/types/store/history.d.ts +65 -0
  209. package/lib/types/store/inbox.d.ts +27 -0
  210. package/lib/types/store/index.d.ts +16 -0
  211. package/lib/types/store/jobs.d.ts +5 -0
  212. package/lib/types/store/library-directory.d.ts +4 -0
  213. package/lib/types/store/lock.d.ts +11 -0
  214. package/lib/types/store/path-names.d.ts +2 -0
  215. package/lib/types/store/paths.d.ts +45 -0
  216. package/lib/types/store/presentation.d.ts +13 -0
  217. package/lib/types/store/regular-file.d.ts +2 -0
  218. package/lib/types/store/rejected-disputes.d.ts +18 -0
  219. package/lib/types/store/rename.d.ts +1 -0
  220. package/lib/types/store/reported-sets.d.ts +24 -0
  221. package/lib/types/store/session-state.d.ts +17 -0
  222. package/lib/types/store/traces.d.ts +6 -0
  223. package/lib/types/store/uploads.d.ts +312 -0
  224. package/lib/types/store/yaml.d.ts +8 -0
  225. package/lib/types/team/errors.d.ts +10 -0
  226. package/lib/types/team/http.d.ts +20 -0
  227. package/lib/types/team/index.d.ts +5 -0
  228. package/lib/types/team/maintainer-client.d.ts +18 -0
  229. package/lib/types/team/router-client.d.ts +14 -0
  230. package/lib/types/team/service.d.ts +28 -0
  231. package/lib/types/team/system-proxy.d.ts +9 -0
  232. package/lib/types/tools/claim.d.ts +63 -0
  233. package/lib/types/tools/consult-router.d.ts +11 -0
  234. package/lib/types/tools/subagent.d.ts +8 -0
  235. package/lib/types/tools/validation.d.ts +2 -0
  236. package/lib/types/upload/consolidation.d.ts +63 -0
  237. package/lib/types/upload/deliver.d.ts +15 -0
  238. package/lib/types/upload/index.d.ts +2 -0
  239. package/lib/types/upload/scheduler.d.ts +19 -0
  240. package/lib/types/upstreams.d.ts +5 -0
  241. package/lib/types/worker/queue.d.ts +17 -0
  242. package/lib/types/worker/types.d.ts +51 -0
  243. package/lib/types/worker/worker.d.ts +39 -0
  244. package/lib/types-C2ST2Zdg.js +17 -0
  245. package/lib/upload.js +3 -0
  246. package/lib/uploads-BCA2p92b.js +210 -0
  247. package/lib/upstreams-DEi-56tD.js +495 -0
  248. package/lib/worker-HMGzJFWd.js +185 -0
  249. package/locale/commands/en.json +1 -0
  250. package/locale/commands/zh.json +1 -0
  251. package/locale/dream/en.json +1 -0
  252. package/locale/dream/zh.json +1 -0
  253. package/locale/en.json +7 -0
  254. package/locale/formation/en.json +1 -0
  255. package/locale/formation/zh.json +1 -0
  256. package/locale/inbox/en.json +1 -0
  257. package/locale/inbox/zh.json +1 -0
  258. package/locale/knowledge/en.json +1 -0
  259. package/locale/knowledge/zh.json +1 -0
  260. package/locale/prompt/en.json +1 -0
  261. package/locale/prompt/zh.json +1 -0
  262. package/locale/tools/en.json +1 -0
  263. package/locale/tools/zh.json +1 -0
  264. package/locale/zh.json +7 -0
  265. package/package.json +262 -3
  266. package/prompts/claim_dream.j2 +77 -0
  267. package/prompts/claim_dream_legacy.j2 +63 -0
  268. package/prompts/dream_compaction.j2 +11 -0
  269. package/prompts/dream_evidence.j2 +5 -0
  270. package/prompts/inbox_claim_attribute_update_internalize.j2 +112 -0
  271. package/prompts/inbox_policy_update_internalize.j2 +87 -0
  272. package/prompts/knowledge.j2 +38 -0
  273. package/prompts/session_recap.j2 +113 -0
  274. package/prompts/what_is_claim.j2 +51 -0
  275. package/prompts/what_is_dispute.j2 +21 -0
  276. package/prompts/what_is_policy.j2 +22 -0
@@ -0,0 +1,344 @@
1
+ import { t as ClaimSchema, x as nowSeconds } from "./claim-DOAGe8ZK.js";
2
+ import { t as abortable } from "./structured-C9byFuzm.js";
3
+ import { n as validateAgentReport } from "./dispute-CtrInHzf.js";
4
+ import { t as TeamError } from "./errors-pPumDOGD.js";
5
+ import { n as InboxMessageSchema, t as InboxAckRequestSchema } from "./inbox-DFtE2fOp.js";
6
+ import { a as AgentQuerySchema, c as RouterQueryResultSchema, r as HealthResponseSchema, u as ScopesOverviewSnapshotSchema } from "./auth-DFI9yowX.js";
7
+ import { z } from "zod";
8
+ import { setTimeout } from "node:timers/promises";
9
+ import { promisify } from "node:util";
10
+ import { BlockList, isIP } from "node:net";
11
+ import { Agent, EnvHttpProxyAgent, ProxyAgent, fetch } from "undici";
12
+ import { execFile } from "node:child_process";
13
+ //#region src/team/system-proxy.ts
14
+ const run = promisify(execFile);
15
+ const empty = () => ({ exceptions: [] });
16
+ function proxyUrl(host, port) {
17
+ if (!host || port !== void 0 && (!/^\d+$/.test(port) || Number(port) < 1 || Number(port) > 65535)) return void 0;
18
+ try {
19
+ const address = port === void 0 ? host : `${host.includes(":") && !host.startsWith("[") ? `[${host}]` : host}:${port}`;
20
+ const url = new URL(address.includes("://") ? address : `http://${address}`);
21
+ return (url.protocol === "http:" || url.protocol === "https:") && url.hostname && !url.username && !url.password ? url.origin : void 0;
22
+ } catch {
23
+ return;
24
+ }
25
+ }
26
+ function parseMacProxy(output) {
27
+ const values = /* @__PURE__ */ new Map();
28
+ const exceptions = [];
29
+ let inExceptions = false;
30
+ for (const raw of output.split(/\r?\n/)) {
31
+ const line = raw.trim();
32
+ if (inExceptions) {
33
+ if (line === "}") inExceptions = false;
34
+ else {
35
+ const m = /^\d+\s*:\s*(.+)$/.exec(line);
36
+ if (m?.[1]) exceptions.push(m[1].trim());
37
+ }
38
+ continue;
39
+ }
40
+ if (/^ExceptionsList\s*:\s*<array>\s*\{$/.test(line)) {
41
+ inExceptions = true;
42
+ continue;
43
+ }
44
+ const pair = /^(\w+)\s*:\s*(.*)$/.exec(line);
45
+ if (pair?.[1] && pair[2] !== void 0) values.set(pair[1], pair[2].trim());
46
+ }
47
+ if (values.get("ProxyAutoConfigEnable") === "1" || values.get("ProxyAutoDiscoveryEnable") === "1") return empty();
48
+ if (values.get("ExcludeSimpleHostnames") === "1") exceptions.push("<local>");
49
+ const http = values.get("HTTPEnable") === "1" ? proxyUrl(values.get("HTTPProxy"), values.get("HTTPPort")) : void 0;
50
+ const https = values.get("HTTPSEnable") === "1" ? proxyUrl(values.get("HTTPSProxy"), values.get("HTTPSPort")) : void 0;
51
+ return {
52
+ ...http ? { http } : {},
53
+ ...https ? { https } : {},
54
+ exceptions
55
+ };
56
+ }
57
+ function parseWindowsProxy(output) {
58
+ const values = /* @__PURE__ */ new Map();
59
+ for (const line of output.split(/\r?\n/)) {
60
+ const m = /^\s*(\w+)\s+REG_\w+\s+(.*)$/.exec(line);
61
+ if (m?.[1] && m[2] !== void 0) values.set(m[1].toLowerCase(), m[2].trim());
62
+ }
63
+ if (values.get("autoconfigurl") || Number(values.get("proxyenable")) !== 1) return empty();
64
+ const server = values.get("proxyserver") ?? "";
65
+ let http;
66
+ let https;
67
+ if (server.includes("=")) for (const entry of server.split(";")) {
68
+ const [protocol, address] = entry.split("=", 2).map((part) => part.trim());
69
+ if (protocol?.toLowerCase() === "http") http = proxyUrl(address);
70
+ if (protocol?.toLowerCase() === "https") https = proxyUrl(address);
71
+ }
72
+ else http = https = proxyUrl(server);
73
+ return {
74
+ ...http ? { http } : {},
75
+ ...https ? { https } : {},
76
+ exceptions: (values.get("proxyoverride") ?? "").split(";").filter(Boolean)
77
+ };
78
+ }
79
+ function bypassSystemProxy(endpoint, exceptions) {
80
+ const host = endpoint.hostname.replace(/^\[|\]$/g, "").toLowerCase();
81
+ const port = endpoint.port || (endpoint.protocol === "https:" ? "443" : "80");
82
+ return exceptions.flatMap((rule) => rule.split(/[,;\s]+/)).some((raw) => {
83
+ const rule = raw.toLowerCase();
84
+ if (!rule) return false;
85
+ if (rule === "*") return true;
86
+ if (rule === "<local>") return isIP(host) === 0 && !host.includes(".");
87
+ if (rule.includes("/")) {
88
+ const [network, prefix] = rule.split("/");
89
+ if (!network || !prefix) return false;
90
+ const family = isIP(host);
91
+ const parts = network.split(".");
92
+ if (family === 4) while (parts.length < 4) parts.push("0");
93
+ const address = family === 4 ? parts.join(".") : network;
94
+ const bits = Number(prefix);
95
+ if (!family || isIP(address) !== family || !Number.isInteger(bits) || bits < 0 || bits > (family === 4 ? 32 : 128)) return false;
96
+ const block = new BlockList();
97
+ const type = family === 4 ? "ipv4" : "ipv6";
98
+ block.addSubnet(address, bits, type);
99
+ return block.check(host, type);
100
+ }
101
+ const m = /^(\[[^\]]+\]|[^:]+)(?::(\d+))?$/.exec(rule);
102
+ if (!m?.[1] || m[2] && m[2] !== port) return false;
103
+ const pattern = m[1].replace(/^\[|\]$/g, "").replace(/^\*?\./, "");
104
+ if (pattern.includes("*")) return new RegExp(`^${pattern.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*")}$`).test(host);
105
+ return host === pattern || isIP(host) === 0 && host.endsWith(`.${pattern}`);
106
+ });
107
+ }
108
+ async function systemProxyFor(endpoint) {
109
+ try {
110
+ let proxy;
111
+ if (process.platform === "darwin") proxy = parseMacProxy((await run("/usr/sbin/scutil", ["--proxy"], { timeout: 5e3 })).stdout);
112
+ else if (process.platform === "win32") proxy = parseWindowsProxy((await run("reg", ["query", "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"], {
113
+ timeout: 5e3,
114
+ windowsHide: true
115
+ })).stdout);
116
+ else return void 0;
117
+ const url = new URL(endpoint);
118
+ if (bypassSystemProxy(url, [...proxy.exceptions, process.env["no_proxy"] ?? process.env["NO_PROXY"] ?? ""])) return void 0;
119
+ return url.protocol === "https:" ? proxy.https : proxy.http;
120
+ } catch {
121
+ return;
122
+ }
123
+ }
124
+ //#endregion
125
+ //#region src/team/http.ts
126
+ const environmentCredential = (reference) => Promise.resolve(process.env[reference]);
127
+ function connectionFailure(error, timedOut) {
128
+ if (timedOut) return "timeout";
129
+ const cause = error instanceof Error && error.cause instanceof Error ? error.cause : error;
130
+ const code = cause !== null && typeof cause === "object" && "code" in cause ? cause.code : void 0;
131
+ return code === "ENOTFOUND" || code === "EAI_AGAIN" ? "dns" : code === "ECONNREFUSED" || code === "ENETUNREACH" || code === "EHOSTUNREACH" ? "unreachable" : "network";
132
+ }
133
+ function bypassProxy(endpoint) {
134
+ const host = new URL(endpoint).hostname.toLowerCase().replace(/^\[|\]$/g, "");
135
+ return host === "localhost" || host.endsWith(".localhost") || host === "::1" || isIP(host) === 4 && host.startsWith("127.");
136
+ }
137
+ function teamUrl(endpoint, path) {
138
+ const url = new URL(endpoint);
139
+ url.pathname = `${url.pathname.replace(/\/+$/, "")}${path}`;
140
+ url.search = "";
141
+ url.hash = "";
142
+ return url.href;
143
+ }
144
+ var TeamHttp = class {
145
+ service;
146
+ endpoint;
147
+ agentId;
148
+ config;
149
+ credential;
150
+ dispatcher;
151
+ stop = new AbortController();
152
+ constructor(service, endpoint, agentId, config, credential = environmentCredential) {
153
+ this.service = service;
154
+ this.endpoint = endpoint;
155
+ this.agentId = agentId;
156
+ this.config = config;
157
+ this.credential = credential;
158
+ const hasEnvironmentProxy = [
159
+ "http_proxy",
160
+ "HTTP_PROXY",
161
+ "https_proxy",
162
+ "HTTPS_PROXY",
163
+ "all_proxy",
164
+ "ALL_PROXY"
165
+ ].some((name) => Boolean(process.env[name]?.trim()));
166
+ const fallback = process.env["all_proxy"] || process.env["ALL_PROXY"];
167
+ const environment = fallback ? {
168
+ httpProxy: process.env["http_proxy"] || process.env["HTTP_PROXY"] || fallback,
169
+ httpsProxy: process.env["https_proxy"] || process.env["HTTPS_PROXY"] || fallback
170
+ } : {};
171
+ this.dispatcher = bypassProxy(endpoint) ? Promise.resolve(new Agent()) : hasEnvironmentProxy ? Promise.resolve(new EnvHttpProxyAgent(environment)) : systemProxyFor(endpoint).then((proxy) => proxy ? new ProxyAgent(proxy) : new Agent());
172
+ }
173
+ async credentialConfigured() {
174
+ return this.config.keyEnv !== "" && Boolean(await this.credential(this.config.keyEnv));
175
+ }
176
+ async post(path, data, schema, signal) {
177
+ const operation = `POST ${path}`;
178
+ for (let attempt = 0;; attempt += 1) {
179
+ const timeout = AbortSignal.timeout(Math.min(this.config.timeoutMs, 2147483647));
180
+ const combined = AbortSignal.any([
181
+ this.stop.signal,
182
+ timeout,
183
+ ...signal === void 0 ? [] : [signal]
184
+ ]);
185
+ let failure;
186
+ try {
187
+ if (combined.aborted) throw new TeamError(timeout.aborted ? "retryable" : "cancelled", this.service, operation);
188
+ const key = this.config.keyEnv ? await abortable(this.credential(this.config.keyEnv), combined) ?? "" : "";
189
+ const response = await fetch(teamUrl(this.endpoint, path), {
190
+ method: "POST",
191
+ headers: { "Content-Type": "application/json" },
192
+ dispatcher: await abortable(this.dispatcher, combined),
193
+ redirect: "error",
194
+ signal: combined,
195
+ body: JSON.stringify({
196
+ auth: {
197
+ agent_id: this.agentId,
198
+ acn_key: key
199
+ },
200
+ data
201
+ })
202
+ });
203
+ if (response.ok) {
204
+ if (schema === void 0) {
205
+ await response.body?.cancel();
206
+ return;
207
+ }
208
+ let body;
209
+ try {
210
+ body = await response.json();
211
+ } catch (error) {
212
+ throw new TeamError(error instanceof SyntaxError ? "protocol" : "retryable", this.service, operation, response.status);
213
+ }
214
+ const parsed = schema.safeParse(body);
215
+ if (!parsed.success) throw new TeamError("protocol", this.service, operation, response.status);
216
+ return parsed.data;
217
+ }
218
+ await response.body?.cancel();
219
+ const status = response.status;
220
+ failure = new TeamError(status === 401 || this.service === "router" && status === 403 ? "auth" : path === "/inbox/ack" && (status === 404 || status === 405) ? "legacy_route" : status === 408 || status === 429 || status >= 500 ? "retryable" : "client", this.service, operation, status);
221
+ } catch (error) {
222
+ if (signal?.aborted && signal.reason instanceof Error && signal.reason.name === "TimeoutError") throw new TeamError("retryable", this.service, operation, void 0, "timeout");
223
+ if (signal?.aborted || this.stop.signal.aborted) throw new TeamError("cancelled", this.service, operation);
224
+ failure = error instanceof TeamError ? error : new TeamError("retryable", this.service, operation, void 0, connectionFailure(error, timeout.aborted));
225
+ }
226
+ if (failure.kind !== "retryable" || attempt >= this.config.retryCount) throw failure;
227
+ const backoff = Math.min(this.config.retryMaxDelayMs, this.config.retryBaseDelayMs * 2 ** Math.min(attempt, 16));
228
+ try {
229
+ await setTimeout(Math.max(1, Math.min(this.config.retryMaxDelayMs, Math.round(backoff * (.8 + Math.random() * .4)))), void 0, { signal: AbortSignal.any([this.stop.signal, ...signal === void 0 ? [] : [signal]]) });
230
+ } catch {
231
+ if (signal?.aborted && signal.reason instanceof Error && signal.reason.name === "TimeoutError") throw new TeamError("retryable", this.service, operation, void 0, "timeout");
232
+ throw new TeamError("cancelled", this.service, operation);
233
+ }
234
+ }
235
+ }
236
+ async close() {
237
+ this.stop.abort();
238
+ await (await this.dispatcher).destroy();
239
+ }
240
+ };
241
+ //#endregion
242
+ //#region src/team/router-client.ts
243
+ var RouterClient = class {
244
+ http;
245
+ constructor(http) {
246
+ this.http = http;
247
+ }
248
+ bounded(signal) {
249
+ return AbortSignal.any([AbortSignal.timeout(Math.min(this.http.config.routerTimeoutMs, 2147483647)), ...signal === void 0 ? [] : [signal]]);
250
+ }
251
+ query(query, signal) {
252
+ return this.http.post("/claims/query", AgentQuerySchema.parse(query), RouterQueryResultSchema, this.bounded(signal));
253
+ }
254
+ overview(signal) {
255
+ return this.http.post("/claims/scopes/overview", {}, ScopesOverviewSnapshotSchema, this.bounded(signal));
256
+ }
257
+ health(signal) {
258
+ return this.http.post("/health", {}, HealthResponseSchema, signal);
259
+ }
260
+ };
261
+ //#endregion
262
+ //#region src/team/maintainer-client.ts
263
+ var MaintainerClient = class {
264
+ http;
265
+ constructor(http) {
266
+ this.http = http;
267
+ }
268
+ pull(signal) {
269
+ return this.http.post("/inbox/pull", { agent_id: this.http.agentId }, z.array(InboxMessageSchema), signal);
270
+ }
271
+ ack(ids, signal) {
272
+ return this.http.post("/inbox/ack", InboxAckRequestSchema.parse({
273
+ agent_id: this.http.agentId,
274
+ inbox_ids: ids
275
+ }), void 0, signal);
276
+ }
277
+ upload(claim, signal) {
278
+ return this.http.post("/claims/upload", ClaimSchema.parse(claim), void 0, signal);
279
+ }
280
+ report(dispute, signal) {
281
+ return this.http.post("/disputes/report", validateAgentReport(dispute), void 0, signal);
282
+ }
283
+ health(signal) {
284
+ return this.http.post("/health", {}, HealthResponseSchema, signal);
285
+ }
286
+ };
287
+ //#endregion
288
+ //#region src/team/service.ts
289
+ var TeamFacade = class {
290
+ logger;
291
+ router;
292
+ maintainer;
293
+ states = {
294
+ mode: "team",
295
+ router: { state: "unknown" },
296
+ maintainer: { state: "unknown" }
297
+ };
298
+ warned = /* @__PURE__ */ new Set();
299
+ constructor(config, agentId, logger, credential) {
300
+ this.logger = logger;
301
+ this.router = new RouterClient(new TeamHttp("router", config.routerEndpoint, agentId, config, credential));
302
+ this.maintainer = new MaintainerClient(new TeamHttp("maintainer", config.maintainerEndpoint, agentId, config, credential));
303
+ }
304
+ status() {
305
+ return structuredClone(this.states);
306
+ }
307
+ async request(service, action) {
308
+ try {
309
+ const result = await action();
310
+ this.states[service] = {
311
+ state: "ok",
312
+ at: nowSeconds()
313
+ };
314
+ return result;
315
+ } catch (error) {
316
+ if (!(error instanceof TeamError)) throw error;
317
+ if (error.kind === "cancelled") throw error;
318
+ this.states[service] = {
319
+ state: "failed",
320
+ at: nowSeconds(),
321
+ error: error.message
322
+ };
323
+ const warning = error.kind === "auth" ? "auth" : `${service}:${error.kind}`;
324
+ if (!this.warned.has(warning)) {
325
+ this.warned.add(warning);
326
+ this.logger.warn(error.message);
327
+ }
328
+ throw error;
329
+ }
330
+ }
331
+ async health(signal) {
332
+ await Promise.allSettled(["router", "maintainer"].map((service) => this.request(service, async () => {
333
+ const result = await this[service].health(signal);
334
+ if (result.team_auth_enabled && result.auth_passed === void 0) throw new TeamError("protocol", service, "POST /health");
335
+ if (result.team_auth_enabled && result.auth_passed === false) throw new TeamError("auth", service, "POST /health", 401);
336
+ return result;
337
+ })));
338
+ }
339
+ async close() {
340
+ await Promise.all([this.router.http.close(), this.maintainer.http.close()]);
341
+ }
342
+ };
343
+ //#endregion
344
+ export { bypassProxy as a, TeamHttp as i, MaintainerClient as n, teamUrl as o, RouterClient as r, TeamFacade as t };
@@ -0,0 +1,305 @@
1
+ import { i as effectiveUpdatedAt, x as nowSeconds } from "./claim-DOAGe8ZK.js";
2
+ import { d as RecapOutputSchema, n as resolveRoute, r as structuredCall, u as FormationValidationError } from "./structured-C9byFuzm.js";
3
+ import { R as nextClaimUpdateAt } from "./evidence-store-DW7kj20i.js";
4
+ import { _ as JobError } from "./lock-DbmlKOoX.js";
5
+ import { s as ensureKnowledgeReady } from "./alignment-CwH0nBf-.js";
6
+ import { t as TeamError } from "./errors-pPumDOGD.js";
7
+ import { t as UploadDelivery } from "./deliver-C-dmhkfm.js";
8
+ import { t as prepareFormation } from "./prepare-CGXwBEcu.js";
9
+ import { s as DisputeResolutionSchema } from "./inbox-DFtE2fOp.js";
10
+ import { t as InboxStore } from "./inbox-2CugZZQm.js";
11
+ import { n as InboxEffectStore } from "./effects-DX1iy6FM.js";
12
+ //#region src/inbox/prepare.ts
13
+ const InternalizeOutputSchema = RecapOutputSchema.omit({ used_claim_ids: true });
14
+ function valid(condition, message) {
15
+ if (!condition) throw new FormationValidationError(message);
16
+ }
17
+ const sameSet = (a, b) => new Set(a).size === new Set(b).size && a.every((id) => b.includes(id));
18
+ const resolutionOf = (message) => message.message_type === "claim_attribute_update" ? message.arbitration_resolution : void 0;
19
+ function validateArbitration(message) {
20
+ const resolution = resolutionOf(message);
21
+ if (resolution === void 0) return;
22
+ valid(resolution.dispute_id === resolution.dispute_snapshot.id, "仲裁 dispute_id 与冻结 Dispute 不一致。");
23
+ valid(resolution.resolution_type !== "unresolved" && resolution.resolution_basis !== "insufficient_evidence", "未解决或证据不足的仲裁不能内化。");
24
+ const direct = resolution.direct_claim_snapshots.map((claim) => claim.id);
25
+ const disputed = resolution.dispute_snapshot.claims;
26
+ valid(new Set(direct).size === direct.length && new Set(disputed).size === disputed.length && sameSet(direct, disputed), "仲裁直接 Claim 快照必须唯一且完整覆盖 Dispute。");
27
+ const assessed = resolution.claim_assessments?.map((item) => item.claim_id) ?? [];
28
+ valid(assessed.length === 0 || new Set(assessed).size === assessed.length && sameSet(assessed, direct), "仲裁 assessment 必须唯一且完整覆盖直接 Claim。");
29
+ }
30
+ function inboxContext(agentId, messages, local) {
31
+ valid(messages.length > 0, "内化批次不能为空。");
32
+ valid(local.every((claim) => claim.holder === agentId) && new Set(local.map((claim) => claim.id)).size === local.length, "本地 Claim 持有权或 ID 不合法。");
33
+ for (const message of messages) validateArbitration(message);
34
+ const first = messages[0];
35
+ valid(first !== void 0 && messages.every((message) => message.message_type === first.message_type && !(message.message_type === "policy_update" && message.policy.status === "deprecated")), "内化批次类型不一致或含待确定性处理的废弃 Policy。");
36
+ const directClaims = messages.flatMap((message) => resolutionOf(message)?.direct_claim_snapshots ?? []);
37
+ const directIds = new Set(directClaims.map((claim) => claim.id));
38
+ const editable = local.filter((claim) => claim.status !== "deprecated" || directIds.has(claim.id));
39
+ return {
40
+ input: first.message_type === "policy_update" ? {
41
+ agent_id: agentId,
42
+ inbox_messages: messages,
43
+ local_claims: editable
44
+ } : {
45
+ agent_id: agentId,
46
+ claim_attribute_updates: messages.map((message) => {
47
+ const context = resolutionOf(message);
48
+ if (context === void 0) return {
49
+ claim_attribute_update: message,
50
+ conclusion: message.policy.statement,
51
+ direct_claims: []
52
+ };
53
+ return {
54
+ claim_attribute_update: message,
55
+ conclusion: context.conclusion,
56
+ resolution: DisputeResolutionSchema.parse(context),
57
+ dispute: context.dispute_snapshot,
58
+ direct_claims: context.direct_claim_snapshots
59
+ };
60
+ }),
61
+ local_claims: editable
62
+ },
63
+ editable,
64
+ directClaims,
65
+ directIds
66
+ };
67
+ }
68
+ function semantics(claim) {
69
+ return JSON.stringify({
70
+ id: claim.id,
71
+ name: claim.name,
72
+ statement: claim.statement,
73
+ scope: claim.scope,
74
+ holder: claim.holder,
75
+ confidence: claim.confidence,
76
+ status: claim.status,
77
+ evidence_summary: claim.evidence_summary,
78
+ source_claim_ids: [...new Set(claim.source_claim_ids)].sort()
79
+ });
80
+ }
81
+ function repeatsResolved(dispute, messages, local, targets) {
82
+ return messages.some((message) => {
83
+ const context = resolutionOf(message);
84
+ if (context === void 0 || !sameSet(dispute.claims, context.dispute_snapshot.claims)) return false;
85
+ return context.direct_claim_snapshots.every((before) => {
86
+ return semantics(targets.find((claim) => claim.id === before.id) ?? local.find((claim) => claim.id === before.id) ?? before) === semantics(before);
87
+ });
88
+ });
89
+ }
90
+ function prepareInbox(raw, agentId, messages, local, now = nowSeconds()) {
91
+ const context = inboxContext(agentId, messages, local);
92
+ const output = InternalizeOutputSchema.parse(raw);
93
+ const policyIds = [...new Set(messages.map((message) => message.policy.id))];
94
+ if (messages[0]?.message_type === "claim_attribute_update") for (const draft of [...output.new_claims, ...output.updated_claims]) {
95
+ if (policyIds.length === 1 && policyIds[0] !== void 0 && !draft.source_claim_ids.some((source) => policyIds.some((id) => id === source))) draft.source_claim_ids.push(policyIds[0]);
96
+ valid(draft.source_claim_ids.some((source) => policyIds.some((id) => id === source)), "每条 CAU 变更必须引用真正相关的本批 Policy;多 Policy 批次不能自动归因。");
97
+ }
98
+ const prepared = prepareFormation({
99
+ ...output,
100
+ used_claim_ids: []
101
+ }, agentId, context.editable, policyIds, now, {
102
+ directClaims: context.directClaims,
103
+ editableDeprecatedIds: context.directIds
104
+ });
105
+ const final = new Map([
106
+ ...context.directClaims,
107
+ ...local,
108
+ ...prepared.claims
109
+ ].map((claim) => [claim.id, claim]));
110
+ valid(prepared.disputes.every((dispute) => dispute.claims.every((id) => final.get(id)?.status !== "deprecated")), "新 Dispute 不得引用本批最终状态为 deprecated 的 Claim。");
111
+ prepared.disputes = prepared.disputes.filter((dispute) => !repeatsResolved(dispute, messages, local, prepared.claims));
112
+ return prepared;
113
+ }
114
+ //#endregion
115
+ //#region src/inbox/cascade.ts
116
+ function deprecatePolicyClaims(policyId, local, now = nowSeconds()) {
117
+ return local.filter((claim) => claim.source_claim_ids.includes(policyId)).map((claim) => claim.status === "deprecated" ? claim : {
118
+ ...claim,
119
+ status: "deprecated",
120
+ updated_at: nextClaimUpdateAt(now, effectiveUpdatedAt(claim))
121
+ });
122
+ }
123
+ //#endregion
124
+ //#region src/inbox/sync.ts
125
+ async function syncInbox(context, team, signal) {
126
+ const report = {
127
+ pulled: 0,
128
+ accepted: 0,
129
+ acknowledged: 0,
130
+ warnings: []
131
+ };
132
+ if (context.mode === "solo" || team === null) return report;
133
+ let messages;
134
+ try {
135
+ messages = await team.request("maintainer", () => team.maintainer.pull(signal));
136
+ } catch (error) {
137
+ if (!(error instanceof TeamError)) throw error;
138
+ report.warnings.push(error.message);
139
+ return report;
140
+ }
141
+ report.pulled = messages.length;
142
+ const store = new InboxStore(context);
143
+ const accepted = [];
144
+ for (const message of messages) {
145
+ signal?.throwIfAborted();
146
+ try {
147
+ await store.acceptPulled(message);
148
+ if (!accepted.includes(message.id)) accepted.push(message.id);
149
+ } catch {
150
+ report.warnings.push("Inbox 快照持久化失败;已保存的前缀仍会确认并处理。");
151
+ break;
152
+ }
153
+ }
154
+ report.accepted = accepted.length;
155
+ if (accepted.length > 0) try {
156
+ await team.request("maintainer", () => team.maintainer.ack(accepted, signal));
157
+ report.acknowledged = accepted.length;
158
+ } catch (error) {
159
+ if (!(error instanceof TeamError)) throw error;
160
+ report.warnings.push(error.message);
161
+ }
162
+ return report;
163
+ }
164
+ //#endregion
165
+ //#region src/inbox/service.ts
166
+ var AcnInbox = class {
167
+ knowledge;
168
+ backend;
169
+ render;
170
+ unregister;
171
+ stopping = new AbortController();
172
+ active = /* @__PURE__ */ new Set();
173
+ constructor(knowledge, backend, render) {
174
+ this.knowledge = knowledge;
175
+ this.backend = backend;
176
+ this.render = render;
177
+ if (knowledge.jobs === null) throw new JobError("unconfigured", "请先配置 agentId。");
178
+ this.unregister = knowledge.jobs.register("inbox", (job, control) => this.track(() => this.run(job, {
179
+ ...control,
180
+ signal: AbortSignal.any([control.signal, this.stopping.signal])
181
+ })));
182
+ }
183
+ async track(operation) {
184
+ this.stopping.signal.throwIfAborted();
185
+ const pending = operation();
186
+ this.active.add(pending);
187
+ try {
188
+ return await pending;
189
+ } finally {
190
+ this.active.delete(pending);
191
+ }
192
+ }
193
+ enqueue(synchronize = true, sessionId) {
194
+ this.stopping.signal.throwIfAborted();
195
+ if (this.knowledge.jobs === null) throw new JobError("unconfigured", "请先配置 agentId。");
196
+ return this.knowledge.jobs.enqueue("inbox", { synchronize }, sessionId);
197
+ }
198
+ async request(signal, sessionId) {
199
+ return this.track(async () => {
200
+ const report = await syncInbox(this.knowledge.context(), this.knowledge.team, signal === void 0 ? this.stopping.signal : AbortSignal.any([signal, this.stopping.signal]));
201
+ const job = await this.enqueue(false, sessionId);
202
+ return {
203
+ ...report,
204
+ pending: (await new InboxStore(this.knowledge.context()).listPending()).length,
205
+ jobId: job.id
206
+ };
207
+ });
208
+ }
209
+ async start() {
210
+ await new InboxEffectStore(this.knowledge.context()).recover();
211
+ if (await new InboxStore(this.knowledge.context()).hasUnfinished()) await this.enqueue();
212
+ }
213
+ async prepare(messages, analysisClaims, job, control) {
214
+ const first = messages[0];
215
+ if (first === void 0) throw new JobError("validation", "Inbox 批次为空。");
216
+ if (first.message_type === "policy_update" && first.policy.status === "deprecated") {
217
+ const syncClaims = deprecatePolicyClaims(first.policy.id, analysisClaims);
218
+ return {
219
+ claims: syncClaims.filter((target) => analysisClaims.some((before) => before.id === target.id && before.status !== "deprecated")),
220
+ syncClaims,
221
+ disputes: [],
222
+ usedClaimIds: [],
223
+ warnings: []
224
+ };
225
+ }
226
+ const context = inboxContext(this.knowledge.context().agentId, messages, analysisClaims);
227
+ const route = await resolveRoute(this.knowledge.config.llm, this.knowledge.context());
228
+ return structuredCall({
229
+ backend: this.backend,
230
+ context: this.knowledge.context(),
231
+ config: this.knowledge.config.llm,
232
+ route,
233
+ jobId: job.id,
234
+ system: this.render(first.message_type === "policy_update" ? "inbox_policy_update_internalize.j2" : "inbox_claim_attribute_update_internalize.j2", {}),
235
+ input: JSON.stringify(context.input),
236
+ schema: InternalizeOutputSchema,
237
+ parse: (value) => prepareInbox(value, this.knowledge.context().agentId, messages, analysisClaims),
238
+ signal: control.signal
239
+ });
240
+ }
241
+ async run(job, control) {
242
+ const context = this.knowledge.context();
243
+ await ensureKnowledgeReady(context.paths.root);
244
+ await new InboxEffectStore(context).recover();
245
+ control.signal.throwIfAborted();
246
+ const sync = job.payload["synchronize"] === false ? {
247
+ pulled: 0,
248
+ accepted: 0,
249
+ acknowledged: 0,
250
+ warnings: []
251
+ } : await syncInbox(context, this.knowledge.team, control.signal);
252
+ await ensureKnowledgeReady(context.paths.root);
253
+ const store = new InboxStore(context, this.knowledge.config.inbox.processingStaleAfterSecs);
254
+ await store.recoverOrphans();
255
+ const claimed = await store.claimPending();
256
+ let applied = 0;
257
+ let handled = 0;
258
+ const entityIds = /* @__PURE__ */ new Set();
259
+ try {
260
+ for (let offset = 0; offset < claimed.length;) {
261
+ const first = claimed[offset];
262
+ if (first === void 0) break;
263
+ const batch = [first];
264
+ offset += 1;
265
+ if (!(first.message.message_type === "policy_update" && first.message.policy.status === "deprecated")) while (offset < claimed.length) {
266
+ const next = claimed[offset];
267
+ if (next === void 0 || next.message.message_type !== first.message.message_type || next.message.message_type === "policy_update" && next.message.policy.status === "deprecated") break;
268
+ batch.push(next);
269
+ offset += 1;
270
+ }
271
+ control.signal.throwIfAborted();
272
+ const analysisClaims = (await this.knowledge.snapshot()).claims;
273
+ const messages = batch.map((item) => item.message);
274
+ const prepared = await this.prepare(messages, analysisClaims, job, control);
275
+ const result = await this.knowledge.applyInboxEffect(messages, analysisClaims, prepared, control);
276
+ control.committed?.();
277
+ applied += result.applied;
278
+ handled += messages.length;
279
+ for (const id of result.entityIds ?? []) entityIds.add(id);
280
+ control.signal.throwIfAborted();
281
+ }
282
+ } finally {
283
+ for (const item of claimed) await store.release(item);
284
+ }
285
+ control.signal.throwIfAborted();
286
+ const delivery = await new UploadDelivery(context, this.knowledge.team).deliver(control.signal);
287
+ if ((await store.listPending()).length > 0) await this.enqueue();
288
+ return {
289
+ ...sync,
290
+ applied,
291
+ handled,
292
+ entityIds: [...entityIds],
293
+ uploadedClaims: delivery.deliveredClaims,
294
+ reportedDisputes: delivery.deliveredDisputes,
295
+ warnings: [...sync.warnings, ...delivery.warnings]
296
+ };
297
+ }
298
+ async close() {
299
+ this.stopping.abort(new JobError("suspended", "Inbox 已暂停,未完成消息保留。"));
300
+ this.unregister();
301
+ await Promise.allSettled([...this.active]);
302
+ }
303
+ };
304
+ //#endregion
305
+ export { inboxContext as a, InternalizeOutputSchema as i, syncInbox as n, prepareInbox as o, deprecatePolicyClaims as r, validateArbitration as s, AcnInbox as t };