@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/README.md
CHANGED
|
@@ -8,9 +8,17 @@ app with a single hook and (optionally) a set of pre-styled components:
|
|
|
8
8
|
a ready-to-render state (plan, steps, tool calls, streamed answer, token
|
|
9
9
|
usage, model-load progress, chat transcript), and get `run` / `stop` /
|
|
10
10
|
`reset` / `reload`.
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
- 💬 **`<AgentChat>`** — a drop-in chat: every tool call with its cost, tokens by
|
|
12
|
+
kind per answer and in total, thoughts, subagents, consent prompts; a
|
|
13
|
+
composer with "+" / Ctrl+V / drag & drop attachments (images, PDFs, files),
|
|
14
|
+
"/" commands, run timer, agents, model + thinking chip, the "⚡ Auto" consent
|
|
15
|
+
chip and speech to text; saved chats in IndexedDB and a workspace (virtual
|
|
16
|
+
file system) panel. Everything is a prop: show/hide, labels (i18n), render
|
|
17
|
+
props, slots, swappable components, theme — see [docs/chat.md](docs/chat.md).
|
|
18
|
+
- 🧩 **Building blocks** — `<AgentComposer>`, `<MessageList>`, `<StepList>`,
|
|
19
|
+
`<ToolApprovalPrompt>`, `<ChatHistoryList>`, `<FilesPanel>`, `<ContextMeter>`,
|
|
20
|
+
`<ModelLoadBar>`, `<UsageBadge>`, `<ApiKeyForm>`; hooks `useChatHistory`,
|
|
21
|
+
`useVirtualFiles`, `useSpeechToText`, `useMcpServers`.
|
|
14
22
|
- 🔑 **`useCredentials`** — store BYOK API keys **encrypted at rest**
|
|
15
23
|
(WebCrypto + IndexedDB).
|
|
16
24
|
- 🖥️ **`useWebLLMModel`** — load a local WebGPU model with download progress.
|
|
@@ -22,9 +30,11 @@ app with a single hook and (optionally) a set of pre-styled components:
|
|
|
22
30
|
[](https://www.npmjs.com/package/@dudko.dev/agent-web-react)
|
|
23
31
|

|
|
24
32
|
|
|
25
|
-
> **▶︎ [Live demo](https://dudko-dev.github.io/agent-web-react/)** —
|
|
26
|
-
> edits a sticky-notes board
|
|
27
|
-
>
|
|
33
|
+
> **▶︎ [Live demo](https://dudko-dev.github.io/agent-web-react/)** — three agents:
|
|
34
|
+
> one edits a sticky-notes board, one drives any number of MCP servers (plus a
|
|
35
|
+
> 185-tool mock catalogue to show tool search), and one plays chess against you
|
|
36
|
+
> — your move triggers it, analyst subagents run in Web Workers. Cloud BYOK or
|
|
37
|
+
> local WebGPU, all in your browser. Source in [`demo/`](demo/).
|
|
28
38
|
|
|
29
39
|
## Install
|
|
30
40
|
|
|
@@ -155,20 +165,26 @@ function Custom() {
|
|
|
155
165
|
|
|
156
166
|
| Field | Description |
|
|
157
167
|
| --- | --- |
|
|
158
|
-
| `run(goal)` | Start a run; resolves with the `RunResult` |
|
|
168
|
+
| `run(goal, { images, files, attachments, label })` | Start a run (with attachments); resolves with the `RunResult` |
|
|
159
169
|
| `stop()` | Abort the in-flight run |
|
|
160
|
-
| `reset()` | Clear the whole conversation |
|
|
170
|
+
| `reset()` | Clear the whole conversation (and the agent's memory of it) |
|
|
161
171
|
| `reload()` | Rebuild the agent (e.g. after storing a new key) |
|
|
162
172
|
| `status` | `idle` \| `initializing` \| `ready` \| `running` \| `error` |
|
|
163
173
|
| `isReady` / `isRunning` | convenience booleans |
|
|
164
|
-
| `messages` |
|
|
165
|
-
| `plan` / `steps` | the live plan and per-step tool calls |
|
|
166
|
-
| `finalText` | the streamed
|
|
167
|
-
| `usage` |
|
|
174
|
+
| `messages` | transcript; each assistant message keeps its steps, tool calls, thoughts, approvals, subagents, usage and duration |
|
|
175
|
+
| `plan` / `steps` | the live plan and per-step tool calls (with timing) |
|
|
176
|
+
| `finalText` / `finalReasoning` | the streamed answer and its thoughts |
|
|
177
|
+
| `usage` / `totalUsage` | tokens of this run / of the conversation, by kind |
|
|
178
|
+
| `pendingApprovals`, `approve(id, { remember })`, `deny(id)` | tool consent |
|
|
179
|
+
| `approvalMode` / `setApprovalMode(mode)` | the autopilot switch, live |
|
|
180
|
+
| `compact()` | summarise the stored transcript now |
|
|
181
|
+
| `sessionId` / `loadChat(chat)` | the memory session; switch conversations |
|
|
182
|
+
| `subagents`, `skills`, `discoveredTools`, `compactions`, `budget` | the rest of the run, folded |
|
|
168
183
|
| `modelLoad` | WebLLM download progress, when loading |
|
|
169
184
|
|
|
170
185
|
**Options:** `deps` (rebuild the agent when these change — e.g. on a model
|
|
171
|
-
switch), `onEvent` (tap the raw event stream), `autoStart`, `maxEvents
|
|
186
|
+
switch), `onEvent` (tap the raw event stream), `autoStart`, `maxEvents`,
|
|
187
|
+
`approvals` (route consent requests into the hook; default true).
|
|
172
188
|
|
|
173
189
|
> Keep `tools` and `describeState` referentially stable (`useMemo` /
|
|
174
190
|
> `useCallback`); pass a changed `deps` array to rebuild the agent on a
|
|
@@ -289,25 +305,48 @@ Two notes:
|
|
|
289
305
|
you do use MCP.
|
|
290
306
|
- `oauthSupported` is `false` on cores older than `@dudko.dev/agent-web@0.0.9`,
|
|
291
307
|
which introduced `BrowserOAuthProvider`; header auth still works there. The
|
|
292
|
-
peer floor is `>=0.0.
|
|
293
|
-
|
|
308
|
+
peer floor is `>=0.0.20` — the first core with the virtual file system,
|
|
309
|
+
attachments, consent, tool search, subagents and context editing this
|
|
310
|
+
package's chat builds on.
|
|
311
|
+
|
|
312
|
+
## Several MCP servers — `useMcpServers`
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
const mcp = useMcpServers({ clientName: 'my-app' }) // the list persists; reconnects on load
|
|
316
|
+
await mcp.add({ name: 'docs', url, auth: 'oauth' }) // 'none' | 'bearer' (+ token) | 'oauth'
|
|
317
|
+
mcp.servers // [{ name, url, status, catalog, error, … }]
|
|
318
|
+
const config = { model, tools: { ...myTools, ...mcp.tools } } // "<name>__<tool>"
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Servers connect in parallel, each with its own deadline; paginated tool lists
|
|
322
|
+
are read to the end; tools a server marks read-only skip the "ask before
|
|
323
|
+
changes" prompt. With hundreds of tools the core switches to **tool search**
|
|
324
|
+
(a compact catalogue + `find_tools`) above `toolSearchThreshold` — see the
|
|
325
|
+
core's [capabilities doc](https://github.com/dudko-dev/agent-web/blob/main/docs/capabilities.md).
|
|
294
326
|
|
|
295
327
|
## Components
|
|
296
328
|
|
|
297
329
|
All components are optional and styled by `styles.css` (class-prefixed `awr-`,
|
|
298
|
-
themeable via `--awr-*` custom properties, light + dark). Each
|
|
299
|
-
`className`; data components take plain props so you can
|
|
330
|
+
themeable via `--awr-*` custom properties, light + dark, or `theme`). Each
|
|
331
|
+
accepts a `className` and `labels`; data components take plain props so you can
|
|
332
|
+
use them standalone. The full guide: [docs/chat.md](docs/chat.md).
|
|
300
333
|
|
|
301
334
|
| Component | Purpose |
|
|
302
335
|
| --- | --- |
|
|
303
|
-
| `<AgentChat>` | Full panel: transcript
|
|
304
|
-
| `<
|
|
305
|
-
| `<
|
|
336
|
+
| `<AgentChat>` | Full panel: transcript with per-answer activity + composer + optional history and files panels. Reads a `controller` prop or the `<AgentProvider>` context. |
|
|
337
|
+
| `<AgentComposer>` | The input and its toolbar: attachments, commands, timer, agents, model/thinking, consent, mic, send/stop. |
|
|
338
|
+
| `<MessageList>` | The transcript; each answer with its steps, tool calls, thoughts, usage. |
|
|
339
|
+
| `<StepList>` / `<ToolCallRow>` | Execution steps / one tool call with its cost and images. |
|
|
340
|
+
| `<ToolApprovalPrompt>` | Consent cards (Allow once / Always / Deny). |
|
|
341
|
+
| `<ApprovalModeSwitch>` | Segmented consent-mode switch. |
|
|
342
|
+
| `<ChatHistoryList>` | Saved chats (from `useChatHistory`). |
|
|
343
|
+
| `<FilesPanel>` | A `VirtualFileSystem`, live: preview, download, delete, upload. |
|
|
344
|
+
| `<ContextMeter>` | Tokens by kind, budget bar, last compaction, Compact. |
|
|
306
345
|
| `<PlanView>` | A plan's reasoning + step list. |
|
|
307
|
-
| `<StepList>` | Live execution steps with tool calls. |
|
|
308
346
|
| `<ModelLoadBar>` | WebLLM download/init progress. |
|
|
309
347
|
| `<UsageBadge>` | Compact token readout. |
|
|
310
348
|
| `<ApiKeyForm>` | BYOK key entry that writes to the encrypted vault. |
|
|
349
|
+
| `<Composer>` | The minimal textarea + send/stop (kept for existing apps). |
|
|
311
350
|
|
|
312
351
|
### Build your own UI
|
|
313
352
|
|
|
@@ -344,10 +383,17 @@ from one place.
|
|
|
344
383
|
|
|
345
384
|
## Browser tests
|
|
346
385
|
|
|
347
|
-
`npm run test:e2e` builds the demo and drives it in Chromium:
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
386
|
+
`npm run test:e2e` builds the demo and drives it in Chromium:
|
|
387
|
+
|
|
388
|
+
- MCP: connecting to one and to several servers, the full OAuth redirect
|
|
389
|
+
round-trip (authorize → come back with a code → connected), reconnecting
|
|
390
|
+
with the stored tokens after a reload, and an unreachable server;
|
|
391
|
+
- the agent, against a scripted Gemini endpoint ([`e2e/gemini.ts`](e2e/gemini.ts),
|
|
392
|
+
the real `@ai-sdk/google` provider underneath): tool calls and tokens by
|
|
393
|
+
kind in the transcript, a chat saved and restored after a reload, an image
|
|
394
|
+
attached (shown, sent as a file part, saved in the workspace), a file
|
|
395
|
+
dropped anywhere on the page, consent in "Ask" mode, slash commands, the
|
|
396
|
+
chess move that triggers the agent, and Russian labels. The MCP and authorization servers it
|
|
351
397
|
talks to are started on loopback by [`e2e/servers.ts`](e2e/servers.ts), CORS
|
|
352
398
|
headers included — so the test also pins the deployment requirement that the
|
|
353
399
|
challenge header be exposed.
|