@softr/sdk 0.0.81 → 0.0.83-alpha.0
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 +21 -18
- package/dist/action.js +12 -26
- package/dist/client.d.ts +1 -2
- package/dist/client.js +1 -2
- package/dist/core/ai.d.ts +76 -0
- package/dist/core/ai.js +64 -0
- package/dist/core/file-upload.d.ts +2 -6
- package/dist/core/file-upload.js +0 -4
- package/dist/core/use-file-upload.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/package.json +1 -3
- package/skills/softr-sdk/SKILL.md +13 -9
- package/skills/softr-sdk/ai/SKILL.md +168 -0
- 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 +8 -9
- 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/comments/comments.d.ts +0 -168
- package/dist/comments/comments.js +0 -413
- package/dist/comments/use-comment-composer.d.ts +0 -46
- package/dist/comments/use-comment-composer.js +0 -134
- package/skills/softr-sdk/comments/SKILL.md +0 -178
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ai
|
|
3
|
+
description: >-
|
|
4
|
+
Run an AI model from the app on Softr's own keys, billed to the workspace's
|
|
5
|
+
AI credits, with nothing to connect: defineAiAction from @softr/sdk declares
|
|
6
|
+
the action with the catalog model it runs on and its permissions;
|
|
7
|
+
ai.generate from @softr/sdk/server runs it with a system text, a prompt, an
|
|
8
|
+
optional JSON schema for an answer that is data, and optional files;
|
|
9
|
+
ai.stream runs it for an answer the user watches being written. Load this
|
|
10
|
+
for a summary, an extraction, a classification, a draft, or a chat the app
|
|
11
|
+
asks a model for, before you decide whether a feature runs on Softr AI
|
|
12
|
+
or on the user's own account, and before you change the model it runs on.
|
|
13
|
+
metadata:
|
|
14
|
+
type: sub-skill
|
|
15
|
+
library: softr-sdk
|
|
16
|
+
library_version: 0.0.79-alpha.0
|
|
17
|
+
---
|
|
18
|
+
|
|
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.
|
|
20
|
+
|
|
21
|
+
# AI
|
|
22
|
+
|
|
23
|
+
An app asks a model through an AI action. Softr runs the call on its own provider keys and bills the workspace's AI credits, so there is no key to ask the user for and nothing to connect. This is the default for every AI feature of the app's own — a summary of a record, fields extracted from a document, a classification, a draft, a chat. The other path is the user's own provider account, through a connected integration: the `integrations` sub-skill. An app can hold both: each feature carries its own choice in its code.
|
|
24
|
+
|
|
25
|
+
## Decide who runs it first
|
|
26
|
+
|
|
27
|
+
Never choose silently between Softr AI and the user's own account. Decide for each AI feature, before you write its code, in this order:
|
|
28
|
+
|
|
29
|
+
1. The user said who runs it: follow it. "My OpenAI key" or "our Anthropic account", with exactly one integration of that type in `integration_list`: use that one, without asking. A new key of a provider they named — they asked for a new one, or the workspace holds none of that type — is one `requestinput` of type `integration` for that type: its card connects one. A connected key runs the feature; a skipped request means Softr AI, and you say so. Several keys of that type, or "my own key" with no provider: ask (step 4). A provider or a model named without "my" or "our" ("use Claude", "summarise with GPT") is a model preference on Softr AI, not a reason to ask.
|
|
30
|
+
2. The app already has AI features: follow the choice they made, and say so in one line.
|
|
31
|
+
3. `integration_list` shows no `OPEN_AI`, `ANTHROPIC_AI` or `GEMINI_AI` integration: use Softr AI, and say so in one line. Call the tool; do not assume the answer.
|
|
32
|
+
4. Otherwise ask with one `requestinput` of type `aiProvider`. Its card lists every key the workspace holds and every provider to connect, unfiltered. The answer is Softr AI, or the integration with its id and type: follow it, even when it is another provider than the one the user named. A declined request means Softr AI: use it, and say so in one line.
|
|
33
|
+
|
|
34
|
+
Never ask who runs a feature, or which key, with the `question` tool: its free-text answer invites the user to type a key into the chat.
|
|
35
|
+
|
|
36
|
+
Ask at most once per turn. A turn that builds several AI features sends one request, and its `feature` names every one of them in the user's words: "Deal summary and lead tagging". It holds the names only, never the provider, the key or how the feature runs, because the card asks exactly that: "Product chat", not "Product chat, using an OpenAI key".
|
|
37
|
+
|
|
38
|
+
An own-account answer leaves this skill: the call goes through `defineIntegration`, as the `integrations` sub-skill describes.
|
|
39
|
+
|
|
40
|
+
## Choose the model
|
|
41
|
+
|
|
42
|
+
The model is chosen when the app is built and frozen in its code. Before you declare an action, read Softr's catalog with the `ai_list_models` tool: the most recent models of each provider. Each entry carries the `id` the action names, the `provider`, `bestFor`, what to pick it for, `reads`, what it reads beside text, and `reasoning`, whether it thinks before it answers. (`providerModelId` is for the own-account path of the `integrations` sub-skill, never for `defineAiAction`.)
|
|
43
|
+
|
|
44
|
+
- by default — a chat, an assistant, a summary, a briefing, a draft: a mid-tier model, `anthropic`'s newest one between its cheapest and strongest. When the user named another provider, that provider's mid-tier model;
|
|
45
|
+
- an extraction or a classification: the cheapest model whose `reads` covers what it is given — an image or a PDF needs `IMAGE`;
|
|
46
|
+
- the strongest model listed only when the user asks for more quality.
|
|
47
|
+
|
|
48
|
+
Copy the `id` exactly from the tool's answer. An id outside the catalog is refused when the action is saved, and a model spelled from memory, or taken from an example, never is in it.
|
|
49
|
+
|
|
50
|
+
## Changing it later
|
|
51
|
+
|
|
52
|
+
A model change asked in chat ("use a cheaper model", "try Gemini") edits the `model` of the feature's action, or, on the user's own account, the `providerModelId` its call sends. Read `ai_list_models` again and copy the new id. It never sends an `aiProvider` request. On the user's own account the new model is one of that account's provider: a model of another provider, or a switch to the user's own key, changes who runs it, so follow step 1 of the order above.
|
|
53
|
+
|
|
54
|
+
## Say it
|
|
55
|
+
|
|
56
|
+
The plan and the closing message give one line per AI feature built or changed: who runs it, its model, what it bills — Softr AI uses the workspace's AI credits, the user's own key is billed by its provider — and that the user can ask to switch the model or to use their own OpenAI, Anthropic or Gemini key. For example: "Deal summary runs on Softr AI with <the model> and uses your workspace's AI credits. Ask me to switch the model or to use your own OpenAI, Anthropic or Gemini key."
|
|
57
|
+
|
|
58
|
+
## Declare the action
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const summarizeDeal = defineAiAction({
|
|
62
|
+
id: 'summarizeDeal',
|
|
63
|
+
model: '<an id from ai_list_models>',
|
|
64
|
+
permissions: { userGroupTypes: ['LOGGED_IN_USERS'] },
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Write the object inline in `defineAiAction`. Passing it through a variable widens the types.
|
|
69
|
+
|
|
70
|
+
**Every call spends the workspace's credits.** Keep the audience to `['LOGGED_IN_USERS']`, narrowed with `customGroups` where the feature is for some users only. Open an AI action to visitors only when a public page really needs it, and say so to the user: anyone on the internet can then bill the workspace.
|
|
71
|
+
|
|
72
|
+
Declare one action per feature — the summary and the extraction are two actions, each with its own `id`, its own model and its own audience.
|
|
73
|
+
|
|
74
|
+
## Core pattern: an answer the server reads
|
|
75
|
+
|
|
76
|
+
`ai.generate(action, init)` runs the action and answers when the model is done. `init` takes:
|
|
77
|
+
|
|
78
|
+
- `prompt` — what the model is asked, with the facts it is given. Required.
|
|
79
|
+
- `system` — what the model is and the rules it answers under.
|
|
80
|
+
- `schema` — a JSON schema the answer has to match. With it the model is asked for JSON only, and the answer comes back parsed in `json` as well as written in `text`.
|
|
81
|
+
- `files` — documents and images the model reads, each as `{ url, mimeType? }`: an `https` URL Softr may fetch, one of the app's own uploads as a rule.
|
|
82
|
+
- `maxOutputTokens` — a cap on the answer's length. Softr caps it further.
|
|
83
|
+
- `messages` — the earlier turns of a conversation, oldest first, each `{ role: 'user' | 'assistant', content }`. The prompt is the newest turn. Leave out for a one-shot call.
|
|
84
|
+
- `reasoning` — `'low'`, `'medium'` or `'high'`: how hard a reasoning model thinks before it answers. The catalog says which models reason; the others ignore it. Leave out for the provider's default.
|
|
85
|
+
- `temperature` — 0 to 1: how varied the answer is. `0` for an extraction or a classification, around `0.7` for a draft. A low default when left out.
|
|
86
|
+
|
|
87
|
+
The answer is `{ text, json, usage, model }`: `text` as the model wrote it, `json` parsed when a schema was given and the model kept to it, `null` otherwise.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
const summarize = createServerFn({ method: 'POST' })
|
|
91
|
+
.validator(z.object({ recordId: z.string() }))
|
|
92
|
+
.handler(async ({ data }) => {
|
|
93
|
+
const deal = await ds.get(dealQuery, { id: data.recordId })
|
|
94
|
+
if (deal === null) throw new Error('This deal no longer exists')
|
|
95
|
+
const facts = [`Name: ${fieldText(deal.fields.name)}`, `Stage: ${fieldText(deal.fields.stage)}`].join('\n')
|
|
96
|
+
const answer = await ai.generate(summarizeDeal, {
|
|
97
|
+
system: 'You brief a sales team. Use only the facts given; say what is missing rather than invent it.',
|
|
98
|
+
prompt: facts,
|
|
99
|
+
maxOutputTokens: 800,
|
|
100
|
+
})
|
|
101
|
+
return answer.text
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Extraction: an answer that is data
|
|
106
|
+
|
|
107
|
+
A document dropped on the app, fields pulled out of it, a record created — the model reads the file and answers in the shape the record needs. Give it the schema and the file; validate the parsed answer before writing it, since a model may stray from the shape.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
const InvoiceFields = z.object({ vendor: z.string(), total: z.number(), issuedOn: z.string() })
|
|
111
|
+
|
|
112
|
+
const extractInvoice = createServerFn({ method: 'POST' })
|
|
113
|
+
.validator(z.object({ fileUrl: z.string().url() }))
|
|
114
|
+
.handler(async ({ data }) => {
|
|
115
|
+
const answer = await ai.generate(readInvoice, {
|
|
116
|
+
system: 'Read the invoice and answer with its fields. Dates as YYYY-MM-DD, amounts as numbers.',
|
|
117
|
+
prompt: 'Extract the vendor, the total and the issue date.',
|
|
118
|
+
schema: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: { vendor: { type: 'string' }, total: { type: 'number' }, issuedOn: { type: 'string' } },
|
|
121
|
+
required: ['vendor', 'total', 'issuedOn'],
|
|
122
|
+
},
|
|
123
|
+
files: [{ url: data.fileUrl, mimeType: 'application/pdf' }],
|
|
124
|
+
})
|
|
125
|
+
const parsed = InvoiceFields.safeParse(answer.json)
|
|
126
|
+
if (!parsed.success) throw new Error('The invoice could not be read. Try a clearer scan.')
|
|
127
|
+
return ds.create(createInvoice, { data: parsed.data })
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The file's URL comes from the app's own upload: load the Softr SDK `file-uploads` guidance for that half. `readInvoice` names a model whose `bestFor` reads PDF documents.
|
|
132
|
+
|
|
133
|
+
## Streaming: an answer the user watches being written
|
|
134
|
+
|
|
135
|
+
A chat, an assistant, a long draft shown as it is typed — never buffer these: the user would watch a blank panel until the last token. A chat box the user types into is always this case, never `ai.generate`. `ai.stream(action, init)` takes the same `init` and answers with a `Response` whose body is a stream of Server-Sent Events. Hand it to the browser from the server function, unchanged:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const draftReply = createServerFn({ method: 'POST' })
|
|
139
|
+
.validator(z.object({ prompt: z.string() }))
|
|
140
|
+
.handler(async ({ data }) => {
|
|
141
|
+
const res = await ai.stream(draftAction, { system: 'You write replies for a support team.', prompt: data.prompt })
|
|
142
|
+
return new Response(res.body, { headers: { 'Content-Type': 'text/event-stream' } })
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Each event is one JSON object on a `data:` line:
|
|
147
|
+
|
|
148
|
+
- `{ "text": "..." }` — the next piece of the answer; append it.
|
|
149
|
+
- `{ "done": true, "usage": { "inputTokens", "outputTokens" }, "model": "..." }` — the answer is complete.
|
|
150
|
+
- `{ "error": "..." }` — in place of `done`, when the call ended before its answer: show the message.
|
|
151
|
+
|
|
152
|
+
On the client, call the server function's URL with `fetch`, read `response.body` with a stream reader, split on blank lines, and parse the JSON after `data:`. A conversation sends its earlier turns in `messages`; the app keeps them, the model holds nothing between calls.
|
|
153
|
+
|
|
154
|
+
## Failure modes
|
|
155
|
+
|
|
156
|
+
**Calling from client code.** `ai` is server-only. Importing it into a component or calling it outside a `createServerFn` handler fails the build or has no request context to act on.
|
|
157
|
+
|
|
158
|
+
**Spelling a model id.** `model` is copied from `ai_list_models`, never written from memory. An id outside the catalog fails the save of the action, so the app cannot be published with it.
|
|
159
|
+
|
|
160
|
+
**No credits left.** `ai.generate` and `ai.stream` throw an `AiError` whose `status` is `402` when the workspace has no AI credits. Show its message to the user; the workspace owner tops the credits up in Softr. Any other refusal carries its status and reason the same way.
|
|
161
|
+
|
|
162
|
+
**Trusting `json` without checking it.** A model may stray from the schema; `json` is then `null`, or a shape close to the one asked. Validate it with `zod` before writing it to a record, and keep `text` as the fallback the user can read.
|
|
163
|
+
|
|
164
|
+
**Buffering a chat.** A chat built on `ai.generate` shows nothing until the whole reply is done, and the user reads "replies appear all at once" in your closing message. A chat streams.
|
|
165
|
+
|
|
166
|
+
**Reading a streamed body with `res.json()`.** The body of `ai.stream` is an event stream, not one JSON document. Return `res.body` in a `Response` or read it with a stream reader.
|
|
167
|
+
|
|
168
|
+
**Asking for the user's API key.** An AI feature of the app's own needs none. Only when the user chose their own provider account for the feature does the call go through a connected integration — load the `integrations` sub-skill then.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.82
|
|
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.
|
|
12
|
+
library_version: 0.0.82
|
|
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.
|
|
10
|
+
library_version: 0.0.82
|
|
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.
|
|
10
|
+
library_version: 0.0.82
|
|
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.
|
|
@@ -127,9 +127,11 @@ Do not add an `Authorization` key to `headers` — Softr injects the integration
|
|
|
127
127
|
|
|
128
128
|
## Calling an AI model
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
**This is the path for the user's own provider account only.** An AI feature of the app's own — a summary, an extraction, a chat — runs on Softr's keys through an AI action, with nothing to connect and no key to ask for: load the `ai` sub-skill for it. Call a model through an integration only when the user chose their own OpenAI, Anthropic or Gemini account for the feature, in the prompt or when asked, and had it connected.
|
|
131
|
+
|
|
132
|
+
**The model id comes from `ai_list_models`, never from memory.** Each entry of that list carries `providerModelId`, the id the provider's own API accepts, and `provider`: `anthropic` for an `ANTHROPIC_AI` integration, `openai` for `OPEN_AI`, `google_ai` for `GEMINI_AI`. Pick an entry of the integration's provider as the `ai` sub-skill's "Choose the model" says, and send its `providerModelId`. An id spelled from memory (`claude-3-5-…`, `gpt-4o`) names a model that no longer answers, and the error only shows up when the button is pressed.
|
|
133
|
+
|
|
134
|
+
An AI integration is called like any other. For `ANTHROPIC_AI`, the action is `POST` on
|
|
133
135
|
`https://api.anthropic.com/v1/messages`, the request carries the `anthropic-version` header and a body of
|
|
134
136
|
`model`, `max_tokens`, `system` and `messages`, and the answer's text is in `content[].text`:
|
|
135
137
|
|
|
@@ -146,7 +148,7 @@ const claude = integration.createFetcher(askClaude)
|
|
|
146
148
|
const res = await claude({
|
|
147
149
|
headers: { 'Content-Type': 'application/json', 'anthropic-version': '2023-06-01' },
|
|
148
150
|
body: JSON.stringify({
|
|
149
|
-
model: '
|
|
151
|
+
model: '<providerModelId of an anthropic entry of ai_list_models>',
|
|
150
152
|
max_tokens: 1024,
|
|
151
153
|
system: 'You write a short briefing for a sales team. Use only the facts given.',
|
|
152
154
|
messages: [{ role: 'user', content: facts }],
|
|
@@ -157,10 +159,7 @@ const body = (await res.json()) as { content: Array<{ type: string; text?: strin
|
|
|
157
159
|
const text = body.content.flatMap((block) => (block.type === 'text' && block.text ? [block.text] : [])).join('')
|
|
158
160
|
```
|
|
159
161
|
|
|
160
|
-
|
|
161
|
-
(`claude-3-5-…`, `claude-sonnet-4-…`) names a model that no longer answers, and the error only shows up when
|
|
162
|
-
the button is pressed. `claude-opus-5-5` is the current default; `claude-sonnet-5-5` is the cheaper one for a
|
|
163
|
-
short summary.
|
|
162
|
+
For `OPEN_AI`, the action is `POST` on `https://api.openai.com/v1/chat/completions` with a body of `model` and `messages` (the system text as the first message, role `system`); the answer's text is in `choices[0].message.content`. For `GEMINI_AI`, the action is `POST` on `https://generativelanguage.googleapis.com/v1beta/models/<providerModelId>:generateContent` with a body of `contents` (`[{ role: 'user', parts: [{ text }] }]`) and an optional `systemInstruction`; the answer's text is in `candidates[0].content.parts[].text`. Read the answer defensively: a refusal or an empty answer leaves the text out.
|
|
164
163
|
|
|
165
164
|
## Base URLs by integration type
|
|
166
165
|
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.82
|
|
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.
|
|
11
|
+
library_version: 0.0.82
|
|
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.
|
|
12
|
+
library_version: 0.0.82
|
|
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.
|
|
12
|
+
library_version: 0.0.82
|
|
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.
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { CommentsAction } from "../action.js";
|
|
2
|
-
|
|
3
|
-
//#region src/comments/comments.d.ts
|
|
4
|
-
/** A person picked in the composer, and where their `@name` sits in the text. */
|
|
5
|
-
type CommentMention = {
|
|
6
|
-
name: string;
|
|
7
|
-
email: string;
|
|
8
|
-
start: number;
|
|
9
|
-
end: number;
|
|
10
|
-
};
|
|
11
|
-
type CommentAttachmentInput = {
|
|
12
|
-
url: string;
|
|
13
|
-
filename: string;
|
|
14
|
-
type?: string | null;
|
|
15
|
-
};
|
|
16
|
-
type CommentView = {
|
|
17
|
-
id: string;
|
|
18
|
-
/** The body as safe HTML. Render it with `dangerouslySetInnerHTML`, never as text. */
|
|
19
|
-
bodyHtml: string;
|
|
20
|
-
attachments: Array<{
|
|
21
|
-
url: string;
|
|
22
|
-
filename: string;
|
|
23
|
-
type: string | null;
|
|
24
|
-
}>;
|
|
25
|
-
author: {
|
|
26
|
-
name: string;
|
|
27
|
-
avatar: string | null;
|
|
28
|
-
isDeactivated: boolean;
|
|
29
|
-
};
|
|
30
|
-
/** ISO 8601. */
|
|
31
|
-
createdAt: string;
|
|
32
|
-
canDelete: boolean;
|
|
33
|
-
canEdit: boolean;
|
|
34
|
-
edited: boolean;
|
|
35
|
-
/** The body as the visitor typed it, to fill an edit box. `null` unless `canEdit`. */
|
|
36
|
-
source: {
|
|
37
|
-
text: string;
|
|
38
|
-
mentions: Array<CommentMention>;
|
|
39
|
-
} | null;
|
|
40
|
-
reactions: Array<{
|
|
41
|
-
emoji: string;
|
|
42
|
-
label: string;
|
|
43
|
-
count: number;
|
|
44
|
-
isSelected: boolean;
|
|
45
|
-
}>;
|
|
46
|
-
};
|
|
47
|
-
type CommentThread = {
|
|
48
|
-
canPost: boolean;
|
|
49
|
-
allowMentions: boolean;
|
|
50
|
-
allowAttachments: boolean;
|
|
51
|
-
notificationsEnabled: boolean;
|
|
52
|
-
quickReactions: ReadonlyArray<{
|
|
53
|
-
emoji: string;
|
|
54
|
-
label: string;
|
|
55
|
-
}>;
|
|
56
|
-
total: number;
|
|
57
|
-
/** Pass it back as `offset` for the next page. `null` on the last page. */
|
|
58
|
-
nextOffset: number | null;
|
|
59
|
-
items: Array<CommentView>;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* The thread on one record, or `null` when this visitor cannot see comments on it. Render nothing
|
|
63
|
-
* for `null`.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* const thread = await comments.list(orderComments, { recordId: order.id })
|
|
67
|
-
*/
|
|
68
|
-
declare function listComments(action: CommentsAction, options: {
|
|
69
|
-
recordId: string;
|
|
70
|
-
offset?: number | null;
|
|
71
|
-
limit?: number;
|
|
72
|
-
}): Promise<CommentThread | null>;
|
|
73
|
-
/**
|
|
74
|
-
* Posts a comment. `body` is the text the visitor typed. `mentions` are the people they picked,
|
|
75
|
-
* each with the range of its `@name` in `body`. A range that no longer reads as `@name` is posted as
|
|
76
|
-
* plain text. `attachments` are the files `useFileUpload` finished uploading.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* await comments.create(orderComments, { recordId, body: "Hey @Ann", mentions, attachments })
|
|
80
|
-
*/
|
|
81
|
-
declare function createComment(action: CommentsAction, options: {
|
|
82
|
-
recordId: string;
|
|
83
|
-
body: string;
|
|
84
|
-
mentions: ReadonlyArray<CommentMention>;
|
|
85
|
-
attachments?: ReadonlyArray<CommentAttachmentInput>;
|
|
86
|
-
}): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* Saves an edit. Offer it only where the comment's `canEdit` is true, and fill the edit box from its
|
|
89
|
-
* `source`. `attachments` is the full list after the edit: the files kept plus any new ones.
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* await comments.update(orderComments, { recordId, commentId, body, mentions, attachments })
|
|
93
|
-
*/
|
|
94
|
-
declare function updateComment(action: CommentsAction, options: {
|
|
95
|
-
recordId: string;
|
|
96
|
-
commentId: string;
|
|
97
|
-
body: string;
|
|
98
|
-
mentions: ReadonlyArray<CommentMention>;
|
|
99
|
-
attachments: ReadonlyArray<CommentAttachmentInput>;
|
|
100
|
-
}): Promise<void>;
|
|
101
|
-
/**
|
|
102
|
-
* Deletes a comment. Offer it only where the comment's `canDelete` is true.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* await comments.delete(orderComments, { recordId, commentId })
|
|
106
|
-
*/
|
|
107
|
-
declare function deleteComment(action: CommentsAction, options: {
|
|
108
|
-
recordId: string;
|
|
109
|
-
commentId: string;
|
|
110
|
-
}): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Adds the visitor's reaction when `selected` is true, and removes it when false. Pass the
|
|
113
|
-
* reaction's current `isSelected` negated.
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* await comments.react(orderComments, { recordId, commentId, emoji: "👍", selected: true })
|
|
117
|
-
*/
|
|
118
|
-
declare function reactToComment(action: CommentsAction, options: {
|
|
119
|
-
recordId: string;
|
|
120
|
-
commentId: string;
|
|
121
|
-
emoji: string;
|
|
122
|
-
selected: boolean;
|
|
123
|
-
}): Promise<void>;
|
|
124
|
-
/**
|
|
125
|
-
* Whether the visitor gets an email when someone comments on this record.
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* const subscribed = await comments.subscription(orderComments, { recordId })
|
|
129
|
-
*/
|
|
130
|
-
declare function readSubscription(action: CommentsAction, options: {
|
|
131
|
-
recordId: string;
|
|
132
|
-
}): Promise<boolean>;
|
|
133
|
-
/**
|
|
134
|
-
* Turns the visitor's emails about this record's comments on or off.
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* await comments.setSubscription(orderComments, { recordId, subscribed: false })
|
|
138
|
-
*/
|
|
139
|
-
declare function setSubscription(action: CommentsAction, options: {
|
|
140
|
-
recordId: string;
|
|
141
|
-
subscribed: boolean;
|
|
142
|
-
}): Promise<void>;
|
|
143
|
-
/**
|
|
144
|
-
* The people the visitor may mention whose name or email matches `query`. Only call it when the
|
|
145
|
-
* thread's `allowMentions` is true.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* const people = await comments.searchMentions(orderComments, { query: "an" })
|
|
149
|
-
*/
|
|
150
|
-
declare function searchMentions(action: CommentsAction, options: {
|
|
151
|
-
query: string;
|
|
152
|
-
}): Promise<Array<{
|
|
153
|
-
name: string;
|
|
154
|
-
email: string;
|
|
155
|
-
avatar: string | null;
|
|
156
|
-
}>>;
|
|
157
|
-
declare const comments: {
|
|
158
|
-
list: typeof listComments;
|
|
159
|
-
create: typeof createComment;
|
|
160
|
-
update: typeof updateComment;
|
|
161
|
-
delete: typeof deleteComment;
|
|
162
|
-
react: typeof reactToComment;
|
|
163
|
-
subscription: typeof readSubscription;
|
|
164
|
-
setSubscription: typeof setSubscription;
|
|
165
|
-
searchMentions: typeof searchMentions;
|
|
166
|
-
};
|
|
167
|
-
//#endregion
|
|
168
|
-
export { CommentAttachmentInput, CommentMention, CommentThread, CommentView, comments };
|