@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
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
function e(e) {
|
|
12
|
+
if (e === void 0) return;
|
|
13
|
+
let t = Array.from(e);
|
|
14
|
+
return t.length <= 64 ? e : t.slice(0, 64).join("");
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { e as t };
|
|
@@ -0,0 +1,192 @@
|
|
|
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 { g as e } from "./BuilderAgentPane-Vj3NCGvZ.js";
|
|
12
|
+
import { i as t } from "./diagnostics-x5QOwca_.js";
|
|
13
|
+
import { t as n } from "./provider-env-Cj6X7Wly.js";
|
|
14
|
+
import { t as r } from "./deferred-tools-nxpq94I4.js";
|
|
15
|
+
import { t as i } from "./headers-CnTiKpOL.js";
|
|
16
|
+
import { t as a } from "./provider-retry-BGImU1PV.js";
|
|
17
|
+
import { c as o, i as s } from "./transform-messages-DvxSeyBQ.js";
|
|
18
|
+
import { n as c, t as l } from "./github-copilot-headers-pRo3v4t7.js";
|
|
19
|
+
import { n as u } from "./openai-ClxLHXsh.js";
|
|
20
|
+
import { n as d, t as f } from "./error-body-pXgvw5vV.js";
|
|
21
|
+
import { t as p } from "./openai-prompt-cache-Bm8Re6Vv.js";
|
|
22
|
+
import { n as m, r as h, t as g } from "./openai-responses-shared-BhQj78KM.js";
|
|
23
|
+
//#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-responses.js
|
|
24
|
+
var _ = /* @__PURE__ */ new Set([
|
|
25
|
+
"openai",
|
|
26
|
+
"openai-codex",
|
|
27
|
+
"opencode"
|
|
28
|
+
]), v = 16;
|
|
29
|
+
function y(e, t) {
|
|
30
|
+
if (!e) return !1;
|
|
31
|
+
let n = t.toLowerCase();
|
|
32
|
+
for (let [t, r] of Object.entries(e)) if (t.toLowerCase() === n && r !== null && r.trim().length > 0) return !0;
|
|
33
|
+
return !1;
|
|
34
|
+
}
|
|
35
|
+
function b(e, t, n) {
|
|
36
|
+
if (t) return t;
|
|
37
|
+
if (y(n, "authorization") || y(n, "cf-aig-authorization")) return "unused";
|
|
38
|
+
throw Error(`No API key for provider: ${e}`);
|
|
39
|
+
}
|
|
40
|
+
function x(e) {
|
|
41
|
+
return e.provider === "openrouter" || e.baseUrl.includes("openrouter.ai") ? "openrouter" : "openai";
|
|
42
|
+
}
|
|
43
|
+
function S(e, t) {
|
|
44
|
+
return e || (n("PI_CACHE_RETENTION", t) === "long" ? "long" : "short");
|
|
45
|
+
}
|
|
46
|
+
function C(e) {
|
|
47
|
+
return {
|
|
48
|
+
supportsDeveloperRole: e.compat?.supportsDeveloperRole ?? !0,
|
|
49
|
+
sessionAffinityFormat: e.compat?.sessionAffinityFormat ?? x(e),
|
|
50
|
+
supportsLongCacheRetention: e.compat?.supportsLongCacheRetention ?? !0,
|
|
51
|
+
supportsStrictMode: e.compat?.supportsStrictMode ?? !1,
|
|
52
|
+
supportsOpenAIGrammarTools: e.compat?.supportsOpenAIGrammarTools ?? !1,
|
|
53
|
+
supportsAdditionalTools: e.compat?.supportsAdditionalTools ?? !1,
|
|
54
|
+
supportsToolSearch: e.compat?.supportsToolSearch ?? !1,
|
|
55
|
+
supportsExplicitPromptCacheMode: e.compat?.supportsExplicitPromptCacheMode ?? !1
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function w(e, t) {
|
|
59
|
+
return t === "long" && e.supportsLongCacheRetention ? "24h" : void 0;
|
|
60
|
+
}
|
|
61
|
+
function T(e) {
|
|
62
|
+
return f(d(e), "OpenAI API error");
|
|
63
|
+
}
|
|
64
|
+
var E = (e, n, r) => {
|
|
65
|
+
let s = new t();
|
|
66
|
+
return (async () => {
|
|
67
|
+
let t = {
|
|
68
|
+
role: "assistant",
|
|
69
|
+
content: [],
|
|
70
|
+
api: e.api,
|
|
71
|
+
provider: e.provider,
|
|
72
|
+
model: e.id,
|
|
73
|
+
usage: {
|
|
74
|
+
input: 0,
|
|
75
|
+
output: 0,
|
|
76
|
+
cacheRead: 0,
|
|
77
|
+
cacheWrite: 0,
|
|
78
|
+
totalTokens: 0,
|
|
79
|
+
cost: {
|
|
80
|
+
input: 0,
|
|
81
|
+
output: 0,
|
|
82
|
+
cacheRead: 0,
|
|
83
|
+
cacheWrite: 0,
|
|
84
|
+
total: 0
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
stopReason: "pending",
|
|
88
|
+
timestamp: Date.now()
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
let c = b(e.provider, r?.apiKey, r?.headers), l = S(r?.cacheRetention, r?.env) === "none" ? void 0 : r?.sessionId, u = C(e), d = o(n.tools, u.supportsOpenAIGrammarTools), f = O(e, n, c, r?.headers, r?.fetch, l), p = k(e, n, r, u, d), m = await r?.onPayload?.(p, e);
|
|
92
|
+
m !== void 0 && (p = m);
|
|
93
|
+
let g = {
|
|
94
|
+
...r?.signal ? { signal: r.signal } : {},
|
|
95
|
+
...r?.timeoutMs === void 0 ? {} : { timeout: r.timeoutMs },
|
|
96
|
+
maxRetries: 0
|
|
97
|
+
}, { data: _, response: v } = await a(() => f.responses.create(p, g).withResponse(), {
|
|
98
|
+
maxRetries: r?.maxRetries,
|
|
99
|
+
maxRetryDelayMs: r?.maxRetryDelayMs,
|
|
100
|
+
signal: r?.signal
|
|
101
|
+
});
|
|
102
|
+
if (await r?.onResponse?.({
|
|
103
|
+
status: v.status,
|
|
104
|
+
headers: i(v.headers)
|
|
105
|
+
}, e), s.push({
|
|
106
|
+
type: "start",
|
|
107
|
+
partial: t
|
|
108
|
+
}), await h(_, t, s, e, {
|
|
109
|
+
serviceTier: r?.serviceTier,
|
|
110
|
+
grammarToolInputProperties: d,
|
|
111
|
+
applyServiceTierPricing: (t, n) => j(t, n, e)
|
|
112
|
+
}), r?.signal?.aborted) throw Error("Request was aborted");
|
|
113
|
+
if (t.stopReason === "pending") throw Error("OpenAI Responses stream ended without a stop reason");
|
|
114
|
+
if (t.stopReason === "aborted" || t.stopReason === "error") throw Error(t.errorMessage || "An unknown error occurred");
|
|
115
|
+
s.push({
|
|
116
|
+
type: "done",
|
|
117
|
+
reason: t.stopReason,
|
|
118
|
+
message: t
|
|
119
|
+
}), s.end();
|
|
120
|
+
} catch (e) {
|
|
121
|
+
for (let e of t.content) delete e.index, delete e.partialJson, delete e.customInput;
|
|
122
|
+
t.stopReason = r?.signal?.aborted ? "aborted" : "error", t.errorMessage = T(e), s.push({
|
|
123
|
+
type: "error",
|
|
124
|
+
reason: t.stopReason,
|
|
125
|
+
error: t
|
|
126
|
+
}), s.end();
|
|
127
|
+
}
|
|
128
|
+
})(), s;
|
|
129
|
+
}, D = (t, n, r) => {
|
|
130
|
+
b(t.provider, r?.apiKey, r?.headers);
|
|
131
|
+
let i = s(t, n, r, r?.apiKey), a = r?.reasoning ? e(t, r.reasoning) : void 0, o = a === "off" ? void 0 : a;
|
|
132
|
+
return E(t, n, {
|
|
133
|
+
...i,
|
|
134
|
+
reasoningEffort: o
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
function O(e, t, n, r, i, a) {
|
|
138
|
+
let o = C(e), s = { ...e.headers };
|
|
139
|
+
if (e.provider === "github-copilot") {
|
|
140
|
+
let e = c(t.messages), n = l({
|
|
141
|
+
messages: t.messages,
|
|
142
|
+
hasImages: e
|
|
143
|
+
});
|
|
144
|
+
Object.assign(s, n);
|
|
145
|
+
}
|
|
146
|
+
return a && (o.sessionAffinityFormat === "openrouter" ? s["x-session-id"] = a : (o.sessionAffinityFormat === "openai" && (s.session_id = a), s["x-client-request-id"] = a)), r && Object.assign(s, r), new u({
|
|
147
|
+
apiKey: n,
|
|
148
|
+
baseURL: e.baseUrl,
|
|
149
|
+
dangerouslyAllowBrowser: !0,
|
|
150
|
+
fetch: i,
|
|
151
|
+
defaultHeaders: s
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function k(e, t, n, i = C(e), a = o(t.tools, i.supportsOpenAIGrammarTools)) {
|
|
155
|
+
let s = i.supportsAdditionalTools ? "additional-tools" : i.supportsToolSearch ? "tool-search" : void 0, c = r(t, s !== void 0), l = g(e, t, _, {
|
|
156
|
+
grammarToolInputProperties: a,
|
|
157
|
+
deferredTools: c.deferred,
|
|
158
|
+
deferredToolsMode: s,
|
|
159
|
+
toolOptions: {
|
|
160
|
+
supportsStrictMode: i.supportsStrictMode,
|
|
161
|
+
supportsOpenAIGrammarTools: i.supportsOpenAIGrammarTools
|
|
162
|
+
}
|
|
163
|
+
}), u = S(n?.cacheRetention, n?.env), d = u === "none" && i.supportsExplicitPromptCacheMode, f = {
|
|
164
|
+
model: e.id,
|
|
165
|
+
input: l,
|
|
166
|
+
stream: !0,
|
|
167
|
+
prompt_cache_key: u === "none" ? void 0 : p(n?.sessionId),
|
|
168
|
+
prompt_cache_retention: w(i, u),
|
|
169
|
+
prompt_cache_options: d ? { mode: "explicit" } : void 0,
|
|
170
|
+
store: !1
|
|
171
|
+
};
|
|
172
|
+
return n?.maxTokens && (f.max_output_tokens = Math.max(n.maxTokens, v)), n?.temperature !== void 0 && (f.temperature = n?.temperature), n?.serviceTier !== void 0 && (f.service_tier = n.serviceTier), c.immediate.length > 0 && (f.tools = m(c.immediate, {
|
|
173
|
+
supportsStrictMode: i.supportsStrictMode,
|
|
174
|
+
supportsOpenAIGrammarTools: i.supportsOpenAIGrammarTools
|
|
175
|
+
})), n?.toolChoice !== void 0 && (f.tool_choice = n.toolChoice), e.reasoning && (n?.reasoningEffort || n?.reasoningSummary ? (f.reasoning = {
|
|
176
|
+
effort: n?.reasoningEffort ? e.thinkingLevelMap?.[n.reasoningEffort] ?? n.reasoningEffort : "medium",
|
|
177
|
+
summary: n?.reasoningSummary || "auto"
|
|
178
|
+
}, f.include = ["reasoning.encrypted_content"]) : e.provider !== "github-copilot" && e.thinkingLevelMap?.off !== null && (f.reasoning = { effort: e.thinkingLevelMap?.off ?? "none" }), e.provider === "xai" && (f.include = ["reasoning.encrypted_content"])), n?.samplingParams && Object.assign(f, n.samplingParams), f;
|
|
179
|
+
}
|
|
180
|
+
function A(e, t) {
|
|
181
|
+
switch (t) {
|
|
182
|
+
case "flex": return .5;
|
|
183
|
+
case "priority": return e.id === "gpt-5.5" ? 2.5 : 2;
|
|
184
|
+
default: return 1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function j(e, t, n) {
|
|
188
|
+
let r = A(n, t);
|
|
189
|
+
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);
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
export { E as stream, D as streamSimple };
|
|
@@ -0,0 +1,481 @@
|
|
|
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 { h as e } from "./BuilderAgentPane-Vj3NCGvZ.js";
|
|
12
|
+
import { n as t } from "./json-parse-CxjAnWaM.js";
|
|
13
|
+
import { d as n, f as r, l as i, p as a, s as o, t as s, u as c } from "./transform-messages-DvxSeyBQ.js";
|
|
14
|
+
import { t as l } from "./hash-BixfZjoG.js";
|
|
15
|
+
//#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-responses-shared.js
|
|
16
|
+
function u(e, t) {
|
|
17
|
+
let n = {
|
|
18
|
+
v: 1,
|
|
19
|
+
id: e
|
|
20
|
+
};
|
|
21
|
+
return t && (n.phase = t), JSON.stringify(n);
|
|
22
|
+
}
|
|
23
|
+
function d(e) {
|
|
24
|
+
if (e) {
|
|
25
|
+
if (e.startsWith("{")) try {
|
|
26
|
+
let t = JSON.parse(e);
|
|
27
|
+
if (t.v === 1 && typeof t.id == "string") return t.phase === "commentary" || t.phase === "final_answer" ? {
|
|
28
|
+
id: t.id,
|
|
29
|
+
phase: t.phase
|
|
30
|
+
} : { id: t.id };
|
|
31
|
+
} catch {}
|
|
32
|
+
return { id: e };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function f(e, t) {
|
|
36
|
+
let n = t.filter((e) => e.type === "text").map((e) => e.text).join("\n"), r = t.filter((e) => e.type === "image"), i = n.length > 0;
|
|
37
|
+
if (r.length === 0 || !e.input.includes("image")) return a(i ? n : r.length > 0 ? "(see attached image)" : "(no tool output)");
|
|
38
|
+
let o = [];
|
|
39
|
+
i && o.push({
|
|
40
|
+
type: "input_text",
|
|
41
|
+
text: a(n)
|
|
42
|
+
});
|
|
43
|
+
for (let e of r) o.push({
|
|
44
|
+
type: "input_image",
|
|
45
|
+
detail: "auto",
|
|
46
|
+
image_url: `data:${e.mimeType};base64,${e.data}`
|
|
47
|
+
});
|
|
48
|
+
return o;
|
|
49
|
+
}
|
|
50
|
+
function p(e, t, n, r) {
|
|
51
|
+
let o = [], c = /* @__PURE__ */ new Set(), u = (e) => {
|
|
52
|
+
let t = e.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
53
|
+
return (t.length > 64 ? t.slice(0, 64) : t).replace(/_+$/, "");
|
|
54
|
+
}, p = (e) => {
|
|
55
|
+
let t = `fc_${l(e)}`;
|
|
56
|
+
return t.length > 64 ? t.slice(0, 64) : t;
|
|
57
|
+
}, h = s(t.messages, e, (t, r, i) => {
|
|
58
|
+
if (!n.has(e.provider) || !t.includes("|")) return u(t);
|
|
59
|
+
let [a, o] = t.split("|"), s = u(a), c = i.provider !== e.provider || i.api !== e.api ? p(o) : u(o);
|
|
60
|
+
return c.startsWith("fc_") || (c = u(`fc_${c}`)), `${s}|${c}`;
|
|
61
|
+
});
|
|
62
|
+
if ((r?.includeSystemPrompt ?? !0) && t.systemPrompt) {
|
|
63
|
+
let n = e.compat, r = e.reasoning && n?.supportsDeveloperRole !== !1 ? "developer" : "system";
|
|
64
|
+
o.push({
|
|
65
|
+
role: r,
|
|
66
|
+
content: a(t.systemPrompt)
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
let g = 0;
|
|
70
|
+
for (let t of h) {
|
|
71
|
+
if (t.role === "user") {
|
|
72
|
+
if (typeof t.content == "string") o.push({
|
|
73
|
+
role: "user",
|
|
74
|
+
content: [{
|
|
75
|
+
type: "input_text",
|
|
76
|
+
text: a(t.content)
|
|
77
|
+
}]
|
|
78
|
+
});
|
|
79
|
+
else {
|
|
80
|
+
let e = t.content.map((e) => e.type === "text" ? {
|
|
81
|
+
type: "input_text",
|
|
82
|
+
text: a(e.text)
|
|
83
|
+
} : {
|
|
84
|
+
type: "input_image",
|
|
85
|
+
detail: "auto",
|
|
86
|
+
image_url: `data:${e.mimeType};base64,${e.data}`
|
|
87
|
+
});
|
|
88
|
+
if (e.length === 0) continue;
|
|
89
|
+
o.push({
|
|
90
|
+
role: "user",
|
|
91
|
+
content: e
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} else if (t.role === "assistant") {
|
|
95
|
+
let n = [], s = t, c = s.provider === e.provider && s.api === e.api, u = c && s.model === e.id, f = c && s.model !== e.id, p = 0;
|
|
96
|
+
for (let e of t.content) if (e.type === "thinking") {
|
|
97
|
+
if (e.thinkingSignature) {
|
|
98
|
+
let t = JSON.parse(e.thinkingSignature);
|
|
99
|
+
n.push(t);
|
|
100
|
+
}
|
|
101
|
+
} else if (e.type === "text") {
|
|
102
|
+
let t = e, r = d(t.textSignature), i = p === 0 ? `msg_pi_${g}` : `msg_pi_${g}_${p}`;
|
|
103
|
+
p++;
|
|
104
|
+
let o = r?.id;
|
|
105
|
+
o ? o.length > 64 && (o = `msg_${l(o)}`) : o = i, n.push({
|
|
106
|
+
type: "message",
|
|
107
|
+
role: "assistant",
|
|
108
|
+
content: [{
|
|
109
|
+
type: "output_text",
|
|
110
|
+
text: a(t.text),
|
|
111
|
+
annotations: []
|
|
112
|
+
}],
|
|
113
|
+
status: "completed",
|
|
114
|
+
id: o,
|
|
115
|
+
phase: r?.phase
|
|
116
|
+
});
|
|
117
|
+
} else if (e.type === "toolCall") {
|
|
118
|
+
let t = e, [o, s] = t.id.split("|"), c = r?.grammarToolInputProperties?.get(t.name), l = s;
|
|
119
|
+
(f && l?.startsWith("fc_") || c === void 0 && !l?.startsWith("fc_")) && (l = void 0);
|
|
120
|
+
let d = u || r?.deferredTools?.has(t.name) === !0;
|
|
121
|
+
c === void 0 ? n.push({
|
|
122
|
+
type: "function_call",
|
|
123
|
+
id: l,
|
|
124
|
+
call_id: o,
|
|
125
|
+
name: t.name,
|
|
126
|
+
arguments: JSON.stringify(t.arguments),
|
|
127
|
+
...d && t.namespace !== void 0 ? { namespace: t.namespace } : {}
|
|
128
|
+
}) : n.push({
|
|
129
|
+
type: "custom_tool_call",
|
|
130
|
+
id: l,
|
|
131
|
+
call_id: o,
|
|
132
|
+
name: t.name,
|
|
133
|
+
input: a(i(t.name, t.arguments, c)),
|
|
134
|
+
...d && t.namespace !== void 0 ? { namespace: t.namespace } : {}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (n.length === 0) continue;
|
|
138
|
+
o.push(...n);
|
|
139
|
+
} else if (t.role === "toolResult") {
|
|
140
|
+
let [n] = t.toolCallId.split("|"), i = f(e, t.content);
|
|
141
|
+
r?.grammarToolInputProperties?.has(t.toolName) ? o.push({
|
|
142
|
+
type: "custom_tool_call_output",
|
|
143
|
+
call_id: n,
|
|
144
|
+
output: i
|
|
145
|
+
}) : o.push({
|
|
146
|
+
type: "function_call_output",
|
|
147
|
+
call_id: n,
|
|
148
|
+
output: i
|
|
149
|
+
});
|
|
150
|
+
let a = [];
|
|
151
|
+
for (let e of t.addedToolNames ?? []) {
|
|
152
|
+
let t = r?.deferredTools?.get(e);
|
|
153
|
+
t && !c.has(e) && (c.add(e), a.push(t));
|
|
154
|
+
}
|
|
155
|
+
if (a.length > 0 && r?.deferredToolsMode === "additional-tools") o.push({
|
|
156
|
+
type: "additional_tools",
|
|
157
|
+
role: "developer",
|
|
158
|
+
tools: m(a, r.toolOptions)
|
|
159
|
+
});
|
|
160
|
+
else if (a.length > 0 && r?.deferredToolsMode === "tool-search") {
|
|
161
|
+
let e = a.map((e) => e.name), n = `pi_tool_load_${l(`${t.toolCallId}:${e.join(",")}`)}`;
|
|
162
|
+
o.push({
|
|
163
|
+
type: "tool_search_call",
|
|
164
|
+
call_id: n,
|
|
165
|
+
execution: "client",
|
|
166
|
+
status: "completed",
|
|
167
|
+
arguments: {
|
|
168
|
+
query: e.join(" "),
|
|
169
|
+
limit: e.length
|
|
170
|
+
}
|
|
171
|
+
}), o.push({
|
|
172
|
+
type: "tool_search_output",
|
|
173
|
+
call_id: n,
|
|
174
|
+
execution: "client",
|
|
175
|
+
status: "completed",
|
|
176
|
+
tools: m(a, {
|
|
177
|
+
...r.toolOptions,
|
|
178
|
+
deferLoading: !0
|
|
179
|
+
})
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
g++;
|
|
184
|
+
}
|
|
185
|
+
return o;
|
|
186
|
+
}
|
|
187
|
+
function m(e, t) {
|
|
188
|
+
let i = t?.strict !== void 0 && t.strict, a = t?.supportsStrictMode ?? !0, o = t?.supportsOpenAIGrammarTools ?? !1;
|
|
189
|
+
return e.map((e) => {
|
|
190
|
+
let s = n(e, o);
|
|
191
|
+
if (s) return {
|
|
192
|
+
type: "custom",
|
|
193
|
+
name: e.name,
|
|
194
|
+
description: e.description,
|
|
195
|
+
format: {
|
|
196
|
+
type: "grammar",
|
|
197
|
+
syntax: s.format,
|
|
198
|
+
definition: s.definition
|
|
199
|
+
},
|
|
200
|
+
...t?.deferLoading ? { defer_loading: !0 } : {}
|
|
201
|
+
};
|
|
202
|
+
let l = r(e, a) ?? i, u = {
|
|
203
|
+
type: "function",
|
|
204
|
+
name: e.name,
|
|
205
|
+
description: e.description,
|
|
206
|
+
parameters: c(e, l === !0),
|
|
207
|
+
...t?.deferLoading ? { defer_loading: !0 } : {}
|
|
208
|
+
};
|
|
209
|
+
return a && (u.strict = l), u;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function h(e) {
|
|
213
|
+
let t = e.customInput?.property;
|
|
214
|
+
if (t === void 0) return "";
|
|
215
|
+
let n = e.arguments[t];
|
|
216
|
+
return typeof n == "string" ? n : "";
|
|
217
|
+
}
|
|
218
|
+
function g(e, t, n) {
|
|
219
|
+
let r = e.customInput;
|
|
220
|
+
if (!r) return;
|
|
221
|
+
let i = o(r.jsonBuffer, r.property, t, n);
|
|
222
|
+
return e.arguments = { [r.property]: t }, i;
|
|
223
|
+
}
|
|
224
|
+
async function _(n, r, i, a, o) {
|
|
225
|
+
let s = !1, c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), d = (e) => {
|
|
226
|
+
e.type === "message" && e.phase === "final_answer" && (r.stopReason = "stop");
|
|
227
|
+
}, f = (e, t) => {
|
|
228
|
+
let n = c.get(e);
|
|
229
|
+
return n?.type === t ? n : void 0;
|
|
230
|
+
}, p = (e, t) => {
|
|
231
|
+
t !== void 0 && i.push({
|
|
232
|
+
type: "toolcall_delta",
|
|
233
|
+
contentIndex: e.contentIndex,
|
|
234
|
+
delta: t,
|
|
235
|
+
partial: r
|
|
236
|
+
});
|
|
237
|
+
}, m = (e, t) => {
|
|
238
|
+
if (t.type === "reasoning") {
|
|
239
|
+
let t = {
|
|
240
|
+
type: "thinking",
|
|
241
|
+
thinking: ""
|
|
242
|
+
};
|
|
243
|
+
r.content.push(t);
|
|
244
|
+
let n = {
|
|
245
|
+
type: "thinking",
|
|
246
|
+
block: t,
|
|
247
|
+
contentIndex: r.content.length - 1
|
|
248
|
+
};
|
|
249
|
+
return c.set(e, n), i.push({
|
|
250
|
+
type: "thinking_start",
|
|
251
|
+
contentIndex: n.contentIndex,
|
|
252
|
+
partial: r
|
|
253
|
+
}), n;
|
|
254
|
+
}
|
|
255
|
+
if (t.type === "message") {
|
|
256
|
+
d(t);
|
|
257
|
+
let n = {
|
|
258
|
+
type: "text",
|
|
259
|
+
text: ""
|
|
260
|
+
};
|
|
261
|
+
r.content.push(n);
|
|
262
|
+
let a = {
|
|
263
|
+
type: "text",
|
|
264
|
+
block: n,
|
|
265
|
+
contentIndex: r.content.length - 1
|
|
266
|
+
};
|
|
267
|
+
return c.set(e, a), i.push({
|
|
268
|
+
type: "text_start",
|
|
269
|
+
contentIndex: a.contentIndex,
|
|
270
|
+
partial: r
|
|
271
|
+
}), a;
|
|
272
|
+
}
|
|
273
|
+
if (t.type === "function_call") {
|
|
274
|
+
let n = {
|
|
275
|
+
type: "toolCall",
|
|
276
|
+
id: `${t.call_id}|${t.id}`,
|
|
277
|
+
name: t.name,
|
|
278
|
+
arguments: {},
|
|
279
|
+
...t.namespace === void 0 ? {} : { namespace: t.namespace },
|
|
280
|
+
partialJson: t.arguments || ""
|
|
281
|
+
};
|
|
282
|
+
r.content.push(n);
|
|
283
|
+
let a = {
|
|
284
|
+
type: "toolCall",
|
|
285
|
+
block: n,
|
|
286
|
+
contentIndex: r.content.length - 1
|
|
287
|
+
};
|
|
288
|
+
return c.set(e, a), i.push({
|
|
289
|
+
type: "toolcall_start",
|
|
290
|
+
contentIndex: a.contentIndex,
|
|
291
|
+
partial: r
|
|
292
|
+
}), a;
|
|
293
|
+
}
|
|
294
|
+
if (t.type === "custom_tool_call") {
|
|
295
|
+
let n = o?.grammarToolInputProperties?.get(t.name) ?? "input", a = t.input || "", s = {
|
|
296
|
+
type: "toolCall",
|
|
297
|
+
id: `${t.call_id}|${t.id}`,
|
|
298
|
+
name: t.name,
|
|
299
|
+
arguments: { [n]: a },
|
|
300
|
+
...t.namespace === void 0 ? {} : { namespace: t.namespace },
|
|
301
|
+
customInput: {
|
|
302
|
+
property: n,
|
|
303
|
+
jsonBuffer: {
|
|
304
|
+
input: "",
|
|
305
|
+
started: !1,
|
|
306
|
+
closed: !1
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
r.content.push(s);
|
|
311
|
+
let l = {
|
|
312
|
+
type: "toolCall",
|
|
313
|
+
block: s,
|
|
314
|
+
contentIndex: r.content.length - 1
|
|
315
|
+
};
|
|
316
|
+
return c.set(e, l), i.push({
|
|
317
|
+
type: "toolcall_start",
|
|
318
|
+
contentIndex: l.contentIndex,
|
|
319
|
+
partial: r
|
|
320
|
+
}), l;
|
|
321
|
+
}
|
|
322
|
+
}, _ = (e, t) => c.get(e) ?? m(e, t), y = (e) => {
|
|
323
|
+
for (let t of e) {
|
|
324
|
+
if (t.type !== "reasoning" || !t.encrypted_content) continue;
|
|
325
|
+
let e = l.get(t.id);
|
|
326
|
+
if (!e?.thinkingSignature) continue;
|
|
327
|
+
let n = JSON.parse(e.thinkingSignature);
|
|
328
|
+
n.encrypted_content || (e.thinkingSignature = JSON.stringify({
|
|
329
|
+
...n,
|
|
330
|
+
encrypted_content: t.encrypted_content
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
}, b = (t) => {
|
|
334
|
+
if (s = !0, y(t.output ?? []), t?.id && (r.responseId = t.id), t?.usage) {
|
|
335
|
+
let e = t.usage.input_tokens_details, n = e?.cached_tokens || 0, i = e?.cache_write_tokens || 0;
|
|
336
|
+
r.usage = {
|
|
337
|
+
input: Math.max(0, (t.usage.input_tokens || 0) - n - i),
|
|
338
|
+
output: t.usage.output_tokens || 0,
|
|
339
|
+
cacheRead: n,
|
|
340
|
+
cacheWrite: i,
|
|
341
|
+
reasoning: t.usage.output_tokens_details?.reasoning_tokens || 0,
|
|
342
|
+
totalTokens: t.usage.total_tokens || 0,
|
|
343
|
+
cost: {
|
|
344
|
+
input: 0,
|
|
345
|
+
output: 0,
|
|
346
|
+
cacheRead: 0,
|
|
347
|
+
cacheWrite: 0,
|
|
348
|
+
total: 0
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
if (e(a, r.usage), o?.applyServiceTierPricing) {
|
|
353
|
+
let e = o.resolveServiceTier ? o.resolveServiceTier(t?.service_tier, o.serviceTier) : t?.service_tier ?? o.serviceTier;
|
|
354
|
+
o.applyServiceTierPricing(r.usage, e);
|
|
355
|
+
}
|
|
356
|
+
let n = t?.status, i = t?.incomplete_details, c = typeof i?.reason == "string" ? i.reason : void 0;
|
|
357
|
+
r.rawStopReason = c ? `${n}.${c}` : n;
|
|
358
|
+
let l = v(n, c);
|
|
359
|
+
r.stopReason = l.stopReason, r.errorMessage = l.errorMessage, r.content.some((e) => e.type === "toolCall") && r.stopReason === "stop" && (r.stopReason = "toolUse");
|
|
360
|
+
};
|
|
361
|
+
for await (let e of n) if (e.type === "response.created") r.responseId = e.response.id;
|
|
362
|
+
else if (e.type === "response.output_item.added") m(e.output_index, e.item);
|
|
363
|
+
else if (e.type === "response.reasoning_summary_text.delta") {
|
|
364
|
+
let t = f(e.output_index, "thinking");
|
|
365
|
+
if (!t) continue;
|
|
366
|
+
t.block.thinking += e.delta, i.push({
|
|
367
|
+
type: "thinking_delta",
|
|
368
|
+
contentIndex: t.contentIndex,
|
|
369
|
+
delta: e.delta,
|
|
370
|
+
partial: r
|
|
371
|
+
});
|
|
372
|
+
} else if (e.type === "response.reasoning_summary_part.done") {
|
|
373
|
+
let t = f(e.output_index, "thinking");
|
|
374
|
+
if (!t) continue;
|
|
375
|
+
t.block.thinking += "\n\n", i.push({
|
|
376
|
+
type: "thinking_delta",
|
|
377
|
+
contentIndex: t.contentIndex,
|
|
378
|
+
delta: "\n\n",
|
|
379
|
+
partial: r
|
|
380
|
+
});
|
|
381
|
+
} else if (e.type === "response.reasoning_text.delta") {
|
|
382
|
+
let t = f(e.output_index, "thinking");
|
|
383
|
+
if (!t) continue;
|
|
384
|
+
t.block.thinking += e.delta, i.push({
|
|
385
|
+
type: "thinking_delta",
|
|
386
|
+
contentIndex: t.contentIndex,
|
|
387
|
+
delta: e.delta,
|
|
388
|
+
partial: r
|
|
389
|
+
});
|
|
390
|
+
} else if (e.type === "response.output_text.delta") {
|
|
391
|
+
let t = f(e.output_index, "text");
|
|
392
|
+
if (!t) continue;
|
|
393
|
+
t.block.text += e.delta, i.push({
|
|
394
|
+
type: "text_delta",
|
|
395
|
+
contentIndex: t.contentIndex,
|
|
396
|
+
delta: e.delta,
|
|
397
|
+
partial: r
|
|
398
|
+
});
|
|
399
|
+
} else if (e.type === "response.refusal.delta") {
|
|
400
|
+
let t = f(e.output_index, "text");
|
|
401
|
+
if (!t) continue;
|
|
402
|
+
t.block.text += e.delta, i.push({
|
|
403
|
+
type: "text_delta",
|
|
404
|
+
contentIndex: t.contentIndex,
|
|
405
|
+
delta: e.delta,
|
|
406
|
+
partial: r
|
|
407
|
+
});
|
|
408
|
+
} else if (e.type === "response.function_call_arguments.delta") {
|
|
409
|
+
let n = f(e.output_index, "toolCall");
|
|
410
|
+
if (!n || n.block.partialJson === void 0) continue;
|
|
411
|
+
n.block.partialJson += e.delta, n.block.arguments = t(n.block.partialJson), p(n, e.delta);
|
|
412
|
+
} else if (e.type === "response.function_call_arguments.done") {
|
|
413
|
+
let n = f(e.output_index, "toolCall");
|
|
414
|
+
if (!n || n.block.partialJson === void 0) continue;
|
|
415
|
+
let r = n.block.partialJson;
|
|
416
|
+
if (n.block.partialJson = e.arguments, n.block.arguments = t(n.block.partialJson), e.arguments.startsWith(r)) {
|
|
417
|
+
let t = e.arguments.slice(r.length);
|
|
418
|
+
t.length > 0 && p(n, t);
|
|
419
|
+
}
|
|
420
|
+
} else if (e.type === "response.custom_tool_call_input.delta") {
|
|
421
|
+
let t = f(e.output_index, "toolCall");
|
|
422
|
+
if (!t || !t.block.customInput) continue;
|
|
423
|
+
p(t, g(t.block, h(t.block) + e.delta, !1));
|
|
424
|
+
} else if (e.type === "response.custom_tool_call_input.done") {
|
|
425
|
+
let t = f(e.output_index, "toolCall");
|
|
426
|
+
if (!t || !t.block.customInput) continue;
|
|
427
|
+
p(t, g(t.block, e.input, !0));
|
|
428
|
+
} else if (e.type === "response.output_item.done") {
|
|
429
|
+
let n = e.item;
|
|
430
|
+
d(n);
|
|
431
|
+
let a = _(e.output_index, n);
|
|
432
|
+
if (n.type === "reasoning" && a?.type === "thinking") {
|
|
433
|
+
let t = n.summary?.map((e) => e.text).join("\n\n") || "", o = n.content?.map((e) => e.text).join("\n\n") || "";
|
|
434
|
+
a.block.thinking = t || o || a.block.thinking, a.block.thinkingSignature = JSON.stringify(n), l.set(n.id, a.block), i.push({
|
|
435
|
+
type: "thinking_end",
|
|
436
|
+
contentIndex: a.contentIndex,
|
|
437
|
+
content: a.block.thinking,
|
|
438
|
+
partial: r
|
|
439
|
+
}), c.delete(e.output_index);
|
|
440
|
+
} else n.type === "message" && a?.type === "text" ? (a.block.text = n.content?.map((e) => e.type === "output_text" ? e.text : e.refusal).join("") || "", a.block.textSignature = u(n.id, n.phase ?? void 0), i.push({
|
|
441
|
+
type: "text_end",
|
|
442
|
+
contentIndex: a.contentIndex,
|
|
443
|
+
content: a.block.text,
|
|
444
|
+
partial: r
|
|
445
|
+
}), c.delete(e.output_index)) : n.type === "function_call" && a?.type === "toolCall" && a.block.partialJson !== void 0 ? (a.block.arguments = t(n.arguments || a.block.partialJson || "{}"), n.namespace !== void 0 && (a.block.namespace = n.namespace), delete a.block.partialJson, i.push({
|
|
446
|
+
type: "toolcall_end",
|
|
447
|
+
contentIndex: a.contentIndex,
|
|
448
|
+
toolCall: a.block,
|
|
449
|
+
partial: r
|
|
450
|
+
}), c.delete(e.output_index)) : n.type === "custom_tool_call" && a?.type === "toolCall" && a.block.customInput && (p(a, g(a.block, n.input ?? h(a.block), !0)), n.namespace !== void 0 && (a.block.namespace = n.namespace), delete a.block.customInput, i.push({
|
|
451
|
+
type: "toolcall_end",
|
|
452
|
+
contentIndex: a.contentIndex,
|
|
453
|
+
toolCall: a.block,
|
|
454
|
+
partial: r
|
|
455
|
+
}), c.delete(e.output_index));
|
|
456
|
+
} else if (e.type === "response.completed" || e.type === "response.incomplete") b(e.response);
|
|
457
|
+
else if (e.type === "error") throw Error(`Error Code ${e.code}: ${e.message}` || "Unknown error");
|
|
458
|
+
else if (e.type === "response.failed") {
|
|
459
|
+
s = !0, r.rawStopReason = e.response?.status;
|
|
460
|
+
let t = e.response?.error, n = e.response?.incomplete_details, i = t ? `${t.code || "unknown"}: ${t.message || "no message"}` : n?.reason ? `incomplete: ${n.reason}` : "Unknown error (no error details in response)";
|
|
461
|
+
throw Error(i);
|
|
462
|
+
}
|
|
463
|
+
if (!s) throw Error("OpenAI Responses stream ended before a terminal response event");
|
|
464
|
+
}
|
|
465
|
+
function v(e, t) {
|
|
466
|
+
if (!e) return { stopReason: "stop" };
|
|
467
|
+
switch (e) {
|
|
468
|
+
case "completed": return { stopReason: "stop" };
|
|
469
|
+
case "incomplete": return t === "max_output_tokens" ? { stopReason: "length" } : {
|
|
470
|
+
stopReason: "error",
|
|
471
|
+
errorMessage: t ? `Response incomplete: ${t}` : "Response incomplete without a provider reason"
|
|
472
|
+
};
|
|
473
|
+
case "failed":
|
|
474
|
+
case "cancelled": return { stopReason: "error" };
|
|
475
|
+
case "in_progress":
|
|
476
|
+
case "queued": return { stopReason: "stop" };
|
|
477
|
+
default: throw Error(`Unhandled stop reason: ${e}`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
export { m as n, _ as r, p as t };
|