@dudko.dev/agent-web-react 0.0.8 → 0.0.10
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/README.md +71 -25
- package/dist/index.cjs +3199 -339
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1050 -39
- package/dist/index.d.ts +1050 -39
- package/dist/index.js +3178 -347
- package/dist/index.js.map +1 -1
- package/dist/styles.css +878 -16
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -31,35 +31,78 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
AgentChat: () => AgentChat,
|
|
34
|
+
AgentComposer: () => AgentComposer,
|
|
35
|
+
AgentLabelsProvider: () => AgentLabelsProvider,
|
|
34
36
|
AgentProvider: () => AgentProvider,
|
|
35
37
|
ApiKeyForm: () => ApiKeyForm,
|
|
38
|
+
ApprovalModeSwitch: () => ApprovalModeSwitch,
|
|
39
|
+
AttachmentView: () => AttachmentView,
|
|
40
|
+
AttachmentsNotSupportedError: () => import_agent_web4.AttachmentsNotSupportedError,
|
|
41
|
+
ChatHistoryList: () => ChatHistoryList,
|
|
42
|
+
ChatHistoryStore: () => ChatHistoryStore,
|
|
36
43
|
Composer: () => Composer,
|
|
44
|
+
ContextMeter: () => ContextMeter,
|
|
45
|
+
FilesPanel: () => FilesPanel,
|
|
46
|
+
ImagesNotSupportedError: () => import_agent_web4.ImagesNotSupportedError,
|
|
47
|
+
IndexedDBStore: () => import_agent_web4.IndexedDBStore,
|
|
37
48
|
MemoryCredentialStore: () => import_agent_web4.MemoryCredentialStore,
|
|
49
|
+
MemoryStore: () => import_agent_web4.MemoryStore,
|
|
38
50
|
MessageList: () => MessageList,
|
|
39
51
|
ModelLoadBar: () => ModelLoadBar,
|
|
40
52
|
PlanView: () => PlanView,
|
|
41
53
|
StepList: () => StepList,
|
|
54
|
+
SubagentRow: () => SubagentRow,
|
|
55
|
+
ToolApprovalPrompt: () => ToolApprovalPrompt,
|
|
56
|
+
ToolCallRow: () => ToolCallRow,
|
|
42
57
|
UsageBadge: () => UsageBadge,
|
|
43
58
|
VaultCredentialStore: () => import_agent_web4.VaultCredentialStore,
|
|
59
|
+
VirtualFileSystem: () => import_agent_web4.VirtualFileSystem,
|
|
44
60
|
agentStateReducer: () => agentStateReducer,
|
|
61
|
+
attachmentKindOf: () => attachmentKindOf,
|
|
62
|
+
attachmentRefusal: () => attachmentRefusal,
|
|
63
|
+
chatTitle: () => chatTitle,
|
|
45
64
|
claimOAuthCallback: () => claimOAuthCallback,
|
|
46
65
|
createAgent: () => import_agent_web4.createAgent,
|
|
66
|
+
createFileTools: () => import_agent_web4.createFileTools,
|
|
47
67
|
createInitialAgentState: () => createInitialAgentState,
|
|
68
|
+
createSubagentTool: () => import_agent_web4.createSubagentTool,
|
|
48
69
|
createWebLLMModel: () => import_agent_web4.createWebLLMModel,
|
|
70
|
+
defaultLabels: () => defaultLabels,
|
|
71
|
+
defineSkill: () => import_agent_web4.defineSkill,
|
|
49
72
|
defineTool: () => import_agent_web4.defineTool,
|
|
50
73
|
describeMcpResult: () => describeMcpResult,
|
|
74
|
+
downscaleImage: () => downscaleImage,
|
|
75
|
+
filterCommands: () => filterCommands,
|
|
76
|
+
formatElapsed: () => formatElapsed,
|
|
51
77
|
isUnauthorizedError: () => isUnauthorizedError,
|
|
52
78
|
isWebGPUAvailable: () => import_agent_web4.isWebGPUAvailable,
|
|
79
|
+
loadSkillFromUrl: () => import_agent_web4.loadSkillFromUrl,
|
|
80
|
+
markReadOnly: () => import_agent_web4.markReadOnly,
|
|
81
|
+
mergeLabels: () => mergeLabels,
|
|
82
|
+
newChatId: () => newChatId,
|
|
83
|
+
noticesOf: () => noticesOf,
|
|
84
|
+
parseSkillMarkdown: () => import_agent_web4.parseSkillMarkdown,
|
|
85
|
+
parseSlash: () => parseSlash,
|
|
53
86
|
preloadWebLLMModel: () => import_agent_web4.preloadWebLLMModel,
|
|
54
87
|
readCallbackParams: () => readCallbackParams,
|
|
88
|
+
serveSubagentWorker: () => import_agent_web4.serveSubagentWorker,
|
|
55
89
|
stripOAuthParams: () => stripOAuthParams,
|
|
90
|
+
supportsImages: () => import_agent_web4.supportsImages,
|
|
91
|
+
supportsPdf: () => import_agent_web4.supportsPdf,
|
|
56
92
|
unloadWebLLMModel: () => import_agent_web4.unloadWebLLMModel,
|
|
93
|
+
usageLine: () => usageLine,
|
|
57
94
|
useAgent: () => useAgent,
|
|
58
95
|
useAgentContext: () => useAgentContext,
|
|
96
|
+
useChatHistory: () => useChatHistory,
|
|
59
97
|
useCredentials: () => useCredentials,
|
|
98
|
+
useLabels: () => useLabels,
|
|
60
99
|
useMcp: () => useMcp,
|
|
100
|
+
useMcpServers: () => useMcpServers,
|
|
61
101
|
useOptionalAgentContext: () => useOptionalAgentContext,
|
|
62
|
-
|
|
102
|
+
useSpeechToText: () => useSpeechToText,
|
|
103
|
+
useVirtualFiles: () => useVirtualFiles,
|
|
104
|
+
useWebLLMModel: () => useWebLLMModel,
|
|
105
|
+
withAttachments: () => withAttachments
|
|
63
106
|
});
|
|
64
107
|
module.exports = __toCommonJS(src_exports);
|
|
65
108
|
|
|
@@ -68,11 +111,31 @@ var import_react = require("react");
|
|
|
68
111
|
var import_agent_web = require("@dudko.dev/agent-web");
|
|
69
112
|
|
|
70
113
|
// src/state.ts
|
|
71
|
-
var
|
|
114
|
+
var approxTokens = (value) => {
|
|
115
|
+
if (value === void 0) return 0;
|
|
116
|
+
let text;
|
|
117
|
+
try {
|
|
118
|
+
text = typeof value === "string" ? value : JSON.stringify(value) ?? "";
|
|
119
|
+
} catch {
|
|
120
|
+
text = String(value);
|
|
121
|
+
}
|
|
122
|
+
return Math.ceil(text.length / 4);
|
|
123
|
+
};
|
|
124
|
+
var emptyUsage = () => ({
|
|
125
|
+
inputTokens: 0,
|
|
126
|
+
outputTokens: 0,
|
|
127
|
+
totalTokens: 0,
|
|
128
|
+
reasoningTokens: 0,
|
|
129
|
+
cachedInputTokens: 0,
|
|
130
|
+
cacheWriteTokens: 0
|
|
131
|
+
});
|
|
72
132
|
var addUsage = (a, b) => ({
|
|
73
133
|
inputTokens: a.inputTokens + b.inputTokens,
|
|
74
134
|
outputTokens: a.outputTokens + b.outputTokens,
|
|
75
|
-
totalTokens: a.totalTokens + b.totalTokens
|
|
135
|
+
totalTokens: a.totalTokens + b.totalTokens,
|
|
136
|
+
reasoningTokens: (a.reasoningTokens ?? 0) + (b.reasoningTokens ?? 0),
|
|
137
|
+
cachedInputTokens: (a.cachedInputTokens ?? 0) + (b.cachedInputTokens ?? 0),
|
|
138
|
+
cacheWriteTokens: (a.cacheWriteTokens ?? 0) + (b.cacheWriteTokens ?? 0)
|
|
76
139
|
});
|
|
77
140
|
var createInitialAgentState = () => ({
|
|
78
141
|
status: "idle",
|
|
@@ -81,6 +144,16 @@ var createInitialAgentState = () => ({
|
|
|
81
144
|
planThought: "",
|
|
82
145
|
steps: [],
|
|
83
146
|
finalText: "",
|
|
147
|
+
finalReasoning: "",
|
|
148
|
+
totalUsage: emptyUsage(),
|
|
149
|
+
runStartedAt: void 0,
|
|
150
|
+
runMessageId: void 0,
|
|
151
|
+
approvals: [],
|
|
152
|
+
subagents: [],
|
|
153
|
+
skills: [],
|
|
154
|
+
discoveredTools: [],
|
|
155
|
+
compactions: [],
|
|
156
|
+
budget: void 0,
|
|
84
157
|
usage: emptyUsage(),
|
|
85
158
|
modelLoad: void 0,
|
|
86
159
|
replan: void 0,
|
|
@@ -94,20 +167,45 @@ var resetRun = (state) => ({
|
|
|
94
167
|
...createInitialAgentState(),
|
|
95
168
|
status: state.status,
|
|
96
169
|
messages: state.messages,
|
|
170
|
+
totalUsage: state.totalUsage,
|
|
97
171
|
seq: state.seq
|
|
98
172
|
});
|
|
99
173
|
var patchStep = (steps, id, fn) => steps.map((s) => s.id === id ? fn(s) : s);
|
|
100
|
-
var
|
|
174
|
+
var patchApproval = (approvals, id, fn) => approvals.map((a) => a.id === id ? fn(a) : a);
|
|
175
|
+
var patchSubagent = (subagents, id, fn) => subagents.map((s) => s.id === id ? fn(s) : s);
|
|
176
|
+
var runningStepId = (steps) => [...steps].reverse().find((s) => s.status === "running")?.id;
|
|
177
|
+
var applySubagentEvent = (view2, event) => {
|
|
178
|
+
switch (event.type) {
|
|
179
|
+
case "step.start":
|
|
180
|
+
return {
|
|
181
|
+
...view2,
|
|
182
|
+
steps: view2.steps + 1,
|
|
183
|
+
activity: `step ${event.index}/${event.total}: ${event.step.description}`
|
|
184
|
+
};
|
|
185
|
+
case "step.tool-call":
|
|
186
|
+
return { ...view2, toolCalls: view2.toolCalls + 1, activity: `\u2192 ${event.name}` };
|
|
187
|
+
case "final.text-delta":
|
|
188
|
+
return { ...view2, text: view2.text + event.delta, activity: "writing the answer" };
|
|
189
|
+
case "final":
|
|
190
|
+
return { ...view2, text: event.text };
|
|
191
|
+
case "usage":
|
|
192
|
+
return { ...view2, usage: addUsage(view2.usage, event.usage) };
|
|
193
|
+
default:
|
|
194
|
+
return view2;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
var finalizeAssistant = (messages, content, extra = {}) => {
|
|
101
198
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
102
199
|
const m = messages[i];
|
|
103
200
|
if (m.role === "assistant" && m.pending) {
|
|
104
201
|
const next = messages.slice();
|
|
105
|
-
next[i] = { ...m, content: content || m.content, pending: false };
|
|
202
|
+
next[i] = { ...m, content: content || m.content, pending: false, ...extra };
|
|
106
203
|
return next;
|
|
107
204
|
}
|
|
108
205
|
}
|
|
109
206
|
return messages;
|
|
110
207
|
};
|
|
208
|
+
var runDuration = (state, at) => at !== void 0 && state.runStartedAt !== void 0 ? { durationMs: Math.max(0, at - state.runStartedAt) } : {};
|
|
111
209
|
var streamAssistant = (messages, content) => {
|
|
112
210
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
113
211
|
const m = messages[i];
|
|
@@ -119,7 +217,7 @@ var streamAssistant = (messages, content) => {
|
|
|
119
217
|
}
|
|
120
218
|
return messages;
|
|
121
219
|
};
|
|
122
|
-
var applyEvent = (state, event) => {
|
|
220
|
+
var applyEvent = (state, event, ctx) => {
|
|
123
221
|
switch (event.type) {
|
|
124
222
|
case "run.start": {
|
|
125
223
|
const base2 = resetRun(state);
|
|
@@ -128,9 +226,17 @@ var applyEvent = (state, event) => {
|
|
|
128
226
|
return {
|
|
129
227
|
...base2,
|
|
130
228
|
goal: event.goal,
|
|
229
|
+
runStartedAt: ctx.at,
|
|
230
|
+
runMessageId: assistantId,
|
|
131
231
|
messages: [
|
|
132
232
|
...base2.messages,
|
|
133
|
-
{
|
|
233
|
+
{
|
|
234
|
+
id: userId,
|
|
235
|
+
role: "user",
|
|
236
|
+
content: event.goal,
|
|
237
|
+
pending: false,
|
|
238
|
+
...ctx.attachments?.length ? { attachments: ctx.attachments } : {}
|
|
239
|
+
},
|
|
134
240
|
{ id: assistantId, role: "assistant", content: "", pending: true }
|
|
135
241
|
],
|
|
136
242
|
seq: base2.seq + 2
|
|
@@ -151,25 +257,40 @@ var applyEvent = (state, event) => {
|
|
|
151
257
|
case "plan.step-added":
|
|
152
258
|
return state;
|
|
153
259
|
case "step.start": {
|
|
154
|
-
const
|
|
260
|
+
const view2 = {
|
|
155
261
|
id: event.step.id,
|
|
156
262
|
index: event.index,
|
|
157
263
|
total: event.total,
|
|
158
264
|
step: event.step,
|
|
159
265
|
text: "",
|
|
266
|
+
reasoning: "",
|
|
160
267
|
toolCalls: [],
|
|
161
268
|
status: "running",
|
|
162
269
|
blocked: false
|
|
163
270
|
};
|
|
164
|
-
return { ...state, steps: [...state.steps,
|
|
271
|
+
return { ...state, steps: [...state.steps, view2] };
|
|
165
272
|
}
|
|
273
|
+
case "step.reasoning-delta":
|
|
274
|
+
return {
|
|
275
|
+
...state,
|
|
276
|
+
steps: patchStep(state.steps, event.step.id, (s) => ({
|
|
277
|
+
...s,
|
|
278
|
+
reasoning: s.reasoning + event.delta
|
|
279
|
+
}))
|
|
280
|
+
};
|
|
166
281
|
case "step.text-delta":
|
|
167
282
|
return {
|
|
168
283
|
...state,
|
|
169
284
|
steps: patchStep(state.steps, event.step.id, (s) => ({ ...s, text: s.text + event.delta }))
|
|
170
285
|
};
|
|
171
286
|
case "step.tool-call": {
|
|
172
|
-
const call = {
|
|
287
|
+
const call = {
|
|
288
|
+
name: event.name,
|
|
289
|
+
input: event.input,
|
|
290
|
+
status: "calling",
|
|
291
|
+
inputTokens: approxTokens(event.input),
|
|
292
|
+
...ctx.at !== void 0 ? { startedAt: ctx.at } : {}
|
|
293
|
+
};
|
|
173
294
|
return {
|
|
174
295
|
...state,
|
|
175
296
|
steps: patchStep(state.steps, event.step.id, (s) => ({
|
|
@@ -186,7 +307,14 @@ var applyEvent = (state, event) => {
|
|
|
186
307
|
const toolCalls = s.toolCalls.slice().reverse().map((c) => {
|
|
187
308
|
if (!done && c.status === "calling" && c.name === event.name) {
|
|
188
309
|
done = true;
|
|
189
|
-
return {
|
|
310
|
+
return {
|
|
311
|
+
...c,
|
|
312
|
+
output: event.output,
|
|
313
|
+
ok: event.ok,
|
|
314
|
+
status: "done",
|
|
315
|
+
outputTokens: approxTokens(event.output),
|
|
316
|
+
...ctx.at !== void 0 && c.startedAt !== void 0 ? { durationMs: Math.max(0, ctx.at - c.startedAt) } : {}
|
|
317
|
+
};
|
|
190
318
|
}
|
|
191
319
|
return c;
|
|
192
320
|
}).reverse();
|
|
@@ -201,14 +329,27 @@ var applyEvent = (state, event) => {
|
|
|
201
329
|
status: "done",
|
|
202
330
|
summary: event.result.summary,
|
|
203
331
|
blocked: event.result.blocked,
|
|
204
|
-
// The result carries the authoritative, ordered tool-call list
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
332
|
+
// The result carries the authoritative, ordered tool-call list; keep
|
|
333
|
+
// the timing the streamed calls measured (matched in order per name).
|
|
334
|
+
toolCalls: (() => {
|
|
335
|
+
const seen = /* @__PURE__ */ new Map();
|
|
336
|
+
return event.result.toolCalls.map((c) => {
|
|
337
|
+
const nth = seen.get(c.name) ?? 0;
|
|
338
|
+
seen.set(c.name, nth + 1);
|
|
339
|
+
const streamed = s.toolCalls.filter((t) => t.name === c.name)[nth];
|
|
340
|
+
return {
|
|
341
|
+
name: c.name,
|
|
342
|
+
input: c.input,
|
|
343
|
+
output: c.output,
|
|
344
|
+
ok: c.ok,
|
|
345
|
+
status: "done",
|
|
346
|
+
inputTokens: approxTokens(c.input),
|
|
347
|
+
outputTokens: approxTokens(c.output),
|
|
348
|
+
...streamed?.startedAt !== void 0 ? { startedAt: streamed.startedAt } : {},
|
|
349
|
+
...streamed?.durationMs !== void 0 ? { durationMs: streamed.durationMs } : {}
|
|
350
|
+
};
|
|
351
|
+
});
|
|
352
|
+
})()
|
|
212
353
|
}))
|
|
213
354
|
};
|
|
214
355
|
case "replan.decision":
|
|
@@ -221,21 +362,146 @@ var applyEvent = (state, event) => {
|
|
|
221
362
|
return {
|
|
222
363
|
...state,
|
|
223
364
|
finalText: event.text,
|
|
224
|
-
messages: finalizeAssistant(state.messages, event.text)
|
|
365
|
+
messages: finalizeAssistant(state.messages, event.text, runDuration(state, ctx.at))
|
|
225
366
|
};
|
|
367
|
+
case "final.reasoning-delta":
|
|
368
|
+
return { ...state, finalReasoning: state.finalReasoning + event.delta };
|
|
226
369
|
case "usage":
|
|
227
|
-
return {
|
|
370
|
+
return {
|
|
371
|
+
...state,
|
|
372
|
+
usage: addUsage(state.usage, event.usage),
|
|
373
|
+
totalUsage: addUsage(state.totalUsage, event.usage)
|
|
374
|
+
};
|
|
375
|
+
case "tool.approval-requested":
|
|
376
|
+
return {
|
|
377
|
+
...state,
|
|
378
|
+
approvals: [
|
|
379
|
+
...state.approvals,
|
|
380
|
+
{
|
|
381
|
+
id: event.id,
|
|
382
|
+
name: event.name,
|
|
383
|
+
input: event.input,
|
|
384
|
+
readOnly: event.readOnly,
|
|
385
|
+
stepId: event.step?.id,
|
|
386
|
+
status: "pending"
|
|
387
|
+
}
|
|
388
|
+
]
|
|
389
|
+
};
|
|
390
|
+
case "tool.approval-resolved": {
|
|
391
|
+
const known = state.approvals.some((a) => a.id === event.id);
|
|
392
|
+
const decided = (a) => ({
|
|
393
|
+
...a,
|
|
394
|
+
status: event.approved ? "approved" : "denied",
|
|
395
|
+
reason: event.reason,
|
|
396
|
+
automatic: event.automatic
|
|
397
|
+
});
|
|
398
|
+
return {
|
|
399
|
+
...state,
|
|
400
|
+
approvals: known ? patchApproval(state.approvals, event.id, decided) : (
|
|
401
|
+
// A policy denial arrives without a request: record it too.
|
|
402
|
+
[
|
|
403
|
+
...state.approvals,
|
|
404
|
+
decided({
|
|
405
|
+
id: event.id,
|
|
406
|
+
name: event.name,
|
|
407
|
+
input: void 0,
|
|
408
|
+
readOnly: false,
|
|
409
|
+
stepId: runningStepId(state.steps),
|
|
410
|
+
status: "pending"
|
|
411
|
+
})
|
|
412
|
+
]
|
|
413
|
+
)
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
case "subagent.start":
|
|
417
|
+
return {
|
|
418
|
+
...state,
|
|
419
|
+
subagents: [
|
|
420
|
+
...state.subagents,
|
|
421
|
+
{
|
|
422
|
+
id: event.id,
|
|
423
|
+
name: event.name,
|
|
424
|
+
task: event.task,
|
|
425
|
+
status: "running",
|
|
426
|
+
stepId: runningStepId(state.steps),
|
|
427
|
+
activity: "starting",
|
|
428
|
+
steps: 0,
|
|
429
|
+
toolCalls: 0,
|
|
430
|
+
text: "",
|
|
431
|
+
usage: emptyUsage()
|
|
432
|
+
}
|
|
433
|
+
]
|
|
434
|
+
};
|
|
435
|
+
case "subagent.event":
|
|
436
|
+
return {
|
|
437
|
+
...state,
|
|
438
|
+
subagents: patchSubagent(
|
|
439
|
+
state.subagents,
|
|
440
|
+
event.id,
|
|
441
|
+
(s) => applySubagentEvent(s, event.event)
|
|
442
|
+
)
|
|
443
|
+
};
|
|
444
|
+
case "subagent.complete":
|
|
445
|
+
return {
|
|
446
|
+
...state,
|
|
447
|
+
subagents: patchSubagent(state.subagents, event.id, (s) => ({
|
|
448
|
+
...s,
|
|
449
|
+
status: "done",
|
|
450
|
+
activity: "done",
|
|
451
|
+
text: event.text,
|
|
452
|
+
usage: event.usage
|
|
453
|
+
}))
|
|
454
|
+
};
|
|
455
|
+
case "subagent.error":
|
|
456
|
+
return {
|
|
457
|
+
...state,
|
|
458
|
+
subagents: patchSubagent(state.subagents, event.id, (s) => ({
|
|
459
|
+
...s,
|
|
460
|
+
status: "error",
|
|
461
|
+
activity: "failed",
|
|
462
|
+
error: event.error
|
|
463
|
+
}))
|
|
464
|
+
};
|
|
465
|
+
case "skill.activated":
|
|
466
|
+
return state.skills.includes(event.name) ? state : { ...state, skills: [...state.skills, event.name] };
|
|
467
|
+
case "tools.discovered":
|
|
468
|
+
return {
|
|
469
|
+
...state,
|
|
470
|
+
discoveredTools: [.../* @__PURE__ */ new Set([...state.discoveredTools, ...event.names])]
|
|
471
|
+
};
|
|
472
|
+
case "context.compacted":
|
|
473
|
+
return {
|
|
474
|
+
...state,
|
|
475
|
+
compactions: [
|
|
476
|
+
...state.compactions,
|
|
477
|
+
{ scope: event.scope, beforeTokens: event.beforeTokens, afterTokens: event.afterTokens }
|
|
478
|
+
]
|
|
479
|
+
};
|
|
480
|
+
case "budget.exceeded":
|
|
481
|
+
return { ...state, budget: { kind: event.kind, tokens: event.tokens, cap: event.cap } };
|
|
228
482
|
case "stopped":
|
|
229
483
|
return {
|
|
230
484
|
...state,
|
|
231
485
|
stopped: true,
|
|
232
|
-
|
|
486
|
+
// Nothing is waiting any more once the run has stopped.
|
|
487
|
+
approvals: state.approvals.map(
|
|
488
|
+
(a) => a.status === "pending" ? { ...a, status: "denied", reason: "stopped" } : a
|
|
489
|
+
),
|
|
490
|
+
messages: finalizeAssistant(
|
|
491
|
+
state.messages,
|
|
492
|
+
state.finalText || "Stopped.",
|
|
493
|
+
runDuration(state, ctx.at)
|
|
494
|
+
)
|
|
233
495
|
};
|
|
234
496
|
case "error":
|
|
235
497
|
return event.phase === "run" ? {
|
|
236
498
|
...state,
|
|
237
499
|
error: event.error,
|
|
238
|
-
messages: finalizeAssistant(
|
|
500
|
+
messages: finalizeAssistant(
|
|
501
|
+
state.messages,
|
|
502
|
+
state.finalText || `Error: ${event.error}`,
|
|
503
|
+
{ ...runDuration(state, ctx.at), error: true }
|
|
504
|
+
)
|
|
239
505
|
} : { ...state, error: event.error };
|
|
240
506
|
case "retry":
|
|
241
507
|
return state;
|
|
@@ -243,6 +509,27 @@ var applyEvent = (state, event) => {
|
|
|
243
509
|
return state;
|
|
244
510
|
}
|
|
245
511
|
};
|
|
512
|
+
var syncRunMessage = (state) => {
|
|
513
|
+
const id = state.runMessageId;
|
|
514
|
+
if (!id) return state;
|
|
515
|
+
const i = state.messages.findIndex((m2) => m2.id === id);
|
|
516
|
+
if (i < 0) return state;
|
|
517
|
+
const m = state.messages[i];
|
|
518
|
+
const decided = state.approvals.filter((a) => a.status !== "pending");
|
|
519
|
+
const patch = {};
|
|
520
|
+
if (m.steps !== state.steps) patch.steps = state.steps;
|
|
521
|
+
if (m.subagents !== state.subagents) patch.subagents = state.subagents;
|
|
522
|
+
if (m.usage !== state.usage) patch.usage = state.usage;
|
|
523
|
+
if ((m.reasoning ?? "") !== state.finalReasoning) patch.reasoning = state.finalReasoning;
|
|
524
|
+
if (m.skills !== state.skills) patch.skills = state.skills;
|
|
525
|
+
if ((m.approvals?.length ?? 0) !== decided.length || decided.some((a, k) => m.approvals?.[k] !== a)) {
|
|
526
|
+
patch.approvals = decided;
|
|
527
|
+
}
|
|
528
|
+
if (Object.keys(patch).length === 0) return state;
|
|
529
|
+
const messages = state.messages.slice();
|
|
530
|
+
messages[i] = { ...m, ...patch };
|
|
531
|
+
return { ...state, messages };
|
|
532
|
+
};
|
|
246
533
|
var agentStateReducer = (state, action) => {
|
|
247
534
|
switch (action.type) {
|
|
248
535
|
case "reset":
|
|
@@ -254,11 +541,26 @@ var agentStateReducer = (state, action) => {
|
|
|
254
541
|
error: action.status === "error" ? action.error : void 0
|
|
255
542
|
};
|
|
256
543
|
case "event": {
|
|
257
|
-
const next =
|
|
544
|
+
const next = syncRunMessage(
|
|
545
|
+
applyEvent(state, action.event, { at: action.at, attachments: action.attachments })
|
|
546
|
+
);
|
|
258
547
|
const cap = action.maxEvents ?? 200;
|
|
259
548
|
const events = cap > 0 ? [...state.events, action.event].slice(-cap) : [...state.events, action.event];
|
|
260
549
|
return { ...next, events };
|
|
261
550
|
}
|
|
551
|
+
case "load": {
|
|
552
|
+
const maxSeq = action.messages.reduce((n, m) => {
|
|
553
|
+
const k = Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1);
|
|
554
|
+
return Math.max(n, k + 1);
|
|
555
|
+
}, state.seq);
|
|
556
|
+
return {
|
|
557
|
+
...createInitialAgentState(),
|
|
558
|
+
status: state.status,
|
|
559
|
+
messages: action.messages.map((m) => m.pending ? { ...m, pending: false } : m),
|
|
560
|
+
totalUsage: action.totalUsage ?? emptyUsage(),
|
|
561
|
+
seq: maxSeq
|
|
562
|
+
};
|
|
563
|
+
}
|
|
262
564
|
default:
|
|
263
565
|
return state;
|
|
264
566
|
}
|
|
@@ -277,6 +579,31 @@ var useAgent = (config, options = {}) => {
|
|
|
277
579
|
configRef.current = config;
|
|
278
580
|
const optionsRef = (0, import_react.useRef)(options);
|
|
279
581
|
optionsRef.current = options;
|
|
582
|
+
const resolversRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
|
583
|
+
const settleAll = (0, import_react.useCallback)((decision) => {
|
|
584
|
+
for (const resolve of resolversRef.current.values()) resolve(decision);
|
|
585
|
+
resolversRef.current.clear();
|
|
586
|
+
}, []);
|
|
587
|
+
const uiOnRequest = (0, import_react.useCallback)(
|
|
588
|
+
(req2) => new Promise((resolve) => {
|
|
589
|
+
resolversRef.current.set(req2.id, resolve);
|
|
590
|
+
}),
|
|
591
|
+
[]
|
|
592
|
+
);
|
|
593
|
+
const [sessionId, setSessionId] = (0, import_react.useState)(config.sessionId ?? "default");
|
|
594
|
+
const sessionRef = (0, import_react.useRef)(sessionId);
|
|
595
|
+
sessionRef.current = sessionId;
|
|
596
|
+
const configMode = config.toolApproval?.mode ?? "autopilot";
|
|
597
|
+
const [approvalMode, setApprovalModeState] = (0, import_react.useState)(configMode);
|
|
598
|
+
const modeRef = (0, import_react.useRef)(configMode);
|
|
599
|
+
const setApprovalMode = (0, import_react.useCallback)((mode) => {
|
|
600
|
+
modeRef.current = mode;
|
|
601
|
+
agentRef.current?.setToolApprovalMode(mode);
|
|
602
|
+
setApprovalModeState(mode);
|
|
603
|
+
}, []);
|
|
604
|
+
(0, import_react.useEffect)(() => {
|
|
605
|
+
if (configMode !== modeRef.current) setApprovalMode(configMode);
|
|
606
|
+
}, [configMode, setApprovalMode]);
|
|
280
607
|
const reload = (0, import_react.useCallback)(() => setGeneration((g) => g + 1), []);
|
|
281
608
|
const { autoStart, deps } = options;
|
|
282
609
|
(0, import_react.useEffect)(() => {
|
|
@@ -287,10 +614,16 @@ var useAgent = (config, options = {}) => {
|
|
|
287
614
|
dispatch({ type: "status", status: "idle" });
|
|
288
615
|
return;
|
|
289
616
|
}
|
|
617
|
+
const routeApprovals = optionsRef.current.approvals !== false && !cfg.toolApproval?.onRequest;
|
|
618
|
+
const built = routeApprovals ? {
|
|
619
|
+
...cfg,
|
|
620
|
+
toolApproval: { ...cfg.toolApproval, mode: modeRef.current, onRequest: uiOnRequest }
|
|
621
|
+
} : cfg;
|
|
290
622
|
let cancelled = false;
|
|
291
623
|
dispatch({ type: "status", status: "initializing" });
|
|
292
|
-
(0, import_agent_web.createAgent)(
|
|
624
|
+
(0, import_agent_web.createAgent)(built).then((agent) => {
|
|
293
625
|
if (cancelled) return;
|
|
626
|
+
agent.setToolApprovalMode(modeRef.current);
|
|
294
627
|
agentRef.current = agent;
|
|
295
628
|
dispatch({ type: "status", status: "ready" });
|
|
296
629
|
}).catch((err) => {
|
|
@@ -301,38 +634,106 @@ var useAgent = (config, options = {}) => {
|
|
|
301
634
|
cancelled = true;
|
|
302
635
|
};
|
|
303
636
|
}, [generation, autoStart, ...deps ?? []]);
|
|
304
|
-
(0, import_react.useEffect)(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
637
|
+
(0, import_react.useEffect)(
|
|
638
|
+
() => () => {
|
|
639
|
+
abortRef.current?.abort();
|
|
640
|
+
settleAll({ approved: false, reason: "the view was closed" });
|
|
641
|
+
},
|
|
642
|
+
[settleAll]
|
|
643
|
+
);
|
|
644
|
+
const run = (0, import_react.useCallback)(
|
|
645
|
+
async (goal, runOptions) => {
|
|
646
|
+
const agent = agentRef.current;
|
|
647
|
+
if (!agent || abortRef.current) return void 0;
|
|
648
|
+
const controller = new AbortController();
|
|
649
|
+
abortRef.current = controller;
|
|
650
|
+
dispatch({ type: "status", status: "running" });
|
|
651
|
+
try {
|
|
652
|
+
return await agent.run(goal, {
|
|
653
|
+
signal: controller.signal,
|
|
654
|
+
sessionId: sessionRef.current,
|
|
655
|
+
...runOptions?.images?.length ? { images: runOptions.images } : {},
|
|
656
|
+
...runOptions?.files?.length ? { files: runOptions.files } : {},
|
|
657
|
+
onEvent: (event) => {
|
|
658
|
+
const start = event.type === "run.start";
|
|
659
|
+
const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
|
|
660
|
+
dispatch({
|
|
661
|
+
type: "event",
|
|
662
|
+
event: shown,
|
|
663
|
+
maxEvents: optionsRef.current.maxEvents,
|
|
664
|
+
at: Date.now(),
|
|
665
|
+
...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
666
|
+
});
|
|
667
|
+
try {
|
|
668
|
+
optionsRef.current.onEvent?.(event);
|
|
669
|
+
} catch {
|
|
670
|
+
}
|
|
319
671
|
}
|
|
320
|
-
}
|
|
321
|
-
})
|
|
322
|
-
|
|
672
|
+
});
|
|
673
|
+
} catch (err) {
|
|
674
|
+
dispatch({
|
|
675
|
+
type: "event",
|
|
676
|
+
event: { type: "error", phase: "run", error: errMessage(err) },
|
|
677
|
+
maxEvents: optionsRef.current.maxEvents
|
|
678
|
+
});
|
|
679
|
+
return void 0;
|
|
680
|
+
} finally {
|
|
681
|
+
abortRef.current = void 0;
|
|
682
|
+
settleAll({ approved: false, reason: "the run ended" });
|
|
683
|
+
dispatch({ type: "status", status: "ready" });
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
[settleAll]
|
|
687
|
+
);
|
|
688
|
+
const stop = (0, import_react.useCallback)(() => {
|
|
689
|
+
abortRef.current?.abort();
|
|
690
|
+
settleAll({ approved: false, reason: "stopped by the user" });
|
|
691
|
+
}, [settleAll]);
|
|
692
|
+
const reset = (0, import_react.useCallback)(() => {
|
|
693
|
+
dispatch({ type: "reset" });
|
|
694
|
+
void configRef.current.memory?.clear(sessionRef.current).catch(() => {
|
|
695
|
+
});
|
|
696
|
+
}, []);
|
|
697
|
+
const loadChat = (0, import_react.useCallback)(
|
|
698
|
+
(chat) => {
|
|
699
|
+
abortRef.current?.abort();
|
|
700
|
+
sessionRef.current = chat.sessionId;
|
|
701
|
+
setSessionId(chat.sessionId);
|
|
702
|
+
dispatch({ type: "load", messages: chat.messages ?? [], totalUsage: chat.totalUsage });
|
|
703
|
+
},
|
|
704
|
+
[]
|
|
705
|
+
);
|
|
706
|
+
const approve = (0, import_react.useCallback)((id, opts) => {
|
|
707
|
+
const resolve = resolversRef.current.get(id);
|
|
708
|
+
if (!resolve) return;
|
|
709
|
+
resolversRef.current.delete(id);
|
|
710
|
+
resolve({ approved: true, remember: opts?.remember });
|
|
711
|
+
}, []);
|
|
712
|
+
const deny = (0, import_react.useCallback)((id, reason) => {
|
|
713
|
+
const resolve = resolversRef.current.get(id);
|
|
714
|
+
if (!resolve) return;
|
|
715
|
+
resolversRef.current.delete(id);
|
|
716
|
+
resolve({ approved: false, reason });
|
|
717
|
+
}, []);
|
|
718
|
+
const compact = (0, import_react.useCallback)(async () => {
|
|
719
|
+
const agent = agentRef.current;
|
|
720
|
+
if (!agent) return void 0;
|
|
721
|
+
const result = await agent.compact({ sessionId: sessionRef.current });
|
|
722
|
+
if (result.compacted) {
|
|
323
723
|
dispatch({
|
|
324
724
|
type: "event",
|
|
325
|
-
event: {
|
|
326
|
-
|
|
725
|
+
event: {
|
|
726
|
+
type: "context.compacted",
|
|
727
|
+
scope: "history",
|
|
728
|
+
beforeTokens: result.beforeTokens,
|
|
729
|
+
afterTokens: result.afterTokens
|
|
730
|
+
},
|
|
731
|
+
maxEvents: optionsRef.current.maxEvents,
|
|
732
|
+
at: Date.now()
|
|
327
733
|
});
|
|
328
|
-
return void 0;
|
|
329
|
-
} finally {
|
|
330
|
-
abortRef.current = void 0;
|
|
331
|
-
dispatch({ type: "status", status: "ready" });
|
|
332
734
|
}
|
|
735
|
+
return result;
|
|
333
736
|
}, []);
|
|
334
|
-
const stop = (0, import_react.useCallback)(() => abortRef.current?.abort(), []);
|
|
335
|
-
const reset = (0, import_react.useCallback)(() => dispatch({ type: "reset" }), []);
|
|
336
737
|
return {
|
|
337
738
|
...state,
|
|
338
739
|
run,
|
|
@@ -341,31 +742,311 @@ var useAgent = (config, options = {}) => {
|
|
|
341
742
|
reload,
|
|
342
743
|
agent: agentRef.current,
|
|
343
744
|
isRunning: state.status === "running",
|
|
344
|
-
isReady: state.status === "ready"
|
|
745
|
+
isReady: state.status === "ready",
|
|
746
|
+
pendingApprovals: state.approvals.filter((a) => a.status === "pending"),
|
|
747
|
+
approve,
|
|
748
|
+
deny,
|
|
749
|
+
approvalMode,
|
|
750
|
+
setApprovalMode,
|
|
751
|
+
compact,
|
|
752
|
+
sessionId,
|
|
753
|
+
loadChat
|
|
345
754
|
};
|
|
346
755
|
};
|
|
347
756
|
|
|
348
|
-
// src/hooks/use-
|
|
757
|
+
// src/hooks/use-chat-history.ts
|
|
349
758
|
var import_react2 = require("react");
|
|
759
|
+
|
|
760
|
+
// src/chat-history.ts
|
|
761
|
+
var DB_VERSION = 1;
|
|
762
|
+
var req = (r) => new Promise((resolve, reject) => {
|
|
763
|
+
r.onsuccess = () => resolve(r.result);
|
|
764
|
+
r.onerror = () => reject(r.error);
|
|
765
|
+
});
|
|
766
|
+
var ChatHistoryStore = class {
|
|
767
|
+
dbName;
|
|
768
|
+
storeName;
|
|
769
|
+
memory;
|
|
770
|
+
db;
|
|
771
|
+
constructor(opts = {}) {
|
|
772
|
+
this.dbName = opts.dbName ?? "agent-web-react";
|
|
773
|
+
this.storeName = opts.storeName ?? "chats";
|
|
774
|
+
if (opts.memory || typeof indexedDB === "undefined") this.memory = /* @__PURE__ */ new Map();
|
|
775
|
+
}
|
|
776
|
+
open() {
|
|
777
|
+
this.db ??= new Promise((resolve, reject) => {
|
|
778
|
+
const r = indexedDB.open(this.dbName, DB_VERSION);
|
|
779
|
+
r.onupgradeneeded = () => {
|
|
780
|
+
if (!r.result.objectStoreNames.contains(this.storeName)) {
|
|
781
|
+
r.result.createObjectStore(this.storeName, { keyPath: "id" });
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
r.onsuccess = () => resolve(r.result);
|
|
785
|
+
r.onerror = () => reject(r.error);
|
|
786
|
+
}).catch((err) => {
|
|
787
|
+
this.db = void 0;
|
|
788
|
+
throw err;
|
|
789
|
+
});
|
|
790
|
+
return this.db;
|
|
791
|
+
}
|
|
792
|
+
async tx(mode) {
|
|
793
|
+
const db = await this.open();
|
|
794
|
+
return db.transaction(this.storeName, mode).objectStore(this.storeName);
|
|
795
|
+
}
|
|
796
|
+
async list() {
|
|
797
|
+
const all = this.memory ? [...this.memory.values()] : await req((await this.tx("readonly")).getAll());
|
|
798
|
+
return all.map(({ messages, ...rest }) => ({ ...rest, messageCount: messages.length })).sort((a, b) => b.updatedAt - a.updatedAt);
|
|
799
|
+
}
|
|
800
|
+
async get(id) {
|
|
801
|
+
if (this.memory) return this.memory.get(id);
|
|
802
|
+
return req((await this.tx("readonly")).get(id));
|
|
803
|
+
}
|
|
804
|
+
async put(record) {
|
|
805
|
+
if (this.memory) {
|
|
806
|
+
this.memory.set(record.id, structuredClone(record));
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
await req((await this.tx("readwrite")).put(record));
|
|
810
|
+
}
|
|
811
|
+
async delete(id) {
|
|
812
|
+
if (this.memory) {
|
|
813
|
+
this.memory.delete(id);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
await req((await this.tx("readwrite")).delete(id));
|
|
817
|
+
}
|
|
818
|
+
async clear() {
|
|
819
|
+
if (this.memory) {
|
|
820
|
+
this.memory.clear();
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
await req((await this.tx("readwrite")).clear());
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
var chatTitle = (messages) => {
|
|
827
|
+
const first = messages.find((m) => m.role === "user")?.content.replace(/\s+/g, " ").trim();
|
|
828
|
+
if (!first) return "New chat";
|
|
829
|
+
return first.length > 60 ? `${first.slice(0, 59)}\u2026` : first;
|
|
830
|
+
};
|
|
831
|
+
var newChatId = () => `chat-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
832
|
+
|
|
833
|
+
// src/hooks/use-chat-history.ts
|
|
834
|
+
var useChatHistory = (agent, options = {}) => {
|
|
835
|
+
const enabled = options.enabled !== false;
|
|
836
|
+
const store = (0, import_react2.useMemo)(() => options.store ?? new ChatHistoryStore(), [options.store]);
|
|
837
|
+
const [chats, setChats] = (0, import_react2.useState)([]);
|
|
838
|
+
const [loading, setLoading] = (0, import_react2.useState)(enabled);
|
|
839
|
+
const createdRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
840
|
+
const agentRef = (0, import_react2.useRef)(agent);
|
|
841
|
+
agentRef.current = agent;
|
|
842
|
+
const refresh = (0, import_react2.useCallback)(async () => {
|
|
843
|
+
try {
|
|
844
|
+
setChats(await store.list());
|
|
845
|
+
} catch {
|
|
846
|
+
}
|
|
847
|
+
}, [store]);
|
|
848
|
+
const newChat = (0, import_react2.useCallback)(() => {
|
|
849
|
+
agentRef.current.loadChat({ sessionId: newChatId(), messages: [] });
|
|
850
|
+
}, []);
|
|
851
|
+
const select = (0, import_react2.useCallback)(
|
|
852
|
+
async (id) => {
|
|
853
|
+
const record = await store.get(id).catch(() => void 0);
|
|
854
|
+
if (!record) return;
|
|
855
|
+
createdRef.current.set(id, record.createdAt);
|
|
856
|
+
agentRef.current.loadChat({
|
|
857
|
+
sessionId: record.id,
|
|
858
|
+
messages: record.messages,
|
|
859
|
+
totalUsage: record.totalUsage
|
|
860
|
+
});
|
|
861
|
+
},
|
|
862
|
+
[store]
|
|
863
|
+
);
|
|
864
|
+
const remove = (0, import_react2.useCallback)(
|
|
865
|
+
async (id) => {
|
|
866
|
+
await store.delete(id).catch(() => {
|
|
867
|
+
});
|
|
868
|
+
if (id === agentRef.current.sessionId) newChat();
|
|
869
|
+
await refresh();
|
|
870
|
+
},
|
|
871
|
+
[store, newChat, refresh]
|
|
872
|
+
);
|
|
873
|
+
(0, import_react2.useEffect)(() => {
|
|
874
|
+
if (!enabled) return;
|
|
875
|
+
let active = true;
|
|
876
|
+
void (async () => {
|
|
877
|
+
const list = await store.list().catch(() => []);
|
|
878
|
+
if (!active) return;
|
|
879
|
+
setChats(list);
|
|
880
|
+
if (options.resumeLatest !== false && list[0]) await select(list[0].id);
|
|
881
|
+
else newChat();
|
|
882
|
+
setLoading(false);
|
|
883
|
+
})();
|
|
884
|
+
return () => {
|
|
885
|
+
active = false;
|
|
886
|
+
};
|
|
887
|
+
}, [enabled, store]);
|
|
888
|
+
const { messages, totalUsage, sessionId, isRunning } = agent;
|
|
889
|
+
(0, import_react2.useEffect)(() => {
|
|
890
|
+
if (!enabled || loading || isRunning || messages.length === 0) return;
|
|
891
|
+
const now = Date.now();
|
|
892
|
+
const createdAt = createdRef.current.get(sessionId) ?? now;
|
|
893
|
+
createdRef.current.set(sessionId, createdAt);
|
|
894
|
+
const record = {
|
|
895
|
+
id: sessionId,
|
|
896
|
+
title: chatTitle(messages),
|
|
897
|
+
createdAt,
|
|
898
|
+
updatedAt: now,
|
|
899
|
+
messages,
|
|
900
|
+
totalUsage
|
|
901
|
+
};
|
|
902
|
+
void store.put(record).then(refresh).catch(() => {
|
|
903
|
+
});
|
|
904
|
+
}, [enabled, loading, isRunning, messages, totalUsage, sessionId, store, refresh]);
|
|
905
|
+
return { chats, currentId: sessionId, loading, select, newChat, remove };
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
// src/hooks/use-virtual-files.ts
|
|
909
|
+
var import_react3 = require("react");
|
|
910
|
+
var readDataUrl = (file) => new Promise((resolve, reject) => {
|
|
911
|
+
const r = new FileReader();
|
|
912
|
+
r.onload = () => resolve(String(r.result));
|
|
913
|
+
r.onerror = () => reject(r.error ?? new Error("could not read the file"));
|
|
914
|
+
r.readAsDataURL(file);
|
|
915
|
+
});
|
|
916
|
+
var useVirtualFiles = (vfs, prefix = "/") => {
|
|
917
|
+
const [files, setFiles] = (0, import_react3.useState)([]);
|
|
918
|
+
const [loading, setLoading] = (0, import_react3.useState)(Boolean(vfs));
|
|
919
|
+
const [error, setError] = (0, import_react3.useState)();
|
|
920
|
+
const refresh = (0, import_react3.useCallback)(async () => {
|
|
921
|
+
if (!vfs) return;
|
|
922
|
+
try {
|
|
923
|
+
setFiles(await vfs.list(prefix));
|
|
924
|
+
setError(void 0);
|
|
925
|
+
} catch (err) {
|
|
926
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
927
|
+
} finally {
|
|
928
|
+
setLoading(false);
|
|
929
|
+
}
|
|
930
|
+
}, [vfs, prefix]);
|
|
931
|
+
(0, import_react3.useEffect)(() => {
|
|
932
|
+
if (!vfs) return;
|
|
933
|
+
void refresh();
|
|
934
|
+
return vfs.onChange(() => void refresh());
|
|
935
|
+
}, [vfs, refresh]);
|
|
936
|
+
const upload = (0, import_react3.useCallback)(
|
|
937
|
+
async (file, dir = "/uploads") => {
|
|
938
|
+
if (!vfs) return;
|
|
939
|
+
const path = `${dir.replace(/\/$/, "")}/${file.name.replace(/[^\w.-]+/g, "_") || "file"}`;
|
|
940
|
+
const type = file.type || "application/octet-stream";
|
|
941
|
+
if (type.startsWith("text/") || /json|xml|yaml|markdown|csv/.test(type)) {
|
|
942
|
+
await vfs.write(path, await file.text(), { mimeType: type });
|
|
943
|
+
} else {
|
|
944
|
+
await vfs.writeDataUrl(path, await readDataUrl(file));
|
|
945
|
+
}
|
|
946
|
+
},
|
|
947
|
+
[vfs]
|
|
948
|
+
);
|
|
949
|
+
const remove = (0, import_react3.useCallback)(
|
|
950
|
+
async (path) => {
|
|
951
|
+
await vfs?.delete(path);
|
|
952
|
+
},
|
|
953
|
+
[vfs]
|
|
954
|
+
);
|
|
955
|
+
const dataUrl = (0, import_react3.useCallback)(async (path) => vfs?.readDataUrl(path), [vfs]);
|
|
956
|
+
const text = (0, import_react3.useCallback)(
|
|
957
|
+
async (path) => {
|
|
958
|
+
const f = await vfs?.read(path);
|
|
959
|
+
return f && f.encoding === "utf8" ? f.content : void 0;
|
|
960
|
+
},
|
|
961
|
+
[vfs]
|
|
962
|
+
);
|
|
963
|
+
return { files, loading, error, refresh, upload, remove, dataUrl, text };
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
// src/hooks/use-speech-to-text.ts
|
|
967
|
+
var import_react4 = require("react");
|
|
968
|
+
var browserRecognizer = () => {
|
|
969
|
+
const g = globalThis;
|
|
970
|
+
const Ctor = g.SpeechRecognition ?? g.webkitSpeechRecognition;
|
|
971
|
+
return Ctor ? () => new Ctor() : void 0;
|
|
972
|
+
};
|
|
973
|
+
var useSpeechToText = (options = {}) => {
|
|
974
|
+
const optionsRef = (0, import_react4.useRef)(options);
|
|
975
|
+
optionsRef.current = options;
|
|
976
|
+
const factory = options.createRecognizer ?? browserRecognizer();
|
|
977
|
+
const [listening, setListening] = (0, import_react4.useState)(false);
|
|
978
|
+
const [interim, setInterim] = (0, import_react4.useState)("");
|
|
979
|
+
const [error, setError] = (0, import_react4.useState)();
|
|
980
|
+
const recRef = (0, import_react4.useRef)(void 0);
|
|
981
|
+
const stop = (0, import_react4.useCallback)(() => {
|
|
982
|
+
recRef.current?.stop();
|
|
983
|
+
}, []);
|
|
984
|
+
const start = (0, import_react4.useCallback)(() => {
|
|
985
|
+
if (!factory || recRef.current) return;
|
|
986
|
+
const rec = factory();
|
|
987
|
+
rec.lang = optionsRef.current.lang ?? (typeof navigator !== "undefined" ? navigator.language : void 0) ?? "en-US";
|
|
988
|
+
rec.continuous = optionsRef.current.continuous !== false;
|
|
989
|
+
rec.interimResults = true;
|
|
990
|
+
rec.onresult = (ev) => {
|
|
991
|
+
let pending = "";
|
|
992
|
+
for (let i = ev.resultIndex; i < ev.results.length; i += 1) {
|
|
993
|
+
const r = ev.results[i];
|
|
994
|
+
if (r.isFinal) optionsRef.current.onFinal?.(r[0].transcript.trim());
|
|
995
|
+
else pending += r[0].transcript;
|
|
996
|
+
}
|
|
997
|
+
setInterim(pending);
|
|
998
|
+
};
|
|
999
|
+
rec.onerror = (ev) => {
|
|
1000
|
+
if (ev.error && ev.error !== "no-speech" && ev.error !== "aborted") setError(ev.error);
|
|
1001
|
+
};
|
|
1002
|
+
rec.onend = () => {
|
|
1003
|
+
recRef.current = void 0;
|
|
1004
|
+
setListening(false);
|
|
1005
|
+
setInterim("");
|
|
1006
|
+
};
|
|
1007
|
+
recRef.current = rec;
|
|
1008
|
+
setError(void 0);
|
|
1009
|
+
try {
|
|
1010
|
+
rec.start();
|
|
1011
|
+
setListening(true);
|
|
1012
|
+
} catch (err) {
|
|
1013
|
+
recRef.current = void 0;
|
|
1014
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
1015
|
+
}
|
|
1016
|
+
}, [factory]);
|
|
1017
|
+
(0, import_react4.useEffect)(() => () => recRef.current?.abort?.(), []);
|
|
1018
|
+
return {
|
|
1019
|
+
supported: Boolean(factory),
|
|
1020
|
+
listening,
|
|
1021
|
+
interim,
|
|
1022
|
+
error,
|
|
1023
|
+
start,
|
|
1024
|
+
stop,
|
|
1025
|
+
toggle: () => recRef.current ? stop() : start()
|
|
1026
|
+
};
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
// src/hooks/use-credentials.ts
|
|
1030
|
+
var import_react5 = require("react");
|
|
350
1031
|
var import_agent_web2 = require("@dudko.dev/agent-web");
|
|
351
1032
|
var useCredentials = (store) => {
|
|
352
|
-
const resolved = (0,
|
|
353
|
-
const [version, setVersion] = (0,
|
|
354
|
-
const setKey = (0,
|
|
1033
|
+
const resolved = (0, import_react5.useMemo)(() => store ?? new import_agent_web2.VaultCredentialStore(), [store]);
|
|
1034
|
+
const [version, setVersion] = (0, import_react5.useState)(0);
|
|
1035
|
+
const setKey = (0, import_react5.useCallback)(
|
|
355
1036
|
async (ref, key) => {
|
|
356
1037
|
await resolved.setApiKey(ref, key);
|
|
357
1038
|
setVersion((v) => v + 1);
|
|
358
1039
|
},
|
|
359
1040
|
[resolved]
|
|
360
1041
|
);
|
|
361
|
-
const removeKey = (0,
|
|
1042
|
+
const removeKey = (0, import_react5.useCallback)(
|
|
362
1043
|
async (ref) => {
|
|
363
1044
|
await resolved.deleteApiKey(ref);
|
|
364
1045
|
setVersion((v) => v + 1);
|
|
365
1046
|
},
|
|
366
1047
|
[resolved]
|
|
367
1048
|
);
|
|
368
|
-
const hasKey = (0,
|
|
1049
|
+
const hasKey = (0, import_react5.useCallback)(
|
|
369
1050
|
async (ref) => await resolved.getApiKey(ref) !== void 0,
|
|
370
1051
|
[resolved]
|
|
371
1052
|
);
|
|
@@ -373,7 +1054,7 @@ var useCredentials = (store) => {
|
|
|
373
1054
|
};
|
|
374
1055
|
|
|
375
1056
|
// src/hooks/use-mcp.ts
|
|
376
|
-
var
|
|
1057
|
+
var import_react6 = require("react");
|
|
377
1058
|
var OAUTH_UNSUPPORTED = "The installed @dudko.dev/agent-web has no MCP OAuth support. Upgrade the core to a version exporting BrowserOAuthProvider, or use a static Authorization header.";
|
|
378
1059
|
var PENDING_KEY = "agent-web-react:mcp:pending";
|
|
379
1060
|
var OAUTH_KEY = "agent-web-react:mcp:oauth";
|
|
@@ -486,27 +1167,27 @@ var watchAuthorization = (tools, mod, onUnauthorized) => {
|
|
|
486
1167
|
return Object.fromEntries(entries);
|
|
487
1168
|
};
|
|
488
1169
|
var useMcp = (options = {}) => {
|
|
489
|
-
const [status, setStatus] = (0,
|
|
490
|
-
const [tools, setTools] = (0,
|
|
491
|
-
const [catalog, setCatalog] = (0,
|
|
492
|
-
const [error, setError] = (0,
|
|
493
|
-
const [authorizationUrl, setAuthorizationUrl] = (0,
|
|
494
|
-
const [oauthSupported, setOauthSupported] = (0,
|
|
495
|
-
const [completingAuthorization, setCompletingAuthorization] = (0,
|
|
1170
|
+
const [status, setStatus] = (0, import_react6.useState)("idle");
|
|
1171
|
+
const [tools, setTools] = (0, import_react6.useState)(void 0);
|
|
1172
|
+
const [catalog, setCatalog] = (0, import_react6.useState)([]);
|
|
1173
|
+
const [error, setError] = (0, import_react6.useState)(void 0);
|
|
1174
|
+
const [authorizationUrl, setAuthorizationUrl] = (0, import_react6.useState)(void 0);
|
|
1175
|
+
const [oauthSupported, setOauthSupported] = (0, import_react6.useState)(void 0);
|
|
1176
|
+
const [completingAuthorization, setCompletingAuthorization] = (0, import_react6.useState)(
|
|
496
1177
|
() => readCallbackParams() !== void 0
|
|
497
1178
|
);
|
|
498
|
-
const connectionRef = (0,
|
|
499
|
-
const providerRef = (0,
|
|
500
|
-
const epochRef = (0,
|
|
501
|
-
const optionsRef = (0,
|
|
1179
|
+
const connectionRef = (0, import_react6.useRef)(void 0);
|
|
1180
|
+
const providerRef = (0, import_react6.useRef)(void 0);
|
|
1181
|
+
const epochRef = (0, import_react6.useRef)(0);
|
|
1182
|
+
const optionsRef = (0, import_react6.useRef)(options);
|
|
502
1183
|
optionsRef.current = options;
|
|
503
|
-
const closeConnection = (0,
|
|
1184
|
+
const closeConnection = (0, import_react6.useCallback)(async () => {
|
|
504
1185
|
const open = connectionRef.current;
|
|
505
1186
|
connectionRef.current = void 0;
|
|
506
1187
|
if (open) await open.close().catch(() => {
|
|
507
1188
|
});
|
|
508
1189
|
}, []);
|
|
509
|
-
const checkOAuthSupport = (0,
|
|
1190
|
+
const checkOAuthSupport = (0, import_react6.useCallback)(async () => {
|
|
510
1191
|
try {
|
|
511
1192
|
const mod = await loadMcp();
|
|
512
1193
|
const supported = typeof mod.BrowserOAuthProvider === "function";
|
|
@@ -517,7 +1198,7 @@ var useMcp = (options = {}) => {
|
|
|
517
1198
|
return false;
|
|
518
1199
|
}
|
|
519
1200
|
}, []);
|
|
520
|
-
const connect = (0,
|
|
1201
|
+
const connect = (0, import_react6.useCallback)(
|
|
521
1202
|
async (opts) => {
|
|
522
1203
|
const epoch = ++epochRef.current;
|
|
523
1204
|
const current = () => epochRef.current === epoch;
|
|
@@ -603,7 +1284,7 @@ var useMcp = (options = {}) => {
|
|
|
603
1284
|
},
|
|
604
1285
|
[closeConnection]
|
|
605
1286
|
);
|
|
606
|
-
const disconnect = (0,
|
|
1287
|
+
const disconnect = (0, import_react6.useCallback)(async () => {
|
|
607
1288
|
epochRef.current++;
|
|
608
1289
|
await closeConnection();
|
|
609
1290
|
setTools(void 0);
|
|
@@ -612,12 +1293,12 @@ var useMcp = (options = {}) => {
|
|
|
612
1293
|
setError(void 0);
|
|
613
1294
|
setStatus("idle");
|
|
614
1295
|
}, [closeConnection]);
|
|
615
|
-
const authorize = (0,
|
|
1296
|
+
const authorize = (0, import_react6.useCallback)(() => {
|
|
616
1297
|
if (authorizationUrl && typeof globalThis.location !== "undefined") {
|
|
617
1298
|
globalThis.location.href = authorizationUrl;
|
|
618
1299
|
}
|
|
619
1300
|
}, [authorizationUrl]);
|
|
620
|
-
const forgetAuthorization = (0,
|
|
1301
|
+
const forgetAuthorization = (0, import_react6.useCallback)(async () => {
|
|
621
1302
|
const record = readRecord(OAUTH_KEY);
|
|
622
1303
|
writeRecord(PENDING_KEY, void 0);
|
|
623
1304
|
writeRecord(OAUTH_KEY, void 0);
|
|
@@ -638,7 +1319,7 @@ var useMcp = (options = {}) => {
|
|
|
638
1319
|
providerRef.current = void 0;
|
|
639
1320
|
await disconnect();
|
|
640
1321
|
}, [disconnect]);
|
|
641
|
-
(0,
|
|
1322
|
+
(0, import_react6.useEffect)(() => {
|
|
642
1323
|
const callback = readCallbackParams();
|
|
643
1324
|
if (!callback) {
|
|
644
1325
|
setCompletingAuthorization(false);
|
|
@@ -683,7 +1364,7 @@ var useMcp = (options = {}) => {
|
|
|
683
1364
|
}
|
|
684
1365
|
})();
|
|
685
1366
|
}, [connect]);
|
|
686
|
-
(0,
|
|
1367
|
+
(0, import_react6.useEffect)(
|
|
687
1368
|
() => () => {
|
|
688
1369
|
epochRef.current++;
|
|
689
1370
|
void closeConnection();
|
|
@@ -706,82 +1387,687 @@ var useMcp = (options = {}) => {
|
|
|
706
1387
|
};
|
|
707
1388
|
};
|
|
708
1389
|
|
|
709
|
-
// src/hooks/use-
|
|
710
|
-
var
|
|
711
|
-
var
|
|
712
|
-
var
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
1390
|
+
// src/hooks/use-mcp-servers.ts
|
|
1391
|
+
var import_react7 = require("react");
|
|
1392
|
+
var DEFAULT_KEY = "agent-web-react:mcp-servers";
|
|
1393
|
+
var sanitize = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 32) || "mcp";
|
|
1394
|
+
var view = (s, patch = {}) => ({
|
|
1395
|
+
name: s.name,
|
|
1396
|
+
url: s.url,
|
|
1397
|
+
auth: s.auth,
|
|
1398
|
+
status: "idle",
|
|
1399
|
+
catalog: [],
|
|
1400
|
+
...patch
|
|
1401
|
+
});
|
|
1402
|
+
var useMcpServers = (options = {}) => {
|
|
1403
|
+
const storageKey = options.storageKey ?? DEFAULT_KEY;
|
|
1404
|
+
const pendingKey = `${storageKey}:pending`;
|
|
1405
|
+
const persist = options.persist !== false;
|
|
1406
|
+
const [servers, setServers] = (0, import_react7.useState)(
|
|
1407
|
+
() => persist ? (readRecord(storageKey) ?? []).map((s) => view(s)) : []
|
|
1408
|
+
);
|
|
1409
|
+
const [oauthSupported, setOauthSupported] = (0, import_react7.useState)(void 0);
|
|
1410
|
+
const [completingAuthorization, setCompleting] = (0, import_react7.useState)(
|
|
1411
|
+
() => readCallbackParams() !== void 0 && readRecord(pendingKey) !== void 0
|
|
1412
|
+
);
|
|
1413
|
+
const [toolsVersion, setToolsVersion] = (0, import_react7.useState)(0);
|
|
1414
|
+
const liveRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
1415
|
+
const specsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
1416
|
+
if (specsRef.current.size === 0 && servers.length > 0) {
|
|
1417
|
+
for (const s of servers)
|
|
1418
|
+
specsRef.current.set(s.name, { name: s.name, url: s.url, auth: s.auth });
|
|
1419
|
+
}
|
|
1420
|
+
const optionsRef = (0, import_react7.useRef)(options);
|
|
719
1421
|
optionsRef.current = options;
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
1422
|
+
const unmountedRef = (0, import_react7.useRef)(false);
|
|
1423
|
+
const saveList = (0, import_react7.useCallback)(() => {
|
|
1424
|
+
if (!persist) return;
|
|
1425
|
+
writeRecord(storageKey, [...specsRef.current.values()]);
|
|
1426
|
+
}, [persist, storageKey]);
|
|
1427
|
+
const patch = (0, import_react7.useCallback)((name, p) => {
|
|
1428
|
+
if (unmountedRef.current) return;
|
|
1429
|
+
setServers((list) => list.map((s) => s.name === name ? { ...s, ...p } : s));
|
|
1430
|
+
}, []);
|
|
1431
|
+
const live = (name) => {
|
|
1432
|
+
let l = liveRef.current.get(name);
|
|
1433
|
+
if (!l) {
|
|
1434
|
+
l = { epoch: 0 };
|
|
1435
|
+
liveRef.current.set(name, l);
|
|
724
1436
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
preload: false,
|
|
737
|
-
initProgressCallback: (report) => {
|
|
738
|
-
setProgress(report.progress);
|
|
739
|
-
setText(report.text);
|
|
740
|
-
modelOptions.initProgressCallback?.(report);
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
await (0, import_agent_web3.preloadWebLLMModel)(built);
|
|
744
|
-
setModel(built);
|
|
745
|
-
return built;
|
|
746
|
-
} catch (err) {
|
|
747
|
-
setError(errMessage(err));
|
|
748
|
-
return void 0;
|
|
749
|
-
} finally {
|
|
750
|
-
setLoading(false);
|
|
1437
|
+
return l;
|
|
1438
|
+
};
|
|
1439
|
+
const closeServer = (0, import_react7.useCallback)(async (name) => {
|
|
1440
|
+
const l = liveRef.current.get(name);
|
|
1441
|
+
if (!l) return;
|
|
1442
|
+
l.epoch += 1;
|
|
1443
|
+
const open = l.connection;
|
|
1444
|
+
l.connection = void 0;
|
|
1445
|
+
if (l.tools) {
|
|
1446
|
+
l.tools = void 0;
|
|
1447
|
+
setToolsVersion((v) => v + 1);
|
|
751
1448
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
1449
|
+
if (open) await open.close().catch(() => {
|
|
1450
|
+
});
|
|
1451
|
+
}, []);
|
|
1452
|
+
const providerFor = (mod, spec) => {
|
|
1453
|
+
if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
|
|
1454
|
+
return new mod.BrowserOAuthProvider({
|
|
1455
|
+
serverUrl: spec.url,
|
|
1456
|
+
redirectUrl: spec.oauth?.redirectUrl ?? defaultRedirectUrl(),
|
|
1457
|
+
clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
|
|
1458
|
+
scope: spec.oauth?.scope
|
|
1459
|
+
});
|
|
762
1460
|
};
|
|
1461
|
+
const connectServer = (0, import_react7.useCallback)(
|
|
1462
|
+
async (name) => {
|
|
1463
|
+
const spec = specsRef.current.get(name);
|
|
1464
|
+
if (!spec) return;
|
|
1465
|
+
await closeServer(name);
|
|
1466
|
+
const l = live(name);
|
|
1467
|
+
const epoch = ++l.epoch;
|
|
1468
|
+
const current = () => !unmountedRef.current && l.epoch === epoch;
|
|
1469
|
+
if (spec.auth === "bearer" && !l.token) {
|
|
1470
|
+
patch(name, { status: "idle", error: "Enter the bearer token to connect." });
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
patch(name, {
|
|
1474
|
+
status: "connecting",
|
|
1475
|
+
error: void 0,
|
|
1476
|
+
authorizationUrl: void 0,
|
|
1477
|
+
catalog: []
|
|
1478
|
+
});
|
|
1479
|
+
try {
|
|
1480
|
+
const mod = await loadMcp();
|
|
1481
|
+
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
1482
|
+
let provider;
|
|
1483
|
+
if (spec.auth === "oauth") {
|
|
1484
|
+
provider = providerFor(mod, spec);
|
|
1485
|
+
l.provider = provider;
|
|
1486
|
+
}
|
|
1487
|
+
const connection = await mod.connectMcpHttp(
|
|
1488
|
+
{
|
|
1489
|
+
[name]: {
|
|
1490
|
+
url: spec.url,
|
|
1491
|
+
headers: spec.auth === "bearer" && l.token ? { Authorization: `Bearer ${l.token}` } : void 0,
|
|
1492
|
+
authProvider: provider,
|
|
1493
|
+
connectTimeoutMs: optionsRef.current.connectTimeoutMs
|
|
1494
|
+
}
|
|
1495
|
+
},
|
|
1496
|
+
{
|
|
1497
|
+
clientName: optionsRef.current.clientName,
|
|
1498
|
+
onLog: optionsRef.current.onLog,
|
|
1499
|
+
connectTimeoutMs: optionsRef.current.connectTimeoutMs
|
|
1500
|
+
}
|
|
1501
|
+
);
|
|
1502
|
+
if (!current()) {
|
|
1503
|
+
await connection.close().catch(() => {
|
|
1504
|
+
});
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
const outcome = describeMcpResult(connection.results[0]);
|
|
1508
|
+
if (outcome.status !== "connected") {
|
|
1509
|
+
await connection.close().catch(() => {
|
|
1510
|
+
});
|
|
1511
|
+
if (outcome.status === "needs-authorization") {
|
|
1512
|
+
const url = provider?.authorizationUrl;
|
|
1513
|
+
patch(name, {
|
|
1514
|
+
status: "needs-authorization",
|
|
1515
|
+
authorizationUrl: url ? String(url) : void 0
|
|
1516
|
+
});
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
throw new Error(outcome.error);
|
|
1520
|
+
}
|
|
1521
|
+
l.connection = connection;
|
|
1522
|
+
l.tools = watchAuthorization(connection.tools, mod, () => {
|
|
1523
|
+
if (!current()) return;
|
|
1524
|
+
const url = l.provider?.authorizationUrl;
|
|
1525
|
+
patch(name, {
|
|
1526
|
+
status: "needs-authorization",
|
|
1527
|
+
authorizationUrl: url ? String(url) : void 0
|
|
1528
|
+
});
|
|
1529
|
+
});
|
|
1530
|
+
setToolsVersion((v) => v + 1);
|
|
1531
|
+
patch(name, { status: "connected", catalog: connection.catalog });
|
|
1532
|
+
} catch (err) {
|
|
1533
|
+
if (!current()) return;
|
|
1534
|
+
patch(name, { status: "error", error: err instanceof Error ? err.message : String(err) });
|
|
1535
|
+
}
|
|
1536
|
+
},
|
|
1537
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1538
|
+
[closeServer, patch, pendingKey]
|
|
1539
|
+
);
|
|
1540
|
+
const add = (0, import_react7.useCallback)(
|
|
1541
|
+
async (input) => {
|
|
1542
|
+
let name = sanitize(input.name);
|
|
1543
|
+
const taken = specsRef.current.get(name);
|
|
1544
|
+
if (taken && taken.url !== input.url) {
|
|
1545
|
+
let n = 2;
|
|
1546
|
+
while (specsRef.current.has(`${name}_${n}`)) n += 1;
|
|
1547
|
+
name = `${name}_${n}`;
|
|
1548
|
+
}
|
|
1549
|
+
const spec = {
|
|
1550
|
+
name,
|
|
1551
|
+
url: input.url,
|
|
1552
|
+
auth: input.auth ?? "none",
|
|
1553
|
+
...input.oauth ? { oauth: input.oauth } : {}
|
|
1554
|
+
};
|
|
1555
|
+
specsRef.current.set(name, spec);
|
|
1556
|
+
live(name).token = input.auth === "bearer" ? input.token : void 0;
|
|
1557
|
+
setServers(
|
|
1558
|
+
(list) => list.some((s) => s.name === name) ? list.map((s) => s.name === name ? view(spec) : s) : [...list, view(spec)]
|
|
1559
|
+
);
|
|
1560
|
+
saveList();
|
|
1561
|
+
await connectServer(name);
|
|
1562
|
+
return name;
|
|
1563
|
+
},
|
|
1564
|
+
[connectServer, saveList]
|
|
1565
|
+
);
|
|
1566
|
+
const remove = (0, import_react7.useCallback)(
|
|
1567
|
+
async (name) => {
|
|
1568
|
+
await closeServer(name);
|
|
1569
|
+
liveRef.current.delete(name);
|
|
1570
|
+
specsRef.current.delete(name);
|
|
1571
|
+
saveList();
|
|
1572
|
+
setServers((list) => list.filter((s) => s.name !== name));
|
|
1573
|
+
},
|
|
1574
|
+
[closeServer, saveList]
|
|
1575
|
+
);
|
|
1576
|
+
const reconnect = (0, import_react7.useCallback)(
|
|
1577
|
+
async (name, token) => {
|
|
1578
|
+
if (token !== void 0) live(name).token = token;
|
|
1579
|
+
await connectServer(name);
|
|
1580
|
+
},
|
|
1581
|
+
[connectServer]
|
|
1582
|
+
);
|
|
1583
|
+
const authorize = (0, import_react7.useCallback)(
|
|
1584
|
+
(name) => {
|
|
1585
|
+
const url = servers.find((s) => s.name === name)?.authorizationUrl;
|
|
1586
|
+
const spec = specsRef.current.get(name);
|
|
1587
|
+
if (!url || !spec || typeof globalThis.location === "undefined") return;
|
|
1588
|
+
const pending = {
|
|
1589
|
+
name,
|
|
1590
|
+
url: spec.url,
|
|
1591
|
+
redirectUrl: spec.oauth?.redirectUrl ?? defaultRedirectUrl(),
|
|
1592
|
+
scope: spec.oauth?.scope,
|
|
1593
|
+
clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
|
|
1594
|
+
startedAt: Date.now()
|
|
1595
|
+
};
|
|
1596
|
+
writeRecord(pendingKey, pending);
|
|
1597
|
+
globalThis.location.href = url;
|
|
1598
|
+
},
|
|
1599
|
+
[servers, pendingKey]
|
|
1600
|
+
);
|
|
1601
|
+
const forgetAuthorization = (0, import_react7.useCallback)(
|
|
1602
|
+
async (name) => {
|
|
1603
|
+
const spec = specsRef.current.get(name);
|
|
1604
|
+
const l = liveRef.current.get(name);
|
|
1605
|
+
let provider = l?.provider;
|
|
1606
|
+
if (!provider && spec?.auth === "oauth") {
|
|
1607
|
+
const mod = await loadMcp().catch(() => void 0);
|
|
1608
|
+
if (mod?.BrowserOAuthProvider) provider = providerFor(mod, spec);
|
|
1609
|
+
}
|
|
1610
|
+
await provider?.reset().catch(() => {
|
|
1611
|
+
});
|
|
1612
|
+
if (l) l.provider = void 0;
|
|
1613
|
+
const pending = readRecord(pendingKey);
|
|
1614
|
+
if (pending?.name === name) writeRecord(pendingKey, void 0);
|
|
1615
|
+
await closeServer(name);
|
|
1616
|
+
patch(name, { status: "idle", authorizationUrl: void 0, catalog: [], error: void 0 });
|
|
1617
|
+
},
|
|
1618
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1619
|
+
[closeServer, patch, pendingKey]
|
|
1620
|
+
);
|
|
1621
|
+
const checkOAuthSupport = (0, import_react7.useCallback)(async () => {
|
|
1622
|
+
try {
|
|
1623
|
+
const mod = await loadMcp();
|
|
1624
|
+
const supported = typeof mod.BrowserOAuthProvider === "function";
|
|
1625
|
+
setOauthSupported(supported);
|
|
1626
|
+
return supported;
|
|
1627
|
+
} catch {
|
|
1628
|
+
setOauthSupported(false);
|
|
1629
|
+
return false;
|
|
1630
|
+
}
|
|
1631
|
+
}, []);
|
|
1632
|
+
(0, import_react7.useEffect)(() => {
|
|
1633
|
+
unmountedRef.current = false;
|
|
1634
|
+
const callback = readCallbackParams();
|
|
1635
|
+
const pending = readRecord(pendingKey);
|
|
1636
|
+
const fresh = pending !== void 0 && Date.now() - pending.startedAt < PENDING_TTL_MS;
|
|
1637
|
+
const ours = Boolean(callback && pending && fresh && claimOAuthCallback(callback));
|
|
1638
|
+
if (callback && pending && !fresh) writeRecord(pendingKey, void 0);
|
|
1639
|
+
if (ours && typeof globalThis.history !== "undefined") {
|
|
1640
|
+
globalThis.history.replaceState(null, "", stripOAuthParams(globalThis.location.href));
|
|
1641
|
+
}
|
|
1642
|
+
const autoConnect = optionsRef.current.autoConnect !== false;
|
|
1643
|
+
void (async () => {
|
|
1644
|
+
if (ours && pending && callback) {
|
|
1645
|
+
try {
|
|
1646
|
+
const mod = await loadMcp();
|
|
1647
|
+
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
1648
|
+
if (!mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
|
|
1649
|
+
const spec = specsRef.current.get(pending.name) ?? {
|
|
1650
|
+
name: pending.name,
|
|
1651
|
+
url: pending.url,
|
|
1652
|
+
auth: "oauth"
|
|
1653
|
+
};
|
|
1654
|
+
if (!specsRef.current.has(spec.name)) {
|
|
1655
|
+
specsRef.current.set(spec.name, spec);
|
|
1656
|
+
setServers((list) => [...list, view(spec)]);
|
|
1657
|
+
saveList();
|
|
1658
|
+
}
|
|
1659
|
+
const provider = providerFor(mod, {
|
|
1660
|
+
...spec,
|
|
1661
|
+
oauth: {
|
|
1662
|
+
redirectUrl: pending.redirectUrl,
|
|
1663
|
+
scope: pending.scope,
|
|
1664
|
+
clientName: pending.clientName
|
|
1665
|
+
}
|
|
1666
|
+
});
|
|
1667
|
+
live(spec.name).provider = provider;
|
|
1668
|
+
await mod.finishMcpOAuth(provider, callback);
|
|
1669
|
+
writeRecord(pendingKey, void 0);
|
|
1670
|
+
} catch (err) {
|
|
1671
|
+
writeRecord(pendingKey, void 0);
|
|
1672
|
+
patch(pending.name, {
|
|
1673
|
+
status: "error",
|
|
1674
|
+
error: err instanceof Error ? err.message : String(err)
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
setCompleting(false);
|
|
1679
|
+
if (autoConnect || ours) {
|
|
1680
|
+
await Promise.all(
|
|
1681
|
+
[...specsRef.current.keys()].filter((name) => autoConnect || name === pending?.name).map((name) => connectServer(name))
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1684
|
+
})();
|
|
1685
|
+
return () => {
|
|
1686
|
+
unmountedRef.current = true;
|
|
1687
|
+
for (const name of liveRef.current.keys()) void closeServer(name);
|
|
1688
|
+
};
|
|
1689
|
+
}, []);
|
|
1690
|
+
const tools = (0, import_react7.useMemo)(() => {
|
|
1691
|
+
const merged = {};
|
|
1692
|
+
for (const l of liveRef.current.values()) if (l.tools) Object.assign(merged, l.tools);
|
|
1693
|
+
return merged;
|
|
1694
|
+
}, [toolsVersion]);
|
|
1695
|
+
const catalog = (0, import_react7.useMemo)(
|
|
1696
|
+
() => servers.filter((s) => s.status === "connected").flatMap((s) => s.catalog),
|
|
1697
|
+
[servers]
|
|
1698
|
+
);
|
|
1699
|
+
return {
|
|
1700
|
+
servers,
|
|
1701
|
+
tools,
|
|
1702
|
+
catalog,
|
|
1703
|
+
connectedCount: servers.filter((s) => s.status === "connected").length,
|
|
1704
|
+
completingAuthorization,
|
|
1705
|
+
oauthSupported,
|
|
1706
|
+
checkOAuthSupport,
|
|
1707
|
+
add,
|
|
1708
|
+
remove,
|
|
1709
|
+
reconnect,
|
|
1710
|
+
authorize,
|
|
1711
|
+
forgetAuthorization
|
|
1712
|
+
};
|
|
1713
|
+
};
|
|
1714
|
+
|
|
1715
|
+
// src/hooks/use-webllm-model.ts
|
|
1716
|
+
var import_react8 = require("react");
|
|
1717
|
+
var import_agent_web3 = require("@dudko.dev/agent-web");
|
|
1718
|
+
var useWebLLMModel = (modelId, options) => {
|
|
1719
|
+
const [model, setModel] = (0, import_react8.useState)(void 0);
|
|
1720
|
+
const [loading, setLoading] = (0, import_react8.useState)(false);
|
|
1721
|
+
const [progress, setProgress] = (0, import_react8.useState)(0);
|
|
1722
|
+
const [text, setText] = (0, import_react8.useState)("");
|
|
1723
|
+
const [error, setError] = (0, import_react8.useState)(void 0);
|
|
1724
|
+
const optionsRef = (0, import_react8.useRef)(options);
|
|
1725
|
+
optionsRef.current = options;
|
|
1726
|
+
const load = (0, import_react8.useCallback)(async () => {
|
|
1727
|
+
if (!(0, import_agent_web3.isWebGPUAvailable)()) {
|
|
1728
|
+
setError("WebGPU is not available in this browser.");
|
|
1729
|
+
return void 0;
|
|
1730
|
+
}
|
|
1731
|
+
setLoading(true);
|
|
1732
|
+
setError(void 0);
|
|
1733
|
+
setProgress(0);
|
|
1734
|
+
setText("");
|
|
1735
|
+
try {
|
|
1736
|
+
const { create = import_agent_web3.createWebLLMModel, ...modelOptions } = optionsRef.current ?? {};
|
|
1737
|
+
const built = await create(modelId, {
|
|
1738
|
+
...modelOptions,
|
|
1739
|
+
// Drive preload here (below) so download progress is reported the same
|
|
1740
|
+
// way whether `create` is the core's `createWebLLMModel` or an injected
|
|
1741
|
+
// factory (e.g. a statically-imported `webLLM`, needed under bundlers).
|
|
1742
|
+
preload: false,
|
|
1743
|
+
initProgressCallback: (report) => {
|
|
1744
|
+
setProgress(report.progress);
|
|
1745
|
+
setText(report.text);
|
|
1746
|
+
modelOptions.initProgressCallback?.(report);
|
|
1747
|
+
}
|
|
1748
|
+
});
|
|
1749
|
+
await (0, import_agent_web3.preloadWebLLMModel)(built);
|
|
1750
|
+
setModel(built);
|
|
1751
|
+
return built;
|
|
1752
|
+
} catch (err) {
|
|
1753
|
+
setError(errMessage(err));
|
|
1754
|
+
return void 0;
|
|
1755
|
+
} finally {
|
|
1756
|
+
setLoading(false);
|
|
1757
|
+
}
|
|
1758
|
+
}, [modelId]);
|
|
1759
|
+
return {
|
|
1760
|
+
model,
|
|
1761
|
+
load,
|
|
1762
|
+
loading,
|
|
1763
|
+
progress,
|
|
1764
|
+
text,
|
|
1765
|
+
error,
|
|
1766
|
+
supported: (0, import_agent_web3.isWebGPUAvailable)(),
|
|
1767
|
+
ready: model !== void 0
|
|
1768
|
+
};
|
|
1769
|
+
};
|
|
1770
|
+
|
|
1771
|
+
// src/labels.tsx
|
|
1772
|
+
var import_react9 = require("react");
|
|
1773
|
+
|
|
1774
|
+
// src/composer.ts
|
|
1775
|
+
var parseSlash = (text) => {
|
|
1776
|
+
const m = /^\/([\w-]*)(?:\s+([\s\S]*))?$/.exec(text.trimStart());
|
|
1777
|
+
return m ? { name: m[1].toLowerCase(), args: (m[2] ?? "").trim() } : void 0;
|
|
1778
|
+
};
|
|
1779
|
+
var filterCommands = (commands, query) => {
|
|
1780
|
+
const q = query.toLowerCase();
|
|
1781
|
+
if (!q) return commands;
|
|
1782
|
+
const starts = commands.filter((c) => c.name.toLowerCase().startsWith(q));
|
|
1783
|
+
const contains = commands.filter(
|
|
1784
|
+
(c) => !starts.includes(c) && (c.name.toLowerCase().includes(q) || c.description.toLowerCase().includes(q))
|
|
1785
|
+
);
|
|
1786
|
+
return [...starts, ...contains];
|
|
1787
|
+
};
|
|
1788
|
+
var attachmentKindOf = (mediaType, name) => {
|
|
1789
|
+
if (mediaType.startsWith("image/")) return "image";
|
|
1790
|
+
if (mediaType === "application/pdf" || /\.pdf$/i.test(name)) return "pdf";
|
|
1791
|
+
if (mediaType.startsWith("text/") || /json|xml|yaml|javascript|typescript|csv|markdown|x-sh|sql|toml/.test(mediaType) || /\.(txt|md|markdown|json|csv|tsv|ya?ml|xml|html?|css|m?[jt]sx?|py|sh|log|sql|toml|ini|env)$/i.test(
|
|
1792
|
+
name
|
|
1793
|
+
)) {
|
|
1794
|
+
return "text";
|
|
1795
|
+
}
|
|
1796
|
+
return "file";
|
|
1797
|
+
};
|
|
1798
|
+
var withAttachments = (text, files) => {
|
|
1799
|
+
const texts = files.filter((f) => f.kind === "text" && f.text !== void 0);
|
|
1800
|
+
if (texts.length === 0) return text;
|
|
1801
|
+
const blocks = texts.map((f) => {
|
|
1802
|
+
const body = f.text;
|
|
1803
|
+
const fence = body.includes("```") ? "~~~" : "```";
|
|
1804
|
+
const where = f.path ? ` (also saved as ${f.path})` : "";
|
|
1805
|
+
return `### ${f.name}${where}
|
|
1806
|
+
${fence}
|
|
1807
|
+
${body}
|
|
1808
|
+
${fence}`;
|
|
1809
|
+
});
|
|
1810
|
+
return `${text}
|
|
1811
|
+
|
|
1812
|
+
Attached file(s):
|
|
1813
|
+
${blocks.join("\n\n")}`;
|
|
1814
|
+
};
|
|
1815
|
+
var attachmentRefusal = (kind, caps, canConvertPdf = false) => {
|
|
1816
|
+
if (kind === "text" || !caps) return void 0;
|
|
1817
|
+
if (kind === "image" && caps.images === false) {
|
|
1818
|
+
return "This model can't see images \u2014 switch to a vision-capable model (Gemini, Claude, GPT-4o/5) to attach one.";
|
|
1819
|
+
}
|
|
1820
|
+
if (kind === "pdf" && caps.pdf === false && !canConvertPdf) {
|
|
1821
|
+
return "This model can't read PDF files \u2014 convert it to text first, or switch to Gemini, Claude or GPT-4o/5.";
|
|
1822
|
+
}
|
|
1823
|
+
if (kind === "file" && caps.files === false) {
|
|
1824
|
+
return "This model can't take file attachments \u2014 paste the text instead.";
|
|
1825
|
+
}
|
|
1826
|
+
return void 0;
|
|
1827
|
+
};
|
|
1828
|
+
var formatElapsed = (ms) => {
|
|
1829
|
+
const s = Math.max(0, Math.floor(ms / 1e3));
|
|
1830
|
+
if (s < 60) return `${s}s`;
|
|
1831
|
+
const m = Math.floor(s / 60);
|
|
1832
|
+
if (m < 60) return `${m}m ${s % 60}s`;
|
|
1833
|
+
return `${Math.floor(m / 60)}h ${m % 60}m`;
|
|
1834
|
+
};
|
|
1835
|
+
var kTokens = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(n >= 1e4 ? 0 : 1)}k` : `${n}`;
|
|
1836
|
+
var defaultNoticeTexts = {
|
|
1837
|
+
limit: (kind, used, cap) => {
|
|
1838
|
+
const calls = kind === "tool-calls";
|
|
1839
|
+
const what = calls ? "Tool-call" : `${kind[0].toUpperCase()}${kind.slice(1)}-token`;
|
|
1840
|
+
const amount = calls ? `${used}/${cap} calls` : `${kTokens(used)}/${kTokens(cap)} tokens`;
|
|
1841
|
+
return `${what} limit reached \xB7 ${amount} \u2014 the agent stopped early and answered with what it had`;
|
|
1842
|
+
},
|
|
1843
|
+
compacted: (scope, before, after) => `Context compacted (${scope}) \xB7 ${kTokens(before)} \u2192 ${kTokens(after)} tokens`
|
|
1844
|
+
};
|
|
1845
|
+
var noticesOf = (state, texts = {}) => {
|
|
1846
|
+
const t = { ...defaultNoticeTexts, ...texts };
|
|
1847
|
+
const out = [];
|
|
1848
|
+
if (state.status === "error" && state.error) {
|
|
1849
|
+
out.push({ id: `error:${state.error}`, tone: "error", text: state.error });
|
|
1850
|
+
}
|
|
1851
|
+
if (state.budget) {
|
|
1852
|
+
const b = state.budget;
|
|
1853
|
+
out.push({
|
|
1854
|
+
id: `budget:${state.goal ?? ""}:${b.kind}:${b.cap}`,
|
|
1855
|
+
tone: "warn",
|
|
1856
|
+
text: t.limit(b.kind, b.tokens, b.cap)
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
const last = state.compactions.at(-1);
|
|
1860
|
+
if (last) {
|
|
1861
|
+
out.push({
|
|
1862
|
+
id: `compact:${state.compactions.length}:${last.beforeTokens}:${last.afterTokens}`,
|
|
1863
|
+
tone: "info",
|
|
1864
|
+
text: t.compacted(last.scope, last.beforeTokens, last.afterTokens)
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
return out;
|
|
763
1868
|
};
|
|
764
1869
|
|
|
765
|
-
// src/
|
|
766
|
-
var
|
|
767
|
-
var
|
|
768
|
-
var
|
|
769
|
-
var
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
|
|
1870
|
+
// src/labels.tsx
|
|
1871
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1872
|
+
var plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
1873
|
+
var kb = (n) => n < 1024 ? `${n} B` : n < 1024 * 1024 ? `${(n / 1024).toFixed(1)} KB` : `${(n / 1024 / 1024).toFixed(1)} MB`;
|
|
1874
|
+
var defaultLabels = {
|
|
1875
|
+
emptyState: "Ask the agent to do something.",
|
|
1876
|
+
status: {
|
|
1877
|
+
idle: "Idle",
|
|
1878
|
+
initializing: "Loading model\u2026",
|
|
1879
|
+
ready: "Ready",
|
|
1880
|
+
running: "Working\u2026",
|
|
1881
|
+
error: "Failed to start"
|
|
1882
|
+
},
|
|
1883
|
+
history: "Chats",
|
|
1884
|
+
newChat: "New chat",
|
|
1885
|
+
files: "Files",
|
|
1886
|
+
totalUsage: "Tokens this conversation used, by kind",
|
|
1887
|
+
showHistory: "Show chats",
|
|
1888
|
+
showFiles: "Show files",
|
|
1889
|
+
close: "Close",
|
|
1890
|
+
steps: (n) => plural(n, "step", "steps"),
|
|
1891
|
+
toolCalls: (n) => plural(n, "tool call", "tool calls"),
|
|
1892
|
+
subagents: (n) => plural(n, "subagent", "subagents"),
|
|
1893
|
+
skillsUsed: (names) => `skills: ${names}`,
|
|
1894
|
+
answerThoughts: "Thinking about the answer",
|
|
1895
|
+
stepThoughts: "Thoughts",
|
|
1896
|
+
usageTitle: "Tokens this answer spent, by kind",
|
|
1897
|
+
attachments: "Attachments",
|
|
1898
|
+
planned: "Plan",
|
|
1899
|
+
replanned: (mode, reason) => `Replanned (${mode}): ${reason}`,
|
|
1900
|
+
placeholder: "Ask the agent to do something\u2026 ( / for commands, Ctrl+V to paste an image )",
|
|
1901
|
+
listening: "Listening\u2026",
|
|
1902
|
+
message: "Message",
|
|
1903
|
+
dropHint: "Drop files or images to attach them",
|
|
1904
|
+
attach: "Attach files",
|
|
1905
|
+
attachTitle: "Attach files or images (or paste with Ctrl+V, or drop them here)",
|
|
1906
|
+
commands: "Commands",
|
|
1907
|
+
commandsTitle: "Commands and skills ( / )",
|
|
1908
|
+
send: "Send",
|
|
1909
|
+
stop: "Stop",
|
|
1910
|
+
dismiss: "Dismiss",
|
|
1911
|
+
remove: (name) => `Remove ${name}`,
|
|
1912
|
+
dictate: "Dictate (speech to text)",
|
|
1913
|
+
dictateTitle: "Dictate \u2014 speech to text in the browser",
|
|
1914
|
+
stopDictation: "Stop dictation",
|
|
1915
|
+
microphone: "Microphone",
|
|
1916
|
+
model: "Model",
|
|
1917
|
+
thinking: "Thinking",
|
|
1918
|
+
toolConsent: "Tool consent",
|
|
1919
|
+
modes: {
|
|
1920
|
+
autopilot: { label: "Auto", hint: "Autopilot \u2014 run every tool without asking" },
|
|
1921
|
+
"ask-writes": {
|
|
1922
|
+
label: "Ask",
|
|
1923
|
+
hint: "Run read-only tools freely; ask before anything that may change state"
|
|
1924
|
+
},
|
|
1925
|
+
"ask-all": { label: "Ask all", hint: "Ask before every tool call" },
|
|
1926
|
+
"read-only": {
|
|
1927
|
+
label: "Read-only",
|
|
1928
|
+
hint: "Only read-only tools; refuse changes without asking"
|
|
1929
|
+
}
|
|
1930
|
+
},
|
|
1931
|
+
timerRunning: "This run so far",
|
|
1932
|
+
timerLast: "The last run took",
|
|
1933
|
+
agents: (n) => plural(n, "agent", "agents"),
|
|
1934
|
+
agentsTitle: "Subagents running in this run",
|
|
1935
|
+
notices: defaultNoticeTexts,
|
|
1936
|
+
attachmentsOnly: "(attachments)",
|
|
1937
|
+
seeAttachments: "See the attachments.",
|
|
1938
|
+
tooLarge: (name, mb) => `${name} is larger than ${mb} MB.`,
|
|
1939
|
+
binaryText: (name) => `${name} looks binary \u2014 it can't be attached as text.`,
|
|
1940
|
+
commandGroups: { commands: "Commands", consent: "Consent", skills: "Skills" },
|
|
1941
|
+
commandDescriptions: {
|
|
1942
|
+
compact: "Summarise the conversation to free context",
|
|
1943
|
+
new: "Start a new conversation",
|
|
1944
|
+
stop: "Stop the current run",
|
|
1945
|
+
autopilot: "Run every tool without asking",
|
|
1946
|
+
ask: "Ask before tools that may change state",
|
|
1947
|
+
askAll: "Ask before every tool call",
|
|
1948
|
+
readOnly: "Only read; refuse changes",
|
|
1949
|
+
think: (levels) => `Set thinking: ${levels}`
|
|
1950
|
+
},
|
|
1951
|
+
thinkingLevels: { off: "Default", low: "Low", medium: "Medium", high: "High" },
|
|
1952
|
+
filesEmpty: "No files yet. Attachments and files the agent writes appear here.",
|
|
1953
|
+
upload: "Upload",
|
|
1954
|
+
download: "Download",
|
|
1955
|
+
delete: "Delete",
|
|
1956
|
+
preview: "Preview",
|
|
1957
|
+
bytes: kb,
|
|
1958
|
+
historyEmpty: "No saved chats yet.",
|
|
1959
|
+
deleteChat: "Delete chat",
|
|
1960
|
+
messagesCount: (n) => plural(n, "message", "messages"),
|
|
1961
|
+
approvalLead: "The agent wants to run",
|
|
1962
|
+
approve: "Allow once",
|
|
1963
|
+
alwaysAllow: "Always allow",
|
|
1964
|
+
deny: "Deny",
|
|
1965
|
+
declinedReason: "the user declined",
|
|
1966
|
+
readOnlyTool: "read-only",
|
|
1967
|
+
consentWaiting: "waiting for your consent",
|
|
1968
|
+
consentAllowed: "allowed",
|
|
1969
|
+
consentDenied: (reason) => `denied${reason ? ` \u2014 ${reason}` : ""}`,
|
|
1970
|
+
failed: "failed",
|
|
1971
|
+
toolCostTitle: "Estimated tokens of the arguments and of the result fed back to the model (chars / 4), and the call's duration"
|
|
1972
|
+
};
|
|
1973
|
+
var NESTED = [
|
|
1974
|
+
"status",
|
|
1975
|
+
"modes",
|
|
1976
|
+
"commandGroups",
|
|
1977
|
+
"commandDescriptions",
|
|
1978
|
+
"thinkingLevels"
|
|
1979
|
+
];
|
|
1980
|
+
var mergeLabels = (base2, over) => {
|
|
1981
|
+
if (!over) return base2;
|
|
1982
|
+
const out = { ...base2, ...over };
|
|
1983
|
+
for (const key of NESTED) {
|
|
1984
|
+
if (over[key]) out[key] = { ...base2[key], ...over[key] };
|
|
1985
|
+
}
|
|
1986
|
+
return out;
|
|
1987
|
+
};
|
|
1988
|
+
var LabelsContext = (0, import_react9.createContext)(defaultLabels);
|
|
1989
|
+
var AgentLabelsProvider = ({ labels, children }) => {
|
|
1990
|
+
const parent = (0, import_react9.useContext)(LabelsContext);
|
|
1991
|
+
const value = (0, import_react9.useMemo)(() => mergeLabels(parent, labels), [parent, labels]);
|
|
1992
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LabelsContext.Provider, { value, children });
|
|
1993
|
+
};
|
|
1994
|
+
var useLabels = (over) => {
|
|
1995
|
+
const ctx = (0, import_react9.useContext)(LabelsContext);
|
|
1996
|
+
return (0, import_react9.useMemo)(() => mergeLabels(ctx, over), [ctx, over]);
|
|
1997
|
+
};
|
|
1998
|
+
|
|
1999
|
+
// src/image-resize.ts
|
|
2000
|
+
var canvasOf = (w, h) => {
|
|
2001
|
+
if (typeof OffscreenCanvas !== "undefined") return new OffscreenCanvas(w, h);
|
|
2002
|
+
if (typeof document !== "undefined") {
|
|
2003
|
+
const c = document.createElement("canvas");
|
|
2004
|
+
c.width = w;
|
|
2005
|
+
c.height = h;
|
|
2006
|
+
return c;
|
|
2007
|
+
}
|
|
2008
|
+
return void 0;
|
|
2009
|
+
};
|
|
2010
|
+
var toBlob = (canvas, type, quality) => "convertToBlob" in canvas ? canvas.convertToBlob({ type, quality }) : new Promise((resolve) => canvas.toBlob(resolve, type, quality));
|
|
2011
|
+
var downscaleImage = async (file, opts = {}) => {
|
|
2012
|
+
const maxDimension = opts.maxDimension ?? 1568;
|
|
2013
|
+
const maxPixels = opts.maxPixels ?? 115e4;
|
|
2014
|
+
if (typeof createImageBitmap !== "function" || !file.type.startsWith("image/") || file.type === "image/gif" || file.type === "image/svg+xml") {
|
|
2015
|
+
return file;
|
|
2016
|
+
}
|
|
2017
|
+
let bitmap;
|
|
2018
|
+
try {
|
|
2019
|
+
bitmap = await createImageBitmap(file);
|
|
2020
|
+
} catch {
|
|
2021
|
+
return file;
|
|
2022
|
+
}
|
|
2023
|
+
const { width, height } = bitmap;
|
|
2024
|
+
const scale = Math.min(
|
|
2025
|
+
1,
|
|
2026
|
+
maxDimension / Math.max(width, height),
|
|
2027
|
+
Math.sqrt(maxPixels / Math.max(1, width * height))
|
|
2028
|
+
);
|
|
2029
|
+
if (scale >= 1) {
|
|
2030
|
+
bitmap.close();
|
|
2031
|
+
return file;
|
|
2032
|
+
}
|
|
2033
|
+
const w = Math.max(1, Math.round(width * scale));
|
|
2034
|
+
const h = Math.max(1, Math.round(height * scale));
|
|
2035
|
+
const canvas = canvasOf(w, h);
|
|
2036
|
+
const ctx = canvas?.getContext("2d");
|
|
2037
|
+
if (!canvas || !ctx) {
|
|
2038
|
+
bitmap.close();
|
|
2039
|
+
return file;
|
|
2040
|
+
}
|
|
2041
|
+
ctx.drawImage(bitmap, 0, 0, w, h);
|
|
2042
|
+
bitmap.close();
|
|
2043
|
+
const type = file.type === "image/png" || file.type === "image/webp" ? file.type : "image/jpeg";
|
|
2044
|
+
const out = await toBlob(canvas, type, opts.quality ?? 0.9);
|
|
2045
|
+
return out && out.size < file.size ? out : file;
|
|
2046
|
+
};
|
|
2047
|
+
|
|
2048
|
+
// src/context.tsx
|
|
2049
|
+
var import_react10 = require("react");
|
|
2050
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
2051
|
+
var AgentContext = (0, import_react10.createContext)(null);
|
|
2052
|
+
var AgentProvider = ({ config, children, ...options }) => {
|
|
2053
|
+
const agent = useAgent(config, options);
|
|
2054
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AgentContext.Provider, { value: agent, children });
|
|
2055
|
+
};
|
|
2056
|
+
var useAgentContext = () => {
|
|
2057
|
+
const ctx = (0, import_react10.useContext)(AgentContext);
|
|
2058
|
+
if (!ctx) throw new Error("useAgentContext must be used within an <AgentProvider>");
|
|
2059
|
+
return ctx;
|
|
2060
|
+
};
|
|
2061
|
+
var useOptionalAgentContext = () => (0, import_react10.useContext)(AgentContext);
|
|
2062
|
+
|
|
780
2063
|
// src/components/AgentChat.tsx
|
|
781
|
-
var
|
|
2064
|
+
var import_react15 = require("react");
|
|
2065
|
+
|
|
2066
|
+
// src/components/AgentComposer.tsx
|
|
2067
|
+
var import_react11 = require("react");
|
|
782
2068
|
|
|
783
2069
|
// src/components/icons.tsx
|
|
784
|
-
var
|
|
2070
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
785
2071
|
var base = (size = 16) => ({
|
|
786
2072
|
width: size,
|
|
787
2073
|
height: size,
|
|
@@ -793,114 +2079,871 @@ var base = (size = 16) => ({
|
|
|
793
2079
|
strokeLinejoin: "round",
|
|
794
2080
|
"aria-hidden": true
|
|
795
2081
|
});
|
|
796
|
-
var SendIcon = ({ size, className }) => /* @__PURE__ */ (0,
|
|
797
|
-
/* @__PURE__ */ (0,
|
|
798
|
-
/* @__PURE__ */ (0,
|
|
2082
|
+
var SendIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2083
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M22 2 11 13" }),
|
|
2084
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M22 2 15 22l-4-9-9-4Z" })
|
|
799
2085
|
] });
|
|
800
|
-
var StopIcon = ({ size, className }) => /* @__PURE__ */ (0,
|
|
801
|
-
var SpinnerIcon = ({ size, className }) => /* @__PURE__ */ (0,
|
|
802
|
-
var CheckIcon = ({ size, className }) => /* @__PURE__ */ (0,
|
|
803
|
-
var AlertIcon = ({ size, className }) => /* @__PURE__ */ (0,
|
|
804
|
-
/* @__PURE__ */ (0,
|
|
805
|
-
/* @__PURE__ */ (0,
|
|
806
|
-
/* @__PURE__ */ (0,
|
|
2086
|
+
var StopIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }) });
|
|
2087
|
+
var SpinnerIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className: ["awr-spin", className].filter(Boolean).join(" "), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" }) });
|
|
2088
|
+
var CheckIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M20 6 9 17l-5-5" }) });
|
|
2089
|
+
var AlertIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2090
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z" }),
|
|
2091
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 9v4" }),
|
|
2092
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 17h.01" })
|
|
807
2093
|
] });
|
|
808
|
-
var ToolIcon = ({ size, className }) => /* @__PURE__ */ (0,
|
|
2094
|
+
var ToolIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76Z" }) });
|
|
2095
|
+
var ShieldIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z" }) });
|
|
2096
|
+
var BrainIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2097
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 3a3 3 0 0 0-3 3 3 3 0 0 0-2 5 3 3 0 0 0 2 5 3 3 0 0 0 6 1V4a3 3 0 0 0-3-1Z" }),
|
|
2098
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M15 3a3 3 0 0 1 3 3 3 3 0 0 1 2 5 3 3 0 0 1-2 5 3 3 0 0 1-6 1" })
|
|
2099
|
+
] });
|
|
2100
|
+
var BotIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2101
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "4", y: "8", width: "16", height: "12", rx: "3" }),
|
|
2102
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 8V4" }),
|
|
2103
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 14h.01M15 14h.01" })
|
|
2104
|
+
] });
|
|
2105
|
+
var PlusIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 5v14M5 12h14" }) });
|
|
2106
|
+
var SlashIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2107
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "3", y: "3", width: "18", height: "18", rx: "3" }),
|
|
2108
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m15 7-6 10" })
|
|
2109
|
+
] });
|
|
2110
|
+
var ClockIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2111
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "9" }),
|
|
2112
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 7v5l3 2" })
|
|
2113
|
+
] });
|
|
2114
|
+
var MicIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2115
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "9", y: "3", width: "6", height: "11", rx: "3" }),
|
|
2116
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M5 11a7 7 0 0 0 14 0M12 18v3" })
|
|
2117
|
+
] });
|
|
2118
|
+
var BoltIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M13 2 4 14h7l-1 8 9-12h-7Z" }) });
|
|
2119
|
+
var EyeIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2120
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" }),
|
|
2121
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "3" })
|
|
2122
|
+
] });
|
|
2123
|
+
var XIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M18 6 6 18M6 6l12 12" }) });
|
|
2124
|
+
var FileIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2125
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9Z" }),
|
|
2126
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M14 3v6h6" })
|
|
2127
|
+
] });
|
|
2128
|
+
var HistoryIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("svg", { ...base(size), className, children: [
|
|
2129
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 12a9 9 0 1 0 3-6.7L3 8" }),
|
|
2130
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 3v5h5M12 7v5l3 2" })
|
|
2131
|
+
] });
|
|
2132
|
+
var DownloadIcon = ({ size, className }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { ...base(size), className, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 3v12m-5-5 5 5 5-5M5 21h14" }) });
|
|
809
2133
|
|
|
810
|
-
// src/components/
|
|
811
|
-
var
|
|
812
|
-
var
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
2134
|
+
// src/components/AgentComposer.tsx
|
|
2135
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
2136
|
+
var thinkingDefaults = (l) => [
|
|
2137
|
+
{ id: "off", label: l.thinkingLevels.off },
|
|
2138
|
+
{ id: "low", label: l.thinkingLevels.low },
|
|
2139
|
+
{ id: "medium", label: l.thinkingLevels.medium },
|
|
2140
|
+
{ id: "high", label: l.thinkingLevels.high }
|
|
2141
|
+
];
|
|
2142
|
+
var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
|
|
2143
|
+
var ModeIcon = ({ mode }) => mode === "autopilot" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BoltIcon, { size: 14 }) : mode === "read-only" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EyeIcon, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ShieldIcon, { size: 14 });
|
|
2144
|
+
var attachSeq = 0;
|
|
2145
|
+
var useIsoLayoutEffect = typeof window === "undefined" ? import_react11.useEffect : import_react11.useLayoutEffect;
|
|
2146
|
+
var useMenuPlacement = (open, anchor, align) => {
|
|
2147
|
+
const [style, setStyle] = (0, import_react11.useState)();
|
|
2148
|
+
useIsoLayoutEffect(() => {
|
|
2149
|
+
if (!open) return;
|
|
2150
|
+
const place = () => {
|
|
2151
|
+
const el = anchor.current;
|
|
2152
|
+
if (!el) return;
|
|
2153
|
+
const r = el.getBoundingClientRect();
|
|
2154
|
+
const vw = window.innerWidth;
|
|
2155
|
+
const vh = window.innerHeight;
|
|
2156
|
+
const above = r.top - 8;
|
|
2157
|
+
const below = vh - r.bottom - 8;
|
|
2158
|
+
const up = above >= 240 || above >= below;
|
|
2159
|
+
const s = {
|
|
2160
|
+
maxHeight: Math.max(120, (up ? above : below) - 6),
|
|
2161
|
+
top: up ? "auto" : r.bottom + 6,
|
|
2162
|
+
bottom: up ? vh - r.top + 6 : "auto",
|
|
2163
|
+
maxWidth: vw - 16
|
|
2164
|
+
};
|
|
2165
|
+
if (align === "stretch") {
|
|
2166
|
+
s.left = Math.max(8, r.left);
|
|
2167
|
+
s.width = Math.min(r.width, vw - 16);
|
|
2168
|
+
} else if (align === "right") {
|
|
2169
|
+
s.left = "auto";
|
|
2170
|
+
s.right = Math.max(8, vw - r.right);
|
|
2171
|
+
} else {
|
|
2172
|
+
s.left = Math.max(8, Math.min(r.left, vw - 248));
|
|
2173
|
+
}
|
|
2174
|
+
setStyle(s);
|
|
2175
|
+
};
|
|
2176
|
+
place();
|
|
2177
|
+
window.addEventListener("resize", place);
|
|
2178
|
+
window.addEventListener("scroll", place, true);
|
|
2179
|
+
return () => {
|
|
2180
|
+
window.removeEventListener("resize", place);
|
|
2181
|
+
window.removeEventListener("scroll", place, true);
|
|
2182
|
+
};
|
|
2183
|
+
}, [open, anchor, align]);
|
|
2184
|
+
return open ? style : void 0;
|
|
2185
|
+
};
|
|
2186
|
+
var readDataUrl2 = (file) => new Promise((resolve, reject) => {
|
|
2187
|
+
const r = new FileReader();
|
|
2188
|
+
r.onload = () => resolve(String(r.result));
|
|
2189
|
+
r.onerror = () => reject(r.error ?? new Error("could not read the file"));
|
|
2190
|
+
r.readAsDataURL(file);
|
|
2191
|
+
});
|
|
2192
|
+
var safeName = (name) => name.replace(/[^\w.-]+/g, "_").slice(0, 80) || "file";
|
|
2193
|
+
var AgentComposer = ({
|
|
2194
|
+
controller: agent,
|
|
2195
|
+
placeholder,
|
|
2196
|
+
model,
|
|
2197
|
+
thinking,
|
|
2198
|
+
labels: labelsOverride,
|
|
2199
|
+
commands = [],
|
|
2200
|
+
builtinCommands = true,
|
|
2201
|
+
skillCommands = true,
|
|
2202
|
+
attachments = true,
|
|
2203
|
+
convertFile,
|
|
2204
|
+
convert = "when-needed",
|
|
2205
|
+
files: vfs,
|
|
2206
|
+
dropZone = "self",
|
|
2207
|
+
speech = true,
|
|
2208
|
+
showTimer = true,
|
|
2209
|
+
showAgents = true,
|
|
2210
|
+
showApprovalMode = true,
|
|
2211
|
+
showNotices = true,
|
|
2212
|
+
compactWidth = 460,
|
|
2213
|
+
toolbarExtra,
|
|
2214
|
+
toolbarEnd,
|
|
2215
|
+
renderAttachment,
|
|
817
2216
|
disabled = false,
|
|
818
|
-
placeholder = "Ask the agent to do something\u2026",
|
|
819
2217
|
className
|
|
820
2218
|
}) => {
|
|
821
|
-
const
|
|
2219
|
+
const L = useLabels(labelsOverride);
|
|
2220
|
+
const MODE_CHIP = L.modes;
|
|
2221
|
+
const DEFAULT_THINKING = thinkingDefaults(L);
|
|
2222
|
+
const [text, setText] = (0, import_react11.useState)("");
|
|
2223
|
+
const [pending, setPending] = (0, import_react11.useState)([]);
|
|
2224
|
+
const [menu, setMenu] = (0, import_react11.useState)(void 0);
|
|
2225
|
+
const [active, setActive] = (0, import_react11.useState)(0);
|
|
2226
|
+
const [dismissed, setDismissed] = (0, import_react11.useState)(() => /* @__PURE__ */ new Set());
|
|
2227
|
+
const [attachError, setAttachError] = (0, import_react11.useState)();
|
|
2228
|
+
const [dragging, setDragging] = (0, import_react11.useState)(false);
|
|
2229
|
+
const rootRef = (0, import_react11.useRef)(null);
|
|
2230
|
+
const modelRef = (0, import_react11.useRef)(null);
|
|
2231
|
+
const modeRef = (0, import_react11.useRef)(null);
|
|
2232
|
+
const [dropRect, setDropRect] = (0, import_react11.useState)();
|
|
2233
|
+
const [compactBar, setCompactBar] = (0, import_react11.useState)(false);
|
|
2234
|
+
(0, import_react11.useEffect)(() => {
|
|
2235
|
+
const el = rootRef.current;
|
|
2236
|
+
if (!el || typeof ResizeObserver === "undefined") return;
|
|
2237
|
+
const ro = new ResizeObserver(
|
|
2238
|
+
() => setCompactBar(el.getBoundingClientRect().width < compactWidth)
|
|
2239
|
+
);
|
|
2240
|
+
ro.observe(el);
|
|
2241
|
+
return () => ro.disconnect();
|
|
2242
|
+
}, [compactWidth]);
|
|
2243
|
+
const fileRef = (0, import_react11.useRef)(null);
|
|
2244
|
+
const inputRef = (0, import_react11.useRef)(null);
|
|
2245
|
+
const busy = agent.isRunning;
|
|
2246
|
+
const ready = agent.isReady && !disabled;
|
|
2247
|
+
const caps = agent.agent?.capabilities;
|
|
2248
|
+
const stt = useSpeechToText({
|
|
2249
|
+
lang: typeof speech === "object" ? speech.lang : void 0,
|
|
2250
|
+
onFinal: (heard) => setText((t) => t.trim() ? `${t.trimEnd()} ${heard}` : heard)
|
|
2251
|
+
});
|
|
2252
|
+
const showMic = speech !== false && stt.supported;
|
|
2253
|
+
const [startedAt, setStartedAt] = (0, import_react11.useState)();
|
|
2254
|
+
const [now, setNow] = (0, import_react11.useState)(() => Date.now());
|
|
2255
|
+
const [lastElapsed, setLastElapsed] = (0, import_react11.useState)();
|
|
2256
|
+
(0, import_react11.useEffect)(() => {
|
|
2257
|
+
if (!busy) {
|
|
2258
|
+
if (startedAt !== void 0) setLastElapsed(Date.now() - startedAt);
|
|
2259
|
+
setStartedAt(void 0);
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
const t0 = Date.now();
|
|
2263
|
+
setStartedAt(t0);
|
|
2264
|
+
setNow(t0);
|
|
2265
|
+
const id = setInterval(() => setNow(Date.now()), 1e3);
|
|
2266
|
+
return () => clearInterval(id);
|
|
2267
|
+
}, [busy]);
|
|
2268
|
+
const elapsed = startedAt !== void 0 ? now - startedAt : lastElapsed;
|
|
2269
|
+
const allCommands = (0, import_react11.useMemo)(() => {
|
|
2270
|
+
const out = [];
|
|
2271
|
+
if (builtinCommands) {
|
|
2272
|
+
out.push(
|
|
2273
|
+
{
|
|
2274
|
+
name: "compact",
|
|
2275
|
+
description: L.commandDescriptions.compact,
|
|
2276
|
+
group: L.commandGroups.commands,
|
|
2277
|
+
run: () => void agent.compact()
|
|
2278
|
+
},
|
|
2279
|
+
{
|
|
2280
|
+
name: "new",
|
|
2281
|
+
description: L.commandDescriptions.new,
|
|
2282
|
+
group: L.commandGroups.commands,
|
|
2283
|
+
run: agent.reset
|
|
2284
|
+
},
|
|
2285
|
+
{
|
|
2286
|
+
name: "stop",
|
|
2287
|
+
description: L.commandDescriptions.stop,
|
|
2288
|
+
group: L.commandGroups.commands,
|
|
2289
|
+
run: agent.stop
|
|
2290
|
+
},
|
|
2291
|
+
{
|
|
2292
|
+
name: "autopilot",
|
|
2293
|
+
description: L.commandDescriptions.autopilot,
|
|
2294
|
+
group: L.commandGroups.consent,
|
|
2295
|
+
run: () => agent.setApprovalMode("autopilot")
|
|
2296
|
+
},
|
|
2297
|
+
{
|
|
2298
|
+
name: "ask",
|
|
2299
|
+
description: L.commandDescriptions.ask,
|
|
2300
|
+
group: L.commandGroups.consent,
|
|
2301
|
+
run: () => agent.setApprovalMode("ask-writes")
|
|
2302
|
+
},
|
|
2303
|
+
{
|
|
2304
|
+
name: "ask-all",
|
|
2305
|
+
description: L.commandDescriptions.askAll,
|
|
2306
|
+
group: L.commandGroups.consent,
|
|
2307
|
+
run: () => agent.setApprovalMode("ask-all")
|
|
2308
|
+
},
|
|
2309
|
+
{
|
|
2310
|
+
name: "read-only",
|
|
2311
|
+
description: L.commandDescriptions.readOnly,
|
|
2312
|
+
group: L.commandGroups.consent,
|
|
2313
|
+
run: () => agent.setApprovalMode("read-only")
|
|
2314
|
+
}
|
|
2315
|
+
);
|
|
2316
|
+
if (thinking) {
|
|
2317
|
+
const levels = (thinking.options ?? DEFAULT_THINKING).map((o) => o.id);
|
|
2318
|
+
out.push({
|
|
2319
|
+
name: "think",
|
|
2320
|
+
description: L.commandDescriptions.think(levels.join(" | ")),
|
|
2321
|
+
group: L.commandGroups.commands,
|
|
2322
|
+
run: (args) => {
|
|
2323
|
+
const level = args.trim().toLowerCase();
|
|
2324
|
+
if (levels.includes(level)) thinking.onChange(level);
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
if (skillCommands) {
|
|
2330
|
+
for (const s of agent.agent?.skills ?? []) {
|
|
2331
|
+
out.push({
|
|
2332
|
+
name: s.name,
|
|
2333
|
+
description: s.description,
|
|
2334
|
+
group: L.commandGroups.skills,
|
|
2335
|
+
kind: "prefix",
|
|
2336
|
+
transform: (args) => `Use the "${s.name}" skill. ${args}`.trim()
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
return [...out, ...commands];
|
|
2341
|
+
}, [agent, builtinCommands, skillCommands, commands, thinking, L]);
|
|
2342
|
+
const slash = parseSlash(text);
|
|
2343
|
+
const matches = slash && !/\s/.test(text.trimStart()) ? filterCommands(allCommands, slash.name) : [];
|
|
2344
|
+
const palette = menu === "commands" && !slash ? allCommands : matches;
|
|
2345
|
+
const paletteOpen = palette.length > 0 && (menu === "commands" || matches.length > 0);
|
|
2346
|
+
const commandsStyle = useMenuPlacement(paletteOpen, rootRef, "stretch");
|
|
2347
|
+
const modelStyle = useMenuPlacement(menu === "model", modelRef, "left");
|
|
2348
|
+
const modeStyle = useMenuPlacement(menu === "mode", modeRef, "right");
|
|
2349
|
+
(0, import_react11.useEffect)(() => setActive(0), [text, menu]);
|
|
2350
|
+
(0, import_react11.useEffect)(() => {
|
|
2351
|
+
if (!menu) return;
|
|
2352
|
+
const onDown = (e) => {
|
|
2353
|
+
if (!rootRef.current?.contains(e.target)) setMenu(void 0);
|
|
2354
|
+
};
|
|
2355
|
+
document.addEventListener("mousedown", onDown);
|
|
2356
|
+
return () => document.removeEventListener("mousedown", onDown);
|
|
2357
|
+
}, [menu]);
|
|
2358
|
+
const pick = (cmd) => {
|
|
2359
|
+
setMenu(void 0);
|
|
2360
|
+
if (cmd.kind === "prefix") {
|
|
2361
|
+
setText(`/${cmd.name} `);
|
|
2362
|
+
inputRef.current?.focus();
|
|
2363
|
+
return;
|
|
2364
|
+
}
|
|
2365
|
+
const args = parseSlash(text)?.args ?? "";
|
|
2366
|
+
setText("");
|
|
2367
|
+
void cmd.run?.(args);
|
|
2368
|
+
};
|
|
2369
|
+
const attachCfg = typeof attachments === "object" ? attachments : {};
|
|
2370
|
+
const maxBytes = attachCfg.maxBytes ?? 20 * 1024 * 1024;
|
|
2371
|
+
const imageMax = attachCfg.imageMaxDimension ?? 1568;
|
|
2372
|
+
const addFiles = async (list) => {
|
|
2373
|
+
const added = [];
|
|
2374
|
+
let problem;
|
|
2375
|
+
for (const f of list) {
|
|
2376
|
+
const mediaType = f.type || "application/octet-stream";
|
|
2377
|
+
const name = f.name || `pasted-${Date.now()}.${mediaType.split("/")[1] ?? "bin"}`;
|
|
2378
|
+
const kind = attachmentKindOf(mediaType, name);
|
|
2379
|
+
if (f.size > maxBytes) {
|
|
2380
|
+
problem = L.tooLarge(name, Math.round(maxBytes / 1024 / 1024));
|
|
2381
|
+
continue;
|
|
2382
|
+
}
|
|
2383
|
+
try {
|
|
2384
|
+
const id = `att-${attachSeq += 1}`;
|
|
2385
|
+
if (kind === "text") {
|
|
2386
|
+
const content = await f.text();
|
|
2387
|
+
if (content.includes("\0")) {
|
|
2388
|
+
problem = L.binaryText(name);
|
|
2389
|
+
continue;
|
|
2390
|
+
}
|
|
2391
|
+
added.push({ id, name, kind, mediaType, text: content, bytes: f.size });
|
|
2392
|
+
continue;
|
|
2393
|
+
}
|
|
2394
|
+
const refusal = attachmentRefusal(kind, caps);
|
|
2395
|
+
const wantConvert = convertFile && (refusal || kind === "pdf" && convert === "always");
|
|
2396
|
+
if (wantConvert && convertFile) {
|
|
2397
|
+
const converted = await convertFile(f);
|
|
2398
|
+
if (converted) {
|
|
2399
|
+
added.push({
|
|
2400
|
+
id,
|
|
2401
|
+
name: converted.name ?? `${name}.md`,
|
|
2402
|
+
kind: "text",
|
|
2403
|
+
mediaType: "text/markdown",
|
|
2404
|
+
text: converted.text,
|
|
2405
|
+
bytes: converted.text.length,
|
|
2406
|
+
note: `converted from ${name}`
|
|
2407
|
+
});
|
|
2408
|
+
continue;
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
if (refusal) {
|
|
2412
|
+
problem = refusal;
|
|
2413
|
+
continue;
|
|
2414
|
+
}
|
|
2415
|
+
const blob = kind === "image" && imageMax !== false ? await downscaleImage(f, {
|
|
2416
|
+
maxDimension: imageMax,
|
|
2417
|
+
maxPixels: attachCfg.imageMaxPixels
|
|
2418
|
+
}) : f;
|
|
2419
|
+
added.push({
|
|
2420
|
+
id,
|
|
2421
|
+
name,
|
|
2422
|
+
kind,
|
|
2423
|
+
mediaType: blob.type || mediaType,
|
|
2424
|
+
dataUrl: await readDataUrl2(blob),
|
|
2425
|
+
bytes: blob.size,
|
|
2426
|
+
...blob !== f ? { note: `downscaled from ${L.bytes(f.size)}` } : {}
|
|
2427
|
+
});
|
|
2428
|
+
} catch (err) {
|
|
2429
|
+
problem = `${name}: ${err instanceof Error ? err.message : String(err)}`;
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
setAttachError(problem);
|
|
2433
|
+
if (added.length) setPending((cur) => [...cur, ...added]);
|
|
2434
|
+
if (fileRef.current) fileRef.current.value = "";
|
|
2435
|
+
};
|
|
2436
|
+
const onPaste = (e) => {
|
|
2437
|
+
if (attachments === false) return;
|
|
2438
|
+
const pasted = Array.from(e.clipboardData?.files ?? []);
|
|
2439
|
+
if (pasted.length === 0) return;
|
|
2440
|
+
e.preventDefault();
|
|
2441
|
+
void addFiles(pasted);
|
|
2442
|
+
};
|
|
2443
|
+
const addFilesRef = (0, import_react11.useRef)(addFiles);
|
|
2444
|
+
addFilesRef.current = addFiles;
|
|
2445
|
+
(0, import_react11.useEffect)(() => {
|
|
2446
|
+
if (attachments === false) return;
|
|
2447
|
+
const target = dropZone === "window" ? globalThis.window : dropZone === "self" ? rootRef.current : dropZone.current;
|
|
2448
|
+
if (!target) return;
|
|
2449
|
+
let depth = 0;
|
|
2450
|
+
const hasFiles = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
|
|
2451
|
+
const onEnter = (e) => {
|
|
2452
|
+
if (!hasFiles(e)) return;
|
|
2453
|
+
depth += 1;
|
|
2454
|
+
if (target === globalThis.window) setDropRect({ inset: 0 });
|
|
2455
|
+
else {
|
|
2456
|
+
const r = target.getBoundingClientRect();
|
|
2457
|
+
setDropRect({ left: r.left, top: r.top, width: r.width, height: r.height });
|
|
2458
|
+
}
|
|
2459
|
+
setDragging(true);
|
|
2460
|
+
};
|
|
2461
|
+
const onOver = (e) => {
|
|
2462
|
+
if (hasFiles(e)) e.preventDefault();
|
|
2463
|
+
};
|
|
2464
|
+
const onLeave = () => {
|
|
2465
|
+
depth = Math.max(0, depth - 1);
|
|
2466
|
+
if (depth === 0) setDragging(false);
|
|
2467
|
+
};
|
|
2468
|
+
const onDropFiles = (e) => {
|
|
2469
|
+
const dropped = e.dataTransfer?.files;
|
|
2470
|
+
depth = 0;
|
|
2471
|
+
setDragging(false);
|
|
2472
|
+
if (!dropped?.length) return;
|
|
2473
|
+
e.preventDefault();
|
|
2474
|
+
void addFilesRef.current(Array.from(dropped));
|
|
2475
|
+
};
|
|
2476
|
+
target.addEventListener("dragenter", onEnter);
|
|
2477
|
+
target.addEventListener("dragover", onOver);
|
|
2478
|
+
target.addEventListener("dragleave", onLeave);
|
|
2479
|
+
target.addEventListener("drop", onDropFiles);
|
|
2480
|
+
return () => {
|
|
2481
|
+
target.removeEventListener("dragenter", onEnter);
|
|
2482
|
+
target.removeEventListener("dragover", onOver);
|
|
2483
|
+
target.removeEventListener("dragleave", onLeave);
|
|
2484
|
+
target.removeEventListener("drop", onDropFiles);
|
|
2485
|
+
};
|
|
2486
|
+
}, [attachments, dropZone]);
|
|
822
2487
|
const submit = () => {
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
2488
|
+
const raw = text.trim();
|
|
2489
|
+
if (busy || !ready) return;
|
|
2490
|
+
const parsed = parseSlash(raw);
|
|
2491
|
+
if (parsed) {
|
|
2492
|
+
const cmd = allCommands.find((c) => c.name === parsed.name);
|
|
2493
|
+
if (cmd?.kind !== "prefix") {
|
|
2494
|
+
if (cmd) {
|
|
2495
|
+
setText("");
|
|
2496
|
+
void cmd.run?.(parsed.args);
|
|
2497
|
+
}
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
if (!parsed.args && pending.length === 0) return;
|
|
2501
|
+
void send(cmd.transform ? cmd.transform(parsed.args) : parsed.args, raw);
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
if (!raw && pending.length === 0) return;
|
|
2505
|
+
void send(raw, raw);
|
|
2506
|
+
};
|
|
2507
|
+
const send = async (goal, shown) => {
|
|
2508
|
+
if (stt.listening) stt.stop();
|
|
2509
|
+
const items = pending;
|
|
825
2510
|
setText("");
|
|
826
|
-
|
|
2511
|
+
setPending([]);
|
|
2512
|
+
if (vfs) {
|
|
2513
|
+
for (const a of items) {
|
|
2514
|
+
const path = `/attachments/${safeName(a.name)}`;
|
|
2515
|
+
try {
|
|
2516
|
+
if (a.dataUrl) await vfs.writeDataUrl(path, a.dataUrl);
|
|
2517
|
+
else if (a.text !== void 0) await vfs.write(path, a.text, { mimeType: a.mediaType });
|
|
2518
|
+
a.path = path;
|
|
2519
|
+
} catch {
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
const toModel = (a) => ({
|
|
2524
|
+
data: a.dataUrl,
|
|
2525
|
+
mediaType: a.mediaType,
|
|
2526
|
+
name: a.name
|
|
2527
|
+
});
|
|
2528
|
+
const shownAttachments = items.map((a) => ({
|
|
2529
|
+
name: a.name,
|
|
2530
|
+
mediaType: a.mediaType,
|
|
2531
|
+
size: a.bytes,
|
|
2532
|
+
...a.kind === "image" && a.dataUrl ? { dataUrl: a.dataUrl } : {},
|
|
2533
|
+
...a.path ? { path: a.path } : {}
|
|
2534
|
+
}));
|
|
2535
|
+
const full = withAttachments(goal || L.seeAttachments, items);
|
|
2536
|
+
const label = shown || (items.length ? L.attachmentsOnly : "");
|
|
2537
|
+
void agent.run(full, {
|
|
2538
|
+
...full !== label ? { label } : {},
|
|
2539
|
+
images: items.filter((a) => a.kind === "image" && a.dataUrl).map(toModel),
|
|
2540
|
+
files: items.filter((a) => (a.kind === "pdf" || a.kind === "file") && a.dataUrl).map(toModel),
|
|
2541
|
+
attachments: shownAttachments
|
|
2542
|
+
});
|
|
827
2543
|
};
|
|
828
2544
|
const onKeyDown = (e) => {
|
|
2545
|
+
if (paletteOpen) {
|
|
2546
|
+
if (e.key === "ArrowDown") {
|
|
2547
|
+
e.preventDefault();
|
|
2548
|
+
setActive((i) => (i + 1) % palette.length);
|
|
2549
|
+
return;
|
|
2550
|
+
}
|
|
2551
|
+
if (e.key === "ArrowUp") {
|
|
2552
|
+
e.preventDefault();
|
|
2553
|
+
setActive((i) => (i - 1 + palette.length) % palette.length);
|
|
2554
|
+
return;
|
|
2555
|
+
}
|
|
2556
|
+
if (e.key === "Tab" || e.key === "Enter" && !e.shiftKey && matches.length > 0) {
|
|
2557
|
+
e.preventDefault();
|
|
2558
|
+
pick(palette[active] ?? palette[0]);
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
if (e.key === "Escape") {
|
|
2562
|
+
setMenu(void 0);
|
|
2563
|
+
setText("");
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
829
2567
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
830
2568
|
e.preventDefault();
|
|
831
2569
|
submit();
|
|
832
2570
|
}
|
|
833
2571
|
};
|
|
834
|
-
|
|
835
|
-
|
|
2572
|
+
const notices = showNotices ? [
|
|
2573
|
+
...noticesOf(agent, L.notices),
|
|
2574
|
+
...attachError ? [{ id: `attach:${attachError}`, tone: "warn", text: attachError }] : [],
|
|
2575
|
+
...stt.error ? [
|
|
2576
|
+
{
|
|
2577
|
+
id: `stt:${stt.error}`,
|
|
2578
|
+
tone: "warn",
|
|
2579
|
+
text: `${L.microphone}: ${stt.error}`
|
|
2580
|
+
}
|
|
2581
|
+
] : []
|
|
2582
|
+
].filter((n) => !dismissed.has(n.id)) : [];
|
|
2583
|
+
const runningAgents = agent.subagents.filter((s) => s.status === "running");
|
|
2584
|
+
const thinkingOptions = thinking?.options ?? DEFAULT_THINKING;
|
|
2585
|
+
const thinkingLabel = thinking ? thinkingOptions.find((o) => o.id === thinking.value)?.label ?? thinking.value : void 0;
|
|
2586
|
+
const canSend = ready && (text.trim().length > 0 || pending.length > 0);
|
|
2587
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2588
|
+
"div",
|
|
836
2589
|
{
|
|
837
|
-
className: [
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
2590
|
+
className: [
|
|
2591
|
+
"awr-composer2",
|
|
2592
|
+
dragging ? "is-dragging" : "",
|
|
2593
|
+
compactBar ? "awr-composer2--compact" : "",
|
|
2594
|
+
className
|
|
2595
|
+
].filter(Boolean).join(" "),
|
|
2596
|
+
ref: rootRef,
|
|
842
2597
|
children: [
|
|
843
|
-
/* @__PURE__ */ (0,
|
|
844
|
-
|
|
2598
|
+
dragging && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-dropnote", style: dropRect, "aria-hidden": "true", children: L.dropHint }),
|
|
2599
|
+
notices.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-notices", children: notices.map((n) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: `awr-notice awr-notice--${n.tone}`, role: "status", children: [
|
|
2600
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: n.text }),
|
|
2601
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2602
|
+
"button",
|
|
2603
|
+
{
|
|
2604
|
+
type: "button",
|
|
2605
|
+
className: "awr-iconbtn",
|
|
2606
|
+
"aria-label": L.dismiss,
|
|
2607
|
+
onClick: () => {
|
|
2608
|
+
setDismissed((d) => new Set(d).add(n.id));
|
|
2609
|
+
if (n.id.startsWith("attach:")) setAttachError(void 0);
|
|
2610
|
+
},
|
|
2611
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(XIcon, { size: 14 })
|
|
2612
|
+
}
|
|
2613
|
+
)
|
|
2614
|
+
] }, n.id)) }),
|
|
2615
|
+
paletteOpen && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2616
|
+
"ul",
|
|
845
2617
|
{
|
|
846
|
-
className: "awr-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
2618
|
+
className: "awr-menu awr-menu--commands",
|
|
2619
|
+
style: commandsStyle,
|
|
2620
|
+
role: "listbox",
|
|
2621
|
+
"aria-label": L.commands,
|
|
2622
|
+
children: palette.map((c, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2623
|
+
"button",
|
|
2624
|
+
{
|
|
2625
|
+
type: "button",
|
|
2626
|
+
role: "option",
|
|
2627
|
+
"aria-selected": i === active,
|
|
2628
|
+
className: `awr-menu__item${i === active ? " is-active" : ""}`,
|
|
2629
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2630
|
+
onClick: () => pick(c),
|
|
2631
|
+
children: [
|
|
2632
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("code", { children: [
|
|
2633
|
+
"/",
|
|
2634
|
+
c.name
|
|
2635
|
+
] }),
|
|
2636
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-menu__desc", children: c.description }),
|
|
2637
|
+
c.group && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-menu__group", children: c.group })
|
|
2638
|
+
]
|
|
2639
|
+
}
|
|
2640
|
+
) }, `${c.group}:${c.name}`))
|
|
853
2641
|
}
|
|
854
2642
|
),
|
|
855
|
-
|
|
2643
|
+
pending.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-files", children: pending.map((a) => {
|
|
2644
|
+
const remove = () => setPending((cur) => cur.filter((x) => x.id !== a.id));
|
|
2645
|
+
if (renderAttachment) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: renderAttachment(a, remove) }, a.id);
|
|
2646
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "awr-chip awr-file", title: a.note ?? a.mediaType, children: [
|
|
2647
|
+
a.kind === "image" && a.dataUrl ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FileIcon, { size: 14 }),
|
|
2648
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-file__name", children: a.name }),
|
|
2649
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2650
|
+
"button",
|
|
2651
|
+
{
|
|
2652
|
+
type: "button",
|
|
2653
|
+
className: "awr-iconbtn",
|
|
2654
|
+
"aria-label": L.remove(a.name),
|
|
2655
|
+
onClick: remove,
|
|
2656
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(XIcon, { size: 12 })
|
|
2657
|
+
}
|
|
2658
|
+
)
|
|
2659
|
+
] }, a.id);
|
|
2660
|
+
}) }),
|
|
2661
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-composer2__inputrow", children: [
|
|
2662
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2663
|
+
"textarea",
|
|
2664
|
+
{
|
|
2665
|
+
ref: inputRef,
|
|
2666
|
+
className: "awr-composer2__input",
|
|
2667
|
+
value: text,
|
|
2668
|
+
onChange: (e) => setText(e.target.value),
|
|
2669
|
+
onKeyDown,
|
|
2670
|
+
onPaste,
|
|
2671
|
+
placeholder: stt.listening ? L.listening : placeholder ?? L.placeholder,
|
|
2672
|
+
disabled,
|
|
2673
|
+
rows: 2,
|
|
2674
|
+
"aria-label": L.message
|
|
2675
|
+
}
|
|
2676
|
+
),
|
|
2677
|
+
showMic && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2678
|
+
"button",
|
|
2679
|
+
{
|
|
2680
|
+
type: "button",
|
|
2681
|
+
className: `awr-iconbtn awr-mic${stt.listening ? " is-on" : ""}`,
|
|
2682
|
+
"aria-label": stt.listening ? L.stopDictation : L.dictate,
|
|
2683
|
+
title: stt.listening ? L.stopDictation : L.dictateTitle,
|
|
2684
|
+
onClick: stt.toggle,
|
|
2685
|
+
disabled,
|
|
2686
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MicIcon, { size: 18 })
|
|
2687
|
+
}
|
|
2688
|
+
)
|
|
2689
|
+
] }),
|
|
2690
|
+
stt.listening && stt.interim && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-composer2__interim", children: stt.interim }),
|
|
2691
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-toolbar", children: [
|
|
2692
|
+
attachments !== false && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
2693
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2694
|
+
"button",
|
|
2695
|
+
{
|
|
2696
|
+
type: "button",
|
|
2697
|
+
className: "awr-iconbtn",
|
|
2698
|
+
"aria-label": L.attach,
|
|
2699
|
+
title: L.attachTitle,
|
|
2700
|
+
onClick: () => fileRef.current?.click(),
|
|
2701
|
+
disabled,
|
|
2702
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PlusIcon, { size: 18 })
|
|
2703
|
+
}
|
|
2704
|
+
),
|
|
2705
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2706
|
+
"input",
|
|
2707
|
+
{
|
|
2708
|
+
ref: fileRef,
|
|
2709
|
+
type: "file",
|
|
2710
|
+
multiple: true,
|
|
2711
|
+
hidden: true,
|
|
2712
|
+
accept: attachCfg.accept,
|
|
2713
|
+
onChange: (e) => void addFiles(Array.from(e.target.files ?? []))
|
|
2714
|
+
}
|
|
2715
|
+
)
|
|
2716
|
+
] }),
|
|
2717
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2718
|
+
"button",
|
|
2719
|
+
{
|
|
2720
|
+
type: "button",
|
|
2721
|
+
className: `awr-iconbtn${menu === "commands" ? " is-on" : ""}`,
|
|
2722
|
+
"aria-label": L.commands,
|
|
2723
|
+
title: L.commandsTitle,
|
|
2724
|
+
onClick: () => setMenu(menu === "commands" ? void 0 : "commands"),
|
|
2725
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlashIcon, { size: 18 })
|
|
2726
|
+
}
|
|
2727
|
+
),
|
|
2728
|
+
toolbarExtra,
|
|
2729
|
+
showTimer && elapsed !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "awr-tchip", title: busy ? L.timerRunning : L.timerLast, children: [
|
|
2730
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ClockIcon, { size: 14 }),
|
|
2731
|
+
" ",
|
|
2732
|
+
formatElapsed(elapsed)
|
|
2733
|
+
] }),
|
|
2734
|
+
showAgents && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2735
|
+
"span",
|
|
2736
|
+
{
|
|
2737
|
+
className: `awr-tchip awr-agents${runningAgents.length ? " is-busy" : ""}`,
|
|
2738
|
+
title: agent.subagents.length ? agent.subagents.map((s) => `${s.name} (${s.status}): ${s.task}`).join("\n") : L.agentsTitle,
|
|
2739
|
+
children: [
|
|
2740
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-agents__dot", "aria-hidden": "true" }),
|
|
2741
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BotIcon, { size: 14 }),
|
|
2742
|
+
" ",
|
|
2743
|
+
compactBar ? runningAgents.length : L.agents(runningAgents.length)
|
|
2744
|
+
]
|
|
2745
|
+
}
|
|
2746
|
+
),
|
|
2747
|
+
(model || thinking) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "awr-popwrap awr-popwrap--model", ref: modelRef, children: [
|
|
2748
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2749
|
+
"button",
|
|
2750
|
+
{
|
|
2751
|
+
type: "button",
|
|
2752
|
+
className: "awr-tchip awr-tchip--btn",
|
|
2753
|
+
onClick: () => setMenu(menu === "model" ? void 0 : "model"),
|
|
2754
|
+
"aria-haspopup": "menu",
|
|
2755
|
+
"aria-expanded": menu === "model",
|
|
2756
|
+
title: [model?.label, thinkingLabel].filter(Boolean).join(" \xB7 "),
|
|
2757
|
+
children: [
|
|
2758
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-tchip__label", children: model?.label ?? L.model }),
|
|
2759
|
+
thinkingLabel && !compactBar && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-tchip__sub", children: thinkingLabel })
|
|
2760
|
+
]
|
|
2761
|
+
}
|
|
2762
|
+
),
|
|
2763
|
+
menu === "model" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-menu awr-menu--pop", style: modelStyle, role: "menu", children: [
|
|
2764
|
+
thinking && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
2765
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-menu__head", children: L.thinking }),
|
|
2766
|
+
thinkingOptions.map((o) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2767
|
+
"button",
|
|
2768
|
+
{
|
|
2769
|
+
type: "button",
|
|
2770
|
+
role: "menuitemradio",
|
|
2771
|
+
"aria-checked": thinking.value === o.id,
|
|
2772
|
+
className: `awr-menu__item${thinking.value === o.id ? " is-active" : ""}`,
|
|
2773
|
+
onClick: () => {
|
|
2774
|
+
thinking.onChange(o.id);
|
|
2775
|
+
setMenu(void 0);
|
|
2776
|
+
},
|
|
2777
|
+
children: o.label
|
|
2778
|
+
},
|
|
2779
|
+
o.id
|
|
2780
|
+
))
|
|
2781
|
+
] }),
|
|
2782
|
+
model?.options?.length ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
2783
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-menu__head", children: L.model }),
|
|
2784
|
+
model.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2785
|
+
"button",
|
|
2786
|
+
{
|
|
2787
|
+
type: "button",
|
|
2788
|
+
role: "menuitemradio",
|
|
2789
|
+
"aria-checked": model.value === o.id,
|
|
2790
|
+
className: `awr-menu__item${model.value === o.id ? " is-active" : ""}`,
|
|
2791
|
+
onClick: () => {
|
|
2792
|
+
model.onSelect?.(o.id);
|
|
2793
|
+
setMenu(void 0);
|
|
2794
|
+
},
|
|
2795
|
+
children: [
|
|
2796
|
+
o.label,
|
|
2797
|
+
o.group && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-menu__group", children: o.group })
|
|
2798
|
+
]
|
|
2799
|
+
},
|
|
2800
|
+
o.id
|
|
2801
|
+
))
|
|
2802
|
+
] }) : null
|
|
2803
|
+
] })
|
|
2804
|
+
] }),
|
|
2805
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-toolbar__spacer" }),
|
|
2806
|
+
toolbarEnd,
|
|
2807
|
+
showApprovalMode && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "awr-popwrap", ref: modeRef, children: [
|
|
2808
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2809
|
+
"button",
|
|
2810
|
+
{
|
|
2811
|
+
type: "button",
|
|
2812
|
+
className: `awr-tchip awr-tchip--btn awr-mode awr-mode--${agent.approvalMode}`,
|
|
2813
|
+
title: MODE_CHIP[agent.approvalMode].hint,
|
|
2814
|
+
onClick: () => setMenu(menu === "mode" ? void 0 : "mode"),
|
|
2815
|
+
"aria-haspopup": "menu",
|
|
2816
|
+
"aria-expanded": menu === "mode",
|
|
2817
|
+
"aria-label": `${L.toolConsent}: ${MODE_CHIP[agent.approvalMode].label}`,
|
|
2818
|
+
children: [
|
|
2819
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ModeIcon, { mode: agent.approvalMode }),
|
|
2820
|
+
!compactBar && ` ${MODE_CHIP[agent.approvalMode].label}`
|
|
2821
|
+
]
|
|
2822
|
+
}
|
|
2823
|
+
),
|
|
2824
|
+
menu === "mode" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-menu awr-menu--pop", style: modeStyle, role: "menu", children: [
|
|
2825
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-menu__head", children: L.toolConsent }),
|
|
2826
|
+
MODES.map((m) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
2827
|
+
"button",
|
|
2828
|
+
{
|
|
2829
|
+
type: "button",
|
|
2830
|
+
role: "menuitemradio",
|
|
2831
|
+
"aria-checked": agent.approvalMode === m,
|
|
2832
|
+
className: `awr-menu__item${agent.approvalMode === m ? " is-active" : ""}`,
|
|
2833
|
+
onClick: () => {
|
|
2834
|
+
agent.setApprovalMode(m);
|
|
2835
|
+
setMenu(void 0);
|
|
2836
|
+
},
|
|
2837
|
+
children: [
|
|
2838
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ModeIcon, { mode: m }),
|
|
2839
|
+
" ",
|
|
2840
|
+
MODE_CHIP[m].label,
|
|
2841
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "awr-menu__desc", children: MODE_CHIP[m].hint })
|
|
2842
|
+
]
|
|
2843
|
+
},
|
|
2844
|
+
m
|
|
2845
|
+
))
|
|
2846
|
+
] })
|
|
2847
|
+
] }),
|
|
2848
|
+
busy ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2849
|
+
"button",
|
|
2850
|
+
{
|
|
2851
|
+
type: "button",
|
|
2852
|
+
className: "awr-sendbtn awr-sendbtn--stop",
|
|
2853
|
+
onClick: agent.stop,
|
|
2854
|
+
"aria-label": L.stop,
|
|
2855
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(StopIcon, { size: 16 })
|
|
2856
|
+
}
|
|
2857
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2858
|
+
"button",
|
|
2859
|
+
{
|
|
2860
|
+
type: "button",
|
|
2861
|
+
className: "awr-sendbtn",
|
|
2862
|
+
onClick: submit,
|
|
2863
|
+
disabled: !canSend,
|
|
2864
|
+
"aria-label": L.send,
|
|
2865
|
+
children: agent.status === "initializing" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SpinnerIcon, { size: 16 }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SendIcon, { size: 16 })
|
|
2866
|
+
}
|
|
2867
|
+
)
|
|
2868
|
+
] })
|
|
2869
|
+
]
|
|
2870
|
+
}
|
|
2871
|
+
);
|
|
2872
|
+
};
|
|
2873
|
+
|
|
2874
|
+
// src/components/ChatHistoryList.tsx
|
|
2875
|
+
var import_react12 = require("react");
|
|
2876
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
2877
|
+
var defaultTime = (ms) => {
|
|
2878
|
+
const d = new Date(ms);
|
|
2879
|
+
const today = (/* @__PURE__ */ new Date()).toDateString() === d.toDateString();
|
|
2880
|
+
return today ? d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) : d.toLocaleDateString();
|
|
2881
|
+
};
|
|
2882
|
+
var ChatHistoryList = ({
|
|
2883
|
+
history,
|
|
2884
|
+
title,
|
|
2885
|
+
disabled,
|
|
2886
|
+
renderChat,
|
|
2887
|
+
formatTime = defaultTime,
|
|
2888
|
+
labels,
|
|
2889
|
+
className
|
|
2890
|
+
}) => {
|
|
2891
|
+
const L = useLabels(labels);
|
|
2892
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: ["awr-history", className].filter(Boolean).join(" "), children: [
|
|
2893
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "awr-panel__head", children: [
|
|
2894
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "awr-panel__title", children: title ?? L.history }),
|
|
2895
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2896
|
+
"button",
|
|
2897
|
+
{
|
|
2898
|
+
type: "button",
|
|
2899
|
+
className: "awr-btn awr-btn--ghost awr-history__new",
|
|
2900
|
+
onClick: history.newChat,
|
|
2901
|
+
disabled,
|
|
2902
|
+
children: [
|
|
2903
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PlusIcon, { size: 14 }),
|
|
2904
|
+
" ",
|
|
2905
|
+
L.newChat
|
|
2906
|
+
]
|
|
2907
|
+
}
|
|
2908
|
+
)
|
|
2909
|
+
] }),
|
|
2910
|
+
!history.loading && history.chats.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "awr-panel__empty", children: L.historyEmpty }),
|
|
2911
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { className: "awr-history__list", children: history.chats.map((c) => {
|
|
2912
|
+
const active = c.id === history.currentId;
|
|
2913
|
+
const row = /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { className: `awr-history__item${active ? " is-active" : ""}`, children: [
|
|
2914
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
856
2915
|
"button",
|
|
857
2916
|
{
|
|
858
2917
|
type: "button",
|
|
859
|
-
className: "awr-
|
|
860
|
-
onClick:
|
|
861
|
-
|
|
862
|
-
|
|
2918
|
+
className: "awr-history__open",
|
|
2919
|
+
onClick: () => void history.select(c.id),
|
|
2920
|
+
disabled: disabled || active,
|
|
2921
|
+
"aria-current": active ? "true" : void 0,
|
|
2922
|
+
children: [
|
|
2923
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "awr-history__title", children: c.title }),
|
|
2924
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "awr-history__meta", children: [
|
|
2925
|
+
formatTime(c.updatedAt),
|
|
2926
|
+
" \xB7 ",
|
|
2927
|
+
L.messagesCount(c.messageCount)
|
|
2928
|
+
] })
|
|
2929
|
+
]
|
|
863
2930
|
}
|
|
864
|
-
)
|
|
2931
|
+
),
|
|
2932
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
865
2933
|
"button",
|
|
866
2934
|
{
|
|
867
|
-
type: "
|
|
868
|
-
className: "awr-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
2935
|
+
type: "button",
|
|
2936
|
+
className: "awr-iconbtn",
|
|
2937
|
+
"aria-label": `${L.deleteChat}: ${c.title}`,
|
|
2938
|
+
title: L.deleteChat,
|
|
2939
|
+
onClick: () => void history.remove(c.id),
|
|
2940
|
+
disabled,
|
|
2941
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(XIcon, { size: 14 })
|
|
872
2942
|
}
|
|
873
2943
|
)
|
|
874
|
-
]
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
};
|
|
878
|
-
|
|
879
|
-
// src/components/MessageList.tsx
|
|
880
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
881
|
-
var MessageList = ({ messages, empty, className }) => {
|
|
882
|
-
if (messages.length === 0) {
|
|
883
|
-
return empty ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "awr-messages__empty", children: empty }) : null;
|
|
884
|
-
}
|
|
885
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: ["awr-messages", className].filter(Boolean).join(" "), children: messages.map((m) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: `awr-msg awr-msg--${m.role}`, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "awr-msg__bubble", children: [
|
|
886
|
-
m.content,
|
|
887
|
-
m.pending && !m.content && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SpinnerIcon, { size: 14, className: "awr-msg__pending" })
|
|
888
|
-
] }) }, m.id)) });
|
|
889
|
-
};
|
|
890
|
-
|
|
891
|
-
// src/components/ModelLoadBar.tsx
|
|
892
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
893
|
-
var ModelLoadBar = ({ load, className }) => {
|
|
894
|
-
const pct = Math.round(Math.max(0, Math.min(1, load.progress)) * 100);
|
|
895
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: ["awr-modelload", className].filter(Boolean).join(" "), children: [
|
|
896
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "awr-modelload__head", children: [
|
|
897
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "awr-modelload__text", children: load.text || "Loading model\u2026" }),
|
|
898
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "awr-modelload__pct", children: [
|
|
899
|
-
pct,
|
|
900
|
-
"%"
|
|
901
|
-
] })
|
|
902
|
-
] }),
|
|
903
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "awr-modelload__track", role: "progressbar", "aria-valuenow": pct, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "awr-modelload__fill", style: { width: `${pct}%` } }) })
|
|
2944
|
+
] }, c.id);
|
|
2945
|
+
return renderChat ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react12.Fragment, { children: renderChat(c, active, row) }, c.id) : row;
|
|
2946
|
+
}) })
|
|
904
2947
|
] });
|
|
905
2948
|
};
|
|
906
2949
|
|
|
@@ -919,79 +2962,571 @@ var previewValue = (value, max = 140) => {
|
|
|
919
2962
|
text = text.replace(/\s+/g, " ").trim();
|
|
920
2963
|
return text.length > max ? `${text.slice(0, max - 1)}\u2026` : text;
|
|
921
2964
|
};
|
|
2965
|
+
var formatTokens = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(n >= 1e4 ? 0 : 1)}k` : String(n);
|
|
2966
|
+
var formatDuration = (ms) => {
|
|
2967
|
+
if (ms < 1e3) return `${Math.round(ms)} ms`;
|
|
2968
|
+
if (ms < 6e4) return `${(ms / 1e3).toFixed(ms < 1e4 ? 1 : 0)} s`;
|
|
2969
|
+
const s = Math.round(ms / 1e3);
|
|
2970
|
+
return `${Math.floor(s / 60)}m ${s % 60}s`;
|
|
2971
|
+
};
|
|
2972
|
+
var isDataImage = (v) => typeof v === "string" && /^data:image\/[\w.+-]+;base64,/.test(v);
|
|
2973
|
+
var imagesInOutput = (output, depth = 0) => {
|
|
2974
|
+
if (depth > 2 || output == null) return [];
|
|
2975
|
+
if (isDataImage(output)) return [output];
|
|
2976
|
+
if (Array.isArray(output)) return output.flatMap((v) => imagesInOutput(v, depth + 1));
|
|
2977
|
+
if (typeof output === "object") {
|
|
2978
|
+
const o = output;
|
|
2979
|
+
if (o.type === "image" && typeof o.data === "string") {
|
|
2980
|
+
const mime = typeof o.mimeType === "string" ? o.mimeType : "image/png";
|
|
2981
|
+
return [o.data.startsWith("data:") ? o.data : `data:${mime};base64,${o.data}`];
|
|
2982
|
+
}
|
|
2983
|
+
for (const key of ["dataUrl", "url", "image"])
|
|
2984
|
+
if (isDataImage(o[key])) return [o[key]];
|
|
2985
|
+
if (depth < 2) return Object.values(o).flatMap((v) => imagesInOutput(v, depth + 1));
|
|
2986
|
+
}
|
|
2987
|
+
return [];
|
|
2988
|
+
};
|
|
922
2989
|
|
|
923
|
-
// src/components/
|
|
2990
|
+
// src/components/ContextMeter.tsx
|
|
924
2991
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
925
|
-
var
|
|
2992
|
+
var ContextMeter = ({
|
|
2993
|
+
usage,
|
|
2994
|
+
budgetTokens,
|
|
2995
|
+
budget,
|
|
2996
|
+
compactions = [],
|
|
2997
|
+
onCompact,
|
|
2998
|
+
compacting,
|
|
2999
|
+
className
|
|
3000
|
+
}) => {
|
|
3001
|
+
const cached = usage.cachedInputTokens ?? 0;
|
|
3002
|
+
const reasoning = usage.reasoningTokens ?? 0;
|
|
3003
|
+
if (usage.totalTokens === 0 && !budget && compactions.length === 0 && !budgetTokens) {
|
|
3004
|
+
return null;
|
|
3005
|
+
}
|
|
3006
|
+
const hitRate = usage.inputTokens > 0 ? Math.round(cached / usage.inputTokens * 100) : 0;
|
|
3007
|
+
const fill = budgetTokens ? Math.min(1, usage.totalTokens / budgetTokens) : void 0;
|
|
3008
|
+
const last = compactions.at(-1);
|
|
3009
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: ["awr-context", className].filter(Boolean).join(" "), children: [
|
|
3010
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-context__row", children: [
|
|
3011
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { title: "input tokens", children: [
|
|
3012
|
+
"in ",
|
|
3013
|
+
formatTokens(usage.inputTokens)
|
|
3014
|
+
] }),
|
|
3015
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { title: "output tokens", children: [
|
|
3016
|
+
"out ",
|
|
3017
|
+
formatTokens(usage.outputTokens)
|
|
3018
|
+
] }),
|
|
3019
|
+
reasoning > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { title: "thinking tokens", children: [
|
|
3020
|
+
"think ",
|
|
3021
|
+
formatTokens(reasoning)
|
|
3022
|
+
] }),
|
|
3023
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { title: "input tokens served from the provider's prompt cache", children: [
|
|
3024
|
+
"cached ",
|
|
3025
|
+
formatTokens(cached),
|
|
3026
|
+
hitRate > 0 ? ` (${hitRate}%)` : ""
|
|
3027
|
+
] }),
|
|
3028
|
+
onCompact && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
3029
|
+
"button",
|
|
3030
|
+
{
|
|
3031
|
+
type: "button",
|
|
3032
|
+
className: "awr-btn awr-btn--ghost awr-context__compact",
|
|
3033
|
+
onClick: onCompact,
|
|
3034
|
+
disabled: compacting,
|
|
3035
|
+
children: compacting ? "Compacting\u2026" : "Compact"
|
|
3036
|
+
}
|
|
3037
|
+
)
|
|
3038
|
+
] }),
|
|
3039
|
+
fill !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
3040
|
+
"div",
|
|
3041
|
+
{
|
|
3042
|
+
className: `awr-context__track${fill >= 1 ? " is-full" : ""}`,
|
|
3043
|
+
title: `${usage.totalTokens} / ${budgetTokens} tokens`,
|
|
3044
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-context__fill", style: { width: `${fill * 100}%` } })
|
|
3045
|
+
}
|
|
3046
|
+
),
|
|
3047
|
+
budget && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-context__note awr-context__note--warn", children: [
|
|
3048
|
+
budget.kind === "tool-calls" ? "Tool-call" : `${budget.kind} token`,
|
|
3049
|
+
" limit reached (",
|
|
3050
|
+
budget.tokens,
|
|
3051
|
+
"/",
|
|
3052
|
+
budget.cap,
|
|
3053
|
+
") \u2014 the agent stopped early."
|
|
3054
|
+
] }),
|
|
3055
|
+
last && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-context__note", children: [
|
|
3056
|
+
"Compacted ",
|
|
3057
|
+
last.scope,
|
|
3058
|
+
": ",
|
|
3059
|
+
formatTokens(last.beforeTokens),
|
|
3060
|
+
" \u2192",
|
|
3061
|
+
" ",
|
|
3062
|
+
formatTokens(last.afterTokens),
|
|
3063
|
+
" tokens"
|
|
3064
|
+
] })
|
|
3065
|
+
] });
|
|
3066
|
+
};
|
|
3067
|
+
|
|
3068
|
+
// src/components/FilesPanel.tsx
|
|
3069
|
+
var import_react13 = require("react");
|
|
3070
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
3071
|
+
var PREVIEW_CHARS = 2e4;
|
|
3072
|
+
var FilesPanel = ({
|
|
3073
|
+
files: vfs,
|
|
3074
|
+
prefix = "/",
|
|
3075
|
+
title,
|
|
3076
|
+
allowUpload = true,
|
|
3077
|
+
allowDelete = true,
|
|
3078
|
+
uploadDir,
|
|
3079
|
+
onOpen,
|
|
3080
|
+
renderFile,
|
|
3081
|
+
labels,
|
|
3082
|
+
className
|
|
3083
|
+
}) => {
|
|
3084
|
+
const L = useLabels(labels);
|
|
3085
|
+
const fs = useVirtualFiles(vfs, prefix);
|
|
3086
|
+
const [preview, setPreview] = (0, import_react13.useState)();
|
|
3087
|
+
const inputRef = (0, import_react13.useRef)(null);
|
|
3088
|
+
(0, import_react13.useEffect)(() => {
|
|
3089
|
+
if (preview && !fs.files.some((f) => f.path === preview.path)) setPreview(void 0);
|
|
3090
|
+
}, [fs.files, preview]);
|
|
3091
|
+
const open = async (f) => {
|
|
3092
|
+
onOpen?.(f);
|
|
3093
|
+
if (preview?.path === f.path) return setPreview(void 0);
|
|
3094
|
+
if (f.mimeType.startsWith("image/")) {
|
|
3095
|
+
const src = await fs.dataUrl(f.path);
|
|
3096
|
+
if (src) setPreview({ path: f.path, kind: "image", src });
|
|
3097
|
+
return;
|
|
3098
|
+
}
|
|
3099
|
+
const text = await fs.text(f.path);
|
|
3100
|
+
if (text !== void 0) setPreview({ path: f.path, kind: "text", text });
|
|
3101
|
+
else setPreview(void 0);
|
|
3102
|
+
};
|
|
3103
|
+
const download = async (f) => {
|
|
3104
|
+
const href = await fs.dataUrl(f.path);
|
|
3105
|
+
if (!href) return;
|
|
3106
|
+
const a = document.createElement("a");
|
|
3107
|
+
a.href = href;
|
|
3108
|
+
a.download = f.path.split("/").pop() || "file";
|
|
3109
|
+
a.click();
|
|
3110
|
+
};
|
|
3111
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: ["awr-filespanel", className].filter(Boolean).join(" "), children: [
|
|
3112
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "awr-panel__head", children: [
|
|
3113
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "awr-panel__title", children: title ?? L.files }),
|
|
3114
|
+
allowUpload && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
3115
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3116
|
+
"button",
|
|
3117
|
+
{
|
|
3118
|
+
type: "button",
|
|
3119
|
+
className: "awr-iconbtn",
|
|
3120
|
+
"aria-label": L.upload,
|
|
3121
|
+
title: L.upload,
|
|
3122
|
+
onClick: () => inputRef.current?.click(),
|
|
3123
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PlusIcon, { size: 16 })
|
|
3124
|
+
}
|
|
3125
|
+
),
|
|
3126
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3127
|
+
"input",
|
|
3128
|
+
{
|
|
3129
|
+
ref: inputRef,
|
|
3130
|
+
type: "file",
|
|
3131
|
+
multiple: true,
|
|
3132
|
+
hidden: true,
|
|
3133
|
+
onChange: async (e) => {
|
|
3134
|
+
for (const f of Array.from(e.target.files ?? [])) await fs.upload(f, uploadDir);
|
|
3135
|
+
e.target.value = "";
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
)
|
|
3139
|
+
] })
|
|
3140
|
+
] }),
|
|
3141
|
+
fs.error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "awr-notice awr-notice--warn", children: fs.error }),
|
|
3142
|
+
!fs.loading && fs.files.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "awr-panel__empty", children: L.filesEmpty }),
|
|
3143
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "awr-filelist", children: fs.files.map((f) => {
|
|
3144
|
+
const row = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
3145
|
+
"li",
|
|
3146
|
+
{
|
|
3147
|
+
className: `awr-filelist__item${preview?.path === f.path ? " is-active" : ""}`,
|
|
3148
|
+
children: [
|
|
3149
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
3150
|
+
"button",
|
|
3151
|
+
{
|
|
3152
|
+
type: "button",
|
|
3153
|
+
className: "awr-filelist__open",
|
|
3154
|
+
onClick: () => void open(f),
|
|
3155
|
+
title: `${L.preview}: ${f.path}`,
|
|
3156
|
+
children: [
|
|
3157
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FileIcon, { size: 14 }),
|
|
3158
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "awr-filelist__path", children: f.path }),
|
|
3159
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "awr-filelist__size", children: L.bytes(f.size) })
|
|
3160
|
+
]
|
|
3161
|
+
}
|
|
3162
|
+
),
|
|
3163
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3164
|
+
"button",
|
|
3165
|
+
{
|
|
3166
|
+
type: "button",
|
|
3167
|
+
className: "awr-iconbtn",
|
|
3168
|
+
"aria-label": `${L.download} ${f.path}`,
|
|
3169
|
+
title: L.download,
|
|
3170
|
+
onClick: () => void download(f),
|
|
3171
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DownloadIcon, { size: 14 })
|
|
3172
|
+
}
|
|
3173
|
+
),
|
|
3174
|
+
allowDelete && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
3175
|
+
"button",
|
|
3176
|
+
{
|
|
3177
|
+
type: "button",
|
|
3178
|
+
className: "awr-iconbtn",
|
|
3179
|
+
"aria-label": `${L.delete} ${f.path}`,
|
|
3180
|
+
title: L.delete,
|
|
3181
|
+
onClick: () => void fs.remove(f.path),
|
|
3182
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(XIcon, { size: 14 })
|
|
3183
|
+
}
|
|
3184
|
+
)
|
|
3185
|
+
]
|
|
3186
|
+
},
|
|
3187
|
+
f.path
|
|
3188
|
+
);
|
|
3189
|
+
return renderFile ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react13.Fragment, { children: renderFile(f, row) }, f.path) : row;
|
|
3190
|
+
}) }),
|
|
3191
|
+
preview && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "awr-filepreview", children: preview.kind === "image" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: preview.src, alt: preview.path }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("pre", { children: preview.text.length > PREVIEW_CHARS ? `${preview.text.slice(0, PREVIEW_CHARS)}
|
|
3192
|
+
\u2026` : preview.text }) })
|
|
3193
|
+
] });
|
|
3194
|
+
};
|
|
3195
|
+
|
|
3196
|
+
// src/components/StepList.tsx
|
|
3197
|
+
var import_react14 = require("react");
|
|
3198
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
3199
|
+
var ToolCallRow = ({ call, showUsage = true, labels }) => {
|
|
3200
|
+
const L = useLabels(labels);
|
|
926
3201
|
const state = call.status === "calling" ? "calling" : call.ok === false ? "failed" : "ok";
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
call.
|
|
932
|
-
|
|
3202
|
+
const images = call.ok === false ? [] : imagesInOutput(call.output).slice(0, 4);
|
|
3203
|
+
const cost = [
|
|
3204
|
+
call.inputTokens ? `\u2248${formatTokens(call.inputTokens)} in` : "",
|
|
3205
|
+
call.outputTokens ? `\u2248${formatTokens(call.outputTokens)} out` : "",
|
|
3206
|
+
call.durationMs !== void 0 ? formatDuration(call.durationMs) : ""
|
|
3207
|
+
].filter(Boolean).join(" \xB7 ");
|
|
3208
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { className: `awr-tool awr-tool--${state}`, children: [
|
|
3209
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "awr-tool__row", children: [
|
|
3210
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ToolIcon, { size: 13, className: "awr-tool__icon" }),
|
|
3211
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("code", { className: "awr-tool__name", children: call.name }),
|
|
3212
|
+
previewValue(call.input) && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-tool__args", children: previewValue(call.input) }),
|
|
3213
|
+
call.status === "calling" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SpinnerIcon, { size: 12, className: "awr-tool__spin" }),
|
|
3214
|
+
call.status === "done" && call.ok === false && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-tool__badge", children: L.failed }),
|
|
3215
|
+
showUsage && cost && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-tool__cost", title: L.toolCostTitle, children: cost })
|
|
3216
|
+
] }),
|
|
3217
|
+
images.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "awr-tool__images", children: images.map((src, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("a", { href: src, target: "_blank", rel: "noreferrer", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { className: "awr-thumb", src, alt: `${call.name} result ${i + 1}` }) }, i)) })
|
|
3218
|
+
] });
|
|
3219
|
+
};
|
|
3220
|
+
var SubagentRow = ({
|
|
3221
|
+
sub,
|
|
3222
|
+
labels
|
|
3223
|
+
}) => {
|
|
3224
|
+
const L = useLabels(labels);
|
|
3225
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { className: `awr-subagent awr-subagent--${sub.status}`, children: [
|
|
3226
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "awr-subagent__head", children: [
|
|
3227
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BotIcon, { size: 13, className: "awr-subagent__icon" }),
|
|
3228
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-subagent__name", children: sub.name }),
|
|
3229
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-subagent__task", title: sub.task, children: previewValue(sub.task, 90) }),
|
|
3230
|
+
sub.status === "running" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SpinnerIcon, { size: 12, className: "awr-tool__spin" })
|
|
3231
|
+
] }),
|
|
3232
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "awr-subagent__activity", children: sub.status === "error" ? sub.error : sub.status === "done" ? previewValue(sub.text, 160) : `${sub.activity}${sub.toolCalls ? ` \xB7 ${L.toolCalls(sub.toolCalls)}` : ""}` })
|
|
933
3233
|
] });
|
|
934
3234
|
};
|
|
935
|
-
var
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
3235
|
+
var decisionLabel = (a, L) => a.status === "pending" ? L.consentWaiting : a.status === "approved" ? L.consentAllowed : L.consentDenied(a.reason);
|
|
3236
|
+
var StepItem = ({
|
|
3237
|
+
step,
|
|
3238
|
+
subagents,
|
|
3239
|
+
approvals,
|
|
3240
|
+
showToolCalls,
|
|
3241
|
+
showUsage,
|
|
3242
|
+
showThoughts,
|
|
3243
|
+
renderToolCall,
|
|
3244
|
+
L
|
|
3245
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { className: `awr-step awr-step--${step.blocked ? "blocked" : step.status}`, children: [
|
|
3246
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "awr-step__head", children: [
|
|
3247
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-step__marker", children: step.status === "running" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SpinnerIcon, { size: 14 }) : step.blocked ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AlertIcon, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CheckIcon, { size: 14 }) }),
|
|
3248
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "awr-step__index", children: [
|
|
939
3249
|
step.index,
|
|
940
3250
|
"/",
|
|
941
3251
|
step.total
|
|
942
3252
|
] }),
|
|
943
|
-
/* @__PURE__ */ (0,
|
|
3253
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-step__desc", children: step.step.description })
|
|
3254
|
+
] }),
|
|
3255
|
+
showThoughts && step.reasoning.trim() && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { className: "awr-thought", open: step.status === "running" && !step.text, children: [
|
|
3256
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("summary", { children: [
|
|
3257
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BrainIcon, { size: 13 }),
|
|
3258
|
+
" ",
|
|
3259
|
+
L.stepThoughts
|
|
3260
|
+
] }),
|
|
3261
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "awr-thought__text", children: step.reasoning.trim() })
|
|
944
3262
|
] }),
|
|
945
|
-
step.text.trim() && /* @__PURE__ */ (0,
|
|
946
|
-
step.toolCalls.length > 0 && /* @__PURE__ */ (0,
|
|
947
|
-
|
|
3263
|
+
step.text.trim() && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "awr-step__text", children: step.text.trim() }),
|
|
3264
|
+
showToolCalls && step.toolCalls.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-step__tools", children: step.toolCalls.map((call, i) => {
|
|
3265
|
+
const row = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ToolCallRow, { call, showUsage }, i);
|
|
3266
|
+
return renderToolCall ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react14.Fragment, { children: renderToolCall(call, row) }, i) : row;
|
|
3267
|
+
}) }),
|
|
3268
|
+
approvals.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-step__tools", children: approvals.map((a) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("li", { className: `awr-tool awr-tool__row awr-tool--approval-${a.status}`, children: [
|
|
3269
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ShieldIcon, { size: 13, className: "awr-tool__icon" }),
|
|
3270
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("code", { className: "awr-tool__name", children: a.name }),
|
|
3271
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "awr-tool__args", children: decisionLabel(a, L) })
|
|
3272
|
+
] }, a.id)) }),
|
|
3273
|
+
subagents.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "awr-subagents", children: subagents.map((sub) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SubagentRow, { sub }, sub.id)) }),
|
|
3274
|
+
step.blocked && step.summary && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "awr-step__blocked", children: step.summary })
|
|
948
3275
|
] });
|
|
949
|
-
var StepList = ({
|
|
3276
|
+
var StepList = ({
|
|
3277
|
+
steps,
|
|
3278
|
+
subagents = [],
|
|
3279
|
+
approvals = [],
|
|
3280
|
+
showToolCalls = true,
|
|
3281
|
+
showUsage = true,
|
|
3282
|
+
showThoughts = true,
|
|
3283
|
+
renderToolCall,
|
|
3284
|
+
labels,
|
|
3285
|
+
className
|
|
3286
|
+
}) => {
|
|
3287
|
+
const L = useLabels(labels);
|
|
950
3288
|
if (steps.length === 0) return null;
|
|
951
|
-
return /* @__PURE__ */ (0,
|
|
3289
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ol", { className: ["awr-steps", className].filter(Boolean).join(" "), children: steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
3290
|
+
StepItem,
|
|
3291
|
+
{
|
|
3292
|
+
step,
|
|
3293
|
+
subagents: subagents.filter((s) => s.stepId === step.id),
|
|
3294
|
+
approvals: approvals.filter((a) => a.stepId === step.id && a.status !== "pending"),
|
|
3295
|
+
showToolCalls,
|
|
3296
|
+
showUsage,
|
|
3297
|
+
showThoughts,
|
|
3298
|
+
renderToolCall,
|
|
3299
|
+
L
|
|
3300
|
+
},
|
|
3301
|
+
step.id
|
|
3302
|
+
)) });
|
|
3303
|
+
};
|
|
3304
|
+
|
|
3305
|
+
// src/components/MessageList.tsx
|
|
3306
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
3307
|
+
var usageLine = (usage, durationMs) => {
|
|
3308
|
+
const parts = [];
|
|
3309
|
+
if (usage && usage.totalTokens > 0) {
|
|
3310
|
+
parts.push(`in ${formatTokens(usage.inputTokens)}`, `out ${formatTokens(usage.outputTokens)}`);
|
|
3311
|
+
if (usage.reasoningTokens) parts.push(`think ${formatTokens(usage.reasoningTokens)}`);
|
|
3312
|
+
if (usage.cachedInputTokens) parts.push(`cached ${formatTokens(usage.cachedInputTokens)}`);
|
|
3313
|
+
}
|
|
3314
|
+
if (durationMs !== void 0) parts.push(formatDuration(durationMs));
|
|
3315
|
+
return parts.join(" \xB7 ");
|
|
3316
|
+
};
|
|
3317
|
+
var AttachmentView = ({ attachment: a }) => a.dataUrl && a.mediaType.startsWith("image/") ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("a", { href: a.dataUrl, target: "_blank", rel: "noreferrer", title: a.path ?? a.name, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("img", { className: "awr-thumb awr-thumb--msg", src: a.dataUrl, alt: a.name }) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "awr-chip awr-file", title: a.path ?? a.mediaType, children: [
|
|
3318
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FileIcon, { size: 13 }),
|
|
3319
|
+
" ",
|
|
3320
|
+
a.name
|
|
3321
|
+
] });
|
|
3322
|
+
var toolCallCount = (m) => (m.steps ?? []).reduce((n, s) => n + s.toolCalls.length, 0);
|
|
3323
|
+
var activitySummary = (m, showToolCalls, L) => {
|
|
3324
|
+
const steps = m.steps ?? [];
|
|
3325
|
+
const parts = [L.steps(steps.length)];
|
|
3326
|
+
if (showToolCalls) parts.push(L.toolCalls(toolCallCount(m)));
|
|
3327
|
+
if (m.subagents?.length) parts.push(L.subagents(m.subagents.length));
|
|
3328
|
+
if (m.skills?.length) parts.push(L.skillsUsed(m.skills.join(", ")));
|
|
3329
|
+
return parts.join(" \xB7 ");
|
|
3330
|
+
};
|
|
3331
|
+
var MessageList = ({
|
|
3332
|
+
messages,
|
|
3333
|
+
empty,
|
|
3334
|
+
showActivity = true,
|
|
3335
|
+
showToolCalls = true,
|
|
3336
|
+
showUsage = true,
|
|
3337
|
+
showThoughts = true,
|
|
3338
|
+
activityOpen = false,
|
|
3339
|
+
liveExtra,
|
|
3340
|
+
renderContent,
|
|
3341
|
+
renderMessage,
|
|
3342
|
+
renderAttachment,
|
|
3343
|
+
renderToolCall,
|
|
3344
|
+
labels,
|
|
3345
|
+
className
|
|
3346
|
+
}) => {
|
|
3347
|
+
const L = useLabels(labels);
|
|
3348
|
+
if (messages.length === 0) {
|
|
3349
|
+
return empty ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "awr-messages__empty", children: empty }) : null;
|
|
3350
|
+
}
|
|
3351
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: ["awr-messages", className].filter(Boolean).join(" "), children: messages.map((m) => {
|
|
3352
|
+
const steps = m.steps ?? [];
|
|
3353
|
+
const hasActivity = showActivity && (steps.length > 0 || (m.subagents?.length ?? 0) > 0 || m.pending && !!liveExtra);
|
|
3354
|
+
const usage = showUsage ? usageLine(m.usage, m.durationMs) : "";
|
|
3355
|
+
const node = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3356
|
+
"div",
|
|
3357
|
+
{
|
|
3358
|
+
className: `awr-msg awr-msg--${m.role}${m.error ? " awr-msg--error" : ""}${m.pending ? " is-pending" : ""}`,
|
|
3359
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "awr-msg__col", children: [
|
|
3360
|
+
m.role === "assistant" && hasActivity && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("details", { className: "awr-activity", open: m.pending || activityOpen, children: [
|
|
3361
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("summary", { className: "awr-activity__summary", children: activitySummary(m, showToolCalls, L) }),
|
|
3362
|
+
m.pending && liveExtra,
|
|
3363
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3364
|
+
StepList,
|
|
3365
|
+
{
|
|
3366
|
+
steps,
|
|
3367
|
+
subagents: m.subagents,
|
|
3368
|
+
approvals: m.approvals,
|
|
3369
|
+
showToolCalls,
|
|
3370
|
+
showUsage,
|
|
3371
|
+
showThoughts,
|
|
3372
|
+
renderToolCall,
|
|
3373
|
+
labels
|
|
3374
|
+
}
|
|
3375
|
+
),
|
|
3376
|
+
showThoughts && m.reasoning?.trim() && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("details", { className: "awr-thought", children: [
|
|
3377
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("summary", { children: [
|
|
3378
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(BrainIcon, { size: 13 }),
|
|
3379
|
+
" ",
|
|
3380
|
+
L.answerThoughts
|
|
3381
|
+
] }),
|
|
3382
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "awr-thought__text", children: m.reasoning.trim() })
|
|
3383
|
+
] })
|
|
3384
|
+
] }),
|
|
3385
|
+
(m.content || m.pending || !m.attachments?.length) && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "awr-msg__bubble", children: [
|
|
3386
|
+
m.content ? renderContent ? renderContent(m) : m.content : null,
|
|
3387
|
+
m.pending && !m.content && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SpinnerIcon, { size: 14, className: "awr-msg__pending" })
|
|
3388
|
+
] }),
|
|
3389
|
+
m.attachments?.length ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "awr-msg__attachments", "aria-label": L.attachments, children: m.attachments.map((a, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "awr-msg__attachment", children: renderAttachment ? renderAttachment(a, m) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AttachmentView, { attachment: a }) }, i)) }) : null,
|
|
3390
|
+
m.role === "assistant" && usage && !m.pending && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "awr-msg__usage", title: L.usageTitle, children: usage })
|
|
3391
|
+
] })
|
|
3392
|
+
},
|
|
3393
|
+
m.id
|
|
3394
|
+
);
|
|
3395
|
+
return renderMessage ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: renderMessage(m, node) }, m.id) : node;
|
|
3396
|
+
}) });
|
|
3397
|
+
};
|
|
3398
|
+
|
|
3399
|
+
// src/components/ModelLoadBar.tsx
|
|
3400
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
3401
|
+
var ModelLoadBar = ({ load, className }) => {
|
|
3402
|
+
const pct = Math.round(Math.max(0, Math.min(1, load.progress)) * 100);
|
|
3403
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: ["awr-modelload", className].filter(Boolean).join(" "), children: [
|
|
3404
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "awr-modelload__head", children: [
|
|
3405
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "awr-modelload__text", children: load.text || "Loading model\u2026" }),
|
|
3406
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "awr-modelload__pct", children: [
|
|
3407
|
+
pct,
|
|
3408
|
+
"%"
|
|
3409
|
+
] })
|
|
3410
|
+
] }),
|
|
3411
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "awr-modelload__track", role: "progressbar", "aria-valuenow": pct, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "awr-modelload__fill", style: { width: `${pct}%` } }) })
|
|
3412
|
+
] });
|
|
3413
|
+
};
|
|
3414
|
+
|
|
3415
|
+
// src/components/ToolApprovalPrompt.tsx
|
|
3416
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
3417
|
+
var ToolApprovalPrompt = ({
|
|
3418
|
+
approvals,
|
|
3419
|
+
onApprove,
|
|
3420
|
+
onDeny,
|
|
3421
|
+
allowRemember = true,
|
|
3422
|
+
renderApproval,
|
|
3423
|
+
labels,
|
|
3424
|
+
className
|
|
3425
|
+
}) => {
|
|
3426
|
+
const L = useLabels(labels);
|
|
3427
|
+
if (approvals.length === 0) return null;
|
|
3428
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: ["awr-approvals", className].filter(Boolean).join(" "), role: "alert", children: approvals.map((a) => {
|
|
3429
|
+
const card = /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "awr-approval", children: [
|
|
3430
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "awr-approval__head", children: [
|
|
3431
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(ShieldIcon, { size: 14, className: "awr-approval__icon" }),
|
|
3432
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
|
|
3433
|
+
L.approvalLead,
|
|
3434
|
+
" ",
|
|
3435
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("code", { className: "awr-tool__name", children: a.name }),
|
|
3436
|
+
a.readOnly ? ` (${L.readOnlyTool})` : ""
|
|
3437
|
+
] })
|
|
3438
|
+
] }),
|
|
3439
|
+
previewValue(a.input, 300) && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("pre", { className: "awr-approval__input", children: previewValue(a.input, 300) }),
|
|
3440
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "awr-approval__actions", children: [
|
|
3441
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3442
|
+
"button",
|
|
3443
|
+
{
|
|
3444
|
+
type: "button",
|
|
3445
|
+
className: "awr-btn awr-btn--primary",
|
|
3446
|
+
onClick: () => onApprove(a.id),
|
|
3447
|
+
children: L.approve
|
|
3448
|
+
}
|
|
3449
|
+
),
|
|
3450
|
+
allowRemember && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3451
|
+
"button",
|
|
3452
|
+
{
|
|
3453
|
+
type: "button",
|
|
3454
|
+
className: "awr-btn",
|
|
3455
|
+
onClick: () => onApprove(a.id, { remember: true }),
|
|
3456
|
+
children: L.alwaysAllow
|
|
3457
|
+
}
|
|
3458
|
+
),
|
|
3459
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3460
|
+
"button",
|
|
3461
|
+
{
|
|
3462
|
+
type: "button",
|
|
3463
|
+
className: "awr-btn awr-btn--danger",
|
|
3464
|
+
onClick: () => onDeny(a.id, L.declinedReason),
|
|
3465
|
+
children: L.deny
|
|
3466
|
+
}
|
|
3467
|
+
)
|
|
3468
|
+
] })
|
|
3469
|
+
] }, a.id);
|
|
3470
|
+
return renderApproval ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { children: renderApproval(a, card) }, a.id) : card;
|
|
3471
|
+
}) });
|
|
952
3472
|
};
|
|
953
3473
|
|
|
954
3474
|
// src/components/UsageBadge.tsx
|
|
955
|
-
var
|
|
956
|
-
var
|
|
957
|
-
var UsageBadge = ({ usage, className }) => {
|
|
3475
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
3476
|
+
var UsageBadge = ({ usage, compact = false, className }) => {
|
|
958
3477
|
if (usage.totalTokens === 0) return null;
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
3478
|
+
const reasoning = usage.reasoningTokens ?? 0;
|
|
3479
|
+
const cached = usage.cachedInputTokens ?? 0;
|
|
3480
|
+
const title = [
|
|
3481
|
+
`${usage.inputTokens} in + ${usage.outputTokens} out = ${usage.totalTokens} tokens`,
|
|
3482
|
+
reasoning ? `${reasoning} thinking` : "",
|
|
3483
|
+
cached ? `${cached} input tokens from the prompt cache` : ""
|
|
3484
|
+
].filter(Boolean).join(" \xB7 ");
|
|
3485
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: ["awr-usage", className].filter(Boolean).join(" "), title, children: [
|
|
3486
|
+
formatTokens(usage.inputTokens),
|
|
3487
|
+
"\u2191 ",
|
|
3488
|
+
formatTokens(usage.outputTokens),
|
|
3489
|
+
"\u2193",
|
|
3490
|
+
!compact && reasoning > 0 && ` \xB7 ${formatTokens(reasoning)} think`,
|
|
3491
|
+
!compact && cached > 0 && ` \xB7 ${formatTokens(cached)} cached`
|
|
3492
|
+
] });
|
|
972
3493
|
};
|
|
973
3494
|
|
|
974
3495
|
// src/components/AgentChat.tsx
|
|
975
|
-
var
|
|
976
|
-
var
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
return "Working\u2026";
|
|
982
|
-
case "error":
|
|
983
|
-
return "Failed to start";
|
|
984
|
-
default:
|
|
985
|
-
return "Ready";
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
var AgentChat = ({
|
|
3496
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3497
|
+
var isHistoryHook = (h) => typeof h === "object" && h !== null && "select" in h && "chats" in h;
|
|
3498
|
+
var cx = (...names) => names.filter(Boolean).join(" ");
|
|
3499
|
+
var AgentChat = (props) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(AgentLabelsProvider, { labels: props.labels ?? NO_LABELS, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(AgentChatInner, { ...props }) });
|
|
3500
|
+
var NO_LABELS = {};
|
|
3501
|
+
var AgentChatInner = ({
|
|
989
3502
|
controller,
|
|
990
3503
|
title,
|
|
3504
|
+
emptyState,
|
|
991
3505
|
placeholder,
|
|
992
3506
|
showActivity = true,
|
|
3507
|
+
showToolCalls = true,
|
|
993
3508
|
showUsage = true,
|
|
994
|
-
|
|
3509
|
+
showThoughts = true,
|
|
3510
|
+
showTotalUsage = true,
|
|
3511
|
+
showStatus = true,
|
|
3512
|
+
showApprovalMode = true,
|
|
3513
|
+
showContext = false,
|
|
3514
|
+
activityOpen = false,
|
|
3515
|
+
history,
|
|
3516
|
+
defaultHistoryOpen,
|
|
3517
|
+
files,
|
|
3518
|
+
defaultFilesOpen = false,
|
|
3519
|
+
narrowWidth = 760,
|
|
3520
|
+
composer,
|
|
3521
|
+
renderContent,
|
|
3522
|
+
renderMessage,
|
|
3523
|
+
renderAttachment,
|
|
3524
|
+
renderToolCall,
|
|
3525
|
+
renderApproval,
|
|
3526
|
+
slots = {},
|
|
3527
|
+
components = {},
|
|
3528
|
+
theme = "auto",
|
|
3529
|
+
classNames = {},
|
|
995
3530
|
className,
|
|
996
3531
|
style
|
|
997
3532
|
}) => {
|
|
@@ -1002,72 +3537,354 @@ var AgentChat = ({
|
|
|
1002
3537
|
"<AgentChat> needs a `controller` prop from useAgent(), or an enclosing <AgentProvider>."
|
|
1003
3538
|
);
|
|
1004
3539
|
}
|
|
1005
|
-
const
|
|
1006
|
-
|
|
3540
|
+
const L = useLabels();
|
|
3541
|
+
const external = isHistoryHook(history) ? history : void 0;
|
|
3542
|
+
const [ownStore] = (0, import_react15.useState)(
|
|
3543
|
+
() => history instanceof ChatHistoryStore ? history : new ChatHistoryStore()
|
|
3544
|
+
);
|
|
3545
|
+
const own = useChatHistory(agent, {
|
|
3546
|
+
store: ownStore,
|
|
3547
|
+
enabled: Boolean(history) && !external
|
|
3548
|
+
});
|
|
3549
|
+
const chats = history ? external ?? own : void 0;
|
|
3550
|
+
const rootRef = (0, import_react15.useRef)(null);
|
|
3551
|
+
const [narrow, setNarrow] = (0, import_react15.useState)(void 0);
|
|
3552
|
+
(0, import_react15.useEffect)(() => {
|
|
3553
|
+
const el = rootRef.current;
|
|
3554
|
+
if (!el || typeof ResizeObserver === "undefined") return setNarrow(false);
|
|
3555
|
+
const measure = () => setNarrow(el.getBoundingClientRect().width < narrowWidth);
|
|
3556
|
+
measure();
|
|
3557
|
+
const ro = new ResizeObserver(measure);
|
|
3558
|
+
ro.observe(el);
|
|
3559
|
+
return () => ro.disconnect();
|
|
3560
|
+
}, [narrowWidth]);
|
|
3561
|
+
const [historyChoice, setHistoryOpen] = (0, import_react15.useState)(defaultHistoryOpen);
|
|
3562
|
+
const historyOpen = historyChoice ?? narrow === false;
|
|
3563
|
+
const [filesOpen, setFilesOpen] = (0, import_react15.useState)(defaultFilesOpen);
|
|
3564
|
+
const toggleHistory = () => {
|
|
3565
|
+
setHistoryOpen(!historyOpen);
|
|
3566
|
+
if (narrow && !historyOpen) setFilesOpen(false);
|
|
3567
|
+
};
|
|
3568
|
+
const toggleFiles = () => {
|
|
3569
|
+
setFilesOpen((o) => !o);
|
|
3570
|
+
if (narrow && !filesOpen) setHistoryOpen(false);
|
|
3571
|
+
};
|
|
3572
|
+
const bodyRef = (0, import_react15.useRef)(null);
|
|
3573
|
+
const stickRef = (0, import_react15.useRef)(true);
|
|
3574
|
+
(0, import_react15.useEffect)(() => {
|
|
1007
3575
|
const el = bodyRef.current;
|
|
1008
|
-
if (el) el.scrollTop = el.scrollHeight;
|
|
1009
|
-
}, [agent.messages, agent.steps, agent.finalText, agent.modelLoad]);
|
|
3576
|
+
if (el && stickRef.current) el.scrollTop = el.scrollHeight;
|
|
3577
|
+
}, [agent.messages, agent.steps, agent.finalText, agent.modelLoad, agent.pendingApprovals]);
|
|
3578
|
+
const [compacting, setCompacting] = (0, import_react15.useState)(false);
|
|
3579
|
+
const compact = () => {
|
|
3580
|
+
setCompacting(true);
|
|
3581
|
+
void agent.compact().finally(() => setCompacting(false));
|
|
3582
|
+
};
|
|
3583
|
+
const Composer2 = components.Composer ?? AgentComposer;
|
|
3584
|
+
const Messages = components.MessageList ?? MessageList;
|
|
3585
|
+
const HistoryList = components.HistoryList ?? ChatHistoryList;
|
|
3586
|
+
const Files = components.FilesPanel ?? FilesPanel;
|
|
3587
|
+
const Approvals = components.ApprovalPrompt ?? ToolApprovalPrompt;
|
|
3588
|
+
const loading = agent.modelLoad && agent.modelLoad.progress < 1;
|
|
1010
3589
|
const showReplan = agent.replan && agent.replan.mode !== "continue";
|
|
1011
|
-
const
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MessageList, { messages: agent.messages, empty: emptyState }),
|
|
1016
|
-
showActivity && (agent.steps.length > 0 || agent.planThought) && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "awr-activity", children: [
|
|
1017
|
-
agent.planThought.trim() && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { className: "awr-activity__plan", children: [
|
|
1018
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("summary", { children: "Plan" }),
|
|
1019
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "awr-activity__thought", children: agent.planThought })
|
|
1020
|
-
] }),
|
|
1021
|
-
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(StepList, { steps: agent.steps }),
|
|
1022
|
-
showReplan && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "awr-activity__replan", children: [
|
|
1023
|
-
"Replanned (",
|
|
1024
|
-
agent.replan.mode,
|
|
1025
|
-
"): ",
|
|
1026
|
-
agent.replan.reason
|
|
1027
|
-
] })
|
|
1028
|
-
] }),
|
|
1029
|
-
agent.modelLoad && (loading || agent.isRunning) && agent.modelLoad.progress < 1 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ModelLoadBar, { load: agent.modelLoad })
|
|
3590
|
+
const liveExtra = agent.planThought.trim() || showReplan ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
3591
|
+
agent.planThought.trim() && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("details", { className: "awr-activity__plan", children: [
|
|
3592
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("summary", { children: L.planned }),
|
|
3593
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "awr-activity__thought", children: agent.planThought })
|
|
1030
3594
|
] }),
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
3595
|
+
showReplan && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "awr-activity__replan", children: L.replanned(agent.replan.mode, agent.replan.reason) })
|
|
3596
|
+
] }) : void 0;
|
|
3597
|
+
const header = slots.header === false ? null : slots.header !== void 0 ? slots.header : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: cx("awr-chat__header", classNames.header), children: [
|
|
3598
|
+
chats && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3599
|
+
"button",
|
|
3600
|
+
{
|
|
3601
|
+
type: "button",
|
|
3602
|
+
className: cx("awr-iconbtn", historyOpen && "is-on"),
|
|
3603
|
+
"aria-label": L.showHistory,
|
|
3604
|
+
title: L.showHistory,
|
|
3605
|
+
"aria-pressed": historyOpen,
|
|
3606
|
+
onClick: toggleHistory,
|
|
3607
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(HistoryIcon, { size: 16 })
|
|
3608
|
+
}
|
|
3609
|
+
),
|
|
3610
|
+
slots.headerStart,
|
|
3611
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "awr-chat__title", children: title }),
|
|
3612
|
+
showStatus && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: `awr-status awr-status--${agent.status}`, title: L.status[agent.status], children: [
|
|
3613
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "awr-status__dot" }),
|
|
3614
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "awr-status__text", children: L.status[agent.status] })
|
|
1035
3615
|
] }),
|
|
1036
|
-
/* @__PURE__ */ (0,
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
{
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
disabled: !agent.isReady && !agent.isRunning,
|
|
1051
|
-
placeholder
|
|
1052
|
-
}
|
|
1053
|
-
)
|
|
1054
|
-
] })
|
|
3616
|
+
showTotalUsage && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { title: L.totalUsage, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(UsageBadge, { usage: agent.totalUsage, compact: narrow !== false }) }),
|
|
3617
|
+
files && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3618
|
+
"button",
|
|
3619
|
+
{
|
|
3620
|
+
type: "button",
|
|
3621
|
+
className: cx("awr-iconbtn", filesOpen && "is-on"),
|
|
3622
|
+
"aria-label": L.showFiles,
|
|
3623
|
+
title: L.showFiles,
|
|
3624
|
+
"aria-pressed": filesOpen,
|
|
3625
|
+
onClick: toggleFiles,
|
|
3626
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FileIcon, { size: 16 })
|
|
3627
|
+
}
|
|
3628
|
+
),
|
|
3629
|
+
slots.headerEnd
|
|
1055
3630
|
] });
|
|
3631
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
3632
|
+
"div",
|
|
3633
|
+
{
|
|
3634
|
+
ref: rootRef,
|
|
3635
|
+
className: cx("awr-chat", narrow && "awr-chat--narrow", className, classNames.root),
|
|
3636
|
+
style,
|
|
3637
|
+
"data-awr-theme": theme === "auto" ? void 0 : theme,
|
|
3638
|
+
children: [
|
|
3639
|
+
chats && historyOpen && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("aside", { className: cx("awr-chat__sidebar", classNames.sidebar), children: [
|
|
3640
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3641
|
+
HistoryList,
|
|
3642
|
+
{
|
|
3643
|
+
history: {
|
|
3644
|
+
...chats,
|
|
3645
|
+
// Picking a chat on a narrow panel closes the overlay.
|
|
3646
|
+
select: async (id) => {
|
|
3647
|
+
await chats.select(id);
|
|
3648
|
+
if (narrow) setHistoryOpen(false);
|
|
3649
|
+
},
|
|
3650
|
+
newChat: () => {
|
|
3651
|
+
chats.newChat();
|
|
3652
|
+
if (narrow) setHistoryOpen(false);
|
|
3653
|
+
}
|
|
3654
|
+
},
|
|
3655
|
+
disabled: agent.isRunning
|
|
3656
|
+
}
|
|
3657
|
+
),
|
|
3658
|
+
slots.sidebar,
|
|
3659
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3660
|
+
"button",
|
|
3661
|
+
{
|
|
3662
|
+
type: "button",
|
|
3663
|
+
className: "awr-iconbtn awr-chat__closeside",
|
|
3664
|
+
"aria-label": L.close,
|
|
3665
|
+
onClick: () => setHistoryOpen(false),
|
|
3666
|
+
children: "\xD7"
|
|
3667
|
+
}
|
|
3668
|
+
)
|
|
3669
|
+
] }),
|
|
3670
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: cx("awr-chat__main", classNames.main), children: [
|
|
3671
|
+
header,
|
|
3672
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
|
|
3673
|
+
"div",
|
|
3674
|
+
{
|
|
3675
|
+
className: cx("awr-chat__body", classNames.body),
|
|
3676
|
+
ref: bodyRef,
|
|
3677
|
+
onScroll: (e) => {
|
|
3678
|
+
const el = e.currentTarget;
|
|
3679
|
+
stickRef.current = el.scrollHeight - el.scrollTop - el.clientHeight < 80;
|
|
3680
|
+
},
|
|
3681
|
+
children: [
|
|
3682
|
+
slots.beforeMessages,
|
|
3683
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3684
|
+
Messages,
|
|
3685
|
+
{
|
|
3686
|
+
messages: agent.messages,
|
|
3687
|
+
empty: emptyState ?? L.emptyState,
|
|
3688
|
+
showActivity,
|
|
3689
|
+
showToolCalls,
|
|
3690
|
+
showUsage,
|
|
3691
|
+
showThoughts,
|
|
3692
|
+
activityOpen,
|
|
3693
|
+
liveExtra,
|
|
3694
|
+
renderContent,
|
|
3695
|
+
renderMessage,
|
|
3696
|
+
renderAttachment,
|
|
3697
|
+
renderToolCall
|
|
3698
|
+
}
|
|
3699
|
+
),
|
|
3700
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3701
|
+
Approvals,
|
|
3702
|
+
{
|
|
3703
|
+
approvals: agent.pendingApprovals,
|
|
3704
|
+
onApprove: agent.approve,
|
|
3705
|
+
onDeny: agent.deny,
|
|
3706
|
+
renderApproval
|
|
3707
|
+
}
|
|
3708
|
+
),
|
|
3709
|
+
agent.modelLoad && loading && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ModelLoadBar, { load: agent.modelLoad }),
|
|
3710
|
+
slots.afterMessages
|
|
3711
|
+
]
|
|
3712
|
+
}
|
|
3713
|
+
),
|
|
3714
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: cx("awr-chat__footer", classNames.footer), children: [
|
|
3715
|
+
slots.footerStart,
|
|
3716
|
+
showContext !== false && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3717
|
+
ContextMeter,
|
|
3718
|
+
{
|
|
3719
|
+
usage: agent.usage,
|
|
3720
|
+
budgetTokens: typeof showContext === "number" ? showContext : void 0,
|
|
3721
|
+
budget: agent.budget,
|
|
3722
|
+
compactions: agent.compactions,
|
|
3723
|
+
onCompact: agent.isRunning ? void 0 : compact,
|
|
3724
|
+
compacting
|
|
3725
|
+
}
|
|
3726
|
+
),
|
|
3727
|
+
composer === false ? agent.error && agent.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "awr-chat__error", children: [
|
|
3728
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(AlertIcon, { size: 14 }),
|
|
3729
|
+
" ",
|
|
3730
|
+
agent.error
|
|
3731
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3732
|
+
Composer2,
|
|
3733
|
+
{
|
|
3734
|
+
controller: agent,
|
|
3735
|
+
showApprovalMode,
|
|
3736
|
+
files,
|
|
3737
|
+
dropZone: rootRef,
|
|
3738
|
+
...placeholder ? { placeholder } : {},
|
|
3739
|
+
...composer
|
|
3740
|
+
}
|
|
3741
|
+
)
|
|
3742
|
+
] })
|
|
3743
|
+
] }),
|
|
3744
|
+
files && filesOpen && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("aside", { className: cx("awr-chat__files", classNames.files), children: [
|
|
3745
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Files, { files }),
|
|
3746
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
3747
|
+
"button",
|
|
3748
|
+
{
|
|
3749
|
+
type: "button",
|
|
3750
|
+
className: "awr-iconbtn awr-chat__closeside",
|
|
3751
|
+
"aria-label": L.close,
|
|
3752
|
+
onClick: () => setFilesOpen(false),
|
|
3753
|
+
children: "\xD7"
|
|
3754
|
+
}
|
|
3755
|
+
)
|
|
3756
|
+
] })
|
|
3757
|
+
]
|
|
3758
|
+
}
|
|
3759
|
+
);
|
|
3760
|
+
};
|
|
3761
|
+
|
|
3762
|
+
// src/components/Composer.tsx
|
|
3763
|
+
var import_react16 = require("react");
|
|
3764
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
3765
|
+
var Composer = ({
|
|
3766
|
+
onSubmit,
|
|
3767
|
+
busy = false,
|
|
3768
|
+
onStop,
|
|
3769
|
+
disabled = false,
|
|
3770
|
+
placeholder = "Ask the agent to do something\u2026",
|
|
3771
|
+
className
|
|
3772
|
+
}) => {
|
|
3773
|
+
const [text, setText] = (0, import_react16.useState)("");
|
|
3774
|
+
const submit = () => {
|
|
3775
|
+
const value = text.trim();
|
|
3776
|
+
if (!value || busy || disabled) return;
|
|
3777
|
+
setText("");
|
|
3778
|
+
onSubmit(value);
|
|
3779
|
+
};
|
|
3780
|
+
const onKeyDown = (e) => {
|
|
3781
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
3782
|
+
e.preventDefault();
|
|
3783
|
+
submit();
|
|
3784
|
+
}
|
|
3785
|
+
};
|
|
3786
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
3787
|
+
"form",
|
|
3788
|
+
{
|
|
3789
|
+
className: ["awr-composer", className].filter(Boolean).join(" "),
|
|
3790
|
+
onSubmit: (e) => {
|
|
3791
|
+
e.preventDefault();
|
|
3792
|
+
submit();
|
|
3793
|
+
},
|
|
3794
|
+
children: [
|
|
3795
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3796
|
+
"textarea",
|
|
3797
|
+
{
|
|
3798
|
+
className: "awr-composer__input",
|
|
3799
|
+
value: text,
|
|
3800
|
+
onChange: (e) => setText(e.target.value),
|
|
3801
|
+
onKeyDown,
|
|
3802
|
+
placeholder,
|
|
3803
|
+
disabled,
|
|
3804
|
+
rows: 1
|
|
3805
|
+
}
|
|
3806
|
+
),
|
|
3807
|
+
busy ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3808
|
+
"button",
|
|
3809
|
+
{
|
|
3810
|
+
type: "button",
|
|
3811
|
+
className: "awr-composer__btn awr-composer__btn--stop",
|
|
3812
|
+
onClick: onStop,
|
|
3813
|
+
"aria-label": "Stop",
|
|
3814
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(StopIcon, { size: 18 })
|
|
3815
|
+
}
|
|
3816
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3817
|
+
"button",
|
|
3818
|
+
{
|
|
3819
|
+
type: "submit",
|
|
3820
|
+
className: "awr-composer__btn",
|
|
3821
|
+
disabled: disabled || !text.trim(),
|
|
3822
|
+
"aria-label": "Send",
|
|
3823
|
+
children: disabled ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SpinnerIcon, { size: 18 }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SendIcon, { size: 18 })
|
|
3824
|
+
}
|
|
3825
|
+
)
|
|
3826
|
+
]
|
|
3827
|
+
}
|
|
3828
|
+
);
|
|
1056
3829
|
};
|
|
1057
3830
|
|
|
1058
3831
|
// src/components/PlanView.tsx
|
|
1059
|
-
var
|
|
3832
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1060
3833
|
var PlanView = ({ plan, showThought = true, className }) => {
|
|
1061
3834
|
if (!plan.steps.length && !plan.thought) return null;
|
|
1062
|
-
return /* @__PURE__ */ (0,
|
|
1063
|
-
showThought && plan.thought.trim() && /* @__PURE__ */ (0,
|
|
1064
|
-
plan.steps.length > 0 && /* @__PURE__ */ (0,
|
|
3835
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: ["awr-plan", className].filter(Boolean).join(" "), children: [
|
|
3836
|
+
showThought && plan.thought.trim() && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { className: "awr-plan__thought", children: plan.thought }),
|
|
3837
|
+
plan.steps.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("ol", { className: "awr-plan__steps", children: plan.steps.map((step) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("li", { className: "awr-plan__step", children: step.description }, step.id)) })
|
|
1065
3838
|
] });
|
|
1066
3839
|
};
|
|
1067
3840
|
|
|
3841
|
+
// src/components/ApprovalModeSwitch.tsx
|
|
3842
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
3843
|
+
var DEFAULT_LABELS = {
|
|
3844
|
+
autopilot: "Autopilot",
|
|
3845
|
+
"ask-writes": "Ask before changes",
|
|
3846
|
+
"ask-all": "Ask always",
|
|
3847
|
+
"read-only": "Read-only"
|
|
3848
|
+
};
|
|
3849
|
+
var HINTS = {
|
|
3850
|
+
autopilot: "Run every tool without asking",
|
|
3851
|
+
"ask-writes": "Run read-only tools freely; ask before anything that may change state",
|
|
3852
|
+
"ask-all": "Ask before every tool call",
|
|
3853
|
+
"read-only": "Run read-only tools; refuse everything else without asking"
|
|
3854
|
+
};
|
|
3855
|
+
var ApprovalModeSwitch = ({
|
|
3856
|
+
mode,
|
|
3857
|
+
onChange,
|
|
3858
|
+
modes = ["autopilot", "ask-writes", "ask-all", "read-only"],
|
|
3859
|
+
labels,
|
|
3860
|
+
disabled,
|
|
3861
|
+
className
|
|
3862
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3863
|
+
"div",
|
|
3864
|
+
{
|
|
3865
|
+
className: ["awr-modeswitch", className].filter(Boolean).join(" "),
|
|
3866
|
+
role: "radiogroup",
|
|
3867
|
+
"aria-label": "Tool consent",
|
|
3868
|
+
children: modes.map((m) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
|
|
3869
|
+
"button",
|
|
3870
|
+
{
|
|
3871
|
+
type: "button",
|
|
3872
|
+
role: "radio",
|
|
3873
|
+
"aria-checked": mode === m,
|
|
3874
|
+
title: HINTS[m],
|
|
3875
|
+
className: `awr-modeswitch__opt${mode === m ? " is-active" : ""}`,
|
|
3876
|
+
onClick: () => onChange(m),
|
|
3877
|
+
disabled,
|
|
3878
|
+
children: labels?.[m] ?? DEFAULT_LABELS[m]
|
|
3879
|
+
},
|
|
3880
|
+
m
|
|
3881
|
+
))
|
|
3882
|
+
}
|
|
3883
|
+
);
|
|
3884
|
+
|
|
1068
3885
|
// src/components/ApiKeyForm.tsx
|
|
1069
|
-
var
|
|
1070
|
-
var
|
|
3886
|
+
var import_react17 = require("react");
|
|
3887
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1071
3888
|
var ApiKeyForm = ({
|
|
1072
3889
|
credentials,
|
|
1073
3890
|
credentialRef,
|
|
@@ -1076,10 +3893,10 @@ var ApiKeyForm = ({
|
|
|
1076
3893
|
onChange,
|
|
1077
3894
|
className
|
|
1078
3895
|
}) => {
|
|
1079
|
-
const [value, setValue] = (0,
|
|
1080
|
-
const [present, setPresent] = (0,
|
|
1081
|
-
const [busy, setBusy] = (0,
|
|
1082
|
-
(0,
|
|
3896
|
+
const [value, setValue] = (0, import_react17.useState)("");
|
|
3897
|
+
const [present, setPresent] = (0, import_react17.useState)(false);
|
|
3898
|
+
const [busy, setBusy] = (0, import_react17.useState)(false);
|
|
3899
|
+
(0, import_react17.useEffect)(() => {
|
|
1083
3900
|
let active = true;
|
|
1084
3901
|
credentials.hasKey(credentialRef).then((has) => {
|
|
1085
3902
|
if (active) setPresent(has);
|
|
@@ -1111,16 +3928,16 @@ var ApiKeyForm = ({
|
|
|
1111
3928
|
setBusy(false);
|
|
1112
3929
|
}
|
|
1113
3930
|
};
|
|
1114
|
-
return /* @__PURE__ */ (0,
|
|
1115
|
-
/* @__PURE__ */ (0,
|
|
3931
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: ["awr-keyform", className].filter(Boolean).join(" "), children: [
|
|
3932
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "awr-keyform__label", children: [
|
|
1116
3933
|
label,
|
|
1117
|
-
present && /* @__PURE__ */ (0,
|
|
1118
|
-
/* @__PURE__ */ (0,
|
|
3934
|
+
present && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "awr-keyform__saved", children: [
|
|
3935
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CheckIcon, { size: 12 }),
|
|
1119
3936
|
" stored, encrypted"
|
|
1120
3937
|
] })
|
|
1121
3938
|
] }),
|
|
1122
|
-
/* @__PURE__ */ (0,
|
|
1123
|
-
/* @__PURE__ */ (0,
|
|
3939
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "awr-keyform__row", children: [
|
|
3940
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1124
3941
|
"input",
|
|
1125
3942
|
{
|
|
1126
3943
|
className: "awr-keyform__input",
|
|
@@ -1138,7 +3955,7 @@ var ApiKeyForm = ({
|
|
|
1138
3955
|
disabled: busy
|
|
1139
3956
|
}
|
|
1140
3957
|
),
|
|
1141
|
-
/* @__PURE__ */ (0,
|
|
3958
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1142
3959
|
"button",
|
|
1143
3960
|
{
|
|
1144
3961
|
type: "button",
|
|
@@ -1148,7 +3965,7 @@ var ApiKeyForm = ({
|
|
|
1148
3965
|
children: "Save"
|
|
1149
3966
|
}
|
|
1150
3967
|
),
|
|
1151
|
-
present && /* @__PURE__ */ (0,
|
|
3968
|
+
present && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
|
|
1152
3969
|
"button",
|
|
1153
3970
|
{
|
|
1154
3971
|
type: "button",
|
|
@@ -1167,34 +3984,77 @@ var import_agent_web4 = require("@dudko.dev/agent-web");
|
|
|
1167
3984
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1168
3985
|
0 && (module.exports = {
|
|
1169
3986
|
AgentChat,
|
|
3987
|
+
AgentComposer,
|
|
3988
|
+
AgentLabelsProvider,
|
|
1170
3989
|
AgentProvider,
|
|
1171
3990
|
ApiKeyForm,
|
|
3991
|
+
ApprovalModeSwitch,
|
|
3992
|
+
AttachmentView,
|
|
3993
|
+
AttachmentsNotSupportedError,
|
|
3994
|
+
ChatHistoryList,
|
|
3995
|
+
ChatHistoryStore,
|
|
1172
3996
|
Composer,
|
|
3997
|
+
ContextMeter,
|
|
3998
|
+
FilesPanel,
|
|
3999
|
+
ImagesNotSupportedError,
|
|
4000
|
+
IndexedDBStore,
|
|
1173
4001
|
MemoryCredentialStore,
|
|
4002
|
+
MemoryStore,
|
|
1174
4003
|
MessageList,
|
|
1175
4004
|
ModelLoadBar,
|
|
1176
4005
|
PlanView,
|
|
1177
4006
|
StepList,
|
|
4007
|
+
SubagentRow,
|
|
4008
|
+
ToolApprovalPrompt,
|
|
4009
|
+
ToolCallRow,
|
|
1178
4010
|
UsageBadge,
|
|
1179
4011
|
VaultCredentialStore,
|
|
4012
|
+
VirtualFileSystem,
|
|
1180
4013
|
agentStateReducer,
|
|
4014
|
+
attachmentKindOf,
|
|
4015
|
+
attachmentRefusal,
|
|
4016
|
+
chatTitle,
|
|
1181
4017
|
claimOAuthCallback,
|
|
1182
4018
|
createAgent,
|
|
4019
|
+
createFileTools,
|
|
1183
4020
|
createInitialAgentState,
|
|
4021
|
+
createSubagentTool,
|
|
1184
4022
|
createWebLLMModel,
|
|
4023
|
+
defaultLabels,
|
|
4024
|
+
defineSkill,
|
|
1185
4025
|
defineTool,
|
|
1186
4026
|
describeMcpResult,
|
|
4027
|
+
downscaleImage,
|
|
4028
|
+
filterCommands,
|
|
4029
|
+
formatElapsed,
|
|
1187
4030
|
isUnauthorizedError,
|
|
1188
4031
|
isWebGPUAvailable,
|
|
4032
|
+
loadSkillFromUrl,
|
|
4033
|
+
markReadOnly,
|
|
4034
|
+
mergeLabels,
|
|
4035
|
+
newChatId,
|
|
4036
|
+
noticesOf,
|
|
4037
|
+
parseSkillMarkdown,
|
|
4038
|
+
parseSlash,
|
|
1189
4039
|
preloadWebLLMModel,
|
|
1190
4040
|
readCallbackParams,
|
|
4041
|
+
serveSubagentWorker,
|
|
1191
4042
|
stripOAuthParams,
|
|
4043
|
+
supportsImages,
|
|
4044
|
+
supportsPdf,
|
|
1192
4045
|
unloadWebLLMModel,
|
|
4046
|
+
usageLine,
|
|
1193
4047
|
useAgent,
|
|
1194
4048
|
useAgentContext,
|
|
4049
|
+
useChatHistory,
|
|
1195
4050
|
useCredentials,
|
|
4051
|
+
useLabels,
|
|
1196
4052
|
useMcp,
|
|
4053
|
+
useMcpServers,
|
|
1197
4054
|
useOptionalAgentContext,
|
|
1198
|
-
|
|
4055
|
+
useSpeechToText,
|
|
4056
|
+
useVirtualFiles,
|
|
4057
|
+
useWebLLMModel,
|
|
4058
|
+
withAttachments
|
|
1199
4059
|
});
|
|
1200
4060
|
//# sourceMappingURL=index.cjs.map
|