reifyui 0.1.0
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/LICENSE +21 -0
- package/README.md +149 -0
- package/dist/index.cjs +2026 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +1994 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -0
- package/styles/chat.css +175 -0
- package/styles/sheet.css +262 -0
- package/styles/slides.css +25 -0
- package/styles/themes/dark.css +26 -0
- package/styles/themes/light.css +26 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1994 @@
|
|
|
1
|
+
// src/stream/responses.js
|
|
2
|
+
function createResponsesDispatcher(h) {
|
|
3
|
+
const fnByIdx = {};
|
|
4
|
+
const self = {
|
|
5
|
+
responseId: null,
|
|
6
|
+
dispatch(ev) {
|
|
7
|
+
const t = ev.type;
|
|
8
|
+
switch (t) {
|
|
9
|
+
case "response.created": {
|
|
10
|
+
const resp = ev.response || {};
|
|
11
|
+
self.responseId = resp.id || self.responseId;
|
|
12
|
+
if (self.responseId) h.onCreated?.(self.responseId);
|
|
13
|
+
const sid = resp.metadata && resp.metadata.session_id || "";
|
|
14
|
+
if (sid) h.onSession?.(sid);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case "response.reasoning_summary_text.delta":
|
|
18
|
+
h.onReasoningDelta?.(ev.delta || "");
|
|
19
|
+
break;
|
|
20
|
+
case "response.output_item.added": {
|
|
21
|
+
const item = ev.item || {};
|
|
22
|
+
if (item.type === "function_call") {
|
|
23
|
+
fnByIdx[ev.output_index] = { name: item.name || "tool", callId: item.call_id || "" };
|
|
24
|
+
} else if (item.type === "function_call_output") {
|
|
25
|
+
h.onToolResult?.(item.call_id || "", String(item.output ?? ""));
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "response.function_call_arguments.done": {
|
|
30
|
+
const fn = fnByIdx[ev.output_index] || { name: "tool", callId: "" };
|
|
31
|
+
h.onToolCall?.(fn.name, ev.arguments || "", fn.callId);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
case "response.output_text.delta":
|
|
35
|
+
h.onTextDelta?.(ev.delta || "");
|
|
36
|
+
break;
|
|
37
|
+
case "response.output_text.annotation.added": {
|
|
38
|
+
const a = ev.annotation || {};
|
|
39
|
+
if (a.type === "container_file_citation") {
|
|
40
|
+
h.onFile?.({ container_id: a.container_id, file_id: a.file_id, filename: a.filename });
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case "response.completed":
|
|
45
|
+
h.onDone?.("completed", ev.response);
|
|
46
|
+
break;
|
|
47
|
+
case "response.incomplete":
|
|
48
|
+
h.onDone?.("incomplete", ev.response);
|
|
49
|
+
break;
|
|
50
|
+
case "response.failed":
|
|
51
|
+
h.onDone?.(ev.response && ev.response.status || "failed", ev.response);
|
|
52
|
+
break;
|
|
53
|
+
case "error":
|
|
54
|
+
h.onError?.(ev.message || "stream error");
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
return self;
|
|
62
|
+
}
|
|
63
|
+
async function readSSEStream(body, onData) {
|
|
64
|
+
const reader = body.getReader();
|
|
65
|
+
const decoder = new TextDecoder();
|
|
66
|
+
let buf = "";
|
|
67
|
+
for (; ; ) {
|
|
68
|
+
const { value, done } = await reader.read();
|
|
69
|
+
if (done) break;
|
|
70
|
+
buf += decoder.decode(value, { stream: true });
|
|
71
|
+
let nl;
|
|
72
|
+
while ((nl = buf.indexOf("\n\n")) !== -1) {
|
|
73
|
+
const frame = buf.slice(0, nl);
|
|
74
|
+
buf = buf.slice(nl + 2);
|
|
75
|
+
const data = frame.split("\n").filter((l) => l.startsWith("data:")).map((l) => l.slice(5).trim()).join("");
|
|
76
|
+
if (!data) continue;
|
|
77
|
+
onData(data);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function pumpResponsesStream(body, handlers) {
|
|
82
|
+
const d = createResponsesDispatcher(handlers);
|
|
83
|
+
await readSSEStream(body, (data) => {
|
|
84
|
+
try {
|
|
85
|
+
d.dispatch(JSON.parse(data));
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return d.responseId;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/state/blocks.js
|
|
93
|
+
function withText(blocks, d) {
|
|
94
|
+
const out = blocks.slice();
|
|
95
|
+
const last = out[out.length - 1];
|
|
96
|
+
if (last && last.kind === "text") out[out.length - 1] = { kind: "text", text: last.text + d };
|
|
97
|
+
else out.push({ kind: "text", text: d });
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
function withReasoning(blocks, d) {
|
|
101
|
+
const out = blocks.slice();
|
|
102
|
+
const last = out[out.length - 1];
|
|
103
|
+
if (last && last.kind === "tools") out[out.length - 1] = { ...last, reasoning: last.reasoning + d };
|
|
104
|
+
else out.push({ kind: "tools", reasoning: d, steps: [] });
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function withStep(blocks, step) {
|
|
108
|
+
const out = blocks.slice();
|
|
109
|
+
const last = out[out.length - 1];
|
|
110
|
+
if (last && last.kind === "tools") out[out.length - 1] = { ...last, steps: [...last.steps, step] };
|
|
111
|
+
else out.push({ kind: "tools", reasoning: "", steps: [step] });
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
function withResult(blocks, callId, output) {
|
|
115
|
+
return blocks.map((b) => b.kind !== "tools" ? b : { ...b, steps: b.steps.map((t) => t.callId && t.callId === callId && t.result === void 0 ? { ...t, result: output } : t) });
|
|
116
|
+
}
|
|
117
|
+
function asstText(a) {
|
|
118
|
+
return a.blocks.filter((b) => b.kind === "text").map((b) => b.text).join("\n\n");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/state/conversationStore.js
|
|
122
|
+
import { useSyncExternalStore } from "react";
|
|
123
|
+
function createConversationStore(makeInitial) {
|
|
124
|
+
const initial = makeInitial || (() => ({ msgs: [], busy: false, prevId: null, firstTurn: true, loaded: false }));
|
|
125
|
+
const store = /* @__PURE__ */ new Map();
|
|
126
|
+
const subs = /* @__PURE__ */ new Map();
|
|
127
|
+
function get(key) {
|
|
128
|
+
let s = store.get(key);
|
|
129
|
+
if (!s) {
|
|
130
|
+
s = initial();
|
|
131
|
+
store.set(key, s);
|
|
132
|
+
}
|
|
133
|
+
return s;
|
|
134
|
+
}
|
|
135
|
+
function set(key, patch) {
|
|
136
|
+
const cur = get(key);
|
|
137
|
+
const p = typeof patch === "function" ? patch(cur) : patch;
|
|
138
|
+
store.set(key, { ...cur, ...p });
|
|
139
|
+
subs.get(key)?.forEach((f) => f());
|
|
140
|
+
}
|
|
141
|
+
function seed(key, state) {
|
|
142
|
+
store.set(key, state);
|
|
143
|
+
subs.get(key)?.forEach((f) => f());
|
|
144
|
+
}
|
|
145
|
+
function updateLastAssistant(key, fn) {
|
|
146
|
+
set(key, (s) => {
|
|
147
|
+
const out = s.msgs.slice();
|
|
148
|
+
for (let i = out.length - 1; i >= 0; i--) {
|
|
149
|
+
if (out[i].role === "assistant") {
|
|
150
|
+
const a = { ...out[i] };
|
|
151
|
+
fn(a);
|
|
152
|
+
out[i] = a;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { msgs: out };
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function use(key) {
|
|
160
|
+
return useSyncExternalStore(
|
|
161
|
+
(cb) => {
|
|
162
|
+
let set_ = subs.get(key);
|
|
163
|
+
if (!set_) {
|
|
164
|
+
set_ = /* @__PURE__ */ new Set();
|
|
165
|
+
subs.set(key, set_);
|
|
166
|
+
}
|
|
167
|
+
set_.add(cb);
|
|
168
|
+
return () => {
|
|
169
|
+
set_.delete(cb);
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
() => get(key),
|
|
173
|
+
() => get(key)
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return { get, set, seed, updateLastAssistant, use };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/components/icons.jsx
|
|
180
|
+
import React from "react";
|
|
181
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
182
|
+
function Svg({ children, s = 16 }) {
|
|
183
|
+
return /* @__PURE__ */ jsx(
|
|
184
|
+
"svg",
|
|
185
|
+
{
|
|
186
|
+
width: s,
|
|
187
|
+
height: s,
|
|
188
|
+
viewBox: "0 0 24 24",
|
|
189
|
+
fill: "none",
|
|
190
|
+
stroke: "currentColor",
|
|
191
|
+
strokeWidth: "1.8",
|
|
192
|
+
strokeLinecap: "round",
|
|
193
|
+
strokeLinejoin: "round",
|
|
194
|
+
children
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
function Chevron({ dir, size = 16 }) {
|
|
199
|
+
const d = dir === "left" ? "M15 18l-6-6 6-6" : dir === "right" ? "M9 18l6-6-6-6" : "M6 9l6 6 6-6";
|
|
200
|
+
return /* @__PURE__ */ jsx(
|
|
201
|
+
"svg",
|
|
202
|
+
{
|
|
203
|
+
width: size,
|
|
204
|
+
height: size,
|
|
205
|
+
viewBox: "0 0 24 24",
|
|
206
|
+
fill: "none",
|
|
207
|
+
stroke: "currentColor",
|
|
208
|
+
strokeWidth: "2",
|
|
209
|
+
strokeLinecap: "round",
|
|
210
|
+
strokeLinejoin: "round",
|
|
211
|
+
children: /* @__PURE__ */ jsx("path", { d })
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
var IcTool = () => /* @__PURE__ */ jsx(Svg, { s: 17, children: /* @__PURE__ */ jsx("path", { d: "M14.7 6.3a4 4 0 0 1-5.4 5.4L4 17v3h3l5.3-5.3a4 4 0 0 1 5.4-5.4l-2.3 2.3-1.7-1.7 2.3-2.3a4 4 0 0 0-1.6 0Z" }) });
|
|
216
|
+
var IcPlug = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
217
|
+
/* @__PURE__ */ jsx("path", { d: "M9 2v6M15 2v6M6 8h12v3a6 6 0 0 1-12 0z" }),
|
|
218
|
+
/* @__PURE__ */ jsx("path", { d: "M12 17v5" })
|
|
219
|
+
] });
|
|
220
|
+
var IcSkill = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
221
|
+
/* @__PURE__ */ jsx("path", { d: "M9 18h6M10 22h4" }),
|
|
222
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2a7 7 0 0 0-4 12.7c.6.5 1 1.3 1 2.1V18h6v-1.2c0-.8.4-1.6 1-2.1A7 7 0 0 0 12 2z" })
|
|
223
|
+
] });
|
|
224
|
+
var IcTerminal = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
225
|
+
/* @__PURE__ */ jsx("rect", { x: "3", y: "4", width: "18", height: "16", rx: "2" }),
|
|
226
|
+
/* @__PURE__ */ jsx("path", { d: "M7 9l3 3-3 3M13 15h4" })
|
|
227
|
+
] });
|
|
228
|
+
var IcDoc = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
229
|
+
/* @__PURE__ */ jsx("path", { d: "M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z" }),
|
|
230
|
+
/* @__PURE__ */ jsx("path", { d: "M14 3v6h6M8 13h8M8 17h6" })
|
|
231
|
+
] });
|
|
232
|
+
var IcList = () => /* @__PURE__ */ jsx(Svg, { s: 17, children: /* @__PURE__ */ jsx("path", { d: "M8 6h12M8 12h12M8 18h12M3.5 6h.01M3.5 12h.01M3.5 18h.01" }) });
|
|
233
|
+
var IcGlobe = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
234
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
235
|
+
/* @__PURE__ */ jsx("path", { d: "M3 12h18M12 3a15 15 0 0 1 0 18a15 15 0 0 1 0-18z" })
|
|
236
|
+
] });
|
|
237
|
+
var IcSearch = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
238
|
+
/* @__PURE__ */ jsx("circle", { cx: "11", cy: "11", r: "7" }),
|
|
239
|
+
/* @__PURE__ */ jsx("path", { d: "m21 21-4.3-4.3" })
|
|
240
|
+
] });
|
|
241
|
+
var IcScroll = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
242
|
+
/* @__PURE__ */ jsx("path", { d: "M6 3h10a2 2 0 0 1 2 2v12a3 3 0 0 0 3 3H8a2 2 0 0 1-2-2V3z" }),
|
|
243
|
+
/* @__PURE__ */ jsx("path", { d: "M6 3a2 2 0 0 0-2 2v2h2M10 8h6M10 12h6" })
|
|
244
|
+
] });
|
|
245
|
+
var IcSpawn = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
246
|
+
/* @__PURE__ */ jsx("circle", { cx: "6", cy: "6", r: "3" }),
|
|
247
|
+
/* @__PURE__ */ jsx("circle", { cx: "18", cy: "18", r: "3" }),
|
|
248
|
+
/* @__PURE__ */ jsx("path", { d: "M6 9v3a3 3 0 0 0 3 3h6" })
|
|
249
|
+
] });
|
|
250
|
+
var IcCheck = () => /* @__PURE__ */ jsxs(Svg, { s: 17, children: [
|
|
251
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
|
|
252
|
+
/* @__PURE__ */ jsx("path", { d: "m9 12 2 2 4-4" })
|
|
253
|
+
] });
|
|
254
|
+
var IcThink = () => /* @__PURE__ */ jsx(Svg, { s: 16, children: /* @__PURE__ */ jsx("path", { d: "M9.5 2a5.5 5.5 0 0 0-3 10.1V15a2 2 0 0 0 2 2h3a2 2 0 0 0 2-2v-2.9A5.5 5.5 0 0 0 9.5 2zM9 20h4M10 22h2" }) });
|
|
255
|
+
var IcSend = () => /* @__PURE__ */ jsxs(Svg, { s: 16, children: [
|
|
256
|
+
/* @__PURE__ */ jsx("path", { d: "M12 19V5" }),
|
|
257
|
+
/* @__PURE__ */ jsx("path", { d: "M5 12l7-7 7 7" })
|
|
258
|
+
] });
|
|
259
|
+
|
|
260
|
+
// src/components/toolMeta.js
|
|
261
|
+
function humanize(s) {
|
|
262
|
+
return (s || "").replace(/[_\-]+/g, " ").trim().replace(/\b\w/g, (c) => c.toUpperCase());
|
|
263
|
+
}
|
|
264
|
+
function parseArgs(args) {
|
|
265
|
+
try {
|
|
266
|
+
return (typeof args === "string" ? JSON.parse(args) : args) || {};
|
|
267
|
+
} catch {
|
|
268
|
+
return {};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function baseName(p) {
|
|
272
|
+
return String(p || "").split("/").filter(Boolean).pop() || String(p || "");
|
|
273
|
+
}
|
|
274
|
+
function prettyJson(s) {
|
|
275
|
+
try {
|
|
276
|
+
return JSON.stringify(JSON.parse(s), null, 2);
|
|
277
|
+
} catch {
|
|
278
|
+
return s || "";
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function toolMeta(name, args) {
|
|
282
|
+
const n = name || "";
|
|
283
|
+
const a = parseArgs(args);
|
|
284
|
+
const mcp = n.match(/^mcp__(.+?)__(.+)$/);
|
|
285
|
+
if (mcp) return { Icon: IcPlug, label: `${humanize(mcp[1])} \xB7 ${humanize(mcp[2])}` };
|
|
286
|
+
switch (n) {
|
|
287
|
+
case "Skill":
|
|
288
|
+
return { Icon: IcSkill, label: "Skill", chip: String(a.command || a.name || a.skill || a.skill_name || "") || void 0 };
|
|
289
|
+
case "ToolSearch":
|
|
290
|
+
return { Icon: IcSearch, label: "Finding tools" };
|
|
291
|
+
case "TaskCreate":
|
|
292
|
+
return { Icon: IcList, label: "Added task" + (a.subject ? `: ${a.subject}` : "") };
|
|
293
|
+
case "TaskUpdate": {
|
|
294
|
+
const s = String(a.status || "");
|
|
295
|
+
return { Icon: IcList, label: s === "completed" ? "Completed task" : s === "in_progress" ? "Started task" : "Updated task" };
|
|
296
|
+
}
|
|
297
|
+
case "Bash": {
|
|
298
|
+
const cmd = String(a.command || "");
|
|
299
|
+
const label = /^\s*mkdir/.test(cmd) ? "Create working directory" : /^\s*(cd|ls|pwd|cat|find)\b/.test(cmd) ? "Inspected the workspace" : "Ran a command";
|
|
300
|
+
return { Icon: IcTerminal, label };
|
|
301
|
+
}
|
|
302
|
+
case "Write":
|
|
303
|
+
return { Icon: IcDoc, label: "Wrote a file", chip: baseName(a.file_path || a.path) };
|
|
304
|
+
case "Edit":
|
|
305
|
+
case "MultiEdit":
|
|
306
|
+
return { Icon: IcDoc, label: "Edited a file", chip: baseName(a.file_path || a.path) };
|
|
307
|
+
case "Read":
|
|
308
|
+
return { Icon: IcScroll, label: "Read " + (baseName(a.file_path || a.path) || "a file") };
|
|
309
|
+
case "Glob":
|
|
310
|
+
return { Icon: IcSearch, label: "Found files" };
|
|
311
|
+
case "Grep":
|
|
312
|
+
return { Icon: IcSearch, label: "Searched code" };
|
|
313
|
+
case "LS":
|
|
314
|
+
return { Icon: IcList, label: "Listed files" };
|
|
315
|
+
case "WebSearch":
|
|
316
|
+
return { Icon: IcGlobe, label: "Searched the web" };
|
|
317
|
+
case "WebFetch":
|
|
318
|
+
return { Icon: IcGlobe, label: "Fetched a web page" };
|
|
319
|
+
case "Task":
|
|
320
|
+
case "Agent":
|
|
321
|
+
return { Icon: IcSpawn, label: "Ran a sub-agent" };
|
|
322
|
+
default:
|
|
323
|
+
return { Icon: IcTool, label: humanize(n) };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function summarizeSteps(steps) {
|
|
327
|
+
const catOf = (n) => {
|
|
328
|
+
if (/^mcp__/.test(n)) return "tool";
|
|
329
|
+
return {
|
|
330
|
+
Bash: "bash",
|
|
331
|
+
Write: "write",
|
|
332
|
+
Edit: "edit",
|
|
333
|
+
MultiEdit: "edit",
|
|
334
|
+
Read: "read",
|
|
335
|
+
Glob: "glob",
|
|
336
|
+
Grep: "grep",
|
|
337
|
+
LS: "ls",
|
|
338
|
+
WebSearch: "websearch",
|
|
339
|
+
WebFetch: "webfetch",
|
|
340
|
+
Task: "agent",
|
|
341
|
+
Agent: "agent",
|
|
342
|
+
ToolSearch: "toolsearch",
|
|
343
|
+
Skill: "skill",
|
|
344
|
+
TaskCreate: "taskcreate",
|
|
345
|
+
TaskUpdate: "taskupdate"
|
|
346
|
+
}[n] || "tool";
|
|
347
|
+
};
|
|
348
|
+
const phrase = (cat, c) => {
|
|
349
|
+
const one = c === 1;
|
|
350
|
+
switch (cat) {
|
|
351
|
+
case "bash":
|
|
352
|
+
return one ? "ran a command" : `ran ${c} commands`;
|
|
353
|
+
case "write":
|
|
354
|
+
return one ? "wrote a file" : `wrote ${c} files`;
|
|
355
|
+
case "edit":
|
|
356
|
+
return one ? "edited a file" : `edited ${c} files`;
|
|
357
|
+
case "read":
|
|
358
|
+
return one ? "read a file" : `read ${c} files`;
|
|
359
|
+
case "grep":
|
|
360
|
+
return one ? "searched code" : `searched code ${c} times`;
|
|
361
|
+
case "glob":
|
|
362
|
+
return "found files";
|
|
363
|
+
case "ls":
|
|
364
|
+
return "listed files";
|
|
365
|
+
case "websearch":
|
|
366
|
+
return one ? "searched the web" : `searched the web ${c} times`;
|
|
367
|
+
case "webfetch":
|
|
368
|
+
return one ? "fetched a page" : `fetched ${c} pages`;
|
|
369
|
+
case "agent":
|
|
370
|
+
return one ? "ran a sub-agent" : `ran ${c} sub-agents`;
|
|
371
|
+
case "toolsearch":
|
|
372
|
+
return "loaded tools";
|
|
373
|
+
case "skill":
|
|
374
|
+
return one ? "used a skill" : `used ${c} skills`;
|
|
375
|
+
case "taskcreate":
|
|
376
|
+
return one ? "added a task" : `added ${c} tasks`;
|
|
377
|
+
case "taskupdate":
|
|
378
|
+
return one ? "updated a task" : `updated ${c} tasks`;
|
|
379
|
+
default:
|
|
380
|
+
return one ? "used a tool" : `used ${c} tools`;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const order = [];
|
|
384
|
+
const counts = {};
|
|
385
|
+
for (const s of steps) {
|
|
386
|
+
const cat = catOf(s.name || "");
|
|
387
|
+
if (!(cat in counts)) {
|
|
388
|
+
counts[cat] = 0;
|
|
389
|
+
order.push(cat);
|
|
390
|
+
}
|
|
391
|
+
counts[cat]++;
|
|
392
|
+
}
|
|
393
|
+
if (order.length === 0) return "Working\u2026";
|
|
394
|
+
const parts = order.map((cat) => phrase(cat, counts[cat]));
|
|
395
|
+
const j = parts.join(", ");
|
|
396
|
+
return j.charAt(0).toUpperCase() + j.slice(1);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// src/components/ToolSteps.jsx
|
|
400
|
+
import React2, { useEffect, useState } from "react";
|
|
401
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
402
|
+
function ToolGroup(props) {
|
|
403
|
+
const {
|
|
404
|
+
reasoning,
|
|
405
|
+
steps,
|
|
406
|
+
running,
|
|
407
|
+
workingLabel = "Working\u2026",
|
|
408
|
+
thinkingLabel = "Thinking",
|
|
409
|
+
doneLabel = "Done",
|
|
410
|
+
thoughtLabel = "Thought process",
|
|
411
|
+
renderStep
|
|
412
|
+
} = props;
|
|
413
|
+
const [open, setOpen] = useState(running);
|
|
414
|
+
useEffect(() => {
|
|
415
|
+
setOpen(running);
|
|
416
|
+
}, [running]);
|
|
417
|
+
if (!reasoning && steps.length === 0) return null;
|
|
418
|
+
const summary = running ? workingLabel : steps.length ? summarizeSteps(steps) : thoughtLabel;
|
|
419
|
+
return /* @__PURE__ */ jsxs2("div", { className: "wbx-acts" + (open ? " open" : ""), children: [
|
|
420
|
+
/* @__PURE__ */ jsxs2("button", { className: "wbx-acts-sum", onClick: () => setOpen((v) => !v), children: [
|
|
421
|
+
/* @__PURE__ */ jsx2(Chevron, { dir: open ? "down" : "right", size: 13 }),
|
|
422
|
+
/* @__PURE__ */ jsx2("span", { children: summary })
|
|
423
|
+
] }),
|
|
424
|
+
open && /* @__PURE__ */ jsxs2("div", { className: "wbx-acts-body", children: [
|
|
425
|
+
reasoning && /* @__PURE__ */ jsxs2("div", { className: "wbx-act", children: [
|
|
426
|
+
/* @__PURE__ */ jsx2("span", { className: "wbx-act-ic-t thinking", children: /* @__PURE__ */ jsx2(IcThink, {}) }),
|
|
427
|
+
/* @__PURE__ */ jsxs2("div", { className: "wbx-act-main", children: [
|
|
428
|
+
/* @__PURE__ */ jsx2("div", { className: "wbx-act-k", children: thinkingLabel }),
|
|
429
|
+
/* @__PURE__ */ jsx2("div", { className: "wbx-act-v", children: reasoning })
|
|
430
|
+
] })
|
|
431
|
+
] }),
|
|
432
|
+
steps.map((s, j) => {
|
|
433
|
+
if (renderStep) {
|
|
434
|
+
const el = renderStep(s, j);
|
|
435
|
+
if (el !== void 0) return /* @__PURE__ */ jsx2(React2.Fragment, { children: el }, j);
|
|
436
|
+
}
|
|
437
|
+
return /* @__PURE__ */ jsx2(ToolRow, { step: s }, j);
|
|
438
|
+
}),
|
|
439
|
+
!running && /* @__PURE__ */ jsxs2("div", { className: "wbx-act", children: [
|
|
440
|
+
/* @__PURE__ */ jsx2("span", { className: "wbx-act-ic-t done", children: /* @__PURE__ */ jsx2(IcCheck, {}) }),
|
|
441
|
+
/* @__PURE__ */ jsx2("div", { className: "wbx-act-main", children: /* @__PURE__ */ jsx2("div", { className: "wbx-act-k", children: doneLabel }) })
|
|
442
|
+
] })
|
|
443
|
+
] })
|
|
444
|
+
] });
|
|
445
|
+
}
|
|
446
|
+
function ToolRow(props) {
|
|
447
|
+
const { step, requestLabel = "Request", resultLabel = "Result" } = props;
|
|
448
|
+
const [open, setOpen] = useState(false);
|
|
449
|
+
const meta = toolMeta(step.name, step.args);
|
|
450
|
+
const Icon = meta.Icon;
|
|
451
|
+
const hasDetail = !!(step.args && step.args !== "{}") || step.result !== void 0;
|
|
452
|
+
return /* @__PURE__ */ jsxs2("div", { className: "wbx-act", children: [
|
|
453
|
+
/* @__PURE__ */ jsx2("span", { className: "wbx-act-ic-t", children: /* @__PURE__ */ jsx2(Icon, {}) }),
|
|
454
|
+
/* @__PURE__ */ jsxs2("div", { className: "wbx-act-main", children: [
|
|
455
|
+
/* @__PURE__ */ jsxs2("button", { className: "wbx-act-row" + (open ? " open" : ""), disabled: !hasDetail, onClick: () => setOpen((v) => !v), children: [
|
|
456
|
+
/* @__PURE__ */ jsx2("span", { className: "wbx-act-k", children: meta.label }),
|
|
457
|
+
meta.chip && /* @__PURE__ */ jsx2("span", { className: "wbx-act-chip", children: meta.chip }),
|
|
458
|
+
hasDetail && /* @__PURE__ */ jsx2("span", { className: "wbx-act-exp", children: /* @__PURE__ */ jsx2(Chevron, { dir: open ? "down" : "right", size: 12 }) })
|
|
459
|
+
] }),
|
|
460
|
+
open && /* @__PURE__ */ jsxs2("div", { className: "wbx-act-detail", children: [
|
|
461
|
+
step.args && step.args !== "{}" && /* @__PURE__ */ jsxs2("div", { className: "wbx-act-block", children: [
|
|
462
|
+
/* @__PURE__ */ jsx2("div", { className: "wbx-act-block-h", children: requestLabel }),
|
|
463
|
+
/* @__PURE__ */ jsx2("pre", { className: "wbx-act-pre", children: prettyJson(step.args) })
|
|
464
|
+
] }),
|
|
465
|
+
step.result !== void 0 && /* @__PURE__ */ jsxs2("div", { className: "wbx-act-block", children: [
|
|
466
|
+
/* @__PURE__ */ jsx2("div", { className: "wbx-act-block-h", children: resultLabel }),
|
|
467
|
+
/* @__PURE__ */ jsx2("pre", { className: "wbx-act-pre", children: String(step.result).slice(0, 4e3) })
|
|
468
|
+
] })
|
|
469
|
+
] })
|
|
470
|
+
] })
|
|
471
|
+
] });
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// src/components/ChatMessages.jsx
|
|
475
|
+
import React3 from "react";
|
|
476
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
477
|
+
var DEFAULT_STATUS_LABELS = {
|
|
478
|
+
failed: "\u2715 Failed \u2014 see the output above for the reason",
|
|
479
|
+
cancelled: "\u25FC Stopped by you",
|
|
480
|
+
incomplete: "\u25D4 Hit its step or time limit \u2014 Continue to resume"
|
|
481
|
+
};
|
|
482
|
+
var defaultMarkdown = (text) => /* @__PURE__ */ jsx3("div", { style: { whiteSpace: "pre-wrap" }, children: text });
|
|
483
|
+
var REVEAL_SEC = 3;
|
|
484
|
+
var MIN_CPS = 10;
|
|
485
|
+
function TypewriterText(props) {
|
|
486
|
+
const { text, active, render } = props;
|
|
487
|
+
const [n, setN] = React3.useState(() => text ? text.length : 0);
|
|
488
|
+
const textRef = React3.useRef(text);
|
|
489
|
+
textRef.current = text;
|
|
490
|
+
const accRef = React3.useRef(text ? text.length : 0);
|
|
491
|
+
React3.useEffect(() => {
|
|
492
|
+
if (!active) {
|
|
493
|
+
setN(textRef.current ? textRef.current.length : 0);
|
|
494
|
+
return void 0;
|
|
495
|
+
}
|
|
496
|
+
let raf;
|
|
497
|
+
let prev = null;
|
|
498
|
+
const tick = (t) => {
|
|
499
|
+
if (prev == null) prev = t;
|
|
500
|
+
const dt = Math.min(0.1, (t - prev) / 1e3);
|
|
501
|
+
prev = t;
|
|
502
|
+
const len = textRef.current ? textRef.current.length : 0;
|
|
503
|
+
const gap = len - accRef.current;
|
|
504
|
+
if (gap > 0) {
|
|
505
|
+
const cps = Math.max(MIN_CPS, gap / REVEAL_SEC);
|
|
506
|
+
accRef.current = Math.min(len, accRef.current + cps * dt);
|
|
507
|
+
setN(Math.floor(accRef.current));
|
|
508
|
+
}
|
|
509
|
+
raf = requestAnimationFrame(tick);
|
|
510
|
+
};
|
|
511
|
+
raf = requestAnimationFrame(tick);
|
|
512
|
+
return () => cancelAnimationFrame(raf);
|
|
513
|
+
}, [active]);
|
|
514
|
+
const shown = active ? (text || "").slice(0, n) : text || "";
|
|
515
|
+
return render(shown);
|
|
516
|
+
}
|
|
517
|
+
function UserTurn(props) {
|
|
518
|
+
const { msg, children } = props;
|
|
519
|
+
return /* @__PURE__ */ jsx3("div", { className: "wbx-turn user", children: /* @__PURE__ */ jsxs3("div", { className: "wbx-bubble-user", children: [
|
|
520
|
+
children,
|
|
521
|
+
msg.text && /* @__PURE__ */ jsx3("div", { className: "wbx-bubble-text", children: msg.text })
|
|
522
|
+
] }) });
|
|
523
|
+
}
|
|
524
|
+
function AssistantTurn(props) {
|
|
525
|
+
const {
|
|
526
|
+
msg,
|
|
527
|
+
renderMarkdown = defaultMarkdown,
|
|
528
|
+
workingLabel = "Working\u2026",
|
|
529
|
+
workingExtra,
|
|
530
|
+
statusLabels = DEFAULT_STATUS_LABELS,
|
|
531
|
+
renderStep,
|
|
532
|
+
toolLabels,
|
|
533
|
+
footer
|
|
534
|
+
} = props;
|
|
535
|
+
return /* @__PURE__ */ jsxs3("div", { className: "wbx-turn asst", children: [
|
|
536
|
+
msg.blocks.map((b, bi) => b.kind === "tools" ? /* @__PURE__ */ jsx3(
|
|
537
|
+
ToolGroup,
|
|
538
|
+
{
|
|
539
|
+
reasoning: b.reasoning,
|
|
540
|
+
steps: b.steps,
|
|
541
|
+
running: msg.status === "running" && bi === msg.blocks.length - 1,
|
|
542
|
+
renderStep,
|
|
543
|
+
...toolLabels || {}
|
|
544
|
+
},
|
|
545
|
+
bi
|
|
546
|
+
) : /* @__PURE__ */ jsx3("div", { className: "wbx-md", children: /* @__PURE__ */ jsx3(
|
|
547
|
+
TypewriterText,
|
|
548
|
+
{
|
|
549
|
+
text: b.text,
|
|
550
|
+
render: renderMarkdown,
|
|
551
|
+
active: msg.status === "running" && bi === msg.blocks.length - 1
|
|
552
|
+
}
|
|
553
|
+
) }, bi)),
|
|
554
|
+
msg.status === "running" && /* @__PURE__ */ jsxs3("div", { className: "wbx-working", "aria-label": "Working", children: [
|
|
555
|
+
/* @__PURE__ */ jsxs3("span", { className: "wbx-working-dots", children: [
|
|
556
|
+
/* @__PURE__ */ jsx3("span", {}),
|
|
557
|
+
/* @__PURE__ */ jsx3("span", {}),
|
|
558
|
+
/* @__PURE__ */ jsx3("span", {})
|
|
559
|
+
] }),
|
|
560
|
+
/* @__PURE__ */ jsx3("span", { className: "wbx-working-txt", children: workingLabel }),
|
|
561
|
+
workingExtra
|
|
562
|
+
] }),
|
|
563
|
+
(msg.status === "failed" || msg.status === "cancelled" || msg.status === "incomplete") && /* @__PURE__ */ jsx3("div", { className: "wbx-turnbadge " + msg.status, role: "status", children: statusLabels[msg.status] }),
|
|
564
|
+
footer
|
|
565
|
+
] });
|
|
566
|
+
}
|
|
567
|
+
var DEFAULT_SKELETON_TURNS = [
|
|
568
|
+
{ role: "assistant", lines: ["94%", "82%", "58%"] },
|
|
569
|
+
{ role: "user", width: "46%", lines: ["88%", "62%"] },
|
|
570
|
+
{ role: "assistant", lines: ["90%", "97%", "71%"] },
|
|
571
|
+
{ role: "user", width: "38%", lines: ["80%"] }
|
|
572
|
+
];
|
|
573
|
+
function ChatMessagesSkeleton(props) {
|
|
574
|
+
const turns = props && props.turns || DEFAULT_SKELETON_TURNS;
|
|
575
|
+
return /* @__PURE__ */ jsx3("div", { className: "wbx-skel", "aria-busy": "true", "aria-label": "Loading conversation", children: turns.map((t, i) => t.role === "user" ? /* @__PURE__ */ jsx3("div", { className: "wbx-turn user wbx-skel-turn", "aria-hidden": "true", children: /* @__PURE__ */ jsx3("div", { className: "wbx-bubble-user wbx-skel-lines", style: { width: t.width }, children: t.lines.map((w, j) => /* @__PURE__ */ jsx3("span", { className: "wbx-skel-bar", style: { width: w } }, j)) }) }, i) : /* @__PURE__ */ jsx3("div", { className: "wbx-turn asst wbx-skel-turn", "aria-hidden": "true", children: /* @__PURE__ */ jsx3("div", { className: "wbx-md wbx-skel-lines", children: t.lines.map((w, j) => /* @__PURE__ */ jsx3("span", { className: "wbx-skel-bar", style: { width: w } }, j)) }) }, i)) });
|
|
576
|
+
}
|
|
577
|
+
function ChatMessages(props) {
|
|
578
|
+
const {
|
|
579
|
+
messages,
|
|
580
|
+
renderMarkdown,
|
|
581
|
+
renderMessage,
|
|
582
|
+
userExtras,
|
|
583
|
+
workingExtra,
|
|
584
|
+
assistantFooter,
|
|
585
|
+
statusLabels,
|
|
586
|
+
renderStep,
|
|
587
|
+
workingLabel,
|
|
588
|
+
toolLabels
|
|
589
|
+
} = props;
|
|
590
|
+
return /* @__PURE__ */ jsx3(Fragment, { children: messages.map((m, i) => {
|
|
591
|
+
if (renderMessage) {
|
|
592
|
+
const el = renderMessage(m, i);
|
|
593
|
+
if (el !== void 0) return /* @__PURE__ */ jsx3(React3.Fragment, { children: el }, i);
|
|
594
|
+
}
|
|
595
|
+
return m.role === "user" ? /* @__PURE__ */ jsx3(UserTurn, { msg: m, children: userExtras?.(m, i) }, i) : /* @__PURE__ */ jsx3(
|
|
596
|
+
AssistantTurn,
|
|
597
|
+
{
|
|
598
|
+
msg: m,
|
|
599
|
+
renderMarkdown,
|
|
600
|
+
workingLabel,
|
|
601
|
+
workingExtra: workingExtra?.(m, i),
|
|
602
|
+
statusLabels,
|
|
603
|
+
renderStep,
|
|
604
|
+
toolLabels,
|
|
605
|
+
footer: assistantFooter?.(m, i)
|
|
606
|
+
},
|
|
607
|
+
i
|
|
608
|
+
);
|
|
609
|
+
}) });
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// src/components/Composer.jsx
|
|
613
|
+
import React4, { useEffect as useEffect2, useRef } from "react";
|
|
614
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
615
|
+
function Composer(props) {
|
|
616
|
+
const {
|
|
617
|
+
value,
|
|
618
|
+
onChange,
|
|
619
|
+
onSend,
|
|
620
|
+
disabled = false,
|
|
621
|
+
sendDisabled,
|
|
622
|
+
placeholder,
|
|
623
|
+
rows = 1,
|
|
624
|
+
autoGrow = true,
|
|
625
|
+
maxRows = 15,
|
|
626
|
+
attachments,
|
|
627
|
+
accessoriesLeft,
|
|
628
|
+
accessoriesRight,
|
|
629
|
+
renderSend,
|
|
630
|
+
classNames = {},
|
|
631
|
+
inputRef
|
|
632
|
+
} = props;
|
|
633
|
+
const ownRef = useRef(null);
|
|
634
|
+
const taRef = inputRef || ownRef;
|
|
635
|
+
useEffect2(() => {
|
|
636
|
+
if (!autoGrow) return;
|
|
637
|
+
const el = taRef.current;
|
|
638
|
+
if (!el) return;
|
|
639
|
+
el.style.height = "auto";
|
|
640
|
+
const cs = getComputedStyle(el);
|
|
641
|
+
const lh = parseFloat(cs.lineHeight) || 21;
|
|
642
|
+
const max = lh * maxRows + parseFloat(cs.paddingTop || "0") + parseFloat(cs.paddingBottom || "0");
|
|
643
|
+
el.style.height = Math.min(el.scrollHeight, max) + "px";
|
|
644
|
+
el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
|
|
645
|
+
}, [value, autoGrow, maxRows, taRef]);
|
|
646
|
+
return /* @__PURE__ */ jsxs4("div", { className: classNames.root ?? "wbx-composer", children: [
|
|
647
|
+
attachments,
|
|
648
|
+
/* @__PURE__ */ jsx4(
|
|
649
|
+
"textarea",
|
|
650
|
+
{
|
|
651
|
+
ref: taRef,
|
|
652
|
+
className: classNames.input ?? "wbx-composer-input",
|
|
653
|
+
placeholder,
|
|
654
|
+
value,
|
|
655
|
+
disabled,
|
|
656
|
+
rows,
|
|
657
|
+
onChange: (e) => onChange(e.target.value),
|
|
658
|
+
onKeyDown: (e) => {
|
|
659
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
660
|
+
e.preventDefault();
|
|
661
|
+
onSend();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
),
|
|
666
|
+
/* @__PURE__ */ jsxs4("div", { className: classNames.row ?? "wbx-composer-row", children: [
|
|
667
|
+
accessoriesLeft,
|
|
668
|
+
/* @__PURE__ */ jsx4("span", { style: { flex: 1 } }),
|
|
669
|
+
accessoriesRight,
|
|
670
|
+
renderSend ? renderSend() : /* @__PURE__ */ jsx4("button", { type: "button", className: "uic-send", disabled: sendDisabled, onClick: () => onSend(), "aria-label": "Send message", children: /* @__PURE__ */ jsx4(IcSend, {}) })
|
|
671
|
+
] })
|
|
672
|
+
] });
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// src/components/CodeBlock.jsx
|
|
676
|
+
import React5 from "react";
|
|
677
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
678
|
+
var _hljsPromise = null;
|
|
679
|
+
function loadHljs() {
|
|
680
|
+
if (!_hljsPromise) {
|
|
681
|
+
_hljsPromise = import("highlight.js/lib/core").then((m) => m.default || m);
|
|
682
|
+
}
|
|
683
|
+
return _hljsPromise;
|
|
684
|
+
}
|
|
685
|
+
var GRAMMARS = {
|
|
686
|
+
javascript: () => import("highlight.js/lib/languages/javascript"),
|
|
687
|
+
typescript: () => import("highlight.js/lib/languages/typescript"),
|
|
688
|
+
python: () => import("highlight.js/lib/languages/python"),
|
|
689
|
+
json: () => import("highlight.js/lib/languages/json"),
|
|
690
|
+
bash: () => import("highlight.js/lib/languages/bash"),
|
|
691
|
+
sql: () => import("highlight.js/lib/languages/sql"),
|
|
692
|
+
java: () => import("highlight.js/lib/languages/java"),
|
|
693
|
+
go: () => import("highlight.js/lib/languages/go"),
|
|
694
|
+
rust: () => import("highlight.js/lib/languages/rust"),
|
|
695
|
+
xml: () => import("highlight.js/lib/languages/xml"),
|
|
696
|
+
css: () => import("highlight.js/lib/languages/css"),
|
|
697
|
+
yaml: () => import("highlight.js/lib/languages/yaml"),
|
|
698
|
+
groovy: () => import("highlight.js/lib/languages/groovy")
|
|
699
|
+
};
|
|
700
|
+
var ALIASES = {
|
|
701
|
+
js: "javascript",
|
|
702
|
+
jsx: "javascript",
|
|
703
|
+
mjs: "javascript",
|
|
704
|
+
cjs: "javascript",
|
|
705
|
+
node: "javascript",
|
|
706
|
+
ts: "typescript",
|
|
707
|
+
tsx: "typescript",
|
|
708
|
+
py: "python",
|
|
709
|
+
python3: "python",
|
|
710
|
+
sh: "bash",
|
|
711
|
+
shell: "bash",
|
|
712
|
+
zsh: "bash",
|
|
713
|
+
console: "bash",
|
|
714
|
+
html: "xml",
|
|
715
|
+
xhtml: "xml",
|
|
716
|
+
svg: "xml",
|
|
717
|
+
yml: "yaml",
|
|
718
|
+
golang: "go",
|
|
719
|
+
rs: "rust",
|
|
720
|
+
jsonc: "json",
|
|
721
|
+
postgres: "sql",
|
|
722
|
+
postgresql: "sql",
|
|
723
|
+
mysql: "sql",
|
|
724
|
+
plsql: "sql",
|
|
725
|
+
gremlin: "groovy"
|
|
726
|
+
};
|
|
727
|
+
function canonicalLang(tag) {
|
|
728
|
+
const t = String(tag || "").toLowerCase();
|
|
729
|
+
if (!t) return null;
|
|
730
|
+
const name = ALIASES[t] || t;
|
|
731
|
+
return GRAMMARS[name] ? name : null;
|
|
732
|
+
}
|
|
733
|
+
var _ready = /* @__PURE__ */ new Map();
|
|
734
|
+
function ensureLanguage(name) {
|
|
735
|
+
if (!_ready.has(name)) {
|
|
736
|
+
const p = Promise.all([loadHljs(), GRAMMARS[name]()]).then(([hljs, mod]) => {
|
|
737
|
+
if (!hljs.getLanguage(name)) hljs.registerLanguage(name, mod.default || mod);
|
|
738
|
+
return hljs;
|
|
739
|
+
}).catch(() => null);
|
|
740
|
+
_ready.set(name, p);
|
|
741
|
+
}
|
|
742
|
+
return _ready.get(name);
|
|
743
|
+
}
|
|
744
|
+
function CodeBlock(props) {
|
|
745
|
+
const { code, language, className } = props;
|
|
746
|
+
const src = String(code || "");
|
|
747
|
+
const lang = canonicalLang(language);
|
|
748
|
+
const [hl, setHl] = React5.useState(null);
|
|
749
|
+
React5.useEffect(() => {
|
|
750
|
+
if (!lang || !src) return void 0;
|
|
751
|
+
let cancelled = false;
|
|
752
|
+
const timer = setTimeout(() => {
|
|
753
|
+
ensureLanguage(lang).then((hljs) => {
|
|
754
|
+
if (!hljs || cancelled) return;
|
|
755
|
+
try {
|
|
756
|
+
const out = hljs.highlight(src, { language: lang, ignoreIllegals: true });
|
|
757
|
+
if (!cancelled) setHl({ src, html: out.value });
|
|
758
|
+
} catch {
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
}, 200);
|
|
762
|
+
return () => {
|
|
763
|
+
cancelled = true;
|
|
764
|
+
clearTimeout(timer);
|
|
765
|
+
};
|
|
766
|
+
}, [src, lang]);
|
|
767
|
+
const html = hl && hl.src === src ? hl.html : null;
|
|
768
|
+
const label = String(language || "").toLowerCase();
|
|
769
|
+
return /* @__PURE__ */ jsxs5("pre", { className: "wbx-code" + (className ? " " + className : ""), children: [
|
|
770
|
+
label ? /* @__PURE__ */ jsx5("span", { className: "wbx-code-lang", "aria-hidden": "true", children: label }) : null,
|
|
771
|
+
html != null ? /* @__PURE__ */ jsx5("code", { className: "hljs language-" + label, dangerouslySetInnerHTML: { __html: html } }) : /* @__PURE__ */ jsx5("code", { className: label ? "language-" + label : void 0, children: src })
|
|
772
|
+
] });
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// src/components/resizable.jsx
|
|
776
|
+
import React6, { useCallback, useRef as useRef2, useState as useState2 } from "react";
|
|
777
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
778
|
+
function useResizablePane(opts = {}) {
|
|
779
|
+
const {
|
|
780
|
+
initial = 380,
|
|
781
|
+
min = 240,
|
|
782
|
+
max = null,
|
|
783
|
+
// absolute px cap (null = none)
|
|
784
|
+
maxFraction = null,
|
|
785
|
+
// viewport-width fraction cap, e.g. 0.6 for 60vw (null = none)
|
|
786
|
+
fromRight = false,
|
|
787
|
+
// divider sits on the pane's LEFT edge (dragging right shrinks)
|
|
788
|
+
storageKey = null
|
|
789
|
+
// persist the chosen width per user (localStorage)
|
|
790
|
+
} = opts;
|
|
791
|
+
const clamp = useCallback((x) => {
|
|
792
|
+
let hi = max ?? Infinity;
|
|
793
|
+
if (maxFraction && typeof window !== "undefined") hi = Math.min(hi, Math.round(window.innerWidth * maxFraction));
|
|
794
|
+
return Math.min(hi, Math.max(min, x));
|
|
795
|
+
}, [min, max, maxFraction]);
|
|
796
|
+
const [width, setWidth] = useState2(() => {
|
|
797
|
+
if (storageKey && typeof window !== "undefined") {
|
|
798
|
+
try {
|
|
799
|
+
const n = parseInt(window.localStorage.getItem(storageKey) || "", 10);
|
|
800
|
+
if (Number.isFinite(n)) return clamp(n);
|
|
801
|
+
} catch {
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return initial;
|
|
805
|
+
});
|
|
806
|
+
const widthRef = useRef2(width);
|
|
807
|
+
widthRef.current = width;
|
|
808
|
+
const persist = useCallback((w) => {
|
|
809
|
+
if (!storageKey) return;
|
|
810
|
+
try {
|
|
811
|
+
window.localStorage.setItem(storageKey, String(w));
|
|
812
|
+
} catch {
|
|
813
|
+
}
|
|
814
|
+
}, [storageKey]);
|
|
815
|
+
const onMouseDown = useCallback((e) => {
|
|
816
|
+
e.preventDefault();
|
|
817
|
+
const sx = e.clientX, base = widthRef.current, dir = fromRight ? -1 : 1;
|
|
818
|
+
document.body.classList.add("uic-resizing");
|
|
819
|
+
const move = (ev) => setWidth(clamp(base + dir * (ev.clientX - sx)));
|
|
820
|
+
const up = () => {
|
|
821
|
+
window.removeEventListener("mousemove", move);
|
|
822
|
+
window.removeEventListener("mouseup", up);
|
|
823
|
+
document.body.style.cursor = "";
|
|
824
|
+
document.body.classList.remove("uic-resizing");
|
|
825
|
+
persist(widthRef.current);
|
|
826
|
+
};
|
|
827
|
+
window.addEventListener("mousemove", move);
|
|
828
|
+
window.addEventListener("mouseup", up);
|
|
829
|
+
document.body.style.cursor = "col-resize";
|
|
830
|
+
}, [clamp, fromRight, persist]);
|
|
831
|
+
const reset = useCallback(() => {
|
|
832
|
+
setWidth(initial);
|
|
833
|
+
if (storageKey) {
|
|
834
|
+
try {
|
|
835
|
+
window.localStorage.removeItem(storageKey);
|
|
836
|
+
} catch {
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}, [initial, storageKey]);
|
|
840
|
+
return { width, onMouseDown, reset };
|
|
841
|
+
}
|
|
842
|
+
function PaneResizer(props) {
|
|
843
|
+
const { pane, className, title = "Drag to resize (double-click to reset)" } = props;
|
|
844
|
+
return /* @__PURE__ */ jsx6(
|
|
845
|
+
"div",
|
|
846
|
+
{
|
|
847
|
+
className: className ?? "uic-vresize",
|
|
848
|
+
role: "separator",
|
|
849
|
+
"aria-orientation": "vertical",
|
|
850
|
+
title,
|
|
851
|
+
onMouseDown: pane.onMouseDown,
|
|
852
|
+
onDoubleClick: pane.reset
|
|
853
|
+
}
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// src/auth/client.js
|
|
858
|
+
var _cfg = {
|
|
859
|
+
engine: "",
|
|
860
|
+
// REQUIRED: your auth backend base URL, set via configureAuth
|
|
861
|
+
product: "",
|
|
862
|
+
loginHash: "#/login"
|
|
863
|
+
};
|
|
864
|
+
function configureAuth(cfg) {
|
|
865
|
+
Object.assign(_cfg, cfg);
|
|
866
|
+
if (!_cfg.product) throw new Error("configureAuth: product is required");
|
|
867
|
+
if (!_cfg.engine) throw new Error("configureAuth: engine (auth backend base URL) is required");
|
|
868
|
+
}
|
|
869
|
+
function authConfig() {
|
|
870
|
+
return { ..._cfg };
|
|
871
|
+
}
|
|
872
|
+
function sessionKey() {
|
|
873
|
+
return `${_cfg.product}.session`;
|
|
874
|
+
}
|
|
875
|
+
var SESSION_EVENT = "ui-core:session";
|
|
876
|
+
function getSession() {
|
|
877
|
+
try {
|
|
878
|
+
const raw = window.localStorage.getItem(sessionKey());
|
|
879
|
+
return raw ? JSON.parse(raw) : null;
|
|
880
|
+
} catch {
|
|
881
|
+
return null;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function setSession(s) {
|
|
885
|
+
window.localStorage.setItem(sessionKey(), JSON.stringify(s));
|
|
886
|
+
window.dispatchEvent(new CustomEvent(SESSION_EVENT));
|
|
887
|
+
}
|
|
888
|
+
function clearSession() {
|
|
889
|
+
window.localStorage.removeItem(sessionKey());
|
|
890
|
+
window.dispatchEvent(new CustomEvent(SESSION_EVENT));
|
|
891
|
+
}
|
|
892
|
+
function getToken() {
|
|
893
|
+
return getSession()?.token ?? null;
|
|
894
|
+
}
|
|
895
|
+
function isAuthed() {
|
|
896
|
+
const s = getSession();
|
|
897
|
+
return !!(s?.token && s?.orgId);
|
|
898
|
+
}
|
|
899
|
+
async function readError(res) {
|
|
900
|
+
try {
|
|
901
|
+
const body = await res.json();
|
|
902
|
+
return typeof body?.detail === "string" ? body.detail : `request failed (${res.status})`;
|
|
903
|
+
} catch {
|
|
904
|
+
return `request failed (${res.status})`;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
function toSession(body) {
|
|
908
|
+
return {
|
|
909
|
+
token: body.token,
|
|
910
|
+
member: body.member,
|
|
911
|
+
orgs: body.orgs ?? [],
|
|
912
|
+
orgId: body.org_id ?? null
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
async function authPost(path, body, token = null) {
|
|
916
|
+
const headers = { "content-type": "application/json" };
|
|
917
|
+
if (token) headers.authorization = `Bearer ${token}`;
|
|
918
|
+
const res = await fetch(`${_cfg.engine}${path}`, {
|
|
919
|
+
method: "POST",
|
|
920
|
+
headers,
|
|
921
|
+
body: body ? JSON.stringify(body) : void 0
|
|
922
|
+
});
|
|
923
|
+
if (!res.ok) throw new Error(await readError(res));
|
|
924
|
+
return res.json();
|
|
925
|
+
}
|
|
926
|
+
async function login(email, password) {
|
|
927
|
+
const s = toSession(await authPost("/v1/auth/login", { email, password, product: _cfg.product }));
|
|
928
|
+
setSession(s);
|
|
929
|
+
return s;
|
|
930
|
+
}
|
|
931
|
+
async function register(email, password, name = "") {
|
|
932
|
+
const s = toSession(await authPost("/v1/auth/register", { email, password, name, product: _cfg.product }));
|
|
933
|
+
setSession(s);
|
|
934
|
+
return s;
|
|
935
|
+
}
|
|
936
|
+
async function googleSignIn(credential) {
|
|
937
|
+
const s = toSession(await authPost("/v1/auth/google", { credential, product: _cfg.product }));
|
|
938
|
+
setSession(s);
|
|
939
|
+
return s;
|
|
940
|
+
}
|
|
941
|
+
async function requestPasswordReset(email) {
|
|
942
|
+
await fetch(`${_cfg.engine}/v1/auth/request-password-reset`, {
|
|
943
|
+
method: "POST",
|
|
944
|
+
headers: { "content-type": "application/json" },
|
|
945
|
+
body: JSON.stringify({ email, product: _cfg.product })
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
async function switchOrg(orgId) {
|
|
949
|
+
const current = getSession();
|
|
950
|
+
if (!current) throw new Error("not authenticated");
|
|
951
|
+
const body = await authPost("/v1/auth/switch-org", { org_id: orgId }, current.token);
|
|
952
|
+
const next = { ...current, token: body.token, orgId: body.org_id };
|
|
953
|
+
setSession(next);
|
|
954
|
+
return next;
|
|
955
|
+
}
|
|
956
|
+
async function refreshToken() {
|
|
957
|
+
const cur = getSession();
|
|
958
|
+
if (!cur?.token) return false;
|
|
959
|
+
try {
|
|
960
|
+
const res = await fetch(`${_cfg.engine}/v1/auth/refresh`, {
|
|
961
|
+
method: "POST",
|
|
962
|
+
headers: { authorization: `Bearer ${cur.token}` }
|
|
963
|
+
});
|
|
964
|
+
if (res.status === 401) {
|
|
965
|
+
handleAuthExpired();
|
|
966
|
+
return false;
|
|
967
|
+
}
|
|
968
|
+
if (!res.ok) return false;
|
|
969
|
+
const body = await res.json();
|
|
970
|
+
const now = getSession();
|
|
971
|
+
if (body?.token && now) setSession({ ...now, token: body.token });
|
|
972
|
+
return true;
|
|
973
|
+
} catch {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
var redirecting = false;
|
|
978
|
+
function handleAuthExpired() {
|
|
979
|
+
if (redirecting) return;
|
|
980
|
+
redirecting = true;
|
|
981
|
+
clearSession();
|
|
982
|
+
window.location.hash = _cfg.loginHash;
|
|
983
|
+
setTimeout(() => {
|
|
984
|
+
redirecting = false;
|
|
985
|
+
}, 500);
|
|
986
|
+
}
|
|
987
|
+
function logout() {
|
|
988
|
+
clearSession();
|
|
989
|
+
window.location.hash = _cfg.loginHash;
|
|
990
|
+
}
|
|
991
|
+
async function authFetch(url, init = {}) {
|
|
992
|
+
const headers = new Headers(init.headers);
|
|
993
|
+
const token = getToken();
|
|
994
|
+
if (token) headers.set("authorization", `Bearer ${token}`);
|
|
995
|
+
const res = await fetch(url, { ...init, headers });
|
|
996
|
+
if (res.status === 401) handleAuthExpired();
|
|
997
|
+
return res;
|
|
998
|
+
}
|
|
999
|
+
async function fetchBalance() {
|
|
1000
|
+
const res = await authFetch(`${_cfg.engine}/v1/billing/balance`);
|
|
1001
|
+
if (!res.ok) throw new Error(await readError(res));
|
|
1002
|
+
return res.json();
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
// src/auth/AuthForm.jsx
|
|
1006
|
+
import { useState as useState4 } from "react";
|
|
1007
|
+
|
|
1008
|
+
// src/auth/GoogleButton.jsx
|
|
1009
|
+
import { useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
1010
|
+
import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1011
|
+
var CLIENT_ID = "247853836408-ojk91u8901hdlbkevid4fohmrfdot17l.apps.googleusercontent.com";
|
|
1012
|
+
function GoogleButton({ onCredential, onError }) {
|
|
1013
|
+
const ref = useRef3(null);
|
|
1014
|
+
const [failed, setFailed] = useState3(false);
|
|
1015
|
+
const cb = useRef3({ onCredential, onError });
|
|
1016
|
+
cb.current = { onCredential, onError };
|
|
1017
|
+
useEffect3(() => {
|
|
1018
|
+
if (!CLIENT_ID || !ref.current) return void 0;
|
|
1019
|
+
const SRC = "https://accounts.google.com/gsi/client";
|
|
1020
|
+
let done = false;
|
|
1021
|
+
const render = () => {
|
|
1022
|
+
if (done) return;
|
|
1023
|
+
const g = window.google;
|
|
1024
|
+
if (!g?.accounts?.id || !ref.current) return;
|
|
1025
|
+
done = true;
|
|
1026
|
+
try {
|
|
1027
|
+
g.accounts.id.initialize({
|
|
1028
|
+
client_id: CLIENT_ID,
|
|
1029
|
+
callback: (resp) => {
|
|
1030
|
+
if (resp?.credential) cb.current.onCredential(resp.credential);
|
|
1031
|
+
else cb.current.onError?.("Google sign in was cancelled.");
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
ref.current.innerHTML = "";
|
|
1035
|
+
g.accounts.id.renderButton(ref.current, {
|
|
1036
|
+
theme: "outline",
|
|
1037
|
+
size: "large",
|
|
1038
|
+
shape: "pill",
|
|
1039
|
+
text: "continue_with",
|
|
1040
|
+
width: 320
|
|
1041
|
+
});
|
|
1042
|
+
} catch {
|
|
1043
|
+
setFailed(true);
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
let s = document.querySelector(`script[src="${SRC}"]`);
|
|
1047
|
+
if (s && window.google) render();
|
|
1048
|
+
else {
|
|
1049
|
+
if (!s) {
|
|
1050
|
+
s = document.createElement("script");
|
|
1051
|
+
s.src = SRC;
|
|
1052
|
+
s.async = true;
|
|
1053
|
+
s.defer = true;
|
|
1054
|
+
document.head.appendChild(s);
|
|
1055
|
+
}
|
|
1056
|
+
s.addEventListener("load", render);
|
|
1057
|
+
}
|
|
1058
|
+
const check = window.setTimeout(() => {
|
|
1059
|
+
const iframe = ref.current?.querySelector("iframe");
|
|
1060
|
+
if (!iframe || iframe.getBoundingClientRect().height < 10) setFailed(true);
|
|
1061
|
+
}, 3500);
|
|
1062
|
+
return () => {
|
|
1063
|
+
s?.removeEventListener("load", render);
|
|
1064
|
+
window.clearTimeout(check);
|
|
1065
|
+
};
|
|
1066
|
+
}, []);
|
|
1067
|
+
if (!CLIENT_ID || failed) return null;
|
|
1068
|
+
return /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
1069
|
+
/* @__PURE__ */ jsx7("div", { className: "auth-or", children: /* @__PURE__ */ jsx7("span", { children: "or" }) }),
|
|
1070
|
+
/* @__PURE__ */ jsx7("div", { ref, className: "auth-gwrap" })
|
|
1071
|
+
] });
|
|
1072
|
+
}
|
|
1073
|
+
var GOOGLE_ENABLED = !!CLIENT_ID;
|
|
1074
|
+
|
|
1075
|
+
// src/auth/AuthForm.jsx
|
|
1076
|
+
import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1077
|
+
function AuthForm({ onDone, subtitle, brand = null, productName = "" }) {
|
|
1078
|
+
const [mode, setMode] = useState4("signin");
|
|
1079
|
+
const [email, setEmail] = useState4("");
|
|
1080
|
+
const [password, setPassword] = useState4("");
|
|
1081
|
+
const [name, setName] = useState4("");
|
|
1082
|
+
const [err, setErr] = useState4("");
|
|
1083
|
+
const [busy, setBusy] = useState4(false);
|
|
1084
|
+
const [choices, setChoices] = useState4(null);
|
|
1085
|
+
const [resetSent, setResetSent] = useState4(false);
|
|
1086
|
+
async function enter(orgId) {
|
|
1087
|
+
const session = await switchOrg(orgId);
|
|
1088
|
+
onDone(session);
|
|
1089
|
+
}
|
|
1090
|
+
async function afterAuth(session) {
|
|
1091
|
+
if (session.orgId) onDone(session);
|
|
1092
|
+
else if (session.orgs.length === 1) await enter(session.orgs[0].id);
|
|
1093
|
+
else if (session.orgs.length > 1) setChoices(session.orgs);
|
|
1094
|
+
else setErr("This account is not a member of any organization yet.");
|
|
1095
|
+
}
|
|
1096
|
+
async function submit(e) {
|
|
1097
|
+
e.preventDefault();
|
|
1098
|
+
setErr("");
|
|
1099
|
+
setBusy(true);
|
|
1100
|
+
try {
|
|
1101
|
+
if (mode === "forgot") {
|
|
1102
|
+
await requestPasswordReset(email.trim());
|
|
1103
|
+
setResetSent(true);
|
|
1104
|
+
} else {
|
|
1105
|
+
const s = mode === "register" ? await register(email.trim(), password, name.trim()) : await login(email.trim(), password);
|
|
1106
|
+
await afterAuth(s);
|
|
1107
|
+
}
|
|
1108
|
+
} catch (ex) {
|
|
1109
|
+
setErr(ex instanceof Error ? ex.message : `${mode === "register" ? "Sign up" : "Sign in"} failed.`);
|
|
1110
|
+
} finally {
|
|
1111
|
+
setBusy(false);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
async function onGoogle(credential) {
|
|
1115
|
+
setErr("");
|
|
1116
|
+
setBusy(true);
|
|
1117
|
+
try {
|
|
1118
|
+
await afterAuth(await googleSignIn(credential));
|
|
1119
|
+
} catch (ex) {
|
|
1120
|
+
setErr(ex instanceof Error ? ex.message : "Google sign in failed.");
|
|
1121
|
+
} finally {
|
|
1122
|
+
setBusy(false);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
if (choices) {
|
|
1126
|
+
return /* @__PURE__ */ jsxs7("div", { children: [
|
|
1127
|
+
/* @__PURE__ */ jsx8("div", { className: "logo", children: brand }),
|
|
1128
|
+
/* @__PURE__ */ jsx8("h1", { children: "Choose workspace" }),
|
|
1129
|
+
/* @__PURE__ */ jsx8("div", { className: "org-list", children: choices.map((o) => /* @__PURE__ */ jsx8(
|
|
1130
|
+
"button",
|
|
1131
|
+
{
|
|
1132
|
+
type: "button",
|
|
1133
|
+
className: "btn",
|
|
1134
|
+
style: { width: "100%", justifyContent: "flex-start", height: 38 },
|
|
1135
|
+
disabled: busy,
|
|
1136
|
+
onClick: () => {
|
|
1137
|
+
setBusy(true);
|
|
1138
|
+
enter(o.id).catch((ex) => {
|
|
1139
|
+
setErr(ex instanceof Error ? ex.message : "Could not select the workspace.");
|
|
1140
|
+
setBusy(false);
|
|
1141
|
+
});
|
|
1142
|
+
},
|
|
1143
|
+
children: o.name || o.id
|
|
1144
|
+
},
|
|
1145
|
+
o.id
|
|
1146
|
+
)) }),
|
|
1147
|
+
err && /* @__PURE__ */ jsx8("div", { className: "auth-err", children: err })
|
|
1148
|
+
] });
|
|
1149
|
+
}
|
|
1150
|
+
return /* @__PURE__ */ jsxs7("form", { onSubmit: submit, children: [
|
|
1151
|
+
/* @__PURE__ */ jsx8("div", { className: "logo", children: brand }),
|
|
1152
|
+
/* @__PURE__ */ jsx8("h1", { children: mode === "register" ? "Create your account" : mode === "forgot" ? "Reset password" : "Sign in" }),
|
|
1153
|
+
/* @__PURE__ */ jsx8("p", { className: "sub", children: mode === "register" ? "Get started in seconds." : mode === "forgot" ? "We will email you a reset link." : subtitle || "Welcome back." }),
|
|
1154
|
+
mode === "forgot" ? resetSent ? /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1155
|
+
/* @__PURE__ */ jsxs7("div", { className: "auth-note", children: [
|
|
1156
|
+
"If an account exists for ",
|
|
1157
|
+
/* @__PURE__ */ jsx8("b", { children: email.trim() }),
|
|
1158
|
+
", a password reset link is on its way. It is valid for 1 hour."
|
|
1159
|
+
] }),
|
|
1160
|
+
/* @__PURE__ */ jsx8(
|
|
1161
|
+
"button",
|
|
1162
|
+
{
|
|
1163
|
+
type: "button",
|
|
1164
|
+
className: "btn primary lg",
|
|
1165
|
+
style: { width: "100%", marginTop: 14 },
|
|
1166
|
+
onClick: () => {
|
|
1167
|
+
setErr("");
|
|
1168
|
+
setResetSent(false);
|
|
1169
|
+
setMode("signin");
|
|
1170
|
+
},
|
|
1171
|
+
children: "Back to sign in"
|
|
1172
|
+
}
|
|
1173
|
+
)
|
|
1174
|
+
] }) : /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1175
|
+
/* @__PURE__ */ jsxs7("div", { className: "field", children: [
|
|
1176
|
+
/* @__PURE__ */ jsx8("label", { children: "Email" }),
|
|
1177
|
+
/* @__PURE__ */ jsx8("input", { className: "input", type: "email", value: email, onChange: (e) => setEmail(e.target.value), autoFocus: true, required: true, autoComplete: "email" })
|
|
1178
|
+
] }),
|
|
1179
|
+
err && /* @__PURE__ */ jsx8("div", { className: "auth-err", children: err }),
|
|
1180
|
+
/* @__PURE__ */ jsx8("button", { type: "submit", className: "btn primary lg", style: { width: "100%", marginTop: 8 }, disabled: busy, children: busy ? "Please wait..." : "Send reset link" }),
|
|
1181
|
+
/* @__PURE__ */ jsx8("p", { className: "auth-switch", children: /* @__PURE__ */ jsx8("button", { type: "button", onClick: () => {
|
|
1182
|
+
setErr("");
|
|
1183
|
+
setMode("signin");
|
|
1184
|
+
}, children: "Back to sign in" }) })
|
|
1185
|
+
] }) : /* @__PURE__ */ jsxs7(Fragment3, { children: [
|
|
1186
|
+
mode === "register" && /* @__PURE__ */ jsxs7("div", { className: "field", children: [
|
|
1187
|
+
/* @__PURE__ */ jsx8("label", { children: "Name" }),
|
|
1188
|
+
/* @__PURE__ */ jsx8("input", { className: "input", value: name, onChange: (e) => setName(e.target.value), autoComplete: "name", placeholder: "Jane Doe" })
|
|
1189
|
+
] }),
|
|
1190
|
+
/* @__PURE__ */ jsxs7("div", { className: "field", children: [
|
|
1191
|
+
/* @__PURE__ */ jsx8("label", { children: "Email" }),
|
|
1192
|
+
/* @__PURE__ */ jsx8("input", { className: "input", type: "email", value: email, onChange: (e) => setEmail(e.target.value), autoFocus: true, required: true, autoComplete: "email" })
|
|
1193
|
+
] }),
|
|
1194
|
+
/* @__PURE__ */ jsxs7("div", { className: "field", children: [
|
|
1195
|
+
/* @__PURE__ */ jsxs7("div", { className: "field-row", children: [
|
|
1196
|
+
/* @__PURE__ */ jsx8("label", { children: "Password" }),
|
|
1197
|
+
mode === "signin" && /* @__PURE__ */ jsx8("button", { type: "button", className: "link-sm", onClick: () => {
|
|
1198
|
+
setErr("");
|
|
1199
|
+
setResetSent(false);
|
|
1200
|
+
setMode("forgot");
|
|
1201
|
+
}, children: "Forgot password?" })
|
|
1202
|
+
] }),
|
|
1203
|
+
/* @__PURE__ */ jsx8(
|
|
1204
|
+
"input",
|
|
1205
|
+
{
|
|
1206
|
+
className: "input",
|
|
1207
|
+
type: "password",
|
|
1208
|
+
value: password,
|
|
1209
|
+
onChange: (e) => setPassword(e.target.value),
|
|
1210
|
+
required: true,
|
|
1211
|
+
autoComplete: mode === "register" ? "new-password" : "current-password",
|
|
1212
|
+
placeholder: mode === "register" ? "At least 8 characters" : ""
|
|
1213
|
+
}
|
|
1214
|
+
)
|
|
1215
|
+
] }),
|
|
1216
|
+
err && /* @__PURE__ */ jsx8("div", { className: "auth-err", children: err }),
|
|
1217
|
+
/* @__PURE__ */ jsx8("button", { type: "submit", className: "btn primary lg", style: { width: "100%", marginTop: 8 }, disabled: busy, children: busy ? "Please wait..." : mode === "register" ? "Create account" : "Sign in" }),
|
|
1218
|
+
GOOGLE_ENABLED && /* @__PURE__ */ jsx8(GoogleButton, { onCredential: onGoogle, onError: setErr }),
|
|
1219
|
+
/* @__PURE__ */ jsxs7("p", { className: "auth-switch", children: [
|
|
1220
|
+
mode === "register" ? "Already have an account?" : `New to ${productName || "the product"}?`,
|
|
1221
|
+
" ",
|
|
1222
|
+
/* @__PURE__ */ jsx8("button", { type: "button", onClick: () => {
|
|
1223
|
+
setErr("");
|
|
1224
|
+
setMode(mode === "register" ? "signin" : "register");
|
|
1225
|
+
}, children: mode === "register" ? "Sign in" : "Create one" })
|
|
1226
|
+
] })
|
|
1227
|
+
] })
|
|
1228
|
+
] });
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// src/sheet/SheetGrid.jsx
|
|
1232
|
+
import { useEffect as useEffect4, useRef as useRef4, useState as useState5 } from "react";
|
|
1233
|
+
import { createPortal } from "react-dom";
|
|
1234
|
+
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1235
|
+
var cellKey = (rowId, colId) => `${rowId}:${colId}`;
|
|
1236
|
+
var uid = (p) => `${p}_${Math.random().toString(36).slice(2, 10)}`;
|
|
1237
|
+
var TYPE_LABEL = {
|
|
1238
|
+
text: "Text",
|
|
1239
|
+
number: "Number",
|
|
1240
|
+
select: "Select",
|
|
1241
|
+
tags: "Tags",
|
|
1242
|
+
checkbox: "Checkbox",
|
|
1243
|
+
date: "Date",
|
|
1244
|
+
url: "Link",
|
|
1245
|
+
resource: "Resource",
|
|
1246
|
+
compute: "Computed"
|
|
1247
|
+
};
|
|
1248
|
+
var MANUAL_TYPES = ["text", "number", "select", "tags", "checkbox", "date", "url", "resource"];
|
|
1249
|
+
var COMPUTE_KINDS = [
|
|
1250
|
+
{ kind: "prompt", label: "AI prompt" },
|
|
1251
|
+
{ kind: "harness", label: "Agent (harness)" },
|
|
1252
|
+
{ kind: "workflow", label: "Workflow" },
|
|
1253
|
+
{ kind: "image", label: "Generate image" }
|
|
1254
|
+
];
|
|
1255
|
+
var RESOURCE_KINDS = ["image", "sheet", "slides", "workflow", "graph"];
|
|
1256
|
+
var RESOURCE_ICON = { image: "\u{1F5BC}", sheet: "\u25A6", slides: "\u25A4", workflow: "\u2699", graph: "\u25C9" };
|
|
1257
|
+
function PopPortal({ anchor, width = 250, estHeight = 300, className, children, onClose }) {
|
|
1258
|
+
useEffect4(() => {
|
|
1259
|
+
if (!onClose) return void 0;
|
|
1260
|
+
const close = () => onClose();
|
|
1261
|
+
window.addEventListener("scroll", close, true);
|
|
1262
|
+
window.addEventListener("resize", close);
|
|
1263
|
+
return () => {
|
|
1264
|
+
window.removeEventListener("scroll", close, true);
|
|
1265
|
+
window.removeEventListener("resize", close);
|
|
1266
|
+
};
|
|
1267
|
+
}, [onClose]);
|
|
1268
|
+
if (!anchor) return null;
|
|
1269
|
+
const left = Math.max(8, Math.min(anchor.right - width, window.innerWidth - width - 8));
|
|
1270
|
+
let top = anchor.bottom + 6;
|
|
1271
|
+
if (top + estHeight > window.innerHeight - 8) top = Math.max(8, anchor.top - estHeight - 6);
|
|
1272
|
+
return createPortal(
|
|
1273
|
+
/* @__PURE__ */ jsx9("div", { className, style: { position: "fixed", top, left, width, zIndex: 1e3 }, children }),
|
|
1274
|
+
document.body
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1277
|
+
var PILL_FALLBACKS = ["#E0E7FF", "#FCE7F3", "#D1FAE5", "#FEF3C7", "#E0F2FE", "#F3E8FF", "#FFE4E6"];
|
|
1278
|
+
function normOptions(options) {
|
|
1279
|
+
return (options || []).map((o, i) => {
|
|
1280
|
+
if (typeof o === "string") return { label: o, color: PILL_FALLBACKS[i % PILL_FALLBACKS.length] };
|
|
1281
|
+
return { label: o.label ?? String(o.value ?? ""), color: o.color || PILL_FALLBACKS[i % PILL_FALLBACKS.length] };
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
function pillColor(label, options) {
|
|
1285
|
+
const opts = normOptions(options);
|
|
1286
|
+
const hit = opts.find((o) => o.label === label);
|
|
1287
|
+
if (hit) return hit.color;
|
|
1288
|
+
let h = 0;
|
|
1289
|
+
for (const ch of String(label)) h = h * 31 + ch.charCodeAt(0) >>> 0;
|
|
1290
|
+
return PILL_FALLBACKS[h % PILL_FALLBACKS.length];
|
|
1291
|
+
}
|
|
1292
|
+
function RefImage({ refVal, fetchBlobUrl }) {
|
|
1293
|
+
const [src, setSrc] = useState5(/^https?:\/\//i.test(refVal.url || "") ? refVal.url : null);
|
|
1294
|
+
useEffect4(() => {
|
|
1295
|
+
let dead = false;
|
|
1296
|
+
let obj = null;
|
|
1297
|
+
if (!src && refVal.url && fetchBlobUrl) {
|
|
1298
|
+
fetchBlobUrl(refVal.url).then((u) => {
|
|
1299
|
+
if (!dead) {
|
|
1300
|
+
obj = u;
|
|
1301
|
+
setSrc(u);
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
return () => {
|
|
1306
|
+
dead = true;
|
|
1307
|
+
if (obj) URL.revokeObjectURL(obj);
|
|
1308
|
+
};
|
|
1309
|
+
}, [refVal.url]);
|
|
1310
|
+
if (!src) return /* @__PURE__ */ jsxs8("span", { className: "shg-refchip", children: [
|
|
1311
|
+
RESOURCE_ICON.image,
|
|
1312
|
+
" ",
|
|
1313
|
+
refVal.name || "image"
|
|
1314
|
+
] });
|
|
1315
|
+
return /* @__PURE__ */ jsx9("img", { className: "shg-refimg", src, alt: refVal.name || "", title: refVal.name || "" });
|
|
1316
|
+
}
|
|
1317
|
+
function ResourceChip({ refVal, onOpen }) {
|
|
1318
|
+
const icon = RESOURCE_ICON[refVal.kind] || "\u25C7";
|
|
1319
|
+
return /* @__PURE__ */ jsxs8(
|
|
1320
|
+
"button",
|
|
1321
|
+
{
|
|
1322
|
+
className: "shg-refchip shg-refchip-btn",
|
|
1323
|
+
title: `Open ${refVal.kind}`,
|
|
1324
|
+
onClick: (e) => {
|
|
1325
|
+
e.stopPropagation();
|
|
1326
|
+
onOpen && onOpen(refVal);
|
|
1327
|
+
},
|
|
1328
|
+
children: [
|
|
1329
|
+
/* @__PURE__ */ jsx9("span", { className: "shg-refchip-ic", children: icon }),
|
|
1330
|
+
/* @__PURE__ */ jsx9("span", { className: "shg-refchip-name", children: refVal.name || refVal.id || refVal.kind })
|
|
1331
|
+
]
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
function StatusDot({ status }) {
|
|
1336
|
+
if (!status || status === "empty") return null;
|
|
1337
|
+
return /* @__PURE__ */ jsx9("span", { className: `shg-dot shg-dot-${status}`, title: status });
|
|
1338
|
+
}
|
|
1339
|
+
function CellValue({ cell, col, fetchBlobUrl, onOpenResource }) {
|
|
1340
|
+
const v = cell?.value;
|
|
1341
|
+
if (v === void 0 || v === null || v === "") return /* @__PURE__ */ jsx9("span", { className: "shg-val-txt" });
|
|
1342
|
+
if (v && typeof v === "object" && !Array.isArray(v) && v.kind) {
|
|
1343
|
+
if (v.kind === "image") return /* @__PURE__ */ jsx9(RefImage, { refVal: v, fetchBlobUrl });
|
|
1344
|
+
return /* @__PURE__ */ jsx9(ResourceChip, { refVal: v, onOpen: onOpenResource });
|
|
1345
|
+
}
|
|
1346
|
+
switch (col.type) {
|
|
1347
|
+
case "select":
|
|
1348
|
+
return /* @__PURE__ */ jsx9("span", { className: "shg-pill", style: { background: pillColor(String(v), col.options) }, children: String(v) });
|
|
1349
|
+
case "tags": {
|
|
1350
|
+
const tags = Array.isArray(v) ? v : String(v).split(",").map((s) => s.trim()).filter(Boolean);
|
|
1351
|
+
return /* @__PURE__ */ jsx9("span", { className: "shg-pills", children: tags.map((t) => /* @__PURE__ */ jsx9("span", { className: "shg-pill", style: { background: pillColor(t, col.options) }, children: t }, t)) });
|
|
1352
|
+
}
|
|
1353
|
+
case "checkbox":
|
|
1354
|
+
return /* @__PURE__ */ jsx9("span", { className: "shg-check" + (v ? " on" : ""), children: v ? "\u2713" : "" });
|
|
1355
|
+
case "url": {
|
|
1356
|
+
const href = /^https?:\/\//i.test(String(v)) ? String(v) : `https://${v}`;
|
|
1357
|
+
return /* @__PURE__ */ jsx9("a", { className: "shg-link", href, target: "_blank", rel: "noreferrer", onClick: (e) => e.stopPropagation(), children: String(v) });
|
|
1358
|
+
}
|
|
1359
|
+
case "number":
|
|
1360
|
+
return /* @__PURE__ */ jsx9("span", { className: "shg-val-txt shg-num", children: String(v) });
|
|
1361
|
+
default:
|
|
1362
|
+
return /* @__PURE__ */ jsx9("span", { className: "shg-val-txt", children: typeof v === "object" ? JSON.stringify(v) : String(v) });
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
function SheetGrid({ sheet, onChange, onRunCell, onRunColumn, readOnly = false, fetchBlobUrl, onOpenResource, peerMarks, onActiveCell }) {
|
|
1366
|
+
const columns = sheet?.columns || [];
|
|
1367
|
+
const rows = sheet?.rows || [];
|
|
1368
|
+
const cells = sheet?.cells || {};
|
|
1369
|
+
const [editing, setEditing] = useState5(null);
|
|
1370
|
+
const [draft, setDraft] = useState5("");
|
|
1371
|
+
const [menuCol, setMenuCol] = useState5(null);
|
|
1372
|
+
const [sizeDraft, setSizeDraft] = useState5({});
|
|
1373
|
+
const [dnd, setDnd] = useState5(null);
|
|
1374
|
+
const [dropAt, setDropAt] = useState5(null);
|
|
1375
|
+
const inputRef = useRef4(null);
|
|
1376
|
+
const dragRef = useRef4(null);
|
|
1377
|
+
const startResize = (e, kind, id, start) => {
|
|
1378
|
+
if (readOnly) return;
|
|
1379
|
+
e.preventDefault();
|
|
1380
|
+
e.stopPropagation();
|
|
1381
|
+
const origin = kind === "col" ? e.clientX : e.clientY;
|
|
1382
|
+
dragRef.current = { kind, id, start, origin, last: start };
|
|
1383
|
+
const onMove = (ev) => {
|
|
1384
|
+
const d = dragRef.current;
|
|
1385
|
+
if (!d) return;
|
|
1386
|
+
const delta = (d.kind === "col" ? ev.clientX : ev.clientY) - d.origin;
|
|
1387
|
+
const next = Math.max(d.kind === "col" ? 90 : 26, d.start + delta);
|
|
1388
|
+
d.last = next;
|
|
1389
|
+
setSizeDraft((sd) => ({ ...sd, [d.kind]: { ...sd[d.kind] || {}, [d.id]: next } }));
|
|
1390
|
+
};
|
|
1391
|
+
const onUp = () => {
|
|
1392
|
+
const d = dragRef.current;
|
|
1393
|
+
dragRef.current = null;
|
|
1394
|
+
window.removeEventListener("mousemove", onMove);
|
|
1395
|
+
window.removeEventListener("mouseup", onUp);
|
|
1396
|
+
document.body.style.cursor = "";
|
|
1397
|
+
if (!d) return;
|
|
1398
|
+
setSizeDraft({});
|
|
1399
|
+
mutate((n) => {
|
|
1400
|
+
if (d.kind === "col") {
|
|
1401
|
+
const c = n.columns.find((x) => x.id === d.id);
|
|
1402
|
+
if (c) c.width = Math.round(d.last);
|
|
1403
|
+
} else {
|
|
1404
|
+
const r = n.rows.find((x) => x.id === d.id);
|
|
1405
|
+
if (r) r.height = Math.round(d.last);
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
};
|
|
1409
|
+
window.addEventListener("mousemove", onMove);
|
|
1410
|
+
window.addEventListener("mouseup", onUp);
|
|
1411
|
+
document.body.style.cursor = kind === "col" ? "col-resize" : "row-resize";
|
|
1412
|
+
};
|
|
1413
|
+
const colWidth = (col) => sizeDraft.col && sizeDraft.col[col.id] || col.width || void 0;
|
|
1414
|
+
const reorder = (kind, fromId, toId, after) => mutate((n) => {
|
|
1415
|
+
const arr = kind === "col" ? n.columns : n.rows;
|
|
1416
|
+
const i = arr.findIndex((x) => x.id === fromId);
|
|
1417
|
+
if (i < 0 || fromId === toId) return;
|
|
1418
|
+
const [item] = arr.splice(i, 1);
|
|
1419
|
+
let j = arr.findIndex((x) => x.id === toId);
|
|
1420
|
+
if (j < 0) {
|
|
1421
|
+
arr.splice(i, 0, item);
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
if (after) j += 1;
|
|
1425
|
+
arr.splice(j, 0, item);
|
|
1426
|
+
});
|
|
1427
|
+
const dndProps = (kind, id) => readOnly ? {} : {
|
|
1428
|
+
draggable: true,
|
|
1429
|
+
onDragStart: (e) => {
|
|
1430
|
+
if (e.target.closest && e.target.closest(".shg-resize-col, .shg-resize-row, input, button")) {
|
|
1431
|
+
e.preventDefault();
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
e.dataTransfer.effectAllowed = "move";
|
|
1435
|
+
e.dataTransfer.setData("text/plain", `${kind}:${id}`);
|
|
1436
|
+
setDnd({ kind, id });
|
|
1437
|
+
},
|
|
1438
|
+
onDragOver: (e) => {
|
|
1439
|
+
if (!dnd || dnd.kind !== kind || dnd.id === id) return;
|
|
1440
|
+
e.preventDefault();
|
|
1441
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
1442
|
+
const after = kind === "col" ? e.clientX > r.x + r.width / 2 : e.clientY > r.y + r.height / 2;
|
|
1443
|
+
setDropAt((d) => d && d.id === id && d.after === after ? d : { kind, id, after });
|
|
1444
|
+
},
|
|
1445
|
+
onDrop: (e) => {
|
|
1446
|
+
e.preventDefault();
|
|
1447
|
+
if (dnd && dnd.kind === kind && dnd.id !== id) {
|
|
1448
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
1449
|
+
const after = kind === "col" ? e.clientX > r.x + r.width / 2 : e.clientY > r.y + r.height / 2;
|
|
1450
|
+
reorder(kind, dnd.id, id, after);
|
|
1451
|
+
}
|
|
1452
|
+
setDnd(null);
|
|
1453
|
+
setDropAt(null);
|
|
1454
|
+
},
|
|
1455
|
+
onDragEnd: () => {
|
|
1456
|
+
setDnd(null);
|
|
1457
|
+
setDropAt(null);
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
const dndClass = (kind, id) => {
|
|
1461
|
+
let cls = "";
|
|
1462
|
+
if (dnd && dnd.kind === kind && dnd.id === id) cls += " shg-dragging";
|
|
1463
|
+
if (dropAt && dropAt.kind === kind && dropAt.id === id) {
|
|
1464
|
+
cls += dropAt.after ? kind === "col" ? " shg-drop-after" : " shg-drop-below" : kind === "col" ? " shg-drop-before" : " shg-drop-above";
|
|
1465
|
+
}
|
|
1466
|
+
return cls;
|
|
1467
|
+
};
|
|
1468
|
+
const numW = Math.max(40, 24 + String(rows.length || 1).length * 9);
|
|
1469
|
+
const numStyle = { width: numW, minWidth: numW, maxWidth: numW };
|
|
1470
|
+
const rowHeight = (row) => sizeDraft.row && sizeDraft.row[row.id] || row.height || void 0;
|
|
1471
|
+
useEffect4(() => {
|
|
1472
|
+
if (editing && inputRef.current) inputRef.current.focus();
|
|
1473
|
+
}, [editing]);
|
|
1474
|
+
const mutate = (fn) => {
|
|
1475
|
+
if (readOnly || !onChange) return;
|
|
1476
|
+
const next = JSON.parse(JSON.stringify(sheet));
|
|
1477
|
+
fn(next);
|
|
1478
|
+
onChange(next);
|
|
1479
|
+
};
|
|
1480
|
+
const setCell = (rowId, colId, value) => mutate((n) => {
|
|
1481
|
+
n.cells = n.cells || {};
|
|
1482
|
+
n.cells[cellKey(rowId, colId)] = { value, status: "done", updated_at: Math.floor(Date.now() / 1e3) };
|
|
1483
|
+
});
|
|
1484
|
+
const openEdit = (rowId, col, anchorEl) => {
|
|
1485
|
+
if (readOnly) return;
|
|
1486
|
+
if (col.type === "compute") return;
|
|
1487
|
+
if (col.type === "checkbox") {
|
|
1488
|
+
const cur = cells[cellKey(rowId, col.id)];
|
|
1489
|
+
setCell(rowId, col.id, !(cur && cur.value));
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
const c = cells[cellKey(rowId, col.id)];
|
|
1493
|
+
const v = c?.value;
|
|
1494
|
+
if (col.type === "tags") setDraft(Array.isArray(v) ? v.join(", ") : v || "");
|
|
1495
|
+
else if (col.type === "resource") setDraft(v && typeof v === "object" ? v : { kind: "sheet", name: "", id: "", url: "" });
|
|
1496
|
+
else setDraft(v == null ? "" : String(v));
|
|
1497
|
+
setEditing({ rowId, colId: col.id, type: col.type, rect: anchorEl?.getBoundingClientRect?.() || null });
|
|
1498
|
+
onActiveCell && onActiveCell(cellKey(rowId, col.id));
|
|
1499
|
+
};
|
|
1500
|
+
const commitEdit = () => {
|
|
1501
|
+
onActiveCell && onActiveCell(null);
|
|
1502
|
+
if (!editing) return;
|
|
1503
|
+
const { rowId, colId, type } = editing;
|
|
1504
|
+
let value = draft;
|
|
1505
|
+
if (type === "number") value = draft === "" ? null : Number(draft);
|
|
1506
|
+
else if (type === "tags") value = draft ? draft.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
1507
|
+
setCell(rowId, colId, value);
|
|
1508
|
+
setEditing(null);
|
|
1509
|
+
};
|
|
1510
|
+
const addColumn = () => mutate((n) => {
|
|
1511
|
+
n.columns.push({ id: uid("col"), name: `Column ${n.columns.length + 1}`, type: "text" });
|
|
1512
|
+
});
|
|
1513
|
+
const addRow = () => mutate((n) => {
|
|
1514
|
+
n.rows.push({ id: uid("row") });
|
|
1515
|
+
});
|
|
1516
|
+
const deleteColumn = (colId) => mutate((n) => {
|
|
1517
|
+
n.columns = n.columns.filter((c) => c.id !== colId);
|
|
1518
|
+
for (const k of Object.keys(n.cells || {})) if (k.endsWith(`:${colId}`)) delete n.cells[k];
|
|
1519
|
+
});
|
|
1520
|
+
const deleteRow = (rowId) => mutate((n) => {
|
|
1521
|
+
n.rows = n.rows.filter((r) => r.id !== rowId);
|
|
1522
|
+
for (const k of Object.keys(n.cells || {})) if (k.startsWith(`${rowId}:`)) delete n.cells[k];
|
|
1523
|
+
});
|
|
1524
|
+
const renameColumn = (colId, name) => mutate((n) => {
|
|
1525
|
+
const c = n.columns.find((x) => x.id === colId);
|
|
1526
|
+
if (c) c.name = name;
|
|
1527
|
+
});
|
|
1528
|
+
const configureColumn = (colId, patch) => mutate((n) => {
|
|
1529
|
+
const c = n.columns.find((x) => x.id === colId);
|
|
1530
|
+
if (!c) return;
|
|
1531
|
+
Object.assign(c, patch);
|
|
1532
|
+
if (patch.type && patch.type !== "compute") delete c.compute;
|
|
1533
|
+
});
|
|
1534
|
+
const renderEditor = (col) => {
|
|
1535
|
+
if (col.type === "resource") {
|
|
1536
|
+
const d = typeof draft === "object" && draft ? draft : { kind: "sheet" };
|
|
1537
|
+
const set = (k, v) => setDraft({ ...d, [k]: v });
|
|
1538
|
+
return /* @__PURE__ */ jsx9(
|
|
1539
|
+
PopPortal,
|
|
1540
|
+
{
|
|
1541
|
+
anchor: editing.rect,
|
|
1542
|
+
width: 240,
|
|
1543
|
+
estHeight: 230,
|
|
1544
|
+
className: "shg-select-pop shg-ref-pop",
|
|
1545
|
+
onClose: () => setEditing(null),
|
|
1546
|
+
children: /* @__PURE__ */ jsxs8("div", { onClick: (e) => e.stopPropagation(), children: [
|
|
1547
|
+
/* @__PURE__ */ jsx9("select", { className: "shg-menu-input", value: d.kind || "sheet", onChange: (e) => set("kind", e.target.value), children: RESOURCE_KINDS.map((k) => /* @__PURE__ */ jsx9("option", { value: k, children: k }, k)) }),
|
|
1548
|
+
/* @__PURE__ */ jsx9("input", { className: "shg-menu-input", placeholder: "Name", value: d.name || "", onChange: (e) => set("name", e.target.value) }),
|
|
1549
|
+
/* @__PURE__ */ jsx9("input", { className: "shg-menu-input", placeholder: "Resource id (e.g. sheet.\u2026)", value: d.id || "", onChange: (e) => set("id", e.target.value) }),
|
|
1550
|
+
/* @__PURE__ */ jsx9("input", { className: "shg-menu-input", placeholder: "or URL", value: d.url || "", onChange: (e) => set("url", e.target.value) }),
|
|
1551
|
+
/* @__PURE__ */ jsxs8("div", { className: "shg-menu-actions", children: [
|
|
1552
|
+
/* @__PURE__ */ jsx9("button", { className: "shg-pop-clear", onClick: () => {
|
|
1553
|
+
setCell(editing.rowId, editing.colId, null);
|
|
1554
|
+
setEditing(null);
|
|
1555
|
+
}, children: "Clear" }),
|
|
1556
|
+
/* @__PURE__ */ jsx9("button", { className: "shg-menu-apply", onClick: () => {
|
|
1557
|
+
setCell(editing.rowId, editing.colId, d);
|
|
1558
|
+
setEditing(null);
|
|
1559
|
+
}, children: "Set" })
|
|
1560
|
+
] })
|
|
1561
|
+
] })
|
|
1562
|
+
}
|
|
1563
|
+
);
|
|
1564
|
+
}
|
|
1565
|
+
if (col.type === "select") {
|
|
1566
|
+
const opts = normOptions(col.options);
|
|
1567
|
+
return /* @__PURE__ */ jsxs8(
|
|
1568
|
+
PopPortal,
|
|
1569
|
+
{
|
|
1570
|
+
anchor: editing.rect,
|
|
1571
|
+
width: 190,
|
|
1572
|
+
estHeight: 40 + opts.length * 30,
|
|
1573
|
+
className: "shg-select-pop",
|
|
1574
|
+
onClose: () => setEditing(null),
|
|
1575
|
+
children: [
|
|
1576
|
+
opts.length === 0 && /* @__PURE__ */ jsx9("div", { className: "shg-pop-note", children: "No options yet \u2014 add them in the column menu." }),
|
|
1577
|
+
opts.map((o) => /* @__PURE__ */ jsx9(
|
|
1578
|
+
"button",
|
|
1579
|
+
{
|
|
1580
|
+
className: "shg-pill shg-pill-btn",
|
|
1581
|
+
style: { background: o.color },
|
|
1582
|
+
onClick: (e) => {
|
|
1583
|
+
e.stopPropagation();
|
|
1584
|
+
setCell(editing.rowId, editing.colId, o.label);
|
|
1585
|
+
setEditing(null);
|
|
1586
|
+
},
|
|
1587
|
+
children: o.label
|
|
1588
|
+
},
|
|
1589
|
+
o.label
|
|
1590
|
+
)),
|
|
1591
|
+
/* @__PURE__ */ jsx9(
|
|
1592
|
+
"button",
|
|
1593
|
+
{
|
|
1594
|
+
className: "shg-pop-clear",
|
|
1595
|
+
onClick: (e) => {
|
|
1596
|
+
e.stopPropagation();
|
|
1597
|
+
setCell(editing.rowId, editing.colId, null);
|
|
1598
|
+
setEditing(null);
|
|
1599
|
+
},
|
|
1600
|
+
children: "Clear"
|
|
1601
|
+
}
|
|
1602
|
+
)
|
|
1603
|
+
]
|
|
1604
|
+
}
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1607
|
+
const inputType = col.type === "date" ? "date" : col.type === "number" ? "number" : "text";
|
|
1608
|
+
return /* @__PURE__ */ jsx9(
|
|
1609
|
+
"input",
|
|
1610
|
+
{
|
|
1611
|
+
ref: inputRef,
|
|
1612
|
+
className: "shg-input",
|
|
1613
|
+
type: inputType,
|
|
1614
|
+
value: draft,
|
|
1615
|
+
placeholder: col.type === "tags" ? "tag, tag, \u2026" : "",
|
|
1616
|
+
onChange: (e) => setDraft(e.target.value),
|
|
1617
|
+
onBlur: commitEdit,
|
|
1618
|
+
onKeyDown: (e) => {
|
|
1619
|
+
if (e.key === "Enter") commitEdit();
|
|
1620
|
+
if (e.key === "Escape") setEditing(null);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
);
|
|
1624
|
+
};
|
|
1625
|
+
return /* @__PURE__ */ jsx9("div", { className: "shg", children: /* @__PURE__ */ jsx9("div", { className: "shg-scroll", children: /* @__PURE__ */ jsxs8("table", { className: "shg-table", children: [
|
|
1626
|
+
/* @__PURE__ */ jsx9("thead", { children: /* @__PURE__ */ jsxs8("tr", { children: [
|
|
1627
|
+
/* @__PURE__ */ jsx9("th", { className: "shg-corner", style: numStyle }),
|
|
1628
|
+
columns.map((col) => /* @__PURE__ */ jsxs8(
|
|
1629
|
+
"th",
|
|
1630
|
+
{
|
|
1631
|
+
className: "shg-col" + (col.type === "compute" ? " shg-col-compute" : "") + dndClass("col", col.id),
|
|
1632
|
+
style: colWidth(col) ? { width: colWidth(col), minWidth: colWidth(col), maxWidth: colWidth(col) } : void 0,
|
|
1633
|
+
...dndProps("col", col.id),
|
|
1634
|
+
children: [
|
|
1635
|
+
!readOnly && /* @__PURE__ */ jsx9("span", { className: "shg-resize-col", onMouseDown: (e) => startResize(e, "col", col.id, colWidth(col) || e.currentTarget.closest("th").offsetWidth) }),
|
|
1636
|
+
/* @__PURE__ */ jsx9("div", { className: "shg-col-h", children: /* @__PURE__ */ jsx9(
|
|
1637
|
+
ColumnHeader,
|
|
1638
|
+
{
|
|
1639
|
+
col,
|
|
1640
|
+
columns,
|
|
1641
|
+
readOnly,
|
|
1642
|
+
menuOpen: menuCol?.id === col.id,
|
|
1643
|
+
menuAnchor: menuCol?.id === col.id ? menuCol.rect : null,
|
|
1644
|
+
onMenu: (e) => setMenuCol(menuCol?.id === col.id ? null : { id: col.id, rect: e.currentTarget.getBoundingClientRect() }),
|
|
1645
|
+
onCloseMenu: () => setMenuCol(null),
|
|
1646
|
+
onRename: renameColumn,
|
|
1647
|
+
onConfigure: configureColumn,
|
|
1648
|
+
onDelete: () => {
|
|
1649
|
+
setMenuCol(null);
|
|
1650
|
+
deleteColumn(col.id);
|
|
1651
|
+
},
|
|
1652
|
+
onRun: col.type === "compute" && onRunColumn ? () => onRunColumn(col.id) : null
|
|
1653
|
+
}
|
|
1654
|
+
) })
|
|
1655
|
+
]
|
|
1656
|
+
},
|
|
1657
|
+
col.id
|
|
1658
|
+
)),
|
|
1659
|
+
!readOnly && /* @__PURE__ */ jsx9("th", { className: "shg-add-col", children: /* @__PURE__ */ jsx9("button", { className: "shg-add", onClick: addColumn, title: "Add column", children: "+" }) })
|
|
1660
|
+
] }) }),
|
|
1661
|
+
/* @__PURE__ */ jsxs8("tbody", { children: [
|
|
1662
|
+
rows.map((row, ri) => /* @__PURE__ */ jsxs8(
|
|
1663
|
+
"tr",
|
|
1664
|
+
{
|
|
1665
|
+
style: {
|
|
1666
|
+
...rowHeight(row) ? { height: rowHeight(row) } : null,
|
|
1667
|
+
"--shg-clamp": Math.max(1, Math.floor(((rowHeight(row) || 34) - 10) / 18))
|
|
1668
|
+
},
|
|
1669
|
+
children: [
|
|
1670
|
+
/* @__PURE__ */ jsxs8(
|
|
1671
|
+
"td",
|
|
1672
|
+
{
|
|
1673
|
+
className: "shg-rownum" + dndClass("row", row.id),
|
|
1674
|
+
style: numStyle,
|
|
1675
|
+
title: "Drag to reorder",
|
|
1676
|
+
...dndProps("row", row.id),
|
|
1677
|
+
children: [
|
|
1678
|
+
/* @__PURE__ */ jsx9("span", { children: ri + 1 }),
|
|
1679
|
+
!readOnly && /* @__PURE__ */ jsx9("button", { className: "shg-rowdel", onClick: () => deleteRow(row.id), title: "Delete row", children: "\xD7" }),
|
|
1680
|
+
!readOnly && /* @__PURE__ */ jsx9("span", { className: "shg-resize-row", onMouseDown: (e) => startResize(e, "row", row.id, rowHeight(row) || e.currentTarget.closest("tr").offsetHeight) })
|
|
1681
|
+
]
|
|
1682
|
+
}
|
|
1683
|
+
),
|
|
1684
|
+
columns.map((col) => {
|
|
1685
|
+
const c = cells[cellKey(row.id, col.id)] || {};
|
|
1686
|
+
const isEditing = editing && editing.rowId === row.id && editing.colId === col.id;
|
|
1687
|
+
const peer = peerMarks && peerMarks[cellKey(row.id, col.id)];
|
|
1688
|
+
return /* @__PURE__ */ jsxs8(
|
|
1689
|
+
"td",
|
|
1690
|
+
{
|
|
1691
|
+
className: "shg-cell" + (col.type === "compute" ? " shg-cell-compute" : "") + (c.status && col.type === "compute" ? ` shg-cell-${c.status}` : "") + (peer ? " shg-cell-peer" : ""),
|
|
1692
|
+
style: peer ? { boxShadow: `inset 0 0 0 2px ${peer.color}` } : void 0,
|
|
1693
|
+
onClick: (e) => {
|
|
1694
|
+
if (!isEditing) openEdit(row.id, col, e.currentTarget);
|
|
1695
|
+
},
|
|
1696
|
+
title: c.error || "",
|
|
1697
|
+
children: [
|
|
1698
|
+
peer && /* @__PURE__ */ jsx9("span", { className: "shg-peer-flag", style: { background: peer.color }, children: peer.name }),
|
|
1699
|
+
isEditing ? renderEditor(col) : /* @__PURE__ */ jsxs8(
|
|
1700
|
+
"div",
|
|
1701
|
+
{
|
|
1702
|
+
className: "shg-val",
|
|
1703
|
+
style: { maxWidth: colWidth(col) ? colWidth(col) - 20 : 400 },
|
|
1704
|
+
children: [
|
|
1705
|
+
col.type === "compute" && /* @__PURE__ */ jsx9(StatusDot, { status: c.status }),
|
|
1706
|
+
/* @__PURE__ */ jsx9(CellValue, { cell: c, col, fetchBlobUrl, onOpenResource }),
|
|
1707
|
+
col.type === "compute" && !readOnly && onRunCell && /* @__PURE__ */ jsx9(
|
|
1708
|
+
"button",
|
|
1709
|
+
{
|
|
1710
|
+
className: "shg-runcell",
|
|
1711
|
+
title: "Run this cell",
|
|
1712
|
+
onClick: (e) => {
|
|
1713
|
+
e.stopPropagation();
|
|
1714
|
+
onRunCell(row.id, col.id);
|
|
1715
|
+
},
|
|
1716
|
+
children: "\u25B6"
|
|
1717
|
+
}
|
|
1718
|
+
)
|
|
1719
|
+
]
|
|
1720
|
+
}
|
|
1721
|
+
)
|
|
1722
|
+
]
|
|
1723
|
+
},
|
|
1724
|
+
col.id
|
|
1725
|
+
);
|
|
1726
|
+
}),
|
|
1727
|
+
!readOnly && /* @__PURE__ */ jsx9("td", { className: "shg-pad" })
|
|
1728
|
+
]
|
|
1729
|
+
},
|
|
1730
|
+
row.id
|
|
1731
|
+
)),
|
|
1732
|
+
!readOnly && /* @__PURE__ */ jsxs8("tr", { className: "shg-ghost-row", onClick: addRow, children: [
|
|
1733
|
+
/* @__PURE__ */ jsx9("td", { className: "shg-rownum shg-ghost-num", style: numStyle, children: "+" }),
|
|
1734
|
+
/* @__PURE__ */ jsx9("td", { className: "shg-ghost-cell", colSpan: columns.length + 1, children: "New row" })
|
|
1735
|
+
] })
|
|
1736
|
+
] })
|
|
1737
|
+
] }) }) });
|
|
1738
|
+
}
|
|
1739
|
+
function ColumnHeader({ col, columns, readOnly, menuOpen, menuAnchor, onMenu, onCloseMenu, onRename, onConfigure, onDelete, onRun }) {
|
|
1740
|
+
const [editing, setEditing] = useState5(false);
|
|
1741
|
+
const [name, setName] = useState5(col.name);
|
|
1742
|
+
useEffect4(() => setName(col.name), [col.name]);
|
|
1743
|
+
return /* @__PURE__ */ jsxs8("div", { className: "shg-colhdr", children: [
|
|
1744
|
+
/* @__PURE__ */ jsxs8("div", { className: "shg-colhdr-main", children: [
|
|
1745
|
+
editing && !readOnly ? /* @__PURE__ */ jsx9(
|
|
1746
|
+
"input",
|
|
1747
|
+
{
|
|
1748
|
+
className: "shg-colname-input",
|
|
1749
|
+
value: name,
|
|
1750
|
+
autoFocus: true,
|
|
1751
|
+
onChange: (e) => setName(e.target.value),
|
|
1752
|
+
onBlur: () => {
|
|
1753
|
+
setEditing(false);
|
|
1754
|
+
if (name.trim() && name !== col.name) onRename(col.id, name.trim());
|
|
1755
|
+
},
|
|
1756
|
+
onKeyDown: (e) => {
|
|
1757
|
+
if (e.key === "Enter") e.target.blur();
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
) : /* @__PURE__ */ jsx9("span", { className: "shg-colname", onDoubleClick: () => !readOnly && setEditing(true), title: col.name, children: col.name }),
|
|
1761
|
+
/* @__PURE__ */ jsxs8("span", { className: "shg-coltype" + (col.type === "compute" ? " compute" : ""), children: [
|
|
1762
|
+
TYPE_LABEL[col.type] || col.type,
|
|
1763
|
+
col.type === "compute" && col.compute?.kind ? ` \xB7 ${col.compute.kind}` : ""
|
|
1764
|
+
] })
|
|
1765
|
+
] }),
|
|
1766
|
+
!readOnly && /* @__PURE__ */ jsxs8("div", { className: "shg-colhdr-tools", children: [
|
|
1767
|
+
onRun && /* @__PURE__ */ jsx9("button", { className: "shg-colrun", onClick: onRun, title: "Run this column", children: "\u25B6 Run" }),
|
|
1768
|
+
/* @__PURE__ */ jsx9("button", { className: "shg-colmenu-btn", onClick: (e) => onMenu(e), title: "Column settings", children: "\u22EF" })
|
|
1769
|
+
] }),
|
|
1770
|
+
menuOpen && !readOnly && /* @__PURE__ */ jsx9(
|
|
1771
|
+
ColumnMenu,
|
|
1772
|
+
{
|
|
1773
|
+
col,
|
|
1774
|
+
columns,
|
|
1775
|
+
anchor: menuAnchor,
|
|
1776
|
+
onApply: (patch) => {
|
|
1777
|
+
onConfigure(col.id, patch);
|
|
1778
|
+
onCloseMenu();
|
|
1779
|
+
},
|
|
1780
|
+
onDelete,
|
|
1781
|
+
onClose: onCloseMenu
|
|
1782
|
+
}
|
|
1783
|
+
)
|
|
1784
|
+
] });
|
|
1785
|
+
}
|
|
1786
|
+
function ColumnMenu({ col, columns, anchor, onApply, onDelete, onClose }) {
|
|
1787
|
+
const [type, setType] = useState5(col.type || "text");
|
|
1788
|
+
const [optText, setOptText] = useState5(
|
|
1789
|
+
normOptions(col.options).map((o) => o.label).join("\n")
|
|
1790
|
+
);
|
|
1791
|
+
const comp = col.compute || {};
|
|
1792
|
+
const [kind, setKind] = useState5(comp.kind || "prompt");
|
|
1793
|
+
const [prompt, setPrompt] = useState5(comp.prompt || "");
|
|
1794
|
+
const [harnessId, setHarnessId] = useState5(comp.harness_id || "");
|
|
1795
|
+
const [wfSlug, setWfSlug] = useState5(comp.workflow_slug || "");
|
|
1796
|
+
const [outKey, setOutKey] = useState5(comp.output_key || "");
|
|
1797
|
+
const [deps, setDeps] = useState5(new Set(comp.deps || []));
|
|
1798
|
+
const ref = useRef4(null);
|
|
1799
|
+
useEffect4(() => {
|
|
1800
|
+
const onDown = (e) => {
|
|
1801
|
+
if (ref.current && !ref.current.contains(e.target)) onClose();
|
|
1802
|
+
};
|
|
1803
|
+
window.addEventListener("mousedown", onDown);
|
|
1804
|
+
return () => window.removeEventListener("mousedown", onDown);
|
|
1805
|
+
}, [onClose]);
|
|
1806
|
+
const others = columns.filter((c) => c.id !== col.id);
|
|
1807
|
+
const toggleDep = (id) => setDeps((s) => {
|
|
1808
|
+
const n = new Set(s);
|
|
1809
|
+
if (n.has(id)) n.delete(id);
|
|
1810
|
+
else n.add(id);
|
|
1811
|
+
return n;
|
|
1812
|
+
});
|
|
1813
|
+
const apply = () => {
|
|
1814
|
+
const patch = { type };
|
|
1815
|
+
if (type === "select" || type === "tags") {
|
|
1816
|
+
patch.options = optText.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
1817
|
+
}
|
|
1818
|
+
if (type === "compute") {
|
|
1819
|
+
const compute = { kind, deps: [...deps] };
|
|
1820
|
+
if (kind === "prompt") compute.prompt = prompt;
|
|
1821
|
+
if (kind === "harness") {
|
|
1822
|
+
compute.harness_id = harnessId;
|
|
1823
|
+
compute.prompt = prompt;
|
|
1824
|
+
}
|
|
1825
|
+
if (kind === "workflow") {
|
|
1826
|
+
compute.workflow_slug = wfSlug;
|
|
1827
|
+
compute.output_key = outKey;
|
|
1828
|
+
}
|
|
1829
|
+
patch.compute = compute;
|
|
1830
|
+
}
|
|
1831
|
+
onApply(patch);
|
|
1832
|
+
};
|
|
1833
|
+
return /* @__PURE__ */ jsx9(PopPortal, { anchor, width: 250, estHeight: 340, className: "shg-menu", onClose, children: /* @__PURE__ */ jsxs8("div", { ref, onClick: (e) => e.stopPropagation(), children: [
|
|
1834
|
+
/* @__PURE__ */ jsxs8("label", { className: "shg-menu-lbl", children: [
|
|
1835
|
+
"Type",
|
|
1836
|
+
/* @__PURE__ */ jsxs8("select", { className: "shg-menu-input", value: type, onChange: (e) => setType(e.target.value), children: [
|
|
1837
|
+
MANUAL_TYPES.map((t) => /* @__PURE__ */ jsx9("option", { value: t, children: TYPE_LABEL[t] }, t)),
|
|
1838
|
+
/* @__PURE__ */ jsx9("option", { value: "compute", children: "Computed" })
|
|
1839
|
+
] })
|
|
1840
|
+
] }),
|
|
1841
|
+
(type === "select" || type === "tags") && /* @__PURE__ */ jsxs8("label", { className: "shg-menu-lbl", children: [
|
|
1842
|
+
"Options (one per line)",
|
|
1843
|
+
/* @__PURE__ */ jsx9(
|
|
1844
|
+
"textarea",
|
|
1845
|
+
{
|
|
1846
|
+
className: "shg-menu-input",
|
|
1847
|
+
rows: 3,
|
|
1848
|
+
value: optText,
|
|
1849
|
+
onChange: (e) => setOptText(e.target.value),
|
|
1850
|
+
placeholder: "Todo\nDoing\nDone"
|
|
1851
|
+
}
|
|
1852
|
+
)
|
|
1853
|
+
] }),
|
|
1854
|
+
type === "compute" && /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
1855
|
+
/* @__PURE__ */ jsxs8("label", { className: "shg-menu-lbl", children: [
|
|
1856
|
+
"Runs",
|
|
1857
|
+
/* @__PURE__ */ jsx9("select", { className: "shg-menu-input", value: kind, onChange: (e) => setKind(e.target.value), children: COMPUTE_KINDS.map((k) => /* @__PURE__ */ jsx9("option", { value: k.kind, children: k.label }, k.kind)) })
|
|
1858
|
+
] }),
|
|
1859
|
+
(kind === "prompt" || kind === "harness") && /* @__PURE__ */ jsxs8("label", { className: "shg-menu-lbl", children: [
|
|
1860
|
+
"Prompt \u2014 reference columns as ",
|
|
1861
|
+
"{{Name}}",
|
|
1862
|
+
/* @__PURE__ */ jsx9(
|
|
1863
|
+
"textarea",
|
|
1864
|
+
{
|
|
1865
|
+
className: "shg-menu-input",
|
|
1866
|
+
rows: 3,
|
|
1867
|
+
value: prompt,
|
|
1868
|
+
onChange: (e) => setPrompt(e.target.value),
|
|
1869
|
+
placeholder: "Summarize {{Company}} in one line"
|
|
1870
|
+
}
|
|
1871
|
+
)
|
|
1872
|
+
] }),
|
|
1873
|
+
kind === "harness" && /* @__PURE__ */ jsxs8("label", { className: "shg-menu-lbl", children: [
|
|
1874
|
+
"Agent id",
|
|
1875
|
+
/* @__PURE__ */ jsx9("input", { className: "shg-menu-input", value: harnessId, onChange: (e) => setHarnessId(e.target.value), placeholder: "chrn_\u2026" })
|
|
1876
|
+
] }),
|
|
1877
|
+
kind === "workflow" && /* @__PURE__ */ jsxs8(Fragment4, { children: [
|
|
1878
|
+
/* @__PURE__ */ jsxs8("label", { className: "shg-menu-lbl", children: [
|
|
1879
|
+
"Workflow id",
|
|
1880
|
+
/* @__PURE__ */ jsx9("input", { className: "shg-menu-input", value: wfSlug, onChange: (e) => setWfSlug(e.target.value), placeholder: "my-workflow" })
|
|
1881
|
+
] }),
|
|
1882
|
+
/* @__PURE__ */ jsxs8("label", { className: "shg-menu-lbl", children: [
|
|
1883
|
+
"Output key (optional)",
|
|
1884
|
+
/* @__PURE__ */ jsx9("input", { className: "shg-menu-input", value: outKey, onChange: (e) => setOutKey(e.target.value), placeholder: "summary" })
|
|
1885
|
+
] })
|
|
1886
|
+
] }),
|
|
1887
|
+
others.length > 0 && /* @__PURE__ */ jsxs8("div", { className: "shg-menu-lbl", children: [
|
|
1888
|
+
"Reads columns",
|
|
1889
|
+
/* @__PURE__ */ jsx9("div", { className: "shg-menu-deps", children: others.map((c) => /* @__PURE__ */ jsxs8("label", { className: "shg-menu-dep", children: [
|
|
1890
|
+
/* @__PURE__ */ jsx9("input", { type: "checkbox", checked: deps.has(c.id), onChange: () => toggleDep(c.id) }),
|
|
1891
|
+
" ",
|
|
1892
|
+
c.name
|
|
1893
|
+
] }, c.id)) })
|
|
1894
|
+
] })
|
|
1895
|
+
] }),
|
|
1896
|
+
/* @__PURE__ */ jsxs8("div", { className: "shg-menu-actions", children: [
|
|
1897
|
+
/* @__PURE__ */ jsx9("button", { className: "shg-menu-del", onClick: onDelete, children: "Delete column" }),
|
|
1898
|
+
/* @__PURE__ */ jsx9("button", { className: "shg-menu-apply", onClick: apply, children: "Apply" })
|
|
1899
|
+
] })
|
|
1900
|
+
] }) });
|
|
1901
|
+
}
|
|
1902
|
+
function sheetToDelimited(sheet, sep = ",") {
|
|
1903
|
+
const cols = sheet?.columns || [];
|
|
1904
|
+
const rows = sheet?.rows || [];
|
|
1905
|
+
const cells = sheet?.cells || {};
|
|
1906
|
+
const esc = (v) => {
|
|
1907
|
+
const s = v == null ? "" : Array.isArray(v) ? v.join(", ") : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
1908
|
+
if (sep === "," && /[",\n]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
|
|
1909
|
+
return s;
|
|
1910
|
+
};
|
|
1911
|
+
const header = cols.map((c) => esc(c.name)).join(sep);
|
|
1912
|
+
const body = rows.map((r) => cols.map((c) => {
|
|
1913
|
+
const cell = cells[cellKey(r.id, c.id)];
|
|
1914
|
+
return esc(cell ? cell.value : "");
|
|
1915
|
+
}).join(sep));
|
|
1916
|
+
return [header, ...body].join("\n");
|
|
1917
|
+
}
|
|
1918
|
+
function sheetToAoA(sheet) {
|
|
1919
|
+
const cols = sheet?.columns || [];
|
|
1920
|
+
const rows = sheet?.rows || [];
|
|
1921
|
+
const cells = sheet?.cells || {};
|
|
1922
|
+
const val = (v) => v == null ? "" : Array.isArray(v) ? v.join(", ") : typeof v === "object" ? JSON.stringify(v) : v;
|
|
1923
|
+
return [
|
|
1924
|
+
cols.map((c) => c.name),
|
|
1925
|
+
...rows.map((r) => cols.map((c) => val(cells[cellKey(r.id, c.id)]?.value)))
|
|
1926
|
+
];
|
|
1927
|
+
}
|
|
1928
|
+
export {
|
|
1929
|
+
AssistantTurn,
|
|
1930
|
+
AuthForm,
|
|
1931
|
+
ChatMessages,
|
|
1932
|
+
ChatMessagesSkeleton,
|
|
1933
|
+
Chevron,
|
|
1934
|
+
CodeBlock,
|
|
1935
|
+
Composer,
|
|
1936
|
+
DEFAULT_STATUS_LABELS,
|
|
1937
|
+
GOOGLE_ENABLED,
|
|
1938
|
+
GoogleButton,
|
|
1939
|
+
IcCheck,
|
|
1940
|
+
IcDoc,
|
|
1941
|
+
IcGlobe,
|
|
1942
|
+
IcList,
|
|
1943
|
+
IcPlug,
|
|
1944
|
+
IcScroll,
|
|
1945
|
+
IcSearch,
|
|
1946
|
+
IcSend,
|
|
1947
|
+
IcSkill,
|
|
1948
|
+
IcSpawn,
|
|
1949
|
+
IcTerminal,
|
|
1950
|
+
IcThink,
|
|
1951
|
+
IcTool,
|
|
1952
|
+
PaneResizer,
|
|
1953
|
+
SESSION_EVENT,
|
|
1954
|
+
SheetGrid,
|
|
1955
|
+
Svg,
|
|
1956
|
+
ToolGroup,
|
|
1957
|
+
ToolRow,
|
|
1958
|
+
UserTurn,
|
|
1959
|
+
asstText,
|
|
1960
|
+
authConfig,
|
|
1961
|
+
authFetch,
|
|
1962
|
+
baseName,
|
|
1963
|
+
clearSession,
|
|
1964
|
+
configureAuth,
|
|
1965
|
+
createConversationStore,
|
|
1966
|
+
createResponsesDispatcher,
|
|
1967
|
+
fetchBalance,
|
|
1968
|
+
getSession,
|
|
1969
|
+
getToken,
|
|
1970
|
+
googleSignIn,
|
|
1971
|
+
handleAuthExpired,
|
|
1972
|
+
humanize,
|
|
1973
|
+
isAuthed,
|
|
1974
|
+
login,
|
|
1975
|
+
logout,
|
|
1976
|
+
parseArgs,
|
|
1977
|
+
prettyJson,
|
|
1978
|
+
pumpResponsesStream,
|
|
1979
|
+
readSSEStream,
|
|
1980
|
+
refreshToken,
|
|
1981
|
+
register,
|
|
1982
|
+
requestPasswordReset,
|
|
1983
|
+
sheetToAoA,
|
|
1984
|
+
sheetToDelimited,
|
|
1985
|
+
summarizeSteps,
|
|
1986
|
+
switchOrg,
|
|
1987
|
+
toolMeta,
|
|
1988
|
+
useResizablePane,
|
|
1989
|
+
withReasoning,
|
|
1990
|
+
withResult,
|
|
1991
|
+
withStep,
|
|
1992
|
+
withText
|
|
1993
|
+
};
|
|
1994
|
+
//# sourceMappingURL=index.js.map
|