@dudko.dev/agent-web-react 0.0.9 → 0.0.11
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 +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { DependencyList, ReactNode, CSSProperties } from 'react';
|
|
3
|
-
import { IPlan, IPlanStep, IUsage, ReplanMode, AgentEvent, RunResult, Agent, AgentEventHandler, BrowserAgentConfig, CredentialStore, AgentToolSet, WebLLMModelOptions, createWebLLMModel } from '@dudko.dev/agent-web';
|
|
4
|
-
export { Agent, AgentEvent, AgentEventHandler, AgentLoggerSink, AgentTool, AgentToolSet, BrowserAgentConfig, CredentialStore, IPlan, IPlanStep, IStepResult, IToolCall, IUsage, LogLevel, MemoryCredentialStore, ModelInput, ProviderModelSpec, ProviderType, RunOptions, RunResult, VaultCredentialStore, createAgent, createWebLLMModel, defineTool, isWebGPUAvailable, preloadWebLLMModel, unloadWebLLMModel } from '@dudko.dev/agent-web';
|
|
2
|
+
import { DependencyList, ReactNode, RefObject, ComponentType, CSSProperties } from 'react';
|
|
3
|
+
import { IPlan, IPlanStep, IUsage, ReplanMode, AgentEvent, RunFile, RunResult, Agent, ToolApprovalMode, CompactResult, AgentEventHandler, BrowserAgentConfig, VirtualFileInfo, VirtualFileSystem, CredentialStore, AgentToolSet, WebLLMModelOptions, createWebLLMModel } from '@dudko.dev/agent-web';
|
|
4
|
+
export { Agent, AgentEvent, AgentEventHandler, AgentLoggerSink, AgentTool, AgentToolSet, AttachmentsNotSupportedError, BrowserAgentConfig, CompactResult, CompactionConfig, CredentialStore, FileToolsOptions, IPlan, IPlanStep, IStepResult, IToolCall, IUsage, ImagesNotSupportedError, IndexedDBStore, LogLevel, MemoryCredentialStore, MemoryStore, ModelInput, ProviderModelSpec, ProviderType, RunFile, RunOptions, RunResult, Skill, SubagentToolOptions, SubagentWorkerConfig, ThinkingLevel, ThinkingSetting, TokenLimits, ToolApprovalConfig, ToolApprovalMode, ToolApprovalRequest, VaultCredentialStore, VirtualFile, VirtualFileInfo, VirtualFileSystem, createAgent, createFileTools, createSubagentTool, createWebLLMModel, defineSkill, defineTool, isWebGPUAvailable, loadSkillFromUrl, markReadOnly, parseSkillMarkdown, preloadWebLLMModel, serveSubagentWorker, supportsImages, supportsPdf, unloadWebLLMModel } from '@dudko.dev/agent-web';
|
|
5
5
|
|
|
6
|
+
/** Why a run stopped early (a `budget.exceeded` event). */
|
|
7
|
+
interface BudgetView {
|
|
8
|
+
kind: 'input' | 'output' | 'reasoning' | 'total' | 'tool-calls';
|
|
9
|
+
tokens: number;
|
|
10
|
+
cap: number;
|
|
11
|
+
}
|
|
6
12
|
/**
|
|
7
13
|
* Lifecycle of the agent instance the hook owns.
|
|
8
14
|
* - `idle` — no config yet, nothing built.
|
|
@@ -13,6 +19,16 @@ export { Agent, AgentEvent, AgentEventHandler, AgentLoggerSink, AgentTool, Agent
|
|
|
13
19
|
* - `error` — the agent failed to build (a run error keeps it `ready`).
|
|
14
20
|
*/
|
|
15
21
|
type AgentStatus = 'idle' | 'initializing' | 'ready' | 'running' | 'error';
|
|
22
|
+
/** A file or image shown with a message (and, for images, sent to the model). */
|
|
23
|
+
interface ChatAttachment {
|
|
24
|
+
name: string;
|
|
25
|
+
mediaType: string;
|
|
26
|
+
/** A data URL (images: thumbnail + full view) — kept so a saved chat can show it again. */
|
|
27
|
+
dataUrl?: string;
|
|
28
|
+
/** Where it was stored in the virtual file system, if it was. */
|
|
29
|
+
path?: string;
|
|
30
|
+
size?: number;
|
|
31
|
+
}
|
|
16
32
|
/** One turn of the chat transcript that a chat UI renders. */
|
|
17
33
|
interface ChatMessage {
|
|
18
34
|
id: string;
|
|
@@ -20,6 +36,24 @@ interface ChatMessage {
|
|
|
20
36
|
content: string;
|
|
21
37
|
/** An assistant message that is still streaming (no final/stopped/error yet). */
|
|
22
38
|
pending: boolean;
|
|
39
|
+
/** User turn: what was attached (images, files). */
|
|
40
|
+
attachments?: ChatAttachment[];
|
|
41
|
+
/** Assistant turn: the run's steps — tool calls, thoughts, subagents — as they happened. */
|
|
42
|
+
steps?: StepView[];
|
|
43
|
+
/** Assistant turn: consent decisions of the run. */
|
|
44
|
+
approvals?: ApprovalView[];
|
|
45
|
+
/** Assistant turn: subagent delegations of the run. */
|
|
46
|
+
subagents?: SubagentView[];
|
|
47
|
+
/** Assistant turn: the synthesizer's thoughts. */
|
|
48
|
+
reasoning?: string;
|
|
49
|
+
/** Assistant turn: tokens the run spent, by kind. */
|
|
50
|
+
usage?: IUsage;
|
|
51
|
+
/** Assistant turn: wall-clock duration of the run (needs timestamps from the hook). */
|
|
52
|
+
durationMs?: number;
|
|
53
|
+
/** Assistant turn: skills the run used. */
|
|
54
|
+
skills?: string[];
|
|
55
|
+
/** Assistant turn ended with an error. */
|
|
56
|
+
error?: boolean;
|
|
23
57
|
}
|
|
24
58
|
/** A single tool call as it appears in a step, streamed then finalized. */
|
|
25
59
|
interface ToolCallView {
|
|
@@ -28,6 +62,52 @@ interface ToolCallView {
|
|
|
28
62
|
output?: unknown;
|
|
29
63
|
ok?: boolean;
|
|
30
64
|
status: 'calling' | 'done';
|
|
65
|
+
/** When the call started (ms epoch; set when the hook stamps events). */
|
|
66
|
+
startedAt?: number;
|
|
67
|
+
/** How long the call took. */
|
|
68
|
+
durationMs?: number;
|
|
69
|
+
/** ≈ tokens of the arguments the model wrote (chars / 4). */
|
|
70
|
+
inputTokens?: number;
|
|
71
|
+
/** ≈ tokens of the result fed back to the model (chars / 4). */
|
|
72
|
+
outputTokens?: number;
|
|
73
|
+
}
|
|
74
|
+
/** A tool call waiting for (or decided by) the user's consent. */
|
|
75
|
+
interface ApprovalView {
|
|
76
|
+
id: string;
|
|
77
|
+
name: string;
|
|
78
|
+
input: unknown;
|
|
79
|
+
readOnly: boolean;
|
|
80
|
+
/** The step the call belongs to, when known. */
|
|
81
|
+
stepId?: string;
|
|
82
|
+
status: 'pending' | 'approved' | 'denied';
|
|
83
|
+
reason?: string;
|
|
84
|
+
/** Decided by policy (rule / read-only mode), not by a person. */
|
|
85
|
+
automatic?: boolean;
|
|
86
|
+
}
|
|
87
|
+
/** A delegated task running in a subagent (in-process or a Web Worker). */
|
|
88
|
+
interface SubagentView {
|
|
89
|
+
id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
task: string;
|
|
92
|
+
status: 'running' | 'done' | 'error';
|
|
93
|
+
/** The step that delegated it, when known. */
|
|
94
|
+
stepId?: string;
|
|
95
|
+
/** What the child is doing right now ("step 2: …", "→ tool"). */
|
|
96
|
+
activity: string;
|
|
97
|
+
/** Steps the child started. */
|
|
98
|
+
steps: number;
|
|
99
|
+
/** Tool calls the child made. */
|
|
100
|
+
toolCalls: number;
|
|
101
|
+
/** The child's answer (streamed, then final). */
|
|
102
|
+
text: string;
|
|
103
|
+
usage: IUsage;
|
|
104
|
+
error?: string;
|
|
105
|
+
}
|
|
106
|
+
/** One compaction of the context (a `context.compacted` event). */
|
|
107
|
+
interface CompactionView {
|
|
108
|
+
scope: 'history' | 'trace' | 'tool-results';
|
|
109
|
+
beforeTokens: number;
|
|
110
|
+
afterTokens: number;
|
|
31
111
|
}
|
|
32
112
|
/** An execution step with its accumulated text and tool calls. */
|
|
33
113
|
interface StepView {
|
|
@@ -37,6 +117,8 @@ interface StepView {
|
|
|
37
117
|
step: IPlanStep;
|
|
38
118
|
/** Streamed executor text for this step (step.text-delta). */
|
|
39
119
|
text: string;
|
|
120
|
+
/** Streamed executor thoughts for this step (step.reasoning-delta). */
|
|
121
|
+
reasoning: string;
|
|
40
122
|
toolCalls: ToolCallView[];
|
|
41
123
|
status: 'running' | 'done';
|
|
42
124
|
summary?: string;
|
|
@@ -69,8 +151,28 @@ interface AgentUiState {
|
|
|
69
151
|
steps: StepView[];
|
|
70
152
|
/** The final answer (streamed via final.text-delta, finalized on final). */
|
|
71
153
|
finalText: string;
|
|
154
|
+
/** The synthesizer's streamed thoughts (final.reasoning-delta). */
|
|
155
|
+
finalReasoning: string;
|
|
156
|
+
/** Tool calls that asked for consent in this run, pending first-come. */
|
|
157
|
+
approvals: ApprovalView[];
|
|
158
|
+
/** Subagent delegations of this run. */
|
|
159
|
+
subagents: SubagentView[];
|
|
160
|
+
/** Skills activated in this run. */
|
|
161
|
+
skills: string[];
|
|
162
|
+
/** Tools activated by find_tools in this run. */
|
|
163
|
+
discoveredTools: string[];
|
|
164
|
+
/** Compactions in this run. */
|
|
165
|
+
compactions: CompactionView[];
|
|
166
|
+
/** Set when a run-level limit stopped the run early. */
|
|
167
|
+
budget?: BudgetView;
|
|
72
168
|
/** Running token total across the current run. */
|
|
73
169
|
usage: IUsage;
|
|
170
|
+
/** Token total across the whole conversation (every run since the last reset). */
|
|
171
|
+
totalUsage: IUsage;
|
|
172
|
+
/** When the current run started (ms epoch; set when the hook stamps events). */
|
|
173
|
+
runStartedAt?: number;
|
|
174
|
+
/** The id of the assistant message the current run streams into. */
|
|
175
|
+
runMessageId?: string;
|
|
74
176
|
/** WebLLM progress, present only while a local model is loading. */
|
|
75
177
|
modelLoad?: ModelLoadState;
|
|
76
178
|
/** The most recent replan decision, if any. */
|
|
@@ -104,13 +206,36 @@ interface UseAgentOptions {
|
|
|
104
206
|
autoStart?: boolean;
|
|
105
207
|
/** Cap the retained raw event log length (default 200; 0 = unbounded). */
|
|
106
208
|
maxEvents?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Route tool-consent requests into the hook (`pendingApprovals`, `approve`,
|
|
211
|
+
* `deny`) when the config has no `toolApproval.onRequest` of its own
|
|
212
|
+
* (default true). Render them with `<ToolApprovalPrompt>`, or your own UI.
|
|
213
|
+
*/
|
|
214
|
+
approvals?: boolean;
|
|
215
|
+
}
|
|
216
|
+
interface ApproveOptions {
|
|
217
|
+
/** Also allow this tool for the rest of the agent's life ("always allow"). */
|
|
218
|
+
remember?: boolean;
|
|
219
|
+
}
|
|
220
|
+
interface RunGoalOptions {
|
|
221
|
+
/**
|
|
222
|
+
* What the transcript shows for this turn when it differs from what the
|
|
223
|
+
* agent receives — e.g. the typed text without the attached files' contents.
|
|
224
|
+
*/
|
|
225
|
+
label?: string;
|
|
226
|
+
/** Images sent to the model with the goal (vision models; see `agent.capabilities`). */
|
|
227
|
+
images?: RunFile[];
|
|
228
|
+
/** PDFs / files / URLs sent to the model with the goal. */
|
|
229
|
+
files?: RunFile[];
|
|
230
|
+
/** What the transcript shows as attached to this turn (thumbnails, chips). */
|
|
231
|
+
attachments?: ChatAttachment[];
|
|
107
232
|
}
|
|
108
233
|
interface UseAgentReturn extends AgentUiState {
|
|
109
234
|
/** Run a goal. Resolves with the RunResult, or `undefined` if it couldn't start. */
|
|
110
|
-
run: (goal: string) => Promise<RunResult | undefined>;
|
|
235
|
+
run: (goal: string, options?: RunGoalOptions) => Promise<RunResult | undefined>;
|
|
111
236
|
/** Abort the in-flight run (observed between phases and mid-stream). */
|
|
112
237
|
stop: () => void;
|
|
113
|
-
/** Clear the whole conversation — transcript and
|
|
238
|
+
/** Clear the whole conversation — transcript, current run, and the agent's memory. */
|
|
114
239
|
reset: () => void;
|
|
115
240
|
/** Rebuild the agent now (e.g. after the user stores a new API key). */
|
|
116
241
|
reload: () => void;
|
|
@@ -118,25 +243,200 @@ interface UseAgentReturn extends AgentUiState {
|
|
|
118
243
|
agent: Agent | undefined;
|
|
119
244
|
isRunning: boolean;
|
|
120
245
|
isReady: boolean;
|
|
246
|
+
/** Tool calls waiting for the user's consent. */
|
|
247
|
+
pendingApprovals: ApprovalView[];
|
|
248
|
+
/** Let a pending call run (`remember` → never ask for this tool again). */
|
|
249
|
+
approve: (id: string, options?: ApproveOptions) => void;
|
|
250
|
+
/** Refuse a pending call; the model is told and works around it. */
|
|
251
|
+
deny: (id: string, reason?: string) => void;
|
|
252
|
+
/** The consent policy in effect. */
|
|
253
|
+
approvalMode: ToolApprovalMode;
|
|
254
|
+
/** Switch the consent policy live — the "autopilot" toggle. */
|
|
255
|
+
setApprovalMode: (mode: ToolApprovalMode) => void;
|
|
256
|
+
/** Summarise the stored transcript now (needs `config.memory`). */
|
|
257
|
+
compact: () => Promise<CompactResult | undefined>;
|
|
258
|
+
/** The memory session runs use (config.sessionId until switched). */
|
|
259
|
+
sessionId: string;
|
|
260
|
+
/**
|
|
261
|
+
* Switch to another conversation: its id becomes the memory session of the
|
|
262
|
+
* next runs, and its saved transcript (chat history) is shown.
|
|
263
|
+
*/
|
|
264
|
+
loadChat: (chat: {
|
|
265
|
+
sessionId: string;
|
|
266
|
+
messages?: ChatMessage[];
|
|
267
|
+
totalUsage?: IUsage;
|
|
268
|
+
}) => void;
|
|
121
269
|
}
|
|
122
270
|
/**
|
|
123
271
|
* The primary React binding for `@dudko.dev/agent-web`. Builds the agent from a
|
|
124
272
|
* {@link BrowserAgentConfig}, streams its typed events into a renderable
|
|
125
|
-
* {@link AgentUiState} (plan, steps, tool calls,
|
|
126
|
-
* usage, model-load progress and a chat
|
|
127
|
-
* / `reset` / `reload
|
|
273
|
+
* {@link AgentUiState} (plan, steps, tool calls, thoughts, consent requests,
|
|
274
|
+
* subagents, streamed final answer, token usage, model-load progress and a chat
|
|
275
|
+
* transcript), and exposes `run` / `stop` / `reset` / `reload` plus consent
|
|
276
|
+
* (`approve` / `deny` / `setApprovalMode`) and `compact`.
|
|
128
277
|
*
|
|
129
278
|
* ```tsx
|
|
130
279
|
* const agent = useAgent({
|
|
131
280
|
* model: { providerType: 'openai', model: 'gpt-4o-mini', credentialRef: 'openai' },
|
|
132
281
|
* credentials,
|
|
133
282
|
* tools,
|
|
283
|
+
* toolApproval: { mode: 'ask-writes' }, // requests land in agent.pendingApprovals
|
|
134
284
|
* })
|
|
135
285
|
* // <button disabled={!agent.isReady} onClick={() => agent.run(text)}>Run</button>
|
|
136
286
|
* ```
|
|
137
287
|
*/
|
|
138
288
|
declare const useAgent: (config: BrowserAgentConfig, options?: UseAgentOptions) => UseAgentReturn;
|
|
139
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Saved conversations — the transcript a chat UI shows (messages with their
|
|
292
|
+
* tool calls, usage and image attachments), one record per conversation. The
|
|
293
|
+
* agent's own memory (what the MODEL sees) lives in the core's ContextStore
|
|
294
|
+
* under the same id; keep both and a reloaded chat continues where it was.
|
|
295
|
+
*/
|
|
296
|
+
interface ChatRecord {
|
|
297
|
+
/** Also the agent's memory session id. */
|
|
298
|
+
id: string;
|
|
299
|
+
title: string;
|
|
300
|
+
createdAt: number;
|
|
301
|
+
updatedAt: number;
|
|
302
|
+
messages: ChatMessage[];
|
|
303
|
+
totalUsage?: IUsage;
|
|
304
|
+
}
|
|
305
|
+
/** A list entry (no messages). */
|
|
306
|
+
type ChatSummary = Omit<ChatRecord, 'messages'> & {
|
|
307
|
+
messageCount: number;
|
|
308
|
+
};
|
|
309
|
+
interface ChatHistoryStoreOptions {
|
|
310
|
+
/** IndexedDB database (default 'agent-web-react'). */
|
|
311
|
+
dbName?: string;
|
|
312
|
+
/** Object store (default 'chats'). */
|
|
313
|
+
storeName?: string;
|
|
314
|
+
/** Keep chats in memory only (tests, private mode; also the fallback without IndexedDB). */
|
|
315
|
+
memory?: boolean;
|
|
316
|
+
}
|
|
317
|
+
/** IndexedDB-backed chat history (raw IndexedDB — no extra dependency). */
|
|
318
|
+
declare class ChatHistoryStore {
|
|
319
|
+
private readonly dbName;
|
|
320
|
+
private readonly storeName;
|
|
321
|
+
private readonly memory?;
|
|
322
|
+
private db?;
|
|
323
|
+
constructor(opts?: ChatHistoryStoreOptions);
|
|
324
|
+
private open;
|
|
325
|
+
private tx;
|
|
326
|
+
list(): Promise<ChatSummary[]>;
|
|
327
|
+
get(id: string): Promise<ChatRecord | undefined>;
|
|
328
|
+
put(record: ChatRecord): Promise<void>;
|
|
329
|
+
delete(id: string): Promise<void>;
|
|
330
|
+
clear(): Promise<void>;
|
|
331
|
+
}
|
|
332
|
+
/** A chat's title: its first user message, trimmed. */
|
|
333
|
+
declare const chatTitle: (messages: ChatMessage[]) => string;
|
|
334
|
+
/** A fresh, sortable conversation id (also a valid memory session id). */
|
|
335
|
+
declare const newChatId: () => string;
|
|
336
|
+
|
|
337
|
+
interface UseChatHistoryOptions {
|
|
338
|
+
/** Where chats are saved (default: a ChatHistoryStore on IndexedDB). */
|
|
339
|
+
store?: ChatHistoryStore;
|
|
340
|
+
/** Switch the hook off (keeps hook order stable in components). Default true. */
|
|
341
|
+
enabled?: boolean;
|
|
342
|
+
/** Open the most recent chat on mount (default true). */
|
|
343
|
+
resumeLatest?: boolean;
|
|
344
|
+
}
|
|
345
|
+
interface UseChatHistoryReturn {
|
|
346
|
+
chats: ChatSummary[];
|
|
347
|
+
/** The open conversation (the agent's memory session). */
|
|
348
|
+
currentId: string;
|
|
349
|
+
loading: boolean;
|
|
350
|
+
/** Open a saved conversation. */
|
|
351
|
+
select: (id: string) => Promise<void>;
|
|
352
|
+
/** Start an empty conversation. */
|
|
353
|
+
newChat: () => void;
|
|
354
|
+
/** Delete a conversation (and start a new one if it was open). */
|
|
355
|
+
remove: (id: string) => Promise<void>;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Persist an agent's conversations — the transcript with its tool calls, usage
|
|
359
|
+
* and image attachments — and switch between them. Each chat id is also the
|
|
360
|
+
* agent's memory session, so with a persistent `memory` (IndexedDBStore) a
|
|
361
|
+
* reopened chat continues with the model's context intact.
|
|
362
|
+
*/
|
|
363
|
+
declare const useChatHistory: (agent: UseAgentReturn, options?: UseChatHistoryOptions) => UseChatHistoryReturn;
|
|
364
|
+
|
|
365
|
+
interface UseVirtualFilesReturn {
|
|
366
|
+
files: VirtualFileInfo[];
|
|
367
|
+
loading: boolean;
|
|
368
|
+
error?: string;
|
|
369
|
+
refresh: () => Promise<void>;
|
|
370
|
+
/** Save a browser File (text as text, anything else as base64). */
|
|
371
|
+
upload: (file: File, dir?: string) => Promise<void>;
|
|
372
|
+
remove: (path: string) => Promise<void>;
|
|
373
|
+
/** A data URL of a file (for previews and downloads). */
|
|
374
|
+
dataUrl: (path: string) => Promise<string | undefined>;
|
|
375
|
+
/** A text file's content. */
|
|
376
|
+
text: (path: string) => Promise<string | undefined>;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* A live listing of a {@link VirtualFileSystem} (the core's browser
|
|
380
|
+
* workspace): re-reads on every write / delete — by the user or by the agent's
|
|
381
|
+
* `fs_*` tools — and offers upload / remove / read helpers. Headless: render
|
|
382
|
+
* it with `<FilesPanel>` or your own UI.
|
|
383
|
+
*/
|
|
384
|
+
declare const useVirtualFiles: (vfs: VirtualFileSystem | undefined, prefix?: string) => UseVirtualFilesReturn;
|
|
385
|
+
|
|
386
|
+
/** The slice of the Web Speech API recognizer this hook drives. */
|
|
387
|
+
interface SpeechRecognizerLike {
|
|
388
|
+
lang: string;
|
|
389
|
+
continuous: boolean;
|
|
390
|
+
interimResults: boolean;
|
|
391
|
+
start(): void;
|
|
392
|
+
stop(): void;
|
|
393
|
+
abort?(): void;
|
|
394
|
+
onresult: ((ev: SpeechResultEventLike) => void) | null;
|
|
395
|
+
onerror: ((ev: {
|
|
396
|
+
error?: string;
|
|
397
|
+
}) => void) | null;
|
|
398
|
+
onend: (() => void) | null;
|
|
399
|
+
}
|
|
400
|
+
interface SpeechResultEventLike {
|
|
401
|
+
resultIndex: number;
|
|
402
|
+
results: ArrayLike<{
|
|
403
|
+
isFinal: boolean;
|
|
404
|
+
0: {
|
|
405
|
+
transcript: string;
|
|
406
|
+
};
|
|
407
|
+
}>;
|
|
408
|
+
}
|
|
409
|
+
interface UseSpeechToTextOptions {
|
|
410
|
+
/** BCP-47 language (default: the page's `navigator.language`). */
|
|
411
|
+
lang?: string;
|
|
412
|
+
/** Keep listening across pauses until stopped (default true). */
|
|
413
|
+
continuous?: boolean;
|
|
414
|
+
/**
|
|
415
|
+
* Build your own recognizer (e.g. a fully local Whisper/WebGPU one) instead
|
|
416
|
+
* of the browser's `SpeechRecognition`.
|
|
417
|
+
*/
|
|
418
|
+
createRecognizer?: () => SpeechRecognizerLike;
|
|
419
|
+
/** Final text chunks, as they are recognized. */
|
|
420
|
+
onFinal?: (text: string) => void;
|
|
421
|
+
}
|
|
422
|
+
interface UseSpeechToTextReturn {
|
|
423
|
+
/** The browser (or your `createRecognizer`) can do speech-to-text. */
|
|
424
|
+
supported: boolean;
|
|
425
|
+
listening: boolean;
|
|
426
|
+
/** Words heard but not final yet (for a live preview). */
|
|
427
|
+
interim: string;
|
|
428
|
+
error?: string;
|
|
429
|
+
start: () => void;
|
|
430
|
+
stop: () => void;
|
|
431
|
+
toggle: () => void;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Speech-to-text in the browser via the Web Speech API (`SpeechRecognition`,
|
|
435
|
+
* prefixed in Chrome/Safari). Note that Chrome sends the audio to its own
|
|
436
|
+
* recognition service; pass `createRecognizer` for an on-device engine.
|
|
437
|
+
*/
|
|
438
|
+
declare const useSpeechToText: (options?: UseSpeechToTextOptions) => UseSpeechToTextReturn;
|
|
439
|
+
|
|
140
440
|
interface UseCredentialsReturn {
|
|
141
441
|
/** The underlying store — pass this straight to `createAgent({ credentials })`. */
|
|
142
442
|
store: CredentialStore;
|
|
@@ -179,6 +479,8 @@ interface McpCatalogEntry {
|
|
|
179
479
|
name: string;
|
|
180
480
|
description: string;
|
|
181
481
|
server: string;
|
|
482
|
+
/** The server marked the tool read-only (newer cores). */
|
|
483
|
+
readOnly?: boolean;
|
|
182
484
|
}
|
|
183
485
|
interface McpServerResult {
|
|
184
486
|
name: string;
|
|
@@ -197,6 +499,8 @@ interface McpHttpServerConfig {
|
|
|
197
499
|
url: string;
|
|
198
500
|
headers?: Record<string, string>;
|
|
199
501
|
authProvider?: unknown;
|
|
502
|
+
/** Per-server connect deadline (newer cores; ignored by older ones). */
|
|
503
|
+
connectTimeoutMs?: number;
|
|
200
504
|
}
|
|
201
505
|
interface McpOAuthCallback {
|
|
202
506
|
code?: string;
|
|
@@ -221,6 +525,7 @@ interface McpModule {
|
|
|
221
525
|
connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opts?: {
|
|
222
526
|
clientName?: string;
|
|
223
527
|
onLog?: (level: string, message: string) => void;
|
|
528
|
+
connectTimeoutMs?: number;
|
|
224
529
|
}) => Promise<ConnectedMcp>;
|
|
225
530
|
BrowserOAuthProvider?: new (opts: BrowserOAuthProviderOptions) => BrowserOAuthProvider;
|
|
226
531
|
readOAuthCallback?: (input?: string | URL) => McpOAuthCallback | undefined;
|
|
@@ -334,6 +639,93 @@ declare const isUnauthorizedError: (err: unknown, mod?: McpModule) => boolean;
|
|
|
334
639
|
*/
|
|
335
640
|
declare const useMcp: (options?: UseMcpOptions) => UseMcpReturn;
|
|
336
641
|
|
|
642
|
+
type McpAuthMode = 'none' | 'bearer' | 'oauth';
|
|
643
|
+
/** One server the user wants connected. */
|
|
644
|
+
interface McpServerSpec {
|
|
645
|
+
/**
|
|
646
|
+
* Unique name; also the tool prefix ("<name>__<tool>"). Sanitised to
|
|
647
|
+
* `[a-zA-Z0-9_-]`; a taken name gets a numeric suffix.
|
|
648
|
+
*/
|
|
649
|
+
name: string;
|
|
650
|
+
/** The server's StreamableHTTP endpoint. */
|
|
651
|
+
url: string;
|
|
652
|
+
auth?: McpAuthMode;
|
|
653
|
+
/** Bearer token for `auth: 'bearer'` — kept in memory only, never persisted. */
|
|
654
|
+
token?: string;
|
|
655
|
+
/** OAuth details for `auth: 'oauth'`. */
|
|
656
|
+
oauth?: {
|
|
657
|
+
redirectUrl?: string;
|
|
658
|
+
scope?: string;
|
|
659
|
+
clientName?: string;
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
/** A server's live state. */
|
|
663
|
+
interface McpServerView {
|
|
664
|
+
name: string;
|
|
665
|
+
url: string;
|
|
666
|
+
auth: McpAuthMode;
|
|
667
|
+
status: McpStatus;
|
|
668
|
+
error?: string;
|
|
669
|
+
/** Where to send the user when `status === 'needs-authorization'`. */
|
|
670
|
+
authorizationUrl?: string;
|
|
671
|
+
catalog: McpCatalogEntry[];
|
|
672
|
+
}
|
|
673
|
+
interface UseMcpServersOptions extends UseMcpOptions {
|
|
674
|
+
/**
|
|
675
|
+
* Remember the server list (never tokens) in localStorage so it survives a
|
|
676
|
+
* reload — and the OAuth redirect, which IS a reload (default true).
|
|
677
|
+
*/
|
|
678
|
+
persist?: boolean;
|
|
679
|
+
/** localStorage key of the list (default 'agent-web-react:mcp-servers'). */
|
|
680
|
+
storageKey?: string;
|
|
681
|
+
/** Reconnect remembered servers on mount (default true). Bearer servers wait for their token. */
|
|
682
|
+
autoConnect?: boolean;
|
|
683
|
+
/** Per-server connect deadline in ms (default: the core's, 30 s). */
|
|
684
|
+
connectTimeoutMs?: number;
|
|
685
|
+
}
|
|
686
|
+
interface UseMcpServersReturn {
|
|
687
|
+
servers: McpServerView[];
|
|
688
|
+
/** Tools of every connected server, merged — pass to `BrowserAgentConfig.tools`. */
|
|
689
|
+
tools: AgentToolSet;
|
|
690
|
+
/** Catalogue of every connected server, merged. */
|
|
691
|
+
catalog: McpCatalogEntry[];
|
|
692
|
+
connectedCount: number;
|
|
693
|
+
/** True while an OAuth redirect is being finished on mount. */
|
|
694
|
+
completingAuthorization: boolean;
|
|
695
|
+
/** Whether the installed core can do OAuth (undefined until checked). */
|
|
696
|
+
oauthSupported?: boolean;
|
|
697
|
+
checkOAuthSupport: () => Promise<boolean>;
|
|
698
|
+
/** Add (or replace, by name) a server and connect it. Resolves with the final name. */
|
|
699
|
+
add: (spec: McpServerSpec) => Promise<string>;
|
|
700
|
+
/** Disconnect and forget a server. */
|
|
701
|
+
remove: (name: string) => Promise<void>;
|
|
702
|
+
/** Connect again — optionally with a fresh bearer token. */
|
|
703
|
+
reconnect: (name: string, token?: string) => Promise<void>;
|
|
704
|
+
/** Navigate to the server's authorization page. Call it from a user gesture. */
|
|
705
|
+
authorize: (name: string) => void;
|
|
706
|
+
/** Drop a server's stored OAuth tokens and registration. */
|
|
707
|
+
forgetAuthorization: (name: string) => Promise<void>;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Connect the browser agent to SEVERAL remote MCP servers at once, each with
|
|
711
|
+
* its own auth (none, a bearer token, or OAuth 2.1 + dynamic registration).
|
|
712
|
+
* Every server is its own connection — adding or removing one never touches
|
|
713
|
+
* the others — and their tools merge into one `tools` set, prefixed by server
|
|
714
|
+
* name. The list is remembered across reloads (tokens excepted), and an OAuth
|
|
715
|
+
* round-trip resumes on return.
|
|
716
|
+
*
|
|
717
|
+
* ```tsx
|
|
718
|
+
* const mcp = useMcpServers()
|
|
719
|
+
* // await mcp.add({ name: 'github', url, auth: 'oauth' })
|
|
720
|
+
* // await mcp.add({ name: 'docs', url, auth: 'bearer', token })
|
|
721
|
+
* const agent = useAgent({ model, tools: { ...local, ...mcp.tools } }, { deps: [mcp.tools] })
|
|
722
|
+
* ```
|
|
723
|
+
*
|
|
724
|
+
* With many servers the merged catalogue can reach hundreds of tools; the core
|
|
725
|
+
* switches to tool search above `toolSearchThreshold` automatically.
|
|
726
|
+
*/
|
|
727
|
+
declare const useMcpServers: (options?: UseMcpServersOptions) => UseMcpServersReturn;
|
|
728
|
+
|
|
337
729
|
/** The AI SDK `LanguageModel` a WebLLM build produces (resolved via agent-web). */
|
|
338
730
|
type WebLLMModel = Awaited<ReturnType<typeof createWebLLMModel>>;
|
|
339
731
|
/**
|
|
@@ -395,6 +787,233 @@ interface UseWebLLMModelReturn {
|
|
|
395
787
|
*/
|
|
396
788
|
declare const useWebLLMModel: (modelId: string, options?: UseWebLLMModelOptions) => UseWebLLMModelReturn;
|
|
397
789
|
|
|
790
|
+
/**
|
|
791
|
+
* Pure helpers behind `<AgentComposer>`: slash commands, attachments, notices
|
|
792
|
+
* and the elapsed-time label. No React, no DOM — unit-tested on their own.
|
|
793
|
+
*/
|
|
794
|
+
/** A command offered when the input starts with "/". */
|
|
795
|
+
interface SlashCommand {
|
|
796
|
+
/** Typed after the slash, e.g. "compact" for "/compact". */
|
|
797
|
+
name: string;
|
|
798
|
+
description: string;
|
|
799
|
+
/**
|
|
800
|
+
* 'action' runs at once on Enter (e.g. /compact); 'prefix' stays in the
|
|
801
|
+
* input and rewrites the goal on submit (e.g. /chess-coach <goal>).
|
|
802
|
+
*/
|
|
803
|
+
kind?: 'action' | 'prefix';
|
|
804
|
+
/** For 'action' commands: what to do (receives the text after the name). */
|
|
805
|
+
run?: (args: string) => void | Promise<void>;
|
|
806
|
+
/** For 'prefix' commands: the goal to send, built from the text after the name. */
|
|
807
|
+
transform?: (args: string) => string;
|
|
808
|
+
/** Grouping label in the palette ("Commands", "Skills", …). */
|
|
809
|
+
group?: string;
|
|
810
|
+
}
|
|
811
|
+
/** "/name rest of text" → { name, args }; undefined unless the text starts with "/". */
|
|
812
|
+
declare const parseSlash: (text: string) => {
|
|
813
|
+
name: string;
|
|
814
|
+
args: string;
|
|
815
|
+
} | undefined;
|
|
816
|
+
/** Commands matching what was typed after "/" — name prefix first, then substring. */
|
|
817
|
+
declare const filterCommands: (commands: SlashCommand[], query: string) => SlashCommand[];
|
|
818
|
+
/**
|
|
819
|
+
* Something attached to the next message:
|
|
820
|
+
* - `text` — its content is inlined into the goal (works with every model);
|
|
821
|
+
* - `image` / `pdf` / `file` — sent to the model as a file part (needs a model
|
|
822
|
+
* that takes that kind — see the core's `agent.capabilities`).
|
|
823
|
+
*/
|
|
824
|
+
interface ComposerAttachment {
|
|
825
|
+
id: string;
|
|
826
|
+
name: string;
|
|
827
|
+
kind: 'text' | 'image' | 'pdf' | 'file';
|
|
828
|
+
mediaType: string;
|
|
829
|
+
/** Text content (kind 'text'). */
|
|
830
|
+
text?: string;
|
|
831
|
+
/** Data URL (kinds image / pdf / file). */
|
|
832
|
+
dataUrl?: string;
|
|
833
|
+
bytes: number;
|
|
834
|
+
/** Where it was saved in the virtual file system, if it was. */
|
|
835
|
+
path?: string;
|
|
836
|
+
/** "converted from report.pdf" and the like. */
|
|
837
|
+
note?: string;
|
|
838
|
+
}
|
|
839
|
+
/** The kind of an attachment from its media type and name. */
|
|
840
|
+
declare const attachmentKindOf: (mediaType: string, name: string) => ComposerAttachment["kind"];
|
|
841
|
+
/**
|
|
842
|
+
* The goal the agent receives: the typed text followed by each attached TEXT
|
|
843
|
+
* file in a fenced block. Binary attachments travel as file parts instead.
|
|
844
|
+
*/
|
|
845
|
+
declare const withAttachments: (text: string, files: ComposerAttachment[]) => string;
|
|
846
|
+
/**
|
|
847
|
+
* Can the current model take this attachment? Returns the reason it can't
|
|
848
|
+
* (an actionable sentence), or undefined. `caps` is the core agent's
|
|
849
|
+
* `capabilities` (true / false / undefined per kind; undefined = will try).
|
|
850
|
+
*/
|
|
851
|
+
declare const attachmentRefusal: (kind: ComposerAttachment["kind"], caps: {
|
|
852
|
+
images?: boolean;
|
|
853
|
+
pdf?: boolean;
|
|
854
|
+
files?: boolean;
|
|
855
|
+
} | undefined, canConvertPdf?: boolean) => string | undefined;
|
|
856
|
+
/** 950 → "0s", 61_000 → "1m 1s", 3_725_000 → "1h 2m". */
|
|
857
|
+
declare const formatElapsed: (ms: number) => string;
|
|
858
|
+
/** A banner above the input. */
|
|
859
|
+
interface ComposerNotice {
|
|
860
|
+
/** Stable per occurrence, so a dismissal sticks until something new happens. */
|
|
861
|
+
id: string;
|
|
862
|
+
tone: 'info' | 'warn' | 'error';
|
|
863
|
+
text: string;
|
|
864
|
+
}
|
|
865
|
+
/** The banner texts (override for another language). */
|
|
866
|
+
interface NoticeTexts {
|
|
867
|
+
/** A limit stopped the run; `kind` is 'input' | 'output' | 'reasoning' | 'total' | 'tool-calls'. */
|
|
868
|
+
limit: (kind: string, used: number, cap: number) => string;
|
|
869
|
+
/** The context was compacted. */
|
|
870
|
+
compacted: (scope: string, before: number, after: number) => string;
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* The notices worth a banner for the current run: a limit that stopped it, the
|
|
874
|
+
* latest compaction, a failure to start. Pure — derived from the UI state.
|
|
875
|
+
*/
|
|
876
|
+
declare const noticesOf: (state: AgentUiState, texts?: Partial<NoticeTexts>) => ComposerNotice[];
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Every string the pre-styled components render — override any of them for
|
|
880
|
+
* another language or wording, per component (`labels` prop) or for a whole
|
|
881
|
+
* tree (`<AgentLabelsProvider>`). Counted phrases are functions, so languages
|
|
882
|
+
* with several plural forms can say them properly.
|
|
883
|
+
*/
|
|
884
|
+
interface AgentLabels {
|
|
885
|
+
emptyState: string;
|
|
886
|
+
status: Record<AgentStatus, string>;
|
|
887
|
+
history: string;
|
|
888
|
+
newChat: string;
|
|
889
|
+
files: string;
|
|
890
|
+
totalUsage: string;
|
|
891
|
+
showHistory: string;
|
|
892
|
+
showFiles: string;
|
|
893
|
+
close: string;
|
|
894
|
+
steps: (n: number) => string;
|
|
895
|
+
toolCalls: (n: number) => string;
|
|
896
|
+
subagents: (n: number) => string;
|
|
897
|
+
skillsUsed: (names: string) => string;
|
|
898
|
+
answerThoughts: string;
|
|
899
|
+
stepThoughts: string;
|
|
900
|
+
usageTitle: string;
|
|
901
|
+
attachments: string;
|
|
902
|
+
planned: string;
|
|
903
|
+
replanned: (mode: string, reason: string) => string;
|
|
904
|
+
placeholder: string;
|
|
905
|
+
listening: string;
|
|
906
|
+
message: string;
|
|
907
|
+
dropHint: string;
|
|
908
|
+
attach: string;
|
|
909
|
+
attachTitle: string;
|
|
910
|
+
commands: string;
|
|
911
|
+
commandsTitle: string;
|
|
912
|
+
send: string;
|
|
913
|
+
stop: string;
|
|
914
|
+
dismiss: string;
|
|
915
|
+
remove: (name: string) => string;
|
|
916
|
+
dictate: string;
|
|
917
|
+
dictateTitle: string;
|
|
918
|
+
stopDictation: string;
|
|
919
|
+
microphone: string;
|
|
920
|
+
model: string;
|
|
921
|
+
thinking: string;
|
|
922
|
+
toolConsent: string;
|
|
923
|
+
modes: Record<ToolApprovalMode, {
|
|
924
|
+
label: string;
|
|
925
|
+
hint: string;
|
|
926
|
+
}>;
|
|
927
|
+
timerRunning: string;
|
|
928
|
+
timerLast: string;
|
|
929
|
+
agents: (n: number) => string;
|
|
930
|
+
agentsTitle: string;
|
|
931
|
+
/** Banners: a limit stopped the run / the context was compacted. */
|
|
932
|
+
notices: NoticeTexts;
|
|
933
|
+
attachmentsOnly: string;
|
|
934
|
+
seeAttachments: string;
|
|
935
|
+
tooLarge: (name: string, mb: number) => string;
|
|
936
|
+
binaryText: (name: string) => string;
|
|
937
|
+
commandGroups: {
|
|
938
|
+
commands: string;
|
|
939
|
+
consent: string;
|
|
940
|
+
skills: string;
|
|
941
|
+
};
|
|
942
|
+
commandDescriptions: {
|
|
943
|
+
compact: string;
|
|
944
|
+
new: string;
|
|
945
|
+
stop: string;
|
|
946
|
+
autopilot: string;
|
|
947
|
+
ask: string;
|
|
948
|
+
askAll: string;
|
|
949
|
+
readOnly: string;
|
|
950
|
+
think: (levels: string) => string;
|
|
951
|
+
};
|
|
952
|
+
thinkingLevels: {
|
|
953
|
+
off: string;
|
|
954
|
+
low: string;
|
|
955
|
+
medium: string;
|
|
956
|
+
high: string;
|
|
957
|
+
};
|
|
958
|
+
filesEmpty: string;
|
|
959
|
+
upload: string;
|
|
960
|
+
download: string;
|
|
961
|
+
delete: string;
|
|
962
|
+
preview: string;
|
|
963
|
+
bytes: (n: number) => string;
|
|
964
|
+
historyEmpty: string;
|
|
965
|
+
deleteChat: string;
|
|
966
|
+
messagesCount: (n: number) => string;
|
|
967
|
+
approvalLead: string;
|
|
968
|
+
approve: string;
|
|
969
|
+
alwaysAllow: string;
|
|
970
|
+
deny: string;
|
|
971
|
+
declinedReason: string;
|
|
972
|
+
readOnlyTool: string;
|
|
973
|
+
consentWaiting: string;
|
|
974
|
+
consentAllowed: string;
|
|
975
|
+
consentDenied: (reason?: string) => string;
|
|
976
|
+
failed: string;
|
|
977
|
+
toolCostTitle: string;
|
|
978
|
+
}
|
|
979
|
+
declare const defaultLabels: AgentLabels;
|
|
980
|
+
/** Overrides: any label, with the nested groups merged key by key. */
|
|
981
|
+
type AgentLabelsOverride = Partial<Omit<AgentLabels, 'status' | 'modes' | 'commandGroups' | 'commandDescriptions' | 'thinkingLevels' | 'notices'>> & {
|
|
982
|
+
status?: Partial<AgentLabels['status']>;
|
|
983
|
+
modes?: Partial<AgentLabels['modes']>;
|
|
984
|
+
commandGroups?: Partial<AgentLabels['commandGroups']>;
|
|
985
|
+
commandDescriptions?: Partial<AgentLabels['commandDescriptions']>;
|
|
986
|
+
thinkingLevels?: Partial<AgentLabels['thinkingLevels']>;
|
|
987
|
+
notices?: Partial<AgentLabels['notices']>;
|
|
988
|
+
};
|
|
989
|
+
/** `base` with `over` applied (nested groups merged, not replaced). */
|
|
990
|
+
declare const mergeLabels: (base: AgentLabels, over?: AgentLabelsOverride) => AgentLabels;
|
|
991
|
+
interface AgentLabelsProviderProps {
|
|
992
|
+
labels: AgentLabelsOverride;
|
|
993
|
+
children?: ReactNode;
|
|
994
|
+
}
|
|
995
|
+
/** Override labels for every component below (nests: inner providers win). */
|
|
996
|
+
declare const AgentLabelsProvider: ({ labels, children }: AgentLabelsProviderProps) => react.JSX.Element;
|
|
997
|
+
/** The labels in effect: the provider's, with a component's own `labels` prop on top. */
|
|
998
|
+
declare const useLabels: (over?: AgentLabelsOverride) => AgentLabels;
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* Downscale an image in the browser before it goes to a model. Providers bill
|
|
1002
|
+
* images by their pixel size and resize anything over ~1.15 MP / 1568 px on
|
|
1003
|
+
* the long edge themselves — sending more only costs upload time and, for
|
|
1004
|
+
* some providers, tokens. GIF and SVG are left as they are.
|
|
1005
|
+
*/
|
|
1006
|
+
interface DownscaleOptions {
|
|
1007
|
+
/** Longest edge in pixels (default 1568). */
|
|
1008
|
+
maxDimension?: number;
|
|
1009
|
+
/** Total pixels (default 1 150 000). */
|
|
1010
|
+
maxPixels?: number;
|
|
1011
|
+
/** JPEG/WebP quality 0..1 (default 0.9). */
|
|
1012
|
+
quality?: number;
|
|
1013
|
+
}
|
|
1014
|
+
/** The image, smaller when it is larger than the limits; the original otherwise. */
|
|
1015
|
+
declare const downscaleImage: (file: Blob, opts?: DownscaleOptions) => Promise<Blob>;
|
|
1016
|
+
|
|
398
1017
|
interface AgentProviderProps extends UseAgentOptions {
|
|
399
1018
|
/** The agent configuration (see `@dudko.dev/agent-web`). */
|
|
400
1019
|
config: BrowserAgentConfig;
|
|
@@ -419,8 +1038,9 @@ declare const useOptionalAgentContext: () => UseAgentReturn | null;
|
|
|
419
1038
|
/**
|
|
420
1039
|
* The reducer that turns the agent's `AgentEvent` stream into a renderable
|
|
421
1040
|
* {@link AgentUiState}. It is a pure function of (state, action) with no React,
|
|
422
|
-
* no clock and no randomness (ids come from a monotonic `seq
|
|
423
|
-
* unit-tested in isolation and reused to
|
|
1041
|
+
* no clock and no randomness (ids come from a monotonic `seq`; times come in on
|
|
1042
|
+
* the action as `at`), so it can be unit-tested in isolation and reused to
|
|
1043
|
+
* build a fully custom UI.
|
|
424
1044
|
*/
|
|
425
1045
|
type AgentAction =
|
|
426
1046
|
/** Clear the whole conversation (transcript + current run), keeping status. */
|
|
@@ -433,16 +1053,326 @@ type AgentAction =
|
|
|
433
1053
|
status: AgentUiState['status'];
|
|
434
1054
|
error?: string;
|
|
435
1055
|
}
|
|
436
|
-
/**
|
|
1056
|
+
/**
|
|
1057
|
+
* Fold one streamed agent event into the view. `at` (ms epoch, from the
|
|
1058
|
+
* hook) times runs and tool calls; `attachments` decorate the user turn a
|
|
1059
|
+
* `run.start` opens.
|
|
1060
|
+
*/
|
|
437
1061
|
| {
|
|
438
1062
|
type: 'event';
|
|
439
1063
|
event: AgentEvent;
|
|
440
1064
|
maxEvents?: number;
|
|
1065
|
+
at?: number;
|
|
1066
|
+
attachments?: ChatAttachment[];
|
|
1067
|
+
}
|
|
1068
|
+
/** Replace the transcript with a saved conversation (chat history). */
|
|
1069
|
+
| {
|
|
1070
|
+
type: 'load';
|
|
1071
|
+
messages: ChatMessage[];
|
|
1072
|
+
totalUsage?: IUsage;
|
|
441
1073
|
};
|
|
442
1074
|
/** A fresh, empty view. */
|
|
443
1075
|
declare const createInitialAgentState: () => AgentUiState;
|
|
444
1076
|
declare const agentStateReducer: (state: AgentUiState, action: AgentAction) => AgentUiState;
|
|
445
1077
|
|
|
1078
|
+
interface ComposerModelChip {
|
|
1079
|
+
/** What the chip says, e.g. "Gemini 3.5 Flash". */
|
|
1080
|
+
label: string;
|
|
1081
|
+
/** Models to switch to from the chip's menu (omit for a read-only label). */
|
|
1082
|
+
options?: {
|
|
1083
|
+
id: string;
|
|
1084
|
+
label: string;
|
|
1085
|
+
group?: string;
|
|
1086
|
+
}[];
|
|
1087
|
+
value?: string;
|
|
1088
|
+
onSelect?: (id: string) => void;
|
|
1089
|
+
}
|
|
1090
|
+
interface ComposerThinkingChip {
|
|
1091
|
+
/** Current level, e.g. 'off' | 'low' | 'medium' | 'high'. */
|
|
1092
|
+
value: string;
|
|
1093
|
+
/** Offered levels (default: default / low / medium / high). */
|
|
1094
|
+
options?: {
|
|
1095
|
+
id: string;
|
|
1096
|
+
label: string;
|
|
1097
|
+
}[];
|
|
1098
|
+
onChange: (value: string) => void;
|
|
1099
|
+
}
|
|
1100
|
+
/** A file turned into text by the host (e.g. a PDF converted to Markdown). */
|
|
1101
|
+
interface ConvertedFile {
|
|
1102
|
+
text: string;
|
|
1103
|
+
/** Name of the text attachment (default: the file's name + ".md"). */
|
|
1104
|
+
name?: string;
|
|
1105
|
+
}
|
|
1106
|
+
interface AgentComposerProps {
|
|
1107
|
+
/** The agent from `useAgent()` (or `useAgentContext()`). */
|
|
1108
|
+
controller: UseAgentReturn;
|
|
1109
|
+
placeholder?: string;
|
|
1110
|
+
/** Model chip (and switcher). */
|
|
1111
|
+
model?: ComposerModelChip;
|
|
1112
|
+
/** Thinking level, shown next to the model and switchable from its menu. */
|
|
1113
|
+
thinking?: ComposerThinkingChip;
|
|
1114
|
+
/** Override any text the composer renders (see `AgentLabels`). */
|
|
1115
|
+
labels?: AgentLabelsOverride;
|
|
1116
|
+
/** Extra slash commands (merged after the built-ins and the agent's skills). */
|
|
1117
|
+
commands?: SlashCommand[];
|
|
1118
|
+
/** Built-in commands: /compact /new /stop /autopilot /ask /ask-all /read-only /think (default true). */
|
|
1119
|
+
builtinCommands?: boolean;
|
|
1120
|
+
/** Offer the agent's skills as "/skill-name …" commands (default true). */
|
|
1121
|
+
skillCommands?: boolean;
|
|
1122
|
+
/**
|
|
1123
|
+
* "+" button, paste (Ctrl+V) and drag & drop of files and images (default
|
|
1124
|
+
* true). Text files are inlined into the message; images, PDFs and other
|
|
1125
|
+
* files go to the model as attachments — when the model can take them.
|
|
1126
|
+
*/
|
|
1127
|
+
attachments?: boolean | {
|
|
1128
|
+
/** The file picker's `accept`. */
|
|
1129
|
+
accept?: string;
|
|
1130
|
+
/** Refuse larger files (default 20 MB). */
|
|
1131
|
+
maxBytes?: number;
|
|
1132
|
+
/**
|
|
1133
|
+
* Downscale images to this longest edge before sending (default 1568 —
|
|
1134
|
+
* what providers bill for; larger only costs upload). false = as is.
|
|
1135
|
+
*/
|
|
1136
|
+
imageMaxDimension?: number | false;
|
|
1137
|
+
/** …and to this many pixels (default 1 150 000). */
|
|
1138
|
+
imageMaxPixels?: number;
|
|
1139
|
+
};
|
|
1140
|
+
/**
|
|
1141
|
+
* Turn a file into text — e.g. PDF → Markdown with `@dudko.dev/pdf-to-md-core`.
|
|
1142
|
+
* Used for PDFs the model can't read (or every PDF with `convert: 'always'`)
|
|
1143
|
+
* and for files of a kind the model refuses. Return undefined to skip.
|
|
1144
|
+
*/
|
|
1145
|
+
convertFile?: (file: File) => Promise<ConvertedFile | undefined>;
|
|
1146
|
+
/** When to use `convertFile` for PDFs (default 'when-needed'). */
|
|
1147
|
+
convert?: 'when-needed' | 'always';
|
|
1148
|
+
/** Save attachments into this virtual file system (under `/attachments/`). */
|
|
1149
|
+
files?: VirtualFileSystem;
|
|
1150
|
+
/**
|
|
1151
|
+
* Where dropping files attaches them: the composer itself ('self', default),
|
|
1152
|
+
* the whole window ('window'), or any element (a ref — `<AgentChat>` passes
|
|
1153
|
+
* its own panel).
|
|
1154
|
+
*/
|
|
1155
|
+
dropZone?: 'self' | 'window' | RefObject<HTMLElement | null>;
|
|
1156
|
+
/** Speech-to-text mic — the browser's Web Speech API (default: on when supported). */
|
|
1157
|
+
speech?: boolean | {
|
|
1158
|
+
lang?: string;
|
|
1159
|
+
};
|
|
1160
|
+
/** Run timer chip (default true). */
|
|
1161
|
+
showTimer?: boolean;
|
|
1162
|
+
/** Running-subagents chip (default true). */
|
|
1163
|
+
showAgents?: boolean;
|
|
1164
|
+
/** Consent-mode chip — "⚡ Auto" for autopilot (default true). */
|
|
1165
|
+
showApprovalMode?: boolean;
|
|
1166
|
+
/** Banners for limits, compaction and errors above the input (default true). */
|
|
1167
|
+
showNotices?: boolean;
|
|
1168
|
+
/** Below this width (px) the toolbar chips show icons and numbers only (default 460). */
|
|
1169
|
+
compactWidth?: number;
|
|
1170
|
+
/** Extra content in the toolbar, after the "/" button. */
|
|
1171
|
+
toolbarExtra?: ReactNode;
|
|
1172
|
+
/** Extra content at the end of the toolbar, before the consent chip. */
|
|
1173
|
+
toolbarEnd?: ReactNode;
|
|
1174
|
+
/** Render an attachment chip yourself (`remove` drops it). */
|
|
1175
|
+
renderAttachment?: (attachment: ComposerAttachment, remove: () => void) => ReactNode;
|
|
1176
|
+
disabled?: boolean;
|
|
1177
|
+
className?: string;
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* A full chat composer for the agent — the input plus everything around it:
|
|
1181
|
+
*
|
|
1182
|
+
* - banners for a limit that stopped the run, a compaction, a start failure,
|
|
1183
|
+
* or an attachment the model can't take;
|
|
1184
|
+
* - the "+" button, Ctrl+V and drag & drop: images (thumbnails), PDFs and text
|
|
1185
|
+
* files — checked against the model's capabilities, optionally converted
|
|
1186
|
+
* (PDF → Markdown) and saved to a virtual file system;
|
|
1187
|
+
* - slash commands: `/compact`, `/new`, `/stop`, the consent modes, `/think`,
|
|
1188
|
+
* and the agent's skills as `/skill-name …`;
|
|
1189
|
+
* - a run timer, the number of running subagents, the model + thinking chip,
|
|
1190
|
+
* the consent-mode chip ("⚡ Auto" = autopilot), a speech-to-text mic, and
|
|
1191
|
+
* send / stop.
|
|
1192
|
+
*
|
|
1193
|
+
* Every piece can be switched off; `<AgentChat>` uses it as its footer.
|
|
1194
|
+
*/
|
|
1195
|
+
declare const AgentComposer: ({ controller: agent, placeholder, model, thinking, labels: labelsOverride, commands, builtinCommands, skillCommands, attachments, convertFile, convert, files: vfs, dropZone, speech, showTimer, showAgents, showApprovalMode, showNotices, compactWidth, toolbarExtra, toolbarEnd, renderAttachment, disabled, className, }: AgentComposerProps) => react.JSX.Element;
|
|
1196
|
+
|
|
1197
|
+
interface ChatHistoryListProps {
|
|
1198
|
+
/** From `useChatHistory(agent)`. */
|
|
1199
|
+
history: UseChatHistoryReturn;
|
|
1200
|
+
title?: ReactNode;
|
|
1201
|
+
/** Disable switching (e.g. while a run is in flight). */
|
|
1202
|
+
disabled?: boolean;
|
|
1203
|
+
/** Render an entry yourself; `fallback` is the built-in `<li>` — return it, or your own `<li>`. */
|
|
1204
|
+
renderChat?: (chat: ChatSummary, active: boolean, fallback: ReactNode) => ReactNode;
|
|
1205
|
+
/** Format an entry's time (default: locale date + time). */
|
|
1206
|
+
formatTime?: (ms: number) => string;
|
|
1207
|
+
labels?: AgentLabelsOverride;
|
|
1208
|
+
className?: string;
|
|
1209
|
+
}
|
|
1210
|
+
/** The saved conversations: a "New chat" button, then one row per chat (newest first). */
|
|
1211
|
+
declare const ChatHistoryList: ({ history, title, disabled, renderChat, formatTime, labels, className, }: ChatHistoryListProps) => react.JSX.Element;
|
|
1212
|
+
|
|
1213
|
+
interface FilesPanelProps {
|
|
1214
|
+
/** The workspace (the core's `VirtualFileSystem`). */
|
|
1215
|
+
files: VirtualFileSystem;
|
|
1216
|
+
/** Only list paths under this prefix (default '/'). */
|
|
1217
|
+
prefix?: string;
|
|
1218
|
+
title?: ReactNode;
|
|
1219
|
+
/** Upload button (default true). */
|
|
1220
|
+
allowUpload?: boolean;
|
|
1221
|
+
/** Delete buttons (default true). */
|
|
1222
|
+
allowDelete?: boolean;
|
|
1223
|
+
/** Directory uploads go to (default '/uploads'). */
|
|
1224
|
+
uploadDir?: string;
|
|
1225
|
+
/** Called when a file row is clicked (in addition to the preview). */
|
|
1226
|
+
onOpen?: (file: VirtualFileInfo) => void;
|
|
1227
|
+
/** Render a row yourself; `fallback` is the built-in `<li>` — return it, or your own `<li>`. */
|
|
1228
|
+
renderFile?: (file: VirtualFileInfo, fallback: ReactNode) => ReactNode;
|
|
1229
|
+
labels?: AgentLabelsOverride;
|
|
1230
|
+
className?: string;
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* The agent's workspace — attachments the user dropped in, files the agent
|
|
1234
|
+
* wrote with its `fs_*` tools — live, with a preview (text / image),
|
|
1235
|
+
* download, delete and upload.
|
|
1236
|
+
*/
|
|
1237
|
+
declare const FilesPanel: ({ files: vfs, prefix, title, allowUpload, allowDelete, uploadDir, onOpen, renderFile, labels, className, }: FilesPanelProps) => react.JSX.Element;
|
|
1238
|
+
|
|
1239
|
+
/** Render a tool call yourself; `fallback` is the built-in `<li>` row — return it, or your own `<li>`. */
|
|
1240
|
+
type RenderToolCall = (call: ToolCallView, fallback: ReactNode) => ReactNode;
|
|
1241
|
+
interface ToolCallRowProps {
|
|
1242
|
+
call: ToolCallView;
|
|
1243
|
+
showUsage?: boolean;
|
|
1244
|
+
labels?: AgentLabelsOverride;
|
|
1245
|
+
}
|
|
1246
|
+
/** One tool call: name, arguments, status — and optionally its cost and any images it returned. */
|
|
1247
|
+
declare const ToolCallRow: ({ call, showUsage, labels }: ToolCallRowProps) => react.JSX.Element;
|
|
1248
|
+
/** A subagent delegation: name, task, live activity, and its answer when done. */
|
|
1249
|
+
declare const SubagentRow: ({ sub, labels, }: {
|
|
1250
|
+
sub: SubagentView;
|
|
1251
|
+
labels?: AgentLabelsOverride;
|
|
1252
|
+
}) => react.JSX.Element;
|
|
1253
|
+
interface StepListProps {
|
|
1254
|
+
steps: StepView[];
|
|
1255
|
+
/** Subagent delegations (`agent.subagents`) — shown under the step that made them. */
|
|
1256
|
+
subagents?: SubagentView[];
|
|
1257
|
+
/** Consent decisions (`agent.approvals`) — shown under their step. */
|
|
1258
|
+
approvals?: ApprovalView[];
|
|
1259
|
+
/** Show each tool call (default true). */
|
|
1260
|
+
showToolCalls?: boolean;
|
|
1261
|
+
/** Show each tool call's ≈tokens and duration (default true). */
|
|
1262
|
+
showUsage?: boolean;
|
|
1263
|
+
/** Show each step's thoughts when the model thinks (default true). */
|
|
1264
|
+
showThoughts?: boolean;
|
|
1265
|
+
/** Render tool calls yourself (gets the built-in row as `fallback`). */
|
|
1266
|
+
renderToolCall?: RenderToolCall;
|
|
1267
|
+
labels?: AgentLabelsOverride;
|
|
1268
|
+
className?: string;
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* The live execution: each step, its thoughts, streamed text, tool calls,
|
|
1272
|
+
* consent decisions and subagent delegations.
|
|
1273
|
+
*/
|
|
1274
|
+
declare const StepList: ({ steps, subagents, approvals, showToolCalls, showUsage, showThoughts, renderToolCall, labels, className, }: StepListProps) => react.JSX.Element | null;
|
|
1275
|
+
|
|
1276
|
+
interface MessageListProps {
|
|
1277
|
+
messages: ChatMessage[];
|
|
1278
|
+
/** Rendered when there are no messages yet. */
|
|
1279
|
+
empty?: ReactNode;
|
|
1280
|
+
/** Each answer's steps, thoughts, subagents and consent decisions (default true). */
|
|
1281
|
+
showActivity?: boolean;
|
|
1282
|
+
/** Each tool call inside the activity (default true). */
|
|
1283
|
+
showToolCalls?: boolean;
|
|
1284
|
+
/** Tokens per answer and per tool call (default true). */
|
|
1285
|
+
showUsage?: boolean;
|
|
1286
|
+
/** Thoughts (step + answer) when the model thinks (default true). */
|
|
1287
|
+
showThoughts?: boolean;
|
|
1288
|
+
/** Open the activity of finished answers too (default: only while it runs). */
|
|
1289
|
+
activityOpen?: boolean;
|
|
1290
|
+
/** Extra content under the latest assistant turn while it streams (plan thought, …). */
|
|
1291
|
+
liveExtra?: ReactNode;
|
|
1292
|
+
/**
|
|
1293
|
+
* A message's text — e.g. through your markdown renderer. Default: plain
|
|
1294
|
+
* text, line breaks kept.
|
|
1295
|
+
*/
|
|
1296
|
+
renderContent?: (message: ChatMessage) => ReactNode;
|
|
1297
|
+
/** A whole message; `fallback` is the built-in one, to wrap or ignore. */
|
|
1298
|
+
renderMessage?: (message: ChatMessage, fallback: ReactNode) => ReactNode;
|
|
1299
|
+
/** An attachment shown with a message (thumbnail / chip by default). */
|
|
1300
|
+
renderAttachment?: (attachment: ChatAttachment, message: ChatMessage) => ReactNode;
|
|
1301
|
+
/** Tool calls inside the activity. */
|
|
1302
|
+
renderToolCall?: RenderToolCall;
|
|
1303
|
+
labels?: AgentLabelsOverride;
|
|
1304
|
+
className?: string;
|
|
1305
|
+
}
|
|
1306
|
+
/** "in 12k · out 456 · think 120 · cached 9k · 4.2 s" for one answer. */
|
|
1307
|
+
declare const usageLine: (usage: IUsage | undefined, durationMs?: number) => string;
|
|
1308
|
+
/** The built-in attachment: an image thumbnail (opens full size) or a file chip. */
|
|
1309
|
+
declare const AttachmentView: ({ attachment: a }: {
|
|
1310
|
+
attachment: ChatAttachment;
|
|
1311
|
+
}) => react.JSX.Element;
|
|
1312
|
+
/**
|
|
1313
|
+
* The chat transcript. User turns show their text and attachments (image
|
|
1314
|
+
* thumbnails, file chips); every assistant turn keeps its own activity — the
|
|
1315
|
+
* steps with each tool call (≈tokens, duration, returned images), thoughts,
|
|
1316
|
+
* subagents, consent decisions — and the tokens it spent by kind. Every part
|
|
1317
|
+
* can be hidden, relabelled or rendered by the host.
|
|
1318
|
+
*/
|
|
1319
|
+
declare const MessageList: ({ messages, empty, showActivity, showToolCalls, showUsage, showThoughts, activityOpen, liveExtra, renderContent, renderMessage, renderAttachment, renderToolCall, labels, className, }: MessageListProps) => react.JSX.Element | null;
|
|
1320
|
+
|
|
1321
|
+
interface ToolApprovalPromptProps {
|
|
1322
|
+
/** Pending requests (e.g. `agent.pendingApprovals`). */
|
|
1323
|
+
approvals: ApprovalView[];
|
|
1324
|
+
onApprove: (id: string, options?: {
|
|
1325
|
+
remember?: boolean;
|
|
1326
|
+
}) => void;
|
|
1327
|
+
onDeny: (id: string, reason?: string) => void;
|
|
1328
|
+
/** Offer "Always allow" (remembers the tool for the agent's life). Default true. */
|
|
1329
|
+
allowRemember?: boolean;
|
|
1330
|
+
/** Render a request yourself (gets the built-in card as `fallback`). */
|
|
1331
|
+
renderApproval?: (approval: ApprovalView, fallback: ReactNode) => ReactNode;
|
|
1332
|
+
labels?: AgentLabelsOverride;
|
|
1333
|
+
className?: string;
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Consent cards for tool calls the agent wants to make — "Allow once",
|
|
1337
|
+
* "Always allow" and "Deny". Wire it to {@link useAgent}'s `pendingApprovals`,
|
|
1338
|
+
* `approve` and `deny`; `<AgentChat>` renders it for you.
|
|
1339
|
+
*/
|
|
1340
|
+
declare const ToolApprovalPrompt: ({ approvals, onApprove, onDeny, allowRemember, renderApproval, labels, className, }: ToolApprovalPromptProps) => react.JSX.Element | null;
|
|
1341
|
+
|
|
1342
|
+
/** Places to put your own content in the panel. */
|
|
1343
|
+
interface AgentChatSlots {
|
|
1344
|
+
/** Replaces the whole header; `false` hides it. */
|
|
1345
|
+
header?: ReactNode | false;
|
|
1346
|
+
/** In the header, before the title. */
|
|
1347
|
+
headerStart?: ReactNode;
|
|
1348
|
+
/** In the header, after the usage badge. */
|
|
1349
|
+
headerEnd?: ReactNode;
|
|
1350
|
+
/** In the body, above / below the transcript. */
|
|
1351
|
+
beforeMessages?: ReactNode;
|
|
1352
|
+
afterMessages?: ReactNode;
|
|
1353
|
+
/** Above the composer. */
|
|
1354
|
+
footerStart?: ReactNode;
|
|
1355
|
+
/** Under the chat list in the history sidebar. */
|
|
1356
|
+
sidebar?: ReactNode;
|
|
1357
|
+
}
|
|
1358
|
+
/** Swap any built-in part for your own component (same props). */
|
|
1359
|
+
interface AgentChatComponents {
|
|
1360
|
+
Composer?: ComponentType<AgentComposerProps>;
|
|
1361
|
+
MessageList?: ComponentType<MessageListProps>;
|
|
1362
|
+
HistoryList?: ComponentType<ChatHistoryListProps>;
|
|
1363
|
+
FilesPanel?: ComponentType<FilesPanelProps>;
|
|
1364
|
+
ApprovalPrompt?: ComponentType<ToolApprovalPromptProps>;
|
|
1365
|
+
}
|
|
1366
|
+
/** Extra class names per part (added to the built-in `awr-` ones). */
|
|
1367
|
+
interface AgentChatClassNames {
|
|
1368
|
+
root?: string;
|
|
1369
|
+
main?: string;
|
|
1370
|
+
header?: string;
|
|
1371
|
+
body?: string;
|
|
1372
|
+
footer?: string;
|
|
1373
|
+
sidebar?: string;
|
|
1374
|
+
files?: string;
|
|
1375
|
+
}
|
|
446
1376
|
interface AgentChatProps {
|
|
447
1377
|
/**
|
|
448
1378
|
* An explicit controller from {@link useAgent}. If omitted, the component
|
|
@@ -450,39 +1380,88 @@ interface AgentChatProps {
|
|
|
450
1380
|
*/
|
|
451
1381
|
controller?: UseAgentReturn;
|
|
452
1382
|
title?: ReactNode;
|
|
1383
|
+
/** Content shown before the first message. */
|
|
1384
|
+
emptyState?: ReactNode;
|
|
1385
|
+
/** @deprecated use `composer={{ placeholder }}` */
|
|
453
1386
|
placeholder?: string;
|
|
454
|
-
/**
|
|
1387
|
+
/** Each answer's steps, thoughts, subagents, consent decisions (default true). */
|
|
455
1388
|
showActivity?: boolean;
|
|
456
|
-
/**
|
|
1389
|
+
/** Each tool call inside the activity (default true). */
|
|
1390
|
+
showToolCalls?: boolean;
|
|
1391
|
+
/** Tokens per answer and per tool call (default true). */
|
|
457
1392
|
showUsage?: boolean;
|
|
458
|
-
/**
|
|
459
|
-
|
|
1393
|
+
/** Thoughts, when the model thinks (default true). */
|
|
1394
|
+
showThoughts?: boolean;
|
|
1395
|
+
/** Conversation total in the header (default true). */
|
|
1396
|
+
showTotalUsage?: boolean;
|
|
1397
|
+
/** Status dot in the header (default true). */
|
|
1398
|
+
showStatus?: boolean;
|
|
1399
|
+
/** Consent-mode chip in the composer — "⚡ Auto" (default true). */
|
|
1400
|
+
showApprovalMode?: boolean;
|
|
1401
|
+
/**
|
|
1402
|
+
* Context meter (tokens by kind, budget bar, Compact) above the composer
|
|
1403
|
+
* (default false). A number draws the bar against that budget.
|
|
1404
|
+
*/
|
|
1405
|
+
showContext?: boolean | number;
|
|
1406
|
+
/** Keep finished answers' activity expanded (default false). */
|
|
1407
|
+
activityOpen?: boolean;
|
|
1408
|
+
/**
|
|
1409
|
+
* Saved conversations in IndexedDB with a sidebar to switch between them:
|
|
1410
|
+
* `true` (default store), your own `ChatHistoryStore`, or the result of your
|
|
1411
|
+
* own `useChatHistory()` (e.g. to render the list elsewhere).
|
|
1412
|
+
*/
|
|
1413
|
+
history?: boolean | ChatHistoryStore | UseChatHistoryReturn;
|
|
1414
|
+
/**
|
|
1415
|
+
* Sidebar open at first (default: on a wide panel yes; on a narrow one —
|
|
1416
|
+
* under `narrowWidth` — it starts closed and opens over the chat).
|
|
1417
|
+
*/
|
|
1418
|
+
defaultHistoryOpen?: boolean;
|
|
1419
|
+
/**
|
|
1420
|
+
* The workspace: attachments are saved here, and a Files panel shows it
|
|
1421
|
+
* (add `createFileTools(files)` to the agent's tools so it can use it too).
|
|
1422
|
+
*/
|
|
1423
|
+
files?: VirtualFileSystem;
|
|
1424
|
+
/** Files panel open at first (default false). */
|
|
1425
|
+
defaultFilesOpen?: boolean;
|
|
1426
|
+
/** Below this width (px) side panels overlay the chat instead of sitting beside it (default 760). */
|
|
1427
|
+
narrowWidth?: number;
|
|
1428
|
+
/** Composer options (model / thinking chips, commands, convertFile, speech…), or `false` to hide it. */
|
|
1429
|
+
composer?: Partial<Omit<AgentComposerProps, 'controller'>> | false;
|
|
1430
|
+
/** A message's text — plug in your markdown renderer here. */
|
|
1431
|
+
renderContent?: MessageListProps['renderContent'];
|
|
1432
|
+
renderMessage?: MessageListProps['renderMessage'];
|
|
1433
|
+
renderAttachment?: MessageListProps['renderAttachment'];
|
|
1434
|
+
renderToolCall?: RenderToolCall;
|
|
1435
|
+
renderApproval?: ToolApprovalPromptProps['renderApproval'];
|
|
1436
|
+
slots?: AgentChatSlots;
|
|
1437
|
+
components?: AgentChatComponents;
|
|
1438
|
+
/** Override any text (i18n); applies to every part inside. */
|
|
1439
|
+
labels?: AgentLabelsOverride;
|
|
1440
|
+
/** Force a colour scheme (default 'auto' = follow the OS). */
|
|
1441
|
+
theme?: 'auto' | 'light' | 'dark';
|
|
1442
|
+
classNames?: AgentChatClassNames;
|
|
460
1443
|
className?: string;
|
|
461
1444
|
/** Inline styles on the root — handy for sizing (e.g. `{ height: 520 }`). */
|
|
462
1445
|
style?: CSSProperties;
|
|
463
1446
|
}
|
|
464
1447
|
/**
|
|
465
|
-
* A drop-in chat panel: transcript
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
1448
|
+
* A drop-in chat panel: transcript with every answer's activity (steps, tool
|
|
1449
|
+
* calls with their cost, thoughts, subagents, consent decisions) and tokens by
|
|
1450
|
+
* kind, live consent prompts, model-load progress, and the full composer
|
|
1451
|
+
* (attachments by "+", Ctrl+V and drag & drop; slash commands; timer; agents;
|
|
1452
|
+
* model + thinking; consent mode; dictation). Optional: saved chats in
|
|
1453
|
+
* IndexedDB (`history`) and a workspace panel (`files`).
|
|
1454
|
+
*
|
|
1455
|
+
* Everything is switchable (`show*`), relabelable (`labels`), replaceable
|
|
1456
|
+
* (`render*`, `slots`, `components`) and themable (`theme`, `--awr-*`
|
|
1457
|
+
* variables, `classNames`). Give it a `controller` from {@link useAgent}, or
|
|
1458
|
+
* wrap it in an {@link AgentProvider}.
|
|
469
1459
|
*
|
|
470
1460
|
* ```tsx
|
|
471
|
-
* <
|
|
472
|
-
* <AgentChat title="Assistant" />
|
|
473
|
-
* </AgentProvider>
|
|
1461
|
+
* <AgentChat controller={agent} history files={vfs} composer={{ model: { label: 'Gemini' } }} />
|
|
474
1462
|
* ```
|
|
475
1463
|
*/
|
|
476
|
-
declare const AgentChat: (
|
|
477
|
-
|
|
478
|
-
interface MessageListProps {
|
|
479
|
-
messages: ChatMessage[];
|
|
480
|
-
/** Rendered when there are no messages yet. */
|
|
481
|
-
empty?: ReactNode;
|
|
482
|
-
className?: string;
|
|
483
|
-
}
|
|
484
|
-
/** The chat transcript: user and assistant turns, with a streaming indicator. */
|
|
485
|
-
declare const MessageList: ({ messages, empty, className }: MessageListProps) => react.JSX.Element | null;
|
|
1464
|
+
declare const AgentChat: (props: AgentChatProps) => react.JSX.Element;
|
|
486
1465
|
|
|
487
1466
|
interface ComposerProps {
|
|
488
1467
|
/** Called with the trimmed text when the user submits. */
|
|
@@ -508,12 +1487,39 @@ interface PlanViewProps {
|
|
|
508
1487
|
/** The plan the agent produced: its reasoning and the ordered step list. */
|
|
509
1488
|
declare const PlanView: ({ plan, showThought, className }: PlanViewProps) => react.JSX.Element | null;
|
|
510
1489
|
|
|
511
|
-
interface
|
|
512
|
-
|
|
1490
|
+
interface ApprovalModeSwitchProps {
|
|
1491
|
+
mode: ToolApprovalMode;
|
|
1492
|
+
onChange: (mode: ToolApprovalMode) => void;
|
|
1493
|
+
/** Which modes to offer, in order (default: all four). */
|
|
1494
|
+
modes?: ToolApprovalMode[];
|
|
1495
|
+
/** Override the button labels. */
|
|
1496
|
+
labels?: Partial<Record<ToolApprovalMode, string>>;
|
|
1497
|
+
disabled?: boolean;
|
|
1498
|
+
className?: string;
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* A segmented control for the tool-consent policy — the "autopilot" switch.
|
|
1502
|
+
* Pair it with {@link useAgent}'s `approvalMode` / `setApprovalMode`.
|
|
1503
|
+
*/
|
|
1504
|
+
declare const ApprovalModeSwitch: ({ mode, onChange, modes, labels, disabled, className, }: ApprovalModeSwitchProps) => react.JSX.Element;
|
|
1505
|
+
|
|
1506
|
+
interface ContextMeterProps {
|
|
1507
|
+
usage: IUsage;
|
|
1508
|
+
/** A run budget to draw the bar against (e.g. limits.maxTotalTokens). */
|
|
1509
|
+
budgetTokens?: number;
|
|
1510
|
+
/** The limit that stopped the run, if any. */
|
|
1511
|
+
budget?: BudgetView;
|
|
1512
|
+
compactions?: CompactionView[];
|
|
1513
|
+
/** Show a "Compact" button (e.g. `agent.compact`). */
|
|
1514
|
+
onCompact?: () => void;
|
|
1515
|
+
compacting?: boolean;
|
|
513
1516
|
className?: string;
|
|
514
1517
|
}
|
|
515
|
-
/**
|
|
516
|
-
|
|
1518
|
+
/**
|
|
1519
|
+
* Where the run's tokens went — input, output, thinking, prompt-cache hits —
|
|
1520
|
+
* with an optional budget bar, the last compaction and a "Compact" button.
|
|
1521
|
+
*/
|
|
1522
|
+
declare const ContextMeter: ({ usage, budgetTokens, budget, compactions, onCompact, compacting, className, }: ContextMeterProps) => react.JSX.Element | null;
|
|
517
1523
|
|
|
518
1524
|
interface ModelLoadBarProps {
|
|
519
1525
|
load: ModelLoadState;
|
|
@@ -524,10 +1530,15 @@ declare const ModelLoadBar: ({ load, className }: ModelLoadBarProps) => react.JS
|
|
|
524
1530
|
|
|
525
1531
|
interface UsageBadgeProps {
|
|
526
1532
|
usage: IUsage;
|
|
1533
|
+
/** Only in ↑ out ↓ (the rest stays in the tooltip) — for tight headers. */
|
|
1534
|
+
compact?: boolean;
|
|
527
1535
|
className?: string;
|
|
528
1536
|
}
|
|
529
|
-
/**
|
|
530
|
-
|
|
1537
|
+
/**
|
|
1538
|
+
* A compact token-usage readout: in ↑ out ↓, plus thinking (🧠) and cache-hit
|
|
1539
|
+
* tokens when the provider reported any. The full breakdown is on hover.
|
|
1540
|
+
*/
|
|
1541
|
+
declare const UsageBadge: ({ usage, compact, className }: UsageBadgeProps) => react.JSX.Element | null;
|
|
531
1542
|
|
|
532
1543
|
interface ApiKeyFormProps {
|
|
533
1544
|
/** The value returned by {@link useCredentials}. */
|
|
@@ -547,4 +1558,4 @@ interface ApiKeyFormProps {
|
|
|
547
1558
|
*/
|
|
548
1559
|
declare const ApiKeyForm: ({ credentials, credentialRef, label, placeholder, onChange, className, }: ApiKeyFormProps) => react.JSX.Element;
|
|
549
1560
|
|
|
550
|
-
export { type AgentAction, AgentChat, type AgentChatProps, AgentProvider, type AgentProviderProps, type AgentStatus, type AgentUiState, ApiKeyForm, type ApiKeyFormProps, type ChatMessage, Composer, type ComposerProps, type ConnectedMcp, type McpCatalogEntry, type McpConnectOptions, type McpModule, type McpOAuthCallback, type McpServerResult, type McpStatus, MessageList, type MessageListProps, ModelLoadBar, type ModelLoadBarProps, type ModelLoadState, PlanView, type PlanViewProps, type ReplanState, StepList, type StepListProps, type StepView, type ToolCallView, UsageBadge, type UsageBadgeProps, type UseAgentOptions, type UseAgentReturn, type UseCredentialsReturn, type UseMcpOptions, type UseMcpReturn, type UseWebLLMModelOptions, type UseWebLLMModelReturn, type WebLLMModelFactory, agentStateReducer, claimOAuthCallback, createInitialAgentState, describeMcpResult, isUnauthorizedError, readCallbackParams, stripOAuthParams, useAgent, useAgentContext, useCredentials, useMcp, useOptionalAgentContext, useWebLLMModel };
|
|
1561
|
+
export { type AgentAction, AgentChat, type AgentChatClassNames, type AgentChatComponents, type AgentChatProps, type AgentChatSlots, AgentComposer, type AgentComposerProps, type AgentLabels, type AgentLabelsOverride, AgentLabelsProvider, type AgentLabelsProviderProps, AgentProvider, type AgentProviderProps, type AgentStatus, type AgentUiState, ApiKeyForm, type ApiKeyFormProps, ApprovalModeSwitch, type ApprovalModeSwitchProps, type ApprovalView, type ApproveOptions, AttachmentView, type BudgetView, type ChatAttachment, ChatHistoryList, type ChatHistoryListProps, ChatHistoryStore, type ChatHistoryStoreOptions, type ChatMessage, type ChatRecord, type ChatSummary, type CompactionView, Composer, type ComposerAttachment, type ComposerModelChip, type ComposerNotice, type ComposerProps, type ComposerThinkingChip, type ConnectedMcp, ContextMeter, type ContextMeterProps, type ConvertedFile, type DownscaleOptions, FilesPanel, type FilesPanelProps, type McpAuthMode, type McpCatalogEntry, type McpConnectOptions, type McpModule, type McpOAuthCallback, type McpServerResult, type McpServerSpec, type McpServerView, type McpStatus, MessageList, type MessageListProps, ModelLoadBar, type ModelLoadBarProps, type ModelLoadState, type NoticeTexts, PlanView, type PlanViewProps, type RenderToolCall, type ReplanState, type RunGoalOptions, type SlashCommand, type SpeechRecognizerLike, StepList, type StepListProps, type StepView, SubagentRow, type SubagentView, ToolApprovalPrompt, type ToolApprovalPromptProps, ToolCallRow, type ToolCallRowProps, type ToolCallView, UsageBadge, type UsageBadgeProps, type UseAgentOptions, type UseAgentReturn, type UseChatHistoryOptions, type UseChatHistoryReturn, type UseCredentialsReturn, type UseMcpOptions, type UseMcpReturn, type UseMcpServersOptions, type UseMcpServersReturn, type UseSpeechToTextOptions, type UseSpeechToTextReturn, type UseVirtualFilesReturn, type UseWebLLMModelOptions, type UseWebLLMModelReturn, type WebLLMModelFactory, agentStateReducer, attachmentKindOf, attachmentRefusal, chatTitle, claimOAuthCallback, createInitialAgentState, defaultLabels, describeMcpResult, downscaleImage, filterCommands, formatElapsed, isUnauthorizedError, mergeLabels, newChatId, noticesOf, parseSlash, readCallbackParams, stripOAuthParams, usageLine, useAgent, useAgentContext, useChatHistory, useCredentials, useLabels, useMcp, useMcpServers, useOptionalAgentContext, useSpeechToText, useVirtualFiles, useWebLLMModel, withAttachments };
|