@softr/sdk 0.0.91-alpha.1 → 0.0.91
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/auth/server.js +1 -1
- package/dist/datasource/record.js +3 -12
- package/dist/formatting.d.ts +3 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/mcp.d.ts +4 -17
- package/dist/mcp.js +18 -61
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +2 -2
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +1 -5
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- 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 +5 -3
- 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 +11 -9
- 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/record-queries/references/filters-and-sorting.md +2 -0
- package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +6 -4
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
- 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/auth/server.js
CHANGED
|
@@ -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
|
|
@@ -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
|
|
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
|
|
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 {
|
|
284
|
+
export { createRecord, deleteRecord, describeFailure, dsUrl, getRecord, listRecords, refererHeader, resolveTarget, updateRecord };
|
package/dist/formatting.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react0 from "react";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
|
|
5
5
|
//#region src/formatting.d.ts
|
|
@@ -94,7 +94,7 @@ declare function FormattingScope({
|
|
|
94
94
|
/** A BCP 47 locale, such as `de-DE`. It drops the app's fixed date format inside the scope. */
|
|
95
95
|
locale?: string;
|
|
96
96
|
children?: ReactNode;
|
|
97
|
-
}):
|
|
97
|
+
}): react0.FunctionComponentElement<react0.ProviderProps<Scope>>;
|
|
98
98
|
/**
|
|
99
99
|
* A date in the app's format, safe to render on the server. A timestamp whose
|
|
100
100
|
* zone is not known yet renders `fallback` until the browser supplies it, so
|
|
@@ -115,6 +115,6 @@ declare function FormattedDate({
|
|
|
115
115
|
time?: boolean;
|
|
116
116
|
/** What renders while the visitor's zone is unknown. */
|
|
117
117
|
fallback?: ReactNode;
|
|
118
|
-
}):
|
|
118
|
+
}): react0.FunctionComponentElement<react0.FragmentProps>;
|
|
119
119
|
//#endregion
|
|
120
120
|
export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,5 @@ import { useOverrides } from "./core/use-overrides.js";
|
|
|
17
17
|
import { useUserTimezone } from "./timezone.js";
|
|
18
18
|
import { PwaInstall, PwaPlatform, SoftrPwaHead, usePwaInstall } from "./pwa.js";
|
|
19
19
|
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
20
|
import { Audience } from "./route/audience.js";
|
|
23
|
-
export { type ActionPermissions, type
|
|
21
|
+
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 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, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
|
package/dist/index.js
CHANGED
|
@@ -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,
|
|
17
|
+
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, 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
|
|
2
|
-
import * as
|
|
1
|
+
import { DatasourceAction } from "./action.js";
|
|
2
|
+
import * as _tanstack_react_start6 from "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/mcp.d.ts
|
|
5
5
|
|
|
6
|
-
type SoftrMcpOptions
|
|
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
|
|
34
|
+
declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start6.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
|
|
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
|
|
260
|
+
function describeTool(action) {
|
|
272
261
|
const { operation, fields } = action.resource;
|
|
273
262
|
const names = Object.keys(fields ?? {});
|
|
274
|
-
const
|
|
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: ${
|
|
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: ${
|
|
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
|
|
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
|
|
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
|
|
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
|
|
371
|
+
function writableFields(action, args) {
|
|
404
372
|
const allowed = action.resource.fields ?? {};
|
|
405
|
-
return Object.fromEntries(Object.entries(args).filter(([name]) => name in allowed
|
|
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
|
|
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
|
-
|
|
430
|
-
|
|
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(
|
|
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
|
|
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:
|
|
436
|
+
text: error instanceof Error ? error.message : String(error)
|
|
480
437
|
}]
|
|
481
438
|
});
|
|
482
439
|
}
|
package/dist/package.js
CHANGED
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/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.91
|
|
12
|
+
library_version: 0.0.91
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
# Softr SDK core
|
|
@@ -52,7 +52,6 @@ Each sub-skill stands alone for its task and repeats the boundary above, so most
|
|
|
52
52
|
| Ask an AI model: a summary, an extraction from a document, a classification, a draft, a chat | [ai/SKILL.md](./ai/SKILL.md) |
|
|
53
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) |
|
|
54
54
|
| 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
55
|
| Let visitors install the app on their home screen | [pwa/SKILL.md](./pwa/SKILL.md) |
|
|
57
56
|
| Show a date, a time or a number | [formatting/SKILL.md](./formatting/SKILL.md) |
|
|
58
57
|
|
|
@@ -95,9 +94,6 @@ Running a model on the user's OWN provider account, because they chose that for
|
|
|
95
94
|
Opening the app to an AI assistant over MCP?
|
|
96
95
|
load softr-sdk/mcp
|
|
97
96
|
|
|
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
97
|
Adding an install button, or making the app installable?
|
|
102
98
|
load softr-sdk/pwa
|
|
103
99
|
|
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 0.0.
|
|
16
|
+
library_version: 0.0.91
|
|
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.91
|
|
12
|
+
library_version: 0.0.91
|
|
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.91
|
|
12
|
+
library_version: 0.0.91
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.91
|
|
12
|
+
library_version: 0.0.91
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
# The current user
|
|
@@ -56,9 +56,9 @@ It returns `User | null` and never suspends or fetches. It selects off root rout
|
|
|
56
56
|
```tsx
|
|
57
57
|
export const Route = createFileRoute('/_app/invoices')({
|
|
58
58
|
beforeLoad: guardRoute(pageSettings),
|
|
59
|
-
loader: (opts) => {
|
|
59
|
+
loader: async (opts) => {
|
|
60
60
|
assertRouteAccess(pageSettings, opts)
|
|
61
|
-
return
|
|
61
|
+
return { name: opts.context.user.fullName, invoices: await getMyInvoices() }
|
|
62
62
|
},
|
|
63
63
|
head: pageHead(pageSettings),
|
|
64
64
|
})
|
|
@@ -66,6 +66,8 @@ export const Route = createFileRoute('/_app/invoices')({
|
|
|
66
66
|
|
|
67
67
|
A `guardRoute` in `beforeLoad` guarantees a visitor at runtime, but it does not change what the compiler sees. `context.user` is still `User | null` in the loader. `assertRouteAccess(pageSettings, opts)` at the top of the loader narrows it there, so prefer that over `!`. Take `opts` whole: a destructured `context` does not narrow. See [routes-and-visibility](../routes-and-visibility/SKILL.md).
|
|
68
68
|
|
|
69
|
+
Never pass the visitor's id from a loader into a server function. The loader also runs in the browser, so the id arrives as an argument anyone can set. `getMyInvoices` below reads the visitor from its own `context`.
|
|
70
|
+
|
|
69
71
|
### In a server function: `context`
|
|
70
72
|
|
|
71
73
|
```ts
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 0.0.91
|
|
10
|
+
library_version: 0.0.91
|
|
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,21 +7,21 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 0.0.91
|
|
10
|
+
library_version: 0.0.91
|
|
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.
|
|
14
14
|
|
|
15
15
|
# Integrations
|
|
16
16
|
|
|
17
|
-
`integration.createFetcher` calls a third-party API through Softr's authenticated proxy. It
|
|
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
19
|
## Setup
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
22
|
import { createServerFn } from '@tanstack/react-start'
|
|
23
23
|
import { defineIntegration } from '@softr/sdk'
|
|
24
|
-
import { integration } from '@softr/sdk/server'
|
|
24
|
+
import { auth, integration } from '@softr/sdk/server'
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
## Reading connected integrations from the prompt
|
|
@@ -77,7 +77,7 @@ const getCalendarEvents = createServerFn().handler(async () => {
|
|
|
77
77
|
})
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
For a dynamic path segment, pass `params` matching each `{placeholder}` token:
|
|
80
|
+
For a dynamic path segment, pass `params` matching each `{placeholder}` token. Here the customer comes from the visitor's own Users row, which `auth.currentUserRow` finds through `usersQuery`, the app's `defineQuery` on the Users table:
|
|
81
81
|
|
|
82
82
|
```ts
|
|
83
83
|
const getStripeCustomer = defineIntegration({
|
|
@@ -89,10 +89,12 @@ const getStripeCustomer = defineIntegration({
|
|
|
89
89
|
})
|
|
90
90
|
|
|
91
91
|
const fetchCustomer = createServerFn({ method: 'GET' })
|
|
92
|
-
.
|
|
93
|
-
|
|
92
|
+
.handler(async ({ context }) => {
|
|
93
|
+
const me = await auth.currentUserRow(context.user, usersQuery, 'email')
|
|
94
|
+
const customerId = me?.fields.stripeCustomerId
|
|
95
|
+
if (!customerId) throw new Error('No Stripe customer for this visitor')
|
|
94
96
|
const stripe = integration.createFetcher(getStripeCustomer)
|
|
95
|
-
const res = await stripe({ params: { id:
|
|
97
|
+
const res = await stripe({ params: { id: customerId } })
|
|
96
98
|
if (!res.ok) throw new Error(`Stripe error: ${res.status} ${await res.text()}`)
|
|
97
99
|
return res.json()
|
|
98
100
|
})
|
|
@@ -110,12 +112,12 @@ const postSlackMessage = defineIntegration({
|
|
|
110
112
|
})
|
|
111
113
|
|
|
112
114
|
const sendSlackMessage = createServerFn({ method: 'POST' })
|
|
113
|
-
.validator((data: {
|
|
115
|
+
.validator((data: { text: string }) => data)
|
|
114
116
|
.handler(async ({ data }) => {
|
|
115
117
|
const slack = integration.createFetcher(postSlackMessage)
|
|
116
118
|
const res = await slack({
|
|
117
119
|
headers: { 'Content-Type': 'application/json' },
|
|
118
|
-
body: JSON.stringify({ channel:
|
|
120
|
+
body: JSON.stringify({ channel: '#sales', text: data.text }),
|
|
119
121
|
})
|
|
120
122
|
if (!res.ok) throw new Error(`Slack error: ${res.status} ${await res.text()}`)
|
|
121
123
|
return res.json()
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.91
|
|
12
|
+
library_version: 0.0.91
|
|
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.91
|
|
11
|
+
library_version: 0.0.91
|
|
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.91
|
|
12
|
+
library_version: 0.0.91
|
|
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.
|
|
@@ -127,6 +127,8 @@ Both take filters or nested groups:
|
|
|
127
127
|
|
|
128
128
|
Nesting goes two levels, a group inside a group. A third level throws `Cannot nest filter groups more than three levels deep.` Flatten by distributing the outer condition rather than nesting further.
|
|
129
129
|
|
|
130
|
+
**An `$or` with no members matches every row.** When its members come from a list that can be empty, return no rows for an empty list instead of reading the table.
|
|
131
|
+
|
|
130
132
|
## Sorting
|
|
131
133
|
|
|
132
134
|
```ts
|