@feltdb/feltkit 0.3.24 → 0.3.26

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 (55) hide show
  1. package/dist/app.d.ts +116 -0
  2. package/dist/app.js +73 -1
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.d.ts +1 -1
  5. package/dist/appboundry/build.js +18 -4
  6. package/dist/appboundry/build.js.map +1 -1
  7. package/dist/appboundry/guest.d.ts +11 -0
  8. package/dist/appboundry/guest.js +20 -0
  9. package/dist/appboundry/guest.js.map +1 -1
  10. package/dist/cli/main.js +59 -2
  11. package/dist/cli/main.js.map +1 -1
  12. package/dist/dashboard/assets/{index-BXTNQAg1.css → index-BehzsQOa.css} +1 -1
  13. package/dist/dashboard/assets/{index-BEjtLLYq.js → index-Clsfddp8.js} +9 -9
  14. package/dist/dashboard/index.html +2 -2
  15. package/dist/docs.d.ts +1 -1
  16. package/dist/docs.js +1 -0
  17. package/dist/docs.js.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/measure/index.d.ts +117 -0
  20. package/dist/measure/index.js +479 -0
  21. package/dist/measure/index.js.map +1 -0
  22. package/dist/platform/deployments.d.ts +1 -1
  23. package/dist/runtime/application-authority.d.ts +54 -0
  24. package/dist/runtime/application-authority.js +55 -0
  25. package/dist/runtime/application-authority.js.map +1 -0
  26. package/dist/runtime/authboundry.d.ts +25 -13
  27. package/dist/runtime/authboundry.js +15 -7
  28. package/dist/runtime/authboundry.js.map +1 -1
  29. package/dist/runtime/browser-inference.d.ts +2 -2
  30. package/dist/runtime/browser-inference.js +2 -2
  31. package/dist/runtime/context.d.ts +51 -0
  32. package/dist/runtime/runtime.js +56 -10
  33. package/dist/runtime/runtime.js.map +1 -1
  34. package/dist/runtime/services.d.ts +34 -0
  35. package/dist/runtime/services.js +58 -1
  36. package/dist/runtime/services.js.map +1 -1
  37. package/dist/runtime/transactions.d.ts +9 -2
  38. package/dist/runtime/transactions.js +14 -4
  39. package/dist/runtime/transactions.js.map +1 -1
  40. package/dist/server/admin.js +20 -2
  41. package/dist/server/admin.js.map +1 -1
  42. package/dist/server/index.js +21 -1
  43. package/dist/server/index.js.map +1 -1
  44. package/dist/server/project.d.ts +2 -0
  45. package/dist/server/project.js +9 -5
  46. package/dist/server/project.js.map +1 -1
  47. package/docs/GUARANTEES.md +10 -0
  48. package/docs/MEASURE.md +144 -0
  49. package/docs/README.md +3 -2
  50. package/docs/TRANSACTIONS.md +46 -0
  51. package/docs/UPSTREAM-GAPS.md +1 -1
  52. package/package.json +6 -6
  53. package/skills/.claude-plugin/marketplace.json +1 -1
  54. package/skills/.claude-plugin/plugin.json +1 -1
  55. package/skills/feltkit-build/SKILL.md +14 -2
@@ -0,0 +1,55 @@
1
+ /**
2
+ * `ctx.authority`: application code asks AuthBoundry through the same implementation FeltKit's
3
+ * platform uses (runtime/authboundry.ts `authBoundryAuthority`), with the application's executor
4
+ * as the asking principal and credentials resolved from custody for the one request.
5
+ */
6
+ import { authBoundryAuthority } from "./authboundry.js";
7
+ const secretId = (ref) => ref.replace(/^credential-ref:/, "");
8
+ /** The configured AuthBoundry origin, or why there is none. Production never uses a development default. */
9
+ export function authorityUrl(config, production, env = process.env) {
10
+ if (typeof config.url === "string")
11
+ return config.url;
12
+ return env[config.url.env] ?? (production ? null : config.url.development ?? null);
13
+ }
14
+ export function applicationAuthority(host) {
15
+ return {
16
+ async decide(request) {
17
+ const config = host.config;
18
+ const executor = config?.executor.principal ?? "";
19
+ const onBehalfOf = request.onBehalfOf ?? null;
20
+ const refused = (outcome, reason) => ({ allowed: false, outcome, decisionId: null, reason, capability: request.capability, executor, onBehalfOf, delegationId: null });
21
+ if (!config)
22
+ return refused("unavailable", "No authority is configured (feltkit({ authority })), so nothing is allowed.");
23
+ if (typeof request.capability !== "string" || !request.capability)
24
+ return refused("invalid", "A capability is required.");
25
+ if (request.onBehalfOf !== undefined && (typeof request.onBehalfOf !== "string" || !request.onBehalfOf.trim()))
26
+ return refused("invalid", "onBehalfOf must be a principal id.");
27
+ const url = authorityUrl(config, host.production, host.env);
28
+ if (!url)
29
+ return refused("unavailable", `AuthBoundry's address is not configured (${typeof config.url === "string" ? "url" : config.url.env}).`);
30
+ const started = Date.now();
31
+ const ask = async (checkCredential, agentCredential) => authBoundryAuthority({ url, application: config.application, checkCredential, enforcementPoint: "feltkit.application", ...(config.timeoutMs ? { timeoutMs: config.timeoutMs } : {}), ...(host.fetch ? { fetch: host.fetch } : {}) }).decide({
32
+ principal: { id: executor, type: config.executor.type ?? "agent" },
33
+ capability: request.capability,
34
+ ...(request.onBehalfOf !== undefined ? { onBehalfOf: request.onBehalfOf } : {}),
35
+ ...(request.resource ? { resource: request.resource } : {}),
36
+ ...(request.context ? { context: request.context } : {}),
37
+ ...(agentCredential ? { agentCredential } : {}),
38
+ });
39
+ let decision;
40
+ try {
41
+ const reference = (ref) => ({ reference: { secretId: secretId(ref), ...(host.tenantId ? { tenantId: host.tenantId } : {}) }, context: { purpose: `authority decision ${request.capability}` } });
42
+ decision = await host.credentials.withSecret(reference(config.checkCredential), (check) => config.executor.credential
43
+ ? host.credentials.withSecret(reference(config.executor.credential), (agent) => ask(check.value, agent.value))
44
+ : ask(check.value));
45
+ }
46
+ catch (error) {
47
+ // A credential that is missing or unreadable is a refusal, named without its value.
48
+ return refused("unavailable", `The authority's credential is unavailable: ${error.message}`);
49
+ }
50
+ host.record?.({ capability: request.capability, executor, onBehalfOf, decision, durationMs: Date.now() - started });
51
+ return { ...decision, capability: request.capability, executor };
52
+ },
53
+ };
54
+ }
55
+ //# sourceMappingURL=application-authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-authority.js","sourceRoot":"","sources":["../../src/runtime/application-authority.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAA0B,MAAM,kBAAkB,CAAC;AA0BhF,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,GAAG,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AAC,OAAO,KAAK,EAAE,CAAC;gBACf,oFAAoF;gBACpF,OAAO,OAAO,CAAC,aAAa,EAAE,8CAA+C,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;YAC1G,CAAC;YACD,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;YACpH,OAAO,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC;QACnE,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -19,23 +19,35 @@ export interface AuthorityDecision {
19
19
  /** allow | deny | unavailable | invalid, and AuthBoundry's reason when it gave one. */
20
20
  outcome: "allow" | "deny" | "unavailable" | "invalid";
21
21
  reason: string | null;
22
+ /** The principal the decision was asked on behalf of (the requester), when it was. */
23
+ onBehalfOf: string | null;
24
+ /** The delegation AuthBoundry decided from, when a delegation decided (an on-behalf allow). */
25
+ delegationId: string | null;
22
26
  }
23
27
  export interface DelegatedAuthority {
24
28
  readonly kind: "authboundry";
25
29
  readonly application: string;
26
- decide(request: {
27
- principal: {
28
- id: string;
29
- type: string;
30
- };
31
- capability: string;
32
- resource?: {
33
- type: string;
34
- id: string;
35
- };
36
- context?: Record<string, string>;
37
- agentCredential?: string;
38
- }): Promise<AuthorityDecision>;
30
+ decide(request: AuthorityRequest): Promise<AuthorityDecision>;
31
+ }
32
+ /**
33
+ * One question to AuthBoundry. `principal` is who asks to act (for delegated work: the executor,
34
+ * an agent); `onBehalfOf`, when present, is whose delegated authority it acts under (the
35
+ * requester). AuthBoundry then decides only from that principal's live delegation for exactly
36
+ * `capability`, never from the executor's own rules.
37
+ */
38
+ export interface AuthorityRequest {
39
+ principal: {
40
+ id: string;
41
+ type: string;
42
+ };
43
+ capability: string;
44
+ onBehalfOf?: string;
45
+ resource?: {
46
+ type: string;
47
+ id: string;
48
+ };
49
+ context?: Record<string, string>;
50
+ agentCredential?: string;
39
51
  }
40
52
  export interface AuthBoundryOptions {
41
53
  /** AuthBoundry's origin. */
@@ -26,9 +26,12 @@ export function authBoundryAuthority(options) {
26
26
  capability: request.capability,
27
27
  mode: "enforce",
28
28
  enforcement_point: options.enforcementPoint ?? "feltkit",
29
+ ...(request.onBehalfOf !== undefined ? { on_behalf_of: request.onBehalfOf } : {}),
29
30
  ...(request.resource ? { resource: request.resource } : {}),
30
31
  ...(request.context ? { context: request.context } : {}),
31
32
  };
33
+ const onBehalfOf = request.onBehalfOf ?? null;
34
+ const result = (r) => ({ ...r, onBehalfOf, delegationId: r.delegationId ?? null });
32
35
  let status;
33
36
  let decision;
34
37
  try {
@@ -49,22 +52,27 @@ export function authBoundryAuthority(options) {
49
52
  }
50
53
  catch (error) {
51
54
  const timedOut = error.name === "TimeoutError" || error.name === "AbortError";
52
- return { allowed: false, decisionId: null, outcome: "unavailable", reason: timedOut ? `AuthBoundry did not decide within ${timeoutMs} ms` : `AuthBoundry is unreachable or answered malformed JSON: ${error.message}` };
55
+ return result({ allowed: false, decisionId: null, outcome: "unavailable", reason: timedOut ? `AuthBoundry did not decide within ${timeoutMs} ms` : `AuthBoundry is unreachable or answered malformed JSON: ${error.message}` });
53
56
  }
54
57
  const reason = decision && typeof decision === "object" && typeof decision.reason === "string" ? decision.reason : null;
55
58
  const decisionId = decision && typeof decision.decision_id === "string" ? decision.decision_id : null;
56
59
  if (status === 400)
57
- return { allowed: false, decisionId, outcome: "invalid", reason: reason ?? "AuthBoundry rejected the request" };
60
+ return result({ allowed: false, decisionId, outcome: "invalid", reason: reason ?? "AuthBoundry rejected the request" });
58
61
  if ([401, 403, 404, 409].includes(status))
59
- return { allowed: false, decisionId, outcome: "deny", reason: reason ?? `AuthBoundry denied the request (${status})` };
62
+ return result({ allowed: false, decisionId, outcome: "deny", reason: reason ?? `AuthBoundry denied the request (${status})` });
60
63
  if (status !== 200 || !decision || typeof decision !== "object")
61
- return { allowed: false, decisionId, outcome: "unavailable", reason: `AuthBoundry could not decide (${status})` };
64
+ return result({ allowed: false, decisionId, outcome: "unavailable", reason: `AuthBoundry could not decide (${status})` });
62
65
  if (decision.decision === "deny")
63
- return { allowed: false, decisionId, outcome: "deny", reason: reason ?? "denied" };
66
+ return result({ allowed: false, decisionId, outcome: "deny", reason: reason ?? "denied" });
64
67
  const exact = decision.decision === "allow" && decision.application_id === body.application_id && decision.principal_id === body.principal_id && decision.capability === body.capability && decision.mode === "enforce" && typeof decision.decision_id === "string";
65
68
  if (!exact)
66
- return { allowed: false, decisionId, outcome: "unavailable", reason: "AuthBoundry returned an unverifiable decision (not an exact allow of this application, principal and capability with a decision id)" };
67
- return { allowed: true, decisionId, outcome: "allow", reason };
69
+ return result({ allowed: false, decisionId, outcome: "unavailable", reason: "AuthBoundry returned an unverifiable decision (not an exact allow of this application, principal and capability with a decision id)" });
70
+ // Acting for someone: the allow must name that same person and the delegation that decided it.
71
+ // An authority that does not understand on_behalf_of would answer for the executor alone.
72
+ if (onBehalfOf !== null && (decision.on_behalf_of !== onBehalfOf || typeof decision.delegation_id !== "string")) {
73
+ return result({ allowed: false, decisionId, outcome: "unavailable", reason: "AuthBoundry returned an allow that is not for this delegator through a delegation (on_behalf_of and delegation_id must be echoed)" });
74
+ }
75
+ return result({ allowed: true, decisionId, outcome: "allow", reason, delegationId: onBehalfOf !== null ? decision.delegation_id : null });
68
76
  },
69
77
  };
70
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"authboundry.js","sourceRoot":"","sources":["../../src/runtime/authboundry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA6BH,MAAM,UAAU,oBAAoB,CAAC,OAA2B;IAC9D,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;IACzC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;IAC5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;IACxC,MAAM,WAAW,GAAG,GAAG,CAAC,+BAA+B,CAAC;IACxD,MAAM,eAAe,GAAG,GAAG,CAAC,oCAAoC,CAAC;IACjE,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,eAAe;QAAE,OAAO,IAAI,CAAC;IAC1D,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,eAAe;QAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,+HAA+H,CAAC,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC;IACzO,OAAO,oBAAoB,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;AACrE,CAAC"}
@@ -28,8 +28,8 @@ import type { FeltKitRuntime } from "./runtime.js";
28
28
  export declare const STUDIO_SETTINGS = "_feltkit_studio";
29
29
  /**
30
30
  * The hosts the weights come from, taken from `@mlc-ai/web-llm`'s own bundle rather than from documentation:
31
- * the model manifest and the WebAssembly libraries are on raw.githubusercontent.com, and the weight shards are on
32
- * Hugging Face, which redirects large files to its CDN.
31
+ * the model manifest (`<model>/resolve/main/mlc-chat-config.json`) and the weight shards are on Hugging Face,
32
+ * which redirects large files to its CDN; the WebAssembly libraries are on raw.githubusercontent.com.
33
33
  */
34
34
  export declare const BROWSER_INFERENCE_HOSTS: readonly string[];
35
35
  export interface BrowserInferenceState {
@@ -4,8 +4,8 @@ export const STUDIO_SETTINGS = "_feltkit_studio";
4
4
  const RECORD_ID = "browser-inference";
5
5
  /**
6
6
  * The hosts the weights come from, taken from `@mlc-ai/web-llm`'s own bundle rather than from documentation:
7
- * the model manifest and the WebAssembly libraries are on raw.githubusercontent.com, and the weight shards are on
8
- * Hugging Face, which redirects large files to its CDN.
7
+ * the model manifest (`<model>/resolve/main/mlc-chat-config.json`) and the weight shards are on Hugging Face,
8
+ * which redirects large files to its CDN; the WebAssembly libraries are on raw.githubusercontent.com.
9
9
  */
10
10
  export const BROWSER_INFERENCE_HOSTS = Object.freeze([
11
11
  "https://huggingface.co",
@@ -91,6 +91,10 @@ export interface MutationCtx {
91
91
  readonly afterCommit: import("./outbox.js").AfterCommit;
92
92
  /** The FeltKit agent, as the caller. */
93
93
  readonly agent: AgentWriter;
94
+ /** AuthBoundry's decision on a capability for this application's executor (`feltkit({ authority })`). */
95
+ readonly authority: ApplicationAuthority;
96
+ /** Call a declared integration operation (`app.integration`) as the caller, its credential resolved server-side. */
97
+ readonly integrations: IntegrationInvoker;
94
98
  /**
95
99
  * Escape hatch: FeltDB access to this application's own collections. Writes made here are not
96
100
  * validated, not part of the mutation's transaction, and not shown as the mutation's writes in
@@ -166,6 +170,53 @@ export interface ActionCtx {
166
170
  } & Record<string, unknown>): void;
167
171
  readonly model: ActionModel;
168
172
  readonly agent: ActionAgent;
173
+ readonly authority: ApplicationAuthority;
174
+ readonly integrations: IntegrationInvoker;
175
+ }
176
+ /**
177
+ * AuthBoundry, asked by application code (`ctx.authority.decide`): the same contract and
178
+ * implementation FeltKit's platform uses (runtime/authboundry.ts). The asking principal is always
179
+ * the application's configured executor (`feltkit({ authority: { executor } })`), never the caller
180
+ * and never a value from arguments: delegated work is the executor acting `onBehalfOf` a
181
+ * requester, decided from that requester's delegation alone. Fail closed: anything but an exact,
182
+ * attributable allow (for an on-behalf request: also naming that requester and a delegation) is
183
+ * `allowed: false`, including an unconfigured, unreachable or slow authority. Credentials are
184
+ * custody references, resolved for the request and never returned, logged or recorded.
185
+ */
186
+ export interface ApplicationAuthority {
187
+ decide(request: {
188
+ capability: string;
189
+ onBehalfOf?: string;
190
+ resource?: {
191
+ type: string;
192
+ id: string;
193
+ };
194
+ context?: Record<string, string>;
195
+ }): Promise<ApplicationAuthorityDecision>;
196
+ }
197
+ export interface ApplicationAuthorityDecision {
198
+ allowed: boolean;
199
+ outcome: "allow" | "deny" | "unavailable" | "invalid";
200
+ decisionId: string | null;
201
+ reason: string | null;
202
+ capability: string;
203
+ /** Who acts: the application's executor principal at AuthBoundry. */
204
+ executor: string;
205
+ /** For whom (the requester), when asked on behalf of someone. */
206
+ onBehalfOf: string | null;
207
+ /** The delegation that decided an on-behalf allow. */
208
+ delegationId: string | null;
209
+ }
210
+ /**
211
+ * `ctx.integrations.invoke("<integration>.<operation>", input)`: the operation's own `access`
212
+ * permission is checked against the caller; its credential reference is resolved only for the
213
+ * request; the call is recorded (before and after it is sent) like an AppPort call of it. Results
214
+ * and errors never carry the credential.
215
+ */
216
+ export interface IntegrationInvoker {
217
+ invoke(capability: string, input: Record<string, unknown>, options?: {
218
+ idempotencyKey?: string;
219
+ }): Promise<unknown>;
169
220
  }
170
221
  export interface ActionModel {
171
222
  /** The environment's model: where it comes from and whether it is ready. Never a secret. */
@@ -19,6 +19,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
19
19
  import { dirname, join } from "node:path";
20
20
  import { AGENT_MAX_BACKOFF_MS } from "../app.js";
21
21
  import { IntegrationHost, integrationDescriptor } from "./integrations.js";
22
+ import { applicationAuthority } from "./application-authority.js";
22
23
  import { verifyStorage } from "./storage-check.js";
23
24
  import { assertNotPartiallyRestored, writeBackup } from "./backup.js";
24
25
  import { backupMeta, remoteBackupRefusal } from "./backup-environment.js";
@@ -419,6 +420,13 @@ export class FeltKitRuntime {
419
420
  if (!result.ok)
420
421
  throw Object.assign(new Error(`${result.error.code}: ${result.error.message}`), { code: result.error.code });
421
422
  },
423
+ // An inbound webhook's handler: the declared mutation, as `integration:<provider>` (no tenant).
424
+ runInbound: async (fn, principal, event) => {
425
+ const result = await this.call(fn, { event }, { principal, via: "integration", requestId: `inbound_${String(event.integrationId)}_${String(event.eventId)}`.slice(0, 200) });
426
+ if (!result.ok)
427
+ throw Object.assign(new Error(`${result.error.code}: ${result.error.message}`), { code: result.error.code });
428
+ return result.value;
429
+ },
422
430
  credentials: this.credentials,
423
431
  ...(config.apiKeys ? { apiKeyVerifierKey: this.#verifierKey() } : {}),
424
432
  // Outside development, webhooks go only to public addresses unless the operator opts in
@@ -454,13 +462,6 @@ export class FeltKitRuntime {
454
462
  const original = appport[method].bind(appport);
455
463
  appport[method] = (request, options = {}) => this.#appportCaller.run({ principal: fromAppPortPrincipal(options?.principal ?? options?.session?.principal) }, () => original(request, options));
456
464
  }
457
- // AppPort's HTTP event stream names every subscription `sub_sse_<index>`, and the application's
458
- // event bus keys subscriptions by that id across connections: a second client's subscription
459
- // replaces the first's, which then stops receiving events (docs/UPSTREAM-GAPS.md A10). Each
460
- // subscription gets a bus id of its own; the connection still echoes the client's id on delivery.
461
- let busSubscriptions = 0;
462
- const subscribe = appport.subscribe.bind(appport);
463
- appport.subscribe = (filter, listener, id) => subscribe(filter, listener, id === undefined ? id : `${id}#${++busSubscriptions}`);
464
465
  this.#project = project;
465
466
  this.#authority = authority;
466
467
  this.#services = services;
@@ -468,6 +469,41 @@ export class FeltKitRuntime {
468
469
  this.#resolver = new CollectionResolver(app.collections);
469
470
  this.#generation += 1;
470
471
  }
472
+ /** `ctx.authority`: AuthBoundry through the shared adapter, as the application's executor; each decision recorded (never a credential). */
473
+ #applicationAuthority(principal, requestId) {
474
+ return applicationAuthority({
475
+ config: this.app.options.authority,
476
+ production: this.environment.production,
477
+ credentials: this.services.credentials,
478
+ tenantId: this.services.scope.tenantId,
479
+ record: ({ capability, executor, onBehalfOf, decision, durationMs }) => this.activity.record({
480
+ kind: "auth",
481
+ name: "authority.decide",
482
+ via: "runtime",
483
+ requestId,
484
+ principal: principal ? { id: principal.id, type: principal.type, roles: principal.roles } : null,
485
+ outcome: decision.allowed ? "success" : decision.outcome === "deny" ? "denied" : "error",
486
+ durationMs,
487
+ detail: { capability, executor, onBehalfOf, outcome: decision.outcome, decisionId: decision.decisionId, delegationId: decision.delegationId, reason: decision.reason },
488
+ }),
489
+ });
490
+ }
491
+ /** `ctx.integrations`: a declared integration operation, as the caller, under the operation's own permission. */
492
+ #integrationInvoker(principal) {
493
+ return {
494
+ invoke: async (capability, input, options = {}) => {
495
+ const found = this.integrations.operationFor(capability);
496
+ if (!found)
497
+ throw new FeltKitError("NOT_FOUND", `${capability} is not an integration operation.`);
498
+ if (!principal)
499
+ throw new FeltKitError("UNAUTHORIZED", `${capability} needs an authenticated caller.`);
500
+ if (!authContext(this.#authority, principal).has(found.op.access)) {
501
+ throw new FeltKitError("FORBIDDEN", `${capability} requires ${found.op.access}; ${principal.id} does not hold it.`);
502
+ }
503
+ return this.integrations.invoke(capability, input, { principal, via: "function", ...(options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}) });
504
+ },
505
+ };
506
+ }
471
507
  /** An integration operation as an AppPort capability: AppPort validates and authorizes; IntegrationHost calls and records. */
472
508
  #integrationCapability(integration, op) {
473
509
  return defineCapability({
@@ -872,10 +908,16 @@ export class FeltKitRuntime {
872
908
  * its `on`). It records the tenant the caller worked in; whether the agent may work there is
873
909
  * decided when it runs, from the agent's own membership.
874
910
  */
875
- #agentEffect(name, input, principal, event) {
911
+ #agentEffect(name, input, principal, event, tenant) {
876
912
  if (!this.app.agents.has(name))
877
913
  throw new FeltKitError("INVALID_ARGUMENT", `No application agent named "${name}".`, { hint: `Declare it with app.agent("${name}", { principal, roles, handler }).` });
878
- return { service: "agent", method: "run", agent: name, input, ...(principal?.tenant ? { tenantId: principal.tenant.id } : {}), ...(event ? { event } : {}) };
914
+ // A caller in a tenant triggers the agent there; one in none (an inbound webhook) may name the
915
+ // tenant to ask for. Either way the agent works there only while it is a member itself.
916
+ if (tenant !== undefined && principal?.tenant && principal.tenant.id !== tenant) {
917
+ throw new FeltKitError("FORBIDDEN", `afterCommit.agent: a caller working in a tenant may not trigger "${name}" in another one.`);
918
+ }
919
+ const tenantId = principal?.tenant?.id ?? tenant;
920
+ return { service: "agent", method: "run", agent: name, input, ...(tenantId ? { tenantId } : {}), ...(event ? { event } : {}) };
879
921
  }
880
922
  /** Start an agent run now, without making the triggering call wait for it. */
881
923
  #dispatchAgent(id) {
@@ -1255,6 +1297,8 @@ export class FeltKitRuntime {
1255
1297
  requestId,
1256
1298
  log: this.logger,
1257
1299
  crypto: { token: async (bytes) => randomBytes(checkTokenBytes(bytes)).toString("base64url") },
1300
+ authority: this.#applicationAuthority(principal, requestId),
1301
+ integrations: this.#integrationInvoker(principal),
1258
1302
  };
1259
1303
  const starts = [];
1260
1304
  const agent = {
@@ -1277,7 +1321,7 @@ export class FeltKitRuntime {
1277
1321
  enabled: { notifications: Boolean(enabled.notifications), webhooks: Boolean(enabled.webhooks), jobs: Boolean(enabled.jobs) },
1278
1322
  stage: (record) => db.stageSystem(OUTBOX_COLLECTION, record),
1279
1323
  newId: newOutboxId,
1280
- agent: (agentName, input) => this.#agentEffect(agentName, input, principal, triggeringEvent),
1324
+ agent: (agentName, input, tenant) => this.#agentEffect(agentName, input, principal, triggeringEvent, tenant),
1281
1325
  work: (component, kind, input, opts) => {
1282
1326
  if (!this.app.options.components?.[component])
1283
1327
  throw new FeltKitError("INVALID_ARGUMENT", `afterCommit.work: "${component}" is not a component of this application.`, { hint: "Declare it in feltkit({ components })." });
@@ -1499,6 +1543,8 @@ export class FeltKitRuntime {
1499
1543
  return { ...result, receipt, memoryId, generationId: handle.generationId };
1500
1544
  },
1501
1545
  },
1546
+ authority: this.#applicationAuthority(principal, requestId),
1547
+ integrations: this.#integrationInvoker(principal),
1502
1548
  agent: {
1503
1549
  tools: async () => {
1504
1550
  const p = signedIn();