@openclaw/codex 2026.9.3 → 2026.9.5

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 (146) hide show
  1. package/assets/activity.svg +30 -0
  2. package/assets/icon.png +0 -0
  3. package/dist/.setup/account-usage-runtime-C2MOIvfq.mjs +75 -0
  4. package/dist/{apply-B6el6hdO.js → .setup/apply-CJ0ZfmBG.mjs} +12 -13
  5. package/dist/.setup/async-questions-DdhOCwGi.mjs +27 -0
  6. package/dist/{attempt-client-cleanup-D6cR54TV.js → .setup/attempt-client-cleanup-BpYKdTA0.mjs} +30 -211
  7. package/dist/{attempt-context-AO4DSjE0.js → .setup/attempt-context-VXVwTCfS.mjs} +6 -6
  8. package/dist/.setup/attempt-terminal-gZrxQ35N.mjs +5 -0
  9. package/dist/{auth-binding-Co2Vfcf_.js → .setup/auth-binding-DhLWa_7K.mjs} +2 -2
  10. package/dist/{auth-cache-key-Kq6oerr6.js → .setup/auth-cache-key-QirmgiCo.mjs} +3 -3
  11. package/dist/{auth-profile-CwzO4_RG.js → .setup/auth-profile-WqZtZfXN.mjs} +1 -1
  12. package/dist/.setup/binding-connection-Bm38niE8.mjs +50 -0
  13. package/dist/.setup/binding-connection.runtime-CnRMC0ta.mjs +48 -0
  14. package/dist/{bounded-turn-lRpmZHFv.js → .setup/bounded-turn-BtlZcivC.mjs} +19 -14
  15. package/dist/{build-state-6RL6qohz.js → .setup/build-state-Xx9ybZqa.mjs} +1 -1
  16. package/dist/{capabilities-BeqLPbtM.js → .setup/capabilities-_vXcZGSx.mjs} +1 -1
  17. package/dist/{client-BEKu4yDx.js → .setup/client-vXs2929Q.mjs} +355 -164
  18. package/dist/{command-dispatch-CisT9Jqq.js → .setup/command-dispatch-naHIZwwF.mjs} +3 -3
  19. package/dist/{command-formatters-DeTfrapr.js → .setup/command-formatters-CGEkdawF.mjs} +4 -3
  20. package/dist/{command-handlers-BfIsJEuA.js → .setup/command-handlers-BtAJEW1X.mjs} +812 -152
  21. package/dist/{command-rpc-BMqRQOFX.js → .setup/command-rpc-DHFpn4le.mjs} +37 -21
  22. package/dist/{compact-CGJZ2rlb.js → .setup/compact-C3i3qlzj.mjs} +28 -43
  23. package/dist/{config-JDfTI4VI.js → .setup/config-CedDWjM-.mjs} +5 -4
  24. package/dist/{config-options-jnIFvwxD.js → .setup/config-options-BsanJ8QG.mjs} +9 -421
  25. package/dist/{protocol-CAAcVIKF.js → .setup/config-parsing-CcB9iPoq.mjs} +9 -51
  26. package/dist/{config-runtime-BWf6JLWG.js → .setup/config-runtime-CeAhl_h4.mjs} +2 -2
  27. package/dist/.setup/config-security-BRQ2mgW9.mjs +465 -0
  28. package/dist/{config-utils-C57JiJrU.js → .setup/config-utils-DujwEnhg.mjs} +2 -4
  29. package/dist/{conversation-binding-CxOlHiix.js → .setup/conversation-binding-DhzrpTM6.mjs} +60 -47
  30. package/dist/{conversation-binding-data-BiodpIzq.js → .setup/conversation-binding-data-CrcyZk6O.mjs} +1 -1
  31. package/dist/{conversation-control-CUCrSIQI.js → .setup/conversation-control-DN53ns41.mjs} +17 -13
  32. package/dist/.setup/cyber-failover-DYwbmf1o.mjs +123 -0
  33. package/dist/.setup/cyber-failover-notice-e9G3J9-e.mjs +17 -0
  34. package/dist/{dynamic-tools-D-JBoaLt.js → .setup/dynamic-tools-D16lOp67.mjs} +168 -61
  35. package/dist/{effective-mcp-catalog-J_5Ep5Um.js → .setup/effective-mcp-catalog-K6kLCN8X.mjs} +3 -3
  36. package/dist/{ephemeral-turn-DSwzP8YY.js → .setup/ephemeral-turn-R1gA8Sn6.mjs} +4 -5
  37. package/dist/{event-projector-assistant-message-BmBM4qBV.js → .setup/event-projector-assistant-message-DNUR1s0A.mjs} +6 -3
  38. package/dist/.setup/event-projector-items-DyTQ_XqL.mjs +200 -0
  39. package/dist/{attempt-notifications--H8zXR5-.js → .setup/event-projector-usage-C7Ntzs-f.mjs} +102 -9
  40. package/dist/{harness-FR6eQgyO.js → .setup/harness-rxaaoN-o.mjs} +90 -19
  41. package/dist/.setup/inference-context-fulhZuz8.mjs +94 -0
  42. package/dist/.setup/inference-proxy-CC15HuSi.mjs +311 -0
  43. package/dist/{isolated-completion-DHBefrzg.js → .setup/isolated-completion-B6srt48J.mjs} +7 -7
  44. package/dist/{launch-args-RXQwn8zV.js → .setup/launch-args-DnMak49W.mjs} +22 -1
  45. package/dist/{managed-binary-DrjjRRUD.js → .setup/managed-binary-DP6Rib3P.mjs} +11 -2
  46. package/dist/{managed-thread-store-D1t5jh3G.js → .setup/managed-thread-store-BMqgThVL.mjs} +48 -14
  47. package/dist/{model-catalog-B_6M04Wo.js → .setup/model-catalog-DkvUuBey.mjs} +35 -10
  48. package/dist/{models-P9k2qAof.js → .setup/models-BDFgm_G-.mjs} +3 -3
  49. package/dist/.setup/native-auth-BLZGqFjw.mjs +57 -0
  50. package/dist/.setup/native-subagent-history-YXaL6dMd.mjs +135 -0
  51. package/dist/.setup/native-subagent-monitor-B1hxzIOy.mjs +5031 -0
  52. package/dist/.setup/native-subagent-task-ids-DsuOonKv.mjs +411 -0
  53. package/dist/{node-cli-sessions-rj0ysJwM.js → .setup/node-cli-sessions-Cl8b2ZF3.mjs} +1 -1
  54. package/dist/{node-exec-server.runtime-BY_ctYnT.js → .setup/node-exec-server.runtime-BaViBKNz.mjs} +5 -5
  55. package/dist/{plan-BMJdMOEF.js → .setup/plan-xD7WKYTM.mjs} +331 -79
  56. package/dist/{plugin-activation-BQK-f5sV.js → .setup/plugin-activation-r8nq5Jzp.mjs} +24 -19
  57. package/dist/{plugin-app-cache-key-CdSQzWyX.js → .setup/plugin-app-cache-key-BOxKP7db.mjs} +29 -25
  58. package/dist/{plugin-approval-roundtrip-DeW95wB5.js → .setup/plugin-approval-roundtrip-CjfzafAZ.mjs} +1 -1
  59. package/dist/{plugin-inventory-CoRCzWW4.js → .setup/plugin-inventory-DUle8DLz.mjs} +12 -8
  60. package/dist/{plugin-marketplace-discovery-3akBizzF.js → .setup/plugin-marketplace-discovery-P-Vndfqq.mjs} +18 -15
  61. package/dist/{plugin-metadata-cache-DgNfRAGA.js → .setup/plugin-metadata-cache-DsS5buNa.mjs} +33 -14
  62. package/dist/{provider-capabilities-W4tfK5Y5.js → .setup/provider-capabilities-B8J4Dy-O.mjs} +2 -2
  63. package/dist/.setup/provider-fFh_-VR3.mjs +50 -0
  64. package/dist/{rate-limits-Bqnx1N4z.js → .setup/rate-limits-DOEGYRNs.mjs} +90 -46
  65. package/dist/.setup/request-BioXJLYa.mjs +292 -0
  66. package/dist/.setup/run-attempt-lifecycle-B7JbY4-F.mjs +71 -0
  67. package/dist/{run-attempt-DwKds3DN.js → .setup/run-attempt-rlA07pUv.mjs} +644 -491
  68. package/dist/{runtime-artifact-T-NwqeSH.js → .setup/runtime-artifact-Dy38Z5iU.mjs} +2 -2
  69. package/dist/{sandbox-guard-BcT66fWy.js → .setup/sandbox-guard-BBP-RbTf.mjs} +4 -3
  70. package/dist/{session-binding-CKSepwIC.js → .setup/session-binding-_0W_fHRr.mjs} +45 -63
  71. package/dist/{session-binding-record-CaZjYwNS.js → .setup/session-binding-record-TH3xA0zj.mjs} +181 -3
  72. package/dist/.setup/session-binding-sidecars-CKYEcfNn.mjs +543 -0
  73. package/dist/{session-catalog-adoption-BKLtSrwi.js → .setup/session-catalog-adoption-CR_whkEW.mjs} +6 -6
  74. package/dist/{session-catalog-archive-D0i2pGj2.js → .setup/session-catalog-archive-CwZaPacf.mjs} +6 -6
  75. package/dist/.setup/session-catalog-events-jMcYfQyd.mjs +250 -0
  76. package/dist/.setup/session-catalog-fUdWDx-U.mjs +2464 -0
  77. package/dist/.setup/session-catalog-index-B141u15s.mjs +1070 -0
  78. package/dist/.setup/session-catalog-index-order-Cc5BzlQr.mjs +48 -0
  79. package/dist/.setup/session-catalog-index-state-BAuDztHN.mjs +180 -0
  80. package/dist/{session-catalog-parsing-CdD3JhdM.js → .setup/session-catalog-native-projection-ChV3cCtm.mjs} +213 -21
  81. package/dist/{session-catalog-node-adoption-BUuDYY8R.js → .setup/session-catalog-node-adoption-BVRsYOSh.mjs} +3 -3
  82. package/dist/{session-catalog-node-continue-CBtc4wkI.js → .setup/session-catalog-node-continue-Dowv8osw.mjs} +7 -7
  83. package/dist/.setup/session-catalog-projection-C1Bj9Jl-.mjs +414 -0
  84. package/dist/{session-cli-CbgaHh0f.js → .setup/session-cli-DIj-IE-E.mjs} +4 -4
  85. package/dist/{session-history-Cz-tOOYj.js → .setup/session-history-C--SrLI8.mjs} +10 -5
  86. package/dist/{session-history-import-DFN7sWRU.js → .setup/session-history-import-JHXT5Xfi.mjs} +4 -4
  87. package/dist/{session-history-read-cxPUxyVV.js → .setup/session-history-read-B3ZfSUbF.mjs} +2 -2
  88. package/dist/{session-history.worker-CNEvGaU5.js → .setup/session-history.worker-CpNj7H_P.mjs} +192 -89
  89. package/dist/{session-initialization-Jo86C60I.js → .setup/session-initialization-DH1z6fXn.mjs} +2 -2
  90. package/dist/{session-permission-policy-B22InTp_.js → .setup/session-permission-policy-DhurXY0l.mjs} +2 -2
  91. package/dist/{session-retirement-BSNG_mhf.js → .setup/session-retirement-CU87AOg9.mjs} +6 -6
  92. package/dist/{settled-turn-context-Du6gdUDd.js → .setup/settled-turn-context-fmwouT5I.mjs} +2 -2
  93. package/dist/{settled-turn-finalizer-BuLUrZl2.js → .setup/settled-turn-finalizer-CiY2bLFK.mjs} +10 -10
  94. package/dist/{shared-client-CVhez2Uo.js → .setup/shared-client-BpTtuLQ5.mjs} +495 -156
  95. package/dist/{side-question-DLbr2vUU.js → .setup/side-question-DSCZyoBD.mjs} +64 -47
  96. package/dist/{source-Da-h6f7e.js → .setup/source-Bjp4UQij.mjs} +15 -14
  97. package/dist/{thread-archive-guard-D1bP04Tf.js → .setup/thread-archive-guard-jmecf6OJ.mjs} +1 -1
  98. package/dist/.setup/thread-history-page-BTx-4xsg.mjs +83 -0
  99. package/dist/{thread-lifecycle-D1pzRwHB.js → .setup/thread-lifecycle-Cik28qWn.mjs} +330 -150
  100. package/dist/{thread-ownership-D6oASVRu.js → .setup/thread-ownership-skomxnIt.mjs} +4 -4
  101. package/dist/{thread-policy-D8kI7yAO.js → .setup/thread-policy-Cjs4B8xf.mjs} +3 -3
  102. package/dist/{thread-resume-T5cveyxA.js → .setup/thread-resume-BkNpj9Pz.mjs} +8 -5
  103. package/dist/.setup/timeout-DZF05XrR.mjs +63 -0
  104. package/dist/{session-catalog-home-id-D7-aLiNt.js → .setup/transcript-history-projection-DHNBDhCU.mjs} +73 -20
  105. package/dist/{transcript-mirror-t5TOccct.js → .setup/transcript-mirror-D4qp_leP.mjs} +15 -6
  106. package/dist/{transcript-mirror-attestation-DibE0krH.js → .setup/transcript-mirror-attestation-CzM-94NC.mjs} +4 -1
  107. package/dist/{transport-stdio-BGjHoYLr.js → .setup/transport-stdio-Cmx94Oiy.mjs} +149 -44
  108. package/dist/{upstream-session-fork-De-sLJ2r.js → .setup/upstream-session-fork-D3UKxgVD.mjs} +27 -26
  109. package/dist/{usage-CPPTmBvZ.js → .setup/usage-BOgBEKso.mjs} +4 -4
  110. package/dist/.setup/usage-limit-error-C0ow7DOc.mjs +166 -0
  111. package/dist/{version-omm6IPI3.js → .setup/version-CoqzXPgK.mjs} +1 -1
  112. package/dist/{web-search-provider.runtime-CSVgQL0w.js → .setup/web-search-provider.runtime-CTGuJt6i.mjs} +3 -3
  113. package/dist/api.js +28 -20
  114. package/dist/cli-metadata.js +1 -1
  115. package/dist/doctor-contract-api.js +8 -528
  116. package/dist/harness.js +1 -1
  117. package/dist/index.js +130 -135
  118. package/dist/media-understanding-provider.js +3 -3
  119. package/dist/migration-provider-api.js +2 -0
  120. package/dist/native-tool-policy.js +12 -0
  121. package/dist/provider-discovery.js +18 -0
  122. package/dist/session-history-worker-runtime.js +23 -5
  123. package/dist/session-history.worker.js +2 -2
  124. package/dist/web-search-contract-api.js +1 -1
  125. package/openclaw.plugin.json +354 -68
  126. package/package.json +11 -8
  127. package/dist/binding-connection-QqgcPCgk.js +0 -60
  128. package/dist/event-projector-usage-CIyrYYid.js +0 -102
  129. package/dist/native-subagent-monitor-BbCUKRwC.js +0 -3350
  130. package/dist/request-CGvGOpeR.js +0 -198
  131. package/dist/session-catalog-HaDcp7Sv.js +0 -1533
  132. package/dist/session-catalog-provenance-DkJHo735.js +0 -124
  133. package/dist/timeout-BVw8aaM1.js +0 -33
  134. package/dist/{auth-profile-selection-DFu9e167.js → .setup/auth-profile-selection-DFu9e167.mjs} +0 -0
  135. package/dist/{context-compaction-activity-CMla5FPJ.js → .setup/context-compaction-activity-CMla5FPJ.mjs} +0 -0
  136. package/dist/{elicitation-input-DPoK8F7w.js → .setup/elicitation-input-DPoK8F7w.mjs} +0 -0
  137. package/dist/{history-rejection-B4nOXNXF.js → .setup/history-rejection-B4nOXNXF.mjs} +0 -0
  138. package/dist/{image-payload-sanitizer-tupAr-2o.js → .setup/image-payload-sanitizer-tupAr-2o.mjs} +0 -0
  139. package/dist/{incognito-session-uhrBF6wJ.js → .setup/incognito-session-uhrBF6wJ.mjs} +0 -0
  140. package/dist/{local-runtime-attribution-B_2mnqhb.js → .setup/local-runtime-attribution-B_2mnqhb.mjs} +0 -0
  141. package/dist/{native-execution-policy-umd0tgh4.js → .setup/native-execution-policy-YBMHSzC4.mjs} +1 -1
  142. /package/dist/{rolldown-runtime-8H4AJuhK.js → .setup/rolldown-runtime-8H4AJuhK.mjs} +0 -0
  143. /package/dist/{session-binding-meta-B7aEMU7g.js → .setup/session-binding-meta-B7aEMU7g.mjs} +0 -0
  144. /package/dist/{session-upstream-marker-D15C9NHp.js → .setup/session-upstream-marker-D15C9NHp.mjs} +0 -0
  145. /package/dist/{upstream-prompt-provenance-LphB8slG.js → .setup/upstream-prompt-provenance-LphB8slG.mjs} +0 -0
  146. /package/dist/{web-search-provider.shared-BrZmlqyR.js → .setup/web-search-provider.shared-BrZmlqyR.mjs} +0 -0
@@ -0,0 +1,200 @@
1
+ import { m as isJsonObject } from "./config-security-BRQ2mgW9.mjs";
2
+ import { asFiniteNumber, normalizeOptionalString as normalizeOptionalString$1, readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
3
+ //#region extensions/codex/src/app-server/event-projector-values.ts
4
+ const BIO_POLICY_SAFETY_ACCESS_BLOCK_PREFIX = "This content was flagged for possible biological risk.";
5
+ /** Project only Codex's explicit refusal contracts; other policy errors retain their own paths. */
6
+ function readCodexProviderRefusal(message, codexErrorInfo) {
7
+ if (!message) return;
8
+ if (codexErrorInfo === "cyberPolicy") return {
9
+ category: "cyber",
10
+ message
11
+ };
12
+ if (codexErrorInfo === "misalignmentPolicyViolation") return {
13
+ category: "misalignment",
14
+ message
15
+ };
16
+ return message.startsWith(BIO_POLICY_SAFETY_ACCESS_BLOCK_PREFIX) ? {
17
+ category: "bio",
18
+ message
19
+ } : void 0;
20
+ }
21
+ function readNonEmptyString(record, key) {
22
+ return normalizeOptionalString$1(record[key]);
23
+ }
24
+ function readNonEmptyStringArray(record, key) {
25
+ const value = record[key];
26
+ if (!Array.isArray(value)) return [];
27
+ const entries = [];
28
+ for (const entry of value) {
29
+ const normalized = normalizeOptionalString$1(entry);
30
+ if (normalized) entries.push(normalized);
31
+ }
32
+ return entries;
33
+ }
34
+ function readNullableString(record, key) {
35
+ const value = record[key];
36
+ if (value === null) return null;
37
+ return typeof value === "string" ? value : void 0;
38
+ }
39
+ function readNonNegativeInteger(record, key) {
40
+ const value = asFiniteNumber(record[key]);
41
+ return value !== void 0 && Number.isInteger(value) && value >= 0 ? value : void 0;
42
+ }
43
+ function readCodexErrorNotificationMessage(record) {
44
+ const error = record.error;
45
+ return isJsonObject(error) ? readStringField(error, "message") : void 0;
46
+ }
47
+ function readHookOutputEntries(value) {
48
+ if (!Array.isArray(value)) return [];
49
+ return value.flatMap((entry) => {
50
+ if (!isJsonObject(entry)) return [];
51
+ const text = readStringField(entry, "text");
52
+ if (!text) return [];
53
+ const kind = readStringField(entry, "kind");
54
+ return [{
55
+ ...kind ? { kind } : {},
56
+ text
57
+ }];
58
+ });
59
+ }
60
+ function splitPlanText(text) {
61
+ return text.split(/\r?\n/).map((line) => line.trim().replace(/^[-*]\s+/, "")).filter((line) => line.length > 0);
62
+ }
63
+ function extractRawAssistantText(item) {
64
+ const parts = (Array.isArray(item.content) ? item.content : []).flatMap((entry) => {
65
+ if (!isJsonObject(entry)) return [];
66
+ const type = readStringField(entry, "type");
67
+ if (type !== "output_text" && type !== "text") return [];
68
+ const value = readStringField(entry, "text");
69
+ return value === void 0 ? [] : [value];
70
+ });
71
+ return parts.length > 0 ? parts.join("").trim() : void 0;
72
+ }
73
+ function readItemString(item, key) {
74
+ const value = item[key];
75
+ return typeof value === "string" ? value : void 0;
76
+ }
77
+ function readItem(value) {
78
+ if (!isJsonObject(value)) return;
79
+ const type = typeof value.type === "string" ? value.type : void 0;
80
+ const id = typeof value.id === "string" ? value.id : void 0;
81
+ if (!type || !id) return;
82
+ return value;
83
+ }
84
+ //#endregion
85
+ //#region extensions/codex/src/app-server/event-projector-items.ts
86
+ function matchesCodexSnapshotTurn(item, turnId) {
87
+ const itemTurnId = readItemString(item, "turnId");
88
+ return itemTurnId === void 0 || itemTurnId === turnId;
89
+ }
90
+ function itemKind(item) {
91
+ switch (item.type) {
92
+ case "dynamicToolCall":
93
+ case "mcpToolCall": return "tool";
94
+ case "commandExecution": return "command";
95
+ case "fileChange": return "patch";
96
+ case "webSearch": return "search";
97
+ case "reasoning":
98
+ case "contextCompaction": return "analysis";
99
+ default: return;
100
+ }
101
+ }
102
+ function itemTitle(item) {
103
+ switch (item.type) {
104
+ case "commandExecution": return "Command";
105
+ case "fileChange": return "File change";
106
+ case "mcpToolCall": return "MCP tool";
107
+ case "dynamicToolCall": return "Tool";
108
+ case "webSearch": return "Web search";
109
+ case "contextCompaction": return "Context compaction";
110
+ case "reasoning": return "Reasoning";
111
+ default: return item.type;
112
+ }
113
+ }
114
+ function itemStatus(item) {
115
+ const status = readItemString(item, "status");
116
+ if (status === "failed" || status === "error") return "failed";
117
+ if (status === "declined") return "blocked";
118
+ if (status === "inProgress" || status === "in_progress" || status === "running") return "running";
119
+ return "completed";
120
+ }
121
+ function unknownItemStatus(item) {
122
+ const status = readItemString(item, "status");
123
+ switch (status) {
124
+ case void 0:
125
+ case "completed":
126
+ case "failed":
127
+ case "error":
128
+ case "declined":
129
+ case "inProgress":
130
+ case "in_progress":
131
+ case "running": return;
132
+ default: return status;
133
+ }
134
+ }
135
+ function auditNativeToolTerminalStatus(item) {
136
+ if (item.type === "imageView" || item.type === "sleep") return "completed";
137
+ const status = readItemString(item, "status");
138
+ if (status === "completed") return "completed";
139
+ if (status === "failed" || status === "error") return "failed";
140
+ if (status === "declined") return "blocked";
141
+ return "unknown";
142
+ }
143
+ function auditNativeToolUnfinishedStatus(item) {
144
+ return item.type === "webSearch" || item.type === "imageGeneration" ? "unknown" : "failed";
145
+ }
146
+ function isNonSuccessItemStatus(status) {
147
+ return status === "failed" || status === "blocked";
148
+ }
149
+ function itemName(item) {
150
+ if (item.type === "dynamicToolCall" && typeof item.tool === "string") return item.tool;
151
+ if (item.type === "mcpToolCall" && typeof item.tool === "string") {
152
+ const server = typeof item.server === "string" ? item.server : void 0;
153
+ return server ? `${server}.${item.tool}` : item.tool;
154
+ }
155
+ if (item.type === "commandExecution") return "bash";
156
+ if (item.type === "fileChange") return "apply_patch";
157
+ if (item.type === "webSearch") return "web_search";
158
+ }
159
+ function auditNativeToolName(item) {
160
+ if (item.type === "dynamicToolCall") return;
161
+ const progressName = itemName(item);
162
+ if (progressName) return progressName;
163
+ if (item.type === "collabAgentToolCall") return typeof item.tool === "string" && item.tool.trim() ? `collab.${item.tool.trim()}` : "collab_agent";
164
+ if (item.type === "imageGeneration") return "image_generation";
165
+ if (item.type === "imageView") return "image_view";
166
+ if (item.type === "sleep") return "sleep";
167
+ }
168
+ function isSideEffectingNativeToolItem(item) {
169
+ return itemStatus(item) !== "blocked" && (isMutatingNativeToolItem(item) || item.type === "mcpToolCall");
170
+ }
171
+ function shouldSynthesizeToolProgressForItem(item) {
172
+ switch (item.type) {
173
+ case "commandExecution":
174
+ case "fileChange":
175
+ case "webSearch":
176
+ case "mcpToolCall": return true;
177
+ default: return false;
178
+ }
179
+ }
180
+ function shouldRecordNativeToolTranscript(item) {
181
+ return shouldSynthesizeToolProgressForItem(item);
182
+ }
183
+ function isMutatingNativeToolItem(item) {
184
+ if (item.type === "commandExecution") return true;
185
+ return item.type === "fileChange" || item.type === "collabAgentToolCall" || item.type === "imageGeneration";
186
+ }
187
+ function shouldClearTerminalPresentationForNativeItem(item) {
188
+ switch (item.type) {
189
+ case "collabAgentToolCall":
190
+ case "commandExecution":
191
+ case "fileChange":
192
+ case "imageGeneration":
193
+ case "imageView":
194
+ case "mcpToolCall":
195
+ case "webSearch": return true;
196
+ default: return false;
197
+ }
198
+ }
199
+ //#endregion
200
+ export { readNonEmptyString as C, splitPlanText as D, readNullableString as E, readItemString as S, readNonNegativeInteger as T, normalizeOptionalString$1 as _, isNonSuccessItemStatus as a, readHookOutputEntries as b, itemName as c, matchesCodexSnapshotTurn as d, shouldClearTerminalPresentationForNativeItem as f, extractRawAssistantText as g, unknownItemStatus as h, isMutatingNativeToolItem as i, itemStatus as l, shouldSynthesizeToolProgressForItem as m, auditNativeToolTerminalStatus as n, isSideEffectingNativeToolItem as o, shouldRecordNativeToolTranscript as p, auditNativeToolUnfinishedStatus as r, itemKind as s, auditNativeToolName as t, itemTitle as u, readCodexErrorNotificationMessage as v, readNonEmptyStringArray as w, readItem as x, readCodexProviderRefusal as y };
@@ -1,5 +1,6 @@
1
- import { o as isJsonObject } from "./protocol-CAAcVIKF.js";
2
- import { readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
1
+ import { m as isJsonObject } from "./config-security-BRQ2mgW9.mjs";
2
+ import { asSafeIntegerInRange, readStringField } from "openclaw/plugin-sdk/string-coerce-runtime";
3
+ import { normalizeUsage } from "openclaw/plugin-sdk/agent-harness-runtime";
3
4
  //#region extensions/codex/src/app-server/attempt-notifications.ts
4
5
  const CODEX_TURN_ABORT_MARKER_START = "<turn_aborted>";
5
6
  const CODEX_TURN_ABORT_MARKER_END = "</turn_aborted>";
@@ -34,12 +35,6 @@ function isRawFunctionToolOutputCompletionNotification(notification) {
34
35
  const item = isJsonObject(notification.params.item) ? notification.params.item : void 0;
35
36
  return item ? readStringField(item, "type") === "function_call_output" : false;
36
37
  }
37
- /** Distinguishes progress-only assistant items from conversation answers. */
38
- function isAssistantCommentaryCompletionNotification(notification) {
39
- if (!isJsonObject(notification.params) || notification.method !== "item/completed") return false;
40
- const item = isJsonObject(notification.params.item) ? notification.params.item : void 0;
41
- return Boolean(item && readStringField(item, "type") === "agentMessage" && (readStringField(item, "phase") === "commentary" || readStringField(item, "delivery") === "async"));
42
- }
43
38
  /** Returns true for terminal app-server thread status strings. */
44
39
  function isTerminalTurnStatus(status) {
45
40
  return status === "completed" || status === "interrupted" || status === "failed";
@@ -106,4 +101,102 @@ function isNonEmptyString(value) {
106
101
  return typeof value === "string" && value.length > 0;
107
102
  }
108
103
  //#endregion
109
- export { isRawFunctionToolOutputCompletionNotification as a, readNotificationItemId as c, isPendingOpenClawDynamicToolCompletionNotification as i, readRawResponseToolCallId as l, isAssistantCommentaryCompletionNotification as n, isTerminalTurnStatus as o, isCodexTurnAbortMarkerNotification as r, readCodexNotificationItem as s, codexExecutionToolName as t, updateActiveTurnItemIds as u };
104
+ //#region extensions/codex/src/app-server/event-projector-usage.ts
105
+ function readTokenCount(record, key) {
106
+ return asSafeIntegerInRange(record[key], { min: 0 });
107
+ }
108
+ function readCodexThreadTokenUsage(params) {
109
+ const tokenUsage = isJsonObject(params.tokenUsage) ? params.tokenUsage : void 0;
110
+ const last = tokenUsage && isJsonObject(tokenUsage.last) ? tokenUsage.last : void 0;
111
+ return last ? normalizeCodexResponseTokenUsage(last) : void 0;
112
+ }
113
+ function readCodexThreadContextSnapshot(params) {
114
+ const tokenUsage = isJsonObject(params.tokenUsage) ? params.tokenUsage : void 0;
115
+ const last = tokenUsage && isJsonObject(tokenUsage.last) ? tokenUsage.last : void 0;
116
+ const modelContextWindow = tokenUsage ? readTokenCount(tokenUsage, "modelContextWindow") : void 0;
117
+ const activeContextTokens = last ? readTokenCount(last, "totalTokens") : void 0;
118
+ const inputTokens = last ? readTokenCount(last, "inputTokens") : void 0;
119
+ const cachedInputTokens = last ? readTokenCount(last, "cachedInputTokens") : void 0;
120
+ const cacheWriteInputTokens = last ? readTokenCount(last, "cacheWriteInputTokens") : void 0;
121
+ const reasoningOutputTokens = last ? readTokenCount(last, "reasoningOutputTokens") : void 0;
122
+ return {
123
+ ...activeContextTokens !== void 0 ? { activeContextTokens } : {},
124
+ ...cachedInputTokens !== void 0 ? { cachedInputTokens } : {},
125
+ ...cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens } : {},
126
+ ...inputTokens !== void 0 ? { inputTokens } : {},
127
+ ...modelContextWindow && modelContextWindow > 0 ? { modelContextWindow } : {},
128
+ ...inputTokens !== void 0 ? { promptTokens: inputTokens } : {},
129
+ ...reasoningOutputTokens !== void 0 ? { reasoningOutputTokens } : {}
130
+ };
131
+ }
132
+ function normalizeCodexResponseTokenUsage(record) {
133
+ const totalTokens = readTokenCount(record, "totalTokens");
134
+ const inputTokens = readTokenCount(record, "inputTokens");
135
+ const cacheRead = readTokenCount(record, "cachedInputTokens");
136
+ const output = readTokenCount(record, "outputTokens");
137
+ const reasoningTokens = readTokenCount(record, "reasoningOutputTokens");
138
+ const cacheWrite = record.cacheWriteInputTokens === void 0 ? 0 : readTokenCount(record, "cacheWriteInputTokens");
139
+ const hasCoherentInput = inputTokens !== void 0 && cacheRead !== void 0 && cacheWrite !== void 0 && cacheRead + cacheWrite <= inputTokens;
140
+ const hasCoherentContext = hasCoherentInput && totalTokens !== void 0 && output !== void 0 && totalTokens === inputTokens + output;
141
+ const usage = normalizeUsage({
142
+ input: hasCoherentInput ? inputTokens - cacheRead - cacheWrite : void 0,
143
+ output,
144
+ cacheRead,
145
+ cacheWrite,
146
+ reasoningTokens,
147
+ total: totalTokens
148
+ });
149
+ if (!usage) return;
150
+ return {
151
+ ...usage,
152
+ contextUsage: hasCoherentContext ? {
153
+ state: "available",
154
+ promptTokens: inputTokens,
155
+ totalTokens
156
+ } : { state: "unavailable" }
157
+ };
158
+ }
159
+ var CodexUsageProjection = class {
160
+ constructor() {
161
+ this.responseIds = /* @__PURE__ */ new Set();
162
+ }
163
+ get usage() {
164
+ const usage = this.responseUsage ?? this.threadUsage;
165
+ return usage ? {
166
+ ...usage,
167
+ contextUsage: this.contextUsage
168
+ } : void 0;
169
+ }
170
+ get modelIterations() {
171
+ return this.responseIds.size;
172
+ }
173
+ invalidateContext() {
174
+ this.contextUsage = { state: "unavailable" };
175
+ }
176
+ recordThread(params) {
177
+ const usage = readCodexThreadTokenUsage(params);
178
+ this.threadUsage = usage ?? this.threadUsage;
179
+ if (!this.responseUsage && usage) this.contextUsage = usage.contextUsage;
180
+ return readCodexThreadContextSnapshot(params);
181
+ }
182
+ record(params, reportOutputTokens) {
183
+ const responseId = readStringField(params, "responseId");
184
+ if (!responseId || this.responseIds.has(responseId)) return;
185
+ this.responseIds.add(responseId);
186
+ const usage = isJsonObject(params.usage) ? normalizeCodexResponseTokenUsage(params.usage) : void 0;
187
+ this.contextUsage = usage?.contextUsage ?? { state: "unavailable" };
188
+ this.responseUsage ??= {};
189
+ for (const field of [
190
+ "input",
191
+ "output",
192
+ "cacheRead",
193
+ "cacheWrite",
194
+ "reasoningTokens",
195
+ "total"
196
+ ]) if (usage?.[field] !== void 0) this.responseUsage[field] = (this.responseUsage[field] ?? 0) + usage[field];
197
+ const outputTokens = usage?.output;
198
+ if (outputTokens !== void 0) reportOutputTokens?.(outputTokens);
199
+ }
200
+ };
201
+ //#endregion
202
+ export { isPendingOpenClawDynamicToolCompletionNotification as a, readCodexNotificationItem as c, updateActiveTurnItemIds as d, isCodexTurnAbortMarkerNotification as i, readNotificationItemId as l, readCodexThreadContextSnapshot as n, isRawFunctionToolOutputCompletionNotification as o, codexExecutionToolName as r, isTerminalTurnStatus as s, CodexUsageProjection as t, readRawResponseToolCallId as u };
@@ -1,5 +1,6 @@
1
- import { l as sessionBindingIdentity } from "./session-binding-record-CaZjYwNS.js";
2
- import { t as codexBuildSymbol } from "./build-state-6RL6qohz.js";
1
+ import { CODEX_NATIVE_TOOL_REQUIREMENTS } from "../native-tool-policy.js";
2
+ import { p as sessionBindingIdentity } from "./session-binding-record-TH3xA0zj.mjs";
3
+ import { t as codexBuildSymbol } from "./build-state-Xx9ybZqa.mjs";
3
4
  import { resolvePluginConfigObject } from "openclaw/plugin-sdk/plugin-config-runtime";
4
5
  import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
5
6
  //#region extensions/codex/src/app-server/model-runtime.ts
@@ -73,6 +74,7 @@ function createCodexAppServerAgentHarness(options) {
73
74
  contextEngineHostCapabilities: CODEX_APP_SERVER_CONTEXT_ENGINE_HOST_CAPABILITIES,
74
75
  conversationToolPolicySupport: "exact",
75
76
  conversationToolPolicySafeDenyTools: CODEX_TOOL_POLICY_SAFE_DENY_NAMES,
77
+ conversationToolPolicyNativeTools: CODEX_NATIVE_TOOL_REQUIREMENTS,
76
78
  deliveryDefaults: { visibleReplies: "message_tool" },
77
79
  authBootstrap: "harness",
78
80
  resolveSessionRuntimeOwnership: (params) => {
@@ -103,7 +105,7 @@ function createCodexAppServerAgentHarness(options) {
103
105
  ...sessionCatalogControlFactory && sessionRuntime ? { sessionFork: {
104
106
  upstreamKinds: ["codex-app-server"],
105
107
  fork: async (params) => {
106
- const { forkCodexUpstreamSession } = await import("./upstream-session-fork-De-sLJ2r.js");
108
+ const { forkCodexUpstreamSession } = await import("./upstream-session-fork-D3UKxgVD.mjs");
107
109
  return await forkCodexUpstreamSession(params, {
108
110
  bindingStore: options.bindingStore,
109
111
  controlFactory: sessionCatalogControlFactory,
@@ -113,27 +115,44 @@ function createCodexAppServerAgentHarness(options) {
113
115
  });
114
116
  }
115
117
  } } : {},
118
+ taskHistory: {
119
+ taskKinds: ["codex-native"],
120
+ read: async (params) => {
121
+ const { readCodexNativeSubagentHistory } = await import("./native-subagent-history-YXaL6dMd.mjs");
122
+ const assertCurrent = () => {
123
+ params.assertCurrent();
124
+ if (disposed) throw new Error("Agent harness is disposed");
125
+ };
126
+ return readCodexNativeSubagentHistory({
127
+ ...params,
128
+ assertCurrent
129
+ }, {
130
+ bindingStore: options.bindingStore,
131
+ pluginConfig: resolveAttemptPluginConfig(params.cfg)
132
+ });
133
+ }
134
+ },
116
135
  authBinding: { fingerprint: async (params) => {
117
- const { fingerprintCodexAppServerAuthBinding } = await import("./auth-binding-Co2Vfcf_.js").then((n) => n.t);
136
+ const { fingerprintCodexAppServerAuthBinding } = await import("./auth-binding-DhLWa_7K.mjs").then((n) => n.t);
118
137
  return fingerprintCodexAppServerAuthBinding(params);
119
138
  } },
120
139
  runtimeArtifact: { validate: async (binding) => {
121
- const { validateCodexAppServerRuntimeArtifact } = await import("./runtime-artifact-T-NwqeSH.js");
140
+ const { validateCodexAppServerRuntimeArtifact } = await import("./runtime-artifact-Dy38Z5iU.mjs");
122
141
  return validateCodexAppServerRuntimeArtifact(binding);
123
142
  } },
124
143
  fetchUsageSnapshot: async (ctx) => {
125
- const { fetchCodexAppServerUsageSnapshot } = await import("./usage-CPPTmBvZ.js");
144
+ const { fetchCodexAppServerUsageSnapshot } = await import("./usage-BOgBEKso.mjs");
126
145
  return await fetchCodexAppServerUsageSnapshot(ctx, { pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig });
127
146
  },
128
147
  loadModelCatalog: async (params) => {
129
- const { createCodexAppServerModelCatalog } = await import("./model-catalog-B_6M04Wo.js");
148
+ const { createCodexAppServerModelCatalog } = await import("./model-catalog-DkvUuBey.mjs");
130
149
  if (disposed) return [];
131
150
  modelCatalog ??= createCodexAppServerModelCatalog(harnessRuntimeId);
132
151
  return await modelCatalog.load(params, resolveAttemptPluginConfig(params.config));
133
152
  },
134
153
  readModelCatalogReadiness: (params) => modelCatalog?.read(params, resolveAttemptPluginConfig(params.config)),
135
154
  loadMcpToolCatalog: async (params) => {
136
- const { loadCodexEffectiveMcpCatalog } = await import("./effective-mcp-catalog-J_5Ep5Um.js");
155
+ const { loadCodexEffectiveMcpCatalog } = await import("./effective-mcp-catalog-K6kLCN8X.mjs");
137
156
  return await loadCodexEffectiveMcpCatalog(params, { bindingStore: options.bindingStore });
138
157
  },
139
158
  supports: (ctx) => {
@@ -176,21 +195,73 @@ function createCodexAppServerAgentHarness(options) {
176
195
  };
177
196
  },
178
197
  runAttempt: async (params) => {
179
- const { runCodexAppServerAttempt } = await import("./run-attempt-DwKds3DN.js");
180
- return runCodexAppServerAttempt(params, {
198
+ const { runCodexAppServerAttempt } = await import("./run-attempt-rlA07pUv.mjs");
199
+ const { planCodexCyberEscalation, readCodexCyberAttemptVerdict, recordCodexCyberTargetUnavailable, reserveCodexCyberProbe, resolveCodexCyberFailoverConfig } = await import("./cyber-failover-DYwbmf1o.mjs");
200
+ const { emitCodexCyberNotice } = await import("./cyber-failover-notice-e9G3J9-e.mjs");
201
+ const pluginConfig = resolveAttemptPluginConfig(params.config);
202
+ const attemptModel = readCodexRuntimeModelId(params.model, params.modelId);
203
+ const runAttemptOnModel = (model, isRetry = false) => runCodexAppServerAttempt(isRetry ? {
204
+ ...params,
205
+ suppressNextUserMessagePersistence: true
206
+ } : params, {
181
207
  bindingStore: options.bindingStore,
182
- pluginConfig: resolveAttemptPluginConfig(params.config),
208
+ pluginConfig,
183
209
  runtime: sessionRuntime,
184
- runtimeModelId: readCodexRuntimeModelId(params.model, params.modelId),
210
+ runtimeModelId: model,
185
211
  nativeHookRelay: { enabled: true }
186
212
  });
213
+ const cyberFailover = resolveCodexCyberFailoverConfig(pluginConfig);
214
+ const workspace = {
215
+ agentId: params.agentId,
216
+ authProfileId: params.authProfileId
217
+ };
218
+ const result = await runAttemptOnModel(attemptModel);
219
+ const refusal = readCodexCyberAttemptVerdict(result);
220
+ if (!refusal.cyberRefused) return result;
221
+ const plan = planCodexCyberEscalation({
222
+ config: cyberFailover,
223
+ currentModel: attemptModel,
224
+ replaySafe: refusal.replaySafe,
225
+ workspace
226
+ });
227
+ if (plan.kind !== "escalate") {
228
+ if (plan.reason === "target_unavailable") await emitCodexCyberNotice(params, {
229
+ state: "unavailable",
230
+ model: attemptModel,
231
+ fallbackModel: cyberFailover.model
232
+ });
233
+ return result;
234
+ }
235
+ const releaseProbe = reserveCodexCyberProbe({
236
+ model: plan.model,
237
+ workspace
238
+ });
239
+ let escalated;
240
+ try {
241
+ escalated = await runAttemptOnModel(plan.model, true);
242
+ } finally {
243
+ releaseProbe();
244
+ }
245
+ const outcome = readCodexCyberAttemptVerdict(escalated);
246
+ if (outcome.unavailable) recordCodexCyberTargetUnavailable({
247
+ model: plan.model,
248
+ workspace,
249
+ cooloffMs: cyberFailover.cooloffMs
250
+ });
251
+ if (outcome.answered || outcome.unavailable) await emitCodexCyberNotice(params, {
252
+ state: outcome.answered ? "escalated" : "unavailable",
253
+ model: attemptModel,
254
+ fallbackModel: plan.model
255
+ });
256
+ if (outcome.unavailable && outcome.replaySafe && escalated.terminal.kind === "failed" && escalated.toolMetas.length === 0) return result;
257
+ return escalated;
187
258
  },
188
259
  runIsolatedCompletionV2: async (params) => {
189
260
  if (params.authorization.owner === "host") {
190
261
  const { runHostPreparedIsolatedCompletion } = await import("openclaw/plugin-sdk/simple-completion-runtime");
191
262
  return runHostPreparedIsolatedCompletion(params);
192
263
  }
193
- const { runCodexIsolatedCompletion } = await import("./isolated-completion-DHBefrzg.js");
264
+ const { runCodexIsolatedCompletion } = await import("./isolated-completion-B6srt48J.mjs");
194
265
  return runCodexIsolatedCompletion(params, { pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig });
195
266
  },
196
267
  runIsolatedCompletion: async (params) => {
@@ -206,11 +277,11 @@ function createCodexAppServerAgentHarness(options) {
206
277
  });
207
278
  },
208
279
  finalizeSettledTurn: async (params) => {
209
- const { runCodexSettledTurnFinalization } = await import("./settled-turn-finalizer-BuLUrZl2.js");
280
+ const { runCodexSettledTurnFinalization } = await import("./settled-turn-finalizer-CiY2bLFK.mjs");
210
281
  return runCodexSettledTurnFinalization(params, { pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig });
211
282
  },
212
283
  runSideQuestion: async (params) => {
213
- const { runCodexAppServerSideQuestion } = await import("./side-question-DLbr2vUU.js");
284
+ const { runCodexAppServerSideQuestion } = await import("./side-question-DSCZyoBD.mjs");
214
285
  return runCodexAppServerSideQuestion(params, {
215
286
  bindingStore: options.bindingStore,
216
287
  pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig,
@@ -220,20 +291,20 @@ function createCodexAppServerAgentHarness(options) {
220
291
  });
221
292
  },
222
293
  compact: async (params) => {
223
- const { maybeCompactCodexAppServerSession } = await import("./compact-CGJZ2rlb.js");
294
+ const { maybeCompactCodexAppServerSession } = await import("./compact-C3i3qlzj.mjs");
224
295
  return maybeCompactCodexAppServerSession(params, {
225
296
  bindingStore: options.bindingStore,
226
297
  pluginConfig: options?.resolvePluginConfig?.() ?? options?.pluginConfig
227
298
  });
228
299
  },
229
300
  withSessionDeletion: async (params, run) => {
230
- const { withCodexAppServerSessionDeletion } = await import("./session-retirement-BSNG_mhf.js");
301
+ const { withCodexAppServerSessionDeletion } = await import("./session-retirement-CU87AOg9.mjs");
231
302
  params.assertCurrent();
232
303
  return withCodexAppServerSessionDeletion(options.bindingStore, params, run);
233
304
  },
234
305
  reset: async (params) => {
235
306
  if (params.sessionId && params.reason !== "deleted") {
236
- const [{ reclaimCurrentCodexSessionGeneration }, { retireCodexAppServerSessionGeneration }] = await Promise.all([import("./session-binding-CKSepwIC.js").then((n) => n.c), import("./session-retirement-BSNG_mhf.js")]);
307
+ const [{ reclaimCurrentCodexSessionGeneration }, { retireCodexAppServerSessionGeneration }] = await Promise.all([import("./session-binding-_0W_fHRr.mjs").then((n) => n.c), import("./session-retirement-CU87AOg9.mjs")]);
237
308
  const identity = sessionBindingIdentity({
238
309
  agentId: params.agentId,
239
310
  sessionId: params.sessionId,
@@ -265,7 +336,7 @@ function createCodexAppServerAgentHarness(options) {
265
336
  /** Creates the private native-compaction bridge registered in host-owned capability state. */
266
337
  function createCodexAppServerNativeCompaction(options) {
267
338
  return async (params) => {
268
- const { maybeCompactCodexAppServerSession } = await import("./compact-CGJZ2rlb.js");
339
+ const { maybeCompactCodexAppServerSession } = await import("./compact-C3i3qlzj.mjs");
269
340
  return maybeCompactCodexAppServerSession(params, {
270
341
  bindingStore: options.bindingStore,
271
342
  pluginConfig: options.resolvePluginConfig?.() ?? options.pluginConfig,
@@ -0,0 +1,94 @@
1
+ import { m as isJsonObject } from "./config-security-BRQ2mgW9.mjs";
2
+ import { randomUUID } from "node:crypto";
3
+ //#region extensions/codex/src/app-server/inference-context.ts
4
+ const MAX_CONTEXT_BYTES = 262144;
5
+ const MAX_ACTIVE_ROOTS = 64;
6
+ const CODEX_INFERENCE_GENERATION_KEY = "openclaw_inference_generation";
7
+ /** One physical inference transport owns these confidential, nonpersistent snapshots. */
8
+ function createCodexInferenceContext(assertClientCurrent) {
9
+ const roots = /* @__PURE__ */ new Map();
10
+ let closed = false;
11
+ const assertOpen = () => {
12
+ if (closed) throw new Error("Codex parent-local inference transport is closed");
13
+ assertClientCurrent();
14
+ };
15
+ return {
16
+ register(params) {
17
+ assertOpen();
18
+ params.signal.throwIfAborted();
19
+ params.assertCurrent();
20
+ if (Buffer.byteLength(params.text) > MAX_CONTEXT_BYTES) throw new Error("Codex parent-local context exceeds the 256 KiB inference limit");
21
+ if (!roots.has(params.threadId) && roots.size >= MAX_ACTIVE_ROOTS) throw new Error("Codex parent-local inference root limit reached");
22
+ roots.get(params.threadId)?.release();
23
+ const controller = new AbortController();
24
+ const registration = {
25
+ generation: randomUUID(),
26
+ text: params.text,
27
+ controller,
28
+ assertCurrent: () => {
29
+ assertOpen();
30
+ controller.signal.throwIfAborted();
31
+ params.signal.throwIfAborted();
32
+ params.assertCurrent();
33
+ if (roots.get(params.threadId) !== registration) throw new Error("Codex parent-local inference generation was replaced");
34
+ },
35
+ release: () => {
36
+ if (roots.get(params.threadId) === registration) roots.delete(params.threadId);
37
+ registration.text = "";
38
+ controller.abort();
39
+ params.signal.removeEventListener("abort", registration.release);
40
+ }
41
+ };
42
+ roots.set(params.threadId, registration);
43
+ params.signal.addEventListener("abort", registration.release, { once: true });
44
+ return {
45
+ generation: registration.generation,
46
+ release: registration.release
47
+ };
48
+ },
49
+ /** Caller must authenticate its private transport before parsing any model request. */
50
+ prepare(body) {
51
+ assertOpen();
52
+ const metadata = isJsonObject(body.client_metadata) ? body.client_metadata : void 0;
53
+ const raw = metadata?.["x-codex-turn-metadata"];
54
+ if (typeof raw !== "string" || Buffer.byteLength(raw) > 1048576) throw new Error("Codex inference request is missing bounded native metadata");
55
+ const value = JSON.parse(raw);
56
+ if (!isJsonObject(value)) throw new Error("Codex inference request has invalid native metadata");
57
+ const threadId = value.thread_id;
58
+ if (metadata?.thread_id != null && threadId != null && metadata.thread_id !== threadId) throw new Error("Codex inference thread metadata disagrees");
59
+ const child = Boolean(value.parent_thread_id || value.subagent_kind || metadata?.["x-openai-subagent"] || metadata?.["x-codex-parent-thread-id"]);
60
+ const kind = value.request_kind;
61
+ if (child || kind === "compaction" || kind === "memory") return {
62
+ body,
63
+ assertCurrent: assertOpen,
64
+ signal: void 0
65
+ };
66
+ if (kind !== "turn" && kind !== "prewarm") throw new Error("Codex inference request has an unsupported native purpose");
67
+ const registration = typeof threadId === "string" ? roots.get(threadId) : void 0;
68
+ const generation = value[CODEX_INFERENCE_GENERATION_KEY];
69
+ if (kind === "prewarm" && body.generate === false && generation == null) return {
70
+ body,
71
+ assertCurrent: assertOpen,
72
+ signal: void 0
73
+ };
74
+ if (!registration || generation !== registration.generation) throw new Error("Codex inference has no current admitted parent generation");
75
+ registration.assertCurrent();
76
+ const instructions = body.instructions;
77
+ if (instructions !== void 0 && typeof instructions !== "string") throw new Error("Codex inference request has invalid top-level instructions");
78
+ return {
79
+ body: registration.text ? {
80
+ ...body,
81
+ instructions: instructions === void 0 ? registration.text : instructions + "\n\n" + registration.text
82
+ } : body,
83
+ assertCurrent: registration.assertCurrent,
84
+ signal: registration.controller.signal
85
+ };
86
+ },
87
+ close() {
88
+ closed = true;
89
+ for (const registration of roots.values()) registration.release();
90
+ }
91
+ };
92
+ }
93
+ //#endregion
94
+ export { createCodexInferenceContext as n, CODEX_INFERENCE_GENERATION_KEY as t };