@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.
Files changed (39) hide show
  1. package/dist/action.d.ts +46 -1
  2. package/dist/action.js +38 -1
  3. package/dist/auth/server.js +1 -1
  4. package/dist/core/email.d.ts +52 -0
  5. package/dist/core/email.js +62 -0
  6. package/dist/core/step.d.ts +20 -0
  7. package/dist/core/step.js +48 -0
  8. package/dist/datasource/record.js +3 -12
  9. package/dist/default-error-overlay.d.ts +2 -2
  10. package/dist/index.d.ts +3 -4
  11. package/dist/index.js +2 -4
  12. package/dist/mcp.d.ts +3 -16
  13. package/dist/mcp.js +18 -61
  14. package/dist/package.js +1 -1
  15. package/dist/pwa.d.ts +2 -2
  16. package/dist/server.d.ts +3 -1
  17. package/dist/server.js +3 -1
  18. package/package.json +1 -1
  19. package/skills/softr-sdk/SKILL.md +10 -8
  20. package/skills/softr-sdk/ai/SKILL.md +10 -10
  21. package/skills/softr-sdk/auth/SKILL.md +1 -1
  22. package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
  23. package/skills/softr-sdk/current-user/SKILL.md +1 -1
  24. package/skills/softr-sdk/email/SKILL.md +127 -0
  25. package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
  26. package/skills/softr-sdk/formatting/SKILL.md +1 -1
  27. package/skills/softr-sdk/integrations/SKILL.md +3 -1
  28. package/skills/softr-sdk/mcp/SKILL.md +1 -16
  29. package/skills/softr-sdk/pwa/SKILL.md +1 -1
  30. package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
  31. package/skills/softr-sdk/record-queries/SKILL.md +1 -1
  32. package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
  33. package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
  34. package/skills/softr-sdk/workflows/SKILL.md +10 -8
  35. package/dist/agent/agent-fns.d.ts +0 -30
  36. package/dist/agent/agent-fns.js +0 -215
  37. package/dist/agent/use-agent-chat.d.ts +0 -106
  38. package/dist/agent/use-agent-chat.js +0 -486
  39. package/skills/softr-sdk/agent-chat/SKILL.md +0 -110
package/dist/action.d.ts CHANGED
@@ -234,6 +234,51 @@ type IntegrationDefinition<TId extends string> = {
234
234
  * const res = await listEvents({ query: { timeMin: now, singleEvents: "true" } })
235
235
  */
236
236
  declare function defineIntegration<const TId extends string>(definition: IntegrationDefinition<TId>): IntegrationAction<TId>;
237
+ type EmailInputs = {
238
+ senderId?: string;
239
+ to?: ReadonlyArray<string>;
240
+ cc?: ReadonlyArray<string>;
241
+ bcc?: ReadonlyArray<string>;
242
+ replyTo?: string;
243
+ };
244
+ type EmailResource = {
245
+ type: "WORKFLOW_STEP";
246
+ stepType: "SOFTR_SEND_EMAIL";
247
+ inputs: EmailInputs;
248
+ };
249
+ type EmailAction<TId extends string = string> = Action<EmailResource> & {
250
+ id: TId;
251
+ };
252
+ type EmailDefinition<TId extends string> = EmailInputs & {
253
+ id: TId;
254
+ permissions: ActionPermissions;
255
+ };
256
+ /**
257
+ * Declares an email action: who may send it, and the fields every email it sends keeps whatever the
258
+ * call says. Softr sends it from the app's email sender and bills the workspace's workflow credits.
259
+ *
260
+ * - `to`, `cc`, `bcc`: addresses. An element may be a whole `{LOGGED_IN_USER:EMAIL}` or
261
+ * `{LOGGED_IN_USER:<field>}` placeholder, filled in for the signed-in sender.
262
+ * - `replyTo`: an address or one such placeholder.
263
+ * - `senderId`: one of the workspace's email senders, for an email that must come from that address.
264
+ * Left out, the app's sender is used. The call can never choose the sender.
265
+ *
266
+ * A field declared here wins over the call's, and declaring `to` also ignores the call's `cc` and
267
+ * `bcc`. Fix the recipients whenever the use case allows,
268
+ * because anyone in the audience can otherwise send any email to anyone.
269
+ *
270
+ * Pass the returned object to `email.send()` at runtime.
271
+ *
272
+ * @example
273
+ * const notifyOwner = defineEmailAction({
274
+ * id: "notifyOwner",
275
+ * to: ["owner@acme.com"],
276
+ * permissions: { userGroupTypes: ["NON_LOGGED_IN_USERS", "LOGGED_IN_USERS"] },
277
+ * })
278
+ *
279
+ * await email.send(notifyOwner, { subject: "New submission", body: html, replyTo: data.email })
280
+ */
281
+ declare function defineEmailAction<const TId extends string>(definition: EmailDefinition<TId>): EmailAction<TId>;
237
282
  type AiResource = {
238
283
  type: "SOFTR_AI";
239
284
  model: string;
@@ -268,4 +313,4 @@ type AiDefinition<TId extends string> = {
268
313
  */
269
314
  declare function defineAiAction<const TId extends string>(definition: AiDefinition<TId>): AiAction<TId>;
270
315
  //#endregion
271
- export { ActionData, ActionPermissions, ActionRecord, ActionShape, AiAction, DatasourceAction, FieldTypeOf, IntegrationAction, ReadOf, ReadShape, SoftrDatasources, WorkflowAction, defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow };
316
+ export { ActionData, ActionPermissions, ActionRecord, ActionShape, AiAction, DatasourceAction, EmailAction, FieldTypeOf, IntegrationAction, ReadOf, ReadShape, SoftrDatasources, WorkflowAction, defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow };
package/dist/action.js CHANGED
@@ -50,6 +50,43 @@ function defineIntegration(definition) {
50
50
  permissions
51
51
  };
52
52
  }
53
+ /**
54
+ * Declares an email action: who may send it, and the fields every email it sends keeps whatever the
55
+ * call says. Softr sends it from the app's email sender and bills the workspace's workflow credits.
56
+ *
57
+ * - `to`, `cc`, `bcc`: addresses. An element may be a whole `{LOGGED_IN_USER:EMAIL}` or
58
+ * `{LOGGED_IN_USER:<field>}` placeholder, filled in for the signed-in sender.
59
+ * - `replyTo`: an address or one such placeholder.
60
+ * - `senderId`: one of the workspace's email senders, for an email that must come from that address.
61
+ * Left out, the app's sender is used. The call can never choose the sender.
62
+ *
63
+ * A field declared here wins over the call's, and declaring `to` also ignores the call's `cc` and
64
+ * `bcc`. Fix the recipients whenever the use case allows,
65
+ * because anyone in the audience can otherwise send any email to anyone.
66
+ *
67
+ * Pass the returned object to `email.send()` at runtime.
68
+ *
69
+ * @example
70
+ * const notifyOwner = defineEmailAction({
71
+ * id: "notifyOwner",
72
+ * to: ["owner@acme.com"],
73
+ * permissions: { userGroupTypes: ["NON_LOGGED_IN_USERS", "LOGGED_IN_USERS"] },
74
+ * })
75
+ *
76
+ * await email.send(notifyOwner, { subject: "New submission", body: html, replyTo: data.email })
77
+ */
78
+ function defineEmailAction(definition) {
79
+ const { id, permissions,...inputs } = definition;
80
+ return {
81
+ id,
82
+ resource: {
83
+ type: "WORKFLOW_STEP",
84
+ stepType: "SOFTR_SEND_EMAIL",
85
+ inputs
86
+ },
87
+ permissions
88
+ };
89
+ }
53
90
  function isDatasourceAction(value) {
54
91
  if (typeof value !== "object" || value === null) return false;
55
92
  const candidate = value;
@@ -69,4 +106,4 @@ function defineAiAction(definition) {
69
106
  }
70
107
 
71
108
  //#endregion
72
- export { defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow, isDatasourceAction };
109
+ export { defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow, isDatasourceAction };
@@ -1,5 +1,4 @@
1
1
  import { settings } from "./methods/settings.js";
2
- import { currentUserRow } from "./current-user-row.js";
3
2
  import { confirmAuthenticatorSetup, removeAuthenticator, resetAuthenticator, sendAuthenticatorResetCode, skipAuthenticatorSetup, startAuthenticatorSetup, verifyAuthenticator } from "./methods/authenticator.js";
4
3
  import { sendSignInCode, signInWithCode } from "./methods/code.js";
5
4
  import { signInWithMagicLink } from "./methods/magicLink.js";
@@ -8,6 +7,7 @@ import { checkPasswordLink, requestPasswordReset, setPasswordWithLink } from "./
8
7
  import { confirmSignUp, signUp } from "./methods/signup.js";
9
8
  import { signInWithGoogle } from "./methods/social.js";
10
9
  import { removeAvatar, updateProfile } from "./methods/profile.js";
10
+ import { currentUserRow } from "./current-user-row.js";
11
11
  import "@tanstack/react-start/server-only";
12
12
 
13
13
  //#region src/auth/server.ts
@@ -0,0 +1,52 @@
1
+ import { EmailAction } from "../action.js";
2
+ import { StepError, StepErrorCode } from "./step.js";
3
+
4
+ //#region src/core/email.d.ts
5
+ /** A file the email carries, by the URL the app holds it under. */
6
+ interface EmailAttachment {
7
+ name: string;
8
+ /** The URL of a file uploaded to this app with `upload`. */
9
+ url: string;
10
+ }
11
+ interface EmailSendInit {
12
+ /** Ignored when the action declares its own. */
13
+ to?: ReadonlyArray<string>;
14
+ /** Ignored when the action declares its own `cc` or `to`. */
15
+ cc?: ReadonlyArray<string>;
16
+ /** Ignored when the action declares its own `bcc` or `to`. */
17
+ bcc?: ReadonlyArray<string>;
18
+ /** Ignored when the action declares its own. */
19
+ replyTo?: string;
20
+ subject: string;
21
+ /** Plain text or HTML. */
22
+ body: string;
23
+ /** Files uploaded to this app with `upload`; any other URL is refused. */
24
+ attachments?: ReadonlyArray<EmailAttachment>;
25
+ /**
26
+ * The same key sends the email once, however often the call is repeated. Pass one derived from
27
+ * what the email is about, such as the id of the record it announces, when the call may be retried.
28
+ * At most 128 characters. Left out, every call gets a fresh one.
29
+ */
30
+ idempotencyKey?: string;
31
+ }
32
+ interface EmailSent {
33
+ /** Null when the mail provider did not report one; the email was still sent. */
34
+ messageId: string | null;
35
+ }
36
+ type EmailErrorCode = StepErrorCode;
37
+ /**
38
+ * Thrown when Softr did not send the email; a {@link StepError}, so `code` says why. For an email, `INVALID_INPUT`
39
+ * is a missing subject or body, an entry that is not exactly one address, more than 50 recipients, an attachment
40
+ * that is not one of the app's uploads, or an idempotency key over 128 characters; `UNAVAILABLE` includes the Softr
41
+ * fallback address past its daily limit and an unconfirmed sender.
42
+ */
43
+ declare class EmailError extends StepError {
44
+ constructor(status: number, code: EmailErrorCode, message: string);
45
+ }
46
+ /** Sends one email through the action. Never retries by itself. */
47
+ declare function sendEmail(action: EmailAction, init: EmailSendInit): Promise<EmailSent>;
48
+ declare const email: {
49
+ send: typeof sendEmail;
50
+ };
51
+ //#endregion
52
+ export { EmailAttachment, EmailError, EmailErrorCode, EmailSendInit, EmailSent, email };
@@ -0,0 +1,62 @@
1
+ import { assert } from "../assertions.js";
2
+ import { softrApiUrl } from "../softr-api.js";
3
+ import { fetch } from "../fetch.js";
4
+ import { sessionConfig } from "../auth/config.js";
5
+ import { readSessionToken } from "../auth/session.js";
6
+ import { StepError, readStepFailure } from "./step.js";
7
+
8
+ //#region src/core/email.ts
9
+ /** Longer than Softr waits for the send itself, so its own timeout answers first. */
10
+ const TIMEOUT_MS = 12e4;
11
+ /**
12
+ * Thrown when Softr did not send the email; a {@link StepError}, so `code` says why. For an email, `INVALID_INPUT`
13
+ * is a missing subject or body, an entry that is not exactly one address, more than 50 recipients, an attachment
14
+ * that is not one of the app's uploads, or an idempotency key over 128 characters; `UNAVAILABLE` includes the Softr
15
+ * fallback address past its daily limit and an unconfirmed sender.
16
+ */
17
+ var EmailError = class extends StepError {
18
+ constructor(status, code, message) {
19
+ super(status, code, message);
20
+ this.name = "EmailError";
21
+ }
22
+ };
23
+ /** Sends one email through the action. Never retries by itself. */
24
+ async function sendEmail(action, init) {
25
+ const { to, cc, bcc, replyTo, subject, body, attachments } = init;
26
+ const sessionToken = readSessionToken();
27
+ let res;
28
+ try {
29
+ res = await fetch(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/step`, {
30
+ method: "POST",
31
+ headers: {
32
+ ...sessionToken ? { Authorization: `Bearer ${sessionToken}` } : {},
33
+ "Content-Type": "application/json",
34
+ "Idempotency-Key": init.idempotencyKey ?? crypto.randomUUID()
35
+ },
36
+ body: JSON.stringify({ input: {
37
+ to,
38
+ cc,
39
+ bcc,
40
+ replyTo,
41
+ subject,
42
+ body,
43
+ attachments
44
+ } }),
45
+ signal: AbortSignal.timeout(TIMEOUT_MS)
46
+ });
47
+ } catch (error) {
48
+ if (error instanceof DOMException && error.name === "TimeoutError") throw new EmailError(504, "TIMEOUT", `Email "${action.id}" got no answer in time. It may still have been sent.`);
49
+ throw new EmailError(502, "UNAVAILABLE", `Email "${action.id}" could not reach Softr: ${error instanceof Error ? error.message : String(error)}`);
50
+ }
51
+ if (res.ok) {
52
+ const sent = await res.json();
53
+ assert(typeof sent === "object" && sent !== null && "messageId" in sent && (typeof sent.messageId === "string" || sent.messageId === null), "the send answered without a messageId");
54
+ return { messageId: sent.messageId };
55
+ }
56
+ const { code, message } = await readStepFailure(res, `Email "${action.id}" failed with HTTP ${res.status}`);
57
+ throw new EmailError(res.status, code, message);
58
+ }
59
+ const email = { send: sendEmail };
60
+
61
+ //#endregion
62
+ export { EmailError, email };
@@ -0,0 +1,20 @@
1
+ //#region src/core/step.d.ts
2
+ /** Why Softr did not run a workflow step the app runs by itself, whatever the step. */
3
+ declare const STEP_ERROR_CODES: readonly ["NOT_FOUND", "INVALID_INPUT", "UNAVAILABLE", "TIMEOUT", "RATE_LIMITED"];
4
+ type StepErrorCode = (typeof STEP_ERROR_CODES)[number];
5
+ /**
6
+ * Thrown when Softr did not run a step the app runs by itself, such as sending an email. `code` says why:
7
+ *
8
+ * - `NOT_FOUND`: no such action, or the caller is not in its audience.
9
+ * - `INVALID_INPUT`: the call's inputs were refused; the message says which.
10
+ * - `UNAVAILABLE`: Softr could not run it, for example with no workflow credits left, or could not be reached.
11
+ * - `TIMEOUT`: no answer in time. It may still have run; retry with the same idempotency key.
12
+ * - `RATE_LIMITED`: the app ran its actions too often in the last minute or day; try again later.
13
+ */
14
+ declare class StepError extends Error {
15
+ readonly status: number;
16
+ readonly code: StepErrorCode;
17
+ constructor(status: number, code: StepErrorCode, message: string);
18
+ }
19
+ //#endregion
20
+ export { StepError, StepErrorCode };
@@ -0,0 +1,48 @@
1
+ //#region src/core/step.ts
2
+ /** Why Softr did not run a workflow step the app runs by itself, whatever the step. */
3
+ const STEP_ERROR_CODES = [
4
+ "NOT_FOUND",
5
+ "INVALID_INPUT",
6
+ "UNAVAILABLE",
7
+ "TIMEOUT",
8
+ "RATE_LIMITED"
9
+ ];
10
+ /**
11
+ * Thrown when Softr did not run a step the app runs by itself, such as sending an email. `code` says why:
12
+ *
13
+ * - `NOT_FOUND`: no such action, or the caller is not in its audience.
14
+ * - `INVALID_INPUT`: the call's inputs were refused; the message says which.
15
+ * - `UNAVAILABLE`: Softr could not run it, for example with no workflow credits left, or could not be reached.
16
+ * - `TIMEOUT`: no answer in time. It may still have run; retry with the same idempotency key.
17
+ * - `RATE_LIMITED`: the app ran its actions too often in the last minute or day; try again later.
18
+ */
19
+ var StepError = class extends Error {
20
+ status;
21
+ code;
22
+ constructor(status, code, message) {
23
+ super(message);
24
+ this.name = "StepError";
25
+ this.status = status;
26
+ this.code = code;
27
+ }
28
+ };
29
+ /** The code and message of a step Softr refused, read from its answer; `fallbackMessage` when it sent none. */
30
+ async function readStepFailure(res, fallbackMessage) {
31
+ const failure = await res.json().catch(() => null);
32
+ const known = typeof failure === "object" && failure !== null ? failure : {};
33
+ return {
34
+ code: ("code" in known ? STEP_ERROR_CODES.find((errorCode) => errorCode === known.code) : void 0) ?? codeOfStatus(res.status),
35
+ message: "message" in known && typeof known.message === "string" && known.message !== "" ? known.message : fallbackMessage
36
+ };
37
+ }
38
+ function codeOfStatus(status) {
39
+ switch (status) {
40
+ case 400: return "INVALID_INPUT";
41
+ case 404: return "NOT_FOUND";
42
+ case 429: return "RATE_LIMITED";
43
+ default: return "UNAVAILABLE";
44
+ }
45
+ }
46
+
47
+ //#endregion
48
+ export { StepError, readStepFailure };
@@ -30,15 +30,6 @@ function refererHeader() {
30
30
  const referer = getRequestHeader("referer");
31
31
  return { Referer: referer !== void 0 && URL.parse(referer)?.origin === page.origin ? referer : page.href };
32
32
  }
33
- /** A datasource call the service refused. `status` is its HTTP status. */
34
- var DatasourceError = class extends Error {
35
- status;
36
- constructor(message, status) {
37
- super(message);
38
- this.name = "DatasourceError";
39
- this.status = status;
40
- }
41
- };
42
33
  async function describeFailure(res) {
43
34
  const body = await res.json().catch(() => null);
44
35
  const message = typeof body === "object" && body !== null && "message" in body ? body.message : null;
@@ -244,7 +235,7 @@ async function updateRecord(action, options) {
244
235
  },
245
236
  body: JSON.stringify({ fields: rawFields })
246
237
  });
247
- if (!res.ok) throw new DatasourceError(`datasource update failed for action "${actionId}": ${await describeFailure(res)}`, res.status);
238
+ if (!res.ok) throw new Error(`datasource update failed for action "${actionId}": ${await describeFailure(res)}`);
248
239
  const record = await res.json();
249
240
  return {
250
241
  id: record.id,
@@ -266,7 +257,7 @@ async function deleteRecord(action, options) {
266
257
  ...refererHeader()
267
258
  }
268
259
  });
269
- if (!res.ok) throw new DatasourceError(`datasource delete failed for action "${actionId}": ${await describeFailure(res)}`, res.status);
260
+ if (!res.ok) throw new Error(`datasource delete failed for action "${actionId}": ${await describeFailure(res)}`);
270
261
  }
271
262
  function resolveTarget(subject, operation) {
272
263
  const declaredBy = operation === "read" ? "defineQuery" : "defineMutation";
@@ -290,4 +281,4 @@ function dealiasData(data, select) {
290
281
  }
291
282
 
292
283
  //#endregion
293
- export { DatasourceError, createRecord, deleteRecord, describeFailure, dsUrl, getRecord, listRecords, refererHeader, resolveTarget, updateRecord };
284
+ export { createRecord, deleteRecord, describeFailure, dsUrl, getRecord, listRecords, refererHeader, resolveTarget, updateRecord };
@@ -1,4 +1,4 @@
1
- import * as react4 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): react4.JSX.Element;
11
+ }: Props): react6.JSX.Element;
12
12
  //#endregion
13
13
  export { DefaultErrorOverlay };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { SoftrUserGroupId, SoftrUserGroups, SoftrUserProperties, User } from "./auth/user.js";
2
- import { ActionPermissions, SoftrDatasources, defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
2
+ import { ActionPermissions, SoftrDatasources, defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
3
3
  import { FileAttachment } from "./core/file-upload.js";
4
4
  import { FileItem, useFileUpload } from "./core/use-file-upload.js";
5
5
  import { AiAnswer, AiFile, AiGenerateInit, AiMessage, AiUsage } from "./core/ai.js";
6
+ import { EmailAttachment, EmailSendInit, EmailSent } from "./core/email.js";
6
7
  import { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting } from "./formatting.js";
7
8
  import { SoftrContext } from "./auth/context.js";
8
9
  import { AuthSettings } from "./auth/platform.js";
@@ -17,7 +18,5 @@ import { useOverrides } from "./core/use-overrides.js";
17
18
  import { useUserTimezone } from "./timezone.js";
18
19
  import { PwaInstall, PwaPlatform, SoftrPwaHead, usePwaInstall } from "./pwa.js";
19
20
  import { DefaultErrorOverlay } from "./default-error-overlay.js";
20
- import { Agent, AgentChatSummary, listAgents } from "./agent/agent-fns.js";
21
- import { AgentBlock, AgentChat, AgentChatOptions, AgentMessage, AgentQuestion, AgentTodo, AgentToolCall, useAgentChat } from "./agent/use-agent-chat.js";
22
21
  import { Audience } from "./route/audience.js";
23
- export { type ActionPermissions, type Agent, type AgentBlock, type AgentChat, type AgentChatOptions, type AgentChatSummary, type AgentMessage, type AgentQuestion, type AgentTodo, type AgentToolCall, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, listAgents, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAgentChat, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
22
+ export { type ActionPermissions, type AiAnswer, type AiFile, type AiGenerateInit, type AiMessage, type AiUsage, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type EmailAttachment, type EmailSendInit, type EmailSent, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type SoftrUserProperties, type User, type WeekDay, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineAiAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
1
+ import { defineAiAction, defineEmailAction, defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
2
2
  import { useFileUpload } from "./core/use-file-upload.js";
3
3
  import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.js";
4
4
  import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
@@ -12,8 +12,6 @@ import { fieldShape, formatDuration, formatField, formatValue, registerSoftrFiel
12
12
  import { useOverrides } from "./core/use-overrides.js";
13
13
  import { useUserTimezone } from "./timezone.js";
14
14
  import { DefaultErrorOverlay } from "./default-error-overlay.js";
15
- import { listAgents } from "./agent/agent-fns.js";
16
- import { useAgentChat } from "./agent/use-agent-chat.js";
17
15
  import { Audience } from "./route/audience.js";
18
16
 
19
- export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, listAgents, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAgentChat, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
17
+ export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineAiAction, defineEmailAction, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
package/dist/mcp.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { DatasourceAction, ReadShape } from "./action.js";
1
+ import { DatasourceAction } from "./action.js";
2
2
  import * as _tanstack_react_start7 from "@tanstack/react-start";
3
3
 
4
4
  //#region src/mcp.d.ts
5
5
 
6
- type SoftrMcpOptions<TUsers extends ReadShape = ReadShape> = {
6
+ type SoftrMcpOptions = {
7
7
  /**
8
8
  * The actions to expose as tools, from `defineQuery` and `defineMutation`.
9
9
  *
@@ -12,19 +12,6 @@ type SoftrMcpOptions<TUsers extends ReadShape = ReadShape> = {
12
12
  * decide who may run the ones that are listed.
13
13
  */
14
14
  actions?: Array<DatasourceAction>;
15
- /**
16
- * Fills the owner of a person's record from who is calling, the way the app's
17
- * pages do with `auth.currentUserRow`. The field is left out of the tool, so
18
- * the assistant can't leave it wrong or name someone else.
19
- */
20
- owner?: SoftrMcpOwner<TUsers>;
21
- };
22
- type SoftrMcpOwner<TUsers extends ReadShape = ReadShape> = {
23
- /** The people table, and its email field, to find the caller's row in. */
24
- users: DatasourceAction<TUsers>;
25
- email: keyof TUsers["fields"] & string;
26
- /** Listed create or update action id to the field that links to the caller's row. */
27
- fields: Record<string, string>;
28
15
  };
29
16
  /**
30
17
  * Serves the MCP endpoint and its OAuth flow from the app's own origin.
@@ -44,6 +31,6 @@ type SoftrMcpOwner<TUsers extends ReadShape = ReadShape> = {
44
31
  * ],
45
32
  * }))
46
33
  */
47
- declare function softrMcpMiddleware<TUsers extends ReadShape>(options?: SoftrMcpOptions<TUsers>): _tanstack_react_start7.RequestMiddlewareAfterServer<{}, undefined, undefined>;
34
+ declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start7.RequestMiddlewareAfterServer<{}, undefined, undefined>;
48
35
  //#endregion
49
36
  export { softrMcpMiddleware };
package/dist/mcp.js CHANGED
@@ -5,10 +5,8 @@ import { softrConfig } from "./softr-config.js";
5
5
  import { sessionConfig } from "./auth/config.js";
6
6
  import { readSessionToken, withSessionToken } from "./auth/session.js";
7
7
  import { isDatasourceAction } from "./action.js";
8
- import { DatasourceError } from "./datasource/record.js";
9
8
  import { makePlatform } from "./auth/platform.js";
10
9
  import { ds } from "./datasource/datasource.js";
11
- import { currentUserRow } from "./auth/current-user-row.js";
12
10
  import { z } from "zod";
13
11
  import { createMiddleware } from "@tanstack/react-start";
14
12
 
@@ -50,14 +48,6 @@ function softrMcpMiddleware(options = {}) {
50
48
  assert(!actions.has(value.id), `two actions share the id "${value.id}"`);
51
49
  actions.set(value.id, value);
52
50
  }
53
- const owner = options.owner;
54
- for (const [actionId, field] of Object.entries(owner?.fields ?? {})) {
55
- const action = actions.get(actionId);
56
- assert(action, `owner names "${actionId}", which is not a listed action`);
57
- const { operation, fields } = action.resource;
58
- assert(operation === "create" || operation === "update", `owner fills "${actionId}", which is a ${operation}`);
59
- assert(field in (fields ?? {}), `"${actionId}" has no field "${field}" for the owner`);
60
- }
61
51
  return createMiddleware({ type: "request" }).server(async ({ next, request }) => {
62
52
  const url = new URL(request.url);
63
53
  const origin = url.origin;
@@ -81,7 +71,7 @@ function softrMcpMiddleware(options = {}) {
81
71
  });
82
72
  case AUTHORIZE_PATH: return await authorize(request, login);
83
73
  case TOKEN_PATH: return await issueToken(request);
84
- case MCP_PATH: return await rpc(request, origin, actions, owner);
74
+ case MCP_PATH: return await rpc(request, origin, actions);
85
75
  default: return await next();
86
76
  }
87
77
  });
@@ -254,8 +244,7 @@ const WHOAMI = {
254
244
  type: "object",
255
245
  properties: {},
256
246
  additionalProperties: false
257
- },
258
- annotations: { readOnlyHint: true }
247
+ }
259
248
  };
260
249
  /** How many records a read returns when the caller does not say. */
261
250
  const DEFAULT_LIMIT = 20;
@@ -268,16 +257,14 @@ const MAX_LIMIT = 100;
268
257
  * that only ever reads one datasource exposes one read, even though its
269
258
  * credentials would allow more.
270
259
  */
271
- function describeTool(action, ownerField) {
260
+ function describeTool(action) {
272
261
  const { operation, fields } = action.resource;
273
262
  const names = Object.keys(fields ?? {});
274
- const writable = names.filter((name) => name !== ownerField);
275
- const fieldProps = Object.fromEntries(writable.map((name) => [name, { description: `The "${name}" field.` }]));
263
+ const fieldProps = Object.fromEntries(names.map((name) => [name, { description: `The "${name}" field.` }]));
276
264
  switch (operation) {
277
265
  case "read": return {
278
266
  name: action.id,
279
267
  description: `Read records from "${action.id}". Returns the fields ${names.join(", ")}. Only records the signed-in user may see come back.`,
280
- annotations: { readOnlyHint: true },
281
268
  inputSchema: {
282
269
  type: "object",
283
270
  properties: {
@@ -298,7 +285,7 @@ function describeTool(action, ownerField) {
298
285
  };
299
286
  case "create": return {
300
287
  name: action.id,
301
- description: `Create a record with "${action.id}". Writable fields: ${writable.join(", ")}.`,
288
+ description: `Create a record with "${action.id}". Writable fields: ${names.join(", ")}.`,
302
289
  inputSchema: {
303
290
  type: "object",
304
291
  properties: fieldProps,
@@ -307,7 +294,7 @@ function describeTool(action, ownerField) {
307
294
  };
308
295
  case "update": return {
309
296
  name: action.id,
310
- description: `Update a record with "${action.id}". Writable fields: ${writable.join(", ")}.`,
297
+ description: `Update a record with "${action.id}". Writable fields: ${names.join(", ")}.`,
311
298
  inputSchema: {
312
299
  type: "object",
313
300
  properties: {
@@ -343,7 +330,7 @@ function describeTool(action, ownerField) {
343
330
  * visitor's user groups exactly as it would a click in the app. Nothing here
344
331
  * decides what is allowed.
345
332
  */
346
- async function runTool(action, args, owner) {
333
+ async function runTool(action, args) {
347
334
  const typed = action;
348
335
  switch (action.resource.operation) {
349
336
  case "read": {
@@ -355,21 +342,13 @@ async function runTool(action, args, owner) {
355
342
  nextOffset: result$1.nextOffset
356
343
  };
357
344
  }
358
- case "create": {
359
- const data = writableFields(action, args, owner?.field);
360
- if (owner !== null) {
361
- const row = await owner.row();
362
- if (row === null) throw new Error("The visitor has no row in the people table, so this record can't be created for them.");
363
- data[owner.field] = { id: row.id };
364
- }
365
- return await ds.create(typed, { data });
366
- }
345
+ case "create": return await ds.create(typed, { data: writableFields(action, args) });
367
346
  case "update": {
368
347
  const { id,...data } = args;
369
348
  assert(typeof id === "string" && id !== "", "update needs a record id");
370
349
  return await ds.update(typed, {
371
350
  id,
372
- data: writableFields(action, data, owner?.field)
351
+ data: writableFields(action, data)
373
352
  });
374
353
  }
375
354
  case "delete": {
@@ -380,19 +359,8 @@ async function runTool(action, args, owner) {
380
359
  }
381
360
  }
382
361
  }
383
- function ownerFieldOf(owner, actionId) {
384
- return owner !== void 0 && Object.hasOwn(owner.fields, actionId) ? owner.fields[actionId] : void 0;
385
- }
386
- function ownerFill(owner, actionId, sessionToken) {
387
- const field = ownerFieldOf(owner, actionId);
388
- if (owner === void 0 || field === void 0) return null;
389
- return {
390
- field,
391
- row: async () => currentUserRow(await resolveUser(sessionToken), owner.users, owner.email)
392
- };
393
- }
394
362
  /**
395
- * Only the fields the action declared, less the owner it fills itself.
363
+ * Only the fields the action declared.
396
364
  *
397
365
  * `additionalProperties: false` in the tool schema is a hint to the model, not
398
366
  * a check — a client can send whatever it likes. An unlisted key reaches the
@@ -400,18 +368,9 @@ function ownerFill(owner, actionId, sessionToken) {
400
368
  * straight through. So the action's field list gets enforced here, or it isn't
401
369
  * a boundary at all.
402
370
  */
403
- function writableFields(action, args, ownerField) {
371
+ function writableFields(action, args) {
404
372
  const allowed = action.resource.fields ?? {};
405
- return Object.fromEntries(Object.entries(args).filter(([name]) => name in allowed && name !== ownerField));
406
- }
407
- /**
408
- * The error as the assistant should read it. A row rule that keeps the caller
409
- * from changing a record answers 404, the same as a deleted record, so a bare
410
- * "not found" would leave the assistant guessing.
411
- */
412
- function describeError(error) {
413
- if (error instanceof DatasourceError && error.status === 404) return "Refused: this record doesn't exist, or the visitor's user group may not change it. If it still shows in a read, it is a permission. Tell the visitor they don't have access to this action, and that the app's builder can grant it.";
414
- return error instanceof Error ? error.message : String(error);
373
+ return Object.fromEntries(Object.entries(args).filter(([name]) => name in allowed));
415
374
  }
416
375
  function clampLimit(raw) {
417
376
  if (typeof raw !== "number" || !Number.isInteger(raw)) return DEFAULT_LIMIT;
@@ -421,15 +380,13 @@ function clampOffset(raw) {
421
380
  if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 0) return null;
422
381
  return raw;
423
382
  }
424
- async function rpc(request, origin, actions, owner) {
383
+ async function rpc(request, origin, actions) {
425
384
  if (request.method !== "POST") return methodNotAllowed("POST");
426
385
  const token = bearerToken(request);
427
386
  if (token === null) return unauthorized(origin);
428
387
  const session = await platformSession(token);
429
- let sessionToken;
430
- if (session.ok) sessionToken = session.sessionToken;
431
- else if (session.refused && await resolveUser(token) !== null) sessionToken = token;
432
- else return session.refused ? unauthorized(origin) : unavailable();
388
+ if (!session.ok) return session.refused ? unauthorized(origin) : unavailable();
389
+ const { sessionToken } = session;
433
390
  const body = await readJson(request);
434
391
  const message = z.object({
435
392
  id: z.union([z.string(), z.number()]).optional(),
@@ -458,7 +415,7 @@ async function rpc(request, origin, actions, owner) {
458
415
  }
459
416
  });
460
417
  }
461
- case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].map((action) => describeTool(action, ownerFieldOf(owner, action.id)))] });
418
+ case "tools/list": return result(id, { tools: [WHOAMI, ...[...actions.values()].map(describeTool)] });
462
419
  case "tools/call": {
463
420
  const name = params?.name;
464
421
  const args = typeof params?.arguments === "object" && params.arguments !== null ? params.arguments : {};
@@ -470,13 +427,13 @@ async function rpc(request, origin, actions, owner) {
470
427
  const action = typeof name === "string" ? actions.get(name) : void 0;
471
428
  if (action === void 0) return failure(id, -32602, `Unknown tool: ${String(name)}`);
472
429
  try {
473
- return result(id, toolResult(await withSessionToken(sessionToken, () => runTool(action, args, ownerFill(owner, action.id, sessionToken)))));
430
+ return result(id, toolResult(await withSessionToken(sessionToken, () => runTool(action, args))));
474
431
  } catch (error) {
475
432
  return result(id, {
476
433
  isError: true,
477
434
  content: [{
478
435
  type: "text",
479
- text: describeError(error)
436
+ text: error instanceof Error ? error.message : String(error)
480
437
  }]
481
438
  });
482
439
  }
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.93-alpha.0";
2
+ var version = "0.0.93-alpha.2";
3
3
 
4
4
  //#endregion
5
5
  export { version };