@softr/sdk 0.0.89-alpha.1 → 0.0.89-alpha.3

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.
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import * as _tanstack_react_start0 from "@tanstack/react-start";
2
+ import * as _tanstack_react_start8 from "@tanstack/react-start";
3
3
 
4
4
  //#region src/agent/agent-fns.d.ts
5
5
 
@@ -15,7 +15,7 @@ type Agent = z.infer<typeof agentSchema>;
15
15
  * The agents the visitor may chat with in this app. The builder attaches them
16
16
  * in Studio, and each one's visibility settings decide who sees it.
17
17
  */
18
- declare const listAgents: _tanstack_react_start0.OptionalFetcher<undefined, undefined, Promise<{
18
+ declare const listAgents: _tanstack_react_start8.OptionalFetcher<undefined, undefined, Promise<{
19
19
  id: string;
20
20
  title: string;
21
21
  avatar?: string | null | undefined;
@@ -34,7 +34,10 @@ type AgentQuestion = {
34
34
  }>;
35
35
  multiSelect: boolean;
36
36
  };
37
- /** One piece of a message, in the order the agent produced it. */
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;
@@ -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 chatKey = (agentId, userId) => `softr-agent-chat:${agentId}:${userId ?? "visitor"}`;
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 localStorage.getItem(key);
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) localStorage.setItem(key, chatId);
463
- else localStorage.removeItem(key);
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) {
@@ -2,9 +2,9 @@ import { User } from "./user.js";
2
2
  import { Formatting } from "../formatting.js";
3
3
  import { Permissions } from "./permissions.js";
4
4
  import { SoftrContext } from "./context.js";
5
- import * as react6 from "react";
5
+ import * as react0 from "react";
6
6
  import { ReactNode } from "react";
7
- import * as _tanstack_react_start8 from "@tanstack/react-start";
7
+ import * as _tanstack_react_start0 from "@tanstack/react-start";
8
8
 
9
9
  //#region src/auth/isomorphic.d.ts
10
10
 
@@ -22,7 +22,7 @@ import * as _tanstack_react_start8 from "@tanstack/react-start";
22
22
  * requestMiddleware: [softrAuthMiddleware()],
23
23
  * }))
24
24
  */
25
- declare function softrAuthMiddleware(): _tanstack_react_start8.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start8.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start8.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start8.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start8.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
25
+ declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
26
26
  user: User | null;
27
27
  permissions: Permissions;
28
28
  formatting: Formatting;
@@ -36,7 +36,7 @@ declare function softrAuthMiddleware(): _tanstack_react_start8.RequestMiddleware
36
36
  * beforeLoad: async () => await getSoftrContext(),
37
37
  * })
38
38
  */
39
- declare const getSoftrContext: _tanstack_react_start8.OptionalFetcher<undefined, undefined, Promise<SoftrContext>>;
39
+ declare const getSoftrContext: _tanstack_react_start0.OptionalFetcher<undefined, undefined, Promise<SoftrContext>>;
40
40
  /**
41
41
  * The context to hand `createRouter`, before any request has resolved one.
42
42
  *
@@ -84,7 +84,7 @@ type AuthOptions = {
84
84
  * staleTime: 60_000,
85
85
  * })
86
86
  */
87
- declare const getAuthSettings: _tanstack_react_start8.OptionalFetcher<undefined, undefined, Promise<AuthOptions>>;
87
+ declare const getAuthSettings: _tanstack_react_start0.OptionalFetcher<undefined, undefined, Promise<AuthOptions>>;
88
88
  /**
89
89
  * Makes the auth options readable with {@link useAuthSettings} anywhere below.
90
90
  *
@@ -104,7 +104,7 @@ declare function AuthSettingsProvider({
104
104
  }: {
105
105
  value: AuthOptions;
106
106
  children?: ReactNode;
107
- }): react6.JSX.Element;
107
+ }): react0.JSX.Element;
108
108
  /**
109
109
  * Which ways in this app offers. Requires an {@link AuthSettingsProvider}
110
110
  * above it.
@@ -1,4 +1,4 @@
1
- import * as react5 from "react";
1
+ import * as react6 from "react";
2
2
 
3
3
  //#region src/default-error-overlay.d.ts
4
4
  type Props = {
@@ -8,6 +8,6 @@ type Props = {
8
8
  declare function DefaultErrorOverlay({
9
9
  error,
10
10
  reset
11
- }: Props): react5.JSX.Element;
11
+ }: Props): react6.JSX.Element;
12
12
  //#endregion
13
13
  export { DefaultErrorOverlay };
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatasourceAction } from "./action.js";
2
- import * as _tanstack_react_start15 from "@tanstack/react-start";
2
+ import * as _tanstack_react_start0 from "@tanstack/react-start";
3
3
 
4
4
  //#region src/mcp.d.ts
5
5
 
@@ -31,6 +31,6 @@ type SoftrMcpOptions = {
31
31
  * ],
32
32
  * }))
33
33
  */
34
- declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start15.RequestMiddlewareAfterServer<{}, undefined, undefined>;
34
+ declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>;
35
35
  //#endregion
36
36
  export { softrMcpMiddleware };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.89-alpha.1";
2
+ var version = "0.0.89-alpha.3";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react3 from "react";
1
+ import * as react4 from "react";
2
2
  import "@tanstack/react-start";
3
3
 
4
4
  //#region src/pwa.d.ts
@@ -23,7 +23,7 @@ import "@tanstack/react-start";
23
23
  * )
24
24
  * }
25
25
  */
26
- declare function SoftrPwaHead(): react3.FunctionComponentElement<react3.FragmentProps>;
26
+ declare function SoftrPwaHead(): react4.FunctionComponentElement<react4.FragmentProps>;
27
27
  type PwaPlatform = "ios" | "android" | "desktop";
28
28
  type PwaInstall = {
29
29
  available: false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.89-alpha.1",
3
+ "version": "0.0.89-alpha.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: core
11
11
  library: softr-sdk
12
- library_version: 0.0.89-alpha.1
12
+ library_version: 0.0.89-alpha.3
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 reject, with no UI. Build the chat from the app's own
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.1
15
+ library_version: 0.0.89-alpha.3
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,12 +58,12 @@ 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 visitor, so the hook reopens it after a remount or a reload.
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.
65
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 always.
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
 
@@ -92,8 +94,9 @@ 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
- - A question with one choice sends on click. One with `multiSelect` or several questions sends once all are answered. An answered question stays locked.
97
+ - An answered question stays locked.
96
98
  - Approve offers the three scopes: once, for this chat, always for this agent.
99
+ - 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.
97
100
  - A tool that needs the visitor's account shows a Connect button.
98
101
 
99
102
  ## Context
@@ -112,12 +115,10 @@ The agent reads and changes data through the app's own MCP, as the visitor who i
112
115
 
113
116
  **Rendering only `text` blocks.** A tool waiting for approval never shows, and the agent waits forever. Render every block type.
114
117
 
115
- **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 the layout, and pass `chat` into the panel. Keep the selected agent there too, or closing the panel resets it.
118
+ **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.
116
119
 
117
120
  **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`.
118
121
 
119
- **Expecting the agent to change data with no MCP wired.** It answers but can't act. List the actions it needs in `softrMcpMiddleware`.
120
-
121
122
  ## References
122
123
 
123
124
  - [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.1
12
+ library_version: 0.0.89-alpha.3
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.1
12
+ library_version: 0.0.89-alpha.3
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.
@@ -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.1
12
+ library_version: 0.0.89-alpha.3
13
13
  ---
14
14
 
15
15
  # The current user
@@ -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.1
10
+ library_version: 0.0.89-alpha.3
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.
@@ -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.1
11
+ library_version: 0.0.89-alpha.3
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -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.1
10
+ library_version: 0.0.89-alpha.3
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.1
12
+ library_version: 0.0.89-alpha.3
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.
@@ -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.1
12
+ library_version: 0.0.89-alpha.3
13
13
  ---
14
14
 
15
15
  # Installing the app
@@ -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.1
11
+ library_version: 0.0.89-alpha.3
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.1
12
+ library_version: 0.0.89-alpha.3
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.1
12
+ library_version: 0.0.89-alpha.3
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` 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.1
12
+ library_version: 0.0.89-alpha.3
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.1
12
+ library_version: 0.0.89-alpha.3
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.