@softr/sdk 0.0.93-alpha.0 → 0.0.93-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/action.d.ts +46 -1
- package/dist/action.js +38 -1
- package/dist/auth/server.js +1 -1
- package/dist/core/email.d.ts +52 -0
- package/dist/core/email.js +62 -0
- package/dist/core/step.d.ts +20 -0
- package/dist/core/step.js +48 -0
- package/dist/datasource/record.js +3 -12
- package/dist/default-error-overlay.d.ts +2 -2
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -4
- package/dist/mcp.d.ts +3 -16
- package/dist/mcp.js +18 -61
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +2 -2
- package/dist/server.d.ts +3 -1
- package/dist/server.js +3 -1
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +10 -8
- package/skills/softr-sdk/ai/SKILL.md +10 -10
- 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/email/SKILL.md +127 -0
- 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 +3 -1
- package/skills/softr-sdk/mcp/SKILL.md +1 -16
- 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 +10 -8
- package/dist/agent/agent-fns.d.ts +0 -30
- package/dist/agent/agent-fns.js +0 -215
- package/dist/agent/use-agent-chat.d.ts +0 -106
- package/dist/agent/use-agent-chat.js +0 -486
- package/skills/softr-sdk/agent-chat/SKILL.md +0 -110
package/dist/pwa.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
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():
|
|
26
|
+
declare function SoftrPwaHead(): react4.FunctionComponentElement<react4.FragmentProps>;
|
|
27
27
|
type PwaPlatform = "ios" | "android" | "desktop";
|
|
28
28
|
type PwaInstall = {
|
|
29
29
|
available: false;
|
package/dist/server.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { upload } from "./core/file-upload.js";
|
|
2
2
|
import { AiError, ai } from "./core/ai.js";
|
|
3
|
+
import { StepError, StepErrorCode } from "./core/step.js";
|
|
4
|
+
import { EmailError, EmailErrorCode, email } from "./core/email.js";
|
|
3
5
|
import { auth } from "./auth/server.js";
|
|
4
6
|
import { FieldChoice, RecordOption, RecordOptions } from "./core/options.js";
|
|
5
7
|
import { ds } from "./datasource/datasource.js";
|
|
6
8
|
import { workflow } from "./core/workflow.js";
|
|
7
9
|
import { integration } from "./core/integration.js";
|
|
8
10
|
import "@tanstack/react-start/server-only";
|
|
9
|
-
export { AiError, type FieldChoice, type RecordOption, type RecordOptions, ai, auth, ds, integration, upload, workflow };
|
|
11
|
+
export { AiError, EmailError, type EmailErrorCode, type FieldChoice, type RecordOption, type RecordOptions, StepError, type StepErrorCode, ai, auth, ds, email, integration, upload, workflow };
|
package/dist/server.js
CHANGED
|
@@ -4,6 +4,8 @@ import { auth } from "./auth/server.js";
|
|
|
4
4
|
import { workflow } from "./core/workflow.js";
|
|
5
5
|
import { integration } from "./core/integration.js";
|
|
6
6
|
import { AiError, ai } from "./core/ai.js";
|
|
7
|
+
import { StepError } from "./core/step.js";
|
|
8
|
+
import { EmailError, email } from "./core/email.js";
|
|
7
9
|
import "@tanstack/react-start/server-only";
|
|
8
10
|
|
|
9
|
-
export { AiError, ai, auth, ds, integration, upload, workflow };
|
|
11
|
+
export { AiError, EmailError, StepError, ai, auth, ds, email, integration, upload, workflow };
|
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.93-alpha.
|
|
12
|
+
library_version: 0.0.93-alpha.2
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
# Softr SDK core
|
|
@@ -22,6 +22,8 @@ metadata:
|
|
|
22
22
|
>
|
|
23
23
|
> **CRITICAL**: The app is already wired. `src/start.ts`, `src/router.tsx` and `src/routes/__root.tsx` register `softrAuthMiddleware` and resolve the session. Do not add a second registration of it. `softrMcpMiddleware` is the one thing an app adds to `src/start.ts` itself — load the `softr-sdk/mcp` sub-skill before doing so.
|
|
24
24
|
>
|
|
25
|
+
> **CRITICAL**: `email.send` lives on `@softr/sdk/server` and only runs inside a `createServerFn` handler. Use `defineEmailAction` from `@softr/sdk` to declare who may send it and the recipients it fixes. An email the app sends itself needs no workflow and no connected mail service. Load the `softr-sdk/email` sub-skill for the full pattern.
|
|
26
|
+
>
|
|
25
27
|
> **CRITICAL**: `ai.generate` and `ai.stream` live on `@softr/sdk/server` and only run inside a `createServerFn` handler. Use `defineAiAction` from `@softr/sdk` to declare the action with the model it runs on, an id copied from the `ai_list_models` tool. Softr runs the model on its own keys; never ask the user for an API key for the app's own AI feature. Load the `softr-sdk/ai` sub-skill for the full pattern.
|
|
26
28
|
>
|
|
27
29
|
> **CRITICAL**: `workflow.trigger` lives on `@softr/sdk/server` and only runs inside a `createServerFn` handler. Use `defineWorkflow` from `@softr/sdk` to declare the action, then pass it to `workflow.trigger`. Load the `softr-sdk/workflows` sub-skill for the full pattern.
|
|
@@ -32,8 +34,8 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
|
|
|
32
34
|
|
|
33
35
|
| Import | Runs | Holds |
|
|
34
36
|
| --- | --- | --- |
|
|
35
|
-
| `@softr/sdk` | Both | `defineQuery`, `defineMutation`, `defineAiAction`, `definePage`, `pageHead`, `defineVisibility`, `guardRoute`, `assertRouteAccess`, `isAuthorized`, `checkAccess`, `Audience`, `useCurrentUser`, `useUserTimezone`, `FormattedDate`, `FormattingScope`, `useFormatting`, `formatDate`, `formatDateTime`, `formatNumber`, `formatValue`, `formatField`, `fieldShape`, `registerSoftrFields`, `useOverrides`, `SoftrPwaHead`, `usePwaInstall`, `getSoftrContext`, `initialSoftrContext`, `softrAuthMiddleware`, the error predicates, and every type |
|
|
36
|
-
| `@softr/sdk/server` | Server only | `ds`, `auth`, `workflow`, `integration`, `ai` |
|
|
37
|
+
| `@softr/sdk` | Both | `defineQuery`, `defineMutation`, `defineEmailAction`, `defineAiAction`, `definePage`, `pageHead`, `defineVisibility`, `guardRoute`, `assertRouteAccess`, `isAuthorized`, `checkAccess`, `Audience`, `useCurrentUser`, `useUserTimezone`, `FormattedDate`, `FormattingScope`, `useFormatting`, `formatDate`, `formatDateTime`, `formatNumber`, `formatValue`, `formatField`, `fieldShape`, `registerSoftrFields`, `useOverrides`, `SoftrPwaHead`, `usePwaInstall`, `getSoftrContext`, `initialSoftrContext`, `softrAuthMiddleware`, the error predicates, and every type |
|
|
38
|
+
| `@softr/sdk/server` | Server only | `ds`, `auth`, `email`, `EmailError`, `workflow`, `integration`, `ai` |
|
|
37
39
|
| `@softr/sdk/client` | Browser only | `useFileUpload` |
|
|
38
40
|
| `@softr/sdk/vite` | Build | `softr()`, already in `vite.config.ts` |
|
|
39
41
|
|
|
@@ -47,12 +49,12 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
|
|
|
47
49
|
| Fetch records from a datasource | [record-queries/SKILL.md](./record-queries/SKILL.md) |
|
|
48
50
|
| Chart, aggregate or count records | [charts-and-metrics/SKILL.md](./charts-and-metrics/SKILL.md) |
|
|
49
51
|
| Create, update or delete a record | [record-mutations/SKILL.md](./record-mutations/SKILL.md) |
|
|
52
|
+
| Send an email from the app: a form that emails the owner, a confirmation, staff emailing a client | [email/SKILL.md](./email/SKILL.md) |
|
|
50
53
|
| Trigger a Softr workflow | [workflows/SKILL.md](./workflows/SKILL.md) |
|
|
51
54
|
| Sign a visitor in, out, or up | [auth/SKILL.md](./auth/SKILL.md) |
|
|
52
55
|
| Ask an AI model: a summary, an extraction from a document, a classification, a draft, a chat | [ai/SKILL.md](./ai/SKILL.md) |
|
|
53
|
-
| Call a connected third-party API (Slack, Stripe, Gmail, …), or an AI model on the user's own provider account | [integrations/SKILL.md](./integrations/SKILL.md) |
|
|
56
|
+
| Call a connected third-party API (Slack, Stripe, Gmail from the user's own mailbox, …), or an AI model on the user's own provider account | [integrations/SKILL.md](./integrations/SKILL.md) |
|
|
54
57
|
| Open the app to AI assistants over MCP | [mcp/SKILL.md](./mcp/SKILL.md) |
|
|
55
|
-
| Let visitors chat with a Softr agent | [agent-chat/SKILL.md](./agent-chat/SKILL.md) |
|
|
56
58
|
| Let visitors install the app on their home screen | [pwa/SKILL.md](./pwa/SKILL.md) |
|
|
57
59
|
| Show a date, a time or a number | [formatting/SKILL.md](./formatting/SKILL.md) |
|
|
58
60
|
|
|
@@ -77,6 +79,9 @@ Drawing a chart, a stat tile, or any aggregated number?
|
|
|
77
79
|
Submitting a form, editing a record, or deleting one?
|
|
78
80
|
load softr-sdk/record-mutations
|
|
79
81
|
|
|
82
|
+
Sending an email when a form is submitted or a button is pressed?
|
|
83
|
+
load softr-sdk/email — no workflow, no connected mail service
|
|
84
|
+
|
|
80
85
|
Triggering a Softr workflow from a button or form?
|
|
81
86
|
load softr-sdk/workflows
|
|
82
87
|
|
|
@@ -95,9 +100,6 @@ Running a model on the user's OWN provider account, because they chose that for
|
|
|
95
100
|
Opening the app to an AI assistant over MCP?
|
|
96
101
|
load softr-sdk/mcp
|
|
97
102
|
|
|
98
|
-
Adding a chat with one of the app's Softr agents, or a Connect button for the visitor's account it needs?
|
|
99
|
-
load softr-sdk/agent-chat
|
|
100
|
-
|
|
101
103
|
Adding an install button, or making the app installable?
|
|
102
104
|
load softr-sdk/pwa
|
|
103
105
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ai
|
|
3
3
|
description: >-
|
|
4
|
-
Run an AI model from the app on Softr's own keys, billed to the workspace's
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
Run an AI model from the app on Softr's own keys, billed to the workspace's AI
|
|
5
|
+
credits, with nothing to connect: defineAiAction from @softr/sdk declares the
|
|
6
|
+
action with the catalog model it runs on and its permissions; ai.generate from
|
|
7
|
+
@softr/sdk/server runs it with a system text, a prompt, an optional JSON
|
|
8
|
+
schema for an answer that is data, and optional files; ai.stream runs it for
|
|
9
|
+
an answer the user watches being written. Load this for a summary, an
|
|
10
|
+
extraction, a classification, a draft, or a chat the app asks a model for,
|
|
11
|
+
before you decide whether a feature runs on Softr AI or on the user's own
|
|
12
|
+
account, and before you change the model it runs on.
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 0.0.93-alpha.
|
|
16
|
+
library_version: 0.0.93-alpha.2
|
|
17
17
|
---
|
|
18
18
|
|
|
19
19
|
**Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` 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.93-alpha.
|
|
12
|
+
library_version: 0.0.93-alpha.2
|
|
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.93-alpha.
|
|
12
|
+
library_version: 0.0.93-alpha.2
|
|
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.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: email
|
|
3
|
+
description: >-
|
|
4
|
+
Send an email from the app itself, with nothing to connect and no workflow:
|
|
5
|
+
defineEmailAction from @softr/sdk declares who may send it and the fields it
|
|
6
|
+
fixes (to, cc, bcc, replyTo, and an optional senderId); email.send from
|
|
7
|
+
@softr/sdk/server sends one with a subject, a text or HTML body and optional
|
|
8
|
+
attachments, and throws an EmailError with a code when Softr does not send it.
|
|
9
|
+
Load this for a contact form that emails the owner, a confirmation to the
|
|
10
|
+
signed-in user, staff emailing a client, or any email the app sends while
|
|
11
|
+
handling what a person does in it.
|
|
12
|
+
metadata:
|
|
13
|
+
type: sub-skill
|
|
14
|
+
library: softr-sdk
|
|
15
|
+
library_version: 0.0.93-alpha.2
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
**Boundary.** `email` and `EmailError` live on `@softr/sdk/server` and run only inside a `createServerFn` handler — importing them into a component fails the build. `defineEmailAction` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
19
|
+
|
|
20
|
+
# Email
|
|
21
|
+
|
|
22
|
+
An app sends an email through an email action. Softr sends it from the app's email sender and bills the workspace's **workflow credits**, so there is no mail service to connect and no workflow to build. Use it for every email the app sends while it handles something a person does in it: a form submitted, a button pressed, a record saved through the app.
|
|
23
|
+
|
|
24
|
+
A workflow is still the answer for an email on a schedule ("every Monday") or on a change made outside the app (a record edited in the table): load `automate-with-workflows` for those. A connected Gmail or Outlook is the answer only when the user wants the email to come from their own mailbox, through the `integrations` sub-skill.
|
|
25
|
+
|
|
26
|
+
`defineEmailAction` missing from `@softr/sdk`? The app was built on an older version. Upgrade `@softr/sdk` to the latest version first, then write the action.
|
|
27
|
+
|
|
28
|
+
## Who can send it, and to whom
|
|
29
|
+
|
|
30
|
+
The action's `permissions` is its audience: everyone in it can send an email through it, directly, without the app's own code. The app's code is not a guard. Only what the declaration fixes holds whatever the caller sends.
|
|
31
|
+
|
|
32
|
+
- **Fix the recipients whenever the use case allows.** A contact form that emails the owner fixes `to` to the owner. "Email me this report" fixes `to` to `{LOGGED_IN_USER:EMAIL}`. Then nobody can send the app's email to anyone else.
|
|
33
|
+
- **When people pick the recipients, narrow the audience.** "Staff email a client" leaves `to` open and keeps the action to the staff group with `customGroups`. An action with open recipients for all signed-in users lets anyone who signs up send any email to anyone from the app's address, up to the workspace's credits. Build that only when the user asks for it, and tell them so in one line. An action open to visitors must fix `to`, `cc` or `bcc`: one that fixes none is not stored.
|
|
34
|
+
|
|
35
|
+
## The sender
|
|
36
|
+
|
|
37
|
+
Every email comes from the app's email sender, unless the action names one of the workspace's senders with `senderId`.
|
|
38
|
+
|
|
39
|
+
- Read the app's sender with `application_get` before you say where the emails come from, and name it. Never write "if no sender is set": read it. That tool shows the sign-in emails' default, an `@softr.app` address, when no sender is set. Emails from an email action then come from Softr's address instead: the workspace's name at `<workspaceId>@softr-email.com`, limited to 30 emails a day for the whole workspace, its workflows included. That address is for testing only. Say so in your closing message when no sender is set, and that the app needs its own sender before real users rely on its emails.
|
|
40
|
+
- When the app has no sender of its own, list the workspace's senders with `workspace_list_email_senders` and offer the confirmed ones by name: for this email (`senderId`, nothing else changes) or as the app's sender. Never pick one yourself.
|
|
41
|
+
- Changing the app's sender also changes the address its sign-in emails come from. Ask the user before you call `application_configure_email_sender`, and name both effects. A workspace whose plan has no custom senders is refused; then say that sending from their own address needs the Professional plan.
|
|
42
|
+
- Set `senderId` only when the user wants this email from a specific address, such as `billing@`. Pick it from `workspace_list_email_senders`, copied exactly. A sender the mail provider has not confirmed makes every send fail until it is confirmed. That confirmation is all an email action needs; the domain's DNS records (DKIM, Return-Path) are needed only before Studio lets the app pick the address as its own sender, and they help the emails stay out of spam.
|
|
43
|
+
|
|
44
|
+
## What it costs
|
|
45
|
+
|
|
46
|
+
Every email costs **5 workflow credits per recipient**, from the workspace's monthly workflow credits, which its workflows spend too. You do not know the workspace's plan, so never name one or count how many emails it covers. The plan and the closing message give the cost and where to watch it, for example: "Each submission emails you, at 5 workflow credits per email. Track them in Settings → Billing → Workflow usage, where this app has its own row."
|
|
47
|
+
|
|
48
|
+
Emails sent from the preview are real and charged, and the actions in the code reach the live app as soon as they are saved. Send at most one test email, and only when the user asks for one. Never send emails in a loop to try something out.
|
|
49
|
+
|
|
50
|
+
## Declare the action
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const notifyOwner = defineEmailAction({
|
|
54
|
+
id: 'notifyOwner',
|
|
55
|
+
to: ['owner@acme.com'],
|
|
56
|
+
permissions: { userGroupTypes: ['NON_LOGGED_IN_USERS', 'LOGGED_IN_USERS'] },
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const emailClient = defineEmailAction({
|
|
60
|
+
id: 'emailClient',
|
|
61
|
+
replyTo: '{LOGGED_IN_USER:EMAIL}',
|
|
62
|
+
permissions: { userGroupTypes: ['LOGGED_IN_USERS'], customGroups: ['<the staff group id>'] },
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- `id` is a name you choose, unique across the app.
|
|
67
|
+
- `to`, `cc`, `bcc`: arrays of addresses. Each one declared here replaces the call's, and declaring `to` also ignores the call's `cc` and `bcc`. An element may be a whole placeholder for the signed-in sender: `{LOGGED_IN_USER:EMAIL}`, or `{LOGGED_IN_USER:<field>}` for an email field of their user record. Never part of a string, never in the call.
|
|
68
|
+
- `replyTo`: an address or one such placeholder.
|
|
69
|
+
- `senderId`: one of the workspace's senders, as above. The call can never set the sender.
|
|
70
|
+
- `permissions`: who may send it, as for queries and mutations.
|
|
71
|
+
|
|
72
|
+
Write the object inline in `defineEmailAction`, every value a literal. A declaration that cannot be read is not stored, and the check reports it.
|
|
73
|
+
|
|
74
|
+
Declare one action per kind of email: the owner's notification and the client's confirmation are two actions, each with its own recipients and audience.
|
|
75
|
+
|
|
76
|
+
## Core pattern
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const submit = createServerFn({ method: 'POST' })
|
|
80
|
+
.validator(contactSchema)
|
|
81
|
+
.handler(async ({ data }) => {
|
|
82
|
+
const saved = await ds.create(saveSubmission, { data })
|
|
83
|
+
try {
|
|
84
|
+
await email.send(notifyOwner, {
|
|
85
|
+
subject: `New message from ${data.name}`,
|
|
86
|
+
body: renderSubmission(data), // the app's own HTML, with what the visitor typed escaped
|
|
87
|
+
replyTo: data.email,
|
|
88
|
+
idempotencyKey: `submission-${saved.id}`,
|
|
89
|
+
})
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof EmailError) return { saved: true, emailed: false, reason: error.message }
|
|
92
|
+
throw error
|
|
93
|
+
}
|
|
94
|
+
return { saved: true, emailed: true }
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`email.send(action, init)` takes:
|
|
99
|
+
|
|
100
|
+
- `subject` and `body`. Required. `body` is plain text or HTML. Escape what visitors typed before you put it into HTML.
|
|
101
|
+
- `to`, `cc`, `bcc`, `replyTo`: each used only where the action does not fix it, and `cc` and `bcc` never when it fixes `to`. Each entry is one address. At most 50 recipients per email.
|
|
102
|
+
- `attachments`: `{ name, url }` each, a file uploaded to this app (the Softr SDK `file-uploads` guidance); any other URL is refused with `INVALID_INPUT`. 10 MB in total.
|
|
103
|
+
- `idempotencyKey`: the same key sends once, however often the call is repeated. Pass one derived from what the email is about, such as the record it announces, so a retried request never sends twice. When nothing is saved first, the form makes one key per submission (`crypto.randomUUID()` when the person starts submitting), sends it with the request and reuses it when they retry. At most 128 characters. Left out, every call is a new email, so a retry after `TIMEOUT` or a double click sends twice.
|
|
104
|
+
|
|
105
|
+
It answers `{ messageId }` once the email is sent. The answer never lists the recipients.
|
|
106
|
+
|
|
107
|
+
## Failure modes
|
|
108
|
+
|
|
109
|
+
**Not handling `EmailError`.** `email.send` throws an `EmailError`, a `StepError` from `@softr/sdk/server`, with `status`, `code` and `message` when the email was not sent, and never retries by itself. Catch it, keep what the request already saved, and show the person a line they can act on: "Saved, but the email could not be sent." The codes:
|
|
110
|
+
|
|
111
|
+
| `code` | Meaning |
|
|
112
|
+
| --- | --- |
|
|
113
|
+
| `NOT_FOUND` | No such action, or the caller is not in its audience |
|
|
114
|
+
| `INVALID_INPUT` | No subject or body, an entry or placeholder that is not exactly one address, more than 50 recipients, an attachment that is not one of the app's uploads, or an idempotency key over 128 characters |
|
|
115
|
+
| `UNAVAILABLE` | Softr could not send it or could not be reached: no workflow credits left, Softr's address past its 30 emails today, an unconfirmed sender, or an outage |
|
|
116
|
+
| `TIMEOUT` | No answer in time. It may still have been sent: retry only with the same key |
|
|
117
|
+
| `RATE_LIMITED` | The app sent too often in the last minute or day. Tell the person to try again later |
|
|
118
|
+
|
|
119
|
+
**Letting a mistyped address reach Softr.** An address the person typed (the reply-to of a contact form, a client's email) that is not one address is refused with `INVALID_INPUT`, which reads as a vague failure. Check its format in the validator and tell them which field is wrong.
|
|
120
|
+
|
|
121
|
+
**Calling from client code.** `email` is server-only. Wrap the send in a `createServerFn` and call that from the form or the button.
|
|
122
|
+
|
|
123
|
+
**Taking recipients from the request when they could be fixed.** A `to` the browser sends is a `to` any caller can change. Fix it in the declaration, or read it on the server from the record the email is about.
|
|
124
|
+
|
|
125
|
+
**Placeholders in the call.** `{LOGGED_IN_USER:EMAIL}` is filled only in the declaration. In the call it is sent as written and fails.
|
|
126
|
+
|
|
127
|
+
**Building a workflow for an email the app sends itself.** A "Run custom workflow" trigger plus a "Send email" step does the same at more cost to the user: a workflow to keep published. Use the email action; keep workflows for schedules and table events.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 0.0.93-alpha.
|
|
10
|
+
library_version: 0.0.93-alpha.2
|
|
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.93-alpha.
|
|
10
|
+
library_version: 0.0.93-alpha.2
|
|
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.
|
|
@@ -16,6 +16,8 @@ metadata:
|
|
|
16
16
|
|
|
17
17
|
`integration.createFetcher` calls a third-party API through Softr's authenticated proxy. It adds the connected account's credentials automatically — you never set API keys or auth headers yourself. **Every call acts as that one account, whoever the visitor is**, so take what a call reaches, such as a customer or a channel, from the session or a record the server read, never from the arguments the browser sends.
|
|
18
18
|
|
|
19
|
+
An email the app sends is the `email` sub-skill, with nothing to connect. Send through a connected Gmail or Outlook only when the user wants the email to come from their own mailbox.
|
|
20
|
+
|
|
19
21
|
## Setup
|
|
20
22
|
|
|
21
23
|
```ts
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.93-alpha.
|
|
12
|
+
library_version: 0.0.93-alpha.2
|
|
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.
|
|
@@ -53,25 +53,10 @@ The list is the whole tool surface. Write it out:
|
|
|
53
53
|
|
|
54
54
|
- An action you leave out is invisible to the assistant, even where the app's pages use it freely.
|
|
55
55
|
- An action you list still obeys its own `permissions`. Listing it does not widen who may run it — the assistant runs as whoever signed in, with that user's groups.
|
|
56
|
-
- The assistant calls the action directly and skips server functions, so a row filter written in one does not apply. A listed read returns every row the user's data restrictions allow, and a listed update or delete takes any id that passes them. On a table whose rows belong to people, list an action only once a data restriction scopes the table to the user's own rows.
|
|
57
|
-
- A create on a table whose rows belong to a person gets its owner from `owner`, never from the assistant. See below.
|
|
58
56
|
- Two actions with the same `id` throw at startup. So does anything that is not a `defineQuery` or `defineMutation` value.
|
|
59
57
|
|
|
60
58
|
Reads first. Add a write only when the user asked for one, and name it back to them.
|
|
61
59
|
|
|
62
|
-
## The owner of a person's record
|
|
63
|
-
|
|
64
|
-
The assistant knows the caller's login, not their row in the people table. Left to fill an owner link, it writes the login id, which shows as a stray name, or anyone's row it likes. `owner` takes the field out of the tool and fills it with the caller's own row, found the way `auth.currentUserRow` finds it:
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
softrMcpMiddleware({
|
|
68
|
-
actions: [listRequests, requestTimeOff],
|
|
69
|
-
owner: { users: usersQuery, email: 'email', fields: { requestTimeOff: 'employee' } },
|
|
70
|
-
})
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
`fields` maps each create or update action id to its owner link. A caller with no row in the people table is refused, and nothing is created. On an update the field is only taken out, so nobody moves a record to someone else.
|
|
74
|
-
|
|
75
60
|
## The login round trip
|
|
76
61
|
|
|
77
62
|
Connecting starts with an approval page the app serves. Most people hit it signed out, and that page cannot sign anyone in. It sends them to the login page named in `softr.json` (`auth.routes.login.path`), with the approval page in the search param named there (`auth.routes.login.redirectParam`).
|
|
@@ -8,7 +8,7 @@ description: >-
|
|
|
8
8
|
metadata:
|
|
9
9
|
type: sub-skill
|
|
10
10
|
library: softr-sdk
|
|
11
|
-
library_version: 0.0.93-alpha.
|
|
11
|
+
library_version: 0.0.93-alpha.2
|
|
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.93-alpha.
|
|
12
|
+
library_version: 0.0.93-alpha.2
|
|
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.93-alpha.
|
|
12
|
+
library_version: 0.0.93-alpha.2
|
|
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.93-alpha.
|
|
12
|
+
library_version: 0.0.93-alpha.2
|
|
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.
|
|
@@ -18,6 +18,8 @@ metadata:
|
|
|
18
18
|
|
|
19
19
|
`workflow.trigger` fires a Softr workflow and waits for it to finish. It resolves to `void`.
|
|
20
20
|
|
|
21
|
+
An email the app sends itself, when a form is submitted or a button is pressed, needs no workflow: load the `email` sub-skill. Fire a workflow for what the workflow's own steps do, such as updating a CRM or posting to a connected service.
|
|
22
|
+
|
|
21
23
|
## Setup
|
|
22
24
|
|
|
23
25
|
```ts
|
|
@@ -31,15 +33,15 @@ import { workflow } from '@softr/sdk/server'
|
|
|
31
33
|
Every trigger needs a workflow action: which workflow, which trigger step, who may run it, and any data that is always sent. The workflow must have a **Run custom workflow** trigger — no other trigger type can be fired from app code.
|
|
32
34
|
|
|
33
35
|
```ts
|
|
34
|
-
const
|
|
35
|
-
id: '
|
|
36
|
+
const syncNewLead = defineWorkflow({
|
|
37
|
+
id: 'syncNewLead',
|
|
36
38
|
workflowId: 'c9d8e7f6-a5b4-4c3d-8e2f-1a0b9c8d7e6f',
|
|
37
39
|
triggerId: '926da496-749f-4006-999c-197d8a556122',
|
|
38
40
|
permissions: { userGroupTypes: ['LOGGED_IN_USERS'] },
|
|
39
41
|
body: {
|
|
40
42
|
email: '{LOGGED_IN_USER:EMAIL}', // resolved server-side from the signed-in user
|
|
41
43
|
name: '{LOGGED_IN_USER:NAME}',
|
|
42
|
-
|
|
44
|
+
source: 'website', // any hardcoded value — always sent, never overridden at runtime
|
|
43
45
|
},
|
|
44
46
|
})
|
|
45
47
|
```
|
|
@@ -70,7 +72,7 @@ These placeholders are resolved server-side when the workflow runs:
|
|
|
70
72
|
const runWorkflow = createServerFn({ method: 'POST' })
|
|
71
73
|
.validator(z.object({ message: z.string() }))
|
|
72
74
|
.handler(async ({ data }) => {
|
|
73
|
-
await workflow.trigger(
|
|
75
|
+
await workflow.trigger(syncNewLead, { message: data.message })
|
|
74
76
|
})
|
|
75
77
|
```
|
|
76
78
|
|
|
@@ -82,7 +84,7 @@ const runWorkflow = createServerFn({ method: 'POST' })
|
|
|
82
84
|
|
|
83
85
|
```ts
|
|
84
86
|
const run = createServerFn({ method: 'POST' }).handler(async () => {
|
|
85
|
-
await workflow.trigger(
|
|
87
|
+
await workflow.trigger(syncNewLead)
|
|
86
88
|
})
|
|
87
89
|
```
|
|
88
90
|
|
|
@@ -94,11 +96,11 @@ Omit the second argument when the action's `body` already carries everything the
|
|
|
94
96
|
|
|
95
97
|
```ts
|
|
96
98
|
// Wrong: calling from a click handler
|
|
97
|
-
<button onClick={() => workflow.trigger(
|
|
99
|
+
<button onClick={() => workflow.trigger(syncNewLead)}>Run</button>
|
|
98
100
|
|
|
99
101
|
// Correct: server function, called from the button
|
|
100
102
|
const run = createServerFn({ method: 'POST' }).handler(() =>
|
|
101
|
-
workflow.trigger(
|
|
103
|
+
workflow.trigger(syncNewLead),
|
|
102
104
|
)
|
|
103
105
|
// …
|
|
104
106
|
const submit = useServerFn(run)
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import * as _tanstack_react_start9 from "@tanstack/react-start";
|
|
3
|
-
|
|
4
|
-
//#region src/agent/agent-fns.d.ts
|
|
5
|
-
|
|
6
|
-
declare const agentSchema: z.ZodObject<{
|
|
7
|
-
id: z.ZodString;
|
|
8
|
-
title: z.ZodString;
|
|
9
|
-
avatar: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
10
|
-
thumbnail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
11
|
-
}, z.core.$strip>;
|
|
12
|
-
/** An agent the visitor may chat with. */
|
|
13
|
-
type Agent = z.infer<typeof agentSchema>;
|
|
14
|
-
/**
|
|
15
|
-
* The agents the visitor may chat with in this app. The builder attaches them
|
|
16
|
-
* in Studio, and each one's visibility settings decide who sees it.
|
|
17
|
-
*/
|
|
18
|
-
declare const listAgents: _tanstack_react_start9.OptionalFetcher<undefined, undefined, Promise<{
|
|
19
|
-
id: string;
|
|
20
|
-
title: string;
|
|
21
|
-
avatar?: string | null | undefined;
|
|
22
|
-
thumbnail?: string | null | undefined;
|
|
23
|
-
}[]>>;
|
|
24
|
-
/** One past chat with an agent. `title` is null until the agent names the chat. */
|
|
25
|
-
type AgentChatSummary = {
|
|
26
|
-
id: string;
|
|
27
|
-
title: string | null;
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
export { Agent, AgentChatSummary, listAgents };
|