@dudko.dev/agent-web-react 0.0.26 β†’ 0.0.27

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 CHANGED
@@ -23,6 +23,10 @@ app with a single hook and (optionally) a set of pre-styled components:
23
23
  chip and speech to text; saved chats in IndexedDB and a workspace (virtual
24
24
  file system) panel. Everything is a prop: show/hide, labels (i18n), render
25
25
  props, slots, swappable components, theme β€” see [docs/chat.md](docs/chat.md).
26
+ - πŸ•ΈοΈ **Pipeline editor** β€” draw a graph of agents on a canvas (our own: no canvas or
27
+ graph library), connect them with conditions and loops, run it with live statuses,
28
+ copy it as code: `<PipelineEditor>` and `usePipeline`, behind
29
+ `@dudko.dev/agent-web-react/pipeline` β€” see [docs/pipeline.md](docs/pipeline.md).
26
30
  - πŸ—£οΈ **Steering and learning** β€” type to the agent while it works (`send`,
27
31
  `stopSubagent`; queued / delivered notes under the step that got them), and watch
28
32
  it keep a notebook: lessons it wrote down as skills (`learned`, `<LearnedSkills>`,
@@ -48,7 +52,7 @@ app with a single hook and (optionally) a set of pre-styled components:
48
52
  > local WebGPU, all in your browser. Settings turn on tool consent, thinking, token
49
53
  > and step limits, compaction, skills - the agent's own **notebook** (it writes down
50
54
  > what it figured out, in the workspace, across reloads) and **web access** limited
51
- > to hosts you list. Type to the agent while it works. Source in [`demo/`](demo/).
55
+ > to hosts you list. Type to the agent while it works. Source in [`apps/demo`](https://github.com/dudko-dev/agents/tree/main/apps/demo).
52
56
 
53
57
  ## Install
54
58
 
@@ -291,7 +295,7 @@ const local = useLocalModel(option.model, option.builtIn ? builtIn : webllm, {
291
295
  ```
292
296
 
293
297
  The demo runs WebLLM, Chrome's Gemini Nano and transformers.js this way β€” see
294
- [`demo/src/local-engines.ts`](demo/src/local-engines.ts).
298
+ [`apps/demo/src/local-engines.ts`](https://github.com/dudko-dev/agents/blob/main/apps/demo/src/local-engines.ts).
295
299
 
296
300
  ## Models in a bundler (Vite, Next, CRA)
297
301
 
@@ -334,8 +338,8 @@ function CloudAgent() {
334
338
  **Local** β€” pass a statically-imported `webLLM` factory via `useWebLLMModel`'s
335
339
  `create` option (see the WebLLM example above).
336
340
 
337
- The [`demo/`](demo/) app does exactly this β€” see
338
- [`demo/src/providers.ts`](demo/src/providers.ts).
341
+ The [`apps/demo`](https://github.com/dudko-dev/agents/tree/main/apps/demo) app does exactly this β€” see
342
+ [`apps/demo/src/providers.ts`](https://github.com/dudko-dev/agents/blob/main/apps/demo/src/providers.ts).
339
343
 
340
344
  ## MCP hooks live in their own subpath
341
345
 
@@ -361,6 +365,37 @@ subpath the decision is yours:
361
365
  > `describeMcpResult`, `isUnauthorizedError`) and types (`McpStatus`,
362
366
  > `McpAuthMode`, `McpServerView`, …) moved: change the import path, nothing else.
363
367
 
368
+ ## Pipelines: an editor on a canvas
369
+
370
+ ```tsx
371
+ import { PipelineEditor, usePipeline } from '@dudko.dev/agent-web-react/pipeline'
372
+ import '@dudko.dev/agent-web-react/pipeline.css'
373
+
374
+ const pipeline = usePipeline(definition, { base: { model, credentials }, tools: { files } })
375
+ return <PipelineEditor value={definition} onChange={setDefinition} controller={pipeline} />
376
+ ```
377
+
378
+ The editor for the core's [pipelines](https://github.com/dudko-dev/agents/blob/main/packages/agent-web/docs/capabilities.md#pipelines-a-graph-of-agents)
379
+ (a graph of agents in plain JSON) lives in its own entry, like MCP and for a similar reason: a
380
+ chat host should not carry a canvas, an inspector and a code generator, nor need a core new
381
+ enough to have `createPipeline`. Nothing in the main entry references it. Its stylesheet,
382
+ `pipeline.css`, is separate too and stands on its own. It adds **no dependency**: the canvas is
383
+ this package's own code.
384
+
385
+ | Export | What it is |
386
+ | --- | --- |
387
+ | `usePipeline(definition, options)` | Builds the pipeline with the core (`resolveNode`, or the registries of `nodeResolver`: `base`, `models`, `skills`, `tools`, `mcpServers`), and returns `run(input)`, `stop()`, `reset()`, `isRunning`, `validation`, `result` plus the state below. |
388
+ | `pipelineStateReducer`, `createInitialPipelineState`, `pipelineNodeView` | The pure event β†’ state reducer: per-node status and visits, which edges fired, what each node's agent is doing, outputs, usage, `stoppedBy`, the error. |
389
+ | `<PipelineEditor>` | The editor: canvas, node cards, inspector, toolbar, validation, run bar, results. Controlled (`value`, `onChange`). |
390
+ | `<PipelineNodeCard>`, `<PipelineInspector>`, `<PipelineResults>`, `<PipelineIssues>`, `<PipelineCodeDialog>` | Its parts, to compose your own. |
391
+ | `<Canvas>`, `<CanvasPort>` and the canvas maths | The generic node-and-edge canvas underneath: pan, zoom, drag, connect, keyboard, screen readers. |
392
+ | `addNode`, `removeNode`, `renameNode`, `addEdge`, `updateEdge`, `removeEdge`, `setEntry`, `autoLayout`, `parsePipelineJson`, ... | Editing a definition, as pure functions. |
393
+ | `pipelineToCode(definition, { target })` | "Copy as code": a snippet for the browser package or for the Node one. |
394
+ | `PipelineLabelsProvider`, `defaultPipelineLabels`, `usePipelineLabels` | Every string of the editor (its own labels object, not `AgentLabels`). |
395
+
396
+ The full guide, with every prop, state field and label: [docs/pipeline.md](docs/pipeline.md).
397
+ Live: <https://agent.dudko.dev/pipeline/>.
398
+
364
399
  ## The `useMcp` hook β€” connect a remote MCP server
365
400
 
366
401
  Let the user name their own MCP server at runtime and hand its tools to the
@@ -388,10 +423,46 @@ forgetAuthorization, checkOAuthSupport }`. `status` is
388
423
  `idle | connecting | connected | needs-authorization | error`.
389
424
 
390
425
  The OAuth round-trip navigates away from your app, so the hook persists what it
391
- needs and, on the way back, finishes the code exchange, strips `?code=…` from
392
- the address bar and reconnects before rendering β€” `completingAuthorization`
426
+ needs and, on the way back, finishes the code exchange (passing `iss` to the
427
+ core, which refuses a response from another authorization server - RFC 9207),
428
+ strips `?code=…` from the address bar and reconnects before rendering β€” `completingAuthorization`
393
429
  covers that window.
394
430
 
431
+ Options:
432
+
433
+ | | |
434
+ | --- | --- |
435
+ | `useMcp({ clientName })` | the MCP client name, and the `client_name` of a dynamic registration |
436
+ | `useMcp({ clientMetadataUrl })` | the URL of a **client ID metadata document** (CIMD) your app hosts, for every OAuth server - see below |
437
+ | `useMcp({ onLog })` | connector log lines |
438
+ | `connect({ url, name, headers })` | the endpoint, the tool prefix (`"<name>__<tool>"`, default `mcp`), static headers |
439
+ | `connect({ oauth })` | `true`, or `{ redirectUrl, scope, clientName, clientMetadataUrl }` (`McpOAuthOptions`) - each overrides the hook-level value for this server |
440
+
441
+ **`clientMetadataUrl` (CIMD).** Instead of registering itself with every authorization server, an
442
+ app can publish one JSON document that describes it and use that document's URL as its
443
+ `client_id`:
444
+
445
+ ```tsx
446
+ const mcp = useMcp({
447
+ clientName: 'my-app',
448
+ clientMetadataUrl: 'https://my-app.example/oauth/client.json',
449
+ })
450
+ await mcp.connect({ url, oauth: true })
451
+ // or for one server only: connect({ url, oauth: { clientMetadataUrl: '…' } })
452
+ ```
453
+
454
+ The hooks pass the URL to the core's OAuth provider unchanged. An authorization server that
455
+ advertises `client_id_metadata_document_supported` takes it as the `client_id` and no registration
456
+ request is made; any other server gets dynamic registration as before, and a registration already
457
+ stored for the server wins over both (`forgetAuthorization` drops it). The URL must be https with a
458
+ path of its own, and the document served there must list the `redirectUrl` (by default this page,
459
+ without query or hash) in its `redirect_uris` - the core refuses any other URL before a request is
460
+ made, and the server ends in `status: 'error'` with the reason. The URL is public and is remembered
461
+ with the rest of the server's OAuth details across the redirect and reloads. The core's
462
+ [README](https://github.com/dudko-dev/agents/blob/main/packages/agent-web/README.md) and
463
+ [security notes](https://github.com/dudko-dev/agents/blob/main/packages/agent-web/docs/security.md)
464
+ say what the document must contain.
465
+
395
466
  Two notes:
396
467
 
397
468
  - The connector lives in the core's optional `@dudko.dev/agent-web/mcp` subpath
@@ -400,11 +471,10 @@ Two notes:
400
471
  core β€” importing these hooks is what puts it in your build.
401
472
  - `oauthSupported` is `false` on cores older than `@dudko.dev/agent-web@0.0.9`,
402
473
  which introduced `BrowserOAuthProvider`; header auth still works there. The
403
- peer floor is `>=0.0.30` β€” the first core with the learning notebook
404
- (`forgetSkill`, `listLearnedSkills`) on top of the virtual file system,
405
- attachments, consent, tool search, subagents, steering and context editing this
406
- package's chat builds on. `agent.usage` / `agent.sessionUsage()` and the
407
- window-derived output caps need `>=0.0.32`.
474
+ peer floor is `>=0.0.38` β€” the first core with pipelines (`createPipeline`,
475
+ which the `./pipeline` entry builds on) and `clientMetadataUrl`, on top of the
476
+ learning notebook, the virtual file system, attachments, consent, tool search,
477
+ subagents, steering and context editing this package's chat builds on.
408
478
 
409
479
  ## Several MCP servers β€” `useMcpServers`
410
480
 
@@ -417,6 +487,16 @@ mcp.servers // [{ name, url, status, catalog, error, … }]
417
487
  const config = { model, tools: { ...myTools, ...mcp.tools } } // "<name>__<tool>"
418
488
  ```
419
489
 
490
+ `useMcpServers` takes the options of `useMcp` (`clientName`, `clientMetadataUrl`, `onLog`) plus
491
+ `persist`, `storageKey`, `autoConnect` and `connectTimeoutMs`. A server added with
492
+ `auth: 'oauth'` may carry its own `oauth: { redirectUrl, scope, clientName, clientMetadataUrl }`,
493
+ which wins over the hook-level values and is remembered with the list:
494
+
495
+ ```tsx
496
+ const mcp = useMcpServers({ clientMetadataUrl: 'https://my-app.example/oauth/client.json' })
497
+ await mcp.add({ name: 'docs', url, auth: 'oauth' }) // CIMD where the server supports it, DCR elsewhere
498
+ ```
499
+
420
500
  Servers connect in parallel, each with its own deadline; paginated tool lists
421
501
  are read to the end; tools a server marks read-only skip the "ask before
422
502
  changes" prompt. With hundreds of tools the core switches to **tool search**
@@ -447,6 +527,7 @@ use them standalone. The full guide: [docs/chat.md](docs/chat.md).
447
527
  | `<UsageBadge>` | Compact token readout. |
448
528
  | `<ApiKeyForm>` | BYOK key entry that writes to the encrypted vault. |
449
529
  | `<Composer>` | The minimal textarea + send/stop (kept for existing apps). |
530
+ | `<PipelineEditor>` and its parts | The pipeline editor - from `@dudko.dev/agent-web-react/pipeline`, styled by `pipeline.css`. See [Pipelines](#pipelines-an-editor-on-a-canvas). |
450
531
 
451
532
  ### Build your own UI
452
533
 
@@ -507,7 +588,14 @@ from one place.
507
588
  is read, a metadata address is refused). The MCP and authorization servers it
508
589
  talks to are started on loopback by [`e2e/servers.ts`](e2e/servers.ts), CORS
509
590
  headers included β€” so the test also pins the deployment requirement that the
510
- challenge header be exposed.
591
+ challenge header be exposed;
592
+ - the pipeline editor at `/pipeline/` ([`e2e/pipeline.spec.ts`](e2e/pipeline.spec.ts)): a node
593
+ added, dragged and connected with the mouse and with the keyboard alone, a three-node
594
+ pipeline run for real against the scripted endpoint (nodes light up in order, the route is
595
+ taken, the loop runs once, the result is shown), stop and a failing node, import / export /
596
+ copy as code, the definition surviving a reload, the vault shared with the demo, and a phone:
597
+ no sideways scroll, the inspector as a bottom sheet, one finger panning and two zooming the
598
+ canvas while the page stays put.
511
599
 
512
600
  These cover what unit tests structurally cannot: effect ordering across a real
513
601
  render, a real navigation away and back, and IndexedDB.
@@ -527,6 +615,9 @@ pnpm --filter demo dev
527
615
  The demo aliases `@dudko.dev/agent-web-react` to this package's built `dist`, so rebuild the
528
616
  library after changing its source.
529
617
 
618
+ The same Vite project has a second page, the pipeline editor (`apps/demo/pipeline/index.html`),
619
+ served at `/pipeline/`: <http://localhost:5173/pipeline/> in dev.
620
+
530
621
  ## License
531
622
 
532
623
  MIT Β© Siarhei Dudko
@@ -0,0 +1,147 @@
1
+ // src/util.ts
2
+ var errMessage = (err) => err instanceof Error ? err.message : String(err);
3
+
4
+ // src/components/icons.tsx
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ var base = (size = 16) => ({
7
+ width: size,
8
+ height: size,
9
+ viewBox: "0 0 24 24",
10
+ fill: "none",
11
+ stroke: "currentColor",
12
+ strokeWidth: 2,
13
+ strokeLinecap: "round",
14
+ strokeLinejoin: "round",
15
+ "aria-hidden": true
16
+ });
17
+ var SendIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
18
+ /* @__PURE__ */ jsx("path", { d: "M22 2 11 13" }),
19
+ /* @__PURE__ */ jsx("path", { d: "M22 2 15 22l-4-9-9-4Z" })
20
+ ] });
21
+ var StopIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2" }) });
22
+ var SpinnerIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className: ["awr-spin", className].filter(Boolean).join(" "), children: /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" }) });
23
+ var CheckIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" }) });
24
+ var AlertIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
25
+ /* @__PURE__ */ 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" }),
26
+ /* @__PURE__ */ jsx("path", { d: "M12 9v4" }),
27
+ /* @__PURE__ */ jsx("path", { d: "M12 17h.01" })
28
+ ] });
29
+ var ToolIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ 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" }) });
30
+ var ChevronIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" }) });
31
+ var ShieldIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("path", { d: "M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z" }) });
32
+ var BrainIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
33
+ /* @__PURE__ */ 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" }),
34
+ /* @__PURE__ */ 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" })
35
+ ] });
36
+ var BotIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
37
+ /* @__PURE__ */ jsx("rect", { x: "4", y: "8", width: "16", height: "12", rx: "3" }),
38
+ /* @__PURE__ */ jsx("path", { d: "M12 8V4" }),
39
+ /* @__PURE__ */ jsx("path", { d: "M9 14h.01M15 14h.01" })
40
+ ] });
41
+ var PlusIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("path", { d: "M12 5v14M5 12h14" }) });
42
+ var SlashIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
43
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "3" }),
44
+ /* @__PURE__ */ jsx("path", { d: "m15 7-6 10" })
45
+ ] });
46
+ var ClockIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
47
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
48
+ /* @__PURE__ */ jsx("path", { d: "M12 7v5l3 2" })
49
+ ] });
50
+ var MicIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
51
+ /* @__PURE__ */ jsx("rect", { x: "9", y: "3", width: "6", height: "11", rx: "3" }),
52
+ /* @__PURE__ */ jsx("path", { d: "M5 11a7 7 0 0 0 14 0M12 18v3" })
53
+ ] });
54
+ var BoltIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("path", { d: "M13 2 4 14h7l-1 8 9-12h-7Z" }) });
55
+ var EyeIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
56
+ /* @__PURE__ */ jsx("path", { d: "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" }),
57
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "3" })
58
+ ] });
59
+ var XIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("path", { d: "M18 6 6 18M6 6l12 12" }) });
60
+ var FileIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
61
+ /* @__PURE__ */ jsx("path", { d: "M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9Z" }),
62
+ /* @__PURE__ */ jsx("path", { d: "M14 3v6h6" })
63
+ ] });
64
+ var HistoryIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
65
+ /* @__PURE__ */ jsx("path", { d: "M3 12a9 9 0 1 0 3-6.7L3 8" }),
66
+ /* @__PURE__ */ jsx("path", { d: "M3 3v5h5M12 7v5l3 2" })
67
+ ] });
68
+ var BookIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
69
+ /* @__PURE__ */ jsx("path", { d: "M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2Z" }),
70
+ /* @__PURE__ */ jsx("path", { d: "M4 19V5M9 7h6" })
71
+ ] });
72
+ var GlobeIcon = ({ size, className }) => /* @__PURE__ */ jsxs("svg", { ...base(size), className, children: [
73
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "9" }),
74
+ /* @__PURE__ */ jsx("path", { d: "M3 12h18M12 3c3 3.2 3 14.8 0 18M12 3c-3 3.2-3 14.8 0 18" })
75
+ ] });
76
+ var DownloadIcon = ({ size, className }) => /* @__PURE__ */ jsx("svg", { ...base(size), className, children: /* @__PURE__ */ jsx("path", { d: "M12 3v12m-5-5 5 5 5-5M5 21h14" }) });
77
+
78
+ // src/components/format.ts
79
+ var previewValue = (value, max = 140) => {
80
+ if (value === void 0) return "";
81
+ let text;
82
+ if (typeof value === "string") text = value;
83
+ else {
84
+ try {
85
+ text = JSON.stringify(value);
86
+ } catch {
87
+ text = String(value);
88
+ }
89
+ }
90
+ text = text.replace(/\s+/g, " ").trim();
91
+ return text.length > max ? `${text.slice(0, max - 1)}\u2026` : text;
92
+ };
93
+ var formatTokens = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(n >= 1e4 ? 0 : 1)}k` : String(n);
94
+ var formatDuration = (ms) => {
95
+ if (ms < 1e3) return `${Math.round(ms)} ms`;
96
+ if (ms < 6e4) return `${(ms / 1e3).toFixed(ms < 1e4 ? 1 : 0)} s`;
97
+ const s = Math.round(ms / 1e3);
98
+ return `${Math.floor(s / 60)}m ${s % 60}s`;
99
+ };
100
+ var isDataImage = (v) => typeof v === "string" && /^data:image\/[\w.+-]+;base64,/.test(v);
101
+ var imagesInOutput = (output, depth = 0) => {
102
+ if (depth > 2 || output == null) return [];
103
+ if (isDataImage(output)) return [output];
104
+ if (Array.isArray(output)) return output.flatMap((v) => imagesInOutput(v, depth + 1));
105
+ if (typeof output === "object") {
106
+ const o = output;
107
+ if (o.type === "image" && typeof o.data === "string") {
108
+ const mime = typeof o.mimeType === "string" ? o.mimeType : "image/png";
109
+ return [o.data.startsWith("data:") ? o.data : `data:${mime};base64,${o.data}`];
110
+ }
111
+ for (const key of ["dataUrl", "url", "image"])
112
+ if (isDataImage(o[key])) return [o[key]];
113
+ if (depth < 2) return Object.values(o).flatMap((v) => imagesInOutput(v, depth + 1));
114
+ }
115
+ return [];
116
+ };
117
+
118
+ export {
119
+ errMessage,
120
+ SendIcon,
121
+ StopIcon,
122
+ SpinnerIcon,
123
+ CheckIcon,
124
+ AlertIcon,
125
+ ToolIcon,
126
+ ChevronIcon,
127
+ ShieldIcon,
128
+ BrainIcon,
129
+ BotIcon,
130
+ PlusIcon,
131
+ SlashIcon,
132
+ ClockIcon,
133
+ MicIcon,
134
+ BoltIcon,
135
+ EyeIcon,
136
+ XIcon,
137
+ FileIcon,
138
+ HistoryIcon,
139
+ BookIcon,
140
+ GlobeIcon,
141
+ DownloadIcon,
142
+ previewValue,
143
+ formatTokens,
144
+ formatDuration,
145
+ imagesInOutput
146
+ };
147
+ //# sourceMappingURL=chunk-LCJZEGB5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util.ts","../src/components/icons.tsx","../src/components/format.ts"],"sourcesContent":["/** Normalize any thrown value into a message string. */\nexport const errMessage = (err: unknown): string =>\n err instanceof Error ? err.message : String(err)\n","// Tiny inline SVG icons β€” no icon-font or image dependency. Each inherits the\n// current text color (`stroke=\"currentColor\"`) and takes an optional size.\n\nexport interface IconProps {\n size?: number\n className?: string\n}\n\nconst base = (size = 16) => ({\n width: size,\n height: size,\n viewBox: '0 0 24 24',\n fill: 'none',\n stroke: 'currentColor',\n strokeWidth: 2,\n strokeLinecap: 'round' as const,\n strokeLinejoin: 'round' as const,\n 'aria-hidden': true,\n})\n\nexport const SendIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M22 2 11 13\" />\n <path d=\"M22 2 15 22l-4-9-9-4Z\" />\n </svg>\n)\n\nexport const StopIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <rect x=\"6\" y=\"6\" width=\"12\" height=\"12\" rx=\"2\" />\n </svg>\n)\n\nexport const SpinnerIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={['awr-spin', className].filter(Boolean).join(' ')}>\n <path d=\"M21 12a9 9 0 1 1-6.219-8.56\" />\n </svg>\n)\n\nexport const CheckIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M20 6 9 17l-5-5\" />\n </svg>\n)\n\nexport const AlertIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <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\" />\n <path d=\"M12 9v4\" />\n <path d=\"M12 17h.01\" />\n </svg>\n)\n\nexport const ToolIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <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\" />\n </svg>\n)\n\nexport const ChevronIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"m6 9 6 6 6-6\" />\n </svg>\n)\n\nexport const ShieldIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z\" />\n </svg>\n)\n\nexport const BrainIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <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\" />\n <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\" />\n </svg>\n)\n\nexport const BotIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <rect x=\"4\" y=\"8\" width=\"16\" height=\"12\" rx=\"3\" />\n <path d=\"M12 8V4\" />\n <path d=\"M9 14h.01M15 14h.01\" />\n </svg>\n)\n\nexport const PlusIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M12 5v14M5 12h14\" />\n </svg>\n)\n\nexport const SlashIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"3\" />\n <path d=\"m15 7-6 10\" />\n </svg>\n)\n\nexport const ClockIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <circle cx=\"12\" cy=\"12\" r=\"9\" />\n <path d=\"M12 7v5l3 2\" />\n </svg>\n)\n\nexport const MicIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <rect x=\"9\" y=\"3\" width=\"6\" height=\"11\" rx=\"3\" />\n <path d=\"M5 11a7 7 0 0 0 14 0M12 18v3\" />\n </svg>\n)\n\nexport const BoltIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M13 2 4 14h7l-1 8 9-12h-7Z\" />\n </svg>\n)\n\nexport const EyeIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z\" />\n <circle cx=\"12\" cy=\"12\" r=\"3\" />\n </svg>\n)\n\nexport const XIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n)\n\nexport const FileIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9Z\" />\n <path d=\"M14 3v6h6\" />\n </svg>\n)\n\nexport const HistoryIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M3 12a9 9 0 1 0 3-6.7L3 8\" />\n <path d=\"M3 3v5h5M12 7v5l3 2\" />\n </svg>\n)\n\nexport const BookIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M4 5a2 2 0 0 1 2-2h13v16H6a2 2 0 0 0-2 2Z\" />\n <path d=\"M4 19V5M9 7h6\" />\n </svg>\n)\n\nexport const GlobeIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <circle cx=\"12\" cy=\"12\" r=\"9\" />\n <path d=\"M3 12h18M12 3c3 3.2 3 14.8 0 18M12 3c-3 3.2-3 14.8 0 18\" />\n </svg>\n)\n\nexport const DownloadIcon = ({ size, className }: IconProps) => (\n <svg {...base(size)} className={className}>\n <path d=\"M12 3v12m-5-5 5 5 5-5M5 21h14\" />\n </svg>\n)\n","/** Compact one-line preview of a tool input/output value, truncated. */\nexport const previewValue = (value: unknown, max = 140): string => {\n if (value === undefined) return ''\n let text: string\n if (typeof value === 'string') text = value\n else {\n try {\n text = JSON.stringify(value)\n } catch {\n text = String(value)\n }\n }\n text = text.replace(/\\s+/g, ' ').trim()\n return text.length > max ? `${text.slice(0, max - 1)}…` : text\n}\n\n/** 1234 β†’ \"1.2k\", 12345 β†’ \"12k\". */\nexport const formatTokens = (n: number): string =>\n n >= 1000 ? `${(n / 1000).toFixed(n >= 10_000 ? 0 : 1)}k` : String(n)\n\n/** 340 β†’ \"340 ms\", 4200 β†’ \"4.2 s\", 125_000 β†’ \"2m 5s\". */\nexport const formatDuration = (ms: number): string => {\n if (ms < 1000) return `${Math.round(ms)} ms`\n if (ms < 60_000) return `${(ms / 1000).toFixed(ms < 10_000 ? 1 : 0)} s`\n const s = Math.round(ms / 1000)\n return `${Math.floor(s / 60)}m ${s % 60}s`\n}\n\nconst isDataImage = (v: unknown): v is string =>\n typeof v === 'string' && /^data:image\\/[\\w.+-]+;base64,/.test(v)\n\n/**\n * Images inside a tool result, as data URLs: MCP image parts\n * (`{ type: 'image', data, mimeType }`), data-URL strings, and objects that\n * carry one (`{ dataUrl }` / `{ url: 'data:…' }`). Looks two levels deep.\n */\nexport const imagesInOutput = (output: unknown, depth = 0): string[] => {\n if (depth > 2 || output == null) return []\n if (isDataImage(output)) return [output]\n if (Array.isArray(output)) return output.flatMap((v) => imagesInOutput(v, depth + 1))\n if (typeof output === 'object') {\n const o = output as Record<string, unknown>\n if (o.type === 'image' && typeof o.data === 'string') {\n const mime = typeof o.mimeType === 'string' ? o.mimeType : 'image/png'\n return [o.data.startsWith('data:') ? o.data : `data:${mime};base64,${o.data}`]\n }\n for (const key of ['dataUrl', 'url', 'image'])\n if (isDataImage(o[key])) return [o[key] as string]\n if (depth < 2) return Object.values(o).flatMap((v) => imagesInOutput(v, depth + 1))\n }\n return []\n}\n"],"mappings":";AACO,IAAM,aAAa,CAAC,QACzB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;;;ACmB/C,SACE,KADF;AAbF,IAAM,OAAO,CAAC,OAAO,QAAQ;AAAA,EAC3B,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,eAAe;AACjB;AAEO,IAAM,WAAW,CAAC,EAAE,MAAM,UAAU,MACzC,qBAAC,SAAK,GAAG,KAAK,IAAI,GAAG,WACnB;AAAA,sBAAC,UAAK,GAAE,eAAc;AAAA,EACtB,oBAAC,UAAK,GAAE,yBAAwB;AAAA,GAClC;AAGK,IAAM,WAAW,CAAC,EAAE,MAAM,UAAU,MACzC,oBAAC,SAAK,GAAG,KAAK,IAAI,GAAG,WACnB,8BAAC,UAAK,GAAE,KAAI,GAAE,KAAI,OAAM,MAAK,QAAO,MAAK,IAAG,KAAI,GAClD;AAGK,IAAM,cAAc,CAAC,EAAE,MAAM,UAAU,MAC5C,oBAAC,SAAK,GAAG,KAAK,IAAI,GAAG,WAAW,CAAC,YAAY,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAC9E,8BAAC,UAAK,GAAE,+BAA8B,GACxC;AAGK,IAAM,YAAY,CAAC,EAAE,MAAM,UAAU,MAC1C,oBAAC,SAAK,GAAG,KAAK,IAAI,GAAG,WACnB,8BAAC,UAAK,GAAE,mBAAkB,GAC5B;AAGK,IAAM,YAAY,CAAC,EAAE,MAAM,UAAU,MAC1C,q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