@hintergrund/ui 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BuilderAgentPane-Vj3NCGvZ.js +25916 -0
- package/dist/IntegrationHealth-D1HcBrQn.js +218 -0
- package/dist/admin.js +22766 -28480
- package/dist/anthropic-messages-D8Vp-Ncs.js +3772 -0
- package/dist/azure-openai-responses-DnjyYuiz.js +168 -0
- package/dist/builder.js +27 -22
- package/dist/config.types-DZ5yfeqq.js +20 -0
- package/dist/deferred-tools-nxpq94I4.js +34 -0
- package/dist/diagnostics-x5QOwca_.js +91 -0
- package/dist/error-body-pXgvw5vV.js +68 -0
- package/dist/font-pool/LICENSES.txt +22 -0
- package/dist/font-pool/inter.ttf +0 -0
- package/dist/font-pool/inter.woff2 +0 -0
- package/dist/font-pool/jetbrains-mono.ttf +0 -0
- package/dist/font-pool/jetbrains-mono.woff2 +0 -0
- package/dist/font-pool/lora.ttf +0 -0
- package/dist/font-pool/lora.woff2 +0 -0
- package/dist/font-pool/merriweather.ttf +0 -0
- package/dist/font-pool/merriweather.woff2 +0 -0
- package/dist/font-pool/montserrat.ttf +0 -0
- package/dist/font-pool/montserrat.woff2 +0 -0
- package/dist/font-pool/playfair-display.ttf +0 -0
- package/dist/font-pool/playfair-display.woff2 +0 -0
- package/dist/font-pool/poppins.ttf +0 -0
- package/dist/font-pool/poppins.woff2 +0 -0
- package/dist/font-pool/roboto.ttf +0 -0
- package/dist/font-pool/roboto.woff2 +0 -0
- package/dist/font-pool/space-grotesk.ttf +0 -0
- package/dist/font-pool/space-grotesk.woff2 +0 -0
- package/dist/font-pool/work-sans.ttf +0 -0
- package/dist/font-pool/work-sans.woff2 +0 -0
- package/dist/github-copilot-headers-pRo3v4t7.js +27 -0
- package/dist/global-xsR9gLDa.js +30568 -0
- package/dist/google-generative-ai-BmzNjEvl.js +291 -0
- package/dist/google-shared-CG2Lbh1z.js +8746 -0
- package/dist/google-vertex-Dfla93V_.js +329 -0
- package/dist/hash-BixfZjoG.js +21 -0
- package/dist/headers-CnTiKpOL.js +24 -0
- package/dist/json-parse-CxjAnWaM.js +231 -0
- package/dist/legacy-Zmnk-v81.js +14 -0
- package/dist/login.js +131 -146
- package/dist/mail.js +694 -789
- package/dist/mistral-conversations-DeDb7Gbd.js +558 -0
- package/dist/openai-ClxLHXsh.js +5371 -0
- package/dist/openai-codex-responses-usgOtWUT.js +909 -0
- package/dist/openai-completions-D_nFQy7A.js +730 -0
- package/dist/openai-prompt-cache-Bm8Re6Vv.js +17 -0
- package/dist/openai-responses-BqL3PFsb.js +192 -0
- package/dist/openai-responses-shared-BhQj78KM.js +481 -0
- package/dist/pi-messages-CRx0yqMp.js +268 -0
- package/dist/pi-user-agent-CsXkkH60.js +20 -0
- package/dist/provider-env-Cj6X7Wly.js +35 -0
- package/dist/provider-retry-BGImU1PV.js +68 -0
- package/dist/rolldown-runtime-nTTD767F.js +37 -0
- package/dist/setup.js +391 -418
- package/dist/transform-messages-DvxSeyBQ.js +383 -0
- package/dist/ui.css +2 -1
- package/package.json +5 -5
- package/dist/BuilderAgentPane-CwG29LOX.js +0 -13938
- package/dist/IntegrationHealth-G_4vzV66.js +0 -209
- package/dist/anthropic-messages-BmLfYiwX.js +0 -5605
- package/dist/azure-openai-responses-yf2M6GVe.js +0 -222
- package/dist/client-Cd7yMX39.js +0 -7860
- package/dist/config.types-iZoywORE.js +0 -15
- package/dist/deferred-tools-BZWMWBYN.js +0 -28
- package/dist/error-body-BUPcH4GF.js +0 -71
- package/dist/github-copilot-headers-B1RBGoZi.js +0 -21
- package/dist/global-CTQcFve1.js +0 -36177
- package/dist/google-generative-ai-DkzwUYzL.js +0 -264
- package/dist/google-shared-DTgKMtfJ.js +0 -11710
- package/dist/google-vertex-D2IzqvQM.js +0 -305
- package/dist/hash-DFlR084x.js +0 -14
- package/dist/headers-D4iLzGaS.js +0 -21
- package/dist/json-parse-LZdWp-Nd.js +0 -232
- package/dist/legacy-CckexQcJ.js +0 -5
- package/dist/mistral-conversations-CNfKG0tU.js +0 -513
- package/dist/openai-codex-responses-BLNjExaC.js +0 -947
- package/dist/openai-completions-46IVoF2N.js +0 -741
- package/dist/openai-prompt-cache-BJwqbEDx.js +0 -13
- package/dist/openai-responses-BfHoZFHI.js +0 -184
- package/dist/openai-responses-shared-DOTQAbCj.js +0 -477
- package/dist/pi-messages-fnW87Z4Z.js +0 -251
- package/dist/pi-user-agent-CUqx-qiX.js +0 -13
- package/dist/provider-env-D2VjEV3S.js +0 -26
- package/dist/provider-retry-BsigVlMg.js +0 -67
- package/dist/select-Cke4DYH1.js +0 -78
- package/dist/transform-messages-CsKsy6b4.js +0 -398
|
@@ -1,947 +0,0 @@
|
|
|
1
|
-
import { D as he, I as we, J as ge, G as Ee, K as z } from "./BuilderAgentPane-CwG29LOX.js";
|
|
2
|
-
import { s as Se } from "./deferred-tools-BZWMWBYN.js";
|
|
3
|
-
import { f as ve, n as xe } from "./error-body-BUPcH4GF.js";
|
|
4
|
-
import { h as re } from "./headers-D4iLzGaS.js";
|
|
5
|
-
import { g as G } from "./provider-env-D2VjEV3S.js";
|
|
6
|
-
import { g as _e } from "./pi-user-agent-CUqx-qiX.js";
|
|
7
|
-
import { c as oe, b as Te } from "./transform-messages-CsKsy6b4.js";
|
|
8
|
-
import { c as ke } from "./openai-prompt-cache-BJwqbEDx.js";
|
|
9
|
-
import { c as se, a as Re, p as ne } from "./openai-responses-shared-DOTQAbCj.js";
|
|
10
|
-
typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(e) {
|
|
11
|
-
return Promise.resolve().then(e);
|
|
12
|
-
} });
|
|
13
|
-
const j = /* @__PURE__ */ new Set();
|
|
14
|
-
function Ce(e) {
|
|
15
|
-
return j.add(e), () => {
|
|
16
|
-
j.delete(e);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
let C = -1 / 0, O = 0;
|
|
20
|
-
function Oe(e) {
|
|
21
|
-
if (globalThis.crypto?.getRandomValues) {
|
|
22
|
-
globalThis.crypto.getRandomValues(e);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
for (let r = 0; r < e.length; r++)
|
|
26
|
-
e[r] = Math.floor(Math.random() * 256);
|
|
27
|
-
}
|
|
28
|
-
function Ae() {
|
|
29
|
-
const e = new Uint8Array(16);
|
|
30
|
-
Oe(e);
|
|
31
|
-
const r = Date.now();
|
|
32
|
-
r > C ? (O = e[6] * 16777216 + e[7] * 65536 + e[8] * 256 + e[9], C = r) : (O = O + 1 >>> 0, O === 0 && C++);
|
|
33
|
-
const t = new Uint8Array(16);
|
|
34
|
-
t[0] = C / 1099511627776 & 255, t[1] = C / 4294967296 & 255, t[2] = C / 16777216 & 255, t[3] = C / 65536 & 255, t[4] = C / 256 & 255, t[5] = C & 255, t[6] = 112 | O >>> 28 & 15, t[7] = O >>> 20 & 255, t[8] = 128 | O >>> 14 & 63, t[9] = O >>> 6 & 255, t[10] = (O & 63) << 2 | e[10] & 3, t[11] = e[11], t[12] = e[12], t[13] = e[13], t[14] = e[14], t[15] = e[15];
|
|
35
|
-
const o = Array.from(t, (n) => n.toString(16).padStart(2, "0"));
|
|
36
|
-
return `${o.slice(0, 4).join("")}-${o.slice(4, 6).join("")}-${o.slice(6, 8).join("")}-${o.slice(8, 10).join("")}-${o.slice(10, 16).join("")}`;
|
|
37
|
-
}
|
|
38
|
-
function Le(e) {
|
|
39
|
-
const r = e.filter((s) => s !== void 0);
|
|
40
|
-
if (r.length === 0)
|
|
41
|
-
return { cleanup: () => {
|
|
42
|
-
} };
|
|
43
|
-
if (r.length === 1)
|
|
44
|
-
return { signal: r[0], cleanup: () => {
|
|
45
|
-
} };
|
|
46
|
-
const t = new AbortController(), o = [], n = (s) => {
|
|
47
|
-
t.signal.aborted || t.abort(s.reason);
|
|
48
|
-
};
|
|
49
|
-
for (const s of r) {
|
|
50
|
-
if (s.aborted) {
|
|
51
|
-
n(s);
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
const i = () => n(s);
|
|
55
|
-
s.addEventListener("abort", i, { once: !0 }), o.push({ signal: s, listener: i });
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
signal: t.signal,
|
|
59
|
-
cleanup: () => {
|
|
60
|
-
for (const { signal: s, listener: i } of o)
|
|
61
|
-
s.removeEventListener("abort", i);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
const We = {
|
|
66
|
-
ftp: 21,
|
|
67
|
-
gopher: 70,
|
|
68
|
-
http: 80,
|
|
69
|
-
https: 443,
|
|
70
|
-
ws: 80,
|
|
71
|
-
wss: 443
|
|
72
|
-
};
|
|
73
|
-
function J(e, r) {
|
|
74
|
-
const t = e.toLowerCase(), o = e.toUpperCase();
|
|
75
|
-
return r?.[t] || r?.[o] || G(t) || G(o) || "";
|
|
76
|
-
}
|
|
77
|
-
function Pe(e) {
|
|
78
|
-
if (e instanceof URL)
|
|
79
|
-
return e;
|
|
80
|
-
try {
|
|
81
|
-
return new URL(e);
|
|
82
|
-
} catch {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function Me(e, r, t) {
|
|
87
|
-
const o = J("no_proxy", t).toLowerCase();
|
|
88
|
-
return o ? o === "*" ? !1 : o.split(/[,\s]/).every((n) => {
|
|
89
|
-
if (!n)
|
|
90
|
-
return !0;
|
|
91
|
-
const s = n.match(/^(.+):(\d+)$/);
|
|
92
|
-
let i = s ? s[1] : n;
|
|
93
|
-
const l = s ? Number.parseInt(s[2], 10) : 0;
|
|
94
|
-
return l && l !== r ? !0 : /^[.*]/.test(i) ? (i.startsWith("*") && (i = i.slice(1)), !e.endsWith(i)) : e !== i;
|
|
95
|
-
}) : !0;
|
|
96
|
-
}
|
|
97
|
-
function De(e, r) {
|
|
98
|
-
const t = Pe(e);
|
|
99
|
-
if (!t?.protocol || !t.host)
|
|
100
|
-
return "";
|
|
101
|
-
const o = t.protocol.split(":", 1)[0], n = t.host.replace(/:\d*$/, ""), s = Number.parseInt(t.port, 10) || We[o] || 0;
|
|
102
|
-
if (!Me(n, s, r))
|
|
103
|
-
return "";
|
|
104
|
-
let i = J(`${o}_proxy`, r) || J("all_proxy", r);
|
|
105
|
-
return i && !i.includes("://") && (i = `${o}://${i}`), i;
|
|
106
|
-
}
|
|
107
|
-
const Ne = "Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.";
|
|
108
|
-
function qe(e, r) {
|
|
109
|
-
const t = De(e, r);
|
|
110
|
-
if (!t)
|
|
111
|
-
return;
|
|
112
|
-
let o;
|
|
113
|
-
try {
|
|
114
|
-
o = new URL(t);
|
|
115
|
-
} catch (n) {
|
|
116
|
-
throw new Error(`Invalid proxy URL ${JSON.stringify(t)}: ${n instanceof Error ? n.message : String(n)}`);
|
|
117
|
-
}
|
|
118
|
-
if (o.protocol !== "http:" && o.protocol !== "https:")
|
|
119
|
-
throw new Error(`${Ne} Got ${o.protocol}`);
|
|
120
|
-
return o;
|
|
121
|
-
}
|
|
122
|
-
const Be = "https://chatgpt.com/backend-api", Ue = "https://api.openai.com/auth", $e = 0, V = 1e3, Ie = 6e4, Fe = 15e3, Je = 3, ie = /* @__PURE__ */ new Set(["openai", "openai-codex", "opencode"]), ze = 1009, He = "websocket_connection_limit_reached", Ke = "previous_response_not_found", Ge = /* @__PURE__ */ new Set([
|
|
123
|
-
"completed",
|
|
124
|
-
"incomplete",
|
|
125
|
-
"failed",
|
|
126
|
-
"cancelled",
|
|
127
|
-
"queued",
|
|
128
|
-
"in_progress"
|
|
129
|
-
]);
|
|
130
|
-
function X(e) {
|
|
131
|
-
if (e.stopReason === "pending")
|
|
132
|
-
throw new Error("Codex stream ended without a stop reason");
|
|
133
|
-
if (e.stopReason === "error" || e.stopReason === "aborted")
|
|
134
|
-
throw new Error(e.errorMessage || "An unknown error occurred");
|
|
135
|
-
}
|
|
136
|
-
function je(e) {
|
|
137
|
-
return /GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(e);
|
|
138
|
-
}
|
|
139
|
-
function Ve(e, r) {
|
|
140
|
-
return e === 429 && je(r) ? !1 : e === 429 || e === 500 || e === 502 || e === 503 || e === 504 ? !0 : /rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(r);
|
|
141
|
-
}
|
|
142
|
-
function Xe(e) {
|
|
143
|
-
const r = e.get("retry-after-ms");
|
|
144
|
-
if (r !== null) {
|
|
145
|
-
const s = Number(r);
|
|
146
|
-
if (Number.isFinite(s))
|
|
147
|
-
return Math.max(0, s);
|
|
148
|
-
}
|
|
149
|
-
const t = e.get("retry-after");
|
|
150
|
-
if (!t)
|
|
151
|
-
return;
|
|
152
|
-
const o = Number(t);
|
|
153
|
-
if (Number.isFinite(o))
|
|
154
|
-
return Math.max(0, o * 1e3);
|
|
155
|
-
const n = Date.parse(t);
|
|
156
|
-
if (!Number.isNaN(n))
|
|
157
|
-
return Math.max(0, n - Date.now());
|
|
158
|
-
}
|
|
159
|
-
class ae extends Error {
|
|
160
|
-
}
|
|
161
|
-
function Ye(e, r) {
|
|
162
|
-
const t = r?.maxRetryDelayMs ?? Ie;
|
|
163
|
-
if (t > 0 && e > t)
|
|
164
|
-
throw new ae(`Server requested ${Math.ceil(e / 1e3)}s retry delay (max: ${Math.ceil(t / 1e3)}s)`);
|
|
165
|
-
return e;
|
|
166
|
-
}
|
|
167
|
-
function Y(e, r) {
|
|
168
|
-
return new Promise((t, o) => {
|
|
169
|
-
if (r?.aborted) {
|
|
170
|
-
o(new Error("Request was aborted"));
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const n = setTimeout(t, e);
|
|
174
|
-
r?.addEventListener("abort", () => {
|
|
175
|
-
clearTimeout(n), o(new Error("Request was aborted"));
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
function Z(e) {
|
|
180
|
-
if (e !== void 0) {
|
|
181
|
-
if (!Number.isFinite(e) || e < 0)
|
|
182
|
-
throw new Error(`Invalid timeoutMs: ${String(e)}`);
|
|
183
|
-
return Math.floor(e);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function Ze() {
|
|
187
|
-
return typeof process > "u" || !(process.versions?.node || process.versions?.bun) ? null : process.getBuiltinModule?.("node:zlib") ?? null;
|
|
188
|
-
}
|
|
189
|
-
function Qe(e) {
|
|
190
|
-
const r = Ze();
|
|
191
|
-
if (!r || typeof r.zstdCompressSync != "function")
|
|
192
|
-
return null;
|
|
193
|
-
try {
|
|
194
|
-
const t = r.zstdCompressSync(e, {
|
|
195
|
-
params: { [r.constants.ZSTD_c_compressionLevel]: Je }
|
|
196
|
-
});
|
|
197
|
-
return new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
|
|
198
|
-
} catch {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const et = (e, r, t) => {
|
|
203
|
-
const o = new he();
|
|
204
|
-
return (async () => {
|
|
205
|
-
const n = {
|
|
206
|
-
role: "assistant",
|
|
207
|
-
content: [],
|
|
208
|
-
api: "openai-codex-responses",
|
|
209
|
-
provider: e.provider,
|
|
210
|
-
model: e.id,
|
|
211
|
-
usage: {
|
|
212
|
-
input: 0,
|
|
213
|
-
output: 0,
|
|
214
|
-
cacheRead: 0,
|
|
215
|
-
cacheWrite: 0,
|
|
216
|
-
totalTokens: 0,
|
|
217
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
|
|
218
|
-
},
|
|
219
|
-
stopReason: "pending",
|
|
220
|
-
timestamp: Date.now()
|
|
221
|
-
};
|
|
222
|
-
try {
|
|
223
|
-
const s = t?.apiKey;
|
|
224
|
-
if (!s)
|
|
225
|
-
throw new Error(`No API key for provider: ${e.provider}`);
|
|
226
|
-
const i = At(s), l = oe(r.tools, e.compat?.supportsOpenAIGrammarTools ?? !1), a = t?.cacheRetention === "none" ? void 0 : t?.sessionId, p = ke(a);
|
|
227
|
-
let u = tt(e, r, t, p, l);
|
|
228
|
-
const c = await t?.onPayload?.(u, e);
|
|
229
|
-
c !== void 0 && (u = c);
|
|
230
|
-
const f = p || Ae(), d = Lt(e.headers, t?.headers, i, s, p), m = Wt(e.headers, t?.headers, i, s, f), y = JSON.stringify(u), b = Z(t?.timeoutMs), k = Z(t?.websocketConnectTimeoutMs), h = t?.transport || "auto";
|
|
231
|
-
let x = !1;
|
|
232
|
-
const R = h !== "sse" && de(a);
|
|
233
|
-
if (R && Q(a), h !== "sse" && !R) {
|
|
234
|
-
let S = !1, v = !1, L = !1;
|
|
235
|
-
for (; ; ) {
|
|
236
|
-
S = !1;
|
|
237
|
-
try {
|
|
238
|
-
if (await Ct(ot(e.baseUrl), u, m, n, o, e, () => {
|
|
239
|
-
S = !0, x || (x = !0, o.push({ type: "start", partial: n }));
|
|
240
|
-
}, b, k, a, i, l, t), t?.signal?.aborted)
|
|
241
|
-
throw new Error("Request was aborted");
|
|
242
|
-
X(n), o.push({
|
|
243
|
-
type: "done",
|
|
244
|
-
reason: n.stopReason,
|
|
245
|
-
message: n
|
|
246
|
-
}), o.end();
|
|
247
|
-
return;
|
|
248
|
-
} catch (_) {
|
|
249
|
-
const M = t?.signal?.aborted, D = !S && it(_), W = at(_);
|
|
250
|
-
if (!M && W && !L) {
|
|
251
|
-
L = !0;
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
if (!M && D && !v) {
|
|
255
|
-
v = !0;
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
if (M || nt(_) && !D || (we(n, ge("provider_transport_failure", _, {
|
|
259
|
-
configuredTransport: h,
|
|
260
|
-
fallbackTransport: S ? void 0 : "sse",
|
|
261
|
-
eventsEmitted: S,
|
|
262
|
-
phase: S ? "after_message_stream_start" : "before_message_stream_start",
|
|
263
|
-
requestBytes: new TextEncoder().encode(y).byteLength
|
|
264
|
-
})), yt(a, _), S))
|
|
265
|
-
throw _;
|
|
266
|
-
Q(a);
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
const g = Qe(y);
|
|
272
|
-
g && d.set("content-encoding", "zstd");
|
|
273
|
-
const A = g ?? y;
|
|
274
|
-
let w, P;
|
|
275
|
-
const $ = t?.maxRetries ?? $e;
|
|
276
|
-
for (let S = 0; S <= $; S++) {
|
|
277
|
-
if (t?.signal?.aborted)
|
|
278
|
-
throw new Error("Request was aborted");
|
|
279
|
-
try {
|
|
280
|
-
const v = b !== void 0 && b > 0 ? AbortSignal.timeout(b) : void 0, L = Le([t?.signal, v]);
|
|
281
|
-
try {
|
|
282
|
-
w = await (t?.fetch ?? globalThis.fetch)(ue(e.baseUrl), {
|
|
283
|
-
method: "POST",
|
|
284
|
-
headers: d,
|
|
285
|
-
body: A,
|
|
286
|
-
signal: L.signal
|
|
287
|
-
});
|
|
288
|
-
} catch (W) {
|
|
289
|
-
throw v?.aborted && !t?.signal?.aborted ? new Error(`Codex SSE response headers timed out after ${b}ms`) : W;
|
|
290
|
-
} finally {
|
|
291
|
-
L.cleanup();
|
|
292
|
-
}
|
|
293
|
-
if (await t?.onResponse?.({ status: w.status, headers: re(w.headers) }, e), w.ok)
|
|
294
|
-
break;
|
|
295
|
-
const _ = await w.text();
|
|
296
|
-
if (S < $ && Ve(w.status, _)) {
|
|
297
|
-
const W = Xe(w.headers), be = W === void 0 ? V * 2 ** S : Ye(W, t);
|
|
298
|
-
await Y(be, t?.signal);
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
const M = new Response(_, {
|
|
302
|
-
status: w.status,
|
|
303
|
-
statusText: w.statusText
|
|
304
|
-
}), D = await Ot(M);
|
|
305
|
-
throw new Error(D.friendlyMessage || D.message);
|
|
306
|
-
} catch (v) {
|
|
307
|
-
if (v instanceof Error && (v.name === "AbortError" || v.message === "Request was aborted"))
|
|
308
|
-
throw new Error("Request was aborted");
|
|
309
|
-
if (P = v instanceof Error ? v : new Error(String(v)), S < $ && !(P instanceof ae) && !P.message.includes("usage limit")) {
|
|
310
|
-
const L = V * 2 ** S;
|
|
311
|
-
await Y(L, t?.signal);
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
throw P;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (!w?.ok)
|
|
318
|
-
throw P ?? new Error("Failed after retries");
|
|
319
|
-
if (!w.body)
|
|
320
|
-
throw new Error("No response body");
|
|
321
|
-
if (x || (x = !0, o.push({ type: "start", partial: n })), await st(w, n, o, e, l, t), t?.signal?.aborted)
|
|
322
|
-
throw new Error("Request was aborted");
|
|
323
|
-
X(n), o.push({ type: "done", reason: n.stopReason, message: n }), o.end();
|
|
324
|
-
} catch (s) {
|
|
325
|
-
for (const i of n.content)
|
|
326
|
-
delete i.partialJson, delete i.customInput;
|
|
327
|
-
n.stopReason = t?.signal?.aborted ? "aborted" : "error", n.errorMessage = ve(xe(s)), o.push({ type: "error", reason: n.stopReason, error: n }), o.end();
|
|
328
|
-
}
|
|
329
|
-
})(), o;
|
|
330
|
-
}, Ft = (e, r, t) => {
|
|
331
|
-
const o = t?.apiKey;
|
|
332
|
-
if (!o)
|
|
333
|
-
throw new Error(`No API key for provider: ${e.provider}`);
|
|
334
|
-
const n = Te(e, r, t, o), s = t?.reasoning ? Ee(e, t.reasoning) : void 0;
|
|
335
|
-
return et(e, r, {
|
|
336
|
-
...n,
|
|
337
|
-
reasoningEffort: s === "off" ? void 0 : s
|
|
338
|
-
});
|
|
339
|
-
};
|
|
340
|
-
function tt(e, r, t, o, n = oe(r.tools, e.compat?.supportsOpenAIGrammarTools ?? !1)) {
|
|
341
|
-
const s = e.compat?.supportsStrictMode ?? !0, i = e.compat?.supportsOpenAIGrammarTools ?? !1, l = e.compat?.supportsAdditionalTools ? "additional-tools" : e.compat?.supportsToolSearch ? "tool-search" : void 0, a = Se(r, l !== void 0), p = se(e, r, ie, {
|
|
342
|
-
includeSystemPrompt: !1,
|
|
343
|
-
grammarToolInputProperties: n,
|
|
344
|
-
deferredTools: a.deferred,
|
|
345
|
-
deferredToolsMode: l,
|
|
346
|
-
toolOptions: {
|
|
347
|
-
strict: null,
|
|
348
|
-
supportsStrictMode: s,
|
|
349
|
-
supportsOpenAIGrammarTools: i
|
|
350
|
-
}
|
|
351
|
-
}), u = {
|
|
352
|
-
model: e.id,
|
|
353
|
-
store: !1,
|
|
354
|
-
stream: !0,
|
|
355
|
-
instructions: r.systemPrompt || "You are a helpful assistant.",
|
|
356
|
-
input: p,
|
|
357
|
-
text: { verbosity: t?.textVerbosity || "low" },
|
|
358
|
-
include: ["reasoning.encrypted_content"],
|
|
359
|
-
prompt_cache_key: o,
|
|
360
|
-
tool_choice: t?.toolChoice ?? "auto",
|
|
361
|
-
parallel_tool_calls: !0
|
|
362
|
-
};
|
|
363
|
-
if (t?.temperature !== void 0 && (u.temperature = t.temperature), t?.serviceTier !== void 0 && (u.service_tier = t.serviceTier), a.immediate.length > 0 && (u.tools = Re(a.immediate, {
|
|
364
|
-
strict: null,
|
|
365
|
-
supportsStrictMode: s,
|
|
366
|
-
supportsOpenAIGrammarTools: i
|
|
367
|
-
})), t?.reasoningEffort !== void 0) {
|
|
368
|
-
const c = t.reasoningEffort === "none" ? e.thinkingLevelMap?.off ?? "none" : e.thinkingLevelMap?.[t.reasoningEffort] ?? t.reasoningEffort;
|
|
369
|
-
c !== null && (u.reasoning = {
|
|
370
|
-
effort: c,
|
|
371
|
-
summary: t.reasoningSummary ?? "auto"
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
return u;
|
|
375
|
-
}
|
|
376
|
-
function rt(e, r) {
|
|
377
|
-
switch (r) {
|
|
378
|
-
case "flex":
|
|
379
|
-
return 0.5;
|
|
380
|
-
case "priority":
|
|
381
|
-
return e.id === "gpt-5.5" ? 2.5 : 2;
|
|
382
|
-
default:
|
|
383
|
-
return 1;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
function ce(e, r, t) {
|
|
387
|
-
const o = rt(t, r);
|
|
388
|
-
o !== 1 && (e.cost.input *= o, e.cost.output *= o, e.cost.cacheRead *= o, e.cost.cacheWrite *= o, e.cost.total = e.cost.input + e.cost.output + e.cost.cacheRead + e.cost.cacheWrite);
|
|
389
|
-
}
|
|
390
|
-
function le(e, r) {
|
|
391
|
-
return e === "default" && (r === "flex" || r === "priority") ? r : e ?? r;
|
|
392
|
-
}
|
|
393
|
-
function ue(e) {
|
|
394
|
-
const t = (e && e.trim().length > 0 ? e : Be).replace(/\/+$/, "");
|
|
395
|
-
return t.endsWith("/codex/responses") ? t : t.endsWith("/codex") ? `${t}/responses` : `${t}/codex/responses`;
|
|
396
|
-
}
|
|
397
|
-
function ot(e) {
|
|
398
|
-
const r = new URL(ue(e));
|
|
399
|
-
return r.protocol === "https:" && (r.protocol = "wss:"), r.protocol === "http:" && (r.protocol = "ws:"), r.toString();
|
|
400
|
-
}
|
|
401
|
-
async function st(e, r, t, o, n, s) {
|
|
402
|
-
await ne(fe(ut(e, s?.signal), r), r, t, o, {
|
|
403
|
-
serviceTier: s?.serviceTier,
|
|
404
|
-
grammarToolInputProperties: n,
|
|
405
|
-
resolveServiceTier: le,
|
|
406
|
-
applyServiceTierPricing: (i, l) => ce(i, l, o)
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
class N extends Error {
|
|
410
|
-
code;
|
|
411
|
-
payload;
|
|
412
|
-
constructor(r, t) {
|
|
413
|
-
super(r), this.name = "CodexApiError", this.code = t?.code, this.payload = t?.payload, this.cause = t?.cause;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
class H extends Error {
|
|
417
|
-
payload;
|
|
418
|
-
constructor(r, t) {
|
|
419
|
-
super(r), this.name = "CodexProtocolError", this.payload = t?.payload, this.cause = t?.cause;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
function nt(e) {
|
|
423
|
-
return e instanceof N || e instanceof H;
|
|
424
|
-
}
|
|
425
|
-
function it(e) {
|
|
426
|
-
return e instanceof N && e.code === He;
|
|
427
|
-
}
|
|
428
|
-
function at(e) {
|
|
429
|
-
return e instanceof N && e.code === Ke;
|
|
430
|
-
}
|
|
431
|
-
function ct(e) {
|
|
432
|
-
const r = e.error && typeof e.error == "object" ? e.error : void 0;
|
|
433
|
-
return {
|
|
434
|
-
code: typeof e.code == "string" ? e.code : typeof r?.code == "string" ? r.code : void 0,
|
|
435
|
-
message: typeof e.message == "string" ? e.message : typeof r?.message == "string" ? r.message : void 0
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
async function* fe(e, r) {
|
|
439
|
-
for await (const t of e) {
|
|
440
|
-
const o = typeof t.type == "string" ? t.type : void 0;
|
|
441
|
-
if (o) {
|
|
442
|
-
if (o === "error") {
|
|
443
|
-
const { code: n, message: s } = ct(t);
|
|
444
|
-
throw new N(`Codex error: ${s || n || JSON.stringify(t)}`, {
|
|
445
|
-
code: n,
|
|
446
|
-
payload: t
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
if (o === "response.failed") {
|
|
450
|
-
const n = t.response, s = n?.error?.code, i = n?.error?.message;
|
|
451
|
-
throw new N(i || "Codex response failed", { code: s, payload: t });
|
|
452
|
-
}
|
|
453
|
-
if (o === "response.done" || o === "response.completed" || o === "response.incomplete") {
|
|
454
|
-
const n = t.response;
|
|
455
|
-
typeof n?.end_turn == "boolean" && (r.endTurn = n.end_turn);
|
|
456
|
-
const s = n && { ...n, status: lt(n.status) };
|
|
457
|
-
yield { ...t, type: "response.completed", response: s };
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
|
-
yield t;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
function lt(e) {
|
|
465
|
-
if (typeof e == "string")
|
|
466
|
-
return Ge.has(e) ? e : void 0;
|
|
467
|
-
}
|
|
468
|
-
async function* ut(e, r) {
|
|
469
|
-
if (!e.body)
|
|
470
|
-
return;
|
|
471
|
-
const t = e.body.getReader(), o = new TextDecoder();
|
|
472
|
-
let n = "";
|
|
473
|
-
const s = () => {
|
|
474
|
-
t.cancel().catch(() => {
|
|
475
|
-
});
|
|
476
|
-
};
|
|
477
|
-
r?.addEventListener("abort", s, { once: !0 });
|
|
478
|
-
try {
|
|
479
|
-
for (; ; ) {
|
|
480
|
-
if (r?.aborted)
|
|
481
|
-
throw new Error("Request was aborted");
|
|
482
|
-
const { done: i, value: l } = await t.read();
|
|
483
|
-
if (r?.aborted)
|
|
484
|
-
throw new Error("Request was aborted");
|
|
485
|
-
if (i)
|
|
486
|
-
break;
|
|
487
|
-
n += o.decode(l, { stream: !0 });
|
|
488
|
-
let a = n.indexOf(`
|
|
489
|
-
|
|
490
|
-
`);
|
|
491
|
-
for (; a !== -1; ) {
|
|
492
|
-
const p = n.slice(0, a);
|
|
493
|
-
n = n.slice(a + 2);
|
|
494
|
-
const u = p.split(`
|
|
495
|
-
`).filter((c) => c.startsWith("data:")).map((c) => c.slice(5).trim());
|
|
496
|
-
if (u.length > 0) {
|
|
497
|
-
const c = u.join(`
|
|
498
|
-
`).trim();
|
|
499
|
-
if (c && c !== "[DONE]")
|
|
500
|
-
try {
|
|
501
|
-
yield JSON.parse(c);
|
|
502
|
-
} catch (f) {
|
|
503
|
-
throw new H(`Invalid Codex SSE JSON: ${z(f)}`, {
|
|
504
|
-
cause: f,
|
|
505
|
-
payload: c
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
a = n.indexOf(`
|
|
510
|
-
|
|
511
|
-
`);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
} finally {
|
|
515
|
-
r?.removeEventListener("abort", s);
|
|
516
|
-
try {
|
|
517
|
-
await t.cancel();
|
|
518
|
-
} catch {
|
|
519
|
-
}
|
|
520
|
-
try {
|
|
521
|
-
t.releaseLock();
|
|
522
|
-
} catch {
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
const ft = "responses_websockets=2026-02-06", dt = 300 * 1e3, pt = 3300 * 1e3, E = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Set();
|
|
527
|
-
function K(e) {
|
|
528
|
-
let r = q.get(e);
|
|
529
|
-
return r || (r = {
|
|
530
|
-
requests: 0,
|
|
531
|
-
connectionsCreated: 0,
|
|
532
|
-
connectionsReused: 0,
|
|
533
|
-
cachedContextRequests: 0,
|
|
534
|
-
storeTrueRequests: 0,
|
|
535
|
-
fullContextRequests: 0,
|
|
536
|
-
deltaRequests: 0,
|
|
537
|
-
lastInputItems: 0,
|
|
538
|
-
websocketFailures: 0,
|
|
539
|
-
sseFallbacks: 0
|
|
540
|
-
}, q.set(e, r)), r;
|
|
541
|
-
}
|
|
542
|
-
function Jt(e) {
|
|
543
|
-
const r = q.get(e);
|
|
544
|
-
return r ? { ...r } : void 0;
|
|
545
|
-
}
|
|
546
|
-
function zt(e) {
|
|
547
|
-
if (e) {
|
|
548
|
-
q.delete(e), U.delete(e);
|
|
549
|
-
return;
|
|
550
|
-
}
|
|
551
|
-
q.clear(), U.clear();
|
|
552
|
-
}
|
|
553
|
-
function mt(e) {
|
|
554
|
-
const r = (t) => {
|
|
555
|
-
t.idleTimer && clearTimeout(t.idleTimer), T(t.socket, 1e3, "debug_close");
|
|
556
|
-
};
|
|
557
|
-
if (e) {
|
|
558
|
-
for (const t of E.get(e)?.values() ?? [])
|
|
559
|
-
r(t);
|
|
560
|
-
E.delete(e);
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
for (const t of E.values())
|
|
564
|
-
for (const o of t.values())
|
|
565
|
-
r(o);
|
|
566
|
-
E.clear();
|
|
567
|
-
}
|
|
568
|
-
Ce(mt);
|
|
569
|
-
function de(e) {
|
|
570
|
-
return e ? U.has(e) : !1;
|
|
571
|
-
}
|
|
572
|
-
function Q(e) {
|
|
573
|
-
if (!e)
|
|
574
|
-
return;
|
|
575
|
-
const r = K(e);
|
|
576
|
-
r.sseFallbacks++, r.websocketFallbackActive = de(e);
|
|
577
|
-
}
|
|
578
|
-
function yt(e, r) {
|
|
579
|
-
if (!e)
|
|
580
|
-
return;
|
|
581
|
-
U.add(e);
|
|
582
|
-
const t = K(e);
|
|
583
|
-
t.websocketFailures++, t.lastWebSocketError = z(r), t.websocketFallbackActive = !0;
|
|
584
|
-
}
|
|
585
|
-
let I = null;
|
|
586
|
-
async function bt(e) {
|
|
587
|
-
if (!e && I)
|
|
588
|
-
return I;
|
|
589
|
-
if (typeof process < "u" && process.versions?.bun) {
|
|
590
|
-
const t = class extends WebSocket {
|
|
591
|
-
constructor(o, n) {
|
|
592
|
-
let s = {};
|
|
593
|
-
Array.isArray(n) || typeof n == "string" ? s = { protocols: n } : s = { ...n };
|
|
594
|
-
const i = qe(o.toString().replace(/^wss:/, "https:").replace(/^ws:/, "http:"), e);
|
|
595
|
-
super(o, { ...s, ...i ? { proxy: i.toString() } : {} });
|
|
596
|
-
}
|
|
597
|
-
};
|
|
598
|
-
return e || (I = t), t;
|
|
599
|
-
}
|
|
600
|
-
const r = globalThis.WebSocket;
|
|
601
|
-
return typeof r != "function" ? null : r;
|
|
602
|
-
}
|
|
603
|
-
class ht extends Error {
|
|
604
|
-
code;
|
|
605
|
-
reason;
|
|
606
|
-
wasClean;
|
|
607
|
-
constructor(r, t) {
|
|
608
|
-
super(r), this.name = "WebSocketCloseError", this.code = t?.code, this.reason = t?.reason, this.wasClean = t?.wasClean;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
function wt(e) {
|
|
612
|
-
const r = e.readyState;
|
|
613
|
-
return typeof r == "number" ? r : void 0;
|
|
614
|
-
}
|
|
615
|
-
function B(e) {
|
|
616
|
-
const r = wt(e);
|
|
617
|
-
return r === void 0 || r === 1;
|
|
618
|
-
}
|
|
619
|
-
function gt(e) {
|
|
620
|
-
return Date.now() - e.createdAt >= pt;
|
|
621
|
-
}
|
|
622
|
-
function T(e, r = 1e3, t = "done") {
|
|
623
|
-
try {
|
|
624
|
-
e.close(r, t);
|
|
625
|
-
} catch {
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
function ee(e, r, t) {
|
|
629
|
-
t.idleTimer && clearTimeout(t.idleTimer), t.idleTimer = setTimeout(() => {
|
|
630
|
-
if (t.busy)
|
|
631
|
-
return;
|
|
632
|
-
T(t.socket, 1e3, "idle_timeout");
|
|
633
|
-
const o = E.get(e);
|
|
634
|
-
o?.get(r) === t && o.delete(r), o?.size === 0 && E.delete(e);
|
|
635
|
-
}, dt);
|
|
636
|
-
}
|
|
637
|
-
async function F(e, r, t, o = Fe, n) {
|
|
638
|
-
const s = await bt(n);
|
|
639
|
-
if (!s)
|
|
640
|
-
throw new Error("WebSocket transport is not available in this runtime");
|
|
641
|
-
const i = re(r);
|
|
642
|
-
return delete i["OpenAI-Beta"], new Promise((l, a) => {
|
|
643
|
-
let p = !1, u, c;
|
|
644
|
-
try {
|
|
645
|
-
c = new s(e, { headers: i });
|
|
646
|
-
} catch (h) {
|
|
647
|
-
a(h instanceof Error ? h : new Error(String(h)));
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
const f = () => {
|
|
651
|
-
u && (clearTimeout(u), u = void 0), c.removeEventListener("open", m), c.removeEventListener("error", y), c.removeEventListener("close", b), t?.removeEventListener("abort", k);
|
|
652
|
-
}, d = (h, x) => {
|
|
653
|
-
p || (p = !0, f(), x && T(c, 1e3, x), a(h));
|
|
654
|
-
}, m = () => {
|
|
655
|
-
p || (p = !0, f(), l(c));
|
|
656
|
-
}, y = (h) => {
|
|
657
|
-
d(pe(h));
|
|
658
|
-
}, b = (h) => {
|
|
659
|
-
d(me(h));
|
|
660
|
-
}, k = () => {
|
|
661
|
-
d(new Error("Request was aborted"), "aborted");
|
|
662
|
-
};
|
|
663
|
-
c.addEventListener("open", m), c.addEventListener("error", y), c.addEventListener("close", b), t?.addEventListener("abort", k), o > 0 && (u = setTimeout(() => {
|
|
664
|
-
d(new Error(`WebSocket connect timeout after ${o}ms`), "connect_timeout");
|
|
665
|
-
}, o)), t?.aborted && k();
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
async function Et(e, r, t, o, n, s, i) {
|
|
669
|
-
if (!t) {
|
|
670
|
-
const c = await F(e, r, n, s, i);
|
|
671
|
-
return {
|
|
672
|
-
socket: c,
|
|
673
|
-
reused: !1,
|
|
674
|
-
release: () => T(c)
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
let l = E.get(t);
|
|
678
|
-
const a = l?.get(o);
|
|
679
|
-
if (a) {
|
|
680
|
-
if (a.idleTimer && (clearTimeout(a.idleTimer), a.idleTimer = void 0), !a.busy && gt(a))
|
|
681
|
-
T(a.socket, 1e3, "connection_age_limit"), l?.delete(o), l?.size === 0 && E.delete(t);
|
|
682
|
-
else if (!a.busy && B(a.socket))
|
|
683
|
-
return a.busy = !0, {
|
|
684
|
-
socket: a.socket,
|
|
685
|
-
entry: a,
|
|
686
|
-
reused: !0,
|
|
687
|
-
release: ({ keep: c } = {}) => {
|
|
688
|
-
if (!c || !B(a.socket)) {
|
|
689
|
-
T(a.socket);
|
|
690
|
-
const f = E.get(t);
|
|
691
|
-
f?.get(o) === a && f.delete(o), f?.size === 0 && E.delete(t);
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
a.busy = !1, ee(t, o, a);
|
|
695
|
-
}
|
|
696
|
-
};
|
|
697
|
-
if (a.busy) {
|
|
698
|
-
const c = await F(e, r, n, s, i);
|
|
699
|
-
return {
|
|
700
|
-
socket: c,
|
|
701
|
-
reused: !1,
|
|
702
|
-
release: () => {
|
|
703
|
-
T(c);
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
B(a.socket) || (T(a.socket), l?.delete(o), l?.size === 0 && E.delete(t));
|
|
708
|
-
}
|
|
709
|
-
const p = await F(e, r, n, s, i), u = { socket: p, busy: !0, createdAt: Date.now() };
|
|
710
|
-
return l = E.get(t), l || (l = /* @__PURE__ */ new Map(), E.set(t, l)), l.set(o, u), {
|
|
711
|
-
socket: p,
|
|
712
|
-
entry: u,
|
|
713
|
-
reused: !1,
|
|
714
|
-
release: ({ keep: c } = {}) => {
|
|
715
|
-
if (!c || !B(u.socket)) {
|
|
716
|
-
T(u.socket), u.idleTimer && clearTimeout(u.idleTimer);
|
|
717
|
-
const f = E.get(t);
|
|
718
|
-
f?.get(o) === u && f.delete(o), f?.size === 0 && E.delete(t);
|
|
719
|
-
return;
|
|
720
|
-
}
|
|
721
|
-
u.busy = !1, ee(t, o, u);
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
function pe(e) {
|
|
726
|
-
if (e && typeof e == "object") {
|
|
727
|
-
const r = "message" in e ? e.message : void 0;
|
|
728
|
-
if (typeof r == "string" && r.length > 0)
|
|
729
|
-
return new Error(r);
|
|
730
|
-
const t = "error" in e ? e.error : void 0;
|
|
731
|
-
if (t instanceof Error && t.message.length > 0)
|
|
732
|
-
return t;
|
|
733
|
-
if (t && typeof t == "object" && "message" in t) {
|
|
734
|
-
const o = t.message;
|
|
735
|
-
if (typeof o == "string" && o.length > 0)
|
|
736
|
-
return new Error(o);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
return new Error("WebSocket error");
|
|
740
|
-
}
|
|
741
|
-
function me(e) {
|
|
742
|
-
if (e && typeof e == "object") {
|
|
743
|
-
const r = "code" in e ? e.code : void 0, t = "reason" in e ? e.reason : void 0, o = "wasClean" in e ? e.wasClean : void 0, n = typeof r == "number" ? ` ${r}` : "";
|
|
744
|
-
let s = typeof t == "string" && t.length > 0 ? ` ${t}` : "";
|
|
745
|
-
return !s && r === ze && (s = " message too big"), new ht(`WebSocket closed${n}${s}`.trim(), {
|
|
746
|
-
code: typeof r == "number" ? r : void 0,
|
|
747
|
-
reason: typeof t == "string" && t.length > 0 ? t : void 0,
|
|
748
|
-
wasClean: typeof o == "boolean" ? o : void 0
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
return new Error("WebSocket closed");
|
|
752
|
-
}
|
|
753
|
-
async function St(e) {
|
|
754
|
-
if (typeof e == "string")
|
|
755
|
-
return e;
|
|
756
|
-
if (e instanceof ArrayBuffer)
|
|
757
|
-
return new TextDecoder().decode(new Uint8Array(e));
|
|
758
|
-
if (ArrayBuffer.isView(e)) {
|
|
759
|
-
const r = e;
|
|
760
|
-
return new TextDecoder().decode(new Uint8Array(r.buffer, r.byteOffset, r.byteLength));
|
|
761
|
-
}
|
|
762
|
-
if (e && typeof e == "object" && "arrayBuffer" in e) {
|
|
763
|
-
const t = await e.arrayBuffer();
|
|
764
|
-
return new TextDecoder().decode(new Uint8Array(t));
|
|
765
|
-
}
|
|
766
|
-
return null;
|
|
767
|
-
}
|
|
768
|
-
async function* vt(e, r, t) {
|
|
769
|
-
const o = [];
|
|
770
|
-
let n = null, s = !1, i = null, l = !1;
|
|
771
|
-
const a = () => {
|
|
772
|
-
if (!n)
|
|
773
|
-
return;
|
|
774
|
-
const d = n;
|
|
775
|
-
n = null, d();
|
|
776
|
-
}, p = (d) => {
|
|
777
|
-
(async () => {
|
|
778
|
-
let m = null;
|
|
779
|
-
try {
|
|
780
|
-
if (!d || typeof d != "object" || !("data" in d) || (m = await St(d.data), !m))
|
|
781
|
-
return;
|
|
782
|
-
const y = JSON.parse(m), b = typeof y.type == "string" ? y.type : "";
|
|
783
|
-
(b === "response.completed" || b === "response.done" || b === "response.incomplete") && (l = !0, s = !0), o.push(y), a();
|
|
784
|
-
} catch (y) {
|
|
785
|
-
i = new H(`Invalid Codex WebSocket JSON: ${z(y)}`, {
|
|
786
|
-
cause: y,
|
|
787
|
-
payload: m
|
|
788
|
-
}), s = !0, a();
|
|
789
|
-
}
|
|
790
|
-
})();
|
|
791
|
-
}, u = (d) => {
|
|
792
|
-
i = pe(d), s = !0, a();
|
|
793
|
-
}, c = (d) => {
|
|
794
|
-
if (l) {
|
|
795
|
-
s = !0, a();
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
i || (i = me(d)), s = !0, a();
|
|
799
|
-
}, f = () => {
|
|
800
|
-
i = new Error("Request was aborted"), s = !0, a();
|
|
801
|
-
};
|
|
802
|
-
e.addEventListener("message", p), e.addEventListener("error", u), e.addEventListener("close", c), r?.addEventListener("abort", f);
|
|
803
|
-
try {
|
|
804
|
-
for (; ; ) {
|
|
805
|
-
if (r?.aborted)
|
|
806
|
-
throw new Error("Request was aborted");
|
|
807
|
-
if (o.length > 0) {
|
|
808
|
-
yield o.shift();
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
if (s)
|
|
812
|
-
break;
|
|
813
|
-
let d;
|
|
814
|
-
await new Promise((m, y) => {
|
|
815
|
-
n = m, t !== void 0 && t > 0 && (d = setTimeout(() => {
|
|
816
|
-
const b = new Error(`WebSocket idle timeout after ${t}ms`);
|
|
817
|
-
i = b, s = !0, n = null, T(e, 1e3, "idle_timeout"), y(b);
|
|
818
|
-
}, t));
|
|
819
|
-
}).finally(() => {
|
|
820
|
-
d && clearTimeout(d);
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
if (i)
|
|
824
|
-
throw i;
|
|
825
|
-
if (!l)
|
|
826
|
-
throw new Error("WebSocket stream closed before response.completed");
|
|
827
|
-
} finally {
|
|
828
|
-
e.removeEventListener("message", p), e.removeEventListener("error", u), e.removeEventListener("close", c), r?.removeEventListener("abort", f);
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
function te(e) {
|
|
832
|
-
const { input: r, previous_response_id: t, ...o } = e;
|
|
833
|
-
return o;
|
|
834
|
-
}
|
|
835
|
-
function xt(e, r) {
|
|
836
|
-
return JSON.stringify(e ?? []) === JSON.stringify(r ?? []);
|
|
837
|
-
}
|
|
838
|
-
function _t(e, r) {
|
|
839
|
-
return JSON.stringify(te(e)) === JSON.stringify(te(r));
|
|
840
|
-
}
|
|
841
|
-
function Tt(e, r) {
|
|
842
|
-
if (!_t(e, r.lastRequestBody))
|
|
843
|
-
return;
|
|
844
|
-
const t = e.input ?? [], o = [...r.lastRequestBody.input ?? [], ...r.lastResponseItems];
|
|
845
|
-
if (t.length < o.length)
|
|
846
|
-
return;
|
|
847
|
-
const n = t.slice(0, o.length);
|
|
848
|
-
if (xt(n, o))
|
|
849
|
-
return t.slice(o.length);
|
|
850
|
-
}
|
|
851
|
-
function kt(e, r) {
|
|
852
|
-
const t = e.continuation;
|
|
853
|
-
if (!t)
|
|
854
|
-
return r;
|
|
855
|
-
const o = Tt(r, t);
|
|
856
|
-
return !o || !t.lastResponseId ? (e.continuation = void 0, r) : {
|
|
857
|
-
...r,
|
|
858
|
-
previous_response_id: t.lastResponseId,
|
|
859
|
-
input: o
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
async function* Rt(e, r) {
|
|
863
|
-
let t = !1;
|
|
864
|
-
for await (const o of e)
|
|
865
|
-
t || (t = !0, r()), yield o;
|
|
866
|
-
}
|
|
867
|
-
async function Ct(e, r, t, o, n, s, i, l, a, p, u, c, f) {
|
|
868
|
-
const { socket: d, entry: m, reused: y, release: b } = await Et(e, t, p, u, f?.signal, a, f?.env);
|
|
869
|
-
let k = !0;
|
|
870
|
-
const h = f?.transport === "websocket-cached" || f?.transport === "auto", x = r, R = h && m ? kt(m, x) : x, g = p ? K(p) : void 0;
|
|
871
|
-
g && (g.requests++, y ? g.connectionsReused++ : g.connectionsCreated++, h && g.cachedContextRequests++, R.store === !0 && g.storeTrueRequests++, g.lastInputItems = R.input?.length ?? 0, R.previous_response_id ? (g.deltaRequests++, g.lastDeltaInputItems = R.input?.length ?? 0, g.lastPreviousResponseId = R.previous_response_id) : (g.fullContextRequests++, g.lastDeltaInputItems = void 0, g.lastPreviousResponseId = void 0));
|
|
872
|
-
try {
|
|
873
|
-
if (d.send(JSON.stringify({ type: "response.create", ...R })), await ne(Rt(fe(vt(d, f?.signal, l), o), i), o, n, s, {
|
|
874
|
-
serviceTier: f?.serviceTier,
|
|
875
|
-
grammarToolInputProperties: c,
|
|
876
|
-
resolveServiceTier: le,
|
|
877
|
-
applyServiceTierPricing: (A, w) => ce(A, w, s)
|
|
878
|
-
}), f?.signal?.aborted)
|
|
879
|
-
k = !1;
|
|
880
|
-
else if (h && m && o.responseId) {
|
|
881
|
-
const A = se(s, { messages: [o] }, ie, {
|
|
882
|
-
includeSystemPrompt: !1,
|
|
883
|
-
grammarToolInputProperties: c
|
|
884
|
-
}).filter((w) => w.type !== "function_call_output" && w.type !== "custom_tool_call_output");
|
|
885
|
-
m.continuation = {
|
|
886
|
-
lastRequestBody: x,
|
|
887
|
-
lastResponseId: o.responseId,
|
|
888
|
-
lastResponseItems: A
|
|
889
|
-
};
|
|
890
|
-
}
|
|
891
|
-
} catch (A) {
|
|
892
|
-
throw m && (m.continuation = void 0), k = !1, A;
|
|
893
|
-
} finally {
|
|
894
|
-
b({ keep: k });
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
async function Ot(e) {
|
|
898
|
-
const r = await e.text();
|
|
899
|
-
let t = r || e.statusText || "Request failed", o;
|
|
900
|
-
try {
|
|
901
|
-
const s = JSON.parse(r)?.error;
|
|
902
|
-
if (s) {
|
|
903
|
-
const i = s.code || s.type || "";
|
|
904
|
-
if (/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(i) || e.status === 429) {
|
|
905
|
-
const l = s.plan_type ? ` (${s.plan_type.toLowerCase()} plan)` : "", a = s.resets_at ? Math.max(0, Math.round((s.resets_at * 1e3 - Date.now()) / 6e4)) : void 0, p = a !== void 0 ? ` Try again in ~${a} min.` : "";
|
|
906
|
-
o = `You have hit your ChatGPT usage limit${l}.${p}`.trim();
|
|
907
|
-
}
|
|
908
|
-
t = s.message || o || t;
|
|
909
|
-
}
|
|
910
|
-
} catch {
|
|
911
|
-
}
|
|
912
|
-
return { message: t, friendlyMessage: o };
|
|
913
|
-
}
|
|
914
|
-
function At(e) {
|
|
915
|
-
try {
|
|
916
|
-
const r = e.split(".");
|
|
917
|
-
if (r.length !== 3)
|
|
918
|
-
throw new Error("Invalid token");
|
|
919
|
-
const o = JSON.parse(atob(r[1]))?.[Ue]?.chatgpt_account_id;
|
|
920
|
-
if (!o)
|
|
921
|
-
throw new Error("No account ID in token");
|
|
922
|
-
return o;
|
|
923
|
-
} catch {
|
|
924
|
-
throw new Error("Failed to extract accountId from token");
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
function ye(e, r, t, o) {
|
|
928
|
-
const n = new Headers(e);
|
|
929
|
-
for (const [s, i] of Object.entries(r || {}))
|
|
930
|
-
i === null ? n.delete(s) : n.set(s, i);
|
|
931
|
-
return n.set("Authorization", `Bearer ${o}`), n.set("chatgpt-account-id", t), n.set("originator", "pi"), n.set("User-Agent", _e()), n;
|
|
932
|
-
}
|
|
933
|
-
function Lt(e, r, t, o, n) {
|
|
934
|
-
const s = ye(e, r, t, o);
|
|
935
|
-
return s.set("OpenAI-Beta", "responses=experimental"), s.set("accept", "text/event-stream"), s.set("content-type", "application/json"), n && (s.set("session-id", n), s.set("x-client-request-id", n)), s;
|
|
936
|
-
}
|
|
937
|
-
function Wt(e, r, t, o, n) {
|
|
938
|
-
const s = ye(e, r, t, o);
|
|
939
|
-
return s.delete("accept"), s.delete("content-type"), s.delete("OpenAI-Beta"), s.delete("openai-beta"), s.set("OpenAI-Beta", ft), s.set("x-client-request-id", n), s.set("session-id", n), s;
|
|
940
|
-
}
|
|
941
|
-
export {
|
|
942
|
-
mt as closeOpenAICodexWebSocketSessions,
|
|
943
|
-
Jt as getOpenAICodexWebSocketDebugStats,
|
|
944
|
-
zt as resetOpenAICodexWebSocketDebugStats,
|
|
945
|
-
et as stream,
|
|
946
|
-
Ft as streamSimple
|
|
947
|
-
};
|