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