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