@feltdb/feltkit 0.3.28 → 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.
Files changed (155) hide show
  1. package/dist/app.d.ts +90 -9
  2. package/dist/app.js +95 -1
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.js.map +1 -1
  5. package/dist/appboundry/guest-tenancy.d.ts +2 -2
  6. package/dist/appboundry/guest-tenancy.js.map +1 -1
  7. package/dist/appboundry/guest.js +4 -1
  8. package/dist/appboundry/guest.js.map +1 -1
  9. package/dist/appboundry/host.js +3 -0
  10. package/dist/appboundry/host.js.map +1 -1
  11. package/dist/authorize.d.ts +23 -1
  12. package/dist/authorize.js +37 -0
  13. package/dist/authorize.js.map +1 -1
  14. package/dist/cli/deploy-appboundry.d.ts +1 -1
  15. package/dist/cli/deploy-appboundry.js.map +1 -1
  16. package/dist/cli/deploy.js.map +1 -1
  17. package/dist/cli/main.js +71 -1
  18. package/dist/cli/main.js.map +1 -1
  19. package/dist/cli/skills.js.map +1 -1
  20. package/dist/client/index.js.map +1 -1
  21. package/dist/dashboard/assets/index-9rMS3yBm.js +15 -0
  22. package/dist/dashboard/assets/index-DkiYTUMR.css +1 -0
  23. package/dist/dashboard/index.html +2 -2
  24. package/dist/docs.d.ts +1 -1
  25. package/dist/docs.js +3 -0
  26. package/dist/docs.js.map +1 -1
  27. package/dist/errors.js.map +1 -1
  28. package/dist/event-stage.js.map +1 -1
  29. package/dist/execution.d.ts +186 -0
  30. package/dist/execution.js +105 -0
  31. package/dist/execution.js.map +1 -0
  32. package/dist/index.d.ts +5 -0
  33. package/dist/index.js +4 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/measure/index.js.map +1 -1
  36. package/dist/platform/approvals.js.map +1 -1
  37. package/dist/platform/artifacts.js.map +1 -1
  38. package/dist/platform/changes.d.ts +54 -54
  39. package/dist/platform/changes.js.map +1 -1
  40. package/dist/platform/deployments.d.ts +32 -32
  41. package/dist/platform/exec.js.map +1 -1
  42. package/dist/platform/platform.js.map +1 -1
  43. package/dist/platform/releases.js.map +1 -1
  44. package/dist/platform/server.js.map +1 -1
  45. package/dist/platform/workspaces.js.map +1 -1
  46. package/dist/react/auth.d.ts +10 -10
  47. package/dist/react/auth.js +1 -1
  48. package/dist/react/auth.js.map +1 -1
  49. package/dist/react/context.d.ts +1 -1
  50. package/dist/react/index.js.map +1 -1
  51. package/dist/runtime/accounts.js.map +1 -1
  52. package/dist/runtime/activity.d.ts +1 -1
  53. package/dist/runtime/activity.js.map +1 -1
  54. package/dist/runtime/agent.d.ts +3 -3
  55. package/dist/runtime/agent.js +9 -3
  56. package/dist/runtime/agent.js.map +1 -1
  57. package/dist/runtime/application-authority.d.ts +22 -3
  58. package/dist/runtime/application-authority.js +25 -7
  59. package/dist/runtime/application-authority.js.map +1 -1
  60. package/dist/runtime/audit.js.map +1 -1
  61. package/dist/runtime/authboundry.d.ts +17 -0
  62. package/dist/runtime/authboundry.js +8 -1
  63. package/dist/runtime/authboundry.js.map +1 -1
  64. package/dist/runtime/authority.d.ts +10 -0
  65. package/dist/runtime/authority.js +17 -0
  66. package/dist/runtime/authority.js.map +1 -1
  67. package/dist/runtime/backup-environment.js.map +1 -1
  68. package/dist/runtime/backup.js.map +1 -1
  69. package/dist/runtime/changes.js.map +1 -1
  70. package/dist/runtime/claims.js.map +1 -1
  71. package/dist/runtime/collections.js.map +1 -1
  72. package/dist/runtime/content.d.ts +27 -2
  73. package/dist/runtime/content.js +55 -5
  74. package/dist/runtime/content.js.map +1 -1
  75. package/dist/runtime/context.d.ts +153 -0
  76. package/dist/runtime/contract.js +9 -1
  77. package/dist/runtime/contract.js.map +1 -1
  78. package/dist/runtime/credentials.d.ts +122 -13
  79. package/dist/runtime/credentials.js +304 -42
  80. package/dist/runtime/credentials.js.map +1 -1
  81. package/dist/runtime/crypto-token.js.map +1 -1
  82. package/dist/runtime/data.js.map +1 -1
  83. package/dist/runtime/decisions.js.map +1 -1
  84. package/dist/runtime/deployment.js.map +1 -1
  85. package/dist/runtime/execution-host.d.ts +54 -0
  86. package/dist/runtime/execution-host.js +54 -0
  87. package/dist/runtime/execution-host.js.map +1 -0
  88. package/dist/runtime/generation.js.map +1 -1
  89. package/dist/runtime/instance.js.map +1 -1
  90. package/dist/runtime/integrations.d.ts +22 -7
  91. package/dist/runtime/integrations.js +76 -9
  92. package/dist/runtime/integrations.js.map +1 -1
  93. package/dist/runtime/invocations.d.ts +313 -0
  94. package/dist/runtime/invocations.js +493 -0
  95. package/dist/runtime/invocations.js.map +1 -0
  96. package/dist/runtime/loader.js.map +1 -1
  97. package/dist/runtime/local-authority.d.ts +50 -0
  98. package/dist/runtime/local-authority.js +214 -0
  99. package/dist/runtime/local-authority.js.map +1 -0
  100. package/dist/runtime/oauth-credentials.d.ts +40 -3
  101. package/dist/runtime/oauth-credentials.js +158 -79
  102. package/dist/runtime/oauth-credentials.js.map +1 -1
  103. package/dist/runtime/outbox.js +3 -0
  104. package/dist/runtime/outbox.js.map +1 -1
  105. package/dist/runtime/projects.d.ts +1 -1
  106. package/dist/runtime/readiness.js +33 -0
  107. package/dist/runtime/readiness.js.map +1 -1
  108. package/dist/runtime/runtime.d.ts +48 -5
  109. package/dist/runtime/runtime.js +150 -19
  110. package/dist/runtime/runtime.js.map +1 -1
  111. package/dist/runtime/services.d.ts +43 -0
  112. package/dist/runtime/services.js +202 -3
  113. package/dist/runtime/services.js.map +1 -1
  114. package/dist/runtime/sessions.js.map +1 -1
  115. package/dist/runtime/state-contract.js.map +1 -1
  116. package/dist/runtime/storage-check.js.map +1 -1
  117. package/dist/runtime/targets.d.ts +1 -1
  118. package/dist/runtime/tenancy.js.map +1 -1
  119. package/dist/runtime/transactions.d.ts +15 -0
  120. package/dist/runtime/transactions.js +5 -0
  121. package/dist/runtime/transactions.js.map +1 -1
  122. package/dist/schema.js.map +1 -1
  123. package/dist/server/admin.d.ts +51 -51
  124. package/dist/server/admin.js +83 -3
  125. package/dist/server/admin.js.map +1 -1
  126. package/dist/server/components.js.map +1 -1
  127. package/dist/server/index.js +43 -4
  128. package/dist/server/index.js.map +1 -1
  129. package/dist/server/management.js.map +1 -1
  130. package/dist/server/mcp.d.ts +59 -37
  131. package/dist/server/mcp.js +24 -1
  132. package/dist/server/mcp.js.map +1 -1
  133. package/dist/server/operators.js.map +1 -1
  134. package/dist/server/ports.d.ts +7 -0
  135. package/dist/server/ports.js +17 -0
  136. package/dist/server/ports.js.map +1 -1
  137. package/dist/server/production.js.map +1 -1
  138. package/dist/server/project.js.map +1 -1
  139. package/dist/server/session-http.js.map +1 -1
  140. package/dist/server/tenancy.js.map +1 -1
  141. package/dist/surfaces.d.ts +153 -0
  142. package/dist/surfaces.js +228 -0
  143. package/dist/surfaces.js.map +1 -0
  144. package/dist/testing/index.js.map +1 -1
  145. package/docs/CONNECTIONS.md +151 -0
  146. package/docs/EXECUTION.md +271 -0
  147. package/docs/GUARANTEES.md +54 -2
  148. package/docs/INVOCATIONS.md +170 -0
  149. package/docs/README.md +5 -2
  150. package/package.json +19 -15
  151. package/skills/.claude-plugin/marketplace.json +1 -1
  152. package/skills/.claude-plugin/plugin.json +1 -1
  153. package/skills/feltkit-services/SKILL.md +1 -1
  154. package/dist/dashboard/assets/index-BehzsQOa.css +0 -1
  155. package/dist/dashboard/assets/index-Clsfddp8.js +0 -15
@@ -13,7 +13,7 @@ import { defaultOwnerId, studioLink } from "./production.js";
13
13
  import { readJSON, safeEqual, sendError, sendJSON, startSSE } from "./http.js";
14
14
  import { INTELLIGENCE_CATALOG, getIntelligenceProvider } from "@appport/services";
15
15
  import { systemPrincipal } from "../runtime/authority.js";
16
- import { credentialId, looksLikeSecret, parseGrant } from "../runtime/credentials.js";
16
+ import { CREDENTIALS_COLLECTION, credentialId, looksLikeSecret, parseGrant } from "../runtime/credentials.js";
17
17
  import { assessReadiness } from "../runtime/readiness.js";
18
18
  import { INTEGRATION_CALLS } from "../runtime/integrations.js";
19
19
  import { SAVED_MODELS } from "../runtime/decisions.js";
@@ -21,6 +21,7 @@ import { BROWSER_INFERENCE_HOSTS, readBrowserInference, setBrowserInference, STU
21
21
  import { fromOpenApi, validateDraft, writeIntegration } from "../runtime/connect.js";
22
22
  import { codingAgentPrincipal, connectInstructions } from "./agent-connect.js";
23
23
  import { OUTBOX_COLLECTION } from "../runtime/outbox.js";
24
+ import { INVOCATIONS_COLLECTION } from "../runtime/invocations.js";
24
25
  import { SEQUENCES_COLLECTION } from "../runtime/data.js";
25
26
  import { OPERATOR_PERMISSIONS, authenticateOperator, checkWrite, csrfFor, newRequestId, operatorKey, requireOperator, setSessionCookie, signIn } from "./operators.js";
26
27
  const DASHBOARD = { id: "dashboard", type: "service", roles: [] };
@@ -28,6 +29,8 @@ const DASHBOARD = { id: "dashboard", type: "service", roles: [] };
28
29
  const PLATFORM_COLLECTIONS = {
29
30
  _feltkit_accounts: { owner: "FeltKit", description: "Built-in accounts (auth.accounts): e-mail, name, roles. The password hash is never shown", redact: (r) => ({ ...r, passwordHash: "<redacted>" }) },
30
31
  [ACTIVITY_COLLECTION]: { owner: "FeltKit", description: "Activity log" },
32
+ // The claim token is what lets a worker move an invocation: never shown.
33
+ [INVOCATIONS_COLLECTION]: { owner: "FeltKit", description: "Invocations from registered surfaces: lifecycle state, history, dispatch and outcome", redact: (r) => ({ ...r, execution: { ...r.execution, claim: r.execution?.claim ? "[held]" : null } }) },
31
34
  [OUTBOX_COLLECTION]: { owner: "FeltKit", description: "After-commit effects (ctx.afterCommit): each notification, webhook event or job, its state (pending, performing, done, failed) and error" },
32
35
  [SEQUENCES_COLLECTION]: { owner: "FeltKit", description: "Named sequences (ctx.db.sequence): the last committed number of each" },
33
36
  [SESSIONS_COLLECTION]: {
@@ -54,6 +57,7 @@ const PLATFORM_COLLECTIONS = {
54
57
  [FILE_CONTENT_COLLECTION]: { owner: "FeltKit", description: "File bytes (base64)", redact: (r) => ({ ...r, data: `<${String(r.data ?? "").length} base64 chars>` }) },
55
58
  [SAVED_MODELS]: { owner: "FeltKit", description: "Saved models: provider, model, endpoint, and credential reference (never a key)" },
56
59
  [STUDIO_SETTINGS]: { owner: "FeltKit", description: "Studio settings this environment's operator chose, such as the browser-inference opt-in" },
60
+ [CREDENTIALS_COLLECTION]: { owner: "FeltKit", description: "Stored credentials (FELTKIT_CREDENTIAL_VAULT=database): encrypted under the host's key; never shown", redact: (r) => ({ id: r.id, kind: r.kind, name: r.name, updatedAt: r.updatedAt, ...(r.kind === "lease" ? { until: r.until } : { material: "<encrypted; never shown>" }) }) },
57
61
  [INTEGRATION_CALLS]: { owner: "FeltKit", description: "Integration calls: recorded before and after each request, with verification evidence (credentials are never stored)" },
58
62
  };
59
63
  export async function handleAdmin(ctx, request, response, path, url) {
@@ -123,6 +127,14 @@ export async function handleAdmin(ctx, request, response, path, url) {
123
127
  const body = (await readJSON(request).catch(() => ({})));
124
128
  return sendJSON(response, 200, { item: await runtime.retryOutbox(segments[1], typeof body.by === "string" && body.by ? body.by.slice(0, 120) : "admin") });
125
129
  }
130
+ // GET /files/orphans: stored bytes no live file references. POST /files/orphans/release: reclaim them (recorded releases).
131
+ if (segments[0] === "files" && segments[1] === "orphans" && segments.length === 2 && method === "GET") {
132
+ return sendJSON(response, 200, await runtime.fileOrphans());
133
+ }
134
+ if (segments[0] === "files" && segments[1] === "orphans" && segments[2] === "release" && segments.length === 3 && method === "POST") {
135
+ const body = (await readJSON(request).catch(() => ({})));
136
+ return sendJSON(response, 200, await runtime.fileOrphans({ release: { by: typeof body.by === "string" && body.by ? body.by.slice(0, 120) : "admin" } }));
137
+ }
126
138
  if (method === "GET" && segments[0] === "environments")
127
139
  return sendJSON(response, 200, describeEnvironments(ctx.projectDir, runtime));
128
140
  if (method === "GET" && segments[0] === "projects")
@@ -734,6 +746,8 @@ export const HOST_CUSTODY = systemPrincipal("credential-custody", "custody");
734
746
  * kept and its version. Never a value.
735
747
  */
736
748
  export async function credentialInventory(runtime) {
749
+ await runtime.integrations.refreshConfiguration();
750
+ await runtime.credentials.refresh();
737
751
  const refs = new Map();
738
752
  const add = (ref, usedBy) => {
739
753
  if (!ref)
@@ -752,7 +766,10 @@ export async function credentialInventory(runtime) {
752
766
  for (const integration of runtime.integrations.definitions()) {
753
767
  const s = runtime.integrations.status(integration);
754
768
  if (s.credential?.ref)
755
- add(s.credential.ref, `integration ${integration.name}`);
769
+ add(s.credential.ref, `integration ${integration.name}${s.credential.kind === "oauth2" ? " (OAuth 2.0 grant)" : ""}`);
770
+ const secret = typeof integration.credential === "object" ? integration.credential.oauth2?.clientSecret : undefined;
771
+ if (secret)
772
+ add(secret, `integration ${integration.name} (OAuth client secret)`);
756
773
  }
757
774
  for (const ref of runtime.credentials.stored())
758
775
  add(ref);
@@ -791,6 +808,10 @@ export async function storeCredential(runtime, input, principal, via) {
791
808
  try {
792
809
  if (input.kind !== undefined && input.kind !== "oauth2")
793
810
  throw new FeltKitError("INVALID_ARGUMENT", 'The only credential kind is "oauth2" (an OAuth 2.0 token response).');
811
+ const grantOf = runtime.integrations.definitions().find((i) => typeof i.credential === "object" && i.credential.oauth2 && credentialId(i.credential.ref) === id);
812
+ if (grantOf && input.kind !== "oauth2") {
813
+ throw new FeltKitError("INVALID_ARGUMENT", `${ref} is ${grantOf.name}'s OAuth 2.0 grant, not a plain value; nothing was stored. Connect it with \`feltkit credential connect ${grantOf.name}\`, or import a token response with \`feltkit credential set ${ref} --oauth\`.`);
814
+ }
794
815
  if (input.kind === "oauth2") {
795
816
  try {
796
817
  parseGrant(input.value);
@@ -980,6 +1001,48 @@ async function handleProduction(ctx, request, response, path, url) {
980
1001
  await read();
981
1002
  return sendJSON(response, 200, { sessions: await runtime.sessions.list() });
982
1003
  }
1004
+ if (segments[0] === "sessions" && segments.length === 1 && method === "POST") {
1005
+ // A service or agent identity for a process that runs on its own (an adapter, a worker): never a
1006
+ // person, only declared roles, always with an expiry. The operator can already sign in under any
1007
+ // declared role (`operator signin --role`); this gives that identity a session of its own that
1008
+ // does not depend on the operator's, and can be listed and revoked.
1009
+ const started = Date.now();
1010
+ const { p, body } = await write();
1011
+ const principal = (body.principal ?? {});
1012
+ if (principal.type !== "service" && principal.type !== "agent")
1013
+ throw new FeltKitError("INVALID_ARGUMENT", "Production sessions are for services and agents (--type service|agent); people sign in.");
1014
+ if (typeof principal.id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,99}$/.test(principal.id))
1015
+ throw new FeltKitError("INVALID_ARGUMENT", "A session needs an id (letters, digits, . _ : -).");
1016
+ const declared = Object.keys(runtime.app.options.roles ?? {});
1017
+ const roles = Array.isArray(principal.roles) ? principal.roles.map(String) : [];
1018
+ if (!roles.length || roles.some((r) => !declared.includes(r)))
1019
+ throw new FeltKitError("INVALID_ARGUMENT", `Roles must be declared ones: ${declared.join(", ") || "(none)"}.`);
1020
+ const ttlMs = Number(body.ttlMs);
1021
+ const MAX = 90 * 24 * 3_600_000;
1022
+ if (!Number.isFinite(ttlMs) || ttlMs <= 0 || ttlMs > MAX)
1023
+ throw new FeltKitError("INVALID_ARGUMENT", "A production session needs an expiry (--ttl <hours>), at most 90 days.");
1024
+ const issued = await runtime.issueSession({ id: principal.id, type: principal.type, roles, ...(typeof principal.displayName === "string" ? { displayName: principal.displayName } : {}) }, {
1025
+ kind: "operator-issued",
1026
+ label: String(body.label ?? `issued by ${p.id}`).slice(0, 200),
1027
+ ttlMs,
1028
+ via: "dashboard",
1029
+ actor: p,
1030
+ });
1031
+ evidence(p, "session.issued", "success", { principal: principal.id, type: principal.type, roles, ttlHours: Math.round(ttlMs / 3_600_000) }, started);
1032
+ return sendJSON(response, 200, issued);
1033
+ }
1034
+ if (segments[0] === "functions" && segments[1] === "call" && segments.length === 2 && method === "POST") {
1035
+ // `feltkit call <module:function>`: as the signed-in operator, through the function's own access
1036
+ // rule (the same authorizer as /api), recorded as activity like any call.
1037
+ const started = Date.now();
1038
+ const { p, body } = await write();
1039
+ const name = String(body.name ?? "");
1040
+ if (!/^[\w/-]+:[\w]+$/.test(name))
1041
+ throw new FeltKitError("INVALID_ARGUMENT", "Name the function as <module>:<function>.");
1042
+ const result = await runtime.call(name, (body.args ?? {}), { principal: p, via: "cli" });
1043
+ evidence(p, "function.called", result.ok ? "success" : "error", { name }, started);
1044
+ return sendJSON(response, 200, result);
1045
+ }
983
1046
  if (segments[0] === "sessions" && segments.length === 2 && method === "DELETE") {
984
1047
  const started = Date.now();
985
1048
  const { p } = await write();
@@ -1237,7 +1300,7 @@ async function handleProduction(ctx, request, response, path, url) {
1237
1300
  // gateway authorizes credential.store for them. Without the production vault opt-in the
1238
1301
  // custody refuses with CUSTODY_READ_ONLY (values come from the host's environment).
1239
1302
  const { p, body } = await write();
1240
- const stored = await storeCredential(runtime, { ref: body.ref, value: body.value, provider: body.provider }, p, "dashboard");
1303
+ const stored = await storeCredential(runtime, { ref: body.ref, value: body.value, provider: body.provider, kind: body.kind }, p, "dashboard");
1241
1304
  return sendJSON(response, 200, { stored, ...(await credentialsView(runtime)) });
1242
1305
  }
1243
1306
  case "POST /agent/tasks/:id/decide": {
@@ -1257,6 +1320,21 @@ async function handleProduction(ctx, request, response, path, url) {
1257
1320
  return;
1258
1321
  }
1259
1322
  }
1323
+ if (method === "POST" && segments[0] === "integrations" && segments[2] === "connect" && segments.length === 3) {
1324
+ // Connecting an OAuth 2.0 grant: the operator holds feltkit.operations.write, and the connection
1325
+ // itself checks credential.store for them (at the start and again at the callback).
1326
+ const started = Date.now();
1327
+ const { p } = await write();
1328
+ const connection = await runtime.oauth.connect(segments[1], p, "dashboard");
1329
+ evidence(p, "credential.connect.started", "success", { integration: segments[1] }, started);
1330
+ return sendJSON(response, 200, connection);
1331
+ }
1332
+ if (method === "DELETE" && segments[0] === "credentials" && segments[1] && segments.length === 2) {
1333
+ // Disconnecting or removing a stored credential (an OAuth grant is revoked at the provider first).
1334
+ const { p } = await write();
1335
+ await removeCredential(runtime, decodeURIComponent(segments[1]), p, "dashboard");
1336
+ return sendJSON(response, 200, await credentialsView(runtime));
1337
+ }
1260
1338
  if (method === "POST" && segments[0] === "integrations" && segments[2] === "check" && segments.length === 3) {
1261
1339
  await write();
1262
1340
  return sendJSON(response, 200, await runtime.integrations.check(segments[1]));
@@ -1402,6 +1480,8 @@ function parseDocument(text) {
1402
1480
  }
1403
1481
  }
1404
1482
  async function integrationsView(runtime) {
1483
+ await runtime.integrations.refreshConfiguration();
1484
+ await runtime.credentials.refresh();
1405
1485
  return {
1406
1486
  integrations: runtime.integrations.definitions().map((i) => runtime.integrations.status(i)),
1407
1487
  calls: (await runtime.integrations.calls({ limit: 100 })).map(({ input: _input, ...call }) => call),