@hintergrund/ui 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/Builder-H8tY8V9I.js +14172 -0
  2. package/dist/admin.js +11160 -9739
  3. package/dist/{anthropic-UhrJpH25.js → anthropic-messages-C3hIUlsA.js} +1134 -1055
  4. package/dist/azure-openai-responses-t7u41KMr.js +222 -0
  5. package/dist/builder.js +2 -2
  6. package/dist/client-Cd7yMX39.js +7860 -0
  7. package/dist/deferred-tools-BZWMWBYN.js +28 -0
  8. package/dist/error-body-BUPcH4GF.js +71 -0
  9. package/dist/github-copilot-headers-B1RBGoZi.js +21 -0
  10. package/dist/{global-CFcrkAa3.js → global-Bk9T4Af5.js} +17896 -16508
  11. package/dist/google-generative-ai-6ZG79NDC.js +264 -0
  12. package/dist/{google-shared-BmdaIInh.js → google-shared-C6y4fA42.js} +1135 -1104
  13. package/dist/google-vertex-f2myaAmm.js +305 -0
  14. package/dist/headers-D4iLzGaS.js +21 -0
  15. package/dist/json-parse-LZdWp-Nd.js +232 -0
  16. package/dist/login.js +79 -75
  17. package/dist/mistral-conversations-D16H8Mgq.js +513 -0
  18. package/dist/openai-codex-responses-DIHPbnIS.js +947 -0
  19. package/dist/openai-completions-vDHGFsWV.js +741 -0
  20. package/dist/{headers-u7rXGJ9f.js → openai-prompt-cache-BJwqbEDx.js} +7 -6
  21. package/dist/openai-responses-B0rjAJxx.js +184 -0
  22. package/dist/openai-responses-shared-DqdzMfa_.js +477 -0
  23. package/dist/pi-messages-DB2BtH-g.js +251 -0
  24. package/dist/pi-user-agent-CUqx-qiX.js +13 -0
  25. package/dist/provider-env-D2VjEV3S.js +26 -0
  26. package/dist/provider-retry-BsigVlMg.js +67 -0
  27. package/dist/setup.js +275 -188
  28. package/dist/transform-messages-CsKsy6b4.js +398 -0
  29. package/package.json +4 -5
  30. package/dist/Builder-B0XYsyXe.js +0 -163449
  31. package/dist/azure-openai-responses-DAC03Qw1.js +0 -203
  32. package/dist/client-Sh7wNjbG.js +0 -5277
  33. package/dist/github-copilot-headers-DWh_6bE3.js +0 -35
  34. package/dist/google-CVz_TaG6.js +0 -248
  35. package/dist/google-vertex-C6GE41DE.js +0 -285
  36. package/dist/json-parse-DmJ6NiZE.js +0 -93
  37. package/dist/mistral-DqYbzWvv.js +0 -22932
  38. package/dist/openai-codex-responses-ZWuD9ryk.js +0 -700
  39. package/dist/openai-completions-B6B2OwYj.js +0 -535
  40. package/dist/openai-responses-D9Ip2Wgd.js +0 -142
  41. package/dist/openai-responses-shared-eUUJSL4D.js +0 -324
  42. package/dist/transform-messages-CkpQp6fJ.js +0 -132
@@ -0,0 +1,251 @@
1
+ import { d as x, h as f, i as y } from "./Builder-H8tY8V9I.js";
2
+ import { p as b, h as w } from "./headers-D4iLzGaS.js";
3
+ import { p as k } from "./json-parse-LZdWp-Nd.js";
4
+ import { g as I } from "./provider-env-D2VjEV3S.js";
5
+ typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(r) {
6
+ return Promise.resolve().then(r);
7
+ } });
8
+ class h extends Error {
9
+ code;
10
+ diagnosticDetails;
11
+ constructor(t, n, e) {
12
+ super(t), this.name = "PiMessagesResponseError", this.code = n, this.diagnosticDetails = e;
13
+ }
14
+ }
15
+ function E(r) {
16
+ try {
17
+ const t = JSON.parse(r), n = t?.error;
18
+ return t && typeof n == "object" && n !== null && !Array.isArray(n) ? t : void 0;
19
+ } catch {
20
+ return;
21
+ }
22
+ }
23
+ function R(r) {
24
+ return r.length > 8192 ? `${r.slice(0, 8192)}…` : r;
25
+ }
26
+ function _(r, t, n) {
27
+ const e = typeof n?.error?.message == "string" ? n.error.message : void 0, s = typeof n?.error?.code == "string" ? n.error.code : void 0, a = e ?? t, o = s ? ` (${s})` : "";
28
+ return `${r.status} ${r.statusText}: ${a}${o}`;
29
+ }
30
+ function M(r, t, n, e) {
31
+ const s = E(e), a = typeof s?.error?.code == "string" ? s.error.code : void 0;
32
+ return new h(_(n, e, s), a, {
33
+ version: 1,
34
+ provider: r.provider,
35
+ model: r.id,
36
+ url: t.toString(),
37
+ status: n.status,
38
+ statusText: n.statusText,
39
+ error: s?.error,
40
+ body: s ? void 0 : R(e),
41
+ timestampMs: Date.now()
42
+ });
43
+ }
44
+ function m() {
45
+ return {
46
+ input: 0,
47
+ output: 0,
48
+ cacheRead: 0,
49
+ cacheWrite: 0,
50
+ totalTokens: 0,
51
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
52
+ };
53
+ }
54
+ function p(r, t) {
55
+ t && f(r, {
56
+ type: "pi_messages_rewrite",
57
+ timestamp: Date.now(),
58
+ details: { ...t }
59
+ });
60
+ }
61
+ function S(r) {
62
+ const t = {
63
+ role: "assistant",
64
+ content: [],
65
+ api: r.api,
66
+ provider: r.provider,
67
+ model: r.id,
68
+ usage: m(),
69
+ stopReason: "pending",
70
+ timestamp: Date.now()
71
+ }, n = /* @__PURE__ */ new Map();
72
+ return (e) => {
73
+ switch (e.type) {
74
+ case "done":
75
+ return Object.assign(t, {
76
+ stopReason: e.reason,
77
+ usage: e.usage,
78
+ responseId: e.responseId
79
+ }), p(t, e.rewrite), { type: "done", reason: e.reason, message: t };
80
+ case "error":
81
+ return Object.assign(t, {
82
+ stopReason: e.reason,
83
+ usage: e.usage,
84
+ errorMessage: e.errorMessage,
85
+ responseId: e.responseId
86
+ }), p(t, e.rewrite), { type: "error", reason: e.reason, error: t };
87
+ case "start":
88
+ break;
89
+ case "text_start":
90
+ t.content[e.contentIndex] = { type: "text", text: "" };
91
+ break;
92
+ case "text_delta":
93
+ t.content[e.contentIndex].text += e.delta;
94
+ break;
95
+ case "text_end":
96
+ Object.assign(t.content[e.contentIndex], {
97
+ text: e.content,
98
+ textSignature: e.contentSignature
99
+ });
100
+ break;
101
+ case "thinking_start":
102
+ t.content[e.contentIndex] = { type: "thinking", thinking: "" };
103
+ break;
104
+ case "thinking_delta":
105
+ t.content[e.contentIndex].thinking += e.delta;
106
+ break;
107
+ case "thinking_end":
108
+ Object.assign(t.content[e.contentIndex], {
109
+ thinking: e.content,
110
+ thinkingSignature: e.contentSignature,
111
+ redacted: e.redacted
112
+ });
113
+ break;
114
+ case "toolcall_start":
115
+ t.content[e.contentIndex] = {
116
+ type: "toolCall",
117
+ id: e.id,
118
+ name: e.toolName,
119
+ arguments: {}
120
+ }, n.set(e.contentIndex, "");
121
+ break;
122
+ case "toolcall_delta": {
123
+ const s = `${n.get(e.contentIndex) ?? ""}${e.delta}`;
124
+ n.set(e.contentIndex, s), t.content[e.contentIndex].arguments = k(s);
125
+ break;
126
+ }
127
+ case "toolcall_end":
128
+ return Object.assign(t.content[e.contentIndex], e.toolCall), n.delete(e.contentIndex), {
129
+ type: "toolcall_end",
130
+ contentIndex: e.contentIndex,
131
+ toolCall: t.content[e.contentIndex],
132
+ partial: t
133
+ };
134
+ }
135
+ return { ...e, partial: t };
136
+ };
137
+ }
138
+ async function* T(r) {
139
+ const t = new TextDecoder(), n = r.getReader();
140
+ let e = "";
141
+ try {
142
+ for (; ; ) {
143
+ const { done: s, value: a } = await n.read();
144
+ e += s ? t.decode() : t.decode(a, { stream: !0 }), e = e.replace(/\r\n/g, `
145
+ `);
146
+ let o = e.indexOf(`
147
+
148
+ `);
149
+ for (; o !== -1; ) {
150
+ const c = l(e.slice(0, o));
151
+ c && (yield c), e = e.slice(o + 2), o = e.indexOf(`
152
+
153
+ `);
154
+ }
155
+ if (s)
156
+ break;
157
+ }
158
+ if (e.trim()) {
159
+ const s = l(e);
160
+ s && (yield s);
161
+ }
162
+ } finally {
163
+ n.releaseLock();
164
+ }
165
+ }
166
+ function l(r) {
167
+ const t = r.split(`
168
+ `).find((n) => n.startsWith("data:"))?.slice(5).trim();
169
+ return t && t !== "[DONE]" ? JSON.parse(t) : void 0;
170
+ }
171
+ function P(r, t, n) {
172
+ const e = n ? "aborted" : "error", s = {
173
+ role: "assistant",
174
+ content: [],
175
+ api: r.api,
176
+ provider: r.provider,
177
+ model: r.id,
178
+ usage: m(),
179
+ stopReason: e,
180
+ errorMessage: t instanceof Error ? t.message : String(t),
181
+ timestamp: Date.now()
182
+ };
183
+ return !n && t instanceof h && f(s, y("pi_messages_response_failure", t, t.diagnosticDetails)), { type: "error", reason: e, error: s };
184
+ }
185
+ function $(r, t) {
186
+ return r || (I("PI_CACHE_RETENTION", t) === "long" ? "long" : void 0);
187
+ }
188
+ const D = (r, t, n) => {
189
+ const e = new x(), s = S(r);
190
+ return (async () => {
191
+ try {
192
+ const a = n?.apiKey;
193
+ if (!a)
194
+ throw new Error(`No API key provided for provider "${r.provider}"`);
195
+ const o = new URL(`${r.baseUrl.replace(/\/+$/u, "")}/messages`);
196
+ n?.debug && o.searchParams.set("debug", "1");
197
+ let c = {
198
+ model: r.id,
199
+ context: t,
200
+ options: {
201
+ temperature: n?.temperature,
202
+ maxTokens: n?.maxTokens,
203
+ reasoning: n?.reasoning,
204
+ cacheRetention: $(n?.cacheRetention, n?.env),
205
+ sessionId: n?.sessionId,
206
+ toolChoice: n?.toolChoice
207
+ }
208
+ };
209
+ const g = await n?.onPayload?.(c, r);
210
+ g !== void 0 && (c = g);
211
+ const i = await (n?.fetch ?? globalThis.fetch)(o, {
212
+ method: "POST",
213
+ headers: {
214
+ authorization: `Bearer ${a}`,
215
+ accept: "text/event-stream",
216
+ "content-type": "application/json",
217
+ ...b(n?.headers)
218
+ },
219
+ body: JSON.stringify(c),
220
+ signal: n?.signal
221
+ });
222
+ if (await n?.onResponse?.({ status: i.status, headers: w(i.headers) }, r), !i.ok) {
223
+ const d = await i.text();
224
+ throw M(r, o, i, d);
225
+ }
226
+ if (!i.body)
227
+ throw new Error(`${r.provider} response has no body`);
228
+ for await (const d of T(i.body)) {
229
+ const u = s(d);
230
+ if (e.push(u), u.type === "done" || u.type === "error")
231
+ return;
232
+ }
233
+ throw new Error(`${r.provider} stream ended without a terminal event`);
234
+ } catch (a) {
235
+ e.push(P(r, a, n?.signal?.aborted ?? !1));
236
+ }
237
+ })(), e;
238
+ }, A = (r, t, n) => {
239
+ const e = n;
240
+ return D(r, t, {
241
+ ...n,
242
+ reasoning: n?.reasoning,
243
+ toolChoice: e?.toolChoice,
244
+ debug: e?.debug
245
+ });
246
+ };
247
+ export {
248
+ h as PiMessagesResponseError,
249
+ D as stream,
250
+ A as streamSimple
251
+ };
@@ -0,0 +1,13 @@
1
+ typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(o) {
2
+ return Promise.resolve().then(o);
3
+ } });
4
+ function r() {
5
+ return typeof process > "u" || !(process.versions?.node || process.versions?.bun) ? null : process.getBuiltinModule?.("node:os") ?? null;
6
+ }
7
+ const e = r();
8
+ function s() {
9
+ return e ? `pi (${e.platform()} ${e.release()}; ${e.arch()})` : "pi (browser)";
10
+ }
11
+ export {
12
+ s as g
13
+ };
@@ -0,0 +1,26 @@
1
+ typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(e) {
2
+ return Promise.resolve().then(e);
3
+ } });
4
+ let n = null;
5
+ function i(e) {
6
+ if (!(typeof process > "u" || !process.versions?.bun || Object.keys(process.env).length > 0)) {
7
+ if (n === null) {
8
+ n = /* @__PURE__ */ new Map();
9
+ try {
10
+ const { readFileSync: o } = require("node:fs"), t = o("/proc/self/environ", "utf-8");
11
+ for (const r of t.split("\0")) {
12
+ const s = r.indexOf("=");
13
+ s > 0 && n.set(r.slice(0, s), r.slice(s + 1));
14
+ }
15
+ } catch {
16
+ }
17
+ }
18
+ return n.get(e);
19
+ }
20
+ }
21
+ function c(e, o) {
22
+ return o?.[e] || (typeof process < "u" ? process.env[e] : void 0) || i(e) || void 0;
23
+ }
24
+ export {
25
+ c as g
26
+ };
@@ -0,0 +1,67 @@
1
+ typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(e) {
2
+ return Promise.resolve().then(e);
3
+ } });
4
+ const c = 6e4;
5
+ function d(e) {
6
+ return !(e instanceof Error) || !("status" in e) || !("headers" in e) ? !1 : (e.status === void 0 || typeof e.status == "number") && (e.headers === void 0 || e.headers instanceof Headers);
7
+ }
8
+ function l(e) {
9
+ const t = e.headers?.get("x-should-retry");
10
+ return t === "true" ? !0 : t === "false" ? !1 : e.status === void 0 ? !0 : e.status === 408 || e.status === 409 || e.status === 429 || typeof e.status == "number" && e.status >= 500;
11
+ }
12
+ function u(e, t, n) {
13
+ const r = t ?? c;
14
+ if (r > 0 && e > r)
15
+ throw new Error(`Server requested ${Math.ceil(e / 1e3)}s retry delay (max: ${Math.ceil(r / 1e3)}s). ${n}`);
16
+ return e;
17
+ }
18
+ function m(e, t, n) {
19
+ const r = e.headers?.get("retry-after-ms");
20
+ if (r) {
21
+ const a = Number.parseFloat(r);
22
+ if (!Number.isNaN(a))
23
+ return u(a, n, e.message);
24
+ }
25
+ const s = e.headers?.get("retry-after");
26
+ if (s) {
27
+ const a = Number.parseFloat(s), f = Number.isNaN(a) ? Date.parse(s) - Date.now() : a * 1e3;
28
+ return u(f, n, e.message);
29
+ }
30
+ return Math.min(0.5 * 2 ** t, 8) * 1e3 * (1 - Math.random() * 0.25);
31
+ }
32
+ function i() {
33
+ const e = new Error("Request aborted");
34
+ return e.name = "AbortError", e;
35
+ }
36
+ function y(e, t) {
37
+ return new Promise((n, r) => {
38
+ if (t?.aborted) {
39
+ r(i());
40
+ return;
41
+ }
42
+ const s = () => {
43
+ clearTimeout(o), r(i());
44
+ }, o = setTimeout(() => {
45
+ t?.removeEventListener("abort", s), n();
46
+ }, Math.max(0, e));
47
+ t?.addEventListener("abort", s, { once: !0 });
48
+ });
49
+ }
50
+ async function b(e, t = {}) {
51
+ const n = t.maxRetries ?? 0;
52
+ let r = n;
53
+ for (; ; )
54
+ try {
55
+ return await e();
56
+ } catch (s) {
57
+ if (t.signal?.aborted)
58
+ throw i();
59
+ if (r <= 0 || !d(s) || !l(s))
60
+ throw s;
61
+ const o = n - r;
62
+ r--, await y(m(s, o, t.maxRetryDelayMs), t.signal);
63
+ }
64
+ }
65
+ export {
66
+ b as r
67
+ };