@feltdb/feltkit 0.3.29 → 0.3.30
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/app.d.ts +74 -2
- package/dist/app.js +95 -1
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest-tenancy.d.ts +2 -2
- package/dist/appboundry/guest-tenancy.js.map +1 -1
- package/dist/appboundry/guest.js +4 -1
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.js +3 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/authorize.d.ts +23 -1
- package/dist/authorize.js +37 -0
- package/dist/authorize.js.map +1 -1
- package/dist/cli/deploy-appboundry.d.ts +1 -1
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +27 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/skills.js.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/dashboard/assets/index-9rMS3yBm.js +15 -0
- package/dist/dashboard/assets/index-DkiYTUMR.css +1 -0
- package/dist/dashboard/index.html +2 -2
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +3 -0
- package/dist/docs.js.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/event-stage.js.map +1 -1
- package/dist/execution.d.ts +186 -0
- package/dist/execution.js +105 -0
- package/dist/execution.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/measure/index.js.map +1 -1
- package/dist/platform/approvals.js.map +1 -1
- package/dist/platform/artifacts.js.map +1 -1
- package/dist/platform/changes.d.ts +54 -54
- package/dist/platform/changes.js.map +1 -1
- package/dist/platform/deployments.d.ts +32 -32
- package/dist/platform/exec.js.map +1 -1
- package/dist/platform/platform.js.map +1 -1
- package/dist/platform/releases.js.map +1 -1
- package/dist/platform/server.js.map +1 -1
- package/dist/platform/workspaces.js.map +1 -1
- package/dist/react/auth.d.ts +10 -10
- package/dist/react/auth.js +1 -1
- package/dist/react/auth.js.map +1 -1
- package/dist/react/context.d.ts +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/accounts.js.map +1 -1
- package/dist/runtime/activity.d.ts +1 -1
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/agent.d.ts +3 -3
- package/dist/runtime/agent.js +9 -3
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/application-authority.d.ts +13 -2
- package/dist/runtime/application-authority.js +18 -6
- package/dist/runtime/application-authority.js.map +1 -1
- package/dist/runtime/audit.js.map +1 -1
- package/dist/runtime/authboundry.d.ts +17 -0
- package/dist/runtime/authboundry.js +8 -1
- package/dist/runtime/authboundry.js.map +1 -1
- package/dist/runtime/authority.d.ts +10 -0
- package/dist/runtime/authority.js +17 -0
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/backup-environment.js.map +1 -1
- package/dist/runtime/backup.js.map +1 -1
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/claims.js.map +1 -1
- package/dist/runtime/collections.js.map +1 -1
- package/dist/runtime/content.d.ts +27 -2
- package/dist/runtime/content.js +55 -5
- package/dist/runtime/content.js.map +1 -1
- package/dist/runtime/context.d.ts +153 -0
- package/dist/runtime/contract.js +5 -1
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/credentials.d.ts +31 -2
- package/dist/runtime/credentials.js +55 -3
- package/dist/runtime/credentials.js.map +1 -1
- package/dist/runtime/crypto-token.js.map +1 -1
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/deployment.js.map +1 -1
- package/dist/runtime/execution-host.d.ts +54 -0
- package/dist/runtime/execution-host.js +54 -0
- package/dist/runtime/execution-host.js.map +1 -0
- package/dist/runtime/generation.js.map +1 -1
- package/dist/runtime/instance.js.map +1 -1
- package/dist/runtime/integrations.d.ts +8 -6
- package/dist/runtime/integrations.js +48 -5
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/invocations.d.ts +313 -0
- package/dist/runtime/invocations.js +493 -0
- package/dist/runtime/invocations.js.map +1 -0
- package/dist/runtime/loader.js.map +1 -1
- package/dist/runtime/local-authority.d.ts +50 -0
- package/dist/runtime/local-authority.js +214 -0
- package/dist/runtime/local-authority.js.map +1 -0
- package/dist/runtime/oauth-credentials.d.ts +40 -3
- package/dist/runtime/oauth-credentials.js +133 -25
- package/dist/runtime/oauth-credentials.js.map +1 -1
- package/dist/runtime/outbox.js +3 -0
- package/dist/runtime/outbox.js.map +1 -1
- package/dist/runtime/projects.d.ts +1 -1
- package/dist/runtime/readiness.js +11 -0
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +48 -5
- package/dist/runtime/runtime.js +139 -17
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +37 -0
- package/dist/runtime/services.js +191 -3
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/state-contract.js.map +1 -1
- package/dist/runtime/storage-check.js.map +1 -1
- package/dist/runtime/targets.d.ts +1 -1
- package/dist/runtime/tenancy.js.map +1 -1
- package/dist/runtime/transactions.d.ts +15 -0
- package/dist/runtime/transactions.js +5 -0
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/schema.js.map +1 -1
- package/dist/server/admin.d.ts +51 -51
- package/dist/server/admin.js +11 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/components.js.map +1 -1
- package/dist/server/index.js +39 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/management.js.map +1 -1
- package/dist/server/mcp.d.ts +59 -37
- package/dist/server/mcp.js +24 -1
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/operators.js.map +1 -1
- package/dist/server/ports.d.ts +7 -0
- package/dist/server/ports.js +17 -0
- package/dist/server/ports.js.map +1 -1
- package/dist/server/production.js.map +1 -1
- package/dist/server/project.js.map +1 -1
- package/dist/server/session-http.js.map +1 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/surfaces.d.ts +153 -0
- package/dist/surfaces.js +228 -0
- package/dist/surfaces.js.map +1 -0
- package/dist/testing/index.js.map +1 -1
- package/docs/CONNECTIONS.md +151 -0
- package/docs/EXECUTION.md +271 -0
- package/docs/GUARANTEES.md +54 -2
- package/docs/INVOCATIONS.md +170 -0
- package/docs/README.md +5 -2
- package/package.json +19 -15
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
- package/dist/dashboard/assets/index-BehzsQOa.css +0 -1
- package/dist/dashboard/assets/index-UuZ63NA6.js +0 -15
|
@@ -15,6 +15,9 @@ 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
17
|
import { OAuthCredentials } from "./oauth-credentials.js";
|
|
18
|
+
import { InvocationStore } from "./invocations.js";
|
|
19
|
+
import { ExecutionHost } from "./execution-host.js";
|
|
20
|
+
import { LocalAuthorityHost } from "./local-authority.js";
|
|
18
21
|
import { type HostCredentials } from "./credentials.js";
|
|
19
22
|
import { AgentHost, type AgentHooks } from "./agent.js";
|
|
20
23
|
import { FeltDbIdempotencyStore } from "./idempotency.js";
|
|
@@ -172,6 +175,12 @@ export declare class FeltKitRuntime {
|
|
|
172
175
|
readonly integrations: IntegrationHost;
|
|
173
176
|
/** OAuth 2.0 grants of integrations: renewed, rotated, disconnected (runtime/oauth-credentials.ts). */
|
|
174
177
|
readonly oauth: OAuthCredentials;
|
|
178
|
+
/** Durable invocations from registered surfaces: lifecycle, dispatch, recovery (runtime/invocations.ts). */
|
|
179
|
+
readonly invocations: InvocationStore;
|
|
180
|
+
/** Where work runs: the registered execution environments, the placement policy and resolver (runtime/execution-host.ts). Grants no authority. */
|
|
181
|
+
readonly execution: ExecutionHost;
|
|
182
|
+
/** A private AuthBoundry (authority.local), when this application asks for one. */
|
|
183
|
+
readonly localAuthority: LocalAuthorityHost;
|
|
175
184
|
/** This environment's credential custody (runtime/credentials.ts). One per runtime; survives reload. */
|
|
176
185
|
readonly credentials: HostCredentials;
|
|
177
186
|
readonly logger: Logger;
|
|
@@ -214,6 +223,23 @@ export declare class FeltKitRuntime {
|
|
|
214
223
|
/** Evolutions applied to this store, newest first. */
|
|
215
224
|
schemaHistory(): Promise<MigrationHistory[]>;
|
|
216
225
|
reload(project: LoadedProject): Promise<void>;
|
|
226
|
+
/** One AuthBoundry decision as the application's executor (a person's connection: runtime/integrations.ts). Recorded like ctx.authority's. */
|
|
227
|
+
decideAsExecutor(principal: Principal | null, requestId: string, request: {
|
|
228
|
+
capability: string;
|
|
229
|
+
onBehalfOf: string;
|
|
230
|
+
context?: Record<string, string>;
|
|
231
|
+
}): Promise<import("./context.js").ApplicationAuthorityDecision>;
|
|
232
|
+
/** `ctx.integrations`: a declared integration operation, as the caller, under the operation's own permission. */
|
|
233
|
+
/**
|
|
234
|
+
* `ctx.invocations`: the platform invocation store, as the caller. `accept` exists only in a mutation
|
|
235
|
+
* (`staging`): the record and its dispatch commit with the mutation's writes.
|
|
236
|
+
*/
|
|
237
|
+
/** This process as a worker: what attempts it runs record as their worker (evidence, never authority). */
|
|
238
|
+
get workerId(): string;
|
|
239
|
+
/** The access a function declares (`app.mutation({ access })`), or undefined when there is no such function. */
|
|
240
|
+
functionAccess(name: string): string | undefined;
|
|
241
|
+
/** Whether `principal` holds `access` under this application's roles ("public" and "authenticated" as functions treat them). */
|
|
242
|
+
holds(principal: Principal | null, access: string): boolean;
|
|
217
243
|
/** Run `work` as the execution of an approved action (called by the agent lifecycle only). */
|
|
218
244
|
runApproved<T>(action: ApprovedAction, work: () => Promise<T>): Promise<T>;
|
|
219
245
|
functions(): FunctionInfo[];
|
|
@@ -277,6 +303,23 @@ export declare class FeltKitRuntime {
|
|
|
277
303
|
state?: OutboxRecord["state"];
|
|
278
304
|
limit?: number;
|
|
279
305
|
}): Promise<OutboxRecord[]>;
|
|
306
|
+
/**
|
|
307
|
+
* Stored file bytes no live file record references (ServicesHost.orphanedContent). With
|
|
308
|
+
* `release`, each is reclaimed as a recorded byte release (outbox effect `files.release`), kept
|
|
309
|
+
* as evidence like any other: `feltkit outbox reclaim-files [--release]`.
|
|
310
|
+
*/
|
|
311
|
+
fileOrphans(options?: {
|
|
312
|
+
release?: {
|
|
313
|
+
by: string;
|
|
314
|
+
};
|
|
315
|
+
}): Promise<{
|
|
316
|
+
orphans: Array<{
|
|
317
|
+
storageKey: string;
|
|
318
|
+
storedAt?: number;
|
|
319
|
+
size: number;
|
|
320
|
+
}>;
|
|
321
|
+
released: OutboxRecord[];
|
|
322
|
+
}>;
|
|
280
323
|
/**
|
|
281
324
|
* An operator's retry of a failed after-commit effect: back to pending (attempts and last error
|
|
282
325
|
* kept), then performed now as its caller, or by the worker if that caller cannot be resolved.
|
|
@@ -373,9 +416,6 @@ export declare class FeltKitRuntime {
|
|
|
373
416
|
development: boolean;
|
|
374
417
|
};
|
|
375
418
|
instance: {
|
|
376
|
-
storage: string;
|
|
377
|
-
location: string;
|
|
378
|
-
sequence: number;
|
|
379
419
|
environment: string;
|
|
380
420
|
mode: "local" | "remote" | "memory";
|
|
381
421
|
namespace: string;
|
|
@@ -384,11 +424,14 @@ export declare class FeltKitRuntime {
|
|
|
384
424
|
durable: boolean;
|
|
385
425
|
openedAt: string;
|
|
386
426
|
pid: number;
|
|
427
|
+
storage: string;
|
|
428
|
+
location: string;
|
|
429
|
+
sequence: number;
|
|
387
430
|
};
|
|
388
431
|
collections: {
|
|
389
|
-
description?: string | undefined;
|
|
390
432
|
name: string;
|
|
391
433
|
schema: import("@appport/protocol").JSONSchema;
|
|
434
|
+
description?: string | undefined;
|
|
392
435
|
}[];
|
|
393
436
|
functions: FunctionInfo[];
|
|
394
437
|
roles: Readonly<Record<string, readonly string[]>>;
|
|
@@ -401,7 +444,7 @@ export declare class FeltKitRuntime {
|
|
|
401
444
|
requestId: string;
|
|
402
445
|
}[];
|
|
403
446
|
activity: {
|
|
404
|
-
mode: "
|
|
447
|
+
mode: "all" | "errors" | "writes";
|
|
405
448
|
lastError: {
|
|
406
449
|
at: string;
|
|
407
450
|
message: string;
|
package/dist/runtime/runtime.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { JOB_CONTEXTS_COLLECTION, jobIdOfRun } from "./job-context.js";
|
|
11
11
|
import { checkTokenBytes } from "./crypto-token.js";
|
|
12
|
-
import { evaluateAuthorize } from "../authorize.js";
|
|
12
|
+
import { evaluateAuthorize, evaluateOwnership } from "../authorize.js";
|
|
13
13
|
import { eventDefinitions, observationAuthorizer, stageEvent } from "./events.js";
|
|
14
14
|
import { AppPortError, createApplication, defineCapability, createMcpBridge, errors as appportErrors, idempotencyStorageKey } from "@appport/sdk";
|
|
15
15
|
import { grantsPermission } from "@appport/authorization";
|
|
@@ -39,6 +39,9 @@ import { applySchema, blockedHint, describePlan, MIGRATIONS_COLLECTION, planSche
|
|
|
39
39
|
import { afterCommit, newOutboxId, OUTBOX_COLLECTION, performEffect } from "./outbox.js";
|
|
40
40
|
import { claimed, isRecoverable, isSequenceConflict, outboxStore, performOutbox, rescheduled, retried, settled } from "./transactions.js";
|
|
41
41
|
import { OAuthCredentials } from "./oauth-credentials.js";
|
|
42
|
+
import { INVOCATIONS_COLLECTION, InvocationStore } from "./invocations.js";
|
|
43
|
+
import { ExecutionHost } from "./execution-host.js";
|
|
44
|
+
import { LocalAuthorityHost } from "./local-authority.js";
|
|
42
45
|
import { credentialsFor, isCustodyError } from "./credentials.js";
|
|
43
46
|
import { AgentHost } from "./agent.js";
|
|
44
47
|
import { FeltDbIdempotencyStore } from "./idempotency.js";
|
|
@@ -102,6 +105,12 @@ export class FeltKitRuntime {
|
|
|
102
105
|
integrations;
|
|
103
106
|
/** OAuth 2.0 grants of integrations: renewed, rotated, disconnected (runtime/oauth-credentials.ts). */
|
|
104
107
|
oauth;
|
|
108
|
+
/** Durable invocations from registered surfaces: lifecycle, dispatch, recovery (runtime/invocations.ts). */
|
|
109
|
+
invocations;
|
|
110
|
+
/** Where work runs: the registered execution environments, the placement policy and resolver (runtime/execution-host.ts). Grants no authority. */
|
|
111
|
+
execution = new ExecutionHost();
|
|
112
|
+
/** A private AuthBoundry (authority.local), when this application asks for one. */
|
|
113
|
+
localAuthority;
|
|
105
114
|
/** This environment's credential custody (runtime/credentials.ts). One per runtime; survives reload. */
|
|
106
115
|
credentials;
|
|
107
116
|
logger;
|
|
@@ -140,6 +149,8 @@ export class FeltKitRuntime {
|
|
|
140
149
|
this.models = new ModelHost(this, { env });
|
|
141
150
|
this.integrations = new IntegrationHost(this);
|
|
142
151
|
this.oauth = new OAuthCredentials(this);
|
|
152
|
+
this.invocations = new InvocationStore(this);
|
|
153
|
+
this.localAuthority = new LocalAuthorityHost(this);
|
|
143
154
|
try {
|
|
144
155
|
this.credentials = credentialsFor({
|
|
145
156
|
environment: environment.name,
|
|
@@ -209,6 +220,7 @@ export class FeltKitRuntime {
|
|
|
209
220
|
}
|
|
210
221
|
await runtime.integrations.refreshConfiguration();
|
|
211
222
|
await runtime.credentials.refresh();
|
|
223
|
+
await runtime.localAuthority.start();
|
|
212
224
|
runtime.activity.record({
|
|
213
225
|
kind: "system",
|
|
214
226
|
name: "runtime.started",
|
|
@@ -420,6 +432,7 @@ export class FeltKitRuntime {
|
|
|
420
432
|
const services = new ServicesHost({
|
|
421
433
|
servicesDb: this.instance.handle("appport-services"),
|
|
422
434
|
contentDb: this.instance.handle("feltkit.files"),
|
|
435
|
+
outboxDb: this.instance.handle("app"),
|
|
423
436
|
applicationId: app.name,
|
|
424
437
|
authority,
|
|
425
438
|
config,
|
|
@@ -490,6 +503,10 @@ export class FeltKitRuntime {
|
|
|
490
503
|
this.#resolver = new CollectionResolver(app.collections);
|
|
491
504
|
this.#generation += 1;
|
|
492
505
|
}
|
|
506
|
+
/** One AuthBoundry decision as the application's executor (a person's connection: runtime/integrations.ts). Recorded like ctx.authority's. */
|
|
507
|
+
decideAsExecutor(principal, requestId, request) {
|
|
508
|
+
return this.#applicationAuthority(principal, requestId).decide(request);
|
|
509
|
+
}
|
|
493
510
|
/** `ctx.authority`: AuthBoundry through the shared adapter, as the application's executor; each decision recorded (never a credential). */
|
|
494
511
|
#applicationAuthority(principal, requestId) {
|
|
495
512
|
return applicationAuthority({
|
|
@@ -499,21 +516,86 @@ export class FeltKitRuntime {
|
|
|
499
516
|
tenantId: this.services.scope.tenantId,
|
|
500
517
|
appName: this.app.name,
|
|
501
518
|
env: this.#env,
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
519
|
+
localUrl: () => this.localAuthority.url(),
|
|
520
|
+
grants: this.localAuthority.grantsFor(principal, requestId),
|
|
521
|
+
record: async ({ capability, executor, onBehalfOf, decision, durationMs }) => {
|
|
522
|
+
await this.invocations.noteDecision(requestId, { capability, onBehalfOf, outcome: decision.outcome, decisionId: decision.decisionId, delegationId: decision.delegationId, executor: decision.executorProof });
|
|
523
|
+
this.activity.record({
|
|
524
|
+
kind: "auth",
|
|
525
|
+
name: "authority.decide",
|
|
526
|
+
via: "runtime",
|
|
527
|
+
requestId,
|
|
528
|
+
principal: principal ? { id: principal.id, type: principal.type, roles: principal.roles } : null,
|
|
529
|
+
outcome: decision.allowed ? "success" : decision.outcome === "deny" ? "denied" : "error",
|
|
530
|
+
durationMs,
|
|
531
|
+
detail: { capability, executor, onBehalfOf, outcome: decision.outcome, decisionId: decision.decisionId, delegationId: decision.delegationId, reason: decision.reason, executorProof: decision.executorProof },
|
|
532
|
+
});
|
|
533
|
+
},
|
|
512
534
|
});
|
|
513
535
|
}
|
|
514
536
|
/** `ctx.integrations`: a declared integration operation, as the caller, under the operation's own permission. */
|
|
537
|
+
/**
|
|
538
|
+
* `ctx.invocations`: the platform invocation store, as the caller. `accept` exists only in a mutation
|
|
539
|
+
* (`staging`): the record and its dispatch commit with the mutation's writes.
|
|
540
|
+
*/
|
|
541
|
+
/** This process as a worker: what attempts it runs record as their worker (evidence, never authority). */
|
|
542
|
+
get workerId() {
|
|
543
|
+
return `${this.app.name}:${process.pid}`;
|
|
544
|
+
}
|
|
545
|
+
/** The access a function declares (`app.mutation({ access })`), or undefined when there is no such function. */
|
|
546
|
+
functionAccess(name) {
|
|
547
|
+
return this.#project.functions.get(name)?.access;
|
|
548
|
+
}
|
|
549
|
+
/** Whether `principal` holds `access` under this application's roles ("public" and "authenticated" as functions treat them). */
|
|
550
|
+
holds(principal, access) {
|
|
551
|
+
if (access === "public")
|
|
552
|
+
return true;
|
|
553
|
+
if (!principal)
|
|
554
|
+
return false;
|
|
555
|
+
if (access === "authenticated")
|
|
556
|
+
return true;
|
|
557
|
+
return grantsPermission(this.#authority.permissionsFor(principal), access);
|
|
558
|
+
}
|
|
559
|
+
#invocationsApi(principal, staging, origin = { via: "runtime", requestId: null }) {
|
|
560
|
+
const store = this.invocations;
|
|
561
|
+
return {
|
|
562
|
+
accept: (input) => {
|
|
563
|
+
if (!staging)
|
|
564
|
+
throw new FeltKitError("FAILED_PRECONDITION", "ctx.invocations.accept runs in a mutation: the record and its dispatch commit together.");
|
|
565
|
+
return store.accept({ principal, ...staging }, input);
|
|
566
|
+
},
|
|
567
|
+
get: (id) => store.get(principal, id),
|
|
568
|
+
list: (filter) => store.list(principal, filter),
|
|
569
|
+
start: (id, options) => store.start(principal, id, options, origin),
|
|
570
|
+
progress: (id, options) => store.progress(principal, id, options),
|
|
571
|
+
resume: (id, options) => store.resume(principal, id, options, origin),
|
|
572
|
+
transition: (id, to, options) => store.transition(principal, id, to, options),
|
|
573
|
+
cancel: (id, options) => store.cancel(principal, id, options),
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
/** Connections are a signed-in person's own. */
|
|
577
|
+
#connectionOwner(principal) {
|
|
578
|
+
if (!principal || principal.type !== "user")
|
|
579
|
+
throw new FeltKitError("FORBIDDEN", "Connections belong to a signed-in person, who manages only their own.");
|
|
580
|
+
return principal.id;
|
|
581
|
+
}
|
|
515
582
|
#integrationInvoker(principal) {
|
|
516
583
|
return {
|
|
584
|
+
connections: {
|
|
585
|
+
list: async () => this.oauth.connections(this.#connectionOwner(principal)),
|
|
586
|
+
connect: async (integration) => {
|
|
587
|
+
this.#connectionOwner(principal);
|
|
588
|
+
const i = this.app.integrations.get(integration);
|
|
589
|
+
if (!i || !OAuthCredentials.personal(i))
|
|
590
|
+
throw new FeltKitError("NOT_FOUND", `${integration} is not connected per person (credential.owner: "person").`);
|
|
591
|
+
const { url, expiresAt } = await this.oauth.connect(integration, principal, "function");
|
|
592
|
+
return { url, expiresAt };
|
|
593
|
+
},
|
|
594
|
+
disconnect: async (integration) => {
|
|
595
|
+
this.#connectionOwner(principal);
|
|
596
|
+
return this.oauth.disconnect(integration, principal);
|
|
597
|
+
},
|
|
598
|
+
},
|
|
517
599
|
invoke: async (capability, input, options = {}) => {
|
|
518
600
|
const found = this.integrations.operationFor(capability);
|
|
519
601
|
if (!found)
|
|
@@ -529,7 +611,7 @@ export class FeltKitRuntime {
|
|
|
529
611
|
if (!parsed.ok) {
|
|
530
612
|
throw new FeltKitError("INVALID_ARGUMENT", `Invalid input for ${capability}: ${parsed.issues.map((i) => `${i.path}: ${i.message}`).join("; ")}`, { details: { issues: parsed.issues } });
|
|
531
613
|
}
|
|
532
|
-
return this.integrations.invoke(capability, parsed.value, { principal, via: "function", ...(options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}) });
|
|
614
|
+
return this.integrations.invoke(capability, parsed.value, { principal, via: "function", ...(options.idempotencyKey ? { idempotencyKey: options.idempotencyKey } : {}), ...(options.onBehalfOf !== undefined ? { onBehalfOf: options.onBehalfOf } : {}) });
|
|
533
615
|
},
|
|
534
616
|
};
|
|
535
617
|
}
|
|
@@ -776,6 +858,8 @@ export class FeltKitRuntime {
|
|
|
776
858
|
async #performOutbox(record, services, principal, requestId) {
|
|
777
859
|
if (record.effect.service === "agent")
|
|
778
860
|
return this.#runAgent(record.id);
|
|
861
|
+
if (record.effect.service === "files")
|
|
862
|
+
return this.#services.releaseFile(record.id);
|
|
779
863
|
return performOutbox(outboxStore(this.instance.handle("app")), record.id, (claim, complete) => {
|
|
780
864
|
const effect = claim.effect;
|
|
781
865
|
// A job or webhook event is created in the transaction that records it done; a notification is sent directly.
|
|
@@ -806,6 +890,13 @@ export class FeltKitRuntime {
|
|
|
806
890
|
performed += 1;
|
|
807
891
|
continue;
|
|
808
892
|
}
|
|
893
|
+
// A byte release needs no caller: it reads as FeltKit's file-release principal, and releases only
|
|
894
|
+
// bytes whose file is already deleted (the caller's decision, made when the metadata was deleted).
|
|
895
|
+
if (record.effect.service === "files") {
|
|
896
|
+
if ((await this.#services.releaseFile(record.id, () => now)) === "done")
|
|
897
|
+
performed += 1;
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
809
900
|
// In the workspace the caller worked in, through the live membership only (no membership: not performed).
|
|
810
901
|
const account = await this.#resolveDurable(record.principalId);
|
|
811
902
|
const inTenant = account && record.tenantId ? await this.withTenant(account, record.tenantId) : account;
|
|
@@ -910,6 +1001,23 @@ export class FeltKitRuntime {
|
|
|
910
1001
|
.sort((a, b) => b.createdAt - a.createdAt)
|
|
911
1002
|
.slice(0, filter.limit ?? 100);
|
|
912
1003
|
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Stored file bytes no live file record references (ServicesHost.orphanedContent). With
|
|
1006
|
+
* `release`, each is reclaimed as a recorded byte release (outbox effect `files.release`), kept
|
|
1007
|
+
* as evidence like any other: `feltkit outbox reclaim-files [--release]`.
|
|
1008
|
+
*/
|
|
1009
|
+
async fileOrphans(options = {}) {
|
|
1010
|
+
this.#assertReady();
|
|
1011
|
+
if (!this.#services.files)
|
|
1012
|
+
return { orphans: [], released: [] };
|
|
1013
|
+
const orphans = await this.#services.orphanedContent();
|
|
1014
|
+
if (!options.release)
|
|
1015
|
+
return { orphans, released: [] };
|
|
1016
|
+
const ids = await this.#services.reclaimOrphanedContent(options.release.by);
|
|
1017
|
+
const outbox = this.instance.handle("app").collection(OUTBOX_COLLECTION);
|
|
1018
|
+
const released = await Promise.all(ids.map(async (id) => { const { __version: _v, ...r } = (await outbox.get(id)); return r; }));
|
|
1019
|
+
return { orphans, released };
|
|
1020
|
+
}
|
|
913
1021
|
/**
|
|
914
1022
|
* An operator's retry of a failed after-commit effect: back to pending (attempts and last error
|
|
915
1023
|
* kept), then performed now as its caller, or by the worker if that caller cannot be resolved.
|
|
@@ -928,8 +1036,8 @@ export class FeltKitRuntime {
|
|
|
928
1036
|
catch {
|
|
929
1037
|
throw new FeltKitError("CONFLICT", `After-commit effect ${id} changed while it was being retried. Nothing was changed; read it again.`);
|
|
930
1038
|
}
|
|
931
|
-
if (record.effect.service === "agent") {
|
|
932
|
-
await this.#runAgent(id);
|
|
1039
|
+
if (record.effect.service === "agent" || record.effect.service === "files") {
|
|
1040
|
+
await (record.effect.service === "agent" ? this.#runAgent(id) : this.#services.releaseFile(id));
|
|
933
1041
|
const { __version: _a, ...after } = (await outbox.get(id));
|
|
934
1042
|
return after;
|
|
935
1043
|
}
|
|
@@ -1027,11 +1135,15 @@ export class FeltKitRuntime {
|
|
|
1027
1135
|
if (this.#ticking)
|
|
1028
1136
|
return this.#ticking;
|
|
1029
1137
|
const run = Promise.all([
|
|
1030
|
-
this.#services.tick(
|
|
1138
|
+
this.#services.tick(this.workerId),
|
|
1031
1139
|
this.recoverOutbox().catch((error) => {
|
|
1032
1140
|
this.logger.warn(`after-commit recovery: ${error.message}`);
|
|
1033
1141
|
return 0;
|
|
1034
1142
|
}),
|
|
1143
|
+
this.invocations.recover().catch((error) => {
|
|
1144
|
+
this.logger.warn(`invocation recovery: ${error.message}`);
|
|
1145
|
+
return null;
|
|
1146
|
+
}),
|
|
1035
1147
|
]).then(([tick]) => tick).catch((error) => {
|
|
1036
1148
|
this.logger.warn(`services worker: ${error.message}`);
|
|
1037
1149
|
return { jobs: 0, deliveries: 0, scheduled: 0, failed: { jobs: 0, deliveries: 0 } };
|
|
@@ -1397,7 +1509,8 @@ export class FeltKitRuntime {
|
|
|
1397
1509
|
};
|
|
1398
1510
|
// Tenant-scoped collections see only the caller's tenant (the session's, never the request's).
|
|
1399
1511
|
const scoped = hasTenantCollections(this.app.collections.values()) ? scopeToTenant(db, (ref) => this.#resolver.resolve(ref), principal?.tenant?.id ?? null) : applicationView(db);
|
|
1400
|
-
const
|
|
1512
|
+
const invocations = this.#invocationsApi(principal, fn.kind === "mutation" && db instanceof Writer ? { stage: (record) => db.stageSystem(INVOCATIONS_COLLECTION, record), staged: () => db.staged.filter((r) => r.collection === INVOCATIONS_COLLECTION).map((r) => r.value.id), effects } : null, { via: String(options.via ?? "function"), requestId });
|
|
1513
|
+
const ctx = fn.kind === "mutation" ? { ...shared, invocations, db: scoped, agent, events, afterCommit: effects, unsafe: Object.freeze({ feltdb: escapeHatch(this.instance.handle("app.unsafe"), this.app.collections) }), ...(options.agentRun ? { trigger: options.agentRun.trigger } : {}) } : { ...shared, db: scoped, invocations: { get: invocations.get, list: invocations.list } };
|
|
1401
1514
|
try {
|
|
1402
1515
|
// feltkit({ authorize }): after roles and validation, with this call's own reader, so its
|
|
1403
1516
|
// reads are fenced at commit (mutations) and tracked for live queries (queries).
|
|
@@ -1590,6 +1703,7 @@ export class FeltKitRuntime {
|
|
|
1590
1703
|
},
|
|
1591
1704
|
authority: this.#applicationAuthority(principal, requestId),
|
|
1592
1705
|
integrations: this.#integrationInvoker(principal),
|
|
1706
|
+
invocations: this.#invocationsApi(principal, null, { via: String(options.via ?? "function"), requestId }),
|
|
1593
1707
|
agent: {
|
|
1594
1708
|
catalog: async () => (await agent.tools(signedIn())).map((t) => ({
|
|
1595
1709
|
name: t.name,
|
|
@@ -1639,11 +1753,18 @@ export class FeltKitRuntime {
|
|
|
1639
1753
|
}
|
|
1640
1754
|
async #authorizeResource(name, fn, args, principal, options, requestId, db, record) {
|
|
1641
1755
|
const hook = this.app.options.authorize;
|
|
1642
|
-
if (!hook)
|
|
1756
|
+
if (!hook && !fn.owner)
|
|
1643
1757
|
return;
|
|
1644
1758
|
try {
|
|
1759
|
+
// The function's declared ownership first (fails closed), then the application's hook.
|
|
1760
|
+
const owned = await evaluateOwnership(fn, { function: name, principal, args, db });
|
|
1761
|
+
if (owned)
|
|
1762
|
+
record.resource = owned;
|
|
1763
|
+
if (!hook)
|
|
1764
|
+
return;
|
|
1645
1765
|
const decision = await evaluateAuthorize(hook, {
|
|
1646
1766
|
function: name,
|
|
1767
|
+
definition: fn,
|
|
1647
1768
|
kind: fn.kind,
|
|
1648
1769
|
access: fn.access,
|
|
1649
1770
|
...(options.capability ? { capability: { name: options.capability.name, version: options.capability.version ?? 1 } } : {}),
|
|
@@ -1754,6 +1875,7 @@ export class FeltKitRuntime {
|
|
|
1754
1875
|
await this.settleAgents();
|
|
1755
1876
|
await this.#appport?.close().catch(() => undefined);
|
|
1756
1877
|
await this.models.close();
|
|
1878
|
+
await this.localAuthority.close().catch(() => undefined);
|
|
1757
1879
|
await this.activity.flush();
|
|
1758
1880
|
await this.instance.close();
|
|
1759
1881
|
this.#state = "closed";
|