@ui-sdk/svelte 0.1.0-beta.13 → 0.1.0-beta.14

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/docs/agents.md CHANGED
@@ -479,7 +479,7 @@ Use these definitions when setting up your agent's tools. Route each tool call t
479
479
 
480
480
  What the tools return comes from the page, so it can include text your users wrote, like a name in a table row. Their descriptions tell the model to treat it as data. Before an agent changes something that matters, have a person confirm it with [Permissions](./agents.md#permissions).
481
481
 
482
- For a browser that supports WebMCP, [register the tools with the browser](./agents.md#webmcp).
482
+ When your model runs on your server, [send the calls to the page](./agents.md#run-the-model-on-your-server) and return the results. For a browser that supports WebMCP, [register the tools with the browser](./agents.md#webmcp).
483
483
 
484
484
  ## Your Own Components
485
485
 
@@ -492,6 +492,7 @@ The snapshot reads the primitive's `controlled` state keys. If none are declared
492
492
  - [Permissions](./agents.md#permissions): approve, refuse, or cancel an agent's changes.
493
493
  - [Observe Changes](./agents.md#observe-changes): keep the agent up to date with what the person changed.
494
494
  - [History and Undo](./agents.md#history-and-undo): record changes, undo them, and preview suggestions.
495
+ - [Run the Model on Your Server](./agents.md#run-the-model-on-your-server): keep the model on your server and run the tools in the browser.
495
496
  - [WebMCP](./agents.md#webmcp): make the tools available to a browser agent.
496
497
  - [Reference](./agents.md#reference): look up options, methods, and return values.
497
498
 
@@ -1421,6 +1422,167 @@ await staged.revert()
1421
1422
  To point at a suggested control, use `elementOf(ref)` from [Observe](./core.md#observe) with one of the refs in `staged.applied`.
1422
1423
 
1423
1424
 
1425
+ # Run the Model on Your Server
1426
+
1427
+ Keep the model and its keys on your server while the agent works with the page.
1428
+
1429
+ The bridge you created in [Get Started](./agents.md#get-started) reads and changes the components on the page, so it runs in the browser. The model can still run on your server, next to your API keys, usage limits, and other tools. Each time the model calls `snapshot`, `act`, or `query`, the call goes to the page, the bridge runs it, and the result goes back to the model.
1430
+
1431
+ This page uses the [AI SDK](https://ai-sdk.dev), where a tool without `execute` on the server is run by the browser. The examples use React.
1432
+
1433
+ ## Declare the Tools on the Server
1434
+
1435
+ Pass `agentTools` to `streamText` as tools without `execute`:
1436
+
1437
+ ```ts title="app/api/chat/route.ts"
1438
+ import { convertToModelMessages, jsonSchema, streamText, tool } from "ai"
1439
+ import { agentTools } from "@ui-sdk/react/agent"
1440
+
1441
+ const tools = Object.fromEntries(
1442
+ agentTools.map(({ name, description, inputSchema }) => [
1443
+ name,
1444
+ tool({ description, inputSchema: jsonSchema(inputSchema) }),
1445
+ ])
1446
+ )
1447
+
1448
+ async function POST(request: Request) {
1449
+ const { messages } = await request.json()
1450
+ const result = streamText({
1451
+ model: "anthropic/claude-sonnet-5.5",
1452
+ messages: await convertToModelMessages(messages),
1453
+ tools,
1454
+ })
1455
+ return result.toUIMessageStreamResponse()
1456
+ }
1457
+
1458
+ export { POST }
1459
+ ```
1460
+
1461
+ The model sees the same names, descriptions, and input schemas as any other agent. When it calls one, the response streams the call to the browser instead of running it on the server.
1462
+
1463
+ ## Run the Calls in the Browser
1464
+
1465
+ In the chat component, run each call on `agent` and add its result. The form sends what the person types, and each message shows its text:
1466
+
1467
+ ```tsx title="chat.tsx"
1468
+ import { useState } from "react"
1469
+ import { useChat } from "@ai-sdk/react"
1470
+ import { lastAssistantMessageIsCompleteWithToolCalls } from "ai"
1471
+ import { agent } from "./agent"
1472
+
1473
+ function Chat() {
1474
+ const [input, setInput] = useState("")
1475
+ const { messages, sendMessage, addToolOutput } = useChat({
1476
+ sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
1477
+ async onToolCall({ toolCall }) {
1478
+ const tool = toolCall.toolName as "snapshot" | "act" | "query"
1479
+ const output = await agent[tool](toolCall.input as never)
1480
+ addToolOutput({ tool, toolCallId: toolCall.toolCallId, output })
1481
+ },
1482
+ })
1483
+
1484
+ return (
1485
+ <form
1486
+ onSubmit={(event) => {
1487
+ event.preventDefault()
1488
+ sendMessage({ text: input })
1489
+ setInput("")
1490
+ }}
1491
+ >
1492
+ {messages.map((message) => (
1493
+ <p key={message.id}>
1494
+ {message.parts
1495
+ .map((part) => (part.type === "text" ? part.text : ""))
1496
+ .join("")}
1497
+ </p>
1498
+ ))}
1499
+ <input value={input} onChange={(event) => setInput(event.target.value)} />
1500
+ </form>
1501
+ )
1502
+ }
1503
+
1504
+ export { Chat }
1505
+ ```
1506
+
1507
+ `sendAutomaticallyWhen` sends the results back once every call in the message has one, and the model continues from there. Ask it to set a field and it calls `act`, the field changes on the page, and the model gets the steps it ran and every field's value.
1508
+
1509
+ The results are plain objects, so they travel as JSON without changes. A step that fails comes back in the result with `ok: false` and the reason, so the model can try again.
1510
+
1511
+ ## Refs Between Calls
1512
+
1513
+ A ref from `snapshot` stays with its component while it's on the page, including across re-renders. If the component is gone, the step fails and lists what's on the page now. Take a new snapshot after you reorder or rename components, since two components with the same kind, label, and row text can trade refs when they come back.
1514
+
1515
+ ## Stopping a Turn
1516
+
1517
+ A step that needs a person waits for your [`allow`](./agents.md#ask-first) callback, and later calls wait behind it. When the person stops the chat, pass a `signal` to `act` so that wait ends too. Here's `chat.tsx` again with one `AbortController` per turn and a **Stop** button:
1518
+
1519
+ ```tsx title="chat.tsx" {1,8-9,13-18,27,40-48}
1520
+ import { useRef, useState } from "react"
1521
+ import { useChat } from "@ai-sdk/react"
1522
+ import { lastAssistantMessageIsCompleteWithToolCalls } from "ai"
1523
+ import { agent } from "./agent"
1524
+
1525
+ function Chat() {
1526
+ const [input, setInput] = useState("")
1527
+ const turn = useRef(new AbortController())
1528
+ const { messages, sendMessage, addToolOutput, stop } = useChat({
1529
+ sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
1530
+ async onToolCall({ toolCall }) {
1531
+ const tool = toolCall.toolName as "snapshot" | "act" | "query"
1532
+ const output =
1533
+ tool === "act"
1534
+ ? await agent.act(toolCall.input as never, {
1535
+ signal: turn.current.signal,
1536
+ })
1537
+ : await agent[tool](toolCall.input as never)
1538
+ addToolOutput({ tool, toolCallId: toolCall.toolCallId, output })
1539
+ },
1540
+ })
1541
+
1542
+ return (
1543
+ <form
1544
+ onSubmit={(event) => {
1545
+ event.preventDefault()
1546
+ turn.current = new AbortController()
1547
+ sendMessage({ text: input })
1548
+ setInput("")
1549
+ }}
1550
+ >
1551
+ {messages.map((message) => (
1552
+ <p key={message.id}>
1553
+ {message.parts
1554
+ .map((part) => (part.type === "text" ? part.text : ""))
1555
+ .join("")}
1556
+ </p>
1557
+ ))}
1558
+ <input value={input} onChange={(event) => setInput(event.target.value)} />
1559
+ <button
1560
+ type="button"
1561
+ onClick={() => {
1562
+ turn.current.abort()
1563
+ stop()
1564
+ }}
1565
+ >
1566
+ Stop
1567
+ </button>
1568
+ </form>
1569
+ )
1570
+ }
1571
+
1572
+ export { Chat }
1573
+ ```
1574
+
1575
+ **Stop** aborts the turn's signal and stops the chat. The step that was waiting fails as cancelled, the steps after it don't run, and the `signal` passed to `allow` aborts so you can close your prompt. The result still goes back with the next message, so the model knows what didn't happen.
1576
+
1577
+ Without a signal, the step fails once `timeout` passes, 5 minutes by default.
1578
+
1579
+ ## Next Steps
1580
+
1581
+ - [Permissions](./agents.md#permissions): approve, refuse, or ask the person before a change.
1582
+ - [Observe Changes](./agents.md#observe-changes): tell the model what the person changed between turns.
1583
+ - [Reference](./agents.md#reference): look up what each tool returns.
1584
+
1585
+
1424
1586
  # WebMCP
1425
1587
 
1426
1588
  Let the agent built into a browser read and use your components.
@@ -1545,6 +1707,8 @@ const result = await agent.act({
1545
1707
  })
1546
1708
  ```
1547
1709
 
1710
+ Pass `{ signal }` as a second argument to stop it early. When the signal aborts, a step waiting on `allow` fails as cancelled, and the steps after it don't run.
1711
+
1548
1712
  ### Steps
1549
1713
 
1550
1714
  Each step is an `AgentStep`:
@@ -418,7 +418,7 @@ An `action` on a Close part runs before it closes the dialog. Return a Promise t
418
418
 
419
419
  Choose Delete Project, then Delete. The first attempt fails so you can try again. While Deleting… is shown, Cancel and Escape leave the dialog open. A successful retry closes it.
420
420
 
421
- While the action runs, its button stays focusable and gets `data-pending`, `aria-busy`, and `aria-disabled`. Other Close parts and dismissals cannot close the dialog until it settles. `onDismissAttempt` reports refused dismissals; a controller can still close it.
421
+ While the action runs, its button stays focusable and gets `data-pending`, `aria-busy`, and `aria-disabled`. Other Close parts get `aria-disabled` and `data-disabled`, and neither they nor dismissals can close the dialog until it settles. `onDismissAttempt` reports refused dismissals; a controller can still close it.
422
422
 
423
423
  The root's `pendingAnnouncement` sets what screen readers hear after a second of waiting. The error clears on the next attempt or when the dialog opens again. The action also receives `{ source }` after its event argument; [Changes After an Await](./button.md#changes-after-an-await) explains when to use it.
424
424
 
@@ -636,6 +636,7 @@ Each part has a `data-slot`, such as `alert-dialog-content`, and shows its state
636
636
  ### AlertDialogClose
637
637
  `[data-slot="alert-dialog-close"]`
638
638
 
639
+ - `data-disabled`
639
640
  - `data-pending`: Present on a Close part while its action runs.
640
641
 
641
642
  ## API Reference
@@ -1065,6 +1065,7 @@ Each part has a `data-slot`, such as `dialog-content`, and shows its state throu
1065
1065
  ### DialogClose
1066
1066
  `[data-slot="dialog-close"]`
1067
1067
 
1068
+ - `data-disabled`
1068
1069
  - `data-pending`: Present on a Close part while its action runs.
1069
1070
 
1070
1071
  ## API Reference
@@ -808,6 +808,7 @@ Leave the content's `translate` and the backdrop's opacity to the drawer. You ca
808
808
  ### DrawerClose
809
809
  `[data-slot="drawer-close"]`
810
810
 
811
+ - `data-disabled`
811
812
  - `data-pending`: Present on a Close part while its action runs.
812
813
 
813
814
  ### DrawerOutlet
@@ -459,6 +459,7 @@ Touch screens have no hover, so a tap follows the link without opening the card.
459
459
  **Keyboard**
460
460
 
461
461
  - Keyboard focus on the link opens the card after the delay.
462
+ - Keyboard focus on a link the pointer opened keeps the card open when the pointer leaves.
462
463
  - Escape closes the card and leaves focus on the link.
463
464
  - Enter follows the link.
464
465
 
@@ -87,7 +87,7 @@ Import the parts and put them together:
87
87
 
88
88
  ## Forms
89
89
 
90
- An ordinary form can save a value and then close the popover. Focus starts on the first field and returns to the trigger when the task finishes. A form with `method="dialog"` closes on submission and returns its submit button's value; the [row editor](#triggers-outside-the-popover) shows that version.
90
+ An ordinary form can save a value and then close the popover. Focus starts on the first field and returns to the trigger when the task finishes. A form with `method="dialog"` closes on submission and returns its submit button's value; the [row editor](#triggers-outside-the-popover) shows that version. Inside another form, pass `container` so the popover's form doesn't nest in it.
91
91
 
92
92
  ```svelte title="form.svelte"
93
93
  <script lang="ts">
@@ -1982,6 +1982,7 @@ Searching, with a search field in the list:
1982
1982
  - Opening focuses the search field and highlights the selected item.
1983
1983
  - The search field is a combobox that controls the listbox in the list.
1984
1984
  - Typing filters the list and highlights the first match.
1985
+ - A field whose onChange renders the filtered list at once still highlights the first match. React only.
1985
1986
  - Typing never jumps by first letter: the characters go into the field.
1986
1987
  - Arrow keys move the highlight while focus stays in the field.
1987
1988
  - Home and End are the field's, so the highlight stays.
@@ -623,7 +623,7 @@ When each tab is a route, render [links](#links) and derive the controlled value
623
623
 
624
624
  ## Scroll into View
625
625
 
626
- If the list scrolls, selecting a tab through a controller or the URL scrolls it into view inside that list. Pointer and arrow-key selection focus the tab, so the browser reveals it as part of focusing it.
626
+ If the list scrolls, selecting a tab scrolls it into view inside that list, whether you click it, reach it with an arrow key, or select it through a controller or the URL.
627
627
 
628
628
  ## Custom Rendering
629
629
 
@@ -1122,6 +1122,7 @@ Every line below is an automated test.
1122
1122
  **Opening**
1123
1123
 
1124
1124
  - Typing a trigger opens the list with every item.
1125
+ - A field controlled through onChange keeps the typed trigger and opens the list. React only.
1125
1126
  - Typing after the trigger filters the list.
1126
1127
  - Text an input method commits filters the list.
1127
1128
  - Queries match Unicode letters and ignore accents.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui-sdk/svelte",
3
- "version": "0.1.0-beta.13",
3
+ "version": "0.1.0-beta.14",
4
4
  "description": "UI SDK for Svelte.",
5
5
  "keywords": [
6
6
  "svelte",
@@ -381,7 +381,7 @@
381
381
  ],
382
382
  "peerDependencies": {
383
383
  "svelte": ">=5.33",
384
- "@ui-sdk/core": "^0.1.0-beta.13"
384
+ "@ui-sdk/core": "^0.1.0-beta.14"
385
385
  },
386
386
  "devDependencies": {
387
387
  "@sveltejs/package": "^2.5.8",
@@ -393,7 +393,7 @@
393
393
  "typescript": "~5.9.3",
394
394
  "vite": "^8.3.3",
395
395
  "vitest": "^5.0.3",
396
- "@ui-sdk/core": "0.1.0-beta.13"
396
+ "@ui-sdk/core": "0.1.0-beta.14"
397
397
  },
398
398
  "scripts": {
399
399
  "build": "node ../../scripts/build/build-svelte-package.mjs",