@softr/sdk 0.0.89-alpha.2 → 0.0.89-alpha.4
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/agent/use-agent-chat.d.ts +5 -2
- package/dist/agent/use-agent-chat.js +19 -6
- package/dist/mcp.js +3 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +2 -2
- package/skills/softr-sdk/agent-chat/SKILL.md +11 -12
- 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
|
@@ -34,7 +34,10 @@ type AgentQuestion = {
|
|
|
34
34
|
}>;
|
|
35
35
|
multiSelect: boolean;
|
|
36
36
|
};
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* One piece of a message, in the order the agent produced it. A tool waiting for
|
|
39
|
+
* the visitor comes last, below the text that asks for it, until they answer.
|
|
40
|
+
*/
|
|
38
41
|
type AgentBlock = {
|
|
39
42
|
type: "text";
|
|
40
43
|
text: string;
|
|
@@ -74,7 +77,7 @@ type AgentChat = {
|
|
|
74
77
|
openChat: (chatId: string) => void;
|
|
75
78
|
/** The visitor's past chats with this agent. */
|
|
76
79
|
listChats: () => Promise<AgentChatSummary[]>;
|
|
77
|
-
/** Lets a tool waiting for approval run
|
|
80
|
+
/** Lets a tool waiting for approval run: once, for the rest of this chat, or for this agent from now on. */
|
|
78
81
|
approve: (toolCallId: string, scope?: "ONCE" | "SESSION" | "USER") => void;
|
|
79
82
|
reject: (toolCallId: string) => void;
|
|
80
83
|
/** Opens the sign-in for a tool's `integration` in a popup. Call it from a click, or the browser blocks the popup. */
|
|
@@ -262,11 +262,11 @@ function useAgentChat(agentId, options = {}) {
|
|
|
262
262
|
reset
|
|
263
263
|
]);
|
|
264
264
|
return {
|
|
265
|
-
messages: live === null ? messages : [...messages, {
|
|
265
|
+
messages: (live === null ? messages : [...messages, {
|
|
266
266
|
id: "live",
|
|
267
267
|
role: "assistant",
|
|
268
268
|
blocks: live
|
|
269
|
-
}],
|
|
269
|
+
}]).map(waitingLast),
|
|
270
270
|
status,
|
|
271
271
|
loading,
|
|
272
272
|
error,
|
|
@@ -281,6 +281,15 @@ function useAgentChat(agentId, options = {}) {
|
|
|
281
281
|
connect
|
|
282
282
|
};
|
|
283
283
|
}
|
|
284
|
+
const waitsForVisitor = (b) => b.type === "tool" && (b.status === "awaiting-approval" || b.status === "awaiting-connection" || b.status === "connecting");
|
|
285
|
+
function waitingLast(message) {
|
|
286
|
+
if (!message.blocks.some(waitsForVisitor)) return message;
|
|
287
|
+
const blocks = [...message.blocks.filter((b) => !waitsForVisitor(b)), ...message.blocks.filter(waitsForVisitor)];
|
|
288
|
+
return {
|
|
289
|
+
...message,
|
|
290
|
+
blocks
|
|
291
|
+
};
|
|
292
|
+
}
|
|
284
293
|
const CONNECT_TIMEOUT_MS = 5 * 6e4;
|
|
285
294
|
const CONNECT_RETRY_MS = 3e3;
|
|
286
295
|
function popupFeatures(width, height) {
|
|
@@ -449,18 +458,22 @@ function fromHistory(history) {
|
|
|
449
458
|
});
|
|
450
459
|
}
|
|
451
460
|
const CHAT_GONE_MESSAGE = "This chat is no longer available. Start a new one.";
|
|
452
|
-
const
|
|
461
|
+
const VISITOR = "visitor";
|
|
462
|
+
const chatKey = (agentId, userId) => `softr-code-app:agent-chat:${agentId}:${userId ?? VISITOR}`;
|
|
463
|
+
function chatStore(key) {
|
|
464
|
+
return key.endsWith(`:${VISITOR}`) ? sessionStorage : localStorage;
|
|
465
|
+
}
|
|
453
466
|
function savedChatId(key) {
|
|
454
467
|
try {
|
|
455
|
-
return
|
|
468
|
+
return chatStore(key).getItem(key);
|
|
456
469
|
} catch {
|
|
457
470
|
return null;
|
|
458
471
|
}
|
|
459
472
|
}
|
|
460
473
|
function saveChatId(key, chatId) {
|
|
461
474
|
try {
|
|
462
|
-
if (chatId)
|
|
463
|
-
else
|
|
475
|
+
if (chatId) chatStore(key).setItem(key, chatId);
|
|
476
|
+
else chatStore(key).removeItem(key);
|
|
464
477
|
} catch {}
|
|
465
478
|
}
|
|
466
479
|
async function failureMessage(res) {
|
package/dist/mcp.js
CHANGED
|
@@ -244,7 +244,8 @@ const WHOAMI = {
|
|
|
244
244
|
type: "object",
|
|
245
245
|
properties: {},
|
|
246
246
|
additionalProperties: false
|
|
247
|
-
}
|
|
247
|
+
},
|
|
248
|
+
annotations: { readOnlyHint: true }
|
|
248
249
|
};
|
|
249
250
|
/** How many records a read returns when the caller does not say. */
|
|
250
251
|
const DEFAULT_LIMIT = 20;
|
|
@@ -265,6 +266,7 @@ function describeTool(action) {
|
|
|
265
266
|
case "read": return {
|
|
266
267
|
name: action.id,
|
|
267
268
|
description: `Read records from "${action.id}". Returns the fields ${names.join(", ")}. Only records the signed-in user may see come back.`,
|
|
269
|
+
annotations: { readOnlyHint: true },
|
|
268
270
|
inputSchema: {
|
|
269
271
|
type: "object",
|
|
270
272
|
properties: {
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: core
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.89-alpha.
|
|
12
|
+
library_version: 0.0.89-alpha.4
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
# Softr SDK core
|
|
@@ -86,7 +86,7 @@ Calling a connected third-party API (Slack, Stripe, Gmail, Google Calendar, …)
|
|
|
86
86
|
Opening the app to an AI assistant over MCP?
|
|
87
87
|
load softr-sdk/mcp
|
|
88
88
|
|
|
89
|
-
Adding a chat with one of the app's Softr agents?
|
|
89
|
+
Adding a chat with one of the app's Softr agents, or a Connect button for the visitor's account it needs?
|
|
90
90
|
load softr-sdk/agent-chat
|
|
91
91
|
|
|
92
92
|
Adding an install button, or making the app installable?
|
|
@@ -3,14 +3,16 @@ name: agent-chat
|
|
|
3
3
|
description: >-
|
|
4
4
|
Let visitors chat with one of the app's Softr agents: listAgents() from
|
|
5
5
|
@softr/sdk gives the agents the visitor may use, and useAgentChat(agentId, {
|
|
6
|
-
record }) returns the messages, the reply as it streams, and
|
|
7
|
-
send, stop, approve and
|
|
6
|
+
record }) returns the messages, the reply as it streams, past chats, and
|
|
7
|
+
send, stop, approve, reject and connect, with no UI. Load it for an agent
|
|
8
|
+
chat panel, approving the agent's actions, or connecting the visitor's own
|
|
9
|
+
account (Gmail, Slack…) that a tool needs. Build the chat from the app's own
|
|
8
10
|
components. The agent acts on the app's data through the app's MCP, so
|
|
9
11
|
softrMcpMiddleware must list the actions it may use.
|
|
10
12
|
metadata:
|
|
11
13
|
type: sub-skill
|
|
12
14
|
library: softr-sdk
|
|
13
|
-
library_version: 0.0.89-alpha.
|
|
15
|
+
library_version: 0.0.89-alpha.4
|
|
14
16
|
---
|
|
15
17
|
|
|
16
18
|
**Boundary.** `listAgents` and `useAgentChat` live on `@softr/sdk`. `listAgents` runs in a route loader, `useAgentChat` in a component. Neither needs a route, server function or registration of its own. It chats as the signed-in visitor, or anonymously when no one is signed in.
|
|
@@ -56,13 +58,13 @@ function AgentPanel({ agentId, ticket }: { agentId: string; ticket: Ticket | nul
|
|
|
56
58
|
|
|
57
59
|
## What the hook returns
|
|
58
60
|
|
|
59
|
-
- `messages`: the whole chat, oldest first. While the agent answers, its reply is the last message and grows as it streams.
|
|
61
|
+
- `messages`: the whole chat, oldest first. While the agent answers, its reply is the last message and grows as it streams. A tool waiting for Approve or Connect comes last in its message, so render blocks in the order given.
|
|
60
62
|
- `status`: `thinking` until the first part of the reply arrives, `replying` until it ends, then `idle`. Show a typing hint while it's `thinking`.
|
|
61
63
|
- `loading`: `true` while a past chat loads. Show a spinner, not the empty-chat greeting.
|
|
62
64
|
- `error`: why the last request failed, or `null`.
|
|
63
65
|
- `send(text)`, `stop()`, `newChat()`.
|
|
64
|
-
- `listChats()` resolves to the visitor's past chats, `{ id, title }[]`, with `title` `null` until the agent names the chat. `openChat(id)` loads one. `chatId` is the open one, `null` for a new chat. The open chat is kept in the browser for each
|
|
65
|
-
- `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
|
|
66
|
+
- `listChats()` resolves to the visitor's past chats, `{ id, title }[]`, with `title` `null` until the agent names the chat. `openChat(id)` loads one. `chatId` is the open one, `null` for a new chat. The open chat is kept in the browser for each signed-in user, so the hook reopens it after a remount or a reload. A signed-out visitor keeps it only until the tab closes.
|
|
67
|
+
- `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 this agent from now on.
|
|
66
68
|
- `connect(toolCallId)` signs the visitor in to a tool's `integration` in a popup. Call it straight from the click, or the browser blocks the popup.
|
|
67
69
|
|
|
68
70
|
## Rendering a message
|
|
@@ -77,7 +79,7 @@ Each message has `role` (`user` or `assistant`) and `blocks`, in the order the a
|
|
|
77
79
|
| `question` | The questions with their options. One question with a single choice sends its label with `send` on click. Several questions, or `multiSelect`, collect the picks and show a Send button, enabled once each question has one. It sends one line per question, picked labels joined by ", ". |
|
|
78
80
|
| `error` | An error line inside the reply |
|
|
79
81
|
|
|
80
|
-
A `tool` with status `awaiting-approval` blocks the agent until the visitor answers.
|
|
82
|
+
A `tool` with status `awaiting-approval` blocks the agent until the visitor answers. Give it a split Approve button and a Reject button, as classic apps do. The button says "Approve once" (`approve(id)`), and its menu offers "Approve for this session" (`approve(id, 'SESSION')`) and "Approve for this agent" (`approve(id, 'USER')`). With only one Approve, the visitor has to approve the same action again on every call. The agent continues on its own after an approval.
|
|
81
83
|
|
|
82
84
|
A `tool` with status `awaiting-connection` needs the visitor's own `integration` account, such as their Gmail. Say "You need to connect to {integration} for this request. You'll only need to connect once.", with the name in readable case, and show a Connect button that calls `connect`. While it's `connecting`, show "Connecting…" and disable the button. The agent continues on its own once they're signed in. Any integration works the same way, so don't build one per integration.
|
|
83
85
|
|
|
@@ -92,8 +94,7 @@ Classic Softr apps ship a chat panel. Visitors expect the same from yours:
|
|
|
92
94
|
- Text renders as Markdown, tables included.
|
|
93
95
|
- The input says "Ask {agent title}…". Enter sends. Shift+Enter adds a line.
|
|
94
96
|
- A line under the input: "AI can make mistakes. Please double-check responses."
|
|
95
|
-
-
|
|
96
|
-
- Approve offers the three scopes: once, for this chat, always for this agent.
|
|
97
|
+
- An answered question stays locked.
|
|
97
98
|
- A tool's `input` is JSON. Show it readable: one `Label: value` line per field, with line breaks kept, never the raw JSON. Leave out `thought`, `input`, `error` or the duration when it's empty.
|
|
98
99
|
- A tool that needs the visitor's account shows a Connect button.
|
|
99
100
|
|
|
@@ -113,12 +114,10 @@ The agent reads and changes data through the app's own MCP, as the visitor who i
|
|
|
113
114
|
|
|
114
115
|
**Rendering only `text` blocks.** A tool waiting for approval never shows, and the agent waits forever. Render every block type.
|
|
115
116
|
|
|
116
|
-
**The hook inside a panel that unmounts when it closes.** Closing it stops a reply that is still coming. Call `useAgentChat` in the component that owns the open state, such as
|
|
117
|
+
**The hook inside a panel that unmounts when it closes.** Closing it stops a reply that is still coming. Call `useAgentChat` in the component that owns the open state, such as `AppLayout` in `src/routes/_app.tsx`, and pass `chat` into the panel. Keep the selected agent there too, or closing the panel resets it.
|
|
117
118
|
|
|
118
119
|
**An agent id written by hand.** The chat fails on the first message, and an agent hidden from the visitor still shows. Take the id from `listAgents`.
|
|
119
120
|
|
|
120
|
-
**Expecting the agent to change data with no MCP wired.** It answers but can't act. List the actions it needs in `softrMcpMiddleware`.
|
|
121
|
-
|
|
122
121
|
## References
|
|
123
122
|
|
|
124
123
|
- [mcp/SKILL.md](../mcp/SKILL.md): the actions the agent may call
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.89-alpha.
|
|
12
|
+
library_version: 0.0.89-alpha.4
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.89-alpha.
|
|
12
|
+
library_version: 0.0.89-alpha.4
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 0.0.89-alpha.
|
|
10
|
+
library_version: 0.0.89-alpha.4
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
**Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 0.0.89-alpha.
|
|
10
|
+
library_version: 0.0.89-alpha.4
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
**Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.89-alpha.
|
|
12
|
+
library_version: 0.0.89-alpha.4
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
|
|
@@ -8,7 +8,7 @@ description: >-
|
|
|
8
8
|
metadata:
|
|
9
9
|
type: sub-skill
|
|
10
10
|
library: softr-sdk
|
|
11
|
-
library_version: 0.0.89-alpha.
|
|
11
|
+
library_version: 0.0.89-alpha.4
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.89-alpha.
|
|
12
|
+
library_version: 0.0.89-alpha.4
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. The same holds for any helper that calls `ds`: declare it inside the handler. A function at module level that calls `ds` keeps the server-only import in the browser bundle, and every page stops loading until it moves. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.89-alpha.
|
|
12
|
+
library_version: 0.0.89-alpha.4
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.89-alpha.
|
|
12
|
+
library_version: 0.0.89-alpha.4
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.
|