@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,311 @@
1
+ import { m as isJsonObject } from "./config-security-BRQ2mgW9.mjs";
2
+ import { n as createCodexInferenceContext } from "./inference-context-fulhZuz8.mjs";
3
+ import { promisify } from "node:util";
4
+ import { zstdCompress, zstdDecompress } from "node:zlib";
5
+ import { Writable } from "node:stream";
6
+ import { WebSocket, WebSocketServer } from "openclaw/plugin-sdk/websocket-runtime";
7
+ import { createServer } from "node:http";
8
+ import { createNodeProxyAgent } from "openclaw/plugin-sdk/fetch-runtime";
9
+ import { generateSecureToken } from "openclaw/plugin-sdk/secure-random-runtime";
10
+ import { fetchWithSsrFGuard, isBlockedHostnameOrIp, resolvePinnedHostnameWithPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
11
+ //#region extensions/codex/src/app-server/inference-proxy.ts
12
+ const MAX_BODY_BYTES = 33554432;
13
+ const MAX_ERROR_BODY_BYTES = 1048576;
14
+ const MAX_CONNECTIONS = 16;
15
+ const compress = promisify(zstdCompress);
16
+ const decompress = promisify(zstdDecompress);
17
+ const HOP_HEADERS = /* @__PURE__ */ new Set([
18
+ "connection",
19
+ "keep-alive",
20
+ "proxy-authenticate",
21
+ "proxy-authorization",
22
+ "te",
23
+ "trailer",
24
+ "transfer-encoding",
25
+ "upgrade",
26
+ "host",
27
+ "content-length"
28
+ ]);
29
+ const FAILURE = "Codex parent-local inference transport failed; retry on a fresh connection.";
30
+ /** Private, fixed-destination relay. No upstream credentials or model content are retained. */
31
+ async function createCodexInferenceProxy(params) {
32
+ const upstream = new URL(params.upstream);
33
+ if (upstream.protocol !== "https:" || upstream.username || upstream.password || upstream.hash) throw new Error("Codex inference requires a credential-free HTTPS upstream URL");
34
+ const lifetime = new AbortController();
35
+ const assertCurrent = () => {
36
+ lifetime.signal.throwIfAborted();
37
+ params.assertCurrent();
38
+ };
39
+ const context = createCodexInferenceContext(assertCurrent);
40
+ const pathPrefix = "/" + generateSecureToken({
41
+ bytes: 32,
42
+ redact: true
43
+ }) + upstream.pathname.replace(/\/$/, "");
44
+ const active = /* @__PURE__ */ new Set();
45
+ const sockets = /* @__PURE__ */ new Set();
46
+ const wss = new WebSocketServer({
47
+ noServer: true,
48
+ maxPayload: MAX_BODY_BYTES,
49
+ perMessageDeflate: false
50
+ });
51
+ const handshakeHeaders = /* @__PURE__ */ new WeakMap();
52
+ wss.on("headers", (headers, request) => {
53
+ for (const [key, value] of Object.entries(handshakeHeaders.get(request) ?? {})) if (!key.startsWith("sec-websocket-")) headers.push(key + ": " + value);
54
+ handshakeHeaders.delete(request);
55
+ });
56
+ const resolveTarget = (request) => {
57
+ assertCurrent();
58
+ if (request.headers.origin || !request.url?.startsWith(pathPrefix + "/") || isBlockedHostnameOrIp(upstream.hostname)) throw new Error(FAILURE);
59
+ const suffix = request.url.slice(pathPrefix.length);
60
+ if (suffix.startsWith("//") || suffix.includes("\\") || /%2e|%2f|%5c|(?:^|\/)\.\.?(?:\/|\?|$)/i.test(suffix)) throw new Error(FAILURE);
61
+ const target = new URL(upstream);
62
+ const incoming = new URL(suffix, "http://localhost");
63
+ target.pathname = upstream.pathname.replace(/\/$/, "") + incoming.pathname;
64
+ for (const [key, value] of incoming.searchParams) target.searchParams.append(key, value);
65
+ return {
66
+ target,
67
+ sampling: incoming.pathname === "/responses"
68
+ };
69
+ };
70
+ const prepare = (bytes, sampling) => {
71
+ assertCurrent();
72
+ if (!sampling) return {
73
+ bytes,
74
+ assertCurrent,
75
+ signal: void 0
76
+ };
77
+ const value = JSON.parse(bytes.toString("utf8"));
78
+ if (!isJsonObject(value)) throw new Error(FAILURE);
79
+ const prepared = context.prepare(value);
80
+ const rewritten = Buffer.from(JSON.stringify(prepared.body));
81
+ if (rewritten.length > MAX_BODY_BYTES) throw new Error(FAILURE);
82
+ return {
83
+ ...prepared,
84
+ bytes: rewritten
85
+ };
86
+ };
87
+ const server = createServer((req, res) => {
88
+ const controller = new AbortController();
89
+ let guarded;
90
+ const abort = () => controller.abort();
91
+ req.once("aborted", abort);
92
+ res.once("close", abort);
93
+ (async () => {
94
+ try {
95
+ const { target, sampling } = resolveTarget(req);
96
+ if (req.method !== "POST" || active.size >= MAX_CONNECTIONS) throw new Error(FAILURE);
97
+ active.add(controller);
98
+ const wire = await readProxyBody(req, MAX_BODY_BYTES);
99
+ const encoding = req.headers["content-encoding"];
100
+ if (encoding && encoding !== "identity" && encoding !== "zstd") throw new Error(FAILURE);
101
+ const decoded = encoding === "zstd" ? await decompress(wire, { maxOutputLength: MAX_BODY_BYTES }) : wire;
102
+ assertCurrent();
103
+ const prepared = prepare(decoded, sampling);
104
+ const body = Buffer.from(encoding === "zstd" ? await compress(prepared.bytes) : prepared.bytes);
105
+ prepared.assertCurrent();
106
+ const signal = AbortSignal.any([
107
+ lifetime.signal,
108
+ controller.signal,
109
+ ...prepared.signal ? [prepared.signal] : []
110
+ ]);
111
+ guarded = await fetchWithSsrFGuard({
112
+ url: target.toString(),
113
+ init: {
114
+ method: "POST",
115
+ headers: relayHeaders(req.headers),
116
+ body,
117
+ signal
118
+ },
119
+ signal,
120
+ beforeRequest: prepared.assertCurrent,
121
+ requireHttps: true,
122
+ maxRedirects: 0,
123
+ capture: false,
124
+ mode: "trusted_env_proxy",
125
+ auditContext: "codex-parent-local-inference"
126
+ });
127
+ prepared.assertCurrent();
128
+ const headers = Object.fromEntries(guarded.response.headers);
129
+ delete headers["content-encoding"];
130
+ res.writeHead(guarded.response.status, relayHeaders(headers));
131
+ if (!guarded.response.body) res.end();
132
+ else await guarded.response.body.pipeTo(Writable.toWeb(res), { signal });
133
+ } catch {
134
+ if (!res.headersSent && !res.destroyed) res.writeHead(502, { "content-type": "text/plain" }).end(FAILURE);
135
+ else res.destroy();
136
+ } finally {
137
+ active.delete(controller);
138
+ req.off("aborted", abort);
139
+ res.off("close", abort);
140
+ await guarded?.release().catch(() => void 0);
141
+ }
142
+ })();
143
+ });
144
+ server.maxConnections = MAX_CONNECTIONS;
145
+ server.requestTimeout = 3e4;
146
+ server.headersTimeout = 1e4;
147
+ server.on("upgrade", (req, socket, head) => {
148
+ (async () => {
149
+ let remote;
150
+ let local;
151
+ let proxyAgent;
152
+ const controller = new AbortController();
153
+ const close = () => {
154
+ controller.abort();
155
+ active.delete(controller);
156
+ remote?.terminate();
157
+ local?.terminate();
158
+ proxyAgent?.destroy();
159
+ if (remote) sockets.delete(remote);
160
+ if (local) sockets.delete(local);
161
+ socket.destroy();
162
+ };
163
+ try {
164
+ const { target, sampling } = resolveTarget(req);
165
+ if (!sampling || active.size >= MAX_CONNECTIONS) throw new Error(FAILURE);
166
+ active.add(controller);
167
+ socket.once("close", close);
168
+ socket.once("error", close);
169
+ const signal = AbortSignal.any([lifetime.signal, controller.signal]);
170
+ proxyAgent = createNodeProxyAgent({
171
+ mode: "env",
172
+ targetUrl: target.href
173
+ });
174
+ const lookup = proxyAgent ? void 0 : (await resolvePinnedHostnameWithPolicy(target.hostname, { signal })).lookup;
175
+ assertCurrent();
176
+ signal.throwIfAborted();
177
+ target.protocol = "wss:";
178
+ const headers = relayHeaders(req.headers);
179
+ for (const key of Object.keys(headers)) if (key.startsWith("sec-websocket-")) delete headers[key];
180
+ remote = new WebSocket(target, {
181
+ headers,
182
+ ...proxyAgent ? { agent: proxyAgent } : { lookup },
183
+ followRedirects: false,
184
+ perMessageDeflate: false,
185
+ maxPayload: MAX_BODY_BYTES,
186
+ handshakeTimeout: 1e4
187
+ });
188
+ sockets.add(remote);
189
+ remote.once("upgrade", (response) => {
190
+ handshakeHeaders.set(req, relayHeaders(response.headers));
191
+ });
192
+ remote.once("error", close);
193
+ remote.once("close", close);
194
+ remote.once("unexpected-response", (_request, response) => {
195
+ (async () => {
196
+ try {
197
+ const body = await readProxyBody(response, MAX_ERROR_BODY_BYTES);
198
+ assertCurrent();
199
+ signal.throwIfAborted();
200
+ const failureHeaders = Object.entries(relayHeaders(response.headers)).map(([key, value]) => key + ": " + value);
201
+ failureHeaders.push("Connection: close", "Content-Length: " + body.length);
202
+ const status = "HTTP/1.1 " + response.statusCode + " " + (response.statusMessage ?? "Upstream refused");
203
+ socket.end(Buffer.concat([Buffer.from(status + "\r\n" + failureHeaders.join("\r\n") + "\r\n\r\n"), body]), close);
204
+ } catch {
205
+ close();
206
+ }
207
+ })();
208
+ });
209
+ remote.once("open", () => {
210
+ try {
211
+ assertCurrent();
212
+ signal.throwIfAborted();
213
+ wss.handleUpgrade(req, socket, head, (accepted) => {
214
+ local = accepted;
215
+ sockets.add(accepted);
216
+ accepted.once("error", close);
217
+ accepted.once("close", close);
218
+ let releaseFrame = () => {};
219
+ accepted.on("message", (data, binary) => {
220
+ try {
221
+ if (binary) throw new Error(FAILURE);
222
+ const prepared = prepare(rawBytes(data), true);
223
+ prepared.assertCurrent();
224
+ releaseFrame();
225
+ const onAbort = () => close();
226
+ prepared.signal?.addEventListener("abort", onAbort, { once: true });
227
+ releaseFrame = () => prepared.signal?.removeEventListener("abort", onAbort);
228
+ if (!remote || remote.readyState !== WebSocket.OPEN || remote.bufferedAmount + prepared.bytes.length > MAX_BODY_BYTES) throw new Error(FAILURE);
229
+ remote.send(prepared.bytes, { binary: false }, (error) => {
230
+ if (error) close();
231
+ });
232
+ } catch {
233
+ close();
234
+ }
235
+ });
236
+ accepted.once("close", () => releaseFrame());
237
+ remote.on("message", (data, binary) => {
238
+ if (accepted.readyState !== WebSocket.OPEN || accepted.bufferedAmount + rawBytes(data).length > MAX_BODY_BYTES) {
239
+ close();
240
+ return;
241
+ }
242
+ accepted.send(data, { binary }, (error) => {
243
+ if (error) close();
244
+ });
245
+ });
246
+ });
247
+ } catch {
248
+ close();
249
+ }
250
+ });
251
+ } catch {
252
+ close();
253
+ }
254
+ })();
255
+ });
256
+ const close = () => {
257
+ lifetime.abort();
258
+ context.close();
259
+ for (const controller of active) controller.abort();
260
+ for (const socket of sockets) socket.terminate();
261
+ server.close();
262
+ server.closeAllConnections();
263
+ wss.close();
264
+ };
265
+ try {
266
+ await new Promise((resolve, reject) => {
267
+ server.once("error", reject);
268
+ server.listen(0, "127.0.0.1", () => {
269
+ server.off("error", reject);
270
+ resolve();
271
+ });
272
+ });
273
+ assertCurrent();
274
+ server.on("error", close);
275
+ const address = server.address();
276
+ if (!address || typeof address === "string") throw new Error(FAILURE);
277
+ return {
278
+ context,
279
+ upstream: upstream.toString(),
280
+ baseUrl: "http://127.0.0.1:" + address.port + pathPrefix,
281
+ assertCurrent,
282
+ close
283
+ };
284
+ } catch (error) {
285
+ close();
286
+ throw error;
287
+ }
288
+ }
289
+ async function readProxyBody(stream, maxBytes) {
290
+ const chunks = [];
291
+ let size = 0;
292
+ for await (const chunk of stream) {
293
+ const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
294
+ size += bytes.length;
295
+ if (size > maxBytes) throw new Error(FAILURE);
296
+ chunks.push(bytes);
297
+ }
298
+ return Buffer.concat(chunks);
299
+ }
300
+ function rawBytes(data) {
301
+ return Array.isArray(data) ? Buffer.concat(data) : Buffer.isBuffer(data) ? data : Buffer.from(data);
302
+ }
303
+ function relayHeaders(input) {
304
+ const excluded = new Set(HOP_HEADERS);
305
+ for (const token of (input.connection ?? "").split(",")) excluded.add(token.trim().toLowerCase());
306
+ const output = {};
307
+ for (const [key, value] of Object.entries(input)) if (value !== void 0 && !excluded.has(key.toLowerCase())) output[key.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;
308
+ return output;
309
+ }
310
+ //#endregion
311
+ export { createCodexInferenceProxy };
@@ -1,10 +1,10 @@
1
- import { i as resolveCodexAppServerHomeScope } from "./config-options-jnIFvwxD.js";
2
- import { x as readCodexPluginConfig } from "./protocol-CAAcVIKF.js";
3
- import { g as assertCodexPassiveTurnItems } from "./client-BEKu4yDx.js";
4
- import "./config-JDfTI4VI.js";
5
- import { Z as resolveCodexAppServerPreparedAuthHandoff } from "./shared-client-CVhez2Uo.js";
6
- import { runBoundedCodexAppServerTurn } from "./bounded-turn-lRpmZHFv.js";
7
- import { a as createAttributedCodexAssistantMessage } from "./event-projector-assistant-message-BmBM4qBV.js";
1
+ import { d as readCodexPluginConfig } from "./config-parsing-CcB9iPoq.mjs";
2
+ import { g as assertCodexPassiveTurnItems } from "./client-vXs2929Q.mjs";
3
+ import { i as resolveCodexAppServerHomeScope } from "./config-options-BsanJ8QG.mjs";
4
+ import "./config-CedDWjM-.mjs";
5
+ import { Z as resolveCodexAppServerPreparedAuthHandoff } from "./shared-client-BpTtuLQ5.mjs";
6
+ import { runBoundedCodexAppServerTurn } from "./bounded-turn-BtlZcivC.mjs";
7
+ import { a as createAttributedCodexAssistantMessage } from "./event-projector-assistant-message-DNUR1s0A.mjs";
8
8
  //#region extensions/codex/src/app-server/isolated-completion.ts
9
9
  /** Runs prompt-only Codex inference on an ephemeral, ring-zero native thread. */
10
10
  async function runCodexIsolatedCompletion(params, options) {
@@ -55,6 +55,27 @@ function readCodexArgs(args) {
55
55
  }
56
56
  return tokens;
57
57
  }
58
+ /** Uses the native CLI configuration for status without starting its transport. */
59
+ function buildCodexLoginStatusArgs(args) {
60
+ const options = /* @__PURE__ */ new Set([
61
+ "-c",
62
+ "--config",
63
+ "-p",
64
+ "--profile",
65
+ "--enable",
66
+ "--disable"
67
+ ]);
68
+ const tokens = readCodexArgs(args);
69
+ const subcommandIndex = tokens.findLast(({ name }) => name === "app-server")?.index ?? -1;
70
+ const prefix = subcommandIndex < 0 ? [] : args.slice(0, subcommandIndex);
71
+ const configArgs = tokens.filter(({ index, name }) => index > subcommandIndex && options.has(name)).flatMap(({ index, end }) => args.slice(index, end));
72
+ return [
73
+ ...prefix,
74
+ ...configArgs,
75
+ "login",
76
+ "status"
77
+ ];
78
+ }
58
79
  function readCodexAppServerConfigOptions(args) {
59
80
  return readCodexArgs(args).filter(({ name }) => name === "-c" || name === "--config" || name === "-p" || name === "--profile");
60
81
  }
@@ -87,4 +108,4 @@ function normalizeCodexAppServerArgs(rawArgs, enforcedOverride) {
87
108
  return normalized.length === rawArgs.length && normalized.every((arg, index) => arg === rawArgs[index]) ? rawArgs : normalized;
88
109
  }
89
110
  //#endregion
90
- export { normalizeCodexAppServerArgs as n, readCodexAppServerConfigOptions as r, isCodexAppServerProxyLaunch as t };
111
+ export { readCodexAppServerConfigOptions as i, isCodexAppServerProxyLaunch as n, normalizeCodexAppServerArgs as r, buildCodexLoginStatusArgs as t };
@@ -1,4 +1,5 @@
1
- import { n as MANAGED_CODEX_APP_SERVER_PACKAGE } from "./version-omm6IPI3.js";
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
+ import { n as MANAGED_CODEX_APP_SERVER_PACKAGE } from "./version-CoqzXPgK.mjs";
2
3
  import { createRequire } from "node:module";
3
4
  import { constants, existsSync, realpathSync } from "node:fs";
4
5
  import path from "node:path";
@@ -47,6 +48,14 @@ function resolveFirstExistingMacOSDesktopCodexBundledMarketplacePath(params = {}
47
48
  * Resolves the managed Codex app-server binary shipped with or installed beside
48
49
  * the Codex plugin before stdio startup.
49
50
  */
51
+ var managed_binary_exports = /* @__PURE__ */ __exportAll({
52
+ isManagedCodexDesktopCommand: () => isManagedCodexDesktopCommand,
53
+ resolveManagedCodexAppServerStartOptions: () => resolveManagedCodexAppServerStartOptions,
54
+ resolveManagedCodexNativeCommand: () => resolveManagedCodexNativeCommand,
55
+ resolveManagedCodexPackageEntrypoint: () => resolveManagedCodexPackageEntrypoint,
56
+ resolvePackagedCodexNativeCommand: () => resolvePackagedCodexNativeCommand,
57
+ setManagedCodexPluginRoot: () => setManagedCodexPluginRoot
58
+ });
50
59
  const registeredCodexPlugin = resolveGlobalSingleton(Symbol.for("openclaw.codexManagedPluginRoot"), () => ({}));
51
60
  /** Records the process-stable plugin root prepared by OpenClaw's plugin loader. */
52
61
  function setManagedCodexPluginRoot(pluginRoot) {
@@ -183,4 +192,4 @@ async function commandPathExists(filePath, platform) {
183
192
  }
184
193
  }
185
194
  //#endregion
186
- export { setManagedCodexPluginRoot as a, resolveMacOSDesktopCodexBundledMarketplaceCandidates as c, resolvePackagedCodexNativeCommand as i, resolveMacOSDesktopCodexComputerUseServiceAppCandidates as l, resolveManagedCodexAppServerStartOptions as n, resolveFirstExistingMacOSDesktopCodexBundledMarketplacePath as o, resolveManagedCodexNativeCommand as r, resolveMacOSDesktopCodexAppPathCandidates as s, isManagedCodexDesktopCommand as t };
195
+ export { resolvePackagedCodexNativeCommand as a, resolveMacOSDesktopCodexAppPathCandidates as c, resolveManagedCodexNativeCommand as i, resolveMacOSDesktopCodexBundledMarketplaceCandidates as l, managed_binary_exports as n, setManagedCodexPluginRoot as o, resolveManagedCodexAppServerStartOptions as r, resolveFirstExistingMacOSDesktopCodexBundledMarketplacePath as s, isManagedCodexDesktopCommand as t, resolveMacOSDesktopCodexComputerUseServiceAppCandidates as u };
@@ -28,10 +28,53 @@ function managedThreadStoreKey(sourceHomeId, threadId) {
28
28
  }
29
29
  /** Durable ownership index for Codex threads created by OpenClaw. */
30
30
  function createCodexManagedThreadStore(state) {
31
+ const byHome = /* @__PURE__ */ new Map();
32
+ const memberships = /* @__PURE__ */ new Map();
33
+ let hydration;
34
+ const remember = ({ sourceHomeId, threadId }) => {
35
+ const key = managedThreadStoreKey(sourceHomeId, threadId);
36
+ if (memberships.has(key)) return key;
37
+ memberships.set(key, {
38
+ sourceHomeId,
39
+ threadId
40
+ });
41
+ let ids = byHome.get(sourceHomeId);
42
+ if (!ids) {
43
+ ids = /* @__PURE__ */ new Set();
44
+ byHome.set(sourceHomeId, ids);
45
+ }
46
+ ids.add(threadId);
47
+ if (memberships.size > 2e4) {
48
+ const oldest = memberships.entries().next().value;
49
+ if (oldest) {
50
+ memberships.delete(oldest[0]);
51
+ const oldestHome = byHome.get(oldest[1].sourceHomeId);
52
+ oldestHome?.delete(oldest[1].threadId);
53
+ if (oldestHome?.size === 0) byHome.delete(oldest[1].sourceHomeId);
54
+ }
55
+ }
56
+ return key;
57
+ };
58
+ const snapshot = async () => {
59
+ hydration ??= state.entries().then((entries) => {
60
+ const marked = new Map(memberships);
61
+ memberships.clear();
62
+ byHome.clear();
63
+ for (const entry of entries.toSorted((a, b) => a.createdAt - b.createdAt)) {
64
+ const parsed = managedThreadSchema.safeParse(entry.value);
65
+ if (parsed.success) marked.delete(remember(parsed.data));
66
+ }
67
+ for (const membership of marked.values()) remember(membership);
68
+ }).catch((error) => {
69
+ hydration = void 0;
70
+ throw error;
71
+ });
72
+ await hydration;
73
+ return byHome;
74
+ };
31
75
  return {
32
76
  async has(sourceHomeId, threadId) {
33
- const parsed = managedThreadSchema.safeParse(state.lookup(managedThreadStoreKey(sourceHomeId, threadId)));
34
- return parsed.success && parsed.data.sourceHomeId === sourceHomeId && parsed.data.threadId === threadId;
77
+ return (await snapshot()).get(sourceHomeId)?.has(threadId) ?? false;
35
78
  },
36
79
  async mark(params) {
37
80
  try {
@@ -42,24 +85,15 @@ function createCodexManagedThreadStore(state) {
42
85
  threadId: params.threadId.trim(),
43
86
  ...params.rolloutPath?.trim() ? { rolloutPath: params.rolloutPath.trim() } : {}
44
87
  });
45
- state.registerIfAbsent(managedThreadStoreKey(value.sourceHomeId, value.threadId), value);
88
+ await state.registerIfAbsent(managedThreadStoreKey(value.sourceHomeId, value.threadId), value);
89
+ remember(value);
46
90
  return true;
47
91
  } catch (error) {
48
92
  embeddedAgentLog.warn("failed to record Codex managed thread ownership", { error });
49
93
  return false;
50
94
  }
51
95
  },
52
- async snapshot() {
53
- const byHome = /* @__PURE__ */ new Map();
54
- for (const entry of state.entries()) {
55
- const parsed = managedThreadSchema.safeParse(entry.value);
56
- if (!parsed.success) continue;
57
- const ids = byHome.get(parsed.data.sourceHomeId) ?? /* @__PURE__ */ new Set();
58
- ids.add(parsed.data.threadId);
59
- byHome.set(parsed.data.sourceHomeId, ids);
60
- }
61
- return byHome;
62
- }
96
+ snapshot
63
97
  };
64
98
  }
65
99
  //#endregion
@@ -1,9 +1,13 @@
1
- import { r as buildCodexRuntimeModelParams } from "./harness-FR6eQgyO.js";
2
- import { o as isJsonObject, x as readCodexPluginConfig } from "./protocol-CAAcVIKF.js";
3
- import { o as withCodexAppServerJsonClient } from "./request-CGvGOpeR.js";
4
- import { n as resolveCodexAppServerRuntimeOptions } from "./config-runtime-BWf6JLWG.js";
5
- import { r as captureSharedCodexAppServerCatalogLifetime } from "./shared-client-CVhez2Uo.js";
6
- import { t as listAllCodexAppServerModels } from "./models-P9k2qAof.js";
1
+ import { r as buildCodexRuntimeModelParams } from "./harness-rxaaoN-o.mjs";
2
+ import { m as isJsonObject } from "./config-security-BRQ2mgW9.mjs";
3
+ import { d as readCodexPluginConfig } from "./config-parsing-CcB9iPoq.mjs";
4
+ import { n as isCodexAppServerProxyLaunch } from "./launch-args-DnMak49W.mjs";
5
+ import { o as withCodexAppServerJsonClient } from "./request-BioXJLYa.mjs";
6
+ import { n as resolveCodexAppServerRuntimeOptions } from "./config-runtime-CeAhl_h4.mjs";
7
+ import { a as resolveCodexAppServerAuthProfileStore, r as resolveCodexAppServerAuthProfileId } from "./auth-profile-WqZtZfXN.mjs";
8
+ import { r as captureSharedCodexAppServerCatalogLifetime } from "./shared-client-BpTtuLQ5.mjs";
9
+ import { t as listAllCodexAppServerModels } from "./models-BDFgm_G-.mjs";
10
+ import { probeCodexNativeAuth } from "./native-auth-BLZGqFjw.mjs";
7
11
  //#region extensions/codex/src/app-server/model-catalog.ts
8
12
  const DEFAULT_MODEL_DISCOVERY_TIMEOUT_MS = 2500;
9
13
  const INPUT_TYPES = /* @__PURE__ */ new Set([
@@ -51,7 +55,10 @@ function createCodexAppServerModelCatalog(runtime) {
51
55
  },
52
56
  read(params, pluginConfig) {
53
57
  const observation = scopes.get(params.config)?.get(scopeKey(params));
54
- return !disposed && params.provider === "openai" && observation !== void 0 && observation.pluginConfig === pluginConfig && observation.models?.has(params.modelId) && observation.accountType && observation.isCurrent?.() ? { accountType: observation.accountType } : void 0;
58
+ return !disposed && params.provider === "openai" && observation !== void 0 && observation.pluginConfig === pluginConfig && observation.models?.has(params.modelId) && observation.accountType && observation.isCurrent?.() ? {
59
+ accountType: observation.accountType,
60
+ ...observation.authMode ? { authMode: observation.authMode } : {}
61
+ } : void 0;
55
62
  },
56
63
  async load(params, pluginConfig) {
57
64
  if (disposed) return [];
@@ -65,13 +72,30 @@ function createCodexAppServerModelCatalog(runtime) {
65
72
  observations.set(key, observation);
66
73
  const discovery = readCodexPluginConfig(pluginConfig).discovery;
67
74
  if (discovery?.enabled === false) return [];
68
- const { start } = resolveCodexAppServerRuntimeOptions({ pluginConfig });
75
+ const options = resolveCodexAppServerRuntimeOptions({ pluginConfig });
76
+ const ownsLocalProcess = options.start.transport === "stdio" && !isCodexAppServerProxyLaunch(options.start.args);
77
+ const authProfileStore = ownsLocalProcess && options.start.homeScope === "agent" ? resolveCodexAppServerAuthProfileStore({
78
+ agentDir: params.agentDir,
79
+ config: params.config
80
+ }) : void 0;
81
+ const authProfileId = authProfileStore ? resolveCodexAppServerAuthProfileId({
82
+ store: authProfileStore,
83
+ config: params.config
84
+ }) : void 0;
85
+ const usesNativeHome = ownsLocalProcess && options.start.homeScope === "user";
86
+ const native = usesNativeHome ? await probeCodexNativeAuth({ pluginConfig }) : void 0;
87
+ if (usesNativeHome && !native || disposed || observations.get(key) !== observation) return [];
88
+ const { start } = options;
69
89
  const timeoutMs = discovery?.timeoutMs ?? DEFAULT_MODEL_DISCOVERY_TIMEOUT_MS;
70
90
  const result = await withCodexAppServerJsonClient({
71
91
  startOptions: start,
72
92
  config: params.config,
73
93
  agentDir: params.agentDir,
74
- timeoutMs
94
+ timeoutMs,
95
+ ...authProfileStore ? {
96
+ authProfileStore,
97
+ authProfileId
98
+ } : {}
75
99
  }, async (request, client) => {
76
100
  const isCurrent = captureSharedCodexAppServerCatalogLifetime(client);
77
101
  const models = (await listAllCodexAppServerModels({
@@ -92,8 +116,9 @@ function createCodexAppServerModelCatalog(runtime) {
92
116
  });
93
117
  if (disposed || observations.get(key) !== observation || !result.isCurrent()) return [];
94
118
  observation.models = new Set(result.models.map((model) => model.id));
95
- observation.accountType = result.accountType;
119
+ observation.accountType = !usesNativeHome || native?.mode === "api-key" && result.accountType === "apiKey" || (native?.mode === "oauth" || native?.mode === "token") && result.accountType === "chatgpt" ? result.accountType : void 0;
96
120
  observation.isCurrent = result.isCurrent;
121
+ observation.authMode = observation.accountType === "apiKey" ? "api_key" : observation.accountType === "chatgpt" && (native?.mode === "oauth" || native?.mode === "token") ? native.mode : void 0;
97
122
  return codexAppServerModelsToCatalogEntries(result.models, runtime);
98
123
  }
99
124
  };
@@ -1,4 +1,4 @@
1
- import { h as assertCodexModelListResponse } from "./client-BEKu4yDx.js";
1
+ import { h as assertCodexModelListResponse } from "./client-vXs2929Q.mjs";
2
2
  import { normalizeOptionalString, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  //#region extensions/codex/src/app-server/models.ts
4
4
  /**
@@ -37,8 +37,8 @@ async function withCodexAppServerModelRequest(options, run) {
37
37
  if (options.request) return await run(options.request);
38
38
  const timeoutMs = options.timeoutMs ?? 2500;
39
39
  const useSharedClient = options.sharedClient !== false;
40
- const { createIsolatedCodexAppServerClient, getLeasedSharedCodexAppServerClient, releaseLeasedSharedCodexAppServerClient } = await import("./shared-client-CVhez2Uo.js").then((n) => n.y);
41
- const { requestCodexAppServerClientJson } = await import("./request-CGvGOpeR.js").then((n) => n.a);
40
+ const { createIsolatedCodexAppServerClient, getLeasedSharedCodexAppServerClient, releaseLeasedSharedCodexAppServerClient } = await import("./shared-client-BpTtuLQ5.mjs").then((n) => n.y);
41
+ const { requestCodexAppServerClientJson } = await import("./request-BioXJLYa.mjs").then((n) => n.a);
42
42
  const client = await (useSharedClient ? getLeasedSharedCodexAppServerClient : createIsolatedCodexAppServerClient)({
43
43
  startOptions: options.startOptions,
44
44
  timeoutMs,
@@ -0,0 +1,57 @@
1
+ import { d as readCodexPluginConfig } from "./config-parsing-CcB9iPoq.mjs";
2
+ import { n as isCodexAppServerProxyLaunch, t as buildCodexLoginStatusArgs } from "./launch-args-DnMak49W.mjs";
3
+ import { r as resolveManagedCodexAppServerStartOptions } from "./managed-binary-DP6Rib3P.mjs";
4
+ import { n as resolveCodexAppServerSpawnEnv } from "./transport-stdio-Cmx94Oiy.mjs";
5
+ import { n as resolveCodexAppServerRuntimeOptions } from "./config-runtime-CeAhl_h4.mjs";
6
+ import { runUtf8CommandWithTimeout } from "openclaw/plugin-sdk/process-runtime";
7
+ import { materializeWindowsSpawnProgram, resolveWindowsSpawnProgram } from "openclaw/plugin-sdk/windows-spawn";
8
+ //#region extensions/codex/src/app-server/native-auth.ts
9
+ const OPENAI_LOGIN_MODES = {
10
+ "Logged in using ChatGPT": "oauth",
11
+ "Logged in using access token": "token",
12
+ "Logged in using personal access token": "token"
13
+ };
14
+ /** Ask the selected native binary about its own store; retain no credential material. */
15
+ async function probeCodexNativeAuth(params) {
16
+ params.signal?.throwIfAborted();
17
+ try {
18
+ const pluginConfig = readCodexPluginConfig(params.pluginConfig ?? params.config?.plugins?.entries?.codex?.config);
19
+ const options = resolveCodexAppServerRuntimeOptions({
20
+ pluginConfig,
21
+ env: params.env
22
+ });
23
+ if (options.start.transport !== "stdio" || options.start.homeScope !== "user" || isCodexAppServerProxyLaunch(options.start.args)) return;
24
+ const start = await resolveManagedCodexAppServerStartOptions(options.start, { pluginRoot: params.pluginRoot });
25
+ if (start.transport !== "stdio") return;
26
+ const env = resolveCodexAppServerSpawnEnv(start, params.env ?? process.env);
27
+ const invocation = materializeWindowsSpawnProgram(resolveWindowsSpawnProgram({
28
+ command: start.command,
29
+ env,
30
+ packageName: "@openai/codex"
31
+ }), buildCodexLoginStatusArgs(start.args));
32
+ const result = await runUtf8CommandWithTimeout([invocation.command, ...invocation.argv], {
33
+ baseEnv: env,
34
+ timeoutMs: 3e3,
35
+ signal: params.signal,
36
+ killProcessTree: true
37
+ });
38
+ params.signal?.throwIfAborted();
39
+ if (result.termination !== "exit" || result.code !== 0) return;
40
+ const line = `${result.stdout}\n${result.stderr}`.split("\n").map((value) => value.trim()).find((value) => value.startsWith("Logged in using "));
41
+ const mode = line?.startsWith("Logged in using an API key - ") ? "api-key" : line ? OPENAI_LOGIN_MODES[line] : void 0;
42
+ return mode ? {
43
+ apiKey: "codex-app-server",
44
+ source: "Codex native login",
45
+ mode,
46
+ nativeAuth: {
47
+ runtime: "codex",
48
+ mode
49
+ }
50
+ } : void 0;
51
+ } catch {
52
+ params.signal?.throwIfAborted();
53
+ return;
54
+ }
55
+ }
56
+ //#endregion
57
+ export { probeCodexNativeAuth };