@hintergrund/ui 0.1.6 → 0.1.7

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.
@@ -0,0 +1,324 @@
1
+ import { D as S } from "./Builder-CHLO8Qn6.js";
2
+ import { s as v } from "./hash-DFlR084x.js";
3
+ import { p as x } from "./json-parse-CMq4Lud0.js";
4
+ import { t as T, s as _ } from "./transform-messages-CkpQp6fJ.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
+ function $(r, t) {
9
+ const l = { v: 1, id: r };
10
+ return t && (l.phase = t), JSON.stringify(l);
11
+ }
12
+ function C(r) {
13
+ if (r) {
14
+ if (r.startsWith("{"))
15
+ try {
16
+ const t = JSON.parse(r);
17
+ if (t.v === 1 && typeof t.id == "string")
18
+ return t.phase === "commentary" || t.phase === "final_answer" ? { id: t.id, phase: t.phase } : { id: t.id };
19
+ } catch {
20
+ }
21
+ return { id: r };
22
+ }
23
+ }
24
+ function z(r, t, l, y) {
25
+ const m = [], i = (s) => {
26
+ const o = s.replace(/[^a-zA-Z0-9_-]/g, "_");
27
+ return (o.length > 64 ? o.slice(0, 64) : o).replace(/_+$/, "");
28
+ }, n = (s) => {
29
+ const o = `fc_${v(s)}`;
30
+ return o.length > 64 ? o.slice(0, 64) : o;
31
+ }, k = (s, o, p) => {
32
+ if (!l.has(r.provider) || !s.includes("|"))
33
+ return i(s);
34
+ const [h, g] = s.split("|"), f = i(h);
35
+ let c = p.provider !== r.provider || p.api !== r.api ? n(g) : i(g);
36
+ return c.startsWith("fc_") || (c = i(`fc_${c}`)), `${f}|${c}`;
37
+ }, d = T(t.messages, r, k);
38
+ if ((y?.includeSystemPrompt ?? !0) && t.systemPrompt) {
39
+ const s = r.reasoning ? "developer" : "system";
40
+ m.push({
41
+ role: s,
42
+ content: _(t.systemPrompt)
43
+ });
44
+ }
45
+ let e = 0;
46
+ for (const s of d) {
47
+ if (s.role === "user")
48
+ if (typeof s.content == "string")
49
+ m.push({
50
+ role: "user",
51
+ content: [{ type: "input_text", text: _(s.content) }]
52
+ });
53
+ else {
54
+ const o = s.content.map((p) => p.type === "text" ? {
55
+ type: "input_text",
56
+ text: _(p.text)
57
+ } : {
58
+ type: "input_image",
59
+ detail: "auto",
60
+ image_url: `data:${p.mimeType};base64,${p.data}`
61
+ });
62
+ if (o.length === 0)
63
+ continue;
64
+ m.push({
65
+ role: "user",
66
+ content: o
67
+ });
68
+ }
69
+ else if (s.role === "assistant") {
70
+ const o = [], p = s, h = p.model !== r.id && p.provider === r.provider && p.api === r.api;
71
+ for (const g of s.content)
72
+ if (g.type === "thinking") {
73
+ if (g.thinkingSignature) {
74
+ const f = JSON.parse(g.thinkingSignature);
75
+ o.push(f);
76
+ }
77
+ } else if (g.type === "text") {
78
+ const f = g, u = C(f.textSignature);
79
+ let c = u?.id;
80
+ c ? c.length > 64 && (c = `msg_${v(c)}`) : c = `msg_${e}`, o.push({
81
+ type: "message",
82
+ role: "assistant",
83
+ content: [{ type: "output_text", text: _(f.text), annotations: [] }],
84
+ status: "completed",
85
+ id: c,
86
+ phase: u?.phase
87
+ });
88
+ } else if (g.type === "toolCall") {
89
+ const f = g, [u, c] = f.id.split("|");
90
+ let I = c;
91
+ h && I?.startsWith("fc_") && (I = void 0), o.push({
92
+ type: "function_call",
93
+ id: I,
94
+ call_id: u,
95
+ name: f.name,
96
+ arguments: JSON.stringify(f.arguments)
97
+ });
98
+ }
99
+ if (o.length === 0)
100
+ continue;
101
+ m.push(...o);
102
+ } else if (s.role === "toolResult") {
103
+ const o = s.content.filter((u) => u.type === "text").map((u) => u.text).join(`
104
+ `), p = s.content.some((u) => u.type === "image"), h = o.length > 0, [g] = s.toolCallId.split("|");
105
+ let f;
106
+ if (p && r.input.includes("image")) {
107
+ const u = [];
108
+ h && u.push({
109
+ type: "input_text",
110
+ text: _(o)
111
+ });
112
+ for (const c of s.content)
113
+ c.type === "image" && u.push({
114
+ type: "input_image",
115
+ detail: "auto",
116
+ image_url: `data:${c.mimeType};base64,${c.data}`
117
+ });
118
+ f = u;
119
+ } else
120
+ f = _(h ? o : "(see attached image)");
121
+ m.push({
122
+ type: "function_call_output",
123
+ call_id: g,
124
+ output: f
125
+ });
126
+ }
127
+ e++;
128
+ }
129
+ return m;
130
+ }
131
+ function M(r, t) {
132
+ const l = t?.strict === void 0 ? !1 : t.strict;
133
+ return r.map((y) => ({
134
+ type: "function",
135
+ name: y.name,
136
+ description: y.description,
137
+ parameters: y.parameters,
138
+ // TypeBox already generates JSON Schema
139
+ strict: l
140
+ }));
141
+ }
142
+ async function W(r, t, l, y, m) {
143
+ let i = null, n = null;
144
+ const k = t.content, d = () => k.length - 1;
145
+ for await (const a of r)
146
+ if (a.type === "response.created")
147
+ t.responseId = a.response.id;
148
+ else if (a.type === "response.output_item.added") {
149
+ const e = a.item;
150
+ e.type === "reasoning" ? (i = e, n = { type: "thinking", thinking: "" }, t.content.push(n), l.push({ type: "thinking_start", contentIndex: d(), partial: t })) : e.type === "message" ? (i = e, n = { type: "text", text: "" }, t.content.push(n), l.push({ type: "text_start", contentIndex: d(), partial: t })) : e.type === "function_call" && (i = e, n = {
151
+ type: "toolCall",
152
+ id: `${e.call_id}|${e.id}`,
153
+ name: e.name,
154
+ arguments: {},
155
+ partialJson: e.arguments || ""
156
+ }, t.content.push(n), l.push({ type: "toolcall_start", contentIndex: d(), partial: t }));
157
+ } else if (a.type === "response.reasoning_summary_part.added")
158
+ i && i.type === "reasoning" && (i.summary = i.summary || [], i.summary.push(a.part));
159
+ else if (a.type === "response.reasoning_summary_text.delta") {
160
+ if (i?.type === "reasoning" && n?.type === "thinking") {
161
+ i.summary = i.summary || [];
162
+ const e = i.summary[i.summary.length - 1];
163
+ e && (n.thinking += a.delta, e.text += a.delta, l.push({
164
+ type: "thinking_delta",
165
+ contentIndex: d(),
166
+ delta: a.delta,
167
+ partial: t
168
+ }));
169
+ }
170
+ } else if (a.type === "response.reasoning_summary_part.done") {
171
+ if (i?.type === "reasoning" && n?.type === "thinking") {
172
+ i.summary = i.summary || [];
173
+ const e = i.summary[i.summary.length - 1];
174
+ e && (n.thinking += `
175
+
176
+ `, e.text += `
177
+
178
+ `, l.push({
179
+ type: "thinking_delta",
180
+ contentIndex: d(),
181
+ delta: `
182
+
183
+ `,
184
+ partial: t
185
+ }));
186
+ }
187
+ } else if (a.type === "response.reasoning_text.delta")
188
+ i?.type === "reasoning" && n?.type === "thinking" && (n.thinking += a.delta, l.push({
189
+ type: "thinking_delta",
190
+ contentIndex: d(),
191
+ delta: a.delta,
192
+ partial: t
193
+ }));
194
+ else if (a.type === "response.content_part.added")
195
+ i?.type === "message" && (i.content = i.content || [], (a.part.type === "output_text" || a.part.type === "refusal") && i.content.push(a.part));
196
+ else if (a.type === "response.output_text.delta") {
197
+ if (i?.type === "message" && n?.type === "text") {
198
+ if (!i.content || i.content.length === 0)
199
+ continue;
200
+ const e = i.content[i.content.length - 1];
201
+ e?.type === "output_text" && (n.text += a.delta, e.text += a.delta, l.push({
202
+ type: "text_delta",
203
+ contentIndex: d(),
204
+ delta: a.delta,
205
+ partial: t
206
+ }));
207
+ }
208
+ } else if (a.type === "response.refusal.delta") {
209
+ if (i?.type === "message" && n?.type === "text") {
210
+ if (!i.content || i.content.length === 0)
211
+ continue;
212
+ const e = i.content[i.content.length - 1];
213
+ e?.type === "refusal" && (n.text += a.delta, e.refusal += a.delta, l.push({
214
+ type: "text_delta",
215
+ contentIndex: d(),
216
+ delta: a.delta,
217
+ partial: t
218
+ }));
219
+ }
220
+ } else if (a.type === "response.function_call_arguments.delta")
221
+ i?.type === "function_call" && n?.type === "toolCall" && (n.partialJson += a.delta, n.arguments = x(n.partialJson), l.push({
222
+ type: "toolcall_delta",
223
+ contentIndex: d(),
224
+ delta: a.delta,
225
+ partial: t
226
+ }));
227
+ else if (a.type === "response.function_call_arguments.done") {
228
+ if (i?.type === "function_call" && n?.type === "toolCall") {
229
+ const e = n.partialJson;
230
+ if (n.partialJson = a.arguments, n.arguments = x(n.partialJson), a.arguments.startsWith(e)) {
231
+ const s = a.arguments.slice(e.length);
232
+ s.length > 0 && l.push({
233
+ type: "toolcall_delta",
234
+ contentIndex: d(),
235
+ delta: s,
236
+ partial: t
237
+ });
238
+ }
239
+ }
240
+ } else if (a.type === "response.output_item.done") {
241
+ const e = a.item;
242
+ if (e.type === "reasoning" && n?.type === "thinking") {
243
+ const s = e.summary?.map((p) => p.text).join(`
244
+
245
+ `) || "", o = e.content?.map((p) => p.text).join(`
246
+
247
+ `) || "";
248
+ n.thinking = s || o || n.thinking, n.thinkingSignature = JSON.stringify(e), l.push({
249
+ type: "thinking_end",
250
+ contentIndex: d(),
251
+ content: n.thinking,
252
+ partial: t
253
+ }), n = null;
254
+ } else if (e.type === "message" && n?.type === "text")
255
+ n.text = e.content.map((s) => s.type === "output_text" ? s.text : s.refusal).join(""), n.textSignature = $(e.id, e.phase ?? void 0), l.push({
256
+ type: "text_end",
257
+ contentIndex: d(),
258
+ content: n.text,
259
+ partial: t
260
+ }), n = null;
261
+ else if (e.type === "function_call") {
262
+ const s = n?.type === "toolCall" && n.partialJson ? x(n.partialJson) : x(e.arguments || "{}");
263
+ let o;
264
+ n?.type === "toolCall" ? (n.arguments = s, delete n.partialJson, o = n) : o = {
265
+ type: "toolCall",
266
+ id: `${e.call_id}|${e.id}`,
267
+ name: e.name,
268
+ arguments: s
269
+ }, n = null, l.push({ type: "toolcall_end", contentIndex: d(), toolCall: o, partial: t });
270
+ }
271
+ } else if (a.type === "response.completed") {
272
+ const e = a.response;
273
+ if (e?.id && (t.responseId = e.id), e?.usage) {
274
+ const s = e.usage.input_tokens_details?.cached_tokens || 0;
275
+ t.usage = {
276
+ // OpenAI includes cached tokens in input_tokens, so subtract to get non-cached input
277
+ input: (e.usage.input_tokens || 0) - s,
278
+ output: e.usage.output_tokens || 0,
279
+ cacheRead: s,
280
+ cacheWrite: 0,
281
+ totalTokens: e.usage.total_tokens || 0,
282
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
283
+ };
284
+ }
285
+ if (S(y, t.usage), m?.applyServiceTierPricing) {
286
+ const s = m.resolveServiceTier ? m.resolveServiceTier(e?.service_tier, m.serviceTier) : e?.service_tier ?? m.serviceTier;
287
+ m.applyServiceTierPricing(t.usage, s);
288
+ }
289
+ t.stopReason = J(e?.status), t.content.some((s) => s.type === "toolCall") && t.stopReason === "stop" && (t.stopReason = "toolUse");
290
+ } else {
291
+ if (a.type === "error")
292
+ throw new Error(`Error Code ${a.code}: ${a.message}` || "Unknown error");
293
+ if (a.type === "response.failed") {
294
+ const e = a.response?.error, s = a.response?.incomplete_details, o = e ? `${e.code || "unknown"}: ${e.message || "no message"}` : s?.reason ? `incomplete: ${s.reason}` : "Unknown error (no error details in response)";
295
+ throw new Error(o);
296
+ }
297
+ }
298
+ }
299
+ function J(r) {
300
+ if (!r)
301
+ return "stop";
302
+ switch (r) {
303
+ case "completed":
304
+ return "stop";
305
+ case "incomplete":
306
+ return "length";
307
+ case "failed":
308
+ case "cancelled":
309
+ return "error";
310
+ // These two are wonky ...
311
+ case "in_progress":
312
+ case "queued":
313
+ return "stop";
314
+ default: {
315
+ const t = r;
316
+ throw new Error(`Unhandled stop reason: ${t}`);
317
+ }
318
+ }
319
+ }
320
+ export {
321
+ M as a,
322
+ z as c,
323
+ W as p
324
+ };
@@ -0,0 +1,132 @@
1
+ typeof globalThis.process > "u" && (globalThis.process = { env: {}, platform: "browser", version: "", versions: {}, browser: !0, nextTick: function(r) {
2
+ return Promise.resolve().then(r);
3
+ } });
4
+ function T(r) {
5
+ return r.replace(new RegExp("[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?<![\\uD800-\\uDBFF])[\\uDC00-\\uDFFF]", "g"), "");
6
+ }
7
+ function D(r, e, n) {
8
+ return {
9
+ temperature: e?.temperature,
10
+ maxTokens: e?.maxTokens ?? (r.maxTokens > 0 ? Math.min(r.maxTokens, 32e3) : void 0),
11
+ signal: e?.signal,
12
+ apiKey: n || e?.apiKey,
13
+ transport: e?.transport,
14
+ cacheRetention: e?.cacheRetention,
15
+ sessionId: e?.sessionId,
16
+ headers: e?.headers,
17
+ onPayload: e?.onPayload,
18
+ onResponse: e?.onResponse,
19
+ timeoutMs: e?.timeoutMs,
20
+ maxRetries: e?.maxRetries,
21
+ maxRetryDelayMs: e?.maxRetryDelayMs,
22
+ metadata: e?.metadata
23
+ };
24
+ }
25
+ function R(r) {
26
+ return r === "xhigh" ? "high" : r;
27
+ }
28
+ function S(r, e, n, u) {
29
+ const m = { ...{
30
+ minimal: 1024,
31
+ low: 2048,
32
+ medium: 8192,
33
+ high: 16384
34
+ }, ...u }, l = 1024, f = R(n);
35
+ let i = m[f];
36
+ const d = Math.min(r + i, e);
37
+ return d <= i && (i = Math.max(0, d - l)), { maxTokens: d, thinkingBudget: i };
38
+ }
39
+ const M = "(image omitted: model does not support images)", I = "(tool image omitted: model does not support images)";
40
+ function y(r, e) {
41
+ const n = [];
42
+ let u = !1;
43
+ for (const p of r) {
44
+ if (p.type === "image") {
45
+ u || n.push({ type: "text", text: e }), u = !0;
46
+ continue;
47
+ }
48
+ n.push(p), u = p.text === e;
49
+ }
50
+ return n;
51
+ }
52
+ function C(r, e) {
53
+ return e.input.includes("image") ? r : r.map((n) => n.role === "user" && Array.isArray(n.content) ? {
54
+ ...n,
55
+ content: y(n.content, M)
56
+ } : n.role === "toolResult" ? {
57
+ ...n,
58
+ content: y(n.content, I)
59
+ } : n);
60
+ }
61
+ function w(r, e, n) {
62
+ const u = /* @__PURE__ */ new Map(), m = C(r, e).map((o) => {
63
+ if (o.role === "user")
64
+ return o;
65
+ if (o.role === "toolResult") {
66
+ const t = u.get(o.toolCallId);
67
+ return t && t !== o.toolCallId ? { ...o, toolCallId: t } : o;
68
+ }
69
+ if (o.role === "assistant") {
70
+ const t = o, a = t.provider === e.provider && t.api === e.api && t.model === e.id, g = t.content.flatMap((s) => {
71
+ if (s.type === "thinking")
72
+ return s.redacted ? a ? s : [] : a && s.thinkingSignature ? s : !s.thinking || s.thinking.trim() === "" ? [] : a ? s : {
73
+ type: "text",
74
+ text: s.thinking
75
+ };
76
+ if (s.type === "text")
77
+ return a ? s : {
78
+ type: "text",
79
+ text: s.text
80
+ };
81
+ if (s.type === "toolCall") {
82
+ const c = s;
83
+ let h = c;
84
+ if (!a && c.thoughtSignature && (h = { ...c }, delete h.thoughtSignature), !a && n) {
85
+ const x = n(c.id, e, t);
86
+ x !== c.id && (u.set(c.id, x), h = { ...h, id: x });
87
+ }
88
+ return h;
89
+ }
90
+ return s;
91
+ });
92
+ return {
93
+ ...t,
94
+ content: g
95
+ };
96
+ }
97
+ return o;
98
+ }), l = [];
99
+ let f = [], i = /* @__PURE__ */ new Set();
100
+ const d = () => {
101
+ if (f.length > 0) {
102
+ for (const o of f)
103
+ i.has(o.id) || l.push({
104
+ role: "toolResult",
105
+ toolCallId: o.id,
106
+ toolName: o.name,
107
+ content: [{ type: "text", text: "No result provided" }],
108
+ isError: !0,
109
+ timestamp: Date.now()
110
+ });
111
+ f = [], i = /* @__PURE__ */ new Set();
112
+ }
113
+ };
114
+ for (let o = 0; o < m.length; o++) {
115
+ const t = m[o];
116
+ if (t.role === "assistant") {
117
+ d();
118
+ const a = t;
119
+ if (a.stopReason === "error" || a.stopReason === "aborted")
120
+ continue;
121
+ const g = a.content.filter((s) => s.type === "toolCall");
122
+ g.length > 0 && (f = g, i = /* @__PURE__ */ new Set()), l.push(t);
123
+ } else t.role === "toolResult" ? (i.add(t.toolCallId), l.push(t)) : (t.role === "user" && d(), l.push(t));
124
+ }
125
+ return d(), l;
126
+ }
127
+ export {
128
+ S as a,
129
+ D as b,
130
+ T as s,
131
+ w as t
132
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hintergrund/ui",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "scripts": {
5
5
  "dev": "concurrently \"vite build --watch\" \"sirv dist --port 5188 --cors --dev\"",
6
6
  "build": "vite build",
@@ -14,13 +14,15 @@
14
14
  "exports": {
15
15
  "./admin.js": "./dist/admin.js",
16
16
  "./login.js": "./dist/login.js",
17
+ "./builder.js": {
18
+ "types": "./dist/builder.d.ts",
19
+ "import": "./dist/builder.js"
20
+ },
17
21
  "./ui.css": "./dist/ui.css"
18
22
  },
19
23
  "devDependencies": {
20
- "@sveltejs/package": "^2.5.4",
21
24
  "@sveltejs/vite-plugin-svelte": "^6.2.0",
22
25
  "concurrently": "^9.2.1",
23
- "publint": "^0.3.15",
24
26
  "sirv-cli": "^3.0.0",
25
27
  "svelte": "^5.39.5",
26
28
  "svelte-check": "^4.3.2",
@@ -31,9 +33,15 @@
31
33
  "svelte"
32
34
  ],
33
35
  "dependencies": {
34
- "@hintergrund/shared": "^0.1.5",
35
- "@primer/css": "^22.0.2",
36
+ "@earendil-works/pi-agent-core": "^0.74.0",
37
+ "@earendil-works/pi-ai": "^0.74.0",
38
+ "@earendil-works/pi-web-ui": "^0.74.0",
39
+ "@hintergrund/shared": "workspace:*",
40
+ "@hintergrund/sveltekit-static-preview": "workspace:*",
41
+ "@jridgewell/sourcemap-codec": "^1.5.5",
36
42
  "@primer/octicons": "^19.19.0",
43
+ "@rich_harris/svelte-split-pane": "^3.0.0",
44
+ "@sveltejs/svelte-json-tree": "^2.2.1",
37
45
  "@tiptap/core": "^3.7.2",
38
46
  "@tiptap/extension-bold": "^3.7.2",
39
47
  "@tiptap/extension-bullet-list": "^3.7.2",
@@ -52,6 +60,8 @@
52
60
  "@tiptap/extension-underline": "^3.7.2",
53
61
  "@tiptap/pm": "^3.7.2",
54
62
  "browser-image-compression": "^2.0.2",
55
- "pdf-lib": "^1.17.1"
63
+ "esm-env": "^1.2.2",
64
+ "marked": "^17.0.1",
65
+ "typebox": "^1.1.24"
56
66
  }
57
67
  }