@softr/sdk 0.0.87-alpha.0 → 0.0.87-alpha.2
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/dist/auth/isomorphic.d.ts +3 -2
- package/dist/auth/isomorphic.js +4 -1
- package/dist/auth/methods/authenticator.js +3 -3
- package/dist/auth/methods/code.js +1 -1
- package/dist/auth/methods/magicLink.js +1 -1
- package/dist/auth/methods/password.js +1 -1
- package/dist/auth/methods/passwordLink.js +1 -1
- package/dist/auth/methods/signup.js +1 -1
- package/dist/auth/methods/social.js +1 -1
- package/dist/auth/platform.js +1 -1
- package/dist/auth/session.js +8 -7
- package/dist/cookies.js +29 -3
- package/dist/default-error-overlay.d.ts +2 -2
- package/dist/embedding.js +33 -0
- package/dist/formatting.d.ts +3 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +3 -5
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +2 -2
- package/dist/route/route.js +1 -1
- package/dist/softr-config.schema.js +3 -1
- package/package.json +1 -1
- package/schema/softr.schema.json +5 -0
- package/skills/softr-sdk/SKILL.md +8 -7
- package/skills/softr-sdk/auth/SKILL.md +1 -1
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +1 -1
- package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
- package/skills/softr-sdk/formatting/SKILL.md +1 -1
- package/skills/softr-sdk/integrations/SKILL.md +1 -1
- package/skills/softr-sdk/mcp/SKILL.md +1 -1
- package/skills/softr-sdk/pwa/SKILL.md +1 -1
- package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
- package/skills/softr-sdk/record-queries/SKILL.md +1 -1
- package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
- package/dist/agent/agent-fns.d.ts +0 -12
- package/dist/agent/agent-fns.js +0 -148
- package/dist/agent/use-agent-chat.d.ts +0 -94
- package/dist/agent/use-agent-chat.js +0 -367
- package/skills/softr-sdk/agent-chat/SKILL.md +0 -103
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: agent-chat
|
|
3
|
-
description: >-
|
|
4
|
-
Let visitors chat with one of the app's Softr agents: useAgentChat(agentId,
|
|
5
|
-
{ record }) from @softr/sdk returns the messages, the reply as it streams,
|
|
6
|
-
and send, stop, approve and reject, with no UI. Build the chat from the app's
|
|
7
|
-
own components. The agent acts on the app's data through the app's MCP, so
|
|
8
|
-
softrMcpMiddleware must list the actions it may use.
|
|
9
|
-
metadata:
|
|
10
|
-
type: sub-skill
|
|
11
|
-
library: softr-sdk
|
|
12
|
-
library_version: 0.0.86
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
**Boundary.** `useAgentChat` lives on `@softr/sdk` and runs in a component. It needs no route, server function or registration of its own. It chats as the signed-in visitor, or anonymously when no one is signed in.
|
|
16
|
-
|
|
17
|
-
# Agent chat
|
|
18
|
-
|
|
19
|
-
A Softr agent is set up in Studio's Agents tab and attached to the app there. The app gives it a chat. There is no ready-made chat widget: the hook gives the state, and the app draws it with its own components.
|
|
20
|
-
|
|
21
|
-
## Setup
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import { useAgentChat } from '@softr/sdk'
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
The agent id is a string from Studio. Ask the builder for it if you don't have it, and write it as a literal. Never guess or invent one.
|
|
28
|
-
|
|
29
|
-
## Core pattern
|
|
30
|
-
|
|
31
|
-
```tsx
|
|
32
|
-
function AgentPanel({ ticket }: { ticket: Ticket | null }) {
|
|
33
|
-
const chat = useAgentChat('a1b2c3d4-...', {
|
|
34
|
-
record: ticket && { id: ticket.id, fields: { Title: ticket.title, Status: ticket.status } },
|
|
35
|
-
})
|
|
36
|
-
const [draft, setDraft] = useState('')
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<>
|
|
40
|
-
{chat.messages.map((message) => (
|
|
41
|
-
<Message key={message.id} message={message} onApprove={chat.approve} onReject={chat.reject} />
|
|
42
|
-
))}
|
|
43
|
-
{chat.error && <p role="alert">{chat.error.message}</p>}
|
|
44
|
-
<form onSubmit={(e) => { e.preventDefault(); chat.send(draft); setDraft('') }}>
|
|
45
|
-
<Textarea value={draft} onChange={(e) => setDraft(e.target.value)} />
|
|
46
|
-
{chat.status === 'idle'
|
|
47
|
-
? <Button type="submit">Send</Button>
|
|
48
|
-
: <Button type="button" onClick={chat.stop}>Stop</Button>}
|
|
49
|
-
</form>
|
|
50
|
-
</>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## What the hook returns
|
|
56
|
-
|
|
57
|
-
- `messages`: the whole chat, oldest first. While the agent answers, its reply is the last message and grows as it streams.
|
|
58
|
-
- `status`: `thinking` until the first part of the reply arrives, `replying` until it ends, then `idle`. Show a typing hint while it's `thinking`.
|
|
59
|
-
- `error`: why the last request failed, or `null`.
|
|
60
|
-
- `send(text)`, `stop()`, `newChat()`.
|
|
61
|
-
- `listChats()` resolves to the visitor's past chats, `{ id, title }[]`. `openChat(id)` loads one. `chatId` is the open one, `null` for a new chat.
|
|
62
|
-
- `approve(toolCallId, scope?)` and `reject(toolCallId)` answer a tool waiting for approval. `scope` is `ONCE` (default), `SESSION` for the rest of this chat, or `USER` for always.
|
|
63
|
-
|
|
64
|
-
## Rendering a message
|
|
65
|
-
|
|
66
|
-
Each message has `role` (`user` or `assistant`) and `blocks`, in the order the agent produced them. Render every block type:
|
|
67
|
-
|
|
68
|
-
| Block | Show it as |
|
|
69
|
-
| --- | --- |
|
|
70
|
-
| `text` | Markdown text |
|
|
71
|
-
| `tool` | One line: the tool `name` and its `status`. Collapse finished ones. |
|
|
72
|
-
| `todo` | A checklist of the agent's plan. It updates in place. |
|
|
73
|
-
| `question` | The questions with their options. A click on an option sends its label with `send`. |
|
|
74
|
-
| `error` | An error line inside the reply |
|
|
75
|
-
|
|
76
|
-
A `tool` with status `awaiting-approval` blocks the agent until the visitor answers. Show Approve and Reject buttons on it. The agent continues on its own after an approval.
|
|
77
|
-
|
|
78
|
-
A `tool` with status `awaiting-connection` needs the visitor to connect the `integration` first. Code apps can't do that yet. Say which integration the agent needs, and that the builder has to connect it for this agent in Studio.
|
|
79
|
-
|
|
80
|
-
## Context
|
|
81
|
-
|
|
82
|
-
`record` is the one record the visitor is looking at, so they can say "close this one". Pass it where a page shows one record, and `null` elsewhere. Use readable field names as keys. The agent reads them as they are.
|
|
83
|
-
|
|
84
|
-
The page title goes along on its own. Nothing else about the page does, so don't try to send whole lists.
|
|
85
|
-
|
|
86
|
-
## Letting the agent act on the app
|
|
87
|
-
|
|
88
|
-
The agent reads and changes data through the app's own MCP, as the visitor who is chatting. Their groups and each action's `permissions` apply. The actions it may use are the ones listed in `softrMcpMiddleware`. With no MCP wired, the agent can only talk. Load [mcp/SKILL.md](../mcp/SKILL.md) to wire it.
|
|
89
|
-
|
|
90
|
-
## Failure modes
|
|
91
|
-
|
|
92
|
-
**Building a chat without the hook.** Calling the agents service from the browser fails: only the app's server can sign the request in as the visitor. Use `useAgentChat`.
|
|
93
|
-
|
|
94
|
-
**Rendering only `text` blocks.** A tool waiting for approval never shows, and the agent waits forever. Render every block type.
|
|
95
|
-
|
|
96
|
-
**An invented agent id.** The chat fails on the first message. Use the id from Studio.
|
|
97
|
-
|
|
98
|
-
**Expecting the agent to change data with no MCP wired.** It answers but can't act. List the actions it needs in `softrMcpMiddleware`.
|
|
99
|
-
|
|
100
|
-
## References
|
|
101
|
-
|
|
102
|
-
- [mcp/SKILL.md](../mcp/SKILL.md): the actions the agent may call
|
|
103
|
-
- [current-user/SKILL.md](../current-user/SKILL.md): showing the chat to signed-in visitors only
|