@daex-dev/chat-ui 0.0.0-stage → 0.7.1
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 +438 -3
- package/dist/index.cjs +4883 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2296 -0
- package/dist/index.d.ts +2296 -0
- package/dist/index.js +4791 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -6
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4883 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// src/AdeChat.tsx
|
|
7
|
+
|
|
8
|
+
// src/composer/composerState.ts
|
|
9
|
+
function resolveComposerAction(input) {
|
|
10
|
+
const text = input.draft.trim();
|
|
11
|
+
const running = input.status === "running";
|
|
12
|
+
if (input.disabled) return { kind: "blocked", reason: "disabled" };
|
|
13
|
+
if (!input.ready) return { kind: "blocked", reason: "no_thread" };
|
|
14
|
+
if (!text.length && !input.hasAttachments) return { kind: "blocked", reason: "empty" };
|
|
15
|
+
if (running) {
|
|
16
|
+
if (input.allowSteer === false) return { kind: "blocked", reason: "steer_unsupported" };
|
|
17
|
+
return { kind: "steer", text };
|
|
18
|
+
}
|
|
19
|
+
return { kind: "send", text };
|
|
20
|
+
}
|
|
21
|
+
function resolveComposerState(input) {
|
|
22
|
+
const action = resolveComposerAction(input);
|
|
23
|
+
const running = input.status === "running";
|
|
24
|
+
return {
|
|
25
|
+
action,
|
|
26
|
+
canSubmit: action.kind !== "blocked",
|
|
27
|
+
canInterrupt: running && !input.disabled && input.ready,
|
|
28
|
+
running,
|
|
29
|
+
submitLabel: running ? "Steer" : "Send"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function blockedHint(reason) {
|
|
33
|
+
switch (reason) {
|
|
34
|
+
case "empty":
|
|
35
|
+
return null;
|
|
36
|
+
case "disabled":
|
|
37
|
+
return null;
|
|
38
|
+
case "no_thread":
|
|
39
|
+
return "Connecting\u2026";
|
|
40
|
+
case "steer_unsupported":
|
|
41
|
+
return "Stop the current response before sending another message.";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function resolveKeyIntent(input) {
|
|
45
|
+
if (input.isComposing) return "none";
|
|
46
|
+
if (input.key === "Escape") {
|
|
47
|
+
return input.running ? "interrupt" : "none";
|
|
48
|
+
}
|
|
49
|
+
if (input.key !== "Enter") return "none";
|
|
50
|
+
if (input.shiftKey) return "newline";
|
|
51
|
+
const commandModified = input.metaKey || input.ctrlKey;
|
|
52
|
+
const shouldSubmit = input.sendOnEnter ? !commandModified : commandModified;
|
|
53
|
+
return shouldSubmit ? "submit" : "newline";
|
|
54
|
+
}
|
|
55
|
+
function mergeAttachments(current, incoming = []) {
|
|
56
|
+
const merged = [];
|
|
57
|
+
const indexById = /* @__PURE__ */ new Map();
|
|
58
|
+
for (const attachment of [...current, ...incoming]) {
|
|
59
|
+
const existing = indexById.get(attachment.id);
|
|
60
|
+
if (existing === void 0) {
|
|
61
|
+
indexById.set(attachment.id, merged.length);
|
|
62
|
+
merged.push(attachment);
|
|
63
|
+
} else {
|
|
64
|
+
merged[existing] = attachment;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return merged;
|
|
68
|
+
}
|
|
69
|
+
function Composer({
|
|
70
|
+
onSend,
|
|
71
|
+
onSteer,
|
|
72
|
+
onInterrupt,
|
|
73
|
+
status = "idle",
|
|
74
|
+
ready = true,
|
|
75
|
+
disabled = false,
|
|
76
|
+
value,
|
|
77
|
+
onValueChange,
|
|
78
|
+
placeholder = "Send a message\u2026",
|
|
79
|
+
sendOnEnter = true,
|
|
80
|
+
autoFocus = false,
|
|
81
|
+
maxRows = 12,
|
|
82
|
+
onRequestAttachment,
|
|
83
|
+
attachments,
|
|
84
|
+
onAttachmentsChange,
|
|
85
|
+
modelRail,
|
|
86
|
+
actions,
|
|
87
|
+
error,
|
|
88
|
+
slashCommands,
|
|
89
|
+
slashCommandsLoading = false,
|
|
90
|
+
slashCommandsError = null,
|
|
91
|
+
onRetrySlashCommands,
|
|
92
|
+
className
|
|
93
|
+
}) {
|
|
94
|
+
const [internalDraft, setInternalDraft] = react.useState("");
|
|
95
|
+
const [internalAttachments, setInternalAttachments] = react.useState([]);
|
|
96
|
+
const [submitError, setSubmitError] = react.useState(null);
|
|
97
|
+
const inputRef = react.useRef(null);
|
|
98
|
+
const [cursorPosition, setCursorPosition] = react.useState(null);
|
|
99
|
+
const [selectedSlashIndex, setSelectedSlashIndex] = react.useState(0);
|
|
100
|
+
const [dismissedSlashQuery, setDismissedSlashQuery] = react.useState(null);
|
|
101
|
+
const slashMenuId = `adechat-slash-${react.useId()}`;
|
|
102
|
+
const draft = value ?? internalDraft;
|
|
103
|
+
const staged = react.useMemo(
|
|
104
|
+
() => mergeAttachments(attachments ?? internalAttachments),
|
|
105
|
+
[attachments, internalAttachments]
|
|
106
|
+
);
|
|
107
|
+
const stagedRef = react.useRef(staged);
|
|
108
|
+
stagedRef.current = staged;
|
|
109
|
+
const setDraft = react.useCallback(
|
|
110
|
+
(next) => {
|
|
111
|
+
if (value === void 0) setInternalDraft(next);
|
|
112
|
+
onValueChange?.(next);
|
|
113
|
+
},
|
|
114
|
+
[onValueChange, value]
|
|
115
|
+
);
|
|
116
|
+
const controlled = attachments !== void 0;
|
|
117
|
+
const setStaged = react.useCallback(
|
|
118
|
+
(next) => {
|
|
119
|
+
stagedRef.current = next;
|
|
120
|
+
if (!controlled) setInternalAttachments(next);
|
|
121
|
+
onAttachmentsChange?.(next);
|
|
122
|
+
},
|
|
123
|
+
[controlled, onAttachmentsChange]
|
|
124
|
+
);
|
|
125
|
+
const state = resolveComposerState({
|
|
126
|
+
draft,
|
|
127
|
+
status,
|
|
128
|
+
ready,
|
|
129
|
+
disabled,
|
|
130
|
+
allowSteer: Boolean(onSteer),
|
|
131
|
+
hasAttachments: staged.length > 0
|
|
132
|
+
});
|
|
133
|
+
const slashMatch = react.useMemo(() => {
|
|
134
|
+
const cursor = cursorPosition ?? draft.length;
|
|
135
|
+
const before = draft.slice(0, cursor);
|
|
136
|
+
const match = /^\/([^\s/]*)$/.exec(before);
|
|
137
|
+
return match ? { start: 0, query: match[1] ?? "" } : null;
|
|
138
|
+
}, [cursorPosition, draft]);
|
|
139
|
+
const slashSuggestions = react.useMemo(() => {
|
|
140
|
+
if (!slashMatch || !slashCommands) return [];
|
|
141
|
+
const query = slashMatch.query.toLocaleLowerCase();
|
|
142
|
+
return slashCommands.filter((command) => command.name.replace(/^\//, "").toLocaleLowerCase().startsWith(query)).slice(0, 10);
|
|
143
|
+
}, [slashCommands, slashMatch]);
|
|
144
|
+
const slashMenuOpen = Boolean(
|
|
145
|
+
slashMatch && dismissedSlashQuery !== slashMatch.query && (slashCommands !== void 0 || slashCommandsLoading || slashCommandsError)
|
|
146
|
+
);
|
|
147
|
+
react.useEffect(() => setSelectedSlashIndex(0), [slashMatch?.query]);
|
|
148
|
+
const selectSlashCommand = react.useCallback((command) => {
|
|
149
|
+
if (!slashMatch) return;
|
|
150
|
+
const cursor = inputRef.current?.selectionStart ?? draft.length;
|
|
151
|
+
const before = draft.slice(0, slashMatch.start);
|
|
152
|
+
const after = draft.slice(cursor);
|
|
153
|
+
const name = command.name.replace(/^\//, "");
|
|
154
|
+
const next = `${before}/${name} ${after}`;
|
|
155
|
+
const nextCursor = before.length + name.length + 2;
|
|
156
|
+
setDraft(next);
|
|
157
|
+
setCursorPosition(nextCursor);
|
|
158
|
+
setDismissedSlashQuery(null);
|
|
159
|
+
requestAnimationFrame(() => {
|
|
160
|
+
const input = inputRef.current;
|
|
161
|
+
input?.focus();
|
|
162
|
+
input?.setSelectionRange(nextCursor, nextCursor);
|
|
163
|
+
});
|
|
164
|
+
}, [draft, setDraft, slashMatch]);
|
|
165
|
+
react.useEffect(() => {
|
|
166
|
+
const node = inputRef.current;
|
|
167
|
+
if (!node) return;
|
|
168
|
+
node.style.height = "auto";
|
|
169
|
+
const lineHeight = Number.parseFloat(getComputedStyle(node).lineHeight) || 20;
|
|
170
|
+
node.style.height = `${Math.min(node.scrollHeight, lineHeight * maxRows)}px`;
|
|
171
|
+
}, [draft, maxRows]);
|
|
172
|
+
const submit = react.useCallback(async () => {
|
|
173
|
+
const action = state.action;
|
|
174
|
+
if (action.kind === "blocked") return;
|
|
175
|
+
const input = {
|
|
176
|
+
text: action.text,
|
|
177
|
+
...staged.length ? { attachments: staged } : {}
|
|
178
|
+
};
|
|
179
|
+
setDraft("");
|
|
180
|
+
setStaged([]);
|
|
181
|
+
setSubmitError(null);
|
|
182
|
+
const restore = () => {
|
|
183
|
+
setDraft(action.text);
|
|
184
|
+
setStaged(mergeAttachments(staged, stagedRef.current));
|
|
185
|
+
};
|
|
186
|
+
try {
|
|
187
|
+
if (action.kind === "steer" && onSteer) await onSteer(input);
|
|
188
|
+
else if (await onSend(input) === false) restore();
|
|
189
|
+
} catch (cause) {
|
|
190
|
+
restore();
|
|
191
|
+
setSubmitError(cause instanceof Error ? cause.message : String(cause));
|
|
192
|
+
}
|
|
193
|
+
}, [onSend, onSteer, setDraft, setStaged, staged, state.action]);
|
|
194
|
+
const interrupt = react.useCallback(async () => {
|
|
195
|
+
if (!onInterrupt || !state.canInterrupt) return;
|
|
196
|
+
await onInterrupt();
|
|
197
|
+
}, [onInterrupt, state.canInterrupt]);
|
|
198
|
+
const handleKeyDown = react.useCallback(
|
|
199
|
+
(event) => {
|
|
200
|
+
if (slashMenuOpen) {
|
|
201
|
+
if (event.key === "ArrowDown" && slashSuggestions.length > 0) {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
setSelectedSlashIndex((current) => (current + 1) % slashSuggestions.length);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (event.key === "ArrowUp" && slashSuggestions.length > 0) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
setSelectedSlashIndex((current) => (current - 1 + slashSuggestions.length) % slashSuggestions.length);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if ((event.key === "Enter" || event.key === "Tab") && slashSuggestions.length > 0) {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
selectSlashCommand(slashSuggestions[selectedSlashIndex] ?? slashSuggestions[0]);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (event.key === "Escape") {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
setDismissedSlashQuery(slashMatch?.query ?? "");
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const intent = resolveKeyIntent({
|
|
223
|
+
key: event.key,
|
|
224
|
+
shiftKey: event.shiftKey,
|
|
225
|
+
metaKey: event.metaKey,
|
|
226
|
+
ctrlKey: event.ctrlKey,
|
|
227
|
+
// React's synthetic event exposes composition state on the native event.
|
|
228
|
+
isComposing: event.nativeEvent.isComposing === true,
|
|
229
|
+
sendOnEnter,
|
|
230
|
+
running: state.running,
|
|
231
|
+
hasDraft: draft.trim().length > 0
|
|
232
|
+
});
|
|
233
|
+
if (intent === "submit") {
|
|
234
|
+
event.preventDefault();
|
|
235
|
+
void submit();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (intent === "interrupt" && onInterrupt) {
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
void interrupt();
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
[draft, interrupt, onInterrupt, sendOnEnter, slashMatch, slashMenuOpen, slashSuggestions, selectedSlashIndex, selectSlashCommand, state.running, submit]
|
|
244
|
+
);
|
|
245
|
+
const attach = react.useCallback(async () => {
|
|
246
|
+
if (!onRequestAttachment) return;
|
|
247
|
+
const next = await onRequestAttachment();
|
|
248
|
+
if (!next || next.length === 0) return;
|
|
249
|
+
setStaged(mergeAttachments(stagedRef.current, next));
|
|
250
|
+
}, [onRequestAttachment, setStaged]);
|
|
251
|
+
const remove = react.useCallback(
|
|
252
|
+
(id) => setStaged(stagedRef.current.filter((item) => item.id !== id)),
|
|
253
|
+
[setStaged]
|
|
254
|
+
);
|
|
255
|
+
const hint = state.action.kind === "blocked" ? blockedHint(state.action.reason) : null;
|
|
256
|
+
const shownError = error ?? submitError;
|
|
257
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ["adechat-composer", className].filter(Boolean).join(" "), children: [
|
|
258
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-composer-surface", children: [
|
|
259
|
+
staged.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-attachments", children: staged.map((attachment) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
260
|
+
"button",
|
|
261
|
+
{
|
|
262
|
+
type: "button",
|
|
263
|
+
className: "adechat-attachment",
|
|
264
|
+
onClick: () => remove(attachment.id),
|
|
265
|
+
"aria-label": `Remove ${attachment.name}`,
|
|
266
|
+
children: [
|
|
267
|
+
attachment.name,
|
|
268
|
+
" \xD7"
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
attachment.id
|
|
272
|
+
)) }) : null,
|
|
273
|
+
slashMenuOpen ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-slash-menu", id: slashMenuId, role: "listbox", "aria-label": "Slash commands", children: [
|
|
274
|
+
slashCommandsLoading && slashCommands === null ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-slash-state", children: "Loading commands\u2026" }) : null,
|
|
275
|
+
slashCommandsError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-slash-error", role: "alert", children: [
|
|
276
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Couldn\u2019t load slash commands." }),
|
|
277
|
+
onRetrySlashCommands ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", onClick: () => void onRetrySlashCommands(), disabled: slashCommandsLoading, children: "Retry" }) : null
|
|
278
|
+
] }) : null,
|
|
279
|
+
slashSuggestions.map((command, index) => {
|
|
280
|
+
const name = command.name.replace(/^\//, "");
|
|
281
|
+
const optionId = `${slashMenuId}-${index}`;
|
|
282
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
283
|
+
"button",
|
|
284
|
+
{
|
|
285
|
+
type: "button",
|
|
286
|
+
role: "option",
|
|
287
|
+
id: optionId,
|
|
288
|
+
"aria-selected": index === selectedSlashIndex,
|
|
289
|
+
className: "adechat-slash-option",
|
|
290
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
291
|
+
onClick: () => selectSlashCommand(command),
|
|
292
|
+
children: [
|
|
293
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
294
|
+
"/",
|
|
295
|
+
name
|
|
296
|
+
] }),
|
|
297
|
+
command.argumentHint ? /* @__PURE__ */ jsxRuntime.jsx("small", { children: command.argumentHint }) : null,
|
|
298
|
+
command.description ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-slash-description", children: command.description }) : null
|
|
299
|
+
]
|
|
300
|
+
},
|
|
301
|
+
`${command.name}-${index}`
|
|
302
|
+
);
|
|
303
|
+
}),
|
|
304
|
+
!slashCommandsLoading && !slashCommandsError && slashCommands !== null && slashSuggestions.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-slash-state", children: "No matching commands." }) : null
|
|
305
|
+
] }) : null,
|
|
306
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
307
|
+
"textarea",
|
|
308
|
+
{
|
|
309
|
+
ref: inputRef,
|
|
310
|
+
className: "adechat-composer-input",
|
|
311
|
+
rows: 1,
|
|
312
|
+
value: draft,
|
|
313
|
+
placeholder,
|
|
314
|
+
disabled,
|
|
315
|
+
autoFocus,
|
|
316
|
+
onChange: (event) => {
|
|
317
|
+
setDraft(event.target.value);
|
|
318
|
+
setCursorPosition(event.currentTarget.selectionStart);
|
|
319
|
+
setDismissedSlashQuery(null);
|
|
320
|
+
},
|
|
321
|
+
onKeyDown: handleKeyDown,
|
|
322
|
+
onClick: (event) => setCursorPosition(event.currentTarget.selectionStart),
|
|
323
|
+
onKeyUp: (event) => setCursorPosition(event.currentTarget.selectionStart),
|
|
324
|
+
"aria-label": "Message",
|
|
325
|
+
...slashMenuOpen ? {
|
|
326
|
+
"aria-autocomplete": "list",
|
|
327
|
+
"aria-controls": slashMenuId,
|
|
328
|
+
"aria-expanded": true,
|
|
329
|
+
...slashSuggestions[selectedSlashIndex] ? { "aria-activedescendant": `${slashMenuId}-${selectedSlashIndex}` } : {}
|
|
330
|
+
} : {}
|
|
331
|
+
}
|
|
332
|
+
),
|
|
333
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-composer-actions", children: [
|
|
334
|
+
onRequestAttachment ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
335
|
+
"button",
|
|
336
|
+
{
|
|
337
|
+
type: "button",
|
|
338
|
+
className: "adechat-button adechat-button-icon",
|
|
339
|
+
onClick: () => void attach(),
|
|
340
|
+
disabled,
|
|
341
|
+
"aria-label": "Add attachment",
|
|
342
|
+
children: "+"
|
|
343
|
+
}
|
|
344
|
+
) : null,
|
|
345
|
+
modelRail ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-composer-rail", children: modelRail }) : null,
|
|
346
|
+
actions,
|
|
347
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-composer-spacer" }),
|
|
348
|
+
hint ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-composer-hint", children: hint }) : null,
|
|
349
|
+
state.canInterrupt && onInterrupt ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
350
|
+
"button",
|
|
351
|
+
{
|
|
352
|
+
type: "button",
|
|
353
|
+
className: "adechat-button",
|
|
354
|
+
"data-variant": "danger",
|
|
355
|
+
onClick: () => void interrupt(),
|
|
356
|
+
children: "Stop"
|
|
357
|
+
}
|
|
358
|
+
) : null,
|
|
359
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
360
|
+
"button",
|
|
361
|
+
{
|
|
362
|
+
type: "button",
|
|
363
|
+
className: "adechat-button",
|
|
364
|
+
"data-variant": "primary",
|
|
365
|
+
onClick: () => void submit(),
|
|
366
|
+
disabled: !state.canSubmit,
|
|
367
|
+
children: state.submitLabel
|
|
368
|
+
}
|
|
369
|
+
)
|
|
370
|
+
] })
|
|
371
|
+
] }),
|
|
372
|
+
shownError ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-composer-error", children: shownError }) : null
|
|
373
|
+
] });
|
|
374
|
+
}
|
|
375
|
+
function QueueStrip({ queue, refreshKey }) {
|
|
376
|
+
const [items, setItems] = react.useState([]);
|
|
377
|
+
const [loading, setLoading] = react.useState(false);
|
|
378
|
+
const [loaded, setLoaded] = react.useState(false);
|
|
379
|
+
const [error, setError] = react.useState(null);
|
|
380
|
+
const [busyId, setBusyId] = react.useState(null);
|
|
381
|
+
const [editingId, setEditingId] = react.useState(null);
|
|
382
|
+
const [editText, setEditText] = react.useState("");
|
|
383
|
+
const refresh = react.useCallback(async () => {
|
|
384
|
+
if (typeof queue?.list !== "function") return;
|
|
385
|
+
setLoading(true);
|
|
386
|
+
try {
|
|
387
|
+
setItems([...await queue.list()]);
|
|
388
|
+
setError(null);
|
|
389
|
+
setLoaded(true);
|
|
390
|
+
} catch (cause) {
|
|
391
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
392
|
+
setLoaded(false);
|
|
393
|
+
} finally {
|
|
394
|
+
setLoading(false);
|
|
395
|
+
}
|
|
396
|
+
}, [queue]);
|
|
397
|
+
react.useEffect(() => {
|
|
398
|
+
void refresh();
|
|
399
|
+
}, [refresh, refreshKey]);
|
|
400
|
+
const act = async (id, action) => {
|
|
401
|
+
if (!action) return;
|
|
402
|
+
setBusyId(id);
|
|
403
|
+
setError(null);
|
|
404
|
+
try {
|
|
405
|
+
await action();
|
|
406
|
+
if (editingId === id) setEditingId(null);
|
|
407
|
+
await refresh();
|
|
408
|
+
} catch (cause) {
|
|
409
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
410
|
+
} finally {
|
|
411
|
+
setBusyId(null);
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
if (typeof queue?.list !== "function") return null;
|
|
415
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "adechat-queue", "aria-label": "Queued messages", children: [
|
|
416
|
+
loading && !loaded ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-queue-state", children: "Loading queued messages\u2026" }) : null,
|
|
417
|
+
error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-queue-error", role: "alert", children: [
|
|
418
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
419
|
+
"Couldn\u2019t load or update the queue: ",
|
|
420
|
+
error
|
|
421
|
+
] }),
|
|
422
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", onClick: () => void refresh(), disabled: loading, children: "Retry" })
|
|
423
|
+
] }) : null,
|
|
424
|
+
loaded && items.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "adechat-queue-list", children: items.map((item, index) => {
|
|
425
|
+
const busy = busyId === item.id;
|
|
426
|
+
const editing = editingId === item.id;
|
|
427
|
+
const canMove = typeof queue.move === "function" && !item.dispatched;
|
|
428
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "adechat-queue-item", children: [
|
|
429
|
+
editing ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
430
|
+
"form",
|
|
431
|
+
{
|
|
432
|
+
className: "adechat-queue-edit",
|
|
433
|
+
onSubmit: (event) => {
|
|
434
|
+
event.preventDefault();
|
|
435
|
+
void act(item.id, queue.edit ? () => queue.edit(item.id, editText) : void 0);
|
|
436
|
+
},
|
|
437
|
+
children: [
|
|
438
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { "aria-label": "Edit queued message", value: editText, onChange: (event) => setEditText(event.target.value), disabled: busy }),
|
|
439
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", className: "adechat-button", disabled: busy || !queue.edit, children: "Save" }),
|
|
440
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", onClick: () => setEditingId(null), disabled: busy, children: "Cancel edit" })
|
|
441
|
+
]
|
|
442
|
+
}
|
|
443
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-queue-text", children: item.text || "Attachment message" }),
|
|
444
|
+
!editing ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-queue-actions", children: [
|
|
445
|
+
canMove ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
446
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", "aria-label": `Move message ${index + 1} up`, disabled: busy || index === 0, onClick: () => void act(item.id, () => queue.move(item.id, index - 1)), children: "\u2191" }),
|
|
447
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", "aria-label": `Move message ${index + 1} down`, disabled: busy || index === items.length - 1, onClick: () => void act(item.id, () => queue.move(item.id, index + 1)), children: "\u2193" })
|
|
448
|
+
] }) : null,
|
|
449
|
+
!item.dispatched && queue.edit ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", disabled: busy, onClick: () => {
|
|
450
|
+
setEditingId(item.id);
|
|
451
|
+
setEditText(item.text);
|
|
452
|
+
}, children: "Edit" }) : null,
|
|
453
|
+
!item.dispatched && queue.dispatch ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", disabled: busy, onClick: () => void act(item.id, () => queue.dispatch(item.id)), children: "Send now" }) : null,
|
|
454
|
+
item.dispatched && queue.cancelDispatched ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", disabled: busy, onClick: () => void act(item.id, () => queue.cancelDispatched(item.id)), children: "Cancel send" }) : null,
|
|
455
|
+
queue.cancel ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", disabled: busy, onClick: () => void act(item.id, () => queue.cancel(item.id)), children: "Cancel" }) : null
|
|
456
|
+
] }) : null
|
|
457
|
+
] }, item.id);
|
|
458
|
+
}) }) : null
|
|
459
|
+
] });
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/models/modelSelection.ts
|
|
463
|
+
function readThreadModelSelection(value) {
|
|
464
|
+
if (!value || typeof value !== "object") return null;
|
|
465
|
+
const record2 = value;
|
|
466
|
+
if (typeof record2.modelId !== "string" || !record2.modelId) return null;
|
|
467
|
+
const info = { modelId: record2.modelId };
|
|
468
|
+
if (typeof record2.displayName === "string" || record2.displayName === null) {
|
|
469
|
+
info.displayName = record2.displayName;
|
|
470
|
+
}
|
|
471
|
+
if (typeof record2.provider === "string" && record2.provider) info.provider = record2.provider;
|
|
472
|
+
return info;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/activity/toolIdentity.ts
|
|
476
|
+
function parseToolIdentity(name) {
|
|
477
|
+
const trimmed = typeof name === "string" ? name.trim() : "";
|
|
478
|
+
if (trimmed.startsWith("mcp__")) {
|
|
479
|
+
const rest = trimmed.slice("mcp__".length);
|
|
480
|
+
const split2 = rest.indexOf("__");
|
|
481
|
+
if (split2 > 0 && split2 + 2 < rest.length) {
|
|
482
|
+
return { server: rest.slice(0, split2), tool: rest.slice(split2 + 2) };
|
|
483
|
+
}
|
|
484
|
+
return { server: null, tool: trimmed };
|
|
485
|
+
}
|
|
486
|
+
if (trimmed.startsWith("mcp:")) {
|
|
487
|
+
const rest = trimmed.slice("mcp:".length);
|
|
488
|
+
const split2 = rest.indexOf(":");
|
|
489
|
+
if (split2 > 0 && split2 + 1 < rest.length) {
|
|
490
|
+
return { server: rest.slice(0, split2), tool: rest.slice(split2 + 1) };
|
|
491
|
+
}
|
|
492
|
+
return { server: null, tool: trimmed };
|
|
493
|
+
}
|
|
494
|
+
const split = trimmed.indexOf(":");
|
|
495
|
+
if (split > 0 && split + 1 < trimmed.length) {
|
|
496
|
+
return { server: trimmed.slice(0, split), tool: trimmed.slice(split + 1) };
|
|
497
|
+
}
|
|
498
|
+
return { server: null, tool: trimmed };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// src/transcript/transcriptRows.ts
|
|
502
|
+
function readRecord(value) {
|
|
503
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
504
|
+
}
|
|
505
|
+
function readPendingInputOptions(value) {
|
|
506
|
+
if (!Array.isArray(value)) return void 0;
|
|
507
|
+
return value.flatMap((entry) => {
|
|
508
|
+
const record2 = readRecord(entry);
|
|
509
|
+
if (typeof record2?.label !== "string" || typeof record2.value !== "string") return [];
|
|
510
|
+
return [{
|
|
511
|
+
label: record2.label,
|
|
512
|
+
value: record2.value,
|
|
513
|
+
...typeof record2.description === "string" ? { description: record2.description } : {},
|
|
514
|
+
...record2.recommended === true ? { recommended: true } : {},
|
|
515
|
+
...typeof record2.preview === "string" ? { preview: record2.preview } : {},
|
|
516
|
+
...record2.previewFormat === "markdown" || record2.previewFormat === "html" ? { previewFormat: record2.previewFormat } : {}
|
|
517
|
+
}];
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function readPendingInputQuestions(value) {
|
|
521
|
+
if (!Array.isArray(value)) return void 0;
|
|
522
|
+
return value.flatMap((entry) => {
|
|
523
|
+
const record2 = readRecord(entry);
|
|
524
|
+
if (typeof record2?.id !== "string" || typeof record2.question !== "string") return [];
|
|
525
|
+
const options = readPendingInputOptions(record2.options);
|
|
526
|
+
return [{
|
|
527
|
+
id: record2.id,
|
|
528
|
+
question: record2.question,
|
|
529
|
+
...typeof record2.header === "string" ? { header: record2.header } : {},
|
|
530
|
+
...options ? { options } : {},
|
|
531
|
+
...record2.multiSelect === true ? { multiSelect: true } : {},
|
|
532
|
+
...typeof record2.allowsFreeform === "boolean" ? { allowsFreeform: record2.allowsFreeform } : {},
|
|
533
|
+
...record2.isSecret === true ? { isSecret: true } : {},
|
|
534
|
+
...typeof record2.defaultAssumption === "string" || record2.defaultAssumption === null ? { defaultAssumption: record2.defaultAssumption } : {},
|
|
535
|
+
...typeof record2.impact === "string" || record2.impact === null ? { impact: record2.impact } : {}
|
|
536
|
+
}];
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
function approvalRequestKind(event) {
|
|
540
|
+
if (typeof event.requestKind === "string" && event.requestKind) return event.requestKind;
|
|
541
|
+
const kind = readRecord(readRecord(event.detail)?.request)?.kind;
|
|
542
|
+
return typeof kind === "string" && kind ? kind : void 0;
|
|
543
|
+
}
|
|
544
|
+
function pendingInputFields(event) {
|
|
545
|
+
const envelope = readRecord(event);
|
|
546
|
+
const detail = readRecord(envelope?.detail);
|
|
547
|
+
const request = readRecord(detail?.request) ?? readRecord(detail?.pendingInput) ?? detail;
|
|
548
|
+
const value = (key) => envelope?.[key] ?? request?.[key] ?? detail?.[key];
|
|
549
|
+
const fields = {};
|
|
550
|
+
const requestId = value("requestId");
|
|
551
|
+
const title = value("title");
|
|
552
|
+
const source = value("source");
|
|
553
|
+
const questions = readPendingInputQuestions(value("questions"));
|
|
554
|
+
const options = readPendingInputOptions(value("options"));
|
|
555
|
+
const providerMetadata = readRecord(value("providerMetadata"));
|
|
556
|
+
if (typeof requestId === "string" && requestId) fields.requestId = requestId;
|
|
557
|
+
if (typeof title === "string" || title === null) fields.title = title;
|
|
558
|
+
if (typeof source === "string") fields.source = source;
|
|
559
|
+
if (questions) fields.questions = questions;
|
|
560
|
+
if (options) fields.options = options;
|
|
561
|
+
if (typeof value("allowsFreeform") === "boolean") fields.allowsFreeform = value("allowsFreeform");
|
|
562
|
+
if (typeof value("canProceedWithoutAnswer") === "boolean") fields.canProceedWithoutAnswer = value("canProceedWithoutAnswer");
|
|
563
|
+
if (providerMetadata) fields.providerMetadata = providerMetadata;
|
|
564
|
+
return fields;
|
|
565
|
+
}
|
|
566
|
+
function eventHasPayload(value) {
|
|
567
|
+
if (value == null) return false;
|
|
568
|
+
if (typeof value === "string") return value.trim().length > 0;
|
|
569
|
+
if (typeof value === "number" || typeof value === "boolean") return true;
|
|
570
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
571
|
+
if (typeof value === "object") return Object.keys(value).length > 0;
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
function formatStructuredValue(value) {
|
|
575
|
+
if (typeof value === "string") return value;
|
|
576
|
+
try {
|
|
577
|
+
return JSON.stringify(value, null, 2);
|
|
578
|
+
} catch {
|
|
579
|
+
return String(value);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function mergeStreamingText(existing, incoming) {
|
|
583
|
+
if (!existing.length) return incoming;
|
|
584
|
+
if (!incoming.length) return existing;
|
|
585
|
+
if (incoming.startsWith(existing)) return incoming;
|
|
586
|
+
return `${existing}${incoming}`;
|
|
587
|
+
}
|
|
588
|
+
function buildRenderKey(envelope, sequence) {
|
|
589
|
+
return `${envelope.sessionId}:${sequence}:${envelope.timestamp}`;
|
|
590
|
+
}
|
|
591
|
+
function buildTextRenderKey(event, envelope, sequence) {
|
|
592
|
+
const messageId = event.messageId?.trim();
|
|
593
|
+
if (messageId) return `${envelope.sessionId}:text:${messageId}:${sequence}`;
|
|
594
|
+
return buildRenderKey(envelope, sequence);
|
|
595
|
+
}
|
|
596
|
+
function getTextIdentity(event) {
|
|
597
|
+
const messageId = event.messageId?.trim();
|
|
598
|
+
return messageId?.length ? messageId : null;
|
|
599
|
+
}
|
|
600
|
+
function turnAndItemMatch(a, b) {
|
|
601
|
+
const aTurnId = a.turnId ?? null;
|
|
602
|
+
const bTurnId = b.turnId ?? null;
|
|
603
|
+
if (!aTurnId || !bTurnId || aTurnId !== bTurnId) return false;
|
|
604
|
+
const aItemId = a.itemId ?? null;
|
|
605
|
+
const bItemId = b.itemId ?? null;
|
|
606
|
+
return !aItemId || !bItemId || aItemId === bItemId;
|
|
607
|
+
}
|
|
608
|
+
function shouldMergeTextRows(previous, next) {
|
|
609
|
+
const previousIdentity = getTextIdentity(previous);
|
|
610
|
+
const nextIdentity = getTextIdentity(next);
|
|
611
|
+
if (previousIdentity || nextIdentity) {
|
|
612
|
+
if (previousIdentity && nextIdentity) return previousIdentity === nextIdentity;
|
|
613
|
+
return turnAndItemMatch(previous, next);
|
|
614
|
+
}
|
|
615
|
+
if (turnAndItemMatch(previous, next)) return true;
|
|
616
|
+
return !previous.turnId && !next.turnId && !previous.itemId && !next.itemId;
|
|
617
|
+
}
|
|
618
|
+
function buildCollapseKey(prefix, event, suffix) {
|
|
619
|
+
const parts = [prefix];
|
|
620
|
+
if (event.turnId) parts.push(event.turnId);
|
|
621
|
+
const stableItemId = event.logicalItemId ?? event.itemId;
|
|
622
|
+
if (stableItemId) parts.push(stableItemId);
|
|
623
|
+
return parts.join("::");
|
|
624
|
+
}
|
|
625
|
+
function isGenericToolIdentifier(value) {
|
|
626
|
+
const normalized = value?.trim().toLowerCase() ?? "";
|
|
627
|
+
return !normalized.length || normalized === "other" || normalized === "tool";
|
|
628
|
+
}
|
|
629
|
+
function readToolTitle(value) {
|
|
630
|
+
const record2 = readRecord(value);
|
|
631
|
+
if (!record2) return null;
|
|
632
|
+
const title = typeof record2.title === "string" ? record2.title.trim() : "";
|
|
633
|
+
return title.length ? title : null;
|
|
634
|
+
}
|
|
635
|
+
function resolveToolName(tool, payload) {
|
|
636
|
+
const titleFallback = readToolTitle(payload);
|
|
637
|
+
return isGenericToolIdentifier(tool) && titleFallback ? titleFallback : tool;
|
|
638
|
+
}
|
|
639
|
+
function toolIdentityOf(tool, mcp) {
|
|
640
|
+
const server = typeof mcp?.server === "string" ? mcp.server.trim() : "";
|
|
641
|
+
const name = typeof mcp?.tool === "string" ? mcp.tool.trim() : "";
|
|
642
|
+
if (server && name) return { server, tool: name };
|
|
643
|
+
return parseToolIdentity(tool);
|
|
644
|
+
}
|
|
645
|
+
function readResourceLinks(value) {
|
|
646
|
+
if (!Array.isArray(value)) return void 0;
|
|
647
|
+
const links = [];
|
|
648
|
+
for (const entry of value) {
|
|
649
|
+
const record2 = readRecord(entry);
|
|
650
|
+
const uri = typeof record2?.uri === "string" ? record2.uri.trim() : "";
|
|
651
|
+
if (!record2 || !uri) continue;
|
|
652
|
+
const link = { uri };
|
|
653
|
+
if (typeof record2.name === "string" && record2.name) link.name = record2.name;
|
|
654
|
+
if (typeof record2.title === "string" && record2.title) link.title = record2.title;
|
|
655
|
+
if (typeof record2.mimeType === "string" && record2.mimeType) link.mimeType = record2.mimeType;
|
|
656
|
+
links.push(link);
|
|
657
|
+
}
|
|
658
|
+
return links.length ? links : void 0;
|
|
659
|
+
}
|
|
660
|
+
var RENDERED_TYPES = /* @__PURE__ */ new Set([
|
|
661
|
+
"user_message",
|
|
662
|
+
"text",
|
|
663
|
+
"reasoning",
|
|
664
|
+
"tool_call",
|
|
665
|
+
"tool_result",
|
|
666
|
+
"error",
|
|
667
|
+
"status",
|
|
668
|
+
"approval_request",
|
|
669
|
+
"pending_input_resolved"
|
|
670
|
+
]);
|
|
671
|
+
var APPROVAL_RESOLUTION_STATE = {
|
|
672
|
+
accepted: "accepted",
|
|
673
|
+
declined: "rejected",
|
|
674
|
+
cancelled: "cancelled"
|
|
675
|
+
};
|
|
676
|
+
function readTurnId(event) {
|
|
677
|
+
const value = event.turnId;
|
|
678
|
+
return typeof value === "string" && value ? value : null;
|
|
679
|
+
}
|
|
680
|
+
function turnEndingOf(event) {
|
|
681
|
+
if (!event) return null;
|
|
682
|
+
if (event.type === "done") return { turnId: readTurnId(event) };
|
|
683
|
+
if (event.type === "status") {
|
|
684
|
+
const turnStatus = event.turnStatus;
|
|
685
|
+
if (turnStatus === "completed" || turnStatus === "failed" || turnStatus === "interrupted") {
|
|
686
|
+
return { turnId: readTurnId(event) };
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
function resolveRestoredApprovalState(input) {
|
|
692
|
+
const held = input.orphanResolutions.get(input.itemId) ?? (input.logicalItemId ? input.orphanResolutions.get(input.logicalItemId) : void 0);
|
|
693
|
+
return held ?? "pending";
|
|
694
|
+
}
|
|
695
|
+
function isRenderedEvent(event) {
|
|
696
|
+
return event ? RENDERED_TYPES.has(event.type) : false;
|
|
697
|
+
}
|
|
698
|
+
var RowCollapser = class {
|
|
699
|
+
raw = [];
|
|
700
|
+
/** collapseKey -> index in `raw`, so a result can find its call. */
|
|
701
|
+
toolRowIndex = /* @__PURE__ */ new Map();
|
|
702
|
+
/** itemId AND logicalItemId -> index, so a resolution can find its request. */
|
|
703
|
+
approvalRowIndex = /* @__PURE__ */ new Map();
|
|
704
|
+
/**
|
|
705
|
+
* Resolutions that arrived before the request they settle.
|
|
706
|
+
*
|
|
707
|
+
* The engine emits the request first and `mergeHistoryWithBuffer` sorts by
|
|
708
|
+
* `sequence`, so this needs a runtime that renumbers — but when it happens,
|
|
709
|
+
* dropping the resolution left a live card with working buttons on a request
|
|
710
|
+
* that is already settled. Held here and applied when the request lands.
|
|
711
|
+
*/
|
|
712
|
+
orphanResolutions = /* @__PURE__ */ new Map();
|
|
713
|
+
/**
|
|
714
|
+
* Item ids of rows built from `restore()` rather than from an envelope.
|
|
715
|
+
*
|
|
716
|
+
* A turn ending never expires these (see `resolveRestoredApprovalState`).
|
|
717
|
+
* A single-pass collapse got that for free by restoring after the walk; an
|
|
718
|
+
* incremental one restores first and then keeps walking, so it has to say so.
|
|
719
|
+
*/
|
|
720
|
+
restoredIds = /* @__PURE__ */ new Set();
|
|
721
|
+
/** Envelopes consumed so far: the positional fallback for `sequence`. */
|
|
722
|
+
position = 0;
|
|
723
|
+
/** Lowest `raw` index changed since the last `takeDirty()`. */
|
|
724
|
+
dirtyFrom = Number.POSITIVE_INFINITY;
|
|
725
|
+
mark(index) {
|
|
726
|
+
if (index < this.dirtyFrom) this.dirtyFrom = index;
|
|
727
|
+
}
|
|
728
|
+
set(index, row) {
|
|
729
|
+
this.raw[index] = row;
|
|
730
|
+
this.mark(index);
|
|
731
|
+
}
|
|
732
|
+
push(row) {
|
|
733
|
+
const index = this.raw.length;
|
|
734
|
+
this.raw.push(row);
|
|
735
|
+
this.mark(index);
|
|
736
|
+
return index;
|
|
737
|
+
}
|
|
738
|
+
/** The lowest changed index, and reset. Infinity when nothing changed. */
|
|
739
|
+
takeDirty() {
|
|
740
|
+
const dirty = this.dirtyFrom;
|
|
741
|
+
this.dirtyFrom = Number.POSITIVE_INFINITY;
|
|
742
|
+
return dirty;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Mark every still-pending approval of a finished turn `expired`.
|
|
746
|
+
*
|
|
747
|
+
* A turn ending settles its approvals whether or not anyone answered them: the
|
|
748
|
+
* provider is gone and a button press would now throw. An ending that names no
|
|
749
|
+
* turn expires every pending row, because there is nothing left running that
|
|
750
|
+
* could still be waiting on one.
|
|
751
|
+
*/
|
|
752
|
+
expirePendingApprovals(turnId) {
|
|
753
|
+
this.raw.forEach((row, index) => {
|
|
754
|
+
const event = row.event;
|
|
755
|
+
if (event.type !== "approval" || event.state !== "pending") return;
|
|
756
|
+
if (this.restoredIds.has(event.id)) return;
|
|
757
|
+
if (turnId !== null && event.turnId !== null && event.turnId !== turnId) return;
|
|
758
|
+
this.set(index, { ...row, event: { ...event, state: "expired" } });
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
append(envelopes) {
|
|
762
|
+
for (const envelope of envelopes) {
|
|
763
|
+
this.step(envelope, this.position);
|
|
764
|
+
this.position += 1;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
step(envelope, position) {
|
|
768
|
+
const rows = this.raw;
|
|
769
|
+
const event = envelope.event;
|
|
770
|
+
if (this.approvalRowIndex.size > 0) {
|
|
771
|
+
const ending = turnEndingOf(event);
|
|
772
|
+
if (ending) this.expirePendingApprovals(ending.turnId);
|
|
773
|
+
}
|
|
774
|
+
if (!isRenderedEvent(event)) return;
|
|
775
|
+
const sequence = envelope.sequence ?? position;
|
|
776
|
+
if (event.type === "approval_request") {
|
|
777
|
+
const row = {
|
|
778
|
+
type: "approval",
|
|
779
|
+
id: event.itemId,
|
|
780
|
+
kind: event.kind,
|
|
781
|
+
description: event.description,
|
|
782
|
+
turnId: event.turnId ?? null,
|
|
783
|
+
state: "pending"
|
|
784
|
+
};
|
|
785
|
+
const requestKind = approvalRequestKind(event);
|
|
786
|
+
if (requestKind !== void 0) row.requestKind = requestKind;
|
|
787
|
+
if (event.detail !== void 0) row.detail = event.detail;
|
|
788
|
+
Object.assign(row, pendingInputFields(event));
|
|
789
|
+
const held = this.orphanResolutions.get(event.itemId) ?? (event.logicalItemId ? this.orphanResolutions.get(event.logicalItemId) : void 0);
|
|
790
|
+
if (held) {
|
|
791
|
+
row.state = held;
|
|
792
|
+
this.orphanResolutions.delete(event.itemId);
|
|
793
|
+
if (event.logicalItemId) this.orphanResolutions.delete(event.logicalItemId);
|
|
794
|
+
}
|
|
795
|
+
const existing = this.approvalRowIndex.get(event.itemId);
|
|
796
|
+
if (existing !== void 0 && rows[existing]) {
|
|
797
|
+
const previous = rows[existing].event;
|
|
798
|
+
const state = previous.type === "approval" ? previous.state : "pending";
|
|
799
|
+
this.restoredIds.delete(event.itemId);
|
|
800
|
+
this.set(existing, {
|
|
801
|
+
...rows[existing],
|
|
802
|
+
timestamp: envelope.timestamp,
|
|
803
|
+
event: { ...row, state }
|
|
804
|
+
});
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
this.approvalRowIndex.set(event.itemId, rows.length);
|
|
808
|
+
if (event.logicalItemId) this.approvalRowIndex.set(event.logicalItemId, rows.length);
|
|
809
|
+
this.push({ key: `approval:${event.itemId}`, timestamp: envelope.timestamp, event: row });
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
if (event.type === "pending_input_resolved") {
|
|
813
|
+
const index = this.approvalRowIndex.get(event.itemId) ?? (event.logicalItemId ? this.approvalRowIndex.get(event.logicalItemId) : void 0);
|
|
814
|
+
const row = index !== void 0 ? rows[index] : void 0;
|
|
815
|
+
const state = APPROVAL_RESOLUTION_STATE[event.resolution];
|
|
816
|
+
if (!state) return;
|
|
817
|
+
if (index === void 0 || !row || row.event.type !== "approval") {
|
|
818
|
+
this.orphanResolutions.set(event.itemId, state);
|
|
819
|
+
if (event.logicalItemId) this.orphanResolutions.set(event.logicalItemId, state);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
this.set(index, { ...row, timestamp: envelope.timestamp, event: { ...row.event, state } });
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
if (event.type === "text") {
|
|
826
|
+
const lastIndex = rows.length - 1;
|
|
827
|
+
const previous = rows[lastIndex];
|
|
828
|
+
if (previous && previous.event.type === "text" && shouldMergeTextRows(previous.event, event)) {
|
|
829
|
+
this.set(lastIndex, {
|
|
830
|
+
key: previous.key,
|
|
831
|
+
timestamp: envelope.timestamp,
|
|
832
|
+
event: {
|
|
833
|
+
...previous.event,
|
|
834
|
+
text: mergeStreamingText(previous.event.text, event.text)
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
this.push({
|
|
840
|
+
key: buildTextRenderKey(event, envelope, sequence),
|
|
841
|
+
timestamp: envelope.timestamp,
|
|
842
|
+
event
|
|
843
|
+
});
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
if (event.type === "tool_call") {
|
|
847
|
+
const collapseKey = buildCollapseKey("tool", event);
|
|
848
|
+
const chip = {
|
|
849
|
+
type: "tool_chip",
|
|
850
|
+
id: collapseKey,
|
|
851
|
+
tool: resolveToolName(event.tool, event.args),
|
|
852
|
+
identity: toolIdentityOf(event.tool, event.mcp),
|
|
853
|
+
args: event.args,
|
|
854
|
+
status: "running",
|
|
855
|
+
turnId: event.turnId ?? null
|
|
856
|
+
};
|
|
857
|
+
const existing = this.toolRowIndex.get(collapseKey);
|
|
858
|
+
if (existing !== void 0 && rows[existing]) {
|
|
859
|
+
this.set(existing, { ...rows[existing], timestamp: envelope.timestamp, event: chip });
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
this.toolRowIndex.set(collapseKey, rows.length);
|
|
863
|
+
this.push({ key: collapseKey, timestamp: envelope.timestamp, event: chip });
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
if (event.type === "tool_result") {
|
|
867
|
+
const collapseKey = buildCollapseKey("tool", event);
|
|
868
|
+
const index = this.toolRowIndex.get(collapseKey);
|
|
869
|
+
const previousChip = index !== void 0 && rows[index]?.event.type === "tool_chip" ? rows[index].event : null;
|
|
870
|
+
const tool = resolveToolName(event.tool, event.result) || previousChip?.tool || event.tool;
|
|
871
|
+
const chip = {
|
|
872
|
+
type: "tool_chip",
|
|
873
|
+
id: collapseKey,
|
|
874
|
+
tool,
|
|
875
|
+
identity: event.mcp || !previousChip ? toolIdentityOf(event.tool || tool, event.mcp) : previousChip.identity,
|
|
876
|
+
args: previousChip?.args,
|
|
877
|
+
result: event.result,
|
|
878
|
+
status: event.status ?? "completed",
|
|
879
|
+
turnId: event.turnId ?? previousChip?.turnId ?? null
|
|
880
|
+
};
|
|
881
|
+
const resourceLinks = readResourceLinks(event.resourceLinks) ?? previousChip?.resourceLinks;
|
|
882
|
+
if (resourceLinks) chip.resourceLinks = resourceLinks;
|
|
883
|
+
if (index !== void 0 && rows[index]) {
|
|
884
|
+
this.set(index, { ...rows[index], timestamp: envelope.timestamp, event: chip });
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
this.toolRowIndex.set(collapseKey, rows.length);
|
|
888
|
+
this.push({ key: collapseKey, timestamp: envelope.timestamp, event: chip });
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
this.push({
|
|
892
|
+
key: buildRenderKey(envelope, sequence),
|
|
893
|
+
timestamp: envelope.timestamp,
|
|
894
|
+
event
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Put a restored approval row where its timestamp says it belongs.
|
|
899
|
+
*
|
|
900
|
+
* Appending it instead pinned it below every message that streamed in later,
|
|
901
|
+
* for the life of the mount: a card answered ten messages ago still read as
|
|
902
|
+
* the newest thing in the transcript. Only the restored rows move; the
|
|
903
|
+
* envelope rows keep the order `sortEnvelopes` gave them, which is by
|
|
904
|
+
* `sequence` and not by clock. Every stored index at or past the insertion
|
|
905
|
+
* point shifts by one, because later envelopes still look rows up by index.
|
|
906
|
+
*/
|
|
907
|
+
insertByTimestamp(row) {
|
|
908
|
+
const index = this.raw.findIndex((existing) => existing.timestamp > row.timestamp);
|
|
909
|
+
if (index === -1) return this.push(row);
|
|
910
|
+
this.raw.splice(index, 0, row);
|
|
911
|
+
for (const map of [this.toolRowIndex, this.approvalRowIndex]) {
|
|
912
|
+
for (const [key, value] of map) if (value >= index) map.set(key, value + 1);
|
|
913
|
+
}
|
|
914
|
+
this.mark(index);
|
|
915
|
+
return index;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Rows built directly from the request shape — no envelope is fabricated for
|
|
919
|
+
* them. An envelope needs a `sessionId` and a `sequence`, and a caller that
|
|
920
|
+
* has neither can only invent them; an invented sequence then collides with
|
|
921
|
+
* the first real envelopes that arrive.
|
|
922
|
+
*/
|
|
923
|
+
restore(pendingApprovals, restoredAt) {
|
|
924
|
+
const at = restoredAt ?? this.raw[this.raw.length - 1]?.timestamp ?? (/* @__PURE__ */ new Date(0)).toISOString();
|
|
925
|
+
for (const request of pendingApprovals) {
|
|
926
|
+
if (!request.itemId) continue;
|
|
927
|
+
if (this.approvalRowIndex.has(request.itemId)) continue;
|
|
928
|
+
if (request.logicalItemId && this.approvalRowIndex.has(request.logicalItemId)) continue;
|
|
929
|
+
const row = {
|
|
930
|
+
type: "approval",
|
|
931
|
+
id: request.itemId,
|
|
932
|
+
kind: request.kind,
|
|
933
|
+
description: request.description,
|
|
934
|
+
turnId: request.turnId ?? null,
|
|
935
|
+
state: resolveRestoredApprovalState({
|
|
936
|
+
itemId: request.itemId,
|
|
937
|
+
...request.logicalItemId ? { logicalItemId: request.logicalItemId } : {},
|
|
938
|
+
orphanResolutions: this.orphanResolutions
|
|
939
|
+
})
|
|
940
|
+
};
|
|
941
|
+
if (request.requestKind !== void 0) row.requestKind = request.requestKind;
|
|
942
|
+
if (request.detail !== void 0) row.detail = request.detail;
|
|
943
|
+
if (request.requestId !== void 0) row.requestId = request.requestId;
|
|
944
|
+
if (request.title !== void 0) row.title = request.title;
|
|
945
|
+
if (request.source !== void 0) row.source = request.source;
|
|
946
|
+
if (request.questions !== void 0) row.questions = request.questions;
|
|
947
|
+
if (request.options !== void 0) row.options = request.options;
|
|
948
|
+
if (request.allowsFreeform !== void 0) row.allowsFreeform = request.allowsFreeform;
|
|
949
|
+
if (request.canProceedWithoutAnswer !== void 0) row.canProceedWithoutAnswer = request.canProceedWithoutAnswer;
|
|
950
|
+
if (request.providerMetadata !== void 0) row.providerMetadata = request.providerMetadata;
|
|
951
|
+
this.restoredIds.add(request.itemId);
|
|
952
|
+
const index = this.insertByTimestamp({
|
|
953
|
+
key: `approval:${request.itemId}`,
|
|
954
|
+
timestamp: at,
|
|
955
|
+
event: row
|
|
956
|
+
});
|
|
957
|
+
this.approvalRowIndex.set(request.itemId, index);
|
|
958
|
+
if (request.logicalItemId) this.approvalRowIndex.set(request.logicalItemId, index);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
function collapseTranscriptEvents(envelopes, pendingApprovals = [], restoredAt) {
|
|
963
|
+
const collapser = new RowCollapser();
|
|
964
|
+
collapser.append(envelopes);
|
|
965
|
+
collapser.restore(pendingApprovals, restoredAt);
|
|
966
|
+
return collapser.raw.slice();
|
|
967
|
+
}
|
|
968
|
+
function sameStatusRow(a, b) {
|
|
969
|
+
return a.turnStatus === b.turnStatus && (a.turnId ?? null) === (b.turnId ?? null) && (a.message ?? "") === (b.message ?? "");
|
|
970
|
+
}
|
|
971
|
+
function mergeReasoningFragment(existing, incoming) {
|
|
972
|
+
if (!existing.length) return incoming;
|
|
973
|
+
if (!incoming.length) return existing;
|
|
974
|
+
if (existing === incoming) return existing;
|
|
975
|
+
if (incoming.startsWith(existing)) return incoming;
|
|
976
|
+
if (existing.startsWith(incoming)) return existing;
|
|
977
|
+
if (incoming.trim().length > 0 && existing.trimEnd().endsWith(incoming.trim())) return existing;
|
|
978
|
+
return `${existing}${incoming}`;
|
|
979
|
+
}
|
|
980
|
+
function mergeReasoningTextFragments(texts) {
|
|
981
|
+
const fragments = [];
|
|
982
|
+
for (const raw of texts) {
|
|
983
|
+
const text = raw.trim();
|
|
984
|
+
if (!text.length) continue;
|
|
985
|
+
if (fragments.includes(text)) continue;
|
|
986
|
+
const contained = fragments.map((fragment, index) => text.includes(fragment) ? index : -1).filter((index) => index >= 0);
|
|
987
|
+
if (contained.length) {
|
|
988
|
+
const firstIndex = contained[0];
|
|
989
|
+
fragments[firstIndex] = text;
|
|
990
|
+
for (const index of contained.slice(1).sort((left, right) => right - left)) {
|
|
991
|
+
fragments.splice(index, 1);
|
|
992
|
+
}
|
|
993
|
+
continue;
|
|
994
|
+
}
|
|
995
|
+
if (fragments.some((fragment) => fragment.includes(text))) continue;
|
|
996
|
+
fragments.push(text);
|
|
997
|
+
}
|
|
998
|
+
return fragments.join("\n\n---\n\n");
|
|
999
|
+
}
|
|
1000
|
+
function groupInto(rows, from, grouped, starts) {
|
|
1001
|
+
let index = from;
|
|
1002
|
+
while (index < rows.length) {
|
|
1003
|
+
const row = rows[index];
|
|
1004
|
+
if (row.event.type === "reasoning") {
|
|
1005
|
+
const head = row.event;
|
|
1006
|
+
const blocks = [];
|
|
1007
|
+
let currentItemKey = `${head.itemId ?? ""}\0${head.summaryIndex ?? ""}`;
|
|
1008
|
+
let currentText = head.text ?? "";
|
|
1009
|
+
let cursor = index + 1;
|
|
1010
|
+
const flushBlock = () => {
|
|
1011
|
+
if (currentText.length) blocks.push(currentText);
|
|
1012
|
+
};
|
|
1013
|
+
while (cursor < rows.length) {
|
|
1014
|
+
const candidate = rows[cursor];
|
|
1015
|
+
if (candidate.event.type !== "reasoning") break;
|
|
1016
|
+
if ((candidate.event.turnId ?? null) !== (head.turnId ?? null)) break;
|
|
1017
|
+
const nextItemKey = `${candidate.event.itemId ?? ""}\0${candidate.event.summaryIndex ?? ""}`;
|
|
1018
|
+
if (nextItemKey === currentItemKey) {
|
|
1019
|
+
currentText = mergeReasoningFragment(currentText, candidate.event.text ?? "");
|
|
1020
|
+
} else {
|
|
1021
|
+
flushBlock();
|
|
1022
|
+
currentText = candidate.event.text ?? "";
|
|
1023
|
+
currentItemKey = nextItemKey;
|
|
1024
|
+
}
|
|
1025
|
+
cursor += 1;
|
|
1026
|
+
}
|
|
1027
|
+
if (cursor > index + 1) {
|
|
1028
|
+
flushBlock();
|
|
1029
|
+
grouped.push({
|
|
1030
|
+
key: `reasoning-group:${row.key}`,
|
|
1031
|
+
timestamp: rows[cursor - 1].timestamp,
|
|
1032
|
+
event: { ...head, text: mergeReasoningTextFragments(blocks) }
|
|
1033
|
+
});
|
|
1034
|
+
starts.push(index);
|
|
1035
|
+
index = cursor;
|
|
1036
|
+
continue;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
if (row.event.type === "status") {
|
|
1040
|
+
const previous = grouped[grouped.length - 1];
|
|
1041
|
+
if (previous && previous.event.type === "status" && sameStatusRow(previous.event, row.event)) {
|
|
1042
|
+
grouped[grouped.length - 1] = row;
|
|
1043
|
+
index += 1;
|
|
1044
|
+
continue;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
grouped.push(row);
|
|
1048
|
+
starts.push(index);
|
|
1049
|
+
index += 1;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
function groupTranscriptRows(rows) {
|
|
1053
|
+
const grouped = [];
|
|
1054
|
+
groupInto(rows, 0, grouped, []);
|
|
1055
|
+
return grouped;
|
|
1056
|
+
}
|
|
1057
|
+
function buildTranscriptRows(envelopes, pendingApprovals = [], restoredAt) {
|
|
1058
|
+
return groupTranscriptRows(collapseTranscriptEvents(envelopes, pendingApprovals, restoredAt));
|
|
1059
|
+
}
|
|
1060
|
+
var TranscriptRowBuilder = class {
|
|
1061
|
+
collapser = new RowCollapser();
|
|
1062
|
+
grouped = [];
|
|
1063
|
+
starts = [];
|
|
1064
|
+
snapshot = [];
|
|
1065
|
+
/** The grouped rows, as a stable array until the next change. */
|
|
1066
|
+
get rows() {
|
|
1067
|
+
return this.snapshot;
|
|
1068
|
+
}
|
|
1069
|
+
/** Fold envelopes onto the end. Returns `rows`. */
|
|
1070
|
+
append(envelopes) {
|
|
1071
|
+
this.collapser.append(envelopes);
|
|
1072
|
+
return this.flush();
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Add the approvals the runtime is still blocked on (see
|
|
1076
|
+
* `collapseTranscriptEvents`). Call once, after the history append.
|
|
1077
|
+
*/
|
|
1078
|
+
restore(pendingApprovals, restoredAt) {
|
|
1079
|
+
this.collapser.restore(pendingApprovals, restoredAt);
|
|
1080
|
+
return this.flush();
|
|
1081
|
+
}
|
|
1082
|
+
flush() {
|
|
1083
|
+
const dirty = this.collapser.takeDirty();
|
|
1084
|
+
if (!Number.isFinite(dirty)) return this.snapshot;
|
|
1085
|
+
let group = this.starts.length - 1;
|
|
1086
|
+
while (group >= 0 && this.starts[group] > dirty) group -= 1;
|
|
1087
|
+
const resumeGroup = Math.max(0, group);
|
|
1088
|
+
const resumeRaw = this.starts[resumeGroup] ?? 0;
|
|
1089
|
+
this.grouped.length = resumeGroup;
|
|
1090
|
+
this.starts.length = resumeGroup;
|
|
1091
|
+
groupInto(this.collapser.raw, resumeRaw, this.grouped, this.starts);
|
|
1092
|
+
this.snapshot = this.grouped.slice();
|
|
1093
|
+
return this.snapshot;
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
var AdeChatContext = react.createContext({ client: null });
|
|
1097
|
+
function DaexChatProvider({ client, labels, children }) {
|
|
1098
|
+
const value = react.useMemo(
|
|
1099
|
+
() => labels ? { client, labels } : { client },
|
|
1100
|
+
[client, labels]
|
|
1101
|
+
);
|
|
1102
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AdeChatContext.Provider, { value, children });
|
|
1103
|
+
}
|
|
1104
|
+
function useDaexChatContext() {
|
|
1105
|
+
return react.useContext(AdeChatContext);
|
|
1106
|
+
}
|
|
1107
|
+
function useDaexChatClient(explicit) {
|
|
1108
|
+
const { client } = useDaexChatContext();
|
|
1109
|
+
const resolved = explicit ?? client;
|
|
1110
|
+
if (!resolved) {
|
|
1111
|
+
throw new Error(
|
|
1112
|
+
"@daex-dev/chat-ui: no DaexChatClient. Pass `client` or wrap the tree in <DaexChatProvider>."
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
return resolved;
|
|
1116
|
+
}
|
|
1117
|
+
function useDaexProviders(explicitClient) {
|
|
1118
|
+
const client = useDaexChatClient(explicitClient);
|
|
1119
|
+
const [statuses, setStatuses] = react.useState([]);
|
|
1120
|
+
const [models, setModels] = react.useState([]);
|
|
1121
|
+
const [loading, setLoading] = react.useState(true);
|
|
1122
|
+
const [error, setError] = react.useState(null);
|
|
1123
|
+
const [nonce, setNonce] = react.useState(0);
|
|
1124
|
+
const refresh = react.useCallback(() => setNonce((value) => value + 1), []);
|
|
1125
|
+
react.useEffect(() => {
|
|
1126
|
+
let cancelled = false;
|
|
1127
|
+
setLoading(true);
|
|
1128
|
+
Promise.all([client.providers.status(), client.models.list()]).then(([nextStatuses, nextModels]) => {
|
|
1129
|
+
if (cancelled) return;
|
|
1130
|
+
setStatuses(nextStatuses);
|
|
1131
|
+
setModels(nextModels);
|
|
1132
|
+
setError(null);
|
|
1133
|
+
}).catch((cause) => {
|
|
1134
|
+
if (cancelled) return;
|
|
1135
|
+
setError(cause instanceof Error ? cause : new Error(String(cause)));
|
|
1136
|
+
}).finally(() => {
|
|
1137
|
+
if (!cancelled) setLoading(false);
|
|
1138
|
+
});
|
|
1139
|
+
return () => {
|
|
1140
|
+
cancelled = true;
|
|
1141
|
+
};
|
|
1142
|
+
}, [client, nonce]);
|
|
1143
|
+
react.useEffect(() => {
|
|
1144
|
+
return client.providers.onChange((next) => {
|
|
1145
|
+
setStatuses(next);
|
|
1146
|
+
client.models.list().then(setModels).catch(() => {
|
|
1147
|
+
});
|
|
1148
|
+
});
|
|
1149
|
+
}, [client]);
|
|
1150
|
+
return { statuses, models, loading, error, refresh };
|
|
1151
|
+
}
|
|
1152
|
+
var IDLE_STATUS = { state: "idle" };
|
|
1153
|
+
var DEFAULT_HISTORY_PAGE_SIZE = 200;
|
|
1154
|
+
function oldestSequence(envelopes) {
|
|
1155
|
+
let oldest = null;
|
|
1156
|
+
for (const envelope of envelopes) {
|
|
1157
|
+
if (typeof envelope.sequence === "number" && (oldest === null || envelope.sequence < oldest)) {
|
|
1158
|
+
oldest = envelope.sequence;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
return oldest;
|
|
1162
|
+
}
|
|
1163
|
+
function cursorFrom(page) {
|
|
1164
|
+
if (!page.hasMore) return null;
|
|
1165
|
+
const before = typeof page.nextBeforeSequence === "number" ? page.nextBeforeSequence : oldestSequence(page.events);
|
|
1166
|
+
return before === null ? null : { beforeSequence: before };
|
|
1167
|
+
}
|
|
1168
|
+
function useDaexThread(key, options) {
|
|
1169
|
+
const client = useDaexChatClient(options?.client);
|
|
1170
|
+
const [thread, setThread] = react.useState(null);
|
|
1171
|
+
const [rows, setRows] = react.useState([]);
|
|
1172
|
+
const envelopesRef = react.useRef([]);
|
|
1173
|
+
const builderRef = react.useRef(new TranscriptRowBuilder());
|
|
1174
|
+
const [olderCursor, setOlderCursor] = react.useState(null);
|
|
1175
|
+
const [loadingOlder, setLoadingOlder] = react.useState(false);
|
|
1176
|
+
const [model, setModelInfo] = react.useState(null);
|
|
1177
|
+
const openEpochRef = react.useRef(0);
|
|
1178
|
+
const restoredRef = react.useRef({
|
|
1179
|
+
restored: [],
|
|
1180
|
+
at: null
|
|
1181
|
+
});
|
|
1182
|
+
const loadingOlderRef = react.useRef(false);
|
|
1183
|
+
const [status, setStatus] = react.useState(IDLE_STATUS);
|
|
1184
|
+
const [usage, setUsage] = react.useState(null);
|
|
1185
|
+
const [slashCommands, setSlashCommands] = react.useState(void 0);
|
|
1186
|
+
const [slashCommandsLoading, setSlashCommandsLoading] = react.useState(false);
|
|
1187
|
+
const [slashCommandsError, setSlashCommandsError] = react.useState(null);
|
|
1188
|
+
const [error, setError] = react.useState(null);
|
|
1189
|
+
const [reopenEpoch, setReopenEpoch] = react.useState(0);
|
|
1190
|
+
const keepRowsOnReopenRef = react.useRef(false);
|
|
1191
|
+
const reopenKeepingRows = react.useCallback(() => {
|
|
1192
|
+
keepRowsOnReopenRef.current = true;
|
|
1193
|
+
setReopenEpoch((value) => value + 1);
|
|
1194
|
+
}, []);
|
|
1195
|
+
const modelId = options?.modelId;
|
|
1196
|
+
const providerId = options?.providerId;
|
|
1197
|
+
const resume = options?.resume;
|
|
1198
|
+
const enabled = options?.enabled ?? true;
|
|
1199
|
+
const pageSizeRef = react.useRef(DEFAULT_HISTORY_PAGE_SIZE);
|
|
1200
|
+
pageSizeRef.current = options?.historyPageSize && options.historyPageSize > 0 ? Math.floor(options.historyPageSize) : DEFAULT_HISTORY_PAGE_SIZE;
|
|
1201
|
+
const requestedModelIdRef = react.useRef(modelId);
|
|
1202
|
+
requestedModelIdRef.current = modelId;
|
|
1203
|
+
const boundModelIdRef = react.useRef(void 0);
|
|
1204
|
+
const rebuildRows = react.useCallback(
|
|
1205
|
+
(restored, at) => {
|
|
1206
|
+
const builder = new TranscriptRowBuilder();
|
|
1207
|
+
builder.append(envelopesRef.current);
|
|
1208
|
+
builder.restore(restored, at ?? void 0);
|
|
1209
|
+
builderRef.current = builder;
|
|
1210
|
+
setRows(builder.rows);
|
|
1211
|
+
},
|
|
1212
|
+
[]
|
|
1213
|
+
);
|
|
1214
|
+
react.useEffect(() => {
|
|
1215
|
+
if (typeof client.on !== "function") return;
|
|
1216
|
+
return client.on("restart", (payload) => {
|
|
1217
|
+
if (payload.ok) reopenKeepingRows();
|
|
1218
|
+
});
|
|
1219
|
+
}, [client, reopenKeepingRows]);
|
|
1220
|
+
react.useEffect(() => {
|
|
1221
|
+
let cancelled = false;
|
|
1222
|
+
const disposers = [];
|
|
1223
|
+
const epoch = ++openEpochRef.current;
|
|
1224
|
+
const keepRows = keepRowsOnReopenRef.current;
|
|
1225
|
+
keepRowsOnReopenRef.current = false;
|
|
1226
|
+
setThread(null);
|
|
1227
|
+
if (!keepRows) {
|
|
1228
|
+
envelopesRef.current = [];
|
|
1229
|
+
builderRef.current = new TranscriptRowBuilder();
|
|
1230
|
+
setRows([]);
|
|
1231
|
+
}
|
|
1232
|
+
setOlderCursor(null);
|
|
1233
|
+
setLoadingOlder(false);
|
|
1234
|
+
loadingOlderRef.current = false;
|
|
1235
|
+
setModelInfo(null);
|
|
1236
|
+
restoredRef.current = { restored: [], at: null };
|
|
1237
|
+
setStatus(IDLE_STATUS);
|
|
1238
|
+
setUsage(null);
|
|
1239
|
+
setSlashCommands(void 0);
|
|
1240
|
+
setSlashCommandsLoading(false);
|
|
1241
|
+
setSlashCommandsError(null);
|
|
1242
|
+
if (!enabled) return;
|
|
1243
|
+
const openOptions = {};
|
|
1244
|
+
const openModelId = requestedModelIdRef.current;
|
|
1245
|
+
boundModelIdRef.current = openModelId;
|
|
1246
|
+
if (openModelId !== void 0) openOptions.modelId = openModelId;
|
|
1247
|
+
if (providerId !== void 0) openOptions.providerId = providerId;
|
|
1248
|
+
if (resume !== void 0) openOptions.resume = resume;
|
|
1249
|
+
client.threads.open(key, openOptions).then(async (opened) => {
|
|
1250
|
+
if (cancelled) return;
|
|
1251
|
+
const live = [];
|
|
1252
|
+
let historyApplied = false;
|
|
1253
|
+
let pendingLive = [];
|
|
1254
|
+
let flushScheduled = false;
|
|
1255
|
+
const flushLive = () => {
|
|
1256
|
+
flushScheduled = false;
|
|
1257
|
+
if (cancelled || pendingLive.length === 0) return;
|
|
1258
|
+
const batch = pendingLive;
|
|
1259
|
+
pendingLive = [];
|
|
1260
|
+
envelopesRef.current.push(...batch);
|
|
1261
|
+
setRows(builderRef.current.append(batch));
|
|
1262
|
+
};
|
|
1263
|
+
disposers.push(
|
|
1264
|
+
opened.on("event", (envelope) => {
|
|
1265
|
+
if (isHistoryInvalidation(envelope)) {
|
|
1266
|
+
reopenKeepingRows();
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
if (!historyApplied) {
|
|
1270
|
+
live.push(envelope);
|
|
1271
|
+
return;
|
|
1272
|
+
}
|
|
1273
|
+
pendingLive.push(envelope);
|
|
1274
|
+
if (!flushScheduled) {
|
|
1275
|
+
flushScheduled = true;
|
|
1276
|
+
queueMicrotask(flushLive);
|
|
1277
|
+
}
|
|
1278
|
+
})
|
|
1279
|
+
);
|
|
1280
|
+
disposers.push(opened.on("status", (next) => setStatus(next)));
|
|
1281
|
+
disposers.push(opened.on("usage", (next) => setUsage(next)));
|
|
1282
|
+
if (typeof opened.slashCommands === "function") {
|
|
1283
|
+
setSlashCommands(null);
|
|
1284
|
+
setSlashCommandsLoading(true);
|
|
1285
|
+
void opened.slashCommands().then((commands) => {
|
|
1286
|
+
if (!cancelled && epoch === openEpochRef.current) {
|
|
1287
|
+
setSlashCommands(commands ?? []);
|
|
1288
|
+
setSlashCommandsError(null);
|
|
1289
|
+
}
|
|
1290
|
+
}).catch((cause) => {
|
|
1291
|
+
if (!cancelled && epoch === openEpochRef.current) {
|
|
1292
|
+
setSlashCommands(null);
|
|
1293
|
+
setSlashCommandsError(cause instanceof Error ? cause.message : String(cause));
|
|
1294
|
+
}
|
|
1295
|
+
}).finally(() => {
|
|
1296
|
+
if (!cancelled && epoch === openEpochRef.current) setSlashCommandsLoading(false);
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
let history;
|
|
1300
|
+
let cursor = null;
|
|
1301
|
+
if (typeof opened.historyPage === "function") {
|
|
1302
|
+
const page = await opened.historyPage({ limit: pageSizeRef.current }).catch(() => null);
|
|
1303
|
+
if (page) {
|
|
1304
|
+
history = page.events ?? [];
|
|
1305
|
+
cursor = cursorFrom(page);
|
|
1306
|
+
} else {
|
|
1307
|
+
history = await opened.history().catch(() => []);
|
|
1308
|
+
}
|
|
1309
|
+
} else {
|
|
1310
|
+
history = await opened.history().catch(() => []);
|
|
1311
|
+
}
|
|
1312
|
+
if (cancelled) return;
|
|
1313
|
+
const restored = await readPendingApprovals(opened);
|
|
1314
|
+
if (cancelled) return;
|
|
1315
|
+
const seen = new Set(history.map(envelopeIdentity));
|
|
1316
|
+
historyApplied = true;
|
|
1317
|
+
const merged = sortEnvelopes([
|
|
1318
|
+
...history,
|
|
1319
|
+
...live.filter((item) => !seen.has(envelopeIdentity(item)))
|
|
1320
|
+
]);
|
|
1321
|
+
const restoredReadAt = merged[merged.length - 1]?.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1322
|
+
if (epoch !== openEpochRef.current) return;
|
|
1323
|
+
envelopesRef.current = merged;
|
|
1324
|
+
rebuildRows(restored, restoredReadAt);
|
|
1325
|
+
setOlderCursor(cursor);
|
|
1326
|
+
restoredRef.current = { restored, at: restoredReadAt };
|
|
1327
|
+
setModelInfo(readThreadModelSelection(opened.model));
|
|
1328
|
+
setThread(opened);
|
|
1329
|
+
setError(null);
|
|
1330
|
+
}).catch((cause) => {
|
|
1331
|
+
if (cancelled) return;
|
|
1332
|
+
setError(cause instanceof Error ? cause : new Error(String(cause)));
|
|
1333
|
+
});
|
|
1334
|
+
return () => {
|
|
1335
|
+
cancelled = true;
|
|
1336
|
+
for (const dispose of disposers) dispose();
|
|
1337
|
+
};
|
|
1338
|
+
}, [client, key, providerId, resume, enabled, rebuildRows, reopenEpoch, reopenKeepingRows]);
|
|
1339
|
+
const threadRef = react.useRef(null);
|
|
1340
|
+
threadRef.current = thread;
|
|
1341
|
+
const send = react.useCallback(async (input) => {
|
|
1342
|
+
await threadRef.current?.send(input);
|
|
1343
|
+
}, []);
|
|
1344
|
+
const steer = react.useCallback(async (input) => {
|
|
1345
|
+
await threadRef.current?.steer(input);
|
|
1346
|
+
}, []);
|
|
1347
|
+
const interrupt = react.useCallback(async () => {
|
|
1348
|
+
await threadRef.current?.interrupt();
|
|
1349
|
+
}, []);
|
|
1350
|
+
const setModel = react.useCallback(async (nextModelId) => {
|
|
1351
|
+
const target = threadRef.current;
|
|
1352
|
+
if (!target || !nextModelId) return;
|
|
1353
|
+
if (boundModelIdRef.current === nextModelId) return;
|
|
1354
|
+
if (typeof target.setModel !== "function") return;
|
|
1355
|
+
const selection = await target.setModel(nextModelId);
|
|
1356
|
+
boundModelIdRef.current = nextModelId;
|
|
1357
|
+
if (threadRef.current === target) {
|
|
1358
|
+
setModelInfo(target.model ?? readThreadModelSelection(selection));
|
|
1359
|
+
}
|
|
1360
|
+
}, []);
|
|
1361
|
+
const update = react.useCallback(async (patch) => {
|
|
1362
|
+
const target = threadRef.current;
|
|
1363
|
+
if (typeof target?.update !== "function") return;
|
|
1364
|
+
const updated = await target.update(patch);
|
|
1365
|
+
if (threadRef.current === target) {
|
|
1366
|
+
const next = target.model ?? readThreadModelSelection(updated?.model);
|
|
1367
|
+
if (next) setModelInfo(next);
|
|
1368
|
+
}
|
|
1369
|
+
}, []);
|
|
1370
|
+
const retry = react.useCallback(async () => {
|
|
1371
|
+
const target = threadRef.current;
|
|
1372
|
+
if (typeof target?.retry !== "function") return;
|
|
1373
|
+
await target.retry();
|
|
1374
|
+
}, []);
|
|
1375
|
+
const editLast = react.useCallback(async (input) => {
|
|
1376
|
+
const target = threadRef.current;
|
|
1377
|
+
if (typeof target?.editLast !== "function") return;
|
|
1378
|
+
await target.editLast(input);
|
|
1379
|
+
}, []);
|
|
1380
|
+
const loadOlder = react.useCallback(async () => {
|
|
1381
|
+
const target = threadRef.current;
|
|
1382
|
+
if (!target || typeof target.historyPage !== "function") return;
|
|
1383
|
+
if (!olderCursor || loadingOlderRef.current) return;
|
|
1384
|
+
const epoch = openEpochRef.current;
|
|
1385
|
+
loadingOlderRef.current = true;
|
|
1386
|
+
setLoadingOlder(true);
|
|
1387
|
+
try {
|
|
1388
|
+
const page = await target.historyPage({
|
|
1389
|
+
beforeSequence: olderCursor.beforeSequence,
|
|
1390
|
+
limit: pageSizeRef.current
|
|
1391
|
+
});
|
|
1392
|
+
if (epoch !== openEpochRef.current || threadRef.current !== target) return;
|
|
1393
|
+
const seen = new Set(envelopesRef.current.map(envelopeIdentity));
|
|
1394
|
+
const older = (page.events ?? []).filter((item) => !seen.has(envelopeIdentity(item)));
|
|
1395
|
+
const next = cursorFrom(page);
|
|
1396
|
+
setOlderCursor(older.length === 0 ? null : next);
|
|
1397
|
+
if (older.length === 0) return;
|
|
1398
|
+
envelopesRef.current = sortEnvelopes([...older, ...envelopesRef.current]);
|
|
1399
|
+
rebuildRows(restoredRef.current.restored, restoredRef.current.at);
|
|
1400
|
+
} catch {
|
|
1401
|
+
} finally {
|
|
1402
|
+
if (epoch === openEpochRef.current) {
|
|
1403
|
+
loadingOlderRef.current = false;
|
|
1404
|
+
setLoadingOlder(false);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}, [olderCursor, rebuildRows]);
|
|
1408
|
+
const approve = react.useCallback(
|
|
1409
|
+
async (itemId, decision, responseText) => {
|
|
1410
|
+
const target = threadRef.current;
|
|
1411
|
+
if (typeof target?.approve !== "function") return;
|
|
1412
|
+
if (responseText === void 0) await target.approve(itemId, decision);
|
|
1413
|
+
else await target.approve(itemId, decision, responseText);
|
|
1414
|
+
},
|
|
1415
|
+
[]
|
|
1416
|
+
);
|
|
1417
|
+
const pendingApprovals = react.useCallback(async () => {
|
|
1418
|
+
const target = threadRef.current;
|
|
1419
|
+
if (typeof target?.pendingApprovals !== "function") return [];
|
|
1420
|
+
return await target.pendingApprovals();
|
|
1421
|
+
}, []);
|
|
1422
|
+
const respond = react.useCallback(async (requestId, response) => {
|
|
1423
|
+
const target = threadRef.current;
|
|
1424
|
+
if (typeof target?.respond !== "function") return;
|
|
1425
|
+
await target.respond(requestId, response);
|
|
1426
|
+
}, []);
|
|
1427
|
+
const reloadSlashCommands = react.useCallback(async () => {
|
|
1428
|
+
const target = threadRef.current;
|
|
1429
|
+
if (typeof target?.slashCommands !== "function") return;
|
|
1430
|
+
setSlashCommandsLoading(true);
|
|
1431
|
+
setSlashCommandsError(null);
|
|
1432
|
+
try {
|
|
1433
|
+
setSlashCommands(await target.slashCommands());
|
|
1434
|
+
} catch (cause) {
|
|
1435
|
+
setSlashCommands(null);
|
|
1436
|
+
setSlashCommandsError(cause instanceof Error ? cause.message : String(cause));
|
|
1437
|
+
} finally {
|
|
1438
|
+
setSlashCommandsLoading(false);
|
|
1439
|
+
}
|
|
1440
|
+
}, []);
|
|
1441
|
+
return {
|
|
1442
|
+
thread,
|
|
1443
|
+
ready: thread !== null,
|
|
1444
|
+
rows,
|
|
1445
|
+
status,
|
|
1446
|
+
usage,
|
|
1447
|
+
error,
|
|
1448
|
+
send,
|
|
1449
|
+
steer,
|
|
1450
|
+
interrupt,
|
|
1451
|
+
setModel,
|
|
1452
|
+
update,
|
|
1453
|
+
retry,
|
|
1454
|
+
editLast,
|
|
1455
|
+
approve,
|
|
1456
|
+
pendingApprovals,
|
|
1457
|
+
respond,
|
|
1458
|
+
canRespond: typeof thread?.respond === "function",
|
|
1459
|
+
slashCommands,
|
|
1460
|
+
slashCommandsLoading,
|
|
1461
|
+
slashCommandsError,
|
|
1462
|
+
reloadSlashCommands,
|
|
1463
|
+
canSetModel: typeof thread?.setModel === "function",
|
|
1464
|
+
canApprove: typeof thread?.approve === "function",
|
|
1465
|
+
canUpdate: typeof thread?.update === "function",
|
|
1466
|
+
canRetry: typeof thread?.retry === "function" && typeof thread?.editLast === "function",
|
|
1467
|
+
model,
|
|
1468
|
+
hasOlder: olderCursor !== null,
|
|
1469
|
+
loadingOlder,
|
|
1470
|
+
loadOlder
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
function isHistoryInvalidation(envelope) {
|
|
1474
|
+
const event = envelope.event;
|
|
1475
|
+
return event?.type === "session_meta_updated" && event.historyInvalidated === true;
|
|
1476
|
+
}
|
|
1477
|
+
function envelopeIdentity(envelope) {
|
|
1478
|
+
return `${envelope.sessionId}:${envelope.sequence ?? "?"}:${envelope.timestamp}:${envelope.event?.type ?? "?"}`;
|
|
1479
|
+
}
|
|
1480
|
+
function sortEnvelopes(envelopes) {
|
|
1481
|
+
return envelopes.map((envelope, index) => ({ envelope, index })).sort((a, b) => {
|
|
1482
|
+
const aSeq = typeof a.envelope.sequence === "number" ? a.envelope.sequence : null;
|
|
1483
|
+
const bSeq = typeof b.envelope.sequence === "number" ? b.envelope.sequence : null;
|
|
1484
|
+
if (aSeq !== null && bSeq === null) return -1;
|
|
1485
|
+
if (aSeq === null && bSeq !== null) return 1;
|
|
1486
|
+
if (aSeq !== null && bSeq !== null) {
|
|
1487
|
+
if (aSeq !== bSeq) return aSeq - bSeq;
|
|
1488
|
+
return a.index - b.index;
|
|
1489
|
+
}
|
|
1490
|
+
if (a.envelope.timestamp !== b.envelope.timestamp) {
|
|
1491
|
+
return a.envelope.timestamp < b.envelope.timestamp ? -1 : 1;
|
|
1492
|
+
}
|
|
1493
|
+
return a.index - b.index;
|
|
1494
|
+
}).map((entry) => entry.envelope);
|
|
1495
|
+
}
|
|
1496
|
+
async function readPendingApprovals(thread) {
|
|
1497
|
+
if (typeof thread.pendingApprovals !== "function") return [];
|
|
1498
|
+
const pending = await thread.pendingApprovals().catch(() => []);
|
|
1499
|
+
return pending.filter((request) => Boolean(request.itemId));
|
|
1500
|
+
}
|
|
1501
|
+
var AdeChatProvider = DaexChatProvider;
|
|
1502
|
+
var useAdeChatClient = useDaexChatClient;
|
|
1503
|
+
var useAdeChatContext = useDaexChatContext;
|
|
1504
|
+
var useAdeProviders = useDaexProviders;
|
|
1505
|
+
var useAdeThread = useDaexThread;
|
|
1506
|
+
|
|
1507
|
+
// src/models/modelSearch.ts
|
|
1508
|
+
function normalizeSearchQuery(input) {
|
|
1509
|
+
const trimmed = input.trim();
|
|
1510
|
+
return trimmed ? trimmed.toLowerCase() : "";
|
|
1511
|
+
}
|
|
1512
|
+
function scoreSubsequenceMatch(value, query) {
|
|
1513
|
+
if (!query) return 0;
|
|
1514
|
+
let queryIndex = 0;
|
|
1515
|
+
let firstMatchIndex = -1;
|
|
1516
|
+
let previousMatchIndex = -1;
|
|
1517
|
+
let gapPenalty = 0;
|
|
1518
|
+
for (let valueIndex = 0; valueIndex < value.length; valueIndex += 1) {
|
|
1519
|
+
if (value[valueIndex] !== query[queryIndex]) continue;
|
|
1520
|
+
if (firstMatchIndex === -1) firstMatchIndex = valueIndex;
|
|
1521
|
+
if (previousMatchIndex !== -1) gapPenalty += valueIndex - previousMatchIndex - 1;
|
|
1522
|
+
previousMatchIndex = valueIndex;
|
|
1523
|
+
queryIndex += 1;
|
|
1524
|
+
if (queryIndex === query.length) {
|
|
1525
|
+
const spanPenalty = valueIndex - firstMatchIndex + 1 - query.length;
|
|
1526
|
+
const valueLengthPenalty = Math.min(64, value.length - query.length);
|
|
1527
|
+
return firstMatchIndex * 2 + gapPenalty * 3 + spanPenalty + valueLengthPenalty;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return null;
|
|
1531
|
+
}
|
|
1532
|
+
function lengthPenalty(value, query) {
|
|
1533
|
+
return Math.min(64, Math.max(0, value.length - query.length));
|
|
1534
|
+
}
|
|
1535
|
+
function findBoundaryMatchIndex(value, query, boundaryMarkers) {
|
|
1536
|
+
let bestIndex = null;
|
|
1537
|
+
for (const marker of boundaryMarkers) {
|
|
1538
|
+
const index = value.indexOf(`${marker}${query}`);
|
|
1539
|
+
if (index === -1) continue;
|
|
1540
|
+
const matchIndex = index + marker.length;
|
|
1541
|
+
if (bestIndex === null || matchIndex < bestIndex) bestIndex = matchIndex;
|
|
1542
|
+
}
|
|
1543
|
+
return bestIndex;
|
|
1544
|
+
}
|
|
1545
|
+
function scoreQueryMatch(input) {
|
|
1546
|
+
const { value, query } = input;
|
|
1547
|
+
if (!value || !query) return null;
|
|
1548
|
+
if (value === query) return input.exactBase;
|
|
1549
|
+
if (input.prefixBase !== void 0 && value.startsWith(query)) {
|
|
1550
|
+
return input.prefixBase + lengthPenalty(value, query);
|
|
1551
|
+
}
|
|
1552
|
+
if (input.boundaryBase !== void 0) {
|
|
1553
|
+
const boundaryIndex = findBoundaryMatchIndex(
|
|
1554
|
+
value,
|
|
1555
|
+
query,
|
|
1556
|
+
input.boundaryMarkers ?? [" ", "-", "_", "/"]
|
|
1557
|
+
);
|
|
1558
|
+
if (boundaryIndex !== null) {
|
|
1559
|
+
return input.boundaryBase + boundaryIndex * 2 + lengthPenalty(value, query);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
if (input.includesBase !== void 0) {
|
|
1563
|
+
const includesIndex = value.indexOf(query);
|
|
1564
|
+
if (includesIndex !== -1) {
|
|
1565
|
+
return input.includesBase + includesIndex * 2 + lengthPenalty(value, query);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
if (input.fuzzyBase !== void 0) {
|
|
1569
|
+
const fuzzyScore = scoreSubsequenceMatch(value, query);
|
|
1570
|
+
if (fuzzyScore !== null) return input.fuzzyBase + fuzzyScore;
|
|
1571
|
+
}
|
|
1572
|
+
return null;
|
|
1573
|
+
}
|
|
1574
|
+
function resolveProviderDisplayName(item) {
|
|
1575
|
+
return item.providerDisplayName ?? item.providerId;
|
|
1576
|
+
}
|
|
1577
|
+
function buildModelSearchText(item) {
|
|
1578
|
+
return normalizeSearchQuery(
|
|
1579
|
+
[item.displayName, item.shortName, item.subProvider, item.providerId, resolveProviderDisplayName(item)].concat(item.aliases ?? []).filter((value) => typeof value === "string" && value.length > 0).join(" ")
|
|
1580
|
+
);
|
|
1581
|
+
}
|
|
1582
|
+
function getSearchFields(item) {
|
|
1583
|
+
return [
|
|
1584
|
+
normalizeSearchQuery(item.displayName),
|
|
1585
|
+
...item.shortName ? [normalizeSearchQuery(item.shortName)] : [],
|
|
1586
|
+
...(item.aliases ?? []).map((alias) => normalizeSearchQuery(alias)).filter(Boolean),
|
|
1587
|
+
...item.subProvider ? [normalizeSearchQuery(item.subProvider)] : [],
|
|
1588
|
+
normalizeSearchQuery(item.providerId),
|
|
1589
|
+
normalizeSearchQuery(resolveProviderDisplayName(item)),
|
|
1590
|
+
buildModelSearchText(item)
|
|
1591
|
+
];
|
|
1592
|
+
}
|
|
1593
|
+
function scoreToken(field, token, fieldBase) {
|
|
1594
|
+
return scoreQueryMatch({
|
|
1595
|
+
value: field,
|
|
1596
|
+
query: token,
|
|
1597
|
+
exactBase: fieldBase,
|
|
1598
|
+
prefixBase: fieldBase + 2,
|
|
1599
|
+
boundaryBase: fieldBase + 4,
|
|
1600
|
+
includesBase: fieldBase + 6,
|
|
1601
|
+
...token.length >= 3 ? { fuzzyBase: fieldBase + 100 } : {}
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
function scoreModelSearch(item, query) {
|
|
1605
|
+
const tokens = normalizeSearchQuery(query).split(/\s+/u).filter((token) => token.length > 0);
|
|
1606
|
+
if (tokens.length === 0) return 0;
|
|
1607
|
+
const fields = getSearchFields(item);
|
|
1608
|
+
let score = 0;
|
|
1609
|
+
for (const token of tokens) {
|
|
1610
|
+
const tokenScores = fields.map((field, index) => scoreToken(field, token, index * 10)).filter((fieldScore) => fieldScore !== null);
|
|
1611
|
+
if (tokenScores.length === 0) return null;
|
|
1612
|
+
score += Math.min(...tokenScores);
|
|
1613
|
+
}
|
|
1614
|
+
return score;
|
|
1615
|
+
}
|
|
1616
|
+
function searchable(model, status) {
|
|
1617
|
+
return {
|
|
1618
|
+
displayName: model.displayName,
|
|
1619
|
+
...model.shortName ? { shortName: model.shortName } : {},
|
|
1620
|
+
...model.subProvider ? { subProvider: model.subProvider } : {},
|
|
1621
|
+
...model.aliases ? { aliases: model.aliases } : {},
|
|
1622
|
+
providerId: model.providerId,
|
|
1623
|
+
...status?.displayName ? { providerDisplayName: status.displayName } : {}
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
function isProviderUsable(status) {
|
|
1627
|
+
return Boolean(status?.installed && status.authenticated);
|
|
1628
|
+
}
|
|
1629
|
+
function isModelSelectable(model, status) {
|
|
1630
|
+
if (model.available === false) return false;
|
|
1631
|
+
return isProviderUsable(status);
|
|
1632
|
+
}
|
|
1633
|
+
function groupModelsByProvider(input) {
|
|
1634
|
+
const statusById = new Map(input.statuses.map((status) => [status.id, status]));
|
|
1635
|
+
const query = input.query?.trim() ?? "";
|
|
1636
|
+
const order = [];
|
|
1637
|
+
for (const status of input.statuses) if (!order.includes(status.id)) order.push(status.id);
|
|
1638
|
+
for (const model of input.models) if (!order.includes(model.providerId)) order.push(model.providerId);
|
|
1639
|
+
const scored = /* @__PURE__ */ new Map();
|
|
1640
|
+
for (const model of input.models) {
|
|
1641
|
+
const status = statusById.get(model.providerId) ?? null;
|
|
1642
|
+
const score = query ? scoreModelSearch(searchable(model, status), query) : 0;
|
|
1643
|
+
if (score === null) continue;
|
|
1644
|
+
const bucket = scored.get(model.providerId) ?? [];
|
|
1645
|
+
bucket.push({ model, score });
|
|
1646
|
+
scored.set(model.providerId, bucket);
|
|
1647
|
+
}
|
|
1648
|
+
const groups = [];
|
|
1649
|
+
for (const providerId of order) {
|
|
1650
|
+
const bucket = scored.get(providerId);
|
|
1651
|
+
if (!bucket || bucket.length === 0) continue;
|
|
1652
|
+
const status = statusById.get(providerId) ?? null;
|
|
1653
|
+
const models = bucket.map((entry, index) => ({ ...entry, index })).sort((a, b) => a.score - b.score || a.index - b.index).map((entry) => entry.model);
|
|
1654
|
+
groups.push({
|
|
1655
|
+
providerId,
|
|
1656
|
+
providerLabel: status?.displayName ?? providerId,
|
|
1657
|
+
status,
|
|
1658
|
+
enabled: isProviderUsable(status),
|
|
1659
|
+
models
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
return groups;
|
|
1663
|
+
}
|
|
1664
|
+
function statusDot(status) {
|
|
1665
|
+
if (!status || !status.installed) return "missing";
|
|
1666
|
+
return status.authenticated ? "ok" : "unauthed";
|
|
1667
|
+
}
|
|
1668
|
+
function ModelPicker(props) {
|
|
1669
|
+
const usesContext = props.models === void 0 || props.providers === void 0;
|
|
1670
|
+
return usesContext ? /* @__PURE__ */ jsxRuntime.jsx(ConnectedModelPicker, { ...props }) : /* @__PURE__ */ jsxRuntime.jsx(ModelPickerView, { ...props });
|
|
1671
|
+
}
|
|
1672
|
+
function ConnectedModelPicker(props) {
|
|
1673
|
+
const { statuses, models, loading, error } = useDaexProviders(props.client);
|
|
1674
|
+
if (error) {
|
|
1675
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-modelpicker-empty", children: [
|
|
1676
|
+
"Could not load models: ",
|
|
1677
|
+
error.message
|
|
1678
|
+
] });
|
|
1679
|
+
}
|
|
1680
|
+
if (loading && models.length === 0) {
|
|
1681
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-modelpicker-empty", children: "Loading models\u2026" });
|
|
1682
|
+
}
|
|
1683
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1684
|
+
ModelPickerView,
|
|
1685
|
+
{
|
|
1686
|
+
...props,
|
|
1687
|
+
models: props.models ?? models,
|
|
1688
|
+
providers: props.providers ?? statuses
|
|
1689
|
+
}
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
function ModelPickerView({
|
|
1693
|
+
value,
|
|
1694
|
+
onChange,
|
|
1695
|
+
models = [],
|
|
1696
|
+
providers = [],
|
|
1697
|
+
searchable: searchable2 = true,
|
|
1698
|
+
renderProviderNotice,
|
|
1699
|
+
reasoningEffort,
|
|
1700
|
+
onReasoningEffortChange,
|
|
1701
|
+
className
|
|
1702
|
+
}) {
|
|
1703
|
+
const [query, setQuery] = react.useState("");
|
|
1704
|
+
const [selectedProvider, setSelectedProvider] = react.useState(null);
|
|
1705
|
+
const railRefs = react.useRef(/* @__PURE__ */ new Map());
|
|
1706
|
+
const groups = react.useMemo(
|
|
1707
|
+
() => groupModelsByProvider({ models, statuses: providers, query }),
|
|
1708
|
+
[models, providers, query]
|
|
1709
|
+
);
|
|
1710
|
+
const activeProvider = react.useMemo(() => {
|
|
1711
|
+
if (selectedProvider && groups.some((group) => group.providerId === selectedProvider)) {
|
|
1712
|
+
return selectedProvider;
|
|
1713
|
+
}
|
|
1714
|
+
const selectedModel2 = models.find((model) => model.id === value);
|
|
1715
|
+
if (selectedModel2 && groups.some((group) => group.providerId === selectedModel2.providerId)) {
|
|
1716
|
+
return selectedModel2.providerId;
|
|
1717
|
+
}
|
|
1718
|
+
return groups[0]?.providerId ?? null;
|
|
1719
|
+
}, [groups, models, selectedProvider, value]);
|
|
1720
|
+
react.useEffect(() => {
|
|
1721
|
+
if (selectedProvider && !groups.some((group) => group.providerId === selectedProvider)) {
|
|
1722
|
+
setSelectedProvider(null);
|
|
1723
|
+
}
|
|
1724
|
+
}, [groups, selectedProvider]);
|
|
1725
|
+
const handleRailKeyDown = react.useCallback(
|
|
1726
|
+
(event, index) => {
|
|
1727
|
+
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
|
|
1728
|
+
event.preventDefault();
|
|
1729
|
+
const last = Math.max(0, groups.length - 1);
|
|
1730
|
+
const nextIndex = event.key === "Home" ? 0 : event.key === "End" ? last : Math.min(Math.max(0, index + (event.key === "ArrowDown" ? 1 : -1)), last);
|
|
1731
|
+
const next = groups[nextIndex];
|
|
1732
|
+
if (!next) return;
|
|
1733
|
+
setSelectedProvider(next.providerId);
|
|
1734
|
+
railRefs.current.get(next.providerId)?.focus();
|
|
1735
|
+
},
|
|
1736
|
+
[groups]
|
|
1737
|
+
);
|
|
1738
|
+
const activeGroup = groups.find((group) => group.providerId === activeProvider) ?? null;
|
|
1739
|
+
const selectedModel = value ? models.find((model) => model.id === value) ?? null : null;
|
|
1740
|
+
const efforts = selectedModel?.reasoningEfforts ?? [];
|
|
1741
|
+
const currentEffort = reasoningEffort ?? selectedModel?.defaultReasoningEffort ?? null;
|
|
1742
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ["adechat-modelpicker", className].filter(Boolean).join(" "), children: [
|
|
1743
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-modelpicker-rail", role: "tablist", "aria-orientation": "vertical", children: [
|
|
1744
|
+
groups.map((group, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1745
|
+
"button",
|
|
1746
|
+
{
|
|
1747
|
+
ref: (node) => {
|
|
1748
|
+
if (node) railRefs.current.set(group.providerId, node);
|
|
1749
|
+
else railRefs.current.delete(group.providerId);
|
|
1750
|
+
},
|
|
1751
|
+
type: "button",
|
|
1752
|
+
role: "tab",
|
|
1753
|
+
className: "adechat-modelpicker-railbutton",
|
|
1754
|
+
"aria-selected": group.providerId === activeProvider,
|
|
1755
|
+
tabIndex: group.providerId === activeProvider ? 0 : -1,
|
|
1756
|
+
onClick: () => setSelectedProvider(group.providerId),
|
|
1757
|
+
onKeyDown: (event) => handleRailKeyDown(event, index),
|
|
1758
|
+
children: [
|
|
1759
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1760
|
+
"span",
|
|
1761
|
+
{
|
|
1762
|
+
className: "adechat-status-dot",
|
|
1763
|
+
"data-status": statusDot(group.status),
|
|
1764
|
+
"aria-hidden": "true"
|
|
1765
|
+
}
|
|
1766
|
+
),
|
|
1767
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-modelpicker-raillabel", children: group.providerLabel })
|
|
1768
|
+
]
|
|
1769
|
+
},
|
|
1770
|
+
group.providerId
|
|
1771
|
+
)),
|
|
1772
|
+
groups.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-modelpicker-empty", children: "No providers" }) : null
|
|
1773
|
+
] }),
|
|
1774
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-modelpicker-main", children: [
|
|
1775
|
+
searchable2 ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1776
|
+
"input",
|
|
1777
|
+
{
|
|
1778
|
+
className: "adechat-modelpicker-search",
|
|
1779
|
+
type: "search",
|
|
1780
|
+
value: query,
|
|
1781
|
+
placeholder: "Search models",
|
|
1782
|
+
onChange: (event) => setQuery(event.target.value),
|
|
1783
|
+
"aria-label": "Search models"
|
|
1784
|
+
}
|
|
1785
|
+
) : null,
|
|
1786
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "adechat-modelpicker-list", role: "listbox", "aria-label": "Models", children: activeGroup ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1787
|
+
ModelGroupRows,
|
|
1788
|
+
{
|
|
1789
|
+
group: activeGroup,
|
|
1790
|
+
selectedId: value ?? null,
|
|
1791
|
+
onChange,
|
|
1792
|
+
...renderProviderNotice ? { renderProviderNotice } : {}
|
|
1793
|
+
}
|
|
1794
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("li", { className: "adechat-modelpicker-empty", children: query ? `No models match \u201C${query}\u201D.` : "No models available." }) }),
|
|
1795
|
+
onReasoningEffortChange && selectedModel && efforts.length ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1796
|
+
"div",
|
|
1797
|
+
{
|
|
1798
|
+
className: "adechat-modelpicker-effort",
|
|
1799
|
+
role: "radiogroup",
|
|
1800
|
+
"aria-label": `Reasoning effort for ${selectedModel.displayName}`,
|
|
1801
|
+
children: [
|
|
1802
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-modelpicker-effortlabel", children: "Effort" }),
|
|
1803
|
+
efforts.map((effort) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1804
|
+
"button",
|
|
1805
|
+
{
|
|
1806
|
+
type: "button",
|
|
1807
|
+
role: "radio",
|
|
1808
|
+
className: "adechat-modelpicker-effortoption",
|
|
1809
|
+
"aria-checked": effort === currentEffort,
|
|
1810
|
+
onClick: () => onReasoningEffortChange(effort, selectedModel),
|
|
1811
|
+
children: effort
|
|
1812
|
+
},
|
|
1813
|
+
effort
|
|
1814
|
+
))
|
|
1815
|
+
]
|
|
1816
|
+
}
|
|
1817
|
+
) : null
|
|
1818
|
+
] })
|
|
1819
|
+
] });
|
|
1820
|
+
}
|
|
1821
|
+
function ModelGroupRows({
|
|
1822
|
+
group,
|
|
1823
|
+
selectedId,
|
|
1824
|
+
onChange,
|
|
1825
|
+
renderProviderNotice
|
|
1826
|
+
}) {
|
|
1827
|
+
const notice = !group.enabled ? renderProviderNotice?.(group.status, group.providerId) : null;
|
|
1828
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1829
|
+
/* @__PURE__ */ jsxRuntime.jsx("li", { className: "adechat-modelpicker-group", "aria-hidden": "true", children: group.providerLabel }),
|
|
1830
|
+
notice ? /* @__PURE__ */ jsxRuntime.jsx("li", { children: notice }) : null,
|
|
1831
|
+
group.models.map((model) => {
|
|
1832
|
+
const selectable = isModelSelectable(model, group.status);
|
|
1833
|
+
return /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1834
|
+
"button",
|
|
1835
|
+
{
|
|
1836
|
+
type: "button",
|
|
1837
|
+
role: "option",
|
|
1838
|
+
className: "adechat-modelpicker-row",
|
|
1839
|
+
"aria-selected": model.id === selectedId,
|
|
1840
|
+
disabled: !selectable,
|
|
1841
|
+
title: selectable ? model.description : `${group.providerLabel} is not ready \u2014 sign in to use this model.`,
|
|
1842
|
+
onClick: () => onChange(model),
|
|
1843
|
+
children: [
|
|
1844
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-modelpicker-rowname", children: model.displayName }),
|
|
1845
|
+
model.subProvider ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-modelpicker-rowmeta", children: model.subProvider }) : null
|
|
1846
|
+
]
|
|
1847
|
+
}
|
|
1848
|
+
) }, model.id);
|
|
1849
|
+
})
|
|
1850
|
+
] });
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
// src/theme/createTheme.ts
|
|
1854
|
+
var DAEX_CHAT_TOKENS = [
|
|
1855
|
+
/**
|
|
1856
|
+
* The outermost surface: the chat root and the composer bar. Separate from
|
|
1857
|
+
* `--adechat-bg` so it alone can be `transparent` while inset surfaces
|
|
1858
|
+
* (code blocks, command boxes) keep an opaque colour.
|
|
1859
|
+
*/
|
|
1860
|
+
"--adechat-root-bg",
|
|
1861
|
+
"--adechat-bg",
|
|
1862
|
+
"--adechat-bg-subtle",
|
|
1863
|
+
"--adechat-bg-raised",
|
|
1864
|
+
"--adechat-fg",
|
|
1865
|
+
"--adechat-muted",
|
|
1866
|
+
"--adechat-accent",
|
|
1867
|
+
"--adechat-accent-fg",
|
|
1868
|
+
"--adechat-accent-subtle",
|
|
1869
|
+
"--adechat-border",
|
|
1870
|
+
"--adechat-border-strong",
|
|
1871
|
+
"--adechat-hover",
|
|
1872
|
+
"--adechat-danger",
|
|
1873
|
+
"--adechat-danger-subtle",
|
|
1874
|
+
"--adechat-success",
|
|
1875
|
+
"--adechat-radius",
|
|
1876
|
+
"--adechat-radius-sm",
|
|
1877
|
+
"--adechat-font",
|
|
1878
|
+
"--adechat-font-mono",
|
|
1879
|
+
"--adechat-font-size",
|
|
1880
|
+
"--adechat-space"
|
|
1881
|
+
];
|
|
1882
|
+
var DEFAULTS = {
|
|
1883
|
+
accent: "#5b8cff",
|
|
1884
|
+
darkBackground: "#101114",
|
|
1885
|
+
lightBackground: "#ffffff",
|
|
1886
|
+
danger: "#e5484d",
|
|
1887
|
+
success: "#30a46c",
|
|
1888
|
+
radius: 10,
|
|
1889
|
+
fontFamily: 'system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
|
|
1890
|
+
monoFontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',
|
|
1891
|
+
fontSize: 14,
|
|
1892
|
+
space: 8
|
|
1893
|
+
};
|
|
1894
|
+
function parseHex(value) {
|
|
1895
|
+
const hex = value.trim().replace(/^#/, "");
|
|
1896
|
+
if (!/^[0-9a-fA-F]+$/.test(hex)) return null;
|
|
1897
|
+
if (hex.length === 3 || hex.length === 4) {
|
|
1898
|
+
const [r, g, b, a] = hex.split("").map((char) => parseInt(char + char, 16));
|
|
1899
|
+
return { r, g, b, a: (a ?? 255) / 255 };
|
|
1900
|
+
}
|
|
1901
|
+
if (hex.length === 6 || hex.length === 8) {
|
|
1902
|
+
const parts = hex.match(/.{2}/g).map((pair) => parseInt(pair, 16));
|
|
1903
|
+
return { r: parts[0], g: parts[1], b: parts[2], a: (parts[3] ?? 255) / 255 };
|
|
1904
|
+
}
|
|
1905
|
+
return null;
|
|
1906
|
+
}
|
|
1907
|
+
function rgba(color, alpha) {
|
|
1908
|
+
const parsed = parseHex(color);
|
|
1909
|
+
if (!parsed) {
|
|
1910
|
+
return color;
|
|
1911
|
+
}
|
|
1912
|
+
return `rgba(${parsed.r}, ${parsed.g}, ${parsed.b}, ${round(alpha * parsed.a)})`;
|
|
1913
|
+
}
|
|
1914
|
+
function round(value) {
|
|
1915
|
+
return Math.round(value * 1e3) / 1e3;
|
|
1916
|
+
}
|
|
1917
|
+
function relativeLuminance(color) {
|
|
1918
|
+
const parsed = parseHex(color);
|
|
1919
|
+
if (!parsed) return null;
|
|
1920
|
+
const channel = (raw) => {
|
|
1921
|
+
const srgb = raw / 255;
|
|
1922
|
+
return srgb <= 0.03928 ? srgb / 12.92 : ((srgb + 0.055) / 1.055) ** 2.4;
|
|
1923
|
+
};
|
|
1924
|
+
return 0.2126 * channel(parsed.r) + 0.7152 * channel(parsed.g) + 0.0722 * channel(parsed.b);
|
|
1925
|
+
}
|
|
1926
|
+
function shade(color, amount, toward) {
|
|
1927
|
+
const parsed = parseHex(color);
|
|
1928
|
+
if (!parsed) return color;
|
|
1929
|
+
const target = toward === "light" ? 255 : 0;
|
|
1930
|
+
const mix = (channel) => Math.round(channel + (target - channel) * amount);
|
|
1931
|
+
return `rgb(${mix(parsed.r)}, ${mix(parsed.g)}, ${mix(parsed.b)})`;
|
|
1932
|
+
}
|
|
1933
|
+
function px(value, fallback) {
|
|
1934
|
+
if (value === void 0) return `${fallback}px`;
|
|
1935
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
1936
|
+
}
|
|
1937
|
+
function contrastForeground(background, scheme) {
|
|
1938
|
+
const luminance = relativeLuminance(background);
|
|
1939
|
+
if (luminance === null) return scheme === "dark" ? "#f5f6f8" : "#16181d";
|
|
1940
|
+
return luminance > 0.5 ? "#16181d" : "#f5f6f8";
|
|
1941
|
+
}
|
|
1942
|
+
function createTheme(input = {}) {
|
|
1943
|
+
const transparent = input.background?.trim().toLowerCase() === "transparent";
|
|
1944
|
+
const requestedBackground = transparent ? void 0 : input.background;
|
|
1945
|
+
const backgroundLuminance = requestedBackground ? relativeLuminance(requestedBackground) : null;
|
|
1946
|
+
const scheme = input.scheme ?? (backgroundLuminance === null ? "dark" : backgroundLuminance > 0.5 ? "light" : "dark");
|
|
1947
|
+
const background = requestedBackground ?? (scheme === "light" ? DEFAULTS.lightBackground : DEFAULTS.darkBackground);
|
|
1948
|
+
const accent = input.accent ?? DEFAULTS.accent;
|
|
1949
|
+
const foreground = input.foreground ?? contrastForeground(background, scheme);
|
|
1950
|
+
const danger = input.danger ?? DEFAULTS.danger;
|
|
1951
|
+
const success = input.success ?? DEFAULTS.success;
|
|
1952
|
+
const toward = scheme === "dark" ? "light" : "dark";
|
|
1953
|
+
const contrastInk = scheme === "dark" ? "#ffffff" : "#000000";
|
|
1954
|
+
const radius = px(input.radius, DEFAULTS.radius);
|
|
1955
|
+
const radiusSm = typeof input.radius === "number" ? `${Math.max(2, Math.round(input.radius * 0.6))}px` : input.radius ? `calc(${radius} * 0.6)` : `${Math.round(DEFAULTS.radius * 0.6)}px`;
|
|
1956
|
+
return {
|
|
1957
|
+
// A reference, not a copy, for every opaque theme: a host that overrides
|
|
1958
|
+
// `--adechat-bg` by hand (on the root, where this is declared) still moves
|
|
1959
|
+
// the root and composer with it, as it did before this token existed.
|
|
1960
|
+
"--adechat-root-bg": transparent ? "transparent" : "var(--adechat-bg)",
|
|
1961
|
+
"--adechat-bg": background,
|
|
1962
|
+
"--adechat-bg-subtle": shade(background, 0.04, toward),
|
|
1963
|
+
"--adechat-bg-raised": shade(background, 0.08, toward),
|
|
1964
|
+
"--adechat-fg": foreground,
|
|
1965
|
+
"--adechat-muted": input.muted ?? rgba(contrastInk, scheme === "dark" ? 0.56 : 0.52),
|
|
1966
|
+
"--adechat-accent": accent,
|
|
1967
|
+
"--adechat-accent-fg": contrastForeground(accent, scheme),
|
|
1968
|
+
"--adechat-accent-subtle": rgba(accent, 0.14),
|
|
1969
|
+
"--adechat-border": rgba(contrastInk, scheme === "dark" ? 0.1 : 0.12),
|
|
1970
|
+
"--adechat-border-strong": rgba(contrastInk, scheme === "dark" ? 0.2 : 0.24),
|
|
1971
|
+
"--adechat-hover": rgba(contrastInk, scheme === "dark" ? 0.06 : 0.05),
|
|
1972
|
+
"--adechat-danger": danger,
|
|
1973
|
+
"--adechat-danger-subtle": rgba(danger, 0.14),
|
|
1974
|
+
"--adechat-success": success,
|
|
1975
|
+
"--adechat-radius": radius,
|
|
1976
|
+
"--adechat-radius-sm": radiusSm,
|
|
1977
|
+
"--adechat-font": input.fontFamily ?? DEFAULTS.fontFamily,
|
|
1978
|
+
"--adechat-font-mono": input.monoFontFamily ?? DEFAULTS.monoFontFamily,
|
|
1979
|
+
"--adechat-font-size": px(input.fontSize, DEFAULTS.fontSize),
|
|
1980
|
+
"--adechat-space": px(input.space, DEFAULTS.space)
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
var defaultTheme = createTheme();
|
|
1984
|
+
function themeToCss(theme, selector = ":root") {
|
|
1985
|
+
const body = Object.keys(theme).map((token) => ` ${token}: ${theme[token]};`).join("\n");
|
|
1986
|
+
return `${selector} {
|
|
1987
|
+
${body}
|
|
1988
|
+
}`;
|
|
1989
|
+
}
|
|
1990
|
+
var ADE_CHAT_TOKENS = DAEX_CHAT_TOKENS;
|
|
1991
|
+
|
|
1992
|
+
// src/theme/styles.ts
|
|
1993
|
+
var ADE_CHAT_STYLE_ID = "adechat-styles";
|
|
1994
|
+
var daexChatCss = `
|
|
1995
|
+
${themeToCss(defaultTheme, ".adechat-root")}
|
|
1996
|
+
|
|
1997
|
+
.adechat-root {
|
|
1998
|
+
display: flex;
|
|
1999
|
+
flex-direction: column;
|
|
2000
|
+
min-height: 0;
|
|
2001
|
+
color: var(--adechat-fg);
|
|
2002
|
+
background: var(--adechat-root-bg, var(--adechat-bg));
|
|
2003
|
+
font-family: var(--adechat-font);
|
|
2004
|
+
font-size: var(--adechat-font-size);
|
|
2005
|
+
line-height: 1.5;
|
|
2006
|
+
box-sizing: border-box;
|
|
2007
|
+
}
|
|
2008
|
+
.adechat-root *,
|
|
2009
|
+
.adechat-root *::before,
|
|
2010
|
+
.adechat-root *::after { box-sizing: inherit; }
|
|
2011
|
+
|
|
2012
|
+
/* Transcript ------------------------------------------------------------- */
|
|
2013
|
+
|
|
2014
|
+
.adechat-transcript {
|
|
2015
|
+
flex: 1 1 auto;
|
|
2016
|
+
min-height: 0;
|
|
2017
|
+
overflow-y: auto;
|
|
2018
|
+
overflow-x: hidden;
|
|
2019
|
+
overscroll-behavior: contain;
|
|
2020
|
+
/* The windowed transcript restores the reader's position itself when older
|
|
2021
|
+
rows load; the browser's own anchoring would apply the shift twice. */
|
|
2022
|
+
overflow-anchor: none;
|
|
2023
|
+
display: flex;
|
|
2024
|
+
flex-direction: column;
|
|
2025
|
+
gap: calc(var(--adechat-space) * 1.5);
|
|
2026
|
+
padding: calc(var(--adechat-space) * 2);
|
|
2027
|
+
}
|
|
2028
|
+
.adechat-row-slot { display: flex; flex-direction: column; min-width: 0; }
|
|
2029
|
+
.adechat-transcript-spacer { flex: 0 0 auto; }
|
|
2030
|
+
.adechat-transcript-older {
|
|
2031
|
+
align-self: center;
|
|
2032
|
+
font: inherit;
|
|
2033
|
+
font-size: 0.85em;
|
|
2034
|
+
color: var(--adechat-muted);
|
|
2035
|
+
background: none;
|
|
2036
|
+
border: 1px solid var(--adechat-border);
|
|
2037
|
+
border-radius: var(--adechat-radius-sm);
|
|
2038
|
+
padding: 2px 10px;
|
|
2039
|
+
cursor: pointer;
|
|
2040
|
+
}
|
|
2041
|
+
.adechat-transcript-older:disabled { cursor: default; opacity: 0.6; }
|
|
2042
|
+
.adechat-transcript-empty {
|
|
2043
|
+
margin: auto;
|
|
2044
|
+
color: var(--adechat-muted);
|
|
2045
|
+
text-align: center;
|
|
2046
|
+
padding: calc(var(--adechat-space) * 3);
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
.adechat-row { display: flex; flex-direction: column; }
|
|
2050
|
+
.adechat-row-user { align-items: flex-end; }
|
|
2051
|
+
|
|
2052
|
+
.adechat-bubble-user {
|
|
2053
|
+
max-width: 82%;
|
|
2054
|
+
padding: calc(var(--adechat-space) * 0.875) calc(var(--adechat-space) * 1.25);
|
|
2055
|
+
border-radius: var(--adechat-radius);
|
|
2056
|
+
background: var(--adechat-accent);
|
|
2057
|
+
color: var(--adechat-accent-fg);
|
|
2058
|
+
white-space: pre-wrap;
|
|
2059
|
+
word-break: break-word;
|
|
2060
|
+
}
|
|
2061
|
+
.adechat-attachments {
|
|
2062
|
+
display: flex;
|
|
2063
|
+
flex-wrap: wrap;
|
|
2064
|
+
gap: calc(var(--adechat-space) * 0.5);
|
|
2065
|
+
margin-top: calc(var(--adechat-space) * 0.5);
|
|
2066
|
+
}
|
|
2067
|
+
.adechat-attachment {
|
|
2068
|
+
font-size: 0.8em;
|
|
2069
|
+
padding: 2px 8px;
|
|
2070
|
+
border-radius: var(--adechat-radius-sm);
|
|
2071
|
+
border: 1px solid var(--adechat-border);
|
|
2072
|
+
color: var(--adechat-muted);
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
.adechat-assistant {
|
|
2076
|
+
max-width: 100%;
|
|
2077
|
+
word-break: break-word;
|
|
2078
|
+
}
|
|
2079
|
+
.adechat-assistant > :first-child { margin-top: 0; }
|
|
2080
|
+
.adechat-assistant > :last-child { margin-bottom: 0; }
|
|
2081
|
+
.adechat-assistant p { margin: 0 0 0.75em; }
|
|
2082
|
+
.adechat-assistant h1,
|
|
2083
|
+
.adechat-assistant h2,
|
|
2084
|
+
.adechat-assistant h3 { margin: 1em 0 0.4em; line-height: 1.25; }
|
|
2085
|
+
.adechat-assistant h1 { font-size: 1.35em; }
|
|
2086
|
+
.adechat-assistant h2 { font-size: 1.2em; }
|
|
2087
|
+
.adechat-assistant h3 { font-size: 1.05em; }
|
|
2088
|
+
.adechat-assistant ul,
|
|
2089
|
+
.adechat-assistant ol { margin: 0 0 0.75em; padding-left: 1.4em; }
|
|
2090
|
+
.adechat-assistant li { margin: 0.15em 0; }
|
|
2091
|
+
.adechat-assistant a { color: var(--adechat-accent); }
|
|
2092
|
+
.adechat-assistant blockquote {
|
|
2093
|
+
margin: 0 0 0.75em;
|
|
2094
|
+
padding-left: calc(var(--adechat-space) * 1.25);
|
|
2095
|
+
border-left: 2px solid var(--adechat-border-strong);
|
|
2096
|
+
color: var(--adechat-muted);
|
|
2097
|
+
}
|
|
2098
|
+
.adechat-assistant hr {
|
|
2099
|
+
border: 0;
|
|
2100
|
+
border-top: 1px solid var(--adechat-border);
|
|
2101
|
+
margin: 1em 0;
|
|
2102
|
+
}
|
|
2103
|
+
.adechat-code-inline {
|
|
2104
|
+
font-family: var(--adechat-font-mono);
|
|
2105
|
+
font-size: 0.9em;
|
|
2106
|
+
padding: 1px 5px;
|
|
2107
|
+
border-radius: var(--adechat-radius-sm);
|
|
2108
|
+
background: var(--adechat-bg-raised);
|
|
2109
|
+
}
|
|
2110
|
+
.adechat-code-block {
|
|
2111
|
+
font-family: var(--adechat-font-mono);
|
|
2112
|
+
font-size: 0.88em;
|
|
2113
|
+
margin: 0 0 0.75em;
|
|
2114
|
+
padding: calc(var(--adechat-space) * 1.25);
|
|
2115
|
+
border-radius: var(--adechat-radius);
|
|
2116
|
+
border: 1px solid var(--adechat-border);
|
|
2117
|
+
background: var(--adechat-bg-subtle);
|
|
2118
|
+
overflow-x: auto;
|
|
2119
|
+
white-space: pre;
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
/* Reasoning -------------------------------------------------------------- */
|
|
2123
|
+
|
|
2124
|
+
.adechat-reasoning { align-self: stretch; }
|
|
2125
|
+
.adechat-reasoning-toggle {
|
|
2126
|
+
display: inline-flex;
|
|
2127
|
+
align-items: center;
|
|
2128
|
+
gap: calc(var(--adechat-space) * 0.5);
|
|
2129
|
+
font: inherit;
|
|
2130
|
+
font-size: 0.88em;
|
|
2131
|
+
color: var(--adechat-muted);
|
|
2132
|
+
background: none;
|
|
2133
|
+
border: 0;
|
|
2134
|
+
padding: 2px 0;
|
|
2135
|
+
cursor: pointer;
|
|
2136
|
+
}
|
|
2137
|
+
.adechat-reasoning-toggle:hover { color: var(--adechat-fg); }
|
|
2138
|
+
.adechat-reasoning-body {
|
|
2139
|
+
margin-top: calc(var(--adechat-space) * 0.75);
|
|
2140
|
+
padding: calc(var(--adechat-space) * 1.25);
|
|
2141
|
+
border-radius: var(--adechat-radius);
|
|
2142
|
+
border: 1px solid var(--adechat-border);
|
|
2143
|
+
background: var(--adechat-bg-subtle);
|
|
2144
|
+
color: var(--adechat-muted);
|
|
2145
|
+
white-space: pre-wrap;
|
|
2146
|
+
font-size: 0.92em;
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
/* Tool chips ------------------------------------------------------------- */
|
|
2150
|
+
|
|
2151
|
+
.adechat-chip {
|
|
2152
|
+
align-self: flex-start;
|
|
2153
|
+
max-width: 100%;
|
|
2154
|
+
border: 1px solid var(--adechat-border);
|
|
2155
|
+
border-radius: var(--adechat-radius);
|
|
2156
|
+
background: var(--adechat-bg-subtle);
|
|
2157
|
+
overflow: hidden;
|
|
2158
|
+
}
|
|
2159
|
+
.adechat-chip-head {
|
|
2160
|
+
display: flex;
|
|
2161
|
+
align-items: center;
|
|
2162
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2163
|
+
width: 100%;
|
|
2164
|
+
font: inherit;
|
|
2165
|
+
font-size: 0.88em;
|
|
2166
|
+
text-align: left;
|
|
2167
|
+
color: var(--adechat-fg);
|
|
2168
|
+
background: none;
|
|
2169
|
+
border: 0;
|
|
2170
|
+
padding: calc(var(--adechat-space) * 0.625) calc(var(--adechat-space) * 1.25);
|
|
2171
|
+
cursor: pointer;
|
|
2172
|
+
}
|
|
2173
|
+
.adechat-chip-head:hover { background: var(--adechat-hover); }
|
|
2174
|
+
.adechat-chip-head[aria-disabled="true"] { cursor: default; }
|
|
2175
|
+
.adechat-chip-head[aria-disabled="true"]:hover { background: none; }
|
|
2176
|
+
.adechat-chip-label {
|
|
2177
|
+
overflow: hidden;
|
|
2178
|
+
text-overflow: ellipsis;
|
|
2179
|
+
white-space: nowrap;
|
|
2180
|
+
}
|
|
2181
|
+
.adechat-chip-elapsed { color: var(--adechat-muted); font-variant-numeric: tabular-nums; }
|
|
2182
|
+
.adechat-chip-icon { display: inline-flex; flex: 0 0 auto; }
|
|
2183
|
+
.adechat-chip-dot {
|
|
2184
|
+
flex: 0 0 auto;
|
|
2185
|
+
width: 6px;
|
|
2186
|
+
height: 6px;
|
|
2187
|
+
border-radius: 50%;
|
|
2188
|
+
background: var(--adechat-muted);
|
|
2189
|
+
}
|
|
2190
|
+
.adechat-chip-dot[data-status="running"] {
|
|
2191
|
+
background: var(--adechat-accent);
|
|
2192
|
+
animation: adechat-pulse 1.4s ease-in-out infinite;
|
|
2193
|
+
}
|
|
2194
|
+
.adechat-chip-dot[data-status="failed"] { background: var(--adechat-danger); }
|
|
2195
|
+
.adechat-chip-dot[data-status="completed"] { background: var(--adechat-success); }
|
|
2196
|
+
.adechat-chip-body {
|
|
2197
|
+
border-top: 1px solid var(--adechat-border);
|
|
2198
|
+
padding: calc(var(--adechat-space) * 1.25);
|
|
2199
|
+
display: flex;
|
|
2200
|
+
flex-direction: column;
|
|
2201
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2202
|
+
}
|
|
2203
|
+
.adechat-chip-section-label {
|
|
2204
|
+
font-size: 0.75em;
|
|
2205
|
+
text-transform: uppercase;
|
|
2206
|
+
letter-spacing: 0.06em;
|
|
2207
|
+
color: var(--adechat-muted);
|
|
2208
|
+
margin-bottom: 4px;
|
|
2209
|
+
}
|
|
2210
|
+
.adechat-chip-actions {
|
|
2211
|
+
display: flex;
|
|
2212
|
+
flex-wrap: wrap;
|
|
2213
|
+
gap: calc(var(--adechat-space) * 0.5);
|
|
2214
|
+
padding: 0 calc(var(--adechat-space) * 1.25) calc(var(--adechat-space) * 0.75);
|
|
2215
|
+
}
|
|
2216
|
+
.adechat-chip-action {
|
|
2217
|
+
font: inherit;
|
|
2218
|
+
font-size: 0.8em;
|
|
2219
|
+
color: var(--adechat-accent);
|
|
2220
|
+
background: var(--adechat-accent-subtle);
|
|
2221
|
+
border: 0;
|
|
2222
|
+
border-radius: var(--adechat-radius-sm);
|
|
2223
|
+
padding: 2px 8px;
|
|
2224
|
+
cursor: pointer;
|
|
2225
|
+
}
|
|
2226
|
+
.adechat-chip-action:hover { filter: brightness(1.1); }
|
|
2227
|
+
.adechat-tool-result { margin-top: calc(var(--adechat-space) * 0.5); }
|
|
2228
|
+
.adechat-chip-pre {
|
|
2229
|
+
font-family: var(--adechat-font-mono);
|
|
2230
|
+
font-size: 0.85em;
|
|
2231
|
+
margin: 0;
|
|
2232
|
+
max-height: 320px;
|
|
2233
|
+
overflow: auto;
|
|
2234
|
+
white-space: pre-wrap;
|
|
2235
|
+
word-break: break-word;
|
|
2236
|
+
color: var(--adechat-muted);
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
/* Errors ----------------------------------------------------------------- */
|
|
2240
|
+
|
|
2241
|
+
.adechat-error {
|
|
2242
|
+
align-self: stretch;
|
|
2243
|
+
border: 1px solid var(--adechat-danger);
|
|
2244
|
+
background: var(--adechat-danger-subtle);
|
|
2245
|
+
border-radius: var(--adechat-radius);
|
|
2246
|
+
padding: calc(var(--adechat-space) * 1.25);
|
|
2247
|
+
}
|
|
2248
|
+
.adechat-error-message { font-weight: 600; }
|
|
2249
|
+
.adechat-error-detail {
|
|
2250
|
+
margin: calc(var(--adechat-space) * 0.5) 0 0;
|
|
2251
|
+
font-family: var(--adechat-font-mono);
|
|
2252
|
+
font-size: 0.85em;
|
|
2253
|
+
white-space: pre-wrap;
|
|
2254
|
+
color: var(--adechat-muted);
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
/* Approvals -------------------------------------------------------------- */
|
|
2258
|
+
|
|
2259
|
+
.adechat-approval {
|
|
2260
|
+
align-self: stretch;
|
|
2261
|
+
display: flex;
|
|
2262
|
+
flex-direction: column;
|
|
2263
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2264
|
+
padding: calc(var(--adechat-space) * 1.25);
|
|
2265
|
+
border: 1px solid var(--adechat-border-strong);
|
|
2266
|
+
border-radius: var(--adechat-radius);
|
|
2267
|
+
background: var(--adechat-bg-subtle);
|
|
2268
|
+
}
|
|
2269
|
+
.adechat-approval[data-state="pending"] { border-color: var(--adechat-accent); }
|
|
2270
|
+
.adechat-approval[data-state="rejected"],
|
|
2271
|
+
.adechat-approval[data-state="cancelled"] { border-color: var(--adechat-border); }
|
|
2272
|
+
.adechat-approval[data-state="expired"] { border-color: var(--adechat-border); opacity: 0.75; }
|
|
2273
|
+
.adechat-approval-head {
|
|
2274
|
+
display: flex;
|
|
2275
|
+
align-items: baseline;
|
|
2276
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2277
|
+
}
|
|
2278
|
+
.adechat-approval-title { font-weight: 600; flex: 1 1 auto; }
|
|
2279
|
+
.adechat-approval-settled { font-size: 0.85em; color: var(--adechat-muted); }
|
|
2280
|
+
.adechat-approval-command {
|
|
2281
|
+
margin: 0;
|
|
2282
|
+
padding: calc(var(--adechat-space) * 0.75) calc(var(--adechat-space) * 1);
|
|
2283
|
+
border-radius: var(--adechat-radius-sm);
|
|
2284
|
+
background: var(--adechat-bg);
|
|
2285
|
+
border: 1px solid var(--adechat-border);
|
|
2286
|
+
font-family: var(--adechat-font-mono);
|
|
2287
|
+
font-size: 0.85em;
|
|
2288
|
+
white-space: pre-wrap;
|
|
2289
|
+
overflow-x: auto;
|
|
2290
|
+
}
|
|
2291
|
+
.adechat-approval-path { margin: 0; font-family: var(--adechat-font-mono); font-size: 0.85em; }
|
|
2292
|
+
.adechat-approval-note { margin: 0; font-size: 0.88em; color: var(--adechat-muted); }
|
|
2293
|
+
.adechat-approval-error { margin: 0; font-size: 0.88em; color: var(--adechat-danger); }
|
|
2294
|
+
.adechat-approval-actions {
|
|
2295
|
+
display: flex;
|
|
2296
|
+
flex-wrap: wrap;
|
|
2297
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2298
|
+
}
|
|
2299
|
+
/* The card never takes focus, so reaching it by keyboard has to be visible. */
|
|
2300
|
+
.adechat-approval-actions .adechat-button:focus-visible {
|
|
2301
|
+
outline: 2px solid var(--adechat-accent);
|
|
2302
|
+
outline-offset: 2px;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
/* Pending input, queue and account surfaces ------------------------------ */
|
|
2306
|
+
.adechat-pending-question {
|
|
2307
|
+
display: flex;
|
|
2308
|
+
flex-direction: column;
|
|
2309
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2310
|
+
min-width: 0;
|
|
2311
|
+
margin: 0;
|
|
2312
|
+
padding: calc(var(--adechat-space) * 0.75);
|
|
2313
|
+
border: 1px solid var(--adechat-border);
|
|
2314
|
+
border-radius: var(--adechat-radius-sm);
|
|
2315
|
+
}
|
|
2316
|
+
.adechat-pending-question legend { padding: 0 calc(var(--adechat-space) * 0.5); font-weight: 600; }
|
|
2317
|
+
.adechat-pending-plan,
|
|
2318
|
+
.adechat-pending-description { margin: 0; white-space: pre-wrap; }
|
|
2319
|
+
.adechat-pending-option { display: flex; align-items: flex-start; gap: calc(var(--adechat-space) * 0.75); }
|
|
2320
|
+
.adechat-pending-option span { display: flex; flex-direction: column; gap: calc(var(--adechat-space) * 0.25); }
|
|
2321
|
+
.adechat-pending-option small { color: var(--adechat-muted); }
|
|
2322
|
+
.adechat-pending-answer,
|
|
2323
|
+
.adechat-queue-edit input,
|
|
2324
|
+
.adechat-api-key-form input,
|
|
2325
|
+
.adechat-sign-in-code-form input {
|
|
2326
|
+
min-width: 0;
|
|
2327
|
+
width: 100%;
|
|
2328
|
+
padding: calc(var(--adechat-space) * 0.75);
|
|
2329
|
+
border: 1px solid var(--adechat-border);
|
|
2330
|
+
border-radius: var(--adechat-radius-sm);
|
|
2331
|
+
background: var(--adechat-bg);
|
|
2332
|
+
color: var(--adechat-fg);
|
|
2333
|
+
font: inherit;
|
|
2334
|
+
}
|
|
2335
|
+
.adechat-pending-answer { min-height: 4.5em; resize: vertical; }
|
|
2336
|
+
.adechat-queue { padding: calc(var(--adechat-space) * 1.25); border-top: 1px solid var(--adechat-border); }
|
|
2337
|
+
.adechat-queue-list { display: flex; flex-direction: column; gap: calc(var(--adechat-space) * 0.75); margin: 0; padding: 0; list-style: none; }
|
|
2338
|
+
.adechat-queue-item { display: flex; align-items: center; gap: calc(var(--adechat-space) * 0.75); min-width: 0; }
|
|
2339
|
+
.adechat-queue-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
|
|
2340
|
+
.adechat-queue-actions,
|
|
2341
|
+
.adechat-queue-edit { display: flex; align-items: center; flex-wrap: wrap; gap: calc(var(--adechat-space) * 0.5); }
|
|
2342
|
+
.adechat-queue-edit { flex: 1 1 auto; }
|
|
2343
|
+
.adechat-queue-state,
|
|
2344
|
+
.adechat-account-state { margin: 0; color: var(--adechat-muted); }
|
|
2345
|
+
.adechat-queue-error,
|
|
2346
|
+
.adechat-account-error,
|
|
2347
|
+
.adechat-usage-limit-error,
|
|
2348
|
+
.adechat-slash-error { display: flex; align-items: center; flex-wrap: wrap; gap: calc(var(--adechat-space) * 0.75); color: var(--adechat-danger); }
|
|
2349
|
+
.adechat-slash-menu { display: flex; flex-direction: column; max-height: 16rem; overflow-y: auto; padding: calc(var(--adechat-space) * 0.5); border: 1px solid var(--adechat-border); border-radius: var(--adechat-radius-sm); background: var(--adechat-bg-raised); }
|
|
2350
|
+
.adechat-slash-option { display: grid; grid-template-columns: auto 1fr; gap: calc(var(--adechat-space) * 0.25) calc(var(--adechat-space) * 0.75); padding: calc(var(--adechat-space) * 0.75); border: 0; border-radius: var(--adechat-radius-sm); background: transparent; color: var(--adechat-fg); text-align: left; font: inherit; cursor: pointer; }
|
|
2351
|
+
.adechat-slash-option[aria-selected="true"],
|
|
2352
|
+
.adechat-slash-option:hover { background: var(--adechat-hover); }
|
|
2353
|
+
.adechat-slash-option small { color: var(--adechat-muted); }
|
|
2354
|
+
.adechat-slash-description { grid-column: 1 / -1; color: var(--adechat-muted); font-size: 0.85em; }
|
|
2355
|
+
.adechat-slash-state { margin: 0; padding: calc(var(--adechat-space) * 0.75); color: var(--adechat-muted); }
|
|
2356
|
+
.adechat-account-list { display: flex; flex-direction: column; gap: calc(var(--adechat-space) * 1); }
|
|
2357
|
+
.adechat-account { display: flex; align-items: center; flex-wrap: wrap; gap: calc(var(--adechat-space) * 1); padding: calc(var(--adechat-space) * 1.25); border: 1px solid var(--adechat-border); border-radius: var(--adechat-radius); background: var(--adechat-bg-subtle); }
|
|
2358
|
+
.adechat-account-summary { display: flex; flex: 1 1 14rem; flex-direction: column; gap: calc(var(--adechat-space) * 0.25); min-width: 0; }
|
|
2359
|
+
.adechat-account-summary span,
|
|
2360
|
+
.adechat-usage-meter-reset { color: var(--adechat-muted); font-size: 0.85em; }
|
|
2361
|
+
.adechat-usage-meter { display: flex; flex: 1 1 10rem; flex-direction: column; gap: calc(var(--adechat-space) * 0.5); }
|
|
2362
|
+
.adechat-usage-meter-label { display: flex; justify-content: space-between; gap: calc(var(--adechat-space) * 1); font-size: 0.85em; }
|
|
2363
|
+
.adechat-usage-meter-track { height: 0.45rem; overflow: hidden; border-radius: 999px; background: var(--adechat-border); }
|
|
2364
|
+
.adechat-usage-meter-track span { display: block; height: 100%; border-radius: inherit; background: var(--adechat-accent); }
|
|
2365
|
+
.adechat-sign-in,
|
|
2366
|
+
.adechat-sign-in-code-form,
|
|
2367
|
+
.adechat-api-key-form { display: flex; flex-direction: column; align-items: flex-start; gap: calc(var(--adechat-space) * 1); }
|
|
2368
|
+
.adechat-sign-in-code-form label,
|
|
2369
|
+
.adechat-api-key-form label { display: flex; flex-direction: column; gap: calc(var(--adechat-space) * 0.5); width: 100%; }
|
|
2370
|
+
.adechat-sign-in-code { overflow-wrap: anywhere; }
|
|
2371
|
+
.adechat-account-switcher { display: inline-flex; align-items: center; gap: calc(var(--adechat-space) * 0.75); }
|
|
2372
|
+
.adechat-account-switcher select { max-width: 100%; padding: calc(var(--adechat-space) * 0.5); border: 1px solid var(--adechat-border); border-radius: var(--adechat-radius-sm); background: var(--adechat-bg); color: var(--adechat-fg); font: inherit; }
|
|
2373
|
+
.adechat-usage-limit { display: flex; align-items: center; flex-wrap: wrap; gap: calc(var(--adechat-space) * 1); padding: calc(var(--adechat-space) * 1.25); border-bottom: 1px solid var(--adechat-border); background: var(--adechat-bg-subtle); }
|
|
2374
|
+
.adechat-usage-limit-copy { display: flex; flex: 1 1 14rem; flex-direction: column; gap: calc(var(--adechat-space) * 0.25); }
|
|
2375
|
+
.adechat-usage-limit-copy span { color: var(--adechat-muted); font-size: 0.9em; }
|
|
2376
|
+
.adechat-usage-limit-actions { display: flex; flex-wrap: wrap; gap: calc(var(--adechat-space) * 0.75); }
|
|
2377
|
+
|
|
2378
|
+
/* Live activity ---------------------------------------------------------- */
|
|
2379
|
+
|
|
2380
|
+
.adechat-activity {
|
|
2381
|
+
display: flex;
|
|
2382
|
+
align-items: center;
|
|
2383
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2384
|
+
color: var(--adechat-muted);
|
|
2385
|
+
font-size: 0.9em;
|
|
2386
|
+
}
|
|
2387
|
+
.adechat-activity-dot {
|
|
2388
|
+
width: 6px;
|
|
2389
|
+
height: 6px;
|
|
2390
|
+
border-radius: 50%;
|
|
2391
|
+
background: var(--adechat-accent);
|
|
2392
|
+
animation: adechat-pulse 1.4s ease-in-out infinite;
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
@keyframes adechat-pulse {
|
|
2396
|
+
0%, 100% { opacity: 1; }
|
|
2397
|
+
50% { opacity: 0.35; }
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
/* Composer --------------------------------------------------------------- */
|
|
2401
|
+
|
|
2402
|
+
.adechat-composer {
|
|
2403
|
+
flex: 0 0 auto;
|
|
2404
|
+
display: flex;
|
|
2405
|
+
flex-direction: column;
|
|
2406
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2407
|
+
padding: calc(var(--adechat-space) * 1.5);
|
|
2408
|
+
border-top: 1px solid var(--adechat-border);
|
|
2409
|
+
background: var(--adechat-root-bg, var(--adechat-bg));
|
|
2410
|
+
}
|
|
2411
|
+
.adechat-composer-surface {
|
|
2412
|
+
display: flex;
|
|
2413
|
+
flex-direction: column;
|
|
2414
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2415
|
+
padding: calc(var(--adechat-space) * 1);
|
|
2416
|
+
border: 1px solid var(--adechat-border);
|
|
2417
|
+
border-radius: var(--adechat-radius);
|
|
2418
|
+
background: var(--adechat-bg-subtle);
|
|
2419
|
+
}
|
|
2420
|
+
.adechat-composer-surface:focus-within { border-color: var(--adechat-border-strong); }
|
|
2421
|
+
.adechat-composer-input {
|
|
2422
|
+
font: inherit;
|
|
2423
|
+
color: var(--adechat-fg);
|
|
2424
|
+
background: none;
|
|
2425
|
+
border: 0;
|
|
2426
|
+
outline: none;
|
|
2427
|
+
resize: none;
|
|
2428
|
+
width: 100%;
|
|
2429
|
+
min-height: 22px;
|
|
2430
|
+
max-height: 40vh;
|
|
2431
|
+
overflow-y: auto;
|
|
2432
|
+
}
|
|
2433
|
+
.adechat-composer-input::placeholder { color: var(--adechat-muted); }
|
|
2434
|
+
.adechat-composer-input:disabled { opacity: 0.6; cursor: not-allowed; }
|
|
2435
|
+
.adechat-composer-actions {
|
|
2436
|
+
display: flex;
|
|
2437
|
+
align-items: center;
|
|
2438
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2439
|
+
}
|
|
2440
|
+
.adechat-composer-rail { display: flex; align-items: center; gap: calc(var(--adechat-space) * 0.5); min-width: 0; }
|
|
2441
|
+
.adechat-composer-spacer { flex: 1 1 auto; }
|
|
2442
|
+
.adechat-composer-hint { color: var(--adechat-muted); font-size: 0.8em; }
|
|
2443
|
+
.adechat-composer-error { color: var(--adechat-danger); font-size: 0.85em; }
|
|
2444
|
+
|
|
2445
|
+
.adechat-button {
|
|
2446
|
+
display: inline-flex;
|
|
2447
|
+
align-items: center;
|
|
2448
|
+
gap: calc(var(--adechat-space) * 0.5);
|
|
2449
|
+
font: inherit;
|
|
2450
|
+
font-size: 0.9em;
|
|
2451
|
+
padding: calc(var(--adechat-space) * 0.625) calc(var(--adechat-space) * 1.25);
|
|
2452
|
+
border-radius: var(--adechat-radius-sm);
|
|
2453
|
+
border: 1px solid var(--adechat-border);
|
|
2454
|
+
background: var(--adechat-bg-raised);
|
|
2455
|
+
color: var(--adechat-fg);
|
|
2456
|
+
cursor: pointer;
|
|
2457
|
+
}
|
|
2458
|
+
.adechat-button:hover:not(:disabled) { background: var(--adechat-hover); }
|
|
2459
|
+
.adechat-button:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
2460
|
+
.adechat-button[data-variant="primary"] {
|
|
2461
|
+
background: var(--adechat-accent);
|
|
2462
|
+
border-color: var(--adechat-accent);
|
|
2463
|
+
color: var(--adechat-accent-fg);
|
|
2464
|
+
}
|
|
2465
|
+
.adechat-button[data-variant="danger"] {
|
|
2466
|
+
background: var(--adechat-danger-subtle);
|
|
2467
|
+
border-color: var(--adechat-danger);
|
|
2468
|
+
color: var(--adechat-danger);
|
|
2469
|
+
}
|
|
2470
|
+
.adechat-button-icon { padding: calc(var(--adechat-space) * 0.625); }
|
|
2471
|
+
|
|
2472
|
+
/* Model picker ----------------------------------------------------------- */
|
|
2473
|
+
|
|
2474
|
+
.adechat-modelpicker {
|
|
2475
|
+
display: flex;
|
|
2476
|
+
min-height: 0;
|
|
2477
|
+
height: 320px;
|
|
2478
|
+
width: 460px;
|
|
2479
|
+
max-width: 100%;
|
|
2480
|
+
border: 1px solid var(--adechat-border);
|
|
2481
|
+
border-radius: var(--adechat-radius);
|
|
2482
|
+
background: var(--adechat-bg-raised);
|
|
2483
|
+
overflow: hidden;
|
|
2484
|
+
}
|
|
2485
|
+
.adechat-modelpicker-rail {
|
|
2486
|
+
display: flex;
|
|
2487
|
+
flex-direction: column;
|
|
2488
|
+
gap: 2px;
|
|
2489
|
+
flex: 0 0 auto;
|
|
2490
|
+
width: 132px;
|
|
2491
|
+
padding: calc(var(--adechat-space) * 0.5);
|
|
2492
|
+
border-right: 1px solid var(--adechat-border);
|
|
2493
|
+
background: var(--adechat-bg-subtle);
|
|
2494
|
+
overflow-y: auto;
|
|
2495
|
+
}
|
|
2496
|
+
.adechat-modelpicker-railbutton {
|
|
2497
|
+
display: flex;
|
|
2498
|
+
align-items: center;
|
|
2499
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2500
|
+
font: inherit;
|
|
2501
|
+
font-size: 0.88em;
|
|
2502
|
+
text-align: left;
|
|
2503
|
+
width: 100%;
|
|
2504
|
+
padding: calc(var(--adechat-space) * 0.625) calc(var(--adechat-space) * 0.875);
|
|
2505
|
+
border: 0;
|
|
2506
|
+
border-radius: var(--adechat-radius-sm);
|
|
2507
|
+
background: none;
|
|
2508
|
+
color: var(--adechat-muted);
|
|
2509
|
+
cursor: pointer;
|
|
2510
|
+
}
|
|
2511
|
+
.adechat-modelpicker-railbutton:hover { background: var(--adechat-hover); color: var(--adechat-fg); }
|
|
2512
|
+
.adechat-modelpicker-railbutton[aria-selected="true"] {
|
|
2513
|
+
background: var(--adechat-accent-subtle);
|
|
2514
|
+
color: var(--adechat-fg);
|
|
2515
|
+
}
|
|
2516
|
+
.adechat-modelpicker-raillabel {
|
|
2517
|
+
flex: 1 1 auto;
|
|
2518
|
+
overflow: hidden;
|
|
2519
|
+
text-overflow: ellipsis;
|
|
2520
|
+
white-space: nowrap;
|
|
2521
|
+
}
|
|
2522
|
+
.adechat-status-dot {
|
|
2523
|
+
flex: 0 0 auto;
|
|
2524
|
+
width: 6px;
|
|
2525
|
+
height: 6px;
|
|
2526
|
+
border-radius: 50%;
|
|
2527
|
+
}
|
|
2528
|
+
.adechat-status-dot[data-status="ok"] { background: var(--adechat-success); }
|
|
2529
|
+
.adechat-status-dot[data-status="unauthed"] { background: var(--adechat-danger); }
|
|
2530
|
+
.adechat-status-dot[data-status="missing"] { background: var(--adechat-muted); }
|
|
2531
|
+
|
|
2532
|
+
.adechat-modelpicker-main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
|
|
2533
|
+
.adechat-modelpicker-search {
|
|
2534
|
+
font: inherit;
|
|
2535
|
+
font-size: 0.9em;
|
|
2536
|
+
color: var(--adechat-fg);
|
|
2537
|
+
background: none;
|
|
2538
|
+
border: 0;
|
|
2539
|
+
border-bottom: 1px solid var(--adechat-border);
|
|
2540
|
+
outline: none;
|
|
2541
|
+
padding: calc(var(--adechat-space) * 1) calc(var(--adechat-space) * 1.25);
|
|
2542
|
+
}
|
|
2543
|
+
.adechat-modelpicker-list {
|
|
2544
|
+
flex: 1 1 auto;
|
|
2545
|
+
min-height: 0;
|
|
2546
|
+
overflow-y: auto;
|
|
2547
|
+
padding: calc(var(--adechat-space) * 0.5);
|
|
2548
|
+
margin: 0;
|
|
2549
|
+
list-style: none;
|
|
2550
|
+
}
|
|
2551
|
+
.adechat-modelpicker-group {
|
|
2552
|
+
font-size: 0.72em;
|
|
2553
|
+
text-transform: uppercase;
|
|
2554
|
+
letter-spacing: 0.07em;
|
|
2555
|
+
color: var(--adechat-muted);
|
|
2556
|
+
padding: calc(var(--adechat-space) * 0.75) calc(var(--adechat-space) * 0.875) 4px;
|
|
2557
|
+
}
|
|
2558
|
+
.adechat-modelpicker-row {
|
|
2559
|
+
display: flex;
|
|
2560
|
+
align-items: baseline;
|
|
2561
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2562
|
+
width: 100%;
|
|
2563
|
+
font: inherit;
|
|
2564
|
+
font-size: 0.9em;
|
|
2565
|
+
text-align: left;
|
|
2566
|
+
padding: calc(var(--adechat-space) * 0.625) calc(var(--adechat-space) * 0.875);
|
|
2567
|
+
border: 0;
|
|
2568
|
+
border-radius: var(--adechat-radius-sm);
|
|
2569
|
+
background: none;
|
|
2570
|
+
color: var(--adechat-fg);
|
|
2571
|
+
cursor: pointer;
|
|
2572
|
+
}
|
|
2573
|
+
.adechat-modelpicker-row:hover:not(:disabled) { background: var(--adechat-hover); }
|
|
2574
|
+
.adechat-modelpicker-row:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
2575
|
+
.adechat-modelpicker-row[aria-selected="true"] { background: var(--adechat-accent-subtle); }
|
|
2576
|
+
.adechat-modelpicker-rowname { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
2577
|
+
.adechat-modelpicker-rowmeta { flex: 1 1 auto; color: var(--adechat-muted); font-size: 0.85em; text-align: right; }
|
|
2578
|
+
.adechat-modelpicker-effort {
|
|
2579
|
+
display: flex;
|
|
2580
|
+
align-items: center;
|
|
2581
|
+
flex-wrap: wrap;
|
|
2582
|
+
gap: calc(var(--adechat-space) * 0.5);
|
|
2583
|
+
padding: calc(var(--adechat-space) * 0.75) calc(var(--adechat-space) * 1);
|
|
2584
|
+
border-top: 1px solid var(--adechat-border);
|
|
2585
|
+
}
|
|
2586
|
+
.adechat-modelpicker-effortlabel { color: var(--adechat-muted); font-size: 0.8em; margin-right: auto; }
|
|
2587
|
+
.adechat-modelpicker-effortoption {
|
|
2588
|
+
font: inherit;
|
|
2589
|
+
font-size: 0.8em;
|
|
2590
|
+
color: var(--adechat-fg);
|
|
2591
|
+
background: none;
|
|
2592
|
+
border: 1px solid var(--adechat-border);
|
|
2593
|
+
border-radius: var(--adechat-radius-sm);
|
|
2594
|
+
padding: 2px 8px;
|
|
2595
|
+
cursor: pointer;
|
|
2596
|
+
}
|
|
2597
|
+
.adechat-modelpicker-effortoption:hover { background: var(--adechat-hover); }
|
|
2598
|
+
.adechat-modelpicker-effortoption[aria-checked="true"] {
|
|
2599
|
+
background: var(--adechat-accent-subtle);
|
|
2600
|
+
border-color: var(--adechat-accent);
|
|
2601
|
+
}
|
|
2602
|
+
.adechat-modelpicker-empty { padding: calc(var(--adechat-space) * 2); color: var(--adechat-muted); font-size: 0.9em; }
|
|
2603
|
+
|
|
2604
|
+
/* Provider card ---------------------------------------------------------- */
|
|
2605
|
+
|
|
2606
|
+
.adechat-providercard {
|
|
2607
|
+
display: flex;
|
|
2608
|
+
flex-direction: column;
|
|
2609
|
+
gap: calc(var(--adechat-space) * 1);
|
|
2610
|
+
padding: calc(var(--adechat-space) * 1.5);
|
|
2611
|
+
border: 1px solid var(--adechat-border);
|
|
2612
|
+
border-radius: var(--adechat-radius);
|
|
2613
|
+
background: var(--adechat-bg-subtle);
|
|
2614
|
+
color: var(--adechat-fg);
|
|
2615
|
+
}
|
|
2616
|
+
.adechat-providercard-head { display: flex; align-items: center; gap: calc(var(--adechat-space) * 0.75); }
|
|
2617
|
+
.adechat-providercard-name { font-weight: 600; flex: 1 1 auto; }
|
|
2618
|
+
.adechat-providercard-state { font-size: 0.85em; color: var(--adechat-muted); }
|
|
2619
|
+
.adechat-providercard-detail { font-size: 0.88em; color: var(--adechat-muted); margin: 0; }
|
|
2620
|
+
.adechat-providercard-probe {
|
|
2621
|
+
display: flex;
|
|
2622
|
+
align-items: baseline;
|
|
2623
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2624
|
+
margin: 0;
|
|
2625
|
+
font-size: 0.82em;
|
|
2626
|
+
color: var(--adechat-muted);
|
|
2627
|
+
min-width: 0;
|
|
2628
|
+
}
|
|
2629
|
+
.adechat-providercard-probe code {
|
|
2630
|
+
font-family: var(--adechat-font-mono);
|
|
2631
|
+
overflow: hidden;
|
|
2632
|
+
text-overflow: ellipsis;
|
|
2633
|
+
white-space: nowrap;
|
|
2634
|
+
}
|
|
2635
|
+
.adechat-command {
|
|
2636
|
+
display: flex;
|
|
2637
|
+
align-items: center;
|
|
2638
|
+
gap: calc(var(--adechat-space) * 0.75);
|
|
2639
|
+
padding: calc(var(--adechat-space) * 0.75) calc(var(--adechat-space) * 1);
|
|
2640
|
+
border: 1px solid var(--adechat-border);
|
|
2641
|
+
border-radius: var(--adechat-radius-sm);
|
|
2642
|
+
background: var(--adechat-bg);
|
|
2643
|
+
}
|
|
2644
|
+
.adechat-command-text {
|
|
2645
|
+
flex: 1 1 auto;
|
|
2646
|
+
font-family: var(--adechat-font-mono);
|
|
2647
|
+
font-size: 0.85em;
|
|
2648
|
+
overflow-x: auto;
|
|
2649
|
+
white-space: nowrap;
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
/* Motion ----------------------------------------------------------------- */
|
|
2653
|
+
|
|
2654
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2655
|
+
.adechat-root *,
|
|
2656
|
+
.adechat-root *::before,
|
|
2657
|
+
.adechat-root *::after {
|
|
2658
|
+
animation-duration: 0.001ms !important;
|
|
2659
|
+
animation-iteration-count: 1 !important;
|
|
2660
|
+
transition-duration: 0.001ms !important;
|
|
2661
|
+
}
|
|
2662
|
+
.adechat-chip-dot[data-status="running"],
|
|
2663
|
+
.adechat-activity-dot { animation: none; opacity: 0.7; }
|
|
2664
|
+
}
|
|
2665
|
+
`;
|
|
2666
|
+
function injectDaexChatStyles(target, options = {}) {
|
|
2667
|
+
const doc = target ?? (typeof document === "undefined" ? null : document);
|
|
2668
|
+
if (!doc) return;
|
|
2669
|
+
if (doc.getElementById(ADE_CHAT_STYLE_ID)) return;
|
|
2670
|
+
const style = doc.createElement("style");
|
|
2671
|
+
style.id = ADE_CHAT_STYLE_ID;
|
|
2672
|
+
if (options.nonce) {
|
|
2673
|
+
style.setAttribute("nonce", options.nonce);
|
|
2674
|
+
style.nonce = options.nonce;
|
|
2675
|
+
}
|
|
2676
|
+
style.textContent = daexChatCss;
|
|
2677
|
+
doc.head.appendChild(style);
|
|
2678
|
+
}
|
|
2679
|
+
var adeChatCss = daexChatCss;
|
|
2680
|
+
var injectAdeChatStyles = injectDaexChatStyles;
|
|
2681
|
+
|
|
2682
|
+
// src/theme/AdeChatStyles.tsx
|
|
2683
|
+
function DaexChatStyles({ nonce } = {}) {
|
|
2684
|
+
react.useEffect(() => {
|
|
2685
|
+
injectDaexChatStyles(void 0, nonce ? { nonce } : {});
|
|
2686
|
+
}, [nonce]);
|
|
2687
|
+
return null;
|
|
2688
|
+
}
|
|
2689
|
+
var AdeChatStyles = DaexChatStyles;
|
|
2690
|
+
|
|
2691
|
+
// src/activity/labels.ts
|
|
2692
|
+
var DEFAULT_ELAPSED_AFTER_MS = 3e3;
|
|
2693
|
+
var DEFAULT_THINKING_LABEL = "Working\u2026";
|
|
2694
|
+
var TIER = 1e6;
|
|
2695
|
+
var QUALIFIED_WILDCARD_BONUS = 1e4;
|
|
2696
|
+
var RENAMED_SERVERS = { "ade-cto": "daex-cto" };
|
|
2697
|
+
function currentServerName(server) {
|
|
2698
|
+
return server === null ? null : RENAMED_SERVERS[server] ?? server;
|
|
2699
|
+
}
|
|
2700
|
+
function scoreLabelKey(key, candidate, identity) {
|
|
2701
|
+
if (key === candidate) return 4 * TIER;
|
|
2702
|
+
const parsed = parseToolIdentity(key);
|
|
2703
|
+
const wildcard = parsed.tool.endsWith("*");
|
|
2704
|
+
const toolPrefix = wildcard ? parsed.tool.slice(0, -1) : parsed.tool;
|
|
2705
|
+
if (parsed.server !== null) {
|
|
2706
|
+
if (currentServerName(identity.server) !== currentServerName(parsed.server)) return -1;
|
|
2707
|
+
if (!wildcard) return parsed.tool === identity.tool ? 3 * TIER : -1;
|
|
2708
|
+
if (!identity.tool.startsWith(toolPrefix)) return -1;
|
|
2709
|
+
return TIER + QUALIFIED_WILDCARD_BONUS + toolPrefix.length;
|
|
2710
|
+
}
|
|
2711
|
+
if (!wildcard) {
|
|
2712
|
+
return identity.server !== null && key === identity.tool ? 2 * TIER : -1;
|
|
2713
|
+
}
|
|
2714
|
+
let best = -1;
|
|
2715
|
+
if (candidate.startsWith(toolPrefix)) best = TIER + toolPrefix.length;
|
|
2716
|
+
if (identity.server !== null && identity.tool.startsWith(toolPrefix)) {
|
|
2717
|
+
best = Math.max(best, TIER + toolPrefix.length);
|
|
2718
|
+
}
|
|
2719
|
+
return best;
|
|
2720
|
+
}
|
|
2721
|
+
function matchLabelKey(keys, candidate, identity = parseToolIdentity(candidate)) {
|
|
2722
|
+
let best = null;
|
|
2723
|
+
let bestScore = -1;
|
|
2724
|
+
for (const key of keys) {
|
|
2725
|
+
const score = scoreLabelKey(key, candidate, identity);
|
|
2726
|
+
if (score < 0) continue;
|
|
2727
|
+
if (score >= 4 * TIER) return key;
|
|
2728
|
+
if (score >= bestScore) {
|
|
2729
|
+
best = key;
|
|
2730
|
+
bestScore = score;
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
return best;
|
|
2734
|
+
}
|
|
2735
|
+
function entryForPhase(entry, phase) {
|
|
2736
|
+
if (typeof entry === "string") {
|
|
2737
|
+
return phase === "running" ? entry : null;
|
|
2738
|
+
}
|
|
2739
|
+
const value = entry[phase];
|
|
2740
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
2741
|
+
}
|
|
2742
|
+
function resolveActivityLabel(source, config) {
|
|
2743
|
+
if (!config) return null;
|
|
2744
|
+
const custom = config.resolve?.(source);
|
|
2745
|
+
if (typeof custom === "string" && custom.length > 0) return custom;
|
|
2746
|
+
if (source.kind === "thinking") {
|
|
2747
|
+
return config.thinkingLabel ?? null;
|
|
2748
|
+
}
|
|
2749
|
+
const key = source.tool;
|
|
2750
|
+
if (!key || !config.map) return null;
|
|
2751
|
+
const identity = source.kind === "tool" ? source.event.identity : void 0;
|
|
2752
|
+
const matched = matchLabelKey(Object.keys(config.map), key, identity);
|
|
2753
|
+
if (!matched) return null;
|
|
2754
|
+
return entryForPhase(config.map[matched], source.phase);
|
|
2755
|
+
}
|
|
2756
|
+
function resolveActivityIcon(tool, config, identity) {
|
|
2757
|
+
if (!tool || !config?.icons) return void 0;
|
|
2758
|
+
const matched = matchLabelKey(Object.keys(config.icons), tool, identity);
|
|
2759
|
+
return matched ? config.icons[matched] : void 0;
|
|
2760
|
+
}
|
|
2761
|
+
function phaseForToolStatus(status) {
|
|
2762
|
+
if (status === "running") return "running";
|
|
2763
|
+
if (status === "failed") return "error";
|
|
2764
|
+
return "done";
|
|
2765
|
+
}
|
|
2766
|
+
function formatElapsed(elapsedMs, elapsedAfterMs = DEFAULT_ELAPSED_AFTER_MS) {
|
|
2767
|
+
if (!Number.isFinite(elapsedMs) || elapsedMs < elapsedAfterMs) return null;
|
|
2768
|
+
const totalSeconds = Math.floor(elapsedMs / 1e3);
|
|
2769
|
+
if (totalSeconds < 60) return `${totalSeconds}s`;
|
|
2770
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
2771
|
+
const seconds = totalSeconds % 60;
|
|
2772
|
+
if (minutes < 60) return seconds === 0 ? `${minutes}m` : `${minutes}m ${seconds}s`;
|
|
2773
|
+
const hours = Math.floor(minutes / 60);
|
|
2774
|
+
return `${hours}h ${minutes % 60}m`;
|
|
2775
|
+
}
|
|
2776
|
+
function describeToolActivity(input) {
|
|
2777
|
+
const { chip, config } = input;
|
|
2778
|
+
const phase = phaseForToolStatus(chip.status);
|
|
2779
|
+
const label = resolveActivityLabel({ kind: "tool", tool: chip.tool, phase, event: chip }, config) ?? chip.tool;
|
|
2780
|
+
const elapsed = phase === "running" && typeof input.elapsedMs === "number" ? formatElapsed(input.elapsedMs, config?.elapsedAfterMs ?? DEFAULT_ELAPSED_AFTER_MS) : null;
|
|
2781
|
+
return { label, elapsed, icon: resolveActivityIcon(chip.tool, config, chip.identity) };
|
|
2782
|
+
}
|
|
2783
|
+
var DEFAULT_LABELS = {
|
|
2784
|
+
accept: "Allow once",
|
|
2785
|
+
acceptAlways: "Always allow",
|
|
2786
|
+
reject: "Reject"
|
|
2787
|
+
};
|
|
2788
|
+
var SETTLED_COPY = {
|
|
2789
|
+
accepted: "Allowed",
|
|
2790
|
+
accepted_always: "Allowed for the rest of this session",
|
|
2791
|
+
rejected: "Rejected",
|
|
2792
|
+
cancelled: "Cancelled",
|
|
2793
|
+
expired: "The turn ended before this was answered."
|
|
2794
|
+
};
|
|
2795
|
+
var UNANSWERABLE_REQUEST_KINDS = /* @__PURE__ */ new Set([
|
|
2796
|
+
"question",
|
|
2797
|
+
"structured_question",
|
|
2798
|
+
"plan_approval",
|
|
2799
|
+
"model_selection"
|
|
2800
|
+
]);
|
|
2801
|
+
var NO_APPROVE_NOTICE = "This host cannot answer approvals.";
|
|
2802
|
+
var UNANSWERABLE_NOTICE = "The assistant is waiting for an answer this UI cannot provide.";
|
|
2803
|
+
function approvalRequestFromRow(row) {
|
|
2804
|
+
const request = {
|
|
2805
|
+
itemId: row.id,
|
|
2806
|
+
kind: row.kind,
|
|
2807
|
+
description: row.description
|
|
2808
|
+
};
|
|
2809
|
+
if (row.requestKind !== void 0) request.requestKind = row.requestKind;
|
|
2810
|
+
if (row.turnId !== null) request.turnId = row.turnId;
|
|
2811
|
+
if (row.detail !== void 0) request.detail = row.detail;
|
|
2812
|
+
return request;
|
|
2813
|
+
}
|
|
2814
|
+
function readText(value) {
|
|
2815
|
+
if (typeof value === "string") return value.trim() ? value : null;
|
|
2816
|
+
if (Array.isArray(value) && value.every((part) => typeof part === "string")) {
|
|
2817
|
+
const joined = value.join(" ").trim();
|
|
2818
|
+
return joined.length ? joined : null;
|
|
2819
|
+
}
|
|
2820
|
+
return null;
|
|
2821
|
+
}
|
|
2822
|
+
function readApprovalCommand(detail) {
|
|
2823
|
+
const record2 = readRecord(detail);
|
|
2824
|
+
if (!record2) return null;
|
|
2825
|
+
return readText(record2.command) ?? readText(readRecord(record2.input)?.command);
|
|
2826
|
+
}
|
|
2827
|
+
function readApprovalPaths(detail) {
|
|
2828
|
+
const record2 = readRecord(detail);
|
|
2829
|
+
if (!record2) return {};
|
|
2830
|
+
const path = readText(record2.path) ?? readText(readRecord(record2.input)?.path);
|
|
2831
|
+
const grantRoot = readText(record2.grantRoot);
|
|
2832
|
+
return {
|
|
2833
|
+
...path ? { path } : {},
|
|
2834
|
+
...grantRoot ? { grantRoot } : {}
|
|
2835
|
+
};
|
|
2836
|
+
}
|
|
2837
|
+
function ApprovalCard({ row, onApprove, options }) {
|
|
2838
|
+
const [submitted, setSubmitted] = react.useState(null);
|
|
2839
|
+
const [failure, setFailure] = react.useState(null);
|
|
2840
|
+
const request = approvalRequestFromRow(row);
|
|
2841
|
+
const unanswerable = row.requestKind !== void 0 && UNANSWERABLE_REQUEST_KINDS.has(row.requestKind);
|
|
2842
|
+
const answerable = Boolean(onApprove) && !unanswerable;
|
|
2843
|
+
const respond = react.useCallback(
|
|
2844
|
+
(decision) => {
|
|
2845
|
+
if (!onApprove) return;
|
|
2846
|
+
setSubmitted(decision);
|
|
2847
|
+
setFailure(null);
|
|
2848
|
+
void (async () => {
|
|
2849
|
+
try {
|
|
2850
|
+
await onApprove(row.id, decision);
|
|
2851
|
+
} catch (cause) {
|
|
2852
|
+
setSubmitted(null);
|
|
2853
|
+
setFailure(cause instanceof Error ? cause.message : String(cause));
|
|
2854
|
+
}
|
|
2855
|
+
})();
|
|
2856
|
+
},
|
|
2857
|
+
[onApprove, row.id]
|
|
2858
|
+
);
|
|
2859
|
+
if (options?.render) {
|
|
2860
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: options.render(request, respond) });
|
|
2861
|
+
}
|
|
2862
|
+
const state = resolveDisplayState(row.state, submitted);
|
|
2863
|
+
const settled = state !== "pending";
|
|
2864
|
+
const command = row.kind === "command" ? readApprovalCommand(row.detail) : null;
|
|
2865
|
+
const paths = row.kind === "file_change" ? readApprovalPaths(row.detail) : {};
|
|
2866
|
+
const title = options?.labels?.title?.(request) ?? row.description;
|
|
2867
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-approval", "data-state": state, "data-kind": row.kind, children: [
|
|
2868
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-approval-head", children: [
|
|
2869
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-approval-title", children: title }),
|
|
2870
|
+
settled ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-approval-settled", children: SETTLED_COPY[state] }) : null
|
|
2871
|
+
] }),
|
|
2872
|
+
command ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "adechat-approval-command", children: command }) : null,
|
|
2873
|
+
paths.path ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-approval-path", children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: paths.path }) }) : null,
|
|
2874
|
+
paths.grantRoot ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "adechat-approval-note", children: [
|
|
2875
|
+
"Inside ",
|
|
2876
|
+
paths.grantRoot
|
|
2877
|
+
] }) : null,
|
|
2878
|
+
unanswerable ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-approval-note", children: UNANSWERABLE_NOTICE }) : null,
|
|
2879
|
+
!unanswerable && !onApprove ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-approval-note", children: NO_APPROVE_NOTICE }) : null,
|
|
2880
|
+
answerable ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-approval-actions", children: [
|
|
2881
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2882
|
+
"button",
|
|
2883
|
+
{
|
|
2884
|
+
type: "button",
|
|
2885
|
+
className: "adechat-button",
|
|
2886
|
+
"data-variant": "primary",
|
|
2887
|
+
disabled: settled,
|
|
2888
|
+
onClick: () => respond("accept"),
|
|
2889
|
+
children: options?.labels?.accept ?? DEFAULT_LABELS.accept
|
|
2890
|
+
}
|
|
2891
|
+
),
|
|
2892
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2893
|
+
"button",
|
|
2894
|
+
{
|
|
2895
|
+
type: "button",
|
|
2896
|
+
className: "adechat-button",
|
|
2897
|
+
disabled: settled,
|
|
2898
|
+
onClick: () => respond("accept_always"),
|
|
2899
|
+
children: options?.labels?.acceptAlways ?? DEFAULT_LABELS.acceptAlways
|
|
2900
|
+
}
|
|
2901
|
+
),
|
|
2902
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2903
|
+
"button",
|
|
2904
|
+
{
|
|
2905
|
+
type: "button",
|
|
2906
|
+
className: "adechat-button",
|
|
2907
|
+
"data-variant": "danger",
|
|
2908
|
+
disabled: settled,
|
|
2909
|
+
onClick: () => respond("reject"),
|
|
2910
|
+
children: options?.labels?.reject ?? DEFAULT_LABELS.reject
|
|
2911
|
+
}
|
|
2912
|
+
)
|
|
2913
|
+
] }) : null,
|
|
2914
|
+
failure ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "adechat-approval-error", role: "alert", children: [
|
|
2915
|
+
"Could not send that answer: ",
|
|
2916
|
+
failure
|
|
2917
|
+
] }) : null
|
|
2918
|
+
] });
|
|
2919
|
+
}
|
|
2920
|
+
function resolveDisplayState(rowState, submitted) {
|
|
2921
|
+
if (rowState === "accepted" && submitted === "accept_always") return "accepted_always";
|
|
2922
|
+
if (rowState !== "pending") return rowState;
|
|
2923
|
+
if (submitted === "accept") return "accepted";
|
|
2924
|
+
if (submitted === "accept_always") return "accepted_always";
|
|
2925
|
+
if (submitted === "reject") return "rejected";
|
|
2926
|
+
return "pending";
|
|
2927
|
+
}
|
|
2928
|
+
function readOptions(value) {
|
|
2929
|
+
if (!Array.isArray(value)) return [];
|
|
2930
|
+
return value.flatMap((entry) => {
|
|
2931
|
+
const option = readRecord(entry);
|
|
2932
|
+
if (typeof option?.label !== "string" || typeof option.value !== "string") return [];
|
|
2933
|
+
return [{ label: option.label, value: option.value, ...typeof option.description === "string" ? { description: option.description } : {} }];
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
function readQuestions(value) {
|
|
2937
|
+
if (!Array.isArray(value)) return [];
|
|
2938
|
+
return value.flatMap((entry) => {
|
|
2939
|
+
const question = readRecord(entry);
|
|
2940
|
+
if (typeof question?.id !== "string" || typeof question.question !== "string") return [];
|
|
2941
|
+
const options = readOptions(question.options);
|
|
2942
|
+
return [{
|
|
2943
|
+
id: question.id,
|
|
2944
|
+
question: question.question,
|
|
2945
|
+
...typeof question.header === "string" ? { header: question.header } : {},
|
|
2946
|
+
...options.length ? { options } : {},
|
|
2947
|
+
...question.multiSelect === true ? { multiSelect: true } : {},
|
|
2948
|
+
...typeof question.allowsFreeform === "boolean" ? { allowsFreeform: question.allowsFreeform } : {},
|
|
2949
|
+
...question.isSecret === true ? { isSecret: true } : {}
|
|
2950
|
+
}];
|
|
2951
|
+
});
|
|
2952
|
+
}
|
|
2953
|
+
function pendingInputFromRow(row) {
|
|
2954
|
+
const detail = readRecord(row.detail);
|
|
2955
|
+
const nested = readRecord(detail?.request) ?? readRecord(detail?.pendingInput) ?? detail;
|
|
2956
|
+
const questions = row.questions ?? readQuestions(nested?.questions);
|
|
2957
|
+
const options = row.options ?? readOptions(nested?.options);
|
|
2958
|
+
return {
|
|
2959
|
+
requestId: row.requestId ?? (typeof nested?.requestId === "string" ? nested.requestId : row.id),
|
|
2960
|
+
title: row.title ?? (typeof nested?.title === "string" ? nested.title : "The assistant needs your input"),
|
|
2961
|
+
description: row.description,
|
|
2962
|
+
questions,
|
|
2963
|
+
options,
|
|
2964
|
+
...row.allowsFreeform !== void 0 ? { allowsFreeform: row.allowsFreeform } : typeof nested?.allowsFreeform === "boolean" ? { allowsFreeform: nested.allowsFreeform } : {},
|
|
2965
|
+
...typeof nested?.canProceedWithoutAnswer === "boolean" ? { canProceedWithoutAnswer: nested.canProceedWithoutAnswer } : {}
|
|
2966
|
+
};
|
|
2967
|
+
}
|
|
2968
|
+
function PendingInputCard({ row, onRespond }) {
|
|
2969
|
+
const request = react.useMemo(() => pendingInputFromRow(row), [row]);
|
|
2970
|
+
const [picks, setPicks] = react.useState({});
|
|
2971
|
+
const [notes, setNotes] = react.useState({});
|
|
2972
|
+
const [submitted, setSubmitted] = react.useState(false);
|
|
2973
|
+
const [busy, setBusy] = react.useState(false);
|
|
2974
|
+
const [failure, setFailure] = react.useState(null);
|
|
2975
|
+
const isPlan = row.requestKind === "plan_approval";
|
|
2976
|
+
const canRespond = Boolean(onRespond) && row.state === "pending" && !busy && !submitted;
|
|
2977
|
+
const hasAnswer = request.questions.length ? request.questions.every((question) => {
|
|
2978
|
+
const selected = picks[question.id] ?? [];
|
|
2979
|
+
return selected.length > 0 || Boolean((notes[question.id] ?? "").trim()) || request.canProceedWithoutAnswer === true;
|
|
2980
|
+
}) : Boolean((notes.response ?? "").trim()) || request.canProceedWithoutAnswer === true;
|
|
2981
|
+
const respond = async (response) => {
|
|
2982
|
+
if (!onRespond || !canRespond) return;
|
|
2983
|
+
setBusy(true);
|
|
2984
|
+
setFailure(null);
|
|
2985
|
+
try {
|
|
2986
|
+
await onRespond(request.requestId, response);
|
|
2987
|
+
setPicks({});
|
|
2988
|
+
setNotes({});
|
|
2989
|
+
setSubmitted(true);
|
|
2990
|
+
} catch (cause) {
|
|
2991
|
+
setFailure(cause instanceof Error ? cause.message : String(cause));
|
|
2992
|
+
} finally {
|
|
2993
|
+
setBusy(false);
|
|
2994
|
+
}
|
|
2995
|
+
};
|
|
2996
|
+
const submitAnswers = () => {
|
|
2997
|
+
const answers = {};
|
|
2998
|
+
if (request.questions.length) {
|
|
2999
|
+
for (const question of request.questions) {
|
|
3000
|
+
const selected = picks[question.id] ?? [];
|
|
3001
|
+
const note = (notes[question.id] ?? "").trim();
|
|
3002
|
+
const values = [...selected, ...note ? [note] : []];
|
|
3003
|
+
if (values.length === 1) answers[question.id] = values[0];
|
|
3004
|
+
else if (values.length > 1) answers[question.id] = values;
|
|
3005
|
+
}
|
|
3006
|
+
} else {
|
|
3007
|
+
const responseText = (notes.response ?? "").trim();
|
|
3008
|
+
if (responseText) {
|
|
3009
|
+
void respond({ responseText });
|
|
3010
|
+
return;
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
void respond({ answers });
|
|
3014
|
+
};
|
|
3015
|
+
const title = isPlan ? "Plan ready for review" : request.title;
|
|
3016
|
+
const settledLabel = row.state === "accepted" ? "Answered" : row.state === "rejected" ? "Declined" : row.state === "cancelled" ? "Cancelled" : row.state === "expired" ? "The turn ended before this was answered." : submitted ? "Answer sent" : null;
|
|
3017
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "adechat-approval adechat-pending-input", "data-state": row.state, children: [
|
|
3018
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-approval-head", children: [
|
|
3019
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { className: "adechat-approval-title", children: title }),
|
|
3020
|
+
settledLabel ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-approval-settled", children: settledLabel }) : null
|
|
3021
|
+
] }),
|
|
3022
|
+
isPlan ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-pending-plan", children: request.description || request.questions[0]?.question || "The assistant has prepared a plan." }) : null,
|
|
3023
|
+
!isPlan && request.questions.length ? request.questions.map((question, index) => {
|
|
3024
|
+
const options = question.options?.length ? question.options : index === 0 ? request.options : [];
|
|
3025
|
+
const allowText = question.allowsFreeform ?? request.allowsFreeform ?? options.length === 0;
|
|
3026
|
+
const answer = notes[question.id] ?? "";
|
|
3027
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: "adechat-pending-question", disabled: !canRespond, children: [
|
|
3028
|
+
/* @__PURE__ */ jsxRuntime.jsxs("legend", { children: [
|
|
3029
|
+
question.header ? /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
3030
|
+
question.header,
|
|
3031
|
+
": "
|
|
3032
|
+
] }) : null,
|
|
3033
|
+
question.question
|
|
3034
|
+
] }),
|
|
3035
|
+
options.map((option) => {
|
|
3036
|
+
const selected = picks[question.id] ?? [];
|
|
3037
|
+
const checked = selected.includes(option.value);
|
|
3038
|
+
const toggle = () => setPicks((current) => {
|
|
3039
|
+
const values = current[question.id] ?? [];
|
|
3040
|
+
const next = question.multiSelect ? checked ? values.filter((value) => value !== option.value) : [...values, option.value] : checked ? [] : [option.value];
|
|
3041
|
+
return { ...current, [question.id]: next };
|
|
3042
|
+
});
|
|
3043
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: "adechat-pending-option", children: [
|
|
3044
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3045
|
+
"input",
|
|
3046
|
+
{
|
|
3047
|
+
type: question.multiSelect ? "checkbox" : "radio",
|
|
3048
|
+
name: `adechat-question-${row.id}-${question.id}`,
|
|
3049
|
+
checked,
|
|
3050
|
+
onChange: toggle,
|
|
3051
|
+
disabled: !canRespond
|
|
3052
|
+
}
|
|
3053
|
+
),
|
|
3054
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
3055
|
+
option.label,
|
|
3056
|
+
option.description ? /* @__PURE__ */ jsxRuntime.jsx("small", { children: option.description }) : null
|
|
3057
|
+
] })
|
|
3058
|
+
] }, option.value);
|
|
3059
|
+
}),
|
|
3060
|
+
allowText ? question.isSecret ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3061
|
+
"input",
|
|
3062
|
+
{
|
|
3063
|
+
className: "adechat-pending-answer",
|
|
3064
|
+
type: "password",
|
|
3065
|
+
autoComplete: "off",
|
|
3066
|
+
"aria-label": `Your answer to ${question.question}`,
|
|
3067
|
+
placeholder: "Enter a private answer\u2026",
|
|
3068
|
+
value: answer,
|
|
3069
|
+
onChange: (event) => setNotes((current) => ({ ...current, [question.id]: event.target.value })),
|
|
3070
|
+
disabled: !canRespond
|
|
3071
|
+
}
|
|
3072
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
3073
|
+
"textarea",
|
|
3074
|
+
{
|
|
3075
|
+
className: "adechat-pending-answer",
|
|
3076
|
+
"aria-label": `Your answer to ${question.question}`,
|
|
3077
|
+
placeholder: "Add a note\u2026",
|
|
3078
|
+
value: answer,
|
|
3079
|
+
onChange: (event) => setNotes((current) => ({ ...current, [question.id]: event.target.value })),
|
|
3080
|
+
disabled: !canRespond
|
|
3081
|
+
}
|
|
3082
|
+
) : null
|
|
3083
|
+
] }, question.id);
|
|
3084
|
+
}) : null,
|
|
3085
|
+
!isPlan && request.questions.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3086
|
+
request.description ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-pending-description", children: request.description }) : null,
|
|
3087
|
+
request.allowsFreeform !== false ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3088
|
+
"textarea",
|
|
3089
|
+
{
|
|
3090
|
+
className: "adechat-pending-answer",
|
|
3091
|
+
"aria-label": "Your answer",
|
|
3092
|
+
placeholder: "Write your answer\u2026",
|
|
3093
|
+
value: notes.response ?? "",
|
|
3094
|
+
onChange: (event) => setNotes((current) => ({ ...current, response: event.target.value })),
|
|
3095
|
+
disabled: !canRespond
|
|
3096
|
+
}
|
|
3097
|
+
) : null
|
|
3098
|
+
] }) : null,
|
|
3099
|
+
!onRespond && row.state === "pending" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-approval-note", children: "This client cannot answer questions or approve plans." }) : null,
|
|
3100
|
+
onRespond && row.state === "pending" ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-approval-actions", children: isPlan ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3101
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { className: "adechat-button", "data-variant": "primary", type: "button", disabled: !canRespond, onClick: () => void respond({ decision: "accept" }), children: "Approve plan" }),
|
|
3102
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { className: "adechat-button", type: "button", disabled: !canRespond, onClick: () => void respond({ decision: "decline" }), children: "Keep planning" })
|
|
3103
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx("button", { className: "adechat-button", "data-variant": "primary", type: "button", disabled: !canRespond || !hasAnswer, onClick: submitAnswers, children: busy ? "Sending\u2026" : "Send answer" }) }) : null,
|
|
3104
|
+
failure ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "adechat-approval-error", role: "alert", children: [
|
|
3105
|
+
"Could not send that answer: ",
|
|
3106
|
+
failure
|
|
3107
|
+
] }) : null
|
|
3108
|
+
] });
|
|
3109
|
+
}
|
|
3110
|
+
var LinkHandlerContext = react.createContext(null);
|
|
3111
|
+
function DaexLinkHandlerProvider({
|
|
3112
|
+
onLinkClick,
|
|
3113
|
+
children
|
|
3114
|
+
}) {
|
|
3115
|
+
const inherited = react.useContext(LinkHandlerContext);
|
|
3116
|
+
return /* @__PURE__ */ jsxRuntime.jsx(LinkHandlerContext.Provider, { value: onLinkClick ?? inherited, children });
|
|
3117
|
+
}
|
|
3118
|
+
function DaexLink({
|
|
3119
|
+
href,
|
|
3120
|
+
source,
|
|
3121
|
+
className,
|
|
3122
|
+
children
|
|
3123
|
+
}) {
|
|
3124
|
+
const onLinkClick = react.useContext(LinkHandlerContext);
|
|
3125
|
+
if (!onLinkClick) {
|
|
3126
|
+
return /* @__PURE__ */ jsxRuntime.jsx("a", { className, href, target: "_blank", rel: "noreferrer noopener", children });
|
|
3127
|
+
}
|
|
3128
|
+
const onClick = (event) => {
|
|
3129
|
+
event.preventDefault();
|
|
3130
|
+
const text = event.currentTarget.textContent ?? href;
|
|
3131
|
+
onLinkClick(href, { source, text });
|
|
3132
|
+
};
|
|
3133
|
+
const onAuxClick = (event) => {
|
|
3134
|
+
if (event.button === 1) onClick(event);
|
|
3135
|
+
};
|
|
3136
|
+
return /* @__PURE__ */ jsxRuntime.jsx("a", { className, href, rel: "noreferrer noopener", onClick, onAuxClick, children });
|
|
3137
|
+
}
|
|
3138
|
+
var AdeLink = DaexLink;
|
|
3139
|
+
var AdeLinkHandlerProvider = DaexLinkHandlerProvider;
|
|
3140
|
+
var FENCE = /^\s*(`{3,}|~{3,})\s*([\w+-]*)\s*$/;
|
|
3141
|
+
var HEADING = /^(#{1,3})\s+(.*)$/;
|
|
3142
|
+
var UNORDERED = /^\s*[-*+]\s+(.*)$/;
|
|
3143
|
+
var ORDERED = /^\s*\d+[.)]\s+(.*)$/;
|
|
3144
|
+
var QUOTE = /^\s*>\s?(.*)$/;
|
|
3145
|
+
var RULE = /^\s*(-{3,}|\*{3,}|_{3,})\s*$/;
|
|
3146
|
+
function parseMarkdownBlocks(source) {
|
|
3147
|
+
const lines = source.replace(/\r\n/g, "\n").split("\n");
|
|
3148
|
+
const blocks = [];
|
|
3149
|
+
let index = 0;
|
|
3150
|
+
while (index < lines.length) {
|
|
3151
|
+
const line = lines[index];
|
|
3152
|
+
const fence = FENCE.exec(line);
|
|
3153
|
+
if (fence) {
|
|
3154
|
+
const marker = fence[1];
|
|
3155
|
+
const language = fence[2] || null;
|
|
3156
|
+
const body = [];
|
|
3157
|
+
index += 1;
|
|
3158
|
+
while (index < lines.length && !lines[index].trimStart().startsWith(marker)) {
|
|
3159
|
+
body.push(lines[index]);
|
|
3160
|
+
index += 1;
|
|
3161
|
+
}
|
|
3162
|
+
if (index < lines.length) index += 1;
|
|
3163
|
+
blocks.push({ kind: "code", language, text: body.join("\n") });
|
|
3164
|
+
continue;
|
|
3165
|
+
}
|
|
3166
|
+
if (!line.trim().length) {
|
|
3167
|
+
index += 1;
|
|
3168
|
+
continue;
|
|
3169
|
+
}
|
|
3170
|
+
if (RULE.test(line)) {
|
|
3171
|
+
blocks.push({ kind: "rule" });
|
|
3172
|
+
index += 1;
|
|
3173
|
+
continue;
|
|
3174
|
+
}
|
|
3175
|
+
const heading = HEADING.exec(line);
|
|
3176
|
+
if (heading) {
|
|
3177
|
+
blocks.push({
|
|
3178
|
+
kind: "heading",
|
|
3179
|
+
level: heading[1].length,
|
|
3180
|
+
text: heading[2].trim()
|
|
3181
|
+
});
|
|
3182
|
+
index += 1;
|
|
3183
|
+
continue;
|
|
3184
|
+
}
|
|
3185
|
+
const listMatch = UNORDERED.exec(line) ?? ORDERED.exec(line);
|
|
3186
|
+
if (listMatch) {
|
|
3187
|
+
const ordered = UNORDERED.exec(line) === null;
|
|
3188
|
+
const items = [];
|
|
3189
|
+
while (index < lines.length) {
|
|
3190
|
+
const candidate = lines[index];
|
|
3191
|
+
const match = ordered ? ORDERED.exec(candidate) : UNORDERED.exec(candidate);
|
|
3192
|
+
if (!match) break;
|
|
3193
|
+
items.push(match[1]);
|
|
3194
|
+
index += 1;
|
|
3195
|
+
}
|
|
3196
|
+
blocks.push({ kind: "list", ordered, items });
|
|
3197
|
+
continue;
|
|
3198
|
+
}
|
|
3199
|
+
if (QUOTE.test(line)) {
|
|
3200
|
+
const body = [];
|
|
3201
|
+
while (index < lines.length) {
|
|
3202
|
+
const match = QUOTE.exec(lines[index]);
|
|
3203
|
+
if (!match) break;
|
|
3204
|
+
body.push(match[1]);
|
|
3205
|
+
index += 1;
|
|
3206
|
+
}
|
|
3207
|
+
blocks.push({ kind: "quote", text: body.join("\n") });
|
|
3208
|
+
continue;
|
|
3209
|
+
}
|
|
3210
|
+
const paragraph = [];
|
|
3211
|
+
while (index < lines.length) {
|
|
3212
|
+
const candidate = lines[index];
|
|
3213
|
+
if (!candidate.trim().length || FENCE.test(candidate) || HEADING.test(candidate) || UNORDERED.test(candidate) || ORDERED.test(candidate) || QUOTE.test(candidate) || RULE.test(candidate)) break;
|
|
3214
|
+
paragraph.push(candidate.trim());
|
|
3215
|
+
index += 1;
|
|
3216
|
+
}
|
|
3217
|
+
blocks.push({ kind: "paragraph", text: paragraph.join("\n") });
|
|
3218
|
+
}
|
|
3219
|
+
return blocks;
|
|
3220
|
+
}
|
|
3221
|
+
var INLINE = /(`+)([^`]*?)\1|\*\*([^*]+)\*\*|__([^_]+)__|\*([^*\n]+)\*|_([^_\n]+)_|\[([^\]]+)\]\(([^)\s]+)\)|(https?:\/\/[^\s<>"')]+)/g;
|
|
3222
|
+
function parseInline(source) {
|
|
3223
|
+
const tokens = [];
|
|
3224
|
+
let lastIndex = 0;
|
|
3225
|
+
INLINE.lastIndex = 0;
|
|
3226
|
+
for (let match = INLINE.exec(source); match; match = INLINE.exec(source)) {
|
|
3227
|
+
if (match.index > lastIndex) {
|
|
3228
|
+
tokens.push({ kind: "text", value: source.slice(lastIndex, match.index) });
|
|
3229
|
+
}
|
|
3230
|
+
if (match[2] !== void 0) tokens.push({ kind: "code", value: match[2] });
|
|
3231
|
+
else if (match[3] !== void 0) tokens.push({ kind: "strong", value: match[3] });
|
|
3232
|
+
else if (match[4] !== void 0) tokens.push({ kind: "strong", value: match[4] });
|
|
3233
|
+
else if (match[5] !== void 0) tokens.push({ kind: "em", value: match[5] });
|
|
3234
|
+
else if (match[6] !== void 0) tokens.push({ kind: "em", value: match[6] });
|
|
3235
|
+
else if (match[7] !== void 0 && match[8] !== void 0) {
|
|
3236
|
+
tokens.push({ kind: "link", value: match[7], href: match[8] });
|
|
3237
|
+
} else if (match[9] !== void 0) {
|
|
3238
|
+
tokens.push({ kind: "link", value: match[9], href: match[9] });
|
|
3239
|
+
}
|
|
3240
|
+
lastIndex = match.index + match[0].length;
|
|
3241
|
+
}
|
|
3242
|
+
if (lastIndex < source.length) tokens.push({ kind: "text", value: source.slice(lastIndex) });
|
|
3243
|
+
return tokens;
|
|
3244
|
+
}
|
|
3245
|
+
var PROTOCOL_RELATIVE = /^[/\\]{2}/;
|
|
3246
|
+
function safeHref(href) {
|
|
3247
|
+
const trimmed = href.trim();
|
|
3248
|
+
if (PROTOCOL_RELATIVE.test(trimmed)) return null;
|
|
3249
|
+
if (/^(https?:|mailto:|tel:|#|\/|\.)/i.test(trimmed)) return trimmed;
|
|
3250
|
+
return null;
|
|
3251
|
+
}
|
|
3252
|
+
function renderInline(source, keyPrefix) {
|
|
3253
|
+
return parseInline(source).map((token, index) => {
|
|
3254
|
+
const key = `${keyPrefix}:${index}`;
|
|
3255
|
+
switch (token.kind) {
|
|
3256
|
+
case "code":
|
|
3257
|
+
return /* @__PURE__ */ jsxRuntime.jsx("code", { className: "adechat-code-inline", children: token.value }, key);
|
|
3258
|
+
case "strong":
|
|
3259
|
+
return /* @__PURE__ */ jsxRuntime.jsx("strong", { children: token.value }, key);
|
|
3260
|
+
case "em":
|
|
3261
|
+
return /* @__PURE__ */ jsxRuntime.jsx("em", { children: token.value }, key);
|
|
3262
|
+
case "link": {
|
|
3263
|
+
const href = safeHref(token.href);
|
|
3264
|
+
if (!href) return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: token.value }, key);
|
|
3265
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DaexLink, { href, source: "markdown", children: token.value }, key);
|
|
3266
|
+
}
|
|
3267
|
+
default:
|
|
3268
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: token.value }, key);
|
|
3269
|
+
}
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
function renderMarkdown(source) {
|
|
3273
|
+
return parseMarkdownBlocks(source).map((block, index) => {
|
|
3274
|
+
const key = `block:${index}`;
|
|
3275
|
+
switch (block.kind) {
|
|
3276
|
+
case "code":
|
|
3277
|
+
return /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "adechat-code-block", "data-language": block.language ?? void 0, children: /* @__PURE__ */ jsxRuntime.jsx("code", { children: block.text }) }, key);
|
|
3278
|
+
case "heading": {
|
|
3279
|
+
const Tag = `h${block.level}`;
|
|
3280
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { children: renderInline(block.text, key) }, key);
|
|
3281
|
+
}
|
|
3282
|
+
case "list": {
|
|
3283
|
+
const Tag = block.ordered ? "ol" : "ul";
|
|
3284
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Tag, { children: block.items.map((item, itemIndex) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: renderInline(item, `${key}:${itemIndex}`) }, `${key}:${itemIndex}`)) }, key);
|
|
3285
|
+
}
|
|
3286
|
+
case "quote":
|
|
3287
|
+
return /* @__PURE__ */ jsxRuntime.jsx("blockquote", { children: renderInline(block.text, key) }, key);
|
|
3288
|
+
case "rule":
|
|
3289
|
+
return /* @__PURE__ */ jsxRuntime.jsx("hr", {}, key);
|
|
3290
|
+
default:
|
|
3291
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { children: renderInline(block.text, key) }, key);
|
|
3292
|
+
}
|
|
3293
|
+
});
|
|
3294
|
+
}
|
|
3295
|
+
function useElapsedMs(startedAt, running) {
|
|
3296
|
+
const [now, setNow] = react.useState(() => Date.now());
|
|
3297
|
+
react.useEffect(() => {
|
|
3298
|
+
if (!running || startedAt === void 0) return;
|
|
3299
|
+
setNow(Date.now());
|
|
3300
|
+
const timer = setInterval(() => setNow(Date.now()), 1e3);
|
|
3301
|
+
return () => clearInterval(timer);
|
|
3302
|
+
}, [running, startedAt]);
|
|
3303
|
+
if (startedAt === void 0 || !running) return void 0;
|
|
3304
|
+
return Math.max(0, now - startedAt);
|
|
3305
|
+
}
|
|
3306
|
+
function ToolChip({ chip, labels, startedAt, expanded, onToggle, actions }) {
|
|
3307
|
+
const [internalExpanded, setInternalExpanded] = react.useState(false);
|
|
3308
|
+
const isExpanded = expanded ?? internalExpanded;
|
|
3309
|
+
const elapsedMs = useElapsedMs(startedAt, chip.status === "running");
|
|
3310
|
+
const { label, elapsed, icon } = describeToolActivity({
|
|
3311
|
+
chip,
|
|
3312
|
+
...labels ? { config: labels } : {},
|
|
3313
|
+
...elapsedMs !== void 0 ? { elapsedMs } : {}
|
|
3314
|
+
});
|
|
3315
|
+
const hasArgs = eventHasPayload(chip.args);
|
|
3316
|
+
const hasResult = eventHasPayload(chip.result);
|
|
3317
|
+
const expandable = hasArgs || hasResult;
|
|
3318
|
+
const toggle = () => {
|
|
3319
|
+
if (!expandable) return;
|
|
3320
|
+
const next = !isExpanded;
|
|
3321
|
+
setInternalExpanded(next);
|
|
3322
|
+
onToggle?.(next);
|
|
3323
|
+
};
|
|
3324
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-chip", "data-status": chip.status, children: [
|
|
3325
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3326
|
+
"button",
|
|
3327
|
+
{
|
|
3328
|
+
type: "button",
|
|
3329
|
+
className: "adechat-chip-head",
|
|
3330
|
+
onClick: toggle,
|
|
3331
|
+
"aria-expanded": expandable ? isExpanded : void 0,
|
|
3332
|
+
"aria-disabled": expandable ? void 0 : "true",
|
|
3333
|
+
children: [
|
|
3334
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-chip-dot", "data-status": chip.status, "aria-hidden": "true" }),
|
|
3335
|
+
icon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-chip-icon", children: icon }) : null,
|
|
3336
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-chip-label", children: label }),
|
|
3337
|
+
elapsed ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-chip-elapsed", children: elapsed }) : null
|
|
3338
|
+
]
|
|
3339
|
+
}
|
|
3340
|
+
),
|
|
3341
|
+
actions?.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-chip-actions", children: actions.map((action) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
3342
|
+
"button",
|
|
3343
|
+
{
|
|
3344
|
+
type: "button",
|
|
3345
|
+
className: "adechat-chip-action",
|
|
3346
|
+
onClick: () => action.onSelect(),
|
|
3347
|
+
children: action.label
|
|
3348
|
+
},
|
|
3349
|
+
action.label
|
|
3350
|
+
)) }) : null,
|
|
3351
|
+
isExpanded && expandable ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-chip-body", children: [
|
|
3352
|
+
hasArgs ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
3353
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-chip-section-label", children: "Arguments" }),
|
|
3354
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "adechat-chip-pre", children: formatStructuredValue(chip.args) })
|
|
3355
|
+
] }) : null,
|
|
3356
|
+
hasResult ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
3357
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-chip-section-label", children: "Result" }),
|
|
3358
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "adechat-chip-pre", children: formatStructuredValue(chip.result) })
|
|
3359
|
+
] }) : null
|
|
3360
|
+
] }) : null
|
|
3361
|
+
] });
|
|
3362
|
+
}
|
|
3363
|
+
var BOTTOM_THRESHOLD_PX = 32;
|
|
3364
|
+
var ESTIMATED_ROW_HEIGHT_PX = 72;
|
|
3365
|
+
function upperBound(values, target) {
|
|
3366
|
+
let low = 0;
|
|
3367
|
+
let high = values.length;
|
|
3368
|
+
while (low < high) {
|
|
3369
|
+
const mid = low + high >>> 1;
|
|
3370
|
+
if (values[mid] <= target) low = mid + 1;
|
|
3371
|
+
else high = mid;
|
|
3372
|
+
}
|
|
3373
|
+
return low;
|
|
3374
|
+
}
|
|
3375
|
+
function useWindowedRows(visible, { threshold, overscan }) {
|
|
3376
|
+
const scrollRef = react.useRef(null);
|
|
3377
|
+
const pinnedRef = react.useRef(true);
|
|
3378
|
+
const [viewport, setViewport] = react.useState({ top: 0, height: 0 });
|
|
3379
|
+
const heightsRef = react.useRef(/* @__PURE__ */ new Map());
|
|
3380
|
+
const [measureVersion, setMeasureVersion] = react.useState(0);
|
|
3381
|
+
const gapRef = react.useRef(0);
|
|
3382
|
+
const frameRef = react.useRef(null);
|
|
3383
|
+
const frameTasksRef = react.useRef(/* @__PURE__ */ new Set());
|
|
3384
|
+
const scheduleFrame = react.useCallback((task) => {
|
|
3385
|
+
frameTasksRef.current.add(task);
|
|
3386
|
+
if (frameRef.current !== null) return;
|
|
3387
|
+
const run = () => {
|
|
3388
|
+
frameRef.current = null;
|
|
3389
|
+
const tasks = [...frameTasksRef.current];
|
|
3390
|
+
frameTasksRef.current.clear();
|
|
3391
|
+
for (const next of tasks) next();
|
|
3392
|
+
};
|
|
3393
|
+
frameRef.current = typeof requestAnimationFrame === "function" ? requestAnimationFrame(run) : setTimeout(run, 16);
|
|
3394
|
+
}, []);
|
|
3395
|
+
const readViewport = react.useCallback(() => {
|
|
3396
|
+
const node = scrollRef.current;
|
|
3397
|
+
if (!node) return;
|
|
3398
|
+
setViewport(
|
|
3399
|
+
(current) => current.top === node.scrollTop && current.height === node.clientHeight ? current : { top: node.scrollTop, height: node.clientHeight }
|
|
3400
|
+
);
|
|
3401
|
+
}, []);
|
|
3402
|
+
const onScroll = react.useCallback(() => {
|
|
3403
|
+
const node = scrollRef.current;
|
|
3404
|
+
if (!node) return;
|
|
3405
|
+
const distance = node.scrollHeight - node.scrollTop - node.clientHeight;
|
|
3406
|
+
pinnedRef.current = distance <= BOTTOM_THRESHOLD_PX;
|
|
3407
|
+
scheduleFrame(readViewport);
|
|
3408
|
+
}, [readViewport, scheduleFrame]);
|
|
3409
|
+
const observer = react.useMemo(() => {
|
|
3410
|
+
if (typeof ResizeObserver === "undefined") return null;
|
|
3411
|
+
return new ResizeObserver((entries) => {
|
|
3412
|
+
let changed = false;
|
|
3413
|
+
for (const entry of entries) {
|
|
3414
|
+
const target = entry.target;
|
|
3415
|
+
if (target === scrollRef.current) {
|
|
3416
|
+
changed = true;
|
|
3417
|
+
continue;
|
|
3418
|
+
}
|
|
3419
|
+
const key = target.dataset.rowKey;
|
|
3420
|
+
if (!key) continue;
|
|
3421
|
+
const height = target.offsetHeight;
|
|
3422
|
+
if (heightsRef.current.get(key) !== height) {
|
|
3423
|
+
heightsRef.current.set(key, height);
|
|
3424
|
+
changed = true;
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
if (changed) {
|
|
3428
|
+
scheduleFrame(() => {
|
|
3429
|
+
readViewport();
|
|
3430
|
+
setMeasureVersion((value) => value + 1);
|
|
3431
|
+
});
|
|
3432
|
+
}
|
|
3433
|
+
});
|
|
3434
|
+
}, [readViewport, scheduleFrame]);
|
|
3435
|
+
react.useEffect(() => {
|
|
3436
|
+
const node = scrollRef.current;
|
|
3437
|
+
if (node) {
|
|
3438
|
+
const gap2 = Number.parseFloat(getComputedStyle(node).rowGap);
|
|
3439
|
+
gapRef.current = Number.isFinite(gap2) ? gap2 : 0;
|
|
3440
|
+
observer?.observe(node);
|
|
3441
|
+
readViewport();
|
|
3442
|
+
}
|
|
3443
|
+
return () => {
|
|
3444
|
+
observer?.disconnect();
|
|
3445
|
+
if (frameRef.current !== null) {
|
|
3446
|
+
if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(frameRef.current);
|
|
3447
|
+
else clearTimeout(frameRef.current);
|
|
3448
|
+
frameRef.current = null;
|
|
3449
|
+
}
|
|
3450
|
+
frameTasksRef.current.clear();
|
|
3451
|
+
};
|
|
3452
|
+
}, [readViewport, observer]);
|
|
3453
|
+
const windowed = observer !== null && viewport.height > 0 && visible.length > threshold;
|
|
3454
|
+
const offsets = react.useMemo(() => {
|
|
3455
|
+
if (!windowed) return null;
|
|
3456
|
+
let measuredTotal = 0;
|
|
3457
|
+
let measuredCount = 0;
|
|
3458
|
+
for (const row of visible) {
|
|
3459
|
+
const height = heightsRef.current.get(row.key);
|
|
3460
|
+
if (height !== void 0) {
|
|
3461
|
+
measuredTotal += height;
|
|
3462
|
+
measuredCount += 1;
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3465
|
+
const estimate = measuredCount ? measuredTotal / measuredCount : ESTIMATED_ROW_HEIGHT_PX;
|
|
3466
|
+
const gap2 = gapRef.current;
|
|
3467
|
+
const result = new Array(visible.length + 1);
|
|
3468
|
+
result[0] = 0;
|
|
3469
|
+
for (let index = 0; index < visible.length; index += 1) {
|
|
3470
|
+
const height = heightsRef.current.get(visible[index].key) ?? estimate;
|
|
3471
|
+
result[index + 1] = result[index] + height + gap2;
|
|
3472
|
+
}
|
|
3473
|
+
return result;
|
|
3474
|
+
}, [windowed, visible, measureVersion]);
|
|
3475
|
+
let start = 0;
|
|
3476
|
+
let end = visible.length - 1;
|
|
3477
|
+
if (offsets) {
|
|
3478
|
+
const total = offsets[visible.length];
|
|
3479
|
+
const top = pinnedRef.current ? Math.max(0, total - viewport.height) : viewport.top;
|
|
3480
|
+
const first = Math.max(0, upperBound(offsets, top) - 1);
|
|
3481
|
+
const last = Math.min(visible.length - 1, upperBound(offsets, top + viewport.height) - 1);
|
|
3482
|
+
start = Math.max(0, first - overscan);
|
|
3483
|
+
end = Math.min(visible.length - 1, last + overscan);
|
|
3484
|
+
}
|
|
3485
|
+
const gap = gapRef.current;
|
|
3486
|
+
const topSpacer = offsets && start > 0 ? Math.max(0, offsets[start] - gap) : 0;
|
|
3487
|
+
const bottomSpacer = offsets && end < visible.length - 1 ? Math.max(0, offsets[visible.length] - offsets[end + 1] - gap) : 0;
|
|
3488
|
+
const rendered = offsets ? visible.slice(start, end + 1) : visible;
|
|
3489
|
+
return { rendered, topSpacer, bottomSpacer, scrollRef, pinnedRef, onScroll, observer, offsets };
|
|
3490
|
+
}
|
|
3491
|
+
function RowSlot({
|
|
3492
|
+
rowKey,
|
|
3493
|
+
observer,
|
|
3494
|
+
children
|
|
3495
|
+
}) {
|
|
3496
|
+
const ref = react.useRef(null);
|
|
3497
|
+
react.useLayoutEffect(() => {
|
|
3498
|
+
const node = ref.current;
|
|
3499
|
+
if (!node || !observer) return;
|
|
3500
|
+
observer.observe(node);
|
|
3501
|
+
return () => observer.unobserve(node);
|
|
3502
|
+
}, [observer]);
|
|
3503
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: "adechat-row-slot", "data-row-key": rowKey, children });
|
|
3504
|
+
}
|
|
3505
|
+
var TOP_LOAD_THRESHOLD_PX = 48;
|
|
3506
|
+
var DEFAULT_WINDOW_THRESHOLD = 150;
|
|
3507
|
+
var DEFAULT_OVERSCAN = 8;
|
|
3508
|
+
var DEFAULT_APPROVAL_WAITING_LABEL = "Waiting for your approval\u2026";
|
|
3509
|
+
function Transcript({
|
|
3510
|
+
rows,
|
|
3511
|
+
status = "idle",
|
|
3512
|
+
labels,
|
|
3513
|
+
hideToolCalls = false,
|
|
3514
|
+
hideReasoning = false,
|
|
3515
|
+
expandReasoning = false,
|
|
3516
|
+
renderMarkdown: renderMarkdown2 = renderMarkdown,
|
|
3517
|
+
onLinkClick,
|
|
3518
|
+
onApprove,
|
|
3519
|
+
onRespond,
|
|
3520
|
+
approvals,
|
|
3521
|
+
renderToolResult,
|
|
3522
|
+
toolChipActions,
|
|
3523
|
+
hasOlder = false,
|
|
3524
|
+
loadingOlder = false,
|
|
3525
|
+
onLoadOlder,
|
|
3526
|
+
windowThreshold = DEFAULT_WINDOW_THRESHOLD,
|
|
3527
|
+
overscan = DEFAULT_OVERSCAN,
|
|
3528
|
+
emptyState,
|
|
3529
|
+
className
|
|
3530
|
+
}) {
|
|
3531
|
+
const visible = react.useMemo(
|
|
3532
|
+
() => rows.filter((row) => {
|
|
3533
|
+
if (hideToolCalls && row.event.type === "tool_chip") return false;
|
|
3534
|
+
if (hideReasoning && row.event.type === "reasoning") return false;
|
|
3535
|
+
return row.event.type !== "status";
|
|
3536
|
+
}),
|
|
3537
|
+
[rows, hideToolCalls, hideReasoning]
|
|
3538
|
+
);
|
|
3539
|
+
const {
|
|
3540
|
+
rendered,
|
|
3541
|
+
topSpacer,
|
|
3542
|
+
bottomSpacer,
|
|
3543
|
+
scrollRef,
|
|
3544
|
+
pinnedRef,
|
|
3545
|
+
onScroll: onWindowScroll,
|
|
3546
|
+
observer,
|
|
3547
|
+
offsets
|
|
3548
|
+
} = useWindowedRows(visible, { threshold: windowThreshold, overscan });
|
|
3549
|
+
const loadOlderRef = react.useRef({
|
|
3550
|
+
hasOlder,
|
|
3551
|
+
loadingOlder
|
|
3552
|
+
});
|
|
3553
|
+
loadOlderRef.current = onLoadOlder ? { hasOlder, loadingOlder, onLoadOlder } : { hasOlder, loadingOlder };
|
|
3554
|
+
const handleScroll = react.useCallback(() => {
|
|
3555
|
+
const node = scrollRef.current;
|
|
3556
|
+
if (!node) return;
|
|
3557
|
+
onWindowScroll();
|
|
3558
|
+
const older = loadOlderRef.current;
|
|
3559
|
+
if (node.scrollTop <= TOP_LOAD_THRESHOLD_PX && older.hasOlder && !older.loadingOlder && older.onLoadOlder && node.scrollHeight > node.clientHeight) {
|
|
3560
|
+
void older.onLoadOlder();
|
|
3561
|
+
}
|
|
3562
|
+
}, [onWindowScroll, scrollRef]);
|
|
3563
|
+
const firstKeyRef = react.useRef(null);
|
|
3564
|
+
const scrollHeightRef = react.useRef(0);
|
|
3565
|
+
react.useLayoutEffect(() => {
|
|
3566
|
+
const node = scrollRef.current;
|
|
3567
|
+
if (!node) return;
|
|
3568
|
+
const firstKey = visible[0]?.key ?? null;
|
|
3569
|
+
const prepended = firstKeyRef.current !== null && firstKey !== firstKeyRef.current && visible.some((row, index) => index > 0 && row.key === firstKeyRef.current);
|
|
3570
|
+
if (pinnedRef.current) {
|
|
3571
|
+
node.scrollTop = node.scrollHeight;
|
|
3572
|
+
} else if (prepended) {
|
|
3573
|
+
node.scrollTop += node.scrollHeight - scrollHeightRef.current;
|
|
3574
|
+
}
|
|
3575
|
+
firstKeyRef.current = firstKey;
|
|
3576
|
+
scrollHeightRef.current = node.scrollHeight;
|
|
3577
|
+
}, [visible, status, offsets, pinnedRef, scrollRef]);
|
|
3578
|
+
const tail = visible[visible.length - 1];
|
|
3579
|
+
const awaitingApproval = tail?.event.type === "approval" && tail.event.state === "pending";
|
|
3580
|
+
const showActivity = awaitingApproval || status === "running" && (visible.length === 0 || tail.event.type !== "tool_chip");
|
|
3581
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DaexLinkHandlerProvider, { onLinkClick, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3582
|
+
"div",
|
|
3583
|
+
{
|
|
3584
|
+
ref: scrollRef,
|
|
3585
|
+
className: ["adechat-transcript", className].filter(Boolean).join(" "),
|
|
3586
|
+
onScroll: handleScroll,
|
|
3587
|
+
role: "log",
|
|
3588
|
+
"aria-live": "polite",
|
|
3589
|
+
"aria-relevant": "additions text",
|
|
3590
|
+
children: [
|
|
3591
|
+
hasOlder && onLoadOlder ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3592
|
+
"button",
|
|
3593
|
+
{
|
|
3594
|
+
type: "button",
|
|
3595
|
+
className: "adechat-transcript-older",
|
|
3596
|
+
onClick: () => void onLoadOlder(),
|
|
3597
|
+
disabled: loadingOlder,
|
|
3598
|
+
children: loadingOlder ? "Loading older messages\u2026" : "Load older messages"
|
|
3599
|
+
}
|
|
3600
|
+
) : null,
|
|
3601
|
+
visible.length === 0 && !showActivity ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-transcript-empty", children: emptyState ?? "No messages yet." }) : null,
|
|
3602
|
+
topSpacer > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-transcript-spacer", style: { height: topSpacer }, "aria-hidden": "true" }) : null,
|
|
3603
|
+
rendered.map((row) => /* @__PURE__ */ jsxRuntime.jsx(RowSlot, { rowKey: row.key, observer, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3604
|
+
TranscriptRowView,
|
|
3605
|
+
{
|
|
3606
|
+
row,
|
|
3607
|
+
...labels ? { labels } : {},
|
|
3608
|
+
expandReasoning,
|
|
3609
|
+
renderMarkdown: renderMarkdown2,
|
|
3610
|
+
...onApprove ? { onApprove } : {},
|
|
3611
|
+
...onRespond ? { onRespond } : {},
|
|
3612
|
+
...approvals ? { approvals } : {},
|
|
3613
|
+
...renderToolResult ? { renderToolResult } : {},
|
|
3614
|
+
...toolChipActions ? { toolChipActions } : {}
|
|
3615
|
+
}
|
|
3616
|
+
) }, row.key)),
|
|
3617
|
+
bottomSpacer > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-transcript-spacer", style: { height: bottomSpacer }, "aria-hidden": "true" }) : null,
|
|
3618
|
+
showActivity ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
3619
|
+
ActivityIndicator,
|
|
3620
|
+
{
|
|
3621
|
+
labels,
|
|
3622
|
+
...awaitingApproval ? { label: DEFAULT_APPROVAL_WAITING_LABEL } : {}
|
|
3623
|
+
}
|
|
3624
|
+
) : null
|
|
3625
|
+
]
|
|
3626
|
+
}
|
|
3627
|
+
) });
|
|
3628
|
+
}
|
|
3629
|
+
var TranscriptRowView = react.memo(function TranscriptRowView2({
|
|
3630
|
+
row,
|
|
3631
|
+
labels,
|
|
3632
|
+
expandReasoning,
|
|
3633
|
+
renderMarkdown: renderMarkdown2,
|
|
3634
|
+
onApprove,
|
|
3635
|
+
onRespond,
|
|
3636
|
+
approvals,
|
|
3637
|
+
renderToolResult,
|
|
3638
|
+
toolChipActions
|
|
3639
|
+
}) {
|
|
3640
|
+
const event = row.event;
|
|
3641
|
+
if (event.type === "approval") {
|
|
3642
|
+
if (event.requestKind === "question" || event.requestKind === "structured_question" || event.requestKind === "plan_approval") {
|
|
3643
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-row", children: /* @__PURE__ */ jsxRuntime.jsx(PendingInputCard, { row: event, ...onRespond ? { onRespond } : {} }) });
|
|
3644
|
+
}
|
|
3645
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-row", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3646
|
+
ApprovalCard,
|
|
3647
|
+
{
|
|
3648
|
+
row: event,
|
|
3649
|
+
...onApprove ? { onApprove } : {},
|
|
3650
|
+
...approvals ? { options: approvals } : {}
|
|
3651
|
+
}
|
|
3652
|
+
) });
|
|
3653
|
+
}
|
|
3654
|
+
if (event.type === "user_message") {
|
|
3655
|
+
const text = event.displayText ?? event.text;
|
|
3656
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-row adechat-row-user", children: [
|
|
3657
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-bubble-user", children: text }),
|
|
3658
|
+
event.attachments?.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-attachments", children: event.attachments.map((attachment) => /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-attachment", children: attachment.name }, attachment.id)) }) : null
|
|
3659
|
+
] });
|
|
3660
|
+
}
|
|
3661
|
+
if (event.type === "text") {
|
|
3662
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-row", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-assistant", children: renderMarkdown2(event.text) }) });
|
|
3663
|
+
}
|
|
3664
|
+
if (event.type === "reasoning") {
|
|
3665
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ReasoningRow, { text: event.text, defaultExpanded: expandReasoning });
|
|
3666
|
+
}
|
|
3667
|
+
if (event.type === "tool_chip") {
|
|
3668
|
+
const actions = toolChipActions?.(event);
|
|
3669
|
+
const extra = renderToolResult?.(event);
|
|
3670
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-row", children: [
|
|
3671
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3672
|
+
ToolChip,
|
|
3673
|
+
{
|
|
3674
|
+
chip: event,
|
|
3675
|
+
...labels ? { labels } : {},
|
|
3676
|
+
...actions?.length ? { actions } : {},
|
|
3677
|
+
startedAt: Date.parse(row.timestamp) || void 0
|
|
3678
|
+
}
|
|
3679
|
+
),
|
|
3680
|
+
extra !== void 0 && extra !== null && extra !== false ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-tool-result", children: extra }) : null
|
|
3681
|
+
] });
|
|
3682
|
+
}
|
|
3683
|
+
if (event.type === "error") {
|
|
3684
|
+
const label = resolveActivityLabel({ kind: "error", tool: null, phase: "error", event }, labels) ?? event.message;
|
|
3685
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-row", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-error", role: "alert", children: [
|
|
3686
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-error-message", children: label }),
|
|
3687
|
+
event.detail ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "adechat-error-detail", children: event.detail }) : null
|
|
3688
|
+
] }) });
|
|
3689
|
+
}
|
|
3690
|
+
return null;
|
|
3691
|
+
});
|
|
3692
|
+
function ReasoningRow({ text, defaultExpanded }) {
|
|
3693
|
+
const [expanded, setExpanded] = react.useState(defaultExpanded);
|
|
3694
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-row adechat-reasoning", children: [
|
|
3695
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3696
|
+
"button",
|
|
3697
|
+
{
|
|
3698
|
+
type: "button",
|
|
3699
|
+
className: "adechat-reasoning-toggle",
|
|
3700
|
+
onClick: () => setExpanded((value) => !value),
|
|
3701
|
+
"aria-expanded": expanded,
|
|
3702
|
+
children: expanded ? "Hide reasoning" : "Show reasoning"
|
|
3703
|
+
}
|
|
3704
|
+
),
|
|
3705
|
+
expanded ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "adechat-reasoning-body", children: text }) : null
|
|
3706
|
+
] });
|
|
3707
|
+
}
|
|
3708
|
+
function ActivityIndicator({
|
|
3709
|
+
labels,
|
|
3710
|
+
label: labelOverride
|
|
3711
|
+
}) {
|
|
3712
|
+
const [dots, setDots] = react.useState(0);
|
|
3713
|
+
const reducedMotion = usePrefersReducedMotion();
|
|
3714
|
+
react.useEffect(() => {
|
|
3715
|
+
if (reducedMotion) return;
|
|
3716
|
+
const timer = setInterval(() => setDots((value) => (value + 1) % 4), 450);
|
|
3717
|
+
return () => clearInterval(timer);
|
|
3718
|
+
}, [reducedMotion]);
|
|
3719
|
+
const label = labelOverride ?? resolveActivityLabel({ kind: "thinking", tool: null, phase: "running", event: null }, labels) ?? DEFAULT_THINKING_LABEL;
|
|
3720
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-activity", role: "status", children: [
|
|
3721
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-activity-dot", "aria-hidden": "true" }),
|
|
3722
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
3723
|
+
label,
|
|
3724
|
+
reducedMotion ? "" : ".".repeat(dots)
|
|
3725
|
+
] })
|
|
3726
|
+
] });
|
|
3727
|
+
}
|
|
3728
|
+
function usePrefersReducedMotion() {
|
|
3729
|
+
const [reduced, setReduced] = react.useState(false);
|
|
3730
|
+
react.useEffect(() => {
|
|
3731
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
|
3732
|
+
const query = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
3733
|
+
setReduced(query.matches);
|
|
3734
|
+
const onChange = (event) => setReduced(event.matches);
|
|
3735
|
+
if (typeof query.addEventListener === "function") {
|
|
3736
|
+
query.addEventListener("change", onChange);
|
|
3737
|
+
return () => query.removeEventListener("change", onChange);
|
|
3738
|
+
}
|
|
3739
|
+
query.addListener(onChange);
|
|
3740
|
+
return () => query.removeListener(onChange);
|
|
3741
|
+
}, []);
|
|
3742
|
+
return reduced;
|
|
3743
|
+
}
|
|
3744
|
+
function UsageLimitNotice({ status, onResumeNow, onContinueOnAlternate }) {
|
|
3745
|
+
const [busy, setBusy] = react.useState(false);
|
|
3746
|
+
const [error, setError] = react.useState(null);
|
|
3747
|
+
if (!status) return null;
|
|
3748
|
+
const alternate = status.alternateAccount ?? (status.alternateAccounts?.[0] ? {
|
|
3749
|
+
instanceId: status.alternateAccounts[0].id,
|
|
3750
|
+
label: status.alternateAccounts[0].label
|
|
3751
|
+
} : null);
|
|
3752
|
+
const resumeLabel = status.state === "resuming" ? "Resume scheduled" : "Resume now";
|
|
3753
|
+
const run = async (action) => {
|
|
3754
|
+
if (!action || busy) return;
|
|
3755
|
+
setBusy(true);
|
|
3756
|
+
setError(null);
|
|
3757
|
+
try {
|
|
3758
|
+
await action();
|
|
3759
|
+
} catch (cause) {
|
|
3760
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
3761
|
+
} finally {
|
|
3762
|
+
setBusy(false);
|
|
3763
|
+
}
|
|
3764
|
+
};
|
|
3765
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("aside", { className: "adechat-usage-limit", role: "status", "aria-live": "polite", children: [
|
|
3766
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-usage-limit-copy", children: [
|
|
3767
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: "Usage limit reached" }),
|
|
3768
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: status.resetAt ? `Resets ${new Date(status.resetAt).toLocaleString()}` : "This conversation is waiting for usage room." })
|
|
3769
|
+
] }),
|
|
3770
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-usage-limit-actions", children: [
|
|
3771
|
+
onResumeNow ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", disabled: busy, onClick: () => void run(onResumeNow), children: busy ? "Working\u2026" : resumeLabel }) : null,
|
|
3772
|
+
alternate && onContinueOnAlternate ? /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "adechat-button", "data-variant": "primary", disabled: busy, onClick: () => void run(onContinueOnAlternate), children: [
|
|
3773
|
+
"Continue on ",
|
|
3774
|
+
alternate.label
|
|
3775
|
+
] }) : null
|
|
3776
|
+
] }),
|
|
3777
|
+
error ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "adechat-usage-limit-error", role: "alert", children: [
|
|
3778
|
+
"Could not continue: ",
|
|
3779
|
+
error
|
|
3780
|
+
] }) : null
|
|
3781
|
+
] });
|
|
3782
|
+
}
|
|
3783
|
+
|
|
3784
|
+
// src/actionResult.ts
|
|
3785
|
+
async function requireAccepted(result) {
|
|
3786
|
+
const value = await result;
|
|
3787
|
+
if (value && typeof value === "object" && value.ok === false) {
|
|
3788
|
+
const message = value.message;
|
|
3789
|
+
throw new Error(typeof message === "string" && message ? message : "The runtime refused this action.");
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
var useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
3793
|
+
function DaexChat(props) {
|
|
3794
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DaexChatProvider, { client: props.client, ...props.labels ? { labels: props.labels } : {}, children: /* @__PURE__ */ jsxRuntime.jsx(AdeChatInner, { ...props }) });
|
|
3795
|
+
}
|
|
3796
|
+
function AdeChatInner({
|
|
3797
|
+
client,
|
|
3798
|
+
threadKey,
|
|
3799
|
+
defaultModelId,
|
|
3800
|
+
modelId,
|
|
3801
|
+
onModelChange,
|
|
3802
|
+
labels,
|
|
3803
|
+
theme,
|
|
3804
|
+
disableStyles = false,
|
|
3805
|
+
placeholder,
|
|
3806
|
+
sendOnEnter,
|
|
3807
|
+
value,
|
|
3808
|
+
onValueChange,
|
|
3809
|
+
onSend,
|
|
3810
|
+
children,
|
|
3811
|
+
threadRef,
|
|
3812
|
+
onRequestAttachment,
|
|
3813
|
+
attachments,
|
|
3814
|
+
onAttachmentsChange,
|
|
3815
|
+
modelRail,
|
|
3816
|
+
actions,
|
|
3817
|
+
reasoningEffort,
|
|
3818
|
+
onReasoningEffortChange,
|
|
3819
|
+
hideToolCalls,
|
|
3820
|
+
hideReasoning,
|
|
3821
|
+
renderMarkdown: renderMarkdown2,
|
|
3822
|
+
onLinkClick,
|
|
3823
|
+
approvals,
|
|
3824
|
+
renderToolResult,
|
|
3825
|
+
toolChipActions,
|
|
3826
|
+
historyPageSize,
|
|
3827
|
+
styleNonce,
|
|
3828
|
+
emptyState,
|
|
3829
|
+
hideModelPicker = false,
|
|
3830
|
+
className
|
|
3831
|
+
}) {
|
|
3832
|
+
const [internalModelId, setInternalModelId] = react.useState(defaultModelId ?? null);
|
|
3833
|
+
const [pickerOpen, setPickerOpen] = react.useState(false);
|
|
3834
|
+
const [selectedLabel, setSelectedLabel] = react.useState(null);
|
|
3835
|
+
const { models, statuses, loading: catalogLoading } = useDaexProviders(client);
|
|
3836
|
+
const fallbackModel = react.useMemo(
|
|
3837
|
+
() => models.find(
|
|
3838
|
+
(model) => isModelSelectable(model, statuses.find((status) => status.id === model.providerId))
|
|
3839
|
+
) ?? null,
|
|
3840
|
+
[models, statuses]
|
|
3841
|
+
);
|
|
3842
|
+
const activeModelId = modelId ?? internalModelId ?? fallbackModel?.id ?? null;
|
|
3843
|
+
const activeModel = react.useMemo(
|
|
3844
|
+
() => models.find((model) => model.id === activeModelId) ?? null,
|
|
3845
|
+
[models, activeModelId]
|
|
3846
|
+
);
|
|
3847
|
+
const thread = useDaexThread(threadKey, {
|
|
3848
|
+
client,
|
|
3849
|
+
enabled: Boolean(activeModelId) || !catalogLoading,
|
|
3850
|
+
...activeModelId ? { modelId: activeModelId } : {},
|
|
3851
|
+
...historyPageSize !== void 0 ? { historyPageSize } : {}
|
|
3852
|
+
});
|
|
3853
|
+
const [usageLimitEvent, setUsageLimitEvent] = react.useState(null);
|
|
3854
|
+
const usageLimit = usageLimitEvent?.key === threadKey ? usageLimitEvent.status : null;
|
|
3855
|
+
const [queueRefreshKey, setQueueRefreshKey] = react.useState(0);
|
|
3856
|
+
react.useEffect(() => {
|
|
3857
|
+
setUsageLimitEvent(null);
|
|
3858
|
+
if (!thread.thread?.usageLimit || typeof client.on !== "function") return;
|
|
3859
|
+
try {
|
|
3860
|
+
return client.on("usageLimit", (event) => {
|
|
3861
|
+
if (event.key !== threadKey) return;
|
|
3862
|
+
setUsageLimitEvent(event);
|
|
3863
|
+
});
|
|
3864
|
+
} catch {
|
|
3865
|
+
return;
|
|
3866
|
+
}
|
|
3867
|
+
}, [client, threadKey, thread.thread?.usageLimit]);
|
|
3868
|
+
const threadStateRef = react.useRef(thread);
|
|
3869
|
+
threadStateRef.current = thread;
|
|
3870
|
+
useIsomorphicLayoutEffect(() => {
|
|
3871
|
+
if (threadRef) threadRef.current = thread;
|
|
3872
|
+
});
|
|
3873
|
+
react.useEffect(() => {
|
|
3874
|
+
if (!threadRef) return;
|
|
3875
|
+
return () => {
|
|
3876
|
+
threadRef.current = null;
|
|
3877
|
+
};
|
|
3878
|
+
}, [threadRef]);
|
|
3879
|
+
const style = react.useMemo(
|
|
3880
|
+
() => theme ? { ...theme } : void 0,
|
|
3881
|
+
[theme]
|
|
3882
|
+
);
|
|
3883
|
+
const { setModel, canSetModel, ready: threadReady, status: threadStatus } = thread;
|
|
3884
|
+
const turnRunning = threadStatus.state === "running";
|
|
3885
|
+
const [modelError, setModelError] = react.useState(null);
|
|
3886
|
+
react.useEffect(() => {
|
|
3887
|
+
if (!threadReady || !activeModelId || !canSetModel || turnRunning) return;
|
|
3888
|
+
let cancelled = false;
|
|
3889
|
+
setModel(activeModelId).then(() => {
|
|
3890
|
+
if (!cancelled) setModelError(null);
|
|
3891
|
+
}).catch((cause) => {
|
|
3892
|
+
if (cancelled) return;
|
|
3893
|
+
setModelError(cause instanceof Error ? cause : new Error(String(cause)));
|
|
3894
|
+
});
|
|
3895
|
+
return () => {
|
|
3896
|
+
cancelled = true;
|
|
3897
|
+
};
|
|
3898
|
+
}, [threadReady, activeModelId, canSetModel, setModel, turnRunning]);
|
|
3899
|
+
const pickerRef = react.useRef(null);
|
|
3900
|
+
react.useEffect(() => {
|
|
3901
|
+
if (!pickerOpen) return;
|
|
3902
|
+
const onPointerDown = (event) => {
|
|
3903
|
+
if (!pickerRef.current?.contains(event.target)) setPickerOpen(false);
|
|
3904
|
+
};
|
|
3905
|
+
const onKeyDown = (event) => {
|
|
3906
|
+
if (event.key === "Escape") setPickerOpen(false);
|
|
3907
|
+
};
|
|
3908
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
3909
|
+
document.addEventListener("keydown", onKeyDown);
|
|
3910
|
+
return () => {
|
|
3911
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
3912
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
3913
|
+
};
|
|
3914
|
+
}, [pickerOpen]);
|
|
3915
|
+
const modelPickerDisabledReason = threadReady && !canSetModel ? "This conversation is already open and its runtime cannot change models mid-thread." : turnRunning ? "Wait for the current reply to finish before changing model." : null;
|
|
3916
|
+
const resolvedModel = thread.model;
|
|
3917
|
+
const resolvedName = resolvedModel?.displayName && (!activeModelId || resolvedModel.modelId === activeModelId || !activeModel) ? resolvedModel.displayName : null;
|
|
3918
|
+
const railLabel = selectedLabel ?? activeModel?.displayName ?? resolvedName ?? activeModelId ?? "Choose model";
|
|
3919
|
+
const defaultRail = hideModelPicker ? null : /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: pickerRef, style: { position: "relative" }, children: [
|
|
3920
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3921
|
+
"button",
|
|
3922
|
+
{
|
|
3923
|
+
type: "button",
|
|
3924
|
+
className: "adechat-button",
|
|
3925
|
+
onClick: () => setPickerOpen((open) => !open),
|
|
3926
|
+
"aria-expanded": pickerOpen,
|
|
3927
|
+
"aria-haspopup": "listbox",
|
|
3928
|
+
disabled: modelPickerDisabledReason !== null,
|
|
3929
|
+
...modelPickerDisabledReason ? { title: modelPickerDisabledReason } : {},
|
|
3930
|
+
children: railLabel
|
|
3931
|
+
}
|
|
3932
|
+
),
|
|
3933
|
+
modelError ? /* @__PURE__ */ jsxRuntime.jsxs("div", { role: "alert", className: "adechat-model-error", children: [
|
|
3934
|
+
"Could not switch model: ",
|
|
3935
|
+
modelError.message
|
|
3936
|
+
] }) : null,
|
|
3937
|
+
pickerOpen ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", bottom: "calc(100% + 8px)", left: 0, zIndex: 20 }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3938
|
+
ModelPicker,
|
|
3939
|
+
{
|
|
3940
|
+
client,
|
|
3941
|
+
value: activeModelId,
|
|
3942
|
+
...reasoningEffort !== void 0 ? { reasoningEffort } : {},
|
|
3943
|
+
...onReasoningEffortChange ? { onReasoningEffortChange } : {},
|
|
3944
|
+
onChange: (model) => {
|
|
3945
|
+
if (modelId === void 0) setInternalModelId(model.id);
|
|
3946
|
+
setSelectedLabel(model.displayName);
|
|
3947
|
+
setPickerOpen(false);
|
|
3948
|
+
onModelChange?.(model);
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
) }) : null
|
|
3952
|
+
] });
|
|
3953
|
+
const attachmentProps = {
|
|
3954
|
+
...onRequestAttachment ? { onRequestAttachment } : {},
|
|
3955
|
+
...attachments !== void 0 ? { attachments } : {},
|
|
3956
|
+
...onAttachmentsChange ? { onAttachmentsChange } : {}
|
|
3957
|
+
};
|
|
3958
|
+
const approvalHandler = thread.canApprove ? { onApprove: thread.approve } : {};
|
|
3959
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ["adechat-root", className].filter(Boolean).join(" "), style, children: [
|
|
3960
|
+
disableStyles ? null : /* @__PURE__ */ jsxRuntime.jsx(DaexChatStyles, { ...styleNonce ? { nonce: styleNonce } : {} }),
|
|
3961
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3962
|
+
Transcript,
|
|
3963
|
+
{
|
|
3964
|
+
rows: thread.rows,
|
|
3965
|
+
status: thread.status.state,
|
|
3966
|
+
...labels ? { labels } : {},
|
|
3967
|
+
...hideToolCalls !== void 0 ? { hideToolCalls } : {},
|
|
3968
|
+
...hideReasoning !== void 0 ? { hideReasoning } : {},
|
|
3969
|
+
...renderMarkdown2 ? { renderMarkdown: renderMarkdown2 } : {},
|
|
3970
|
+
...onLinkClick ? { onLinkClick } : {},
|
|
3971
|
+
...approvals ? { approvals } : {},
|
|
3972
|
+
...approvalHandler,
|
|
3973
|
+
...thread.canRespond ? { onRespond: thread.respond } : {},
|
|
3974
|
+
...renderToolResult ? { renderToolResult } : {},
|
|
3975
|
+
...toolChipActions ? { toolChipActions } : {},
|
|
3976
|
+
hasOlder: thread.hasOlder,
|
|
3977
|
+
loadingOlder: thread.loadingOlder,
|
|
3978
|
+
onLoadOlder: thread.loadOlder,
|
|
3979
|
+
...emptyState !== void 0 ? { emptyState } : {}
|
|
3980
|
+
}
|
|
3981
|
+
),
|
|
3982
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3983
|
+
UsageLimitNotice,
|
|
3984
|
+
{
|
|
3985
|
+
status: usageLimit,
|
|
3986
|
+
...thread.thread?.usageLimit?.resumeNow ? { onResumeNow: () => requireAccepted(thread.thread.usageLimit.resumeNow()) } : {},
|
|
3987
|
+
...thread.thread?.usageLimit?.continueOnAlternate ? { onContinueOnAlternate: () => requireAccepted(thread.thread.usageLimit.continueOnAlternate()) } : {}
|
|
3988
|
+
}
|
|
3989
|
+
),
|
|
3990
|
+
children ? children(thread) : null,
|
|
3991
|
+
thread.thread?.queue ? /* @__PURE__ */ jsxRuntime.jsx(QueueStrip, { queue: thread.thread.queue, refreshKey: `${queueRefreshKey}:${thread.status.state}` }, threadKey) : null,
|
|
3992
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3993
|
+
Composer,
|
|
3994
|
+
{
|
|
3995
|
+
onSend: async (input) => {
|
|
3996
|
+
const result = onSend ? await onSend(input, threadStateRef.current) : void 0;
|
|
3997
|
+
if (result === false) return false;
|
|
3998
|
+
if (result === "handled") {
|
|
3999
|
+
setQueueRefreshKey((value2) => value2 + 1);
|
|
4000
|
+
return;
|
|
4001
|
+
}
|
|
4002
|
+
await threadStateRef.current.send(input);
|
|
4003
|
+
setQueueRefreshKey((value2) => value2 + 1);
|
|
4004
|
+
},
|
|
4005
|
+
onSteer: async (input) => {
|
|
4006
|
+
await thread.steer(input);
|
|
4007
|
+
setQueueRefreshKey((value2) => value2 + 1);
|
|
4008
|
+
},
|
|
4009
|
+
onInterrupt: thread.interrupt,
|
|
4010
|
+
status: thread.status.state,
|
|
4011
|
+
ready: thread.ready,
|
|
4012
|
+
...placeholder !== void 0 ? { placeholder } : {},
|
|
4013
|
+
...sendOnEnter !== void 0 ? { sendOnEnter } : {},
|
|
4014
|
+
...value !== void 0 ? { value } : {},
|
|
4015
|
+
...onValueChange ? { onValueChange } : {},
|
|
4016
|
+
...attachmentProps,
|
|
4017
|
+
modelRail: modelRail !== void 0 ? modelRail : defaultRail,
|
|
4018
|
+
...actions !== void 0 ? { actions } : {},
|
|
4019
|
+
error: thread.error?.message ?? null,
|
|
4020
|
+
...thread.slashCommands !== void 0 ? { slashCommands: thread.slashCommands } : {},
|
|
4021
|
+
slashCommandsLoading: thread.slashCommandsLoading,
|
|
4022
|
+
slashCommandsError: thread.slashCommandsError,
|
|
4023
|
+
onRetrySlashCommands: thread.reloadSlashCommands
|
|
4024
|
+
}
|
|
4025
|
+
)
|
|
4026
|
+
] });
|
|
4027
|
+
}
|
|
4028
|
+
var AdeChat = DaexChat;
|
|
4029
|
+
function resolveState(status) {
|
|
4030
|
+
if (!status.installed) return "not_installed";
|
|
4031
|
+
if (!status.authenticated) return "unauthenticated";
|
|
4032
|
+
return "ready";
|
|
4033
|
+
}
|
|
4034
|
+
var STATE_COPY = {
|
|
4035
|
+
ready: "Ready",
|
|
4036
|
+
unauthenticated: "Not signed in",
|
|
4037
|
+
not_installed: "Not installed"
|
|
4038
|
+
};
|
|
4039
|
+
function resolveStateCopy(status) {
|
|
4040
|
+
const state = resolveState(status);
|
|
4041
|
+
if (state === "not_installed" && status.source === "derived") return "Not detected";
|
|
4042
|
+
return STATE_COPY[state];
|
|
4043
|
+
}
|
|
4044
|
+
function truncateBinaryPath(value, maxLength = 44) {
|
|
4045
|
+
if (value.length <= maxLength) return value;
|
|
4046
|
+
const separator = value.lastIndexOf("\\") > value.lastIndexOf("/") ? "\\" : "/";
|
|
4047
|
+
const index = value.lastIndexOf(separator);
|
|
4048
|
+
if (index <= 0) return `\u2026${value.slice(value.length - maxLength + 1)}`;
|
|
4049
|
+
const tail = value.slice(index);
|
|
4050
|
+
if (tail.length + 1 >= maxLength) return `\u2026${tail}`;
|
|
4051
|
+
return `${value.slice(0, maxLength - tail.length - 1)}\u2026${tail}`;
|
|
4052
|
+
}
|
|
4053
|
+
function ProviderCard({
|
|
4054
|
+
status,
|
|
4055
|
+
renderAction,
|
|
4056
|
+
onCopy,
|
|
4057
|
+
showDetail = false,
|
|
4058
|
+
onLinkClick,
|
|
4059
|
+
className
|
|
4060
|
+
}) {
|
|
4061
|
+
const state = resolveState(status);
|
|
4062
|
+
const command = state === "not_installed" ? status.installCommand : state === "unauthenticated" ? status.loginCommand : void 0;
|
|
4063
|
+
const commandKind = state === "not_installed" ? "install" : "login";
|
|
4064
|
+
const docsHref = status.docsUrl ? safeHref(status.docsUrl) : null;
|
|
4065
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DaexLinkHandlerProvider, { onLinkClick, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4066
|
+
"div",
|
|
4067
|
+
{
|
|
4068
|
+
className: ["adechat-providercard", className].filter(Boolean).join(" "),
|
|
4069
|
+
"data-state": state,
|
|
4070
|
+
children: [
|
|
4071
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-providercard-head", children: [
|
|
4072
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4073
|
+
"span",
|
|
4074
|
+
{
|
|
4075
|
+
className: "adechat-status-dot",
|
|
4076
|
+
"data-status": state === "ready" ? "ok" : state === "unauthenticated" ? "unauthed" : "missing",
|
|
4077
|
+
"aria-hidden": "true"
|
|
4078
|
+
}
|
|
4079
|
+
),
|
|
4080
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-providercard-name", children: status.displayName ?? status.id }),
|
|
4081
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-providercard-state", children: resolveStateCopy(status) })
|
|
4082
|
+
] }),
|
|
4083
|
+
status.detail ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-providercard-detail", children: status.detail }) : null,
|
|
4084
|
+
showDetail && (status.version || status.binaryPath) ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "adechat-providercard-probe", children: [
|
|
4085
|
+
status.version ? /* @__PURE__ */ jsxRuntime.jsx("span", { children: status.version }) : null,
|
|
4086
|
+
status.binaryPath ? /* @__PURE__ */ jsxRuntime.jsx("code", { title: status.binaryPath, children: truncateBinaryPath(status.binaryPath) }) : null
|
|
4087
|
+
] }) : null,
|
|
4088
|
+
command ? renderAction?.(command, commandKind) ?? /* @__PURE__ */ jsxRuntime.jsx(CopyableCommand, { command, ...onCopy ? { onCopy } : {} }) : null,
|
|
4089
|
+
docsHref ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4090
|
+
DaexLink,
|
|
4091
|
+
{
|
|
4092
|
+
className: "adechat-providercard-detail",
|
|
4093
|
+
href: docsHref,
|
|
4094
|
+
source: "provider-docs",
|
|
4095
|
+
children: "Documentation"
|
|
4096
|
+
}
|
|
4097
|
+
) : null
|
|
4098
|
+
]
|
|
4099
|
+
}
|
|
4100
|
+
) });
|
|
4101
|
+
}
|
|
4102
|
+
function CopyableCommand({
|
|
4103
|
+
command,
|
|
4104
|
+
onCopy
|
|
4105
|
+
}) {
|
|
4106
|
+
const [copied, setCopied] = react.useState(false);
|
|
4107
|
+
react.useEffect(() => {
|
|
4108
|
+
if (!copied) return;
|
|
4109
|
+
const timer = setTimeout(() => setCopied(false), 1600);
|
|
4110
|
+
return () => clearTimeout(timer);
|
|
4111
|
+
}, [copied]);
|
|
4112
|
+
const copy = react.useCallback(async () => {
|
|
4113
|
+
try {
|
|
4114
|
+
if (onCopy) await onCopy(command);
|
|
4115
|
+
else if (typeof navigator !== "undefined" && navigator.clipboard) {
|
|
4116
|
+
await navigator.clipboard.writeText(command);
|
|
4117
|
+
} else return;
|
|
4118
|
+
setCopied(true);
|
|
4119
|
+
} catch {
|
|
4120
|
+
}
|
|
4121
|
+
}, [command, onCopy]);
|
|
4122
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-command", children: [
|
|
4123
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { className: "adechat-command-text", children: command }),
|
|
4124
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", onClick: () => void copy(), children: copied ? "Copied" : "Copy" })
|
|
4125
|
+
] });
|
|
4126
|
+
}
|
|
4127
|
+
function ProviderCards(props) {
|
|
4128
|
+
return props.statuses ? /* @__PURE__ */ jsxRuntime.jsx(ProviderCardsView, { ...props, statuses: props.statuses }) : /* @__PURE__ */ jsxRuntime.jsx(ConnectedProviderCards, { ...props });
|
|
4129
|
+
}
|
|
4130
|
+
function ConnectedProviderCards(props) {
|
|
4131
|
+
const connected = useDaexProviders(props.client);
|
|
4132
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ProviderCardsView, { ...props, statuses: connected.statuses });
|
|
4133
|
+
}
|
|
4134
|
+
function ProviderCardsView({
|
|
4135
|
+
statuses = [],
|
|
4136
|
+
onlyNeedsAttention = true,
|
|
4137
|
+
renderAction,
|
|
4138
|
+
onCopy,
|
|
4139
|
+
showDetail,
|
|
4140
|
+
onLinkClick,
|
|
4141
|
+
className
|
|
4142
|
+
}) {
|
|
4143
|
+
const visible = onlyNeedsAttention ? statuses.filter((status) => resolveState(status) !== "ready") : statuses;
|
|
4144
|
+
if (visible.length === 0) return null;
|
|
4145
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: visible.map((status) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4146
|
+
ProviderCard,
|
|
4147
|
+
{
|
|
4148
|
+
status,
|
|
4149
|
+
...renderAction ? { renderAction } : {},
|
|
4150
|
+
...onCopy ? { onCopy } : {},
|
|
4151
|
+
...showDetail !== void 0 ? { showDetail } : {},
|
|
4152
|
+
...onLinkClick ? { onLinkClick } : {},
|
|
4153
|
+
...className ? { className } : {}
|
|
4154
|
+
},
|
|
4155
|
+
status.id
|
|
4156
|
+
)) });
|
|
4157
|
+
}
|
|
4158
|
+
|
|
4159
|
+
// src/adapters/sdkClient.ts
|
|
4160
|
+
function record(value) {
|
|
4161
|
+
return value && typeof value === "object" ? value : {};
|
|
4162
|
+
}
|
|
4163
|
+
function optionalString(value) {
|
|
4164
|
+
return typeof value === "string" && value ? value : void 0;
|
|
4165
|
+
}
|
|
4166
|
+
function optionalNumber(value) {
|
|
4167
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
4168
|
+
}
|
|
4169
|
+
function threadStatusFromEnvelope(envelope) {
|
|
4170
|
+
const event = record(envelope?.event);
|
|
4171
|
+
const type = event.type;
|
|
4172
|
+
const turnId = optionalString(event.turnId) ?? null;
|
|
4173
|
+
if (type === "error") {
|
|
4174
|
+
return {
|
|
4175
|
+
state: "error",
|
|
4176
|
+
turnId,
|
|
4177
|
+
message: optionalString(event.message) ?? optionalString(event.detail) ?? "The turn failed."
|
|
4178
|
+
};
|
|
4179
|
+
}
|
|
4180
|
+
if (type === "done") return { state: "idle", turnId };
|
|
4181
|
+
if (type === "status") {
|
|
4182
|
+
switch (event.turnStatus) {
|
|
4183
|
+
case "started":
|
|
4184
|
+
return { state: "running", turnId };
|
|
4185
|
+
case "completed":
|
|
4186
|
+
case "interrupted":
|
|
4187
|
+
return { state: "idle", turnId };
|
|
4188
|
+
// Also the SDK's synthetic status for a runtime that exited mid-turn
|
|
4189
|
+
// (`synthetic: true`), which no `done` follows.
|
|
4190
|
+
case "failed":
|
|
4191
|
+
return {
|
|
4192
|
+
state: "error",
|
|
4193
|
+
turnId,
|
|
4194
|
+
message: optionalString(event.message) ?? "The turn failed."
|
|
4195
|
+
};
|
|
4196
|
+
default:
|
|
4197
|
+
return null;
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
return null;
|
|
4201
|
+
}
|
|
4202
|
+
function threadUsageFromEnvelope(envelope) {
|
|
4203
|
+
const event = record(envelope?.event);
|
|
4204
|
+
const source = event.type === "context_usage" ? record(event.usage) : event;
|
|
4205
|
+
const usage = {};
|
|
4206
|
+
const input = optionalNumber(source.inputTokens) ?? optionalNumber(source.input_tokens);
|
|
4207
|
+
const output = optionalNumber(source.outputTokens) ?? optionalNumber(source.output_tokens);
|
|
4208
|
+
const total = optionalNumber(source.totalTokens) ?? optionalNumber(source.total_tokens) ?? (input !== void 0 && output !== void 0 ? input + output : void 0);
|
|
4209
|
+
const contextWindow = optionalNumber(source.maxTokens) ?? optionalNumber(source.contextWindow) ?? optionalNumber(source.context_window);
|
|
4210
|
+
if (input !== void 0) usage.inputTokens = input;
|
|
4211
|
+
if (output !== void 0) usage.outputTokens = output;
|
|
4212
|
+
if (total !== void 0) usage.totalTokens = total;
|
|
4213
|
+
if (contextWindow !== void 0) usage.contextWindow = contextWindow;
|
|
4214
|
+
return Object.keys(usage).length > 0 ? usage : null;
|
|
4215
|
+
}
|
|
4216
|
+
function providerStatusesFromSdk(statuses, options = {}) {
|
|
4217
|
+
const hints = options.commandHints ?? {};
|
|
4218
|
+
const entries = Object.values(statuses ?? {});
|
|
4219
|
+
const ordered = options.providerFilter ? options.providerFilter.map((id) => entries.find((entry) => entry.provider === id)).filter((entry) => Boolean(entry)) : entries;
|
|
4220
|
+
return ordered.map((entry) => {
|
|
4221
|
+
const hint = hints[entry.provider] ?? {};
|
|
4222
|
+
const status = {
|
|
4223
|
+
id: entry.provider,
|
|
4224
|
+
displayName: entry.displayName || entry.provider,
|
|
4225
|
+
// A runtime that probes the filesystem answers this directly. Only when
|
|
4226
|
+
// it does not does "DAEX knows models for it" stand in — the closest
|
|
4227
|
+
// honest reading available from a catalog alone. It is never inferred
|
|
4228
|
+
// from `authenticated`: that would render an unauthenticated provider as
|
|
4229
|
+
// "not installed" and send the user to the wrong copyable command.
|
|
4230
|
+
//
|
|
4231
|
+
// The same derivation exists in `@daex-dev/sdk` (`src/providers.ts`,
|
|
4232
|
+
// `deriveProviderStatus`). This copy is load-bearing rather than
|
|
4233
|
+
// redundant: it serves 0.1 clients, WebSocket proxies and test doubles
|
|
4234
|
+
// that send a record with neither `installed` nor `source`, which the SDK
|
|
4235
|
+
// never has to consider. Keep the two rules identical.
|
|
4236
|
+
installed: entry.installed ?? entry.modelCount > 0,
|
|
4237
|
+
authenticated: entry.authenticated
|
|
4238
|
+
};
|
|
4239
|
+
status.source = entry.source ?? (entry.installed === void 0 ? "derived" : "probed");
|
|
4240
|
+
if (entry.binaryPath) status.binaryPath = entry.binaryPath;
|
|
4241
|
+
if (entry.version) status.version = entry.version;
|
|
4242
|
+
if (entry.checkedAt) status.checkedAt = entry.checkedAt;
|
|
4243
|
+
const installCommand = hint.installCommand ?? entry.installCommand;
|
|
4244
|
+
const loginCommand = hint.loginCommand ?? entry.loginCommand;
|
|
4245
|
+
const docsUrl = hint.docsUrl ?? entry.docsUrl;
|
|
4246
|
+
if (installCommand) status.installCommand = installCommand;
|
|
4247
|
+
if (loginCommand) status.loginCommand = loginCommand;
|
|
4248
|
+
if (docsUrl) status.docsUrl = docsUrl;
|
|
4249
|
+
const detail = describeProvider(entry);
|
|
4250
|
+
if (detail) status.detail = detail;
|
|
4251
|
+
return status;
|
|
4252
|
+
});
|
|
4253
|
+
}
|
|
4254
|
+
function describeProvider(entry) {
|
|
4255
|
+
if (entry.detail) return entry.detail;
|
|
4256
|
+
if (entry.modelCount === 0) return "DAEX has no models for this provider.";
|
|
4257
|
+
if (!entry.authenticated) return "Not signed in.";
|
|
4258
|
+
if (entry.requiresConfiguration) return "Needs configuration before it can run.";
|
|
4259
|
+
if (!entry.available) return "Signed in, but no model is usable right now.";
|
|
4260
|
+
if (entry.stale) return "Status was read from a stale catalog.";
|
|
4261
|
+
return void 0;
|
|
4262
|
+
}
|
|
4263
|
+
function modelDescriptorsFromSdk(models, options = {}) {
|
|
4264
|
+
const allowed = options.providerFilter ? new Set(options.providerFilter) : null;
|
|
4265
|
+
return (models ?? []).filter((model) => !allowed || allowed.has(model.provider)).map((model) => {
|
|
4266
|
+
const descriptor = {
|
|
4267
|
+
id: model.id,
|
|
4268
|
+
providerId: model.provider,
|
|
4269
|
+
displayName: model.displayName || model.id
|
|
4270
|
+
};
|
|
4271
|
+
if (model.description) descriptor.description = model.description;
|
|
4272
|
+
if (model.reasoningEfforts?.length) descriptor.reasoningEfforts = [...model.reasoningEfforts];
|
|
4273
|
+
if (model.defaultReasoningEffort) descriptor.defaultReasoningEffort = model.defaultReasoningEffort;
|
|
4274
|
+
if (model.isAvailable === false) descriptor.available = false;
|
|
4275
|
+
return descriptor;
|
|
4276
|
+
});
|
|
4277
|
+
}
|
|
4278
|
+
function toSendText(input) {
|
|
4279
|
+
return typeof input === "string" ? input : input.text;
|
|
4280
|
+
}
|
|
4281
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
4282
|
+
".bmp",
|
|
4283
|
+
".gif",
|
|
4284
|
+
".heic",
|
|
4285
|
+
".heif",
|
|
4286
|
+
".ico",
|
|
4287
|
+
".jpeg",
|
|
4288
|
+
".jpg",
|
|
4289
|
+
".png",
|
|
4290
|
+
".svg",
|
|
4291
|
+
".tif",
|
|
4292
|
+
".tiff",
|
|
4293
|
+
".webp"
|
|
4294
|
+
]);
|
|
4295
|
+
function isImageAttachmentPath(filePath) {
|
|
4296
|
+
const extension = filePath.match(/\.[^./\\]+$/)?.[0]?.toLowerCase();
|
|
4297
|
+
return extension ? IMAGE_EXTENSIONS.has(extension) : false;
|
|
4298
|
+
}
|
|
4299
|
+
function inferAttachmentType(filePath, mimeType) {
|
|
4300
|
+
if (mimeType?.toLowerCase().startsWith("image/")) return "image";
|
|
4301
|
+
return isImageAttachmentPath(filePath) ? "image" : "file";
|
|
4302
|
+
}
|
|
4303
|
+
function attachmentKind(attachment) {
|
|
4304
|
+
if (attachment.type) return attachment.type;
|
|
4305
|
+
return inferAttachmentType(attachment.uri || attachment.name || "", attachment.mimeType);
|
|
4306
|
+
}
|
|
4307
|
+
function sdkSendArgs(input) {
|
|
4308
|
+
const refs = toFileRefs(input);
|
|
4309
|
+
return refs ? { text: toSendText(input), opts: { attachments: refs } } : { text: toSendText(input) };
|
|
4310
|
+
}
|
|
4311
|
+
function toFileRefs(input) {
|
|
4312
|
+
if (typeof input === "string") return void 0;
|
|
4313
|
+
const attachments = input.attachments ?? [];
|
|
4314
|
+
const refs = attachments.map((attachment) => {
|
|
4315
|
+
if (!attachment.uri) return null;
|
|
4316
|
+
const ref = { path: attachment.uri, type: attachmentKind(attachment) };
|
|
4317
|
+
if (attachment.name) ref.name = attachment.name;
|
|
4318
|
+
if (attachment.mimeType) ref.mimeType = attachment.mimeType;
|
|
4319
|
+
if (attachment.sizeBytes !== void 0) ref.bytes = attachment.sizeBytes;
|
|
4320
|
+
if (attachment.hydrate !== void 0) ref.hydrate = attachment.hydrate;
|
|
4321
|
+
return ref;
|
|
4322
|
+
}).filter((ref) => ref !== null);
|
|
4323
|
+
return refs.length > 0 ? refs : void 0;
|
|
4324
|
+
}
|
|
4325
|
+
var AdaptedThread = class {
|
|
4326
|
+
constructor(inner) {
|
|
4327
|
+
this.inner = inner;
|
|
4328
|
+
if (inner.setModel) {
|
|
4329
|
+
this.setModel = (modelId) => inner.setModel(modelId);
|
|
4330
|
+
}
|
|
4331
|
+
if (inner.approve) {
|
|
4332
|
+
this.approve = (itemId, decision, responseText) => responseText === void 0 ? inner.approve(itemId, decision) : inner.approve(itemId, decision, responseText);
|
|
4333
|
+
}
|
|
4334
|
+
if (inner.pendingApprovals) {
|
|
4335
|
+
this.pendingApprovals = () => inner.pendingApprovals();
|
|
4336
|
+
}
|
|
4337
|
+
if (inner.respond) {
|
|
4338
|
+
this.respond = (requestId, response) => inner.respond(requestId, response);
|
|
4339
|
+
}
|
|
4340
|
+
if (inner.queue) {
|
|
4341
|
+
const queue = inner.queue;
|
|
4342
|
+
this.queue = {
|
|
4343
|
+
...queue.list ? { list: () => queue.list() } : {},
|
|
4344
|
+
...queue.cancel ? { cancel: (id) => queue.cancel(id) } : {},
|
|
4345
|
+
...queue.edit ? { edit: (id, text) => queue.edit(id, text) } : {},
|
|
4346
|
+
...queue.move ? { move: (id, index) => queue.move(id, index) } : {},
|
|
4347
|
+
...queue.dispatch ? { dispatch: (id) => queue.dispatch(id) } : {},
|
|
4348
|
+
...queue.cancelDispatched ? { cancelDispatched: (id) => queue.cancelDispatched(id) } : {},
|
|
4349
|
+
...queue.restore ? { restore: () => queue.restore() } : {}
|
|
4350
|
+
};
|
|
4351
|
+
}
|
|
4352
|
+
if (inner.slashCommands) {
|
|
4353
|
+
this.slashCommands = () => inner.slashCommands();
|
|
4354
|
+
}
|
|
4355
|
+
if (inner.usageLimit) {
|
|
4356
|
+
const usageLimit = inner.usageLimit;
|
|
4357
|
+
this.usageLimit = {
|
|
4358
|
+
...usageLimit.resumeNow ? { resumeNow: () => usageLimit.resumeNow() } : {},
|
|
4359
|
+
...usageLimit.continueOnAlternate ? { continueOnAlternate: () => usageLimit.continueOnAlternate() } : {}
|
|
4360
|
+
};
|
|
4361
|
+
}
|
|
4362
|
+
if (inner.switchAccount) {
|
|
4363
|
+
this.switchAccount = (instanceId) => inner.switchAccount(instanceId);
|
|
4364
|
+
}
|
|
4365
|
+
if (inner.update) {
|
|
4366
|
+
this.update = (patch) => inner.update(patch);
|
|
4367
|
+
}
|
|
4368
|
+
if (inner.retry) {
|
|
4369
|
+
this.retry = () => inner.retry();
|
|
4370
|
+
}
|
|
4371
|
+
if (inner.editLast) {
|
|
4372
|
+
this.editLast = (input) => {
|
|
4373
|
+
const dropAttachments = typeof input !== "string" && input.attachments?.length === 0;
|
|
4374
|
+
if (dropAttachments) return inner.editLast(toSendText(input), { attachments: [] });
|
|
4375
|
+
const { text, opts } = sdkSendArgs(input);
|
|
4376
|
+
return inner.editLast(text, opts);
|
|
4377
|
+
};
|
|
4378
|
+
}
|
|
4379
|
+
if (inner.historyPage) {
|
|
4380
|
+
this.historyPage = async (request) => {
|
|
4381
|
+
const page = await inner.historyPage(request ?? {});
|
|
4382
|
+
return {
|
|
4383
|
+
events: page?.events ?? [],
|
|
4384
|
+
hasMore: page?.hasMore === true,
|
|
4385
|
+
nextBeforeSequence: page?.nextBeforeSequence ?? null
|
|
4386
|
+
};
|
|
4387
|
+
};
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
inner;
|
|
4391
|
+
/**
|
|
4392
|
+
* Present only when the underlying SDK thread supports it, so `canSetModel`
|
|
4393
|
+
* reflects the inner thread's real capability rather than the wrapper's.
|
|
4394
|
+
* Assigned in the constructor instead of initialized to `undefined` because
|
|
4395
|
+
* `exactOptionalPropertyTypes` makes those two different things: an absent
|
|
4396
|
+
* property and a property holding `undefined` are distinguishable, and only
|
|
4397
|
+
* the former reads as "not supported".
|
|
4398
|
+
*/
|
|
4399
|
+
setModel;
|
|
4400
|
+
/**
|
|
4401
|
+
* Present only when the inner thread can answer approvals, for the same
|
|
4402
|
+
* reason as `setModel`: the card renders read-only rather than offering a
|
|
4403
|
+
* button whose click would throw.
|
|
4404
|
+
*/
|
|
4405
|
+
approve;
|
|
4406
|
+
pendingApprovals;
|
|
4407
|
+
respond;
|
|
4408
|
+
queue;
|
|
4409
|
+
slashCommands;
|
|
4410
|
+
usageLimit;
|
|
4411
|
+
switchAccount;
|
|
4412
|
+
/** Present only when the inner thread has `update`. */
|
|
4413
|
+
update;
|
|
4414
|
+
/** Present only when the inner thread has `retry` / `editLast`. */
|
|
4415
|
+
retry;
|
|
4416
|
+
editLast;
|
|
4417
|
+
/** Present only when the inner thread pages, so the hook can feature-detect it. */
|
|
4418
|
+
historyPage;
|
|
4419
|
+
/**
|
|
4420
|
+
* Read through to the inner thread every time: the SDK replaces its value
|
|
4421
|
+
* after `setModel`, so a copy taken at construction would go stale.
|
|
4422
|
+
*/
|
|
4423
|
+
get model() {
|
|
4424
|
+
return readThreadModelSelection(this.inner.model);
|
|
4425
|
+
}
|
|
4426
|
+
get key() {
|
|
4427
|
+
return this.inner.key;
|
|
4428
|
+
}
|
|
4429
|
+
async send(input) {
|
|
4430
|
+
const { text, opts } = sdkSendArgs(input);
|
|
4431
|
+
await this.inner.send(text, opts);
|
|
4432
|
+
}
|
|
4433
|
+
async steer(input) {
|
|
4434
|
+
const { text, opts } = sdkSendArgs(input);
|
|
4435
|
+
await this.inner.steer(text, opts);
|
|
4436
|
+
}
|
|
4437
|
+
async interrupt() {
|
|
4438
|
+
await this.inner.interrupt();
|
|
4439
|
+
}
|
|
4440
|
+
async history() {
|
|
4441
|
+
return await this.inner.history();
|
|
4442
|
+
}
|
|
4443
|
+
/**
|
|
4444
|
+
* Taken as a discriminated tuple rather than two loose parameters: narrowing
|
|
4445
|
+
* on `args[0]` narrows `args[1]` with it, so the channel and its listener stay
|
|
4446
|
+
* connected without a cast to reunite them.
|
|
4447
|
+
*/
|
|
4448
|
+
on(...args) {
|
|
4449
|
+
if (args[0] === "event") {
|
|
4450
|
+
return this.inner.on("event", args[1]);
|
|
4451
|
+
}
|
|
4452
|
+
if (args[0] === "status") {
|
|
4453
|
+
const listener2 = args[1];
|
|
4454
|
+
return this.inner.on("status", (envelope) => {
|
|
4455
|
+
const status = threadStatusFromEnvelope(envelope);
|
|
4456
|
+
if (status) listener2(status);
|
|
4457
|
+
});
|
|
4458
|
+
}
|
|
4459
|
+
const listener = args[1];
|
|
4460
|
+
return this.inner.on("usage", (envelope) => {
|
|
4461
|
+
const usage = threadUsageFromEnvelope(envelope);
|
|
4462
|
+
if (usage) listener(usage);
|
|
4463
|
+
});
|
|
4464
|
+
}
|
|
4465
|
+
};
|
|
4466
|
+
function adaptSdkClient(sdk, options = {}) {
|
|
4467
|
+
let catalog = [];
|
|
4468
|
+
const openOptionsFor = (opts) => {
|
|
4469
|
+
const defaults = options.defaults ?? {};
|
|
4470
|
+
const modelId = opts?.modelId ?? defaults.model;
|
|
4471
|
+
const fromCatalog = modelId ? catalog.find((model) => model.id === modelId) : void 0;
|
|
4472
|
+
const provider = opts?.providerId ?? fromCatalog?.provider ?? defaults.provider;
|
|
4473
|
+
return {
|
|
4474
|
+
...defaults,
|
|
4475
|
+
...provider ? { provider } : {},
|
|
4476
|
+
...modelId ? { model: modelId } : {}
|
|
4477
|
+
};
|
|
4478
|
+
};
|
|
4479
|
+
const refresh = sdk.providers.refresh;
|
|
4480
|
+
const on = sdk.on;
|
|
4481
|
+
return {
|
|
4482
|
+
providers: {
|
|
4483
|
+
status: async () => providerStatusesFromSdk(await sdk.providers.status(), options),
|
|
4484
|
+
onChange: (cb) => sdk.providers.onChange((statuses) => cb(providerStatusesFromSdk(statuses, options))),
|
|
4485
|
+
// Forwarded only when the SDK client has it, so a host can tell a
|
|
4486
|
+
// re-probing runtime from one that only derives statuses from a catalog.
|
|
4487
|
+
...refresh ? {
|
|
4488
|
+
refresh: async () => providerStatusesFromSdk(await refresh.call(sdk.providers), options)
|
|
4489
|
+
} : {},
|
|
4490
|
+
...sdk.providers.capabilities ? { capabilities: (provider) => sdk.providers.capabilities(provider) } : {}
|
|
4491
|
+
},
|
|
4492
|
+
models: {
|
|
4493
|
+
list: async () => {
|
|
4494
|
+
catalog = await sdk.models.list();
|
|
4495
|
+
return modelDescriptorsFromSdk(catalog, options);
|
|
4496
|
+
}
|
|
4497
|
+
},
|
|
4498
|
+
threads: {
|
|
4499
|
+
open: async (key, opts) => new AdaptedThread(await sdk.threads.open(key, openOptionsFor(opts)))
|
|
4500
|
+
},
|
|
4501
|
+
...sdk.accounts ? { accounts: sdk.accounts } : {},
|
|
4502
|
+
...sdk.credentials ? { credentials: sdk.credentials } : {},
|
|
4503
|
+
...on ? {
|
|
4504
|
+
on: (event, cb) => {
|
|
4505
|
+
if (event === "usageLimit") {
|
|
4506
|
+
try {
|
|
4507
|
+
const subscribe = on;
|
|
4508
|
+
return subscribe.call(sdk, "usageLimit", cb);
|
|
4509
|
+
} catch (cause) {
|
|
4510
|
+
if (cause instanceof Error && /Unknown client event/.test(cause.message)) return () => {
|
|
4511
|
+
};
|
|
4512
|
+
throw cause;
|
|
4513
|
+
}
|
|
4514
|
+
}
|
|
4515
|
+
return on.call(sdk, event, cb);
|
|
4516
|
+
}
|
|
4517
|
+
} : {}
|
|
4518
|
+
};
|
|
4519
|
+
}
|
|
4520
|
+
function UsageMeter({ usage, label = "Usage", className }) {
|
|
4521
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: ["adechat-usage-meter", className].filter(Boolean).join(" "), "aria-label": label, children: [
|
|
4522
|
+
usage.windows.map((window2) => /* @__PURE__ */ jsxRuntime.jsx(UsageWindow, { window: window2 }, window2.type)),
|
|
4523
|
+
usage.state !== "ok" && usage.note ? /* @__PURE__ */ jsxRuntime.jsx("small", { className: "adechat-usage-meter-reset", children: usage.note }) : null
|
|
4524
|
+
] });
|
|
4525
|
+
}
|
|
4526
|
+
function UsageWindow({ window: window2 }) {
|
|
4527
|
+
const percent = window2.unlimited ? 100 : Math.max(0, Math.min(100, window2.percentLeft));
|
|
4528
|
+
const summary = window2.unlimited ? "Unlimited" : window2.countLeft !== void 0 && window2.countTotal !== void 0 ? `${window2.countLeft} of ${window2.countTotal} left` : `${Math.round(percent)}% left`;
|
|
4529
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4530
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-usage-meter-label", children: [
|
|
4531
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: window2.label }),
|
|
4532
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: summary })
|
|
4533
|
+
] }),
|
|
4534
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4535
|
+
"div",
|
|
4536
|
+
{
|
|
4537
|
+
className: "adechat-usage-meter-track",
|
|
4538
|
+
role: "meter",
|
|
4539
|
+
"aria-label": `${window2.label} left`,
|
|
4540
|
+
"aria-valuemin": 0,
|
|
4541
|
+
"aria-valuemax": 100,
|
|
4542
|
+
"aria-valuenow": Math.round(percent),
|
|
4543
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { width: `${percent}%` } })
|
|
4544
|
+
}
|
|
4545
|
+
),
|
|
4546
|
+
window2.resetsAt ? /* @__PURE__ */ jsxRuntime.jsxs("small", { className: "adechat-usage-meter-reset", children: [
|
|
4547
|
+
"Resets ",
|
|
4548
|
+
new Date(window2.resetsAt).toLocaleString()
|
|
4549
|
+
] }) : null
|
|
4550
|
+
] });
|
|
4551
|
+
}
|
|
4552
|
+
function AccountList({ client, accounts: supplied, onSelect, className }) {
|
|
4553
|
+
const [accounts, setAccounts] = react.useState(supplied ?? []);
|
|
4554
|
+
const [loading, setLoading] = react.useState(false);
|
|
4555
|
+
const [loaded, setLoaded] = react.useState(supplied !== void 0);
|
|
4556
|
+
const [error, setError] = react.useState(null);
|
|
4557
|
+
const [busy, setBusy] = react.useState(false);
|
|
4558
|
+
const api = client?.accounts;
|
|
4559
|
+
const refresh = react.useCallback(async () => {
|
|
4560
|
+
if (supplied !== void 0) {
|
|
4561
|
+
setAccounts(supplied);
|
|
4562
|
+
setLoaded(true);
|
|
4563
|
+
return;
|
|
4564
|
+
}
|
|
4565
|
+
if (!api?.list) return;
|
|
4566
|
+
setLoading(true);
|
|
4567
|
+
try {
|
|
4568
|
+
setAccounts(await api.list());
|
|
4569
|
+
setLoaded(true);
|
|
4570
|
+
setError(null);
|
|
4571
|
+
} catch (cause) {
|
|
4572
|
+
setLoaded(false);
|
|
4573
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
4574
|
+
} finally {
|
|
4575
|
+
setLoading(false);
|
|
4576
|
+
}
|
|
4577
|
+
}, [api, supplied]);
|
|
4578
|
+
react.useEffect(() => {
|
|
4579
|
+
void refresh();
|
|
4580
|
+
}, [refresh]);
|
|
4581
|
+
const run = async (action) => {
|
|
4582
|
+
if (busy) return;
|
|
4583
|
+
setBusy(true);
|
|
4584
|
+
setError(null);
|
|
4585
|
+
try {
|
|
4586
|
+
await action();
|
|
4587
|
+
await refresh();
|
|
4588
|
+
} catch (cause) {
|
|
4589
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
4590
|
+
} finally {
|
|
4591
|
+
setBusy(false);
|
|
4592
|
+
}
|
|
4593
|
+
};
|
|
4594
|
+
if (supplied === void 0 && !api?.list) {
|
|
4595
|
+
return /* @__PURE__ */ jsxRuntime.jsx("p", { className: joinClass("adechat-account-state", className), children: "Account management is unavailable in this client." });
|
|
4596
|
+
}
|
|
4597
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: joinClass("adechat-account-list", className), "aria-label": "Provider accounts", children: [
|
|
4598
|
+
loading && !loaded ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-account-state", children: "Loading accounts\u2026" }) : null,
|
|
4599
|
+
error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-account-error", role: "alert", children: [
|
|
4600
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
4601
|
+
"Couldn\u2019t load accounts: ",
|
|
4602
|
+
error
|
|
4603
|
+
] }),
|
|
4604
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", disabled: loading, onClick: () => void refresh(), children: "Retry" })
|
|
4605
|
+
] }) : null,
|
|
4606
|
+
loaded && accounts.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-account-state", children: "No accounts are available." }) : null,
|
|
4607
|
+
loaded ? accounts.map((account) => /* @__PURE__ */ jsxRuntime.jsxs("article", { className: "adechat-account", children: [
|
|
4608
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "adechat-account-summary", children: [
|
|
4609
|
+
/* @__PURE__ */ jsxRuntime.jsx("strong", { children: account.label || account.provider }),
|
|
4610
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: [account.email, account.plan, account.signedIn ? "Signed in" : "Signed out", account.isDefault ? "Default" : null].filter(Boolean).join(" \xB7 ") })
|
|
4611
|
+
] }),
|
|
4612
|
+
account.usage ? /* @__PURE__ */ jsxRuntime.jsx(UsageMeter, { usage: account.usage, label: `${account.label} usage` }) : null,
|
|
4613
|
+
onSelect ? /* @__PURE__ */ jsxRuntime.jsx("button", { className: "adechat-button", type: "button", disabled: busy, onClick: () => void run(() => onSelect(account)), children: "Select" }) : null,
|
|
4614
|
+
api?.setDefault && !account.isDefault ? /* @__PURE__ */ jsxRuntime.jsx("button", { className: "adechat-button", type: "button", disabled: busy, onClick: () => void run(() => api.setDefault(account.id)), children: "Make default" }) : null,
|
|
4615
|
+
api?.signOut && account.signedIn ? /* @__PURE__ */ jsxRuntime.jsx("button", { className: "adechat-button", type: "button", disabled: busy, onClick: () => void run(() => api.signOut(account.id)), children: "Sign out" }) : null,
|
|
4616
|
+
api?.remove ? /* @__PURE__ */ jsxRuntime.jsx("button", { className: "adechat-button", type: "button", "data-variant": "danger", disabled: busy, onClick: () => void run(() => api.remove(account.id)), children: "Remove" }) : null
|
|
4617
|
+
] }, account.id)) : null
|
|
4618
|
+
] });
|
|
4619
|
+
}
|
|
4620
|
+
function joinClass(...values) {
|
|
4621
|
+
return values.filter(Boolean).join(" ");
|
|
4622
|
+
}
|
|
4623
|
+
function AccountSwitcher({ accounts, currentAccountId, thread, onSwitch, className }) {
|
|
4624
|
+
const [busy, setBusy] = react.useState(false);
|
|
4625
|
+
const [error, setError] = react.useState(null);
|
|
4626
|
+
const switchTo = onSwitch ?? (thread?.switchAccount ? (id) => requireAccepted(thread.switchAccount(id)) : void 0);
|
|
4627
|
+
if (!switchTo) return null;
|
|
4628
|
+
const choices = accounts.filter((account) => account.signedIn);
|
|
4629
|
+
if (choices.length < 2) return null;
|
|
4630
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("label", { className: ["adechat-account-switcher", className].filter(Boolean).join(" "), children: [
|
|
4631
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: "Account" }),
|
|
4632
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4633
|
+
"select",
|
|
4634
|
+
{
|
|
4635
|
+
value: currentAccountId ?? "",
|
|
4636
|
+
disabled: busy,
|
|
4637
|
+
onChange: (event) => {
|
|
4638
|
+
const id = event.target.value;
|
|
4639
|
+
if (!id || id === currentAccountId) return;
|
|
4640
|
+
setBusy(true);
|
|
4641
|
+
setError(null);
|
|
4642
|
+
void Promise.resolve(switchTo(id)).catch((cause) => setError(cause instanceof Error ? cause.message : String(cause))).finally(() => setBusy(false));
|
|
4643
|
+
},
|
|
4644
|
+
children: [
|
|
4645
|
+
/* @__PURE__ */ jsxRuntime.jsx("option", { value: "", disabled: true, children: "Select an account" }),
|
|
4646
|
+
choices.map((account) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: account.id, children: account.label || account.provider }, account.id))
|
|
4647
|
+
]
|
|
4648
|
+
}
|
|
4649
|
+
),
|
|
4650
|
+
error ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "adechat-account-error", role: "alert", children: [
|
|
4651
|
+
"Could not switch account: ",
|
|
4652
|
+
error
|
|
4653
|
+
] }) : null
|
|
4654
|
+
] });
|
|
4655
|
+
}
|
|
4656
|
+
function ApiKeyForm({ provider, client, onSubmit, className }) {
|
|
4657
|
+
const [key, setKey] = react.useState("");
|
|
4658
|
+
const [label, setLabel] = react.useState("");
|
|
4659
|
+
const [busy, setBusy] = react.useState(false);
|
|
4660
|
+
const [saved, setSaved] = react.useState(false);
|
|
4661
|
+
const [failed, setFailed] = react.useState(false);
|
|
4662
|
+
const save = onSubmit ?? client?.credentials?.add?.bind(client.credentials);
|
|
4663
|
+
const submit = async (event) => {
|
|
4664
|
+
event.preventDefault();
|
|
4665
|
+
if (!save || !key || busy) return;
|
|
4666
|
+
setBusy(true);
|
|
4667
|
+
setSaved(false);
|
|
4668
|
+
setFailed(false);
|
|
4669
|
+
try {
|
|
4670
|
+
await save({ provider, key, ...label.trim() ? { label: label.trim() } : {} });
|
|
4671
|
+
setKey("");
|
|
4672
|
+
setSaved(true);
|
|
4673
|
+
} catch {
|
|
4674
|
+
setFailed(true);
|
|
4675
|
+
} finally {
|
|
4676
|
+
setBusy(false);
|
|
4677
|
+
}
|
|
4678
|
+
};
|
|
4679
|
+
if (!save) return null;
|
|
4680
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("form", { className: ["adechat-api-key-form", className].filter(Boolean).join(" "), onSubmit: (event) => void submit(event), children: [
|
|
4681
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
4682
|
+
"Label",
|
|
4683
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { value: label, onChange: (event) => setLabel(event.target.value), autoComplete: "off", disabled: busy })
|
|
4684
|
+
] }),
|
|
4685
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
4686
|
+
"API key",
|
|
4687
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { type: "password", value: key, onChange: (event) => setKey(event.target.value), autoComplete: "new-password", spellCheck: false, disabled: busy })
|
|
4688
|
+
] }),
|
|
4689
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", className: "adechat-button", "data-variant": "primary", disabled: busy || !key, children: busy ? "Saving\u2026" : "Save API key" }),
|
|
4690
|
+
saved ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-sign-in-state", role: "status", children: "API key saved." }) : null,
|
|
4691
|
+
failed ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "adechat-account-error", role: "alert", children: "Could not save this API key." }) : null
|
|
4692
|
+
] });
|
|
4693
|
+
}
|
|
4694
|
+
function SignInCard({ handle: providedHandle, onStart, onComplete, className }) {
|
|
4695
|
+
const [handle, setHandle] = react.useState(providedHandle ?? null);
|
|
4696
|
+
const [update, setUpdate] = react.useState({ state: "running" });
|
|
4697
|
+
const [code, setCode] = react.useState("");
|
|
4698
|
+
const [busy, setBusy] = react.useState(false);
|
|
4699
|
+
const [error, setError] = react.useState(null);
|
|
4700
|
+
const onCompleteRef = react.useRef(onComplete);
|
|
4701
|
+
onCompleteRef.current = onComplete;
|
|
4702
|
+
react.useEffect(() => setHandle(providedHandle ?? null), [providedHandle]);
|
|
4703
|
+
react.useEffect(() => {
|
|
4704
|
+
if (!handle) return;
|
|
4705
|
+
let active = true;
|
|
4706
|
+
const stop = handle.on("update", (next) => {
|
|
4707
|
+
if (active) setUpdate(next);
|
|
4708
|
+
});
|
|
4709
|
+
void handle.done.then((account) => {
|
|
4710
|
+
if (!active) return;
|
|
4711
|
+
setUpdate((current) => ({ ...current, state: "succeeded" }));
|
|
4712
|
+
onCompleteRef.current?.(account);
|
|
4713
|
+
}).catch((cause) => {
|
|
4714
|
+
if (active) {
|
|
4715
|
+
setUpdate((current) => ({ ...current, state: "failed" }));
|
|
4716
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
4717
|
+
}
|
|
4718
|
+
});
|
|
4719
|
+
return () => {
|
|
4720
|
+
active = false;
|
|
4721
|
+
stop();
|
|
4722
|
+
};
|
|
4723
|
+
}, [handle]);
|
|
4724
|
+
const start = async () => {
|
|
4725
|
+
if (!onStart || busy) return;
|
|
4726
|
+
setBusy(true);
|
|
4727
|
+
setError(null);
|
|
4728
|
+
try {
|
|
4729
|
+
setHandle(await onStart());
|
|
4730
|
+
} catch (cause) {
|
|
4731
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
4732
|
+
} finally {
|
|
4733
|
+
setBusy(false);
|
|
4734
|
+
}
|
|
4735
|
+
};
|
|
4736
|
+
const submit = async (event) => {
|
|
4737
|
+
event.preventDefault();
|
|
4738
|
+
if (!handle || !code.trim() || busy) return;
|
|
4739
|
+
setBusy(true);
|
|
4740
|
+
setError(null);
|
|
4741
|
+
try {
|
|
4742
|
+
await handle.submitCode(code);
|
|
4743
|
+
setCode("");
|
|
4744
|
+
} catch (cause) {
|
|
4745
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
4746
|
+
} finally {
|
|
4747
|
+
setBusy(false);
|
|
4748
|
+
}
|
|
4749
|
+
};
|
|
4750
|
+
const cancel = async () => {
|
|
4751
|
+
if (!handle || busy) return;
|
|
4752
|
+
setBusy(true);
|
|
4753
|
+
setError(null);
|
|
4754
|
+
try {
|
|
4755
|
+
await handle.cancel();
|
|
4756
|
+
setUpdate((current) => ({ ...current, state: "cancelled" }));
|
|
4757
|
+
} catch (cause) {
|
|
4758
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
4759
|
+
} finally {
|
|
4760
|
+
setBusy(false);
|
|
4761
|
+
}
|
|
4762
|
+
};
|
|
4763
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: ["adechat-sign-in", className].filter(Boolean).join(" "), "aria-label": "Sign in", children: [
|
|
4764
|
+
update.url ? /* @__PURE__ */ jsxRuntime.jsx("a", { href: update.url, target: "_blank", rel: "noreferrer noopener", children: "Continue sign-in" }) : null,
|
|
4765
|
+
update.deviceCode ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "adechat-sign-in-code", children: [
|
|
4766
|
+
"Device code: ",
|
|
4767
|
+
/* @__PURE__ */ jsxRuntime.jsx("code", { children: update.deviceCode })
|
|
4768
|
+
] }) : null,
|
|
4769
|
+
update.message ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-account-state", children: update.message }) : null,
|
|
4770
|
+
update.state === "verifying" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-sign-in-state", role: "status", children: "Checking the sign-in\u2026" }) : null,
|
|
4771
|
+
update.state === "succeeded" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-sign-in-state", role: "status", children: "Signed in." }) : null,
|
|
4772
|
+
update.state === "expired" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-account-error", role: "alert", children: "This sign-in expired. Start it again." }) : null,
|
|
4773
|
+
update.state === "cancelled" ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-sign-in-state", role: "status", children: "Sign-in cancelled." }) : null,
|
|
4774
|
+
update.state === "failed" && !error ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "adechat-account-error", role: "alert", children: "Sign-in could not continue." }) : null,
|
|
4775
|
+
update.awaitingCode && handle ? /* @__PURE__ */ jsxRuntime.jsxs("form", { className: "adechat-sign-in-code-form", onSubmit: (event) => void submit(event), children: [
|
|
4776
|
+
/* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
|
|
4777
|
+
"Paste the code from the sign-in page",
|
|
4778
|
+
/* @__PURE__ */ jsxRuntime.jsx("input", { autoComplete: "one-time-code", value: code, onChange: (event) => setCode(event.target.value), disabled: busy })
|
|
4779
|
+
] }),
|
|
4780
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", className: "adechat-button", "data-variant": "primary", disabled: busy || !code.trim(), children: "Submit code" })
|
|
4781
|
+
] }) : null,
|
|
4782
|
+
handle && !["succeeded", "failed", "cancelled", "expired"].includes(update.state) ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", onClick: () => void cancel(), disabled: busy, children: "Cancel sign-in" }) : null,
|
|
4783
|
+
!handle && onStart ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "adechat-button", onClick: () => void start(), disabled: busy, children: busy ? "Starting\u2026" : "Start sign-in" }) : null,
|
|
4784
|
+
error ? /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "adechat-account-error", role: "alert", children: [
|
|
4785
|
+
"Sign-in could not continue: ",
|
|
4786
|
+
error
|
|
4787
|
+
] }) : null
|
|
4788
|
+
] });
|
|
4789
|
+
}
|
|
4790
|
+
|
|
4791
|
+
exports.ADE_CHAT_TOKENS = ADE_CHAT_TOKENS;
|
|
4792
|
+
exports.AccountList = AccountList;
|
|
4793
|
+
exports.AccountSwitcher = AccountSwitcher;
|
|
4794
|
+
exports.ActivityIndicator = ActivityIndicator;
|
|
4795
|
+
exports.AdeChat = AdeChat;
|
|
4796
|
+
exports.AdeChatProvider = AdeChatProvider;
|
|
4797
|
+
exports.AdeChatStyles = AdeChatStyles;
|
|
4798
|
+
exports.AdeLink = AdeLink;
|
|
4799
|
+
exports.AdeLinkHandlerProvider = AdeLinkHandlerProvider;
|
|
4800
|
+
exports.ApiKeyForm = ApiKeyForm;
|
|
4801
|
+
exports.ApprovalCard = ApprovalCard;
|
|
4802
|
+
exports.Composer = Composer;
|
|
4803
|
+
exports.DAEX_CHAT_TOKENS = DAEX_CHAT_TOKENS;
|
|
4804
|
+
exports.DEFAULT_APPROVAL_WAITING_LABEL = DEFAULT_APPROVAL_WAITING_LABEL;
|
|
4805
|
+
exports.DEFAULT_ELAPSED_AFTER_MS = DEFAULT_ELAPSED_AFTER_MS;
|
|
4806
|
+
exports.DEFAULT_HISTORY_PAGE_SIZE = DEFAULT_HISTORY_PAGE_SIZE;
|
|
4807
|
+
exports.DEFAULT_THINKING_LABEL = DEFAULT_THINKING_LABEL;
|
|
4808
|
+
exports.DaexChat = DaexChat;
|
|
4809
|
+
exports.DaexChatProvider = DaexChatProvider;
|
|
4810
|
+
exports.DaexChatStyles = DaexChatStyles;
|
|
4811
|
+
exports.DaexLink = DaexLink;
|
|
4812
|
+
exports.DaexLinkHandlerProvider = DaexLinkHandlerProvider;
|
|
4813
|
+
exports.ModelPicker = ModelPicker;
|
|
4814
|
+
exports.NO_APPROVE_NOTICE = NO_APPROVE_NOTICE;
|
|
4815
|
+
exports.PendingInputCard = PendingInputCard;
|
|
4816
|
+
exports.ProviderCard = ProviderCard;
|
|
4817
|
+
exports.ProviderCards = ProviderCards;
|
|
4818
|
+
exports.QueueStrip = QueueStrip;
|
|
4819
|
+
exports.SignInCard = SignInCard;
|
|
4820
|
+
exports.ToolChip = ToolChip;
|
|
4821
|
+
exports.Transcript = Transcript;
|
|
4822
|
+
exports.TranscriptRowBuilder = TranscriptRowBuilder;
|
|
4823
|
+
exports.UNANSWERABLE_NOTICE = UNANSWERABLE_NOTICE;
|
|
4824
|
+
exports.UsageLimitNotice = UsageLimitNotice;
|
|
4825
|
+
exports.UsageMeter = UsageMeter;
|
|
4826
|
+
exports.adaptSdkClient = adaptSdkClient;
|
|
4827
|
+
exports.adeChatCss = adeChatCss;
|
|
4828
|
+
exports.approvalRequestFromRow = approvalRequestFromRow;
|
|
4829
|
+
exports.attachmentKind = attachmentKind;
|
|
4830
|
+
exports.blockedHint = blockedHint;
|
|
4831
|
+
exports.buildTranscriptRows = buildTranscriptRows;
|
|
4832
|
+
exports.collapseTranscriptEvents = collapseTranscriptEvents;
|
|
4833
|
+
exports.createTheme = createTheme;
|
|
4834
|
+
exports.daexChatCss = daexChatCss;
|
|
4835
|
+
exports.defaultTheme = defaultTheme;
|
|
4836
|
+
exports.describeToolActivity = describeToolActivity;
|
|
4837
|
+
exports.eventHasPayload = eventHasPayload;
|
|
4838
|
+
exports.formatElapsed = formatElapsed;
|
|
4839
|
+
exports.formatStructuredValue = formatStructuredValue;
|
|
4840
|
+
exports.groupModelsByProvider = groupModelsByProvider;
|
|
4841
|
+
exports.groupTranscriptRows = groupTranscriptRows;
|
|
4842
|
+
exports.inferAttachmentType = inferAttachmentType;
|
|
4843
|
+
exports.injectAdeChatStyles = injectAdeChatStyles;
|
|
4844
|
+
exports.injectDaexChatStyles = injectDaexChatStyles;
|
|
4845
|
+
exports.isModelSelectable = isModelSelectable;
|
|
4846
|
+
exports.isProviderUsable = isProviderUsable;
|
|
4847
|
+
exports.matchLabelKey = matchLabelKey;
|
|
4848
|
+
exports.mergeAttachments = mergeAttachments;
|
|
4849
|
+
exports.mergeStreamingText = mergeStreamingText;
|
|
4850
|
+
exports.modelDescriptorsFromSdk = modelDescriptorsFromSdk;
|
|
4851
|
+
exports.parseInline = parseInline;
|
|
4852
|
+
exports.parseMarkdownBlocks = parseMarkdownBlocks;
|
|
4853
|
+
exports.parseToolIdentity = parseToolIdentity;
|
|
4854
|
+
exports.phaseForToolStatus = phaseForToolStatus;
|
|
4855
|
+
exports.providerStatusesFromSdk = providerStatusesFromSdk;
|
|
4856
|
+
exports.readApprovalCommand = readApprovalCommand;
|
|
4857
|
+
exports.readApprovalPaths = readApprovalPaths;
|
|
4858
|
+
exports.renderMarkdown = renderMarkdown;
|
|
4859
|
+
exports.resolveActivityIcon = resolveActivityIcon;
|
|
4860
|
+
exports.resolveActivityLabel = resolveActivityLabel;
|
|
4861
|
+
exports.resolveComposerAction = resolveComposerAction;
|
|
4862
|
+
exports.resolveComposerState = resolveComposerState;
|
|
4863
|
+
exports.resolveKeyIntent = resolveKeyIntent;
|
|
4864
|
+
exports.resolveStateCopy = resolveStateCopy;
|
|
4865
|
+
exports.resolveToolName = resolveToolName;
|
|
4866
|
+
exports.safeHref = safeHref;
|
|
4867
|
+
exports.scoreModelSearch = scoreModelSearch;
|
|
4868
|
+
exports.shouldMergeTextRows = shouldMergeTextRows;
|
|
4869
|
+
exports.themeToCss = themeToCss;
|
|
4870
|
+
exports.threadStatusFromEnvelope = threadStatusFromEnvelope;
|
|
4871
|
+
exports.threadUsageFromEnvelope = threadUsageFromEnvelope;
|
|
4872
|
+
exports.truncateBinaryPath = truncateBinaryPath;
|
|
4873
|
+
exports.useAdeChatClient = useAdeChatClient;
|
|
4874
|
+
exports.useAdeChatContext = useAdeChatContext;
|
|
4875
|
+
exports.useAdeProviders = useAdeProviders;
|
|
4876
|
+
exports.useAdeThread = useAdeThread;
|
|
4877
|
+
exports.useDaexChatClient = useDaexChatClient;
|
|
4878
|
+
exports.useDaexChatContext = useDaexChatContext;
|
|
4879
|
+
exports.useDaexProviders = useDaexProviders;
|
|
4880
|
+
exports.useDaexThread = useDaexThread;
|
|
4881
|
+
exports.usePrefersReducedMotion = usePrefersReducedMotion;
|
|
4882
|
+
//# sourceMappingURL=index.cjs.map
|
|
4883
|
+
//# sourceMappingURL=index.cjs.map
|