@feltdb/feltkit 0.3.26 → 0.3.28

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 (96) hide show
  1. package/dist/app.d.ts +52 -2
  2. package/dist/app.js +29 -2
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.d.ts +5 -1
  5. package/dist/appboundry/build.js +16 -24
  6. package/dist/appboundry/build.js.map +1 -1
  7. package/dist/appboundry/guest-index.d.ts +1 -0
  8. package/dist/appboundry/guest-index.js +1 -0
  9. package/dist/appboundry/guest-index.js.map +1 -1
  10. package/dist/appboundry/guest-tenancy.d.ts +40 -0
  11. package/dist/appboundry/guest-tenancy.js +162 -0
  12. package/dist/appboundry/guest-tenancy.js.map +1 -0
  13. package/dist/appboundry/guest.js +22 -1
  14. package/dist/appboundry/guest.js.map +1 -1
  15. package/dist/appboundry/host.d.ts +24 -0
  16. package/dist/appboundry/host.js +157 -5
  17. package/dist/appboundry/host.js.map +1 -1
  18. package/dist/cli/deploy-appboundry.d.ts +55 -0
  19. package/dist/cli/deploy-appboundry.js +77 -1
  20. package/dist/cli/deploy-appboundry.js.map +1 -1
  21. package/dist/cli/main.js +202 -15
  22. package/dist/cli/main.js.map +1 -1
  23. package/dist/index.d.ts +3 -1
  24. package/dist/index.js +2 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/platform/server.js +5 -3
  27. package/dist/platform/server.js.map +1 -1
  28. package/dist/react/auth.js +3 -2
  29. package/dist/react/auth.js.map +1 -1
  30. package/dist/runtime/agent.d.ts +14 -0
  31. package/dist/runtime/agent.js +59 -9
  32. package/dist/runtime/agent.js.map +1 -1
  33. package/dist/runtime/content.d.ts +1 -0
  34. package/dist/runtime/context.d.ts +29 -0
  35. package/dist/runtime/credentials.d.ts +76 -0
  36. package/dist/runtime/credentials.js +87 -2
  37. package/dist/runtime/credentials.js.map +1 -1
  38. package/dist/runtime/data.d.ts +1 -24
  39. package/dist/runtime/data.js +4 -67
  40. package/dist/runtime/data.js.map +1 -1
  41. package/dist/runtime/integrations.d.ts +3 -0
  42. package/dist/runtime/integrations.js +31 -4
  43. package/dist/runtime/integrations.js.map +1 -1
  44. package/dist/runtime/job-context.d.ts +26 -0
  45. package/dist/runtime/job-context.js +24 -0
  46. package/dist/runtime/job-context.js.map +1 -0
  47. package/dist/runtime/oauth-credentials.d.ts +68 -0
  48. package/dist/runtime/oauth-credentials.js +496 -0
  49. package/dist/runtime/oauth-credentials.js.map +1 -0
  50. package/dist/runtime/paged-read.d.ts +35 -0
  51. package/dist/runtime/paged-read.js +69 -0
  52. package/dist/runtime/paged-read.js.map +1 -0
  53. package/dist/runtime/runtime.d.ts +3 -0
  54. package/dist/runtime/runtime.js +64 -12
  55. package/dist/runtime/runtime.js.map +1 -1
  56. package/dist/runtime/services.d.ts +14 -38
  57. package/dist/runtime/services.js +124 -17
  58. package/dist/runtime/services.js.map +1 -1
  59. package/dist/runtime/sha256.d.ts +1 -0
  60. package/dist/runtime/sha256.js +91 -0
  61. package/dist/runtime/sha256.js.map +1 -0
  62. package/dist/runtime/tenancy.d.ts +34 -1
  63. package/dist/runtime/tenancy.js +62 -11
  64. package/dist/runtime/tenancy.js.map +1 -1
  65. package/dist/runtime/transactions.d.ts +2 -0
  66. package/dist/runtime/transactions.js +2 -1
  67. package/dist/runtime/transactions.js.map +1 -1
  68. package/dist/server/admin.d.ts +3 -0
  69. package/dist/server/admin.js +129 -18
  70. package/dist/server/admin.js.map +1 -1
  71. package/dist/server/index.d.ts +7 -0
  72. package/dist/server/index.js +44 -14
  73. package/dist/server/index.js.map +1 -1
  74. package/dist/server/ports.d.ts +43 -0
  75. package/dist/server/ports.js +96 -0
  76. package/dist/server/ports.js.map +1 -0
  77. package/dist/server/project.d.ts +8 -1
  78. package/dist/server/project.js +6 -9
  79. package/dist/server/project.js.map +1 -1
  80. package/dist/server/tenancy.js +2 -1
  81. package/dist/server/tenancy.js.map +1 -1
  82. package/dist/testing/index.d.ts +36 -2
  83. package/dist/testing/index.js +17 -4
  84. package/dist/testing/index.js.map +1 -1
  85. package/dist/words.d.ts +9 -0
  86. package/dist/words.js +15 -0
  87. package/dist/words.js.map +1 -0
  88. package/docs/APPBOUNDRY.md +15 -6
  89. package/docs/AUTH.md +16 -3
  90. package/docs/GUARANTEES.md +23 -2
  91. package/docs/PATH-TO-PRODUCTION.md +1 -1
  92. package/docs/README.md +2 -2
  93. package/package.json +3 -3
  94. package/skills/.claude-plugin/marketplace.json +1 -1
  95. package/skills/.claude-plugin/plugin.json +1 -1
  96. package/skills/feltkit-services/SKILL.md +1 -1
@@ -0,0 +1,69 @@
1
+ import { FeltKitError } from "../errors.js";
2
+ /**
3
+ * The largest page FeltDB's `db.query` answers (it refuses a larger `limit`, on every runtime).
4
+ * Whole results are read as consecutive pages of this size, following FeltDB's cursor.
5
+ */
6
+ export const PAGE_LIMIT = 1_000;
7
+ /**
8
+ * Every record matching `request`, one FeltDB page at a time, following `nextCursor` to the end.
9
+ *
10
+ * This is the only way FeltKit reads more than one page. `collection.find()` is not used for
11
+ * whole results: FeltDB 0.18 answers it with a default page of 100 when given options (silently
12
+ * incomplete), and FeltDB 0.20 refuses it past 1,000 matches. A page that says more records remain
13
+ * without a cursor to them, or a cursor that does not move, is refused here rather than returned as
14
+ * a complete result.
15
+ */
16
+ export async function* queryPages(db, request, pageSize = PAGE_LIMIT) {
17
+ let cursor;
18
+ const seen = new Set();
19
+ for (;;) {
20
+ const page = await db.query({
21
+ collection: request.collection,
22
+ ...(request.where?.length ? { where: request.where } : {}),
23
+ ...(request.orderBy?.length ? { orderBy: request.orderBy } : {}),
24
+ limit: pageSize,
25
+ ...(cursor ? { cursor } : {}),
26
+ });
27
+ yield page.records.map(storedDocument);
28
+ if (!page.nextCursor) {
29
+ if (page.exhausted === false) {
30
+ throw new FeltKitError("INTERNAL", `FeltDB reported more "${request.collection}" records without a cursor to them; the read was stopped rather than returned incomplete.`, { details: { collection: request.collection } });
31
+ }
32
+ return;
33
+ }
34
+ if (seen.has(page.nextCursor)) {
35
+ throw new FeltKitError("INTERNAL", `FeltDB returned the same cursor twice while reading "${request.collection}"; the read was stopped rather than repeated.`, { details: { collection: request.collection } });
36
+ }
37
+ seen.add(page.nextCursor);
38
+ cursor = page.nextCursor;
39
+ }
40
+ }
41
+ /** Every matching record (or the first `limit`), read in pages. Holds the result, so use it for results the caller returns. */
42
+ export async function readAll(db, request, limit) {
43
+ const out = [];
44
+ for await (const page of queryPages(db, request, limit !== undefined ? Math.min(limit, PAGE_LIMIT) : PAGE_LIMIT)) {
45
+ for (const record of page) {
46
+ if (limit !== undefined && out.length >= limit)
47
+ return out;
48
+ out.push(record);
49
+ }
50
+ if (limit !== undefined && out.length >= limit)
51
+ return out;
52
+ }
53
+ return out;
54
+ }
55
+ /** How many records match, counted page by page; no page is kept. */
56
+ export async function countAll(db, request) {
57
+ let n = 0;
58
+ for await (const page of queryPages(db, request))
59
+ n += page.length;
60
+ return n;
61
+ }
62
+ /** As FeltDB's own `find()` does: a server reports a record's key as `recordId` beside its `id`. */
63
+ function storedDocument(record) {
64
+ if (!record || typeof record !== "object" || !("recordId" in record) || record.recordId !== record.id)
65
+ return record;
66
+ const { recordId: _key, ...document } = record;
67
+ return document;
68
+ }
69
+ //# sourceMappingURL=paged-read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paged-read.js","sourceRoot":"","sources":["../../src/runtime/paged-read.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAK5C;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC;AAQhC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,UAAU,CAAC,EAAgB,EAAE,OAAkB,EAAE,QAAQ,GAAG,UAAU;IAC3F,IAAI,MAA0B,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,SAAS,CAAC;QACR,MAAM,I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C1E,OAAO,QAAkB,CAAC;AAC5B,CAAC"}
@@ -14,6 +14,7 @@ import { type InstanceFactory, type StateInstance } from "./instance.js";
14
14
  import { ServicesHost, type ServiceTick } from "./services.js";
15
15
  import { type MigrationHistory, type SchemaApplied, type SchemaPlan } from "./state-contract.js";
16
16
  import { type OutboxRecord } from "./outbox.js";
17
+ import { OAuthCredentials } from "./oauth-credentials.js";
17
18
  import { type HostCredentials } from "./credentials.js";
18
19
  import { AgentHost, type AgentHooks } from "./agent.js";
19
20
  import { FeltDbIdempotencyStore } from "./idempotency.js";
@@ -169,6 +170,8 @@ export declare class FeltKitRuntime {
169
170
  readonly models: ModelHost;
170
171
  /** HTTP integrations declared with app.integration() (runtime/integrations.ts). */
171
172
  readonly integrations: IntegrationHost;
173
+ /** OAuth 2.0 grants of integrations: renewed, rotated, disconnected (runtime/oauth-credentials.ts). */
174
+ readonly oauth: OAuthCredentials;
172
175
  /** This environment's credential custody (runtime/credentials.ts). One per runtime; survives reload. */
173
176
  readonly credentials: HostCredentials;
174
177
  readonly logger: Logger;
@@ -7,6 +7,7 @@
7
7
  * application definition (functions, capabilities, policy) without reopening state.
8
8
  * close() is idempotent and releases the instance.
9
9
  */
10
+ import { JOB_CONTEXTS_COLLECTION, jobIdOfRun } from "./job-context.js";
10
11
  import { checkTokenBytes } from "./crypto-token.js";
11
12
  import { evaluateAuthorize } from "../authorize.js";
12
13
  import { eventDefinitions, observationAuthorizer, stageEvent } from "./events.js";
@@ -14,7 +15,7 @@ import { AppPortError, createApplication, defineCapability, createMcpBridge, err
14
15
  import { grantsPermission } from "@appport/authorization";
15
16
  import { AsyncLocalStorage } from "node:async_hooks";
16
17
  import { performance } from "node:perf_hooks";
17
- import { createHash, randomBytes, randomUUID } from "node:crypto";
18
+ import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
18
19
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
19
20
  import { dirname, join } from "node:path";
20
21
  import { AGENT_MAX_BACKOFF_MS } from "../app.js";
@@ -26,7 +27,7 @@ import { backupMeta, remoteBackupRefusal } from "./backup-environment.js";
26
27
  import { FeltKitError, isFeltKitError, statusFor } from "../errors.js";
27
28
  import { validate } from "../schema.js";
28
29
  import { ActivityLog, errorSummary } from "./activity.js";
29
- import { Authority, authContext, fromAppPortPrincipal, normalizePrincipal } from "./authority.js";
30
+ import { Authority, authContext, fromAppPortPrincipal, normalizePrincipal, toAppPortPrincipal } from "./authority.js";
30
31
  import { ChangeFeed } from "./changes.js";
31
32
  import { generationDigest } from "./generation.js";
32
33
  import { ModelHost } from "./decisions.js";
@@ -37,6 +38,7 @@ import { explainServiceDenials, ServicesHost } from "./services.js";
37
38
  import { applySchema, blockedHint, describePlan, MIGRATIONS_COLLECTION, planSchema, publicPlan } from "./state-contract.js";
38
39
  import { afterCommit, newOutboxId, OUTBOX_COLLECTION, performEffect } from "./outbox.js";
39
40
  import { claimed, isRecoverable, isSequenceConflict, outboxStore, performOutbox, rescheduled, retried, settled } from "./transactions.js";
41
+ import { OAuthCredentials } from "./oauth-credentials.js";
40
42
  import { credentialsFor, isCustodyError } from "./credentials.js";
41
43
  import { AgentHost } from "./agent.js";
42
44
  import { FeltDbIdempotencyStore } from "./idempotency.js";
@@ -50,6 +52,12 @@ import { accountMail } from "./mail.js";
50
52
  import { ChallengeStore } from "./challenges.js";
51
53
  import { MEMBERSHIPS_COLLECTION, TenancyStore } from "./tenancy.js";
52
54
  import { hasTenantCollections, scopeToTenant } from "./tenant-scope.js";
55
+ /** Tenancy's randomness and HMAC in FeltKit's runtime (an artifact's guest supplies the host's crypto@1 instead). */
56
+ const NODE_TENANCY_CRYPTO = {
57
+ randomHex: (bytes) => randomBytes(bytes).toString("hex"),
58
+ randomBase64url: (bytes) => randomBytes(bytes).toString("base64url"),
59
+ hmacBase64url: (key, data) => createHmac("sha256", key).update(data).digest("base64url"),
60
+ };
53
61
  const consoleLogger = {
54
62
  info: (m, f) => console.log(`[feltkit] ${m}`, f ?? ""),
55
63
  warn: (m, f) => console.warn(`[feltkit] ${m}`, f ?? ""),
@@ -88,6 +96,8 @@ export class FeltKitRuntime {
88
96
  models;
89
97
  /** HTTP integrations declared with app.integration() (runtime/integrations.ts). */
90
98
  integrations;
99
+ /** OAuth 2.0 grants of integrations: renewed, rotated, disconnected (runtime/oauth-credentials.ts). */
100
+ oauth;
91
101
  /** This environment's credential custody (runtime/credentials.ts). One per runtime; survives reload. */
92
102
  credentials;
93
103
  logger;
@@ -125,6 +135,7 @@ export class FeltKitRuntime {
125
135
  this.idempotency = new FeltDbIdempotencyStore(instance.handle("appport.idempotency"));
126
136
  this.models = new ModelHost(this, { env });
127
137
  this.integrations = new IntegrationHost(this);
138
+ this.oauth = new OAuthCredentials(this);
128
139
  try {
129
140
  this.credentials = credentialsFor({
130
141
  environment: environment.name,
@@ -353,7 +364,7 @@ export class FeltKitRuntime {
353
364
  this.accounts = accounts ? new AccountStore(this.instance.handle("feltkit.accounts"), accounts) : null;
354
365
  this.challenges = accounts ? new ChallengeStore(this.instance.handle("feltkit.accounts"), () => this.authSecret()) : null;
355
366
  const tenant = app.options.auth?.tenant;
356
- this.tenancy = tenant ? new TenancyStore(this.instance.handle("feltkit.tenancy"), tenant, () => this.authSecret()) : null;
367
+ this.tenancy = tenant ? new TenancyStore(this.instance.handle("feltkit.tenancy"), tenant, () => this.authSecret(), NODE_TENANCY_CRYPTO) : null;
357
368
  this.mail = accounts?.email ? accountMail({ env: this.#env, development: !this.environment.production, from: accounts.email.from, identity: accounts.email.identity ?? "auth", logger: this.logger }) : null;
358
369
  const config = app.options.services ?? {};
359
370
  const store = this.accounts;
@@ -406,7 +417,8 @@ export class FeltKitRuntime {
406
417
  authority,
407
418
  config,
408
419
  environment: this.environment.name,
409
- resolveDurable: (subjectId) => this.#resolveDurable(subjectId),
420
+ resolveDurable: (subjectId, _kind, runId) => this.#resolveDurable(subjectId, runId),
421
+ withTenant: (principal, tenantId) => this.withTenant(principal, tenantId),
410
422
  runJob: async (fn, payload, principal, runId) => {
411
423
  // The job, not the attempt, is the unit of effect: a re-run (lease expired after the commit) replays the
412
424
  // first commit by its transaction id instead of committing again.
@@ -438,8 +450,10 @@ export class FeltKitRuntime {
438
450
  .filter(([, fn]) => fn.capability)
439
451
  .map(([name, fn]) => this.#capabilityFor(name, fn));
440
452
  for (const integration of app.integrations.values()) {
453
+ // An operation declared `expose: false` is for application code only: not an AppPort capability.
441
454
  for (const op of Object.values(integration.operations))
442
- capabilities.push(this.#integrationCapability(integration, op));
455
+ if ((op.expose ?? integration.expose ?? true) !== false)
456
+ capabilities.push(this.#integrationCapability(integration, op));
443
457
  }
444
458
  const appport = createApplication({
445
459
  application: { id: app.name, name: app.name, version: app.version, ...(app.options.description ? { description: app.options.description } : {}) },
@@ -500,7 +514,13 @@ export class FeltKitRuntime {
500
514
  if (!authContext(this.#authority, principal).has(found.op.access)) {
501
515
  throw new FeltKitError("FORBIDDEN", `${capability} requires ${found.op.access}; ${principal.id} does not hold it.`);
502
516
  }
503
- return this.integrations.invoke(capability, input, { principal, via: "function", ...(options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}) });
517
+ // The operation's declared input is its contract on every path: AppPort validates it for a
518
+ // capability call, and here it is validated for application code, before anything is sent.
519
+ const parsed = validate(found.op.inputSchema, input);
520
+ if (!parsed.ok) {
521
+ throw new FeltKitError("INVALID_ARGUMENT", `Invalid input for ${capability}: ${parsed.issues.map((i) => `${i.path}: ${i.message}`).join("; ")}`, { details: { issues: parsed.issues } });
522
+ }
523
+ return this.integrations.invoke(capability, parsed.value, { principal, via: "function", ...(options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}) });
504
524
  },
505
525
  };
506
526
  }
@@ -679,8 +699,20 @@ export class FeltKitRuntime {
679
699
  * exists and is not revoked holds services.apiKeys.roles; anyone else holds the roles of
680
700
  * their most recent active session. No active session → null, and the work is refused.
681
701
  */
682
- async #resolveDurable(subjectId) {
683
- return this.resolvePrincipal(subjectId);
702
+ async #resolveDurable(subjectId, runId) {
703
+ const principal = await this.resolvePrincipal(subjectId);
704
+ if (!principal || !runId)
705
+ return principal;
706
+ // A job queued in a workspace runs in it, through the live membership only (job-context.ts).
707
+ const context = (await this.instance.handle("app").collection(JOB_CONTEXTS_COLLECTION).get(jobIdOfRun(runId))) ?? null;
708
+ if (!context)
709
+ return principal;
710
+ const inTenant = await this.withTenant(principal, context.tenantId);
711
+ if (inTenant.tenant?.id !== context.tenantId) {
712
+ this.logger.warn(`job ${context.jobId}: ${subjectId} is no longer a member of the workspace it was queued in; refused`, { tenantId: context.tenantId });
713
+ return null;
714
+ }
715
+ return inTenant;
684
716
  }
685
717
  /**
686
718
  * A principal as it is now, by id: a live API key, else the most recent active session.
@@ -765,10 +797,14 @@ export class FeltKitRuntime {
765
797
  performed += 1;
766
798
  continue;
767
799
  }
768
- const principal = await this.#resolveDurable(record.principalId);
800
+ // In the workspace the caller worked in, through the live membership only (no membership: not performed).
801
+ const account = await this.#resolveDurable(record.principalId);
802
+ const inTenant = account && record.tenantId ? await this.withTenant(account, record.tenantId) : account;
803
+ const principal = inTenant && record.tenantId && inTenant.tenant?.id !== record.tenantId ? null : inTenant;
769
804
  if (!principal) {
805
+ const why = account ? `${record.principalId} is no longer a member of the workspace the effect was staged in` : `${record.principalId} could not be resolved to a current principal (no active session or API key)`;
770
806
  await store
771
- .transaction({ operations: [{ collection: OUTBOX_COLLECTION, id: record.id, ifVersion: record.__version, value: settled(record, { ok: false, error: { code: "UNAUTHORIZED", message: `${record.principalId} could not be resolved to a current principal (no active session or API key), so the effect was not performed.` } }, Date.now()) }] })
807
+ .transaction({ operations: [{ collection: OUTBOX_COLLECTION, id: record.id, ifVersion: record.__version, value: settled(record, { ok: false, error: { code: "UNAUTHORIZED", message: `${why}, so the effect was not performed.` } }, Date.now()) }] })
772
808
  .catch(() => undefined);
773
809
  continue;
774
810
  }
@@ -1062,7 +1098,7 @@ export class FeltKitRuntime {
1062
1098
  }
1063
1099
  if (!this.environment.production && this.serverUrl)
1064
1100
  return this.serverUrl.replace(/\/+$/, "");
1065
- throw new FeltKitError("CONFIGURATION", "Set FELTKIT_PUBLIC_URL to the URL people open this app at (https://…): account e-mail links and sign-in providers return there.", {
1101
+ throw new FeltKitError("CONFIGURATION", "Set FELTKIT_PUBLIC_URL to the URL people open this app at (https://…): account e-mail links, sign-in providers and integration connections (OAuth) return there.", {
1066
1102
  hint: "`npx feltkit vercel env` sets it from the recorded deployment.",
1067
1103
  });
1068
1104
  }
@@ -1546,6 +1582,18 @@ export class FeltKitRuntime {
1546
1582
  authority: this.#applicationAuthority(principal, requestId),
1547
1583
  integrations: this.#integrationInvoker(principal),
1548
1584
  agent: {
1585
+ catalog: async () => (await agent.tools(signedIn())).map((t) => ({
1586
+ name: t.name,
1587
+ source: t.source,
1588
+ effect: t.effect,
1589
+ ...(t.description ? { description: t.description } : {}),
1590
+ allowed: t.allowed,
1591
+ ...(t.invoke ? { invoke: t.invoke } : {}),
1592
+ ...(t.approval ? { approval: t.approval } : {}),
1593
+ ...(t.inputSchema ? { inputSchema: t.inputSchema } : {}),
1594
+ ...(t.integration ? { integration: t.integration } : {}),
1595
+ ...(t.readiness ? { readiness: t.readiness } : {}),
1596
+ })),
1549
1597
  tools: async () => {
1550
1598
  const p = signedIn();
1551
1599
  return (await agent.tools(p))
@@ -1708,8 +1756,9 @@ function pick(principal) {
1708
1756
  function argKeys(value) {
1709
1757
  return value && typeof value === "object" ? Object.keys(value) : [];
1710
1758
  }
1759
+ /** As toAppPortPrincipal: the workspace travels with the principal (dropping it ran agent actions with no workspace, G-02). */
1711
1760
  function toAppPort(principal) {
1712
- return { id: principal.id, type: principal.type === "agent" ? "application" : principal.type, attributes: { roles: principal.roles, feltkitType: principal.type } };
1761
+ return toAppPortPrincipal(principal);
1713
1762
  }
1714
1763
  /**
1715
1764
  * HTTP status for the AppPort codes FeltKit itself returns that AppPort's HTTP binding does not
@@ -1742,6 +1791,9 @@ function toAppPortError(error) {
1742
1791
  return new AppPortError("feltkit.FAILED_PRECONDITION", error.message, { retryable: false, details: (error.details ?? null) });
1743
1792
  case "PAYLOAD_TOO_LARGE":
1744
1793
  return appportErrors.payloadTooLarge(error.message);
1794
+ // AppPort's standard code: retryable, with when (details.retryAfterMs) when known.
1795
+ case "RATE_LIMITED":
1796
+ return appportErrors.rateLimited(error.message, (error.details ?? undefined));
1745
1797
  // Not INTERNAL: a caller must be able to tell "may have been applied" from "failed".
1746
1798
  case "OUTCOME_UNKNOWN":
1747
1799
  return new AppPortError("OUTCOME_UNKNOWN", error.message, { retryable: false, details: (error.details ?? null) });