@feltdb/feltkit 0.3.25 → 0.3.27

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 (95) hide show
  1. package/dist/app.d.ts +60 -3
  2. package/dist/app.js +23 -13
  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/main.js +17 -5
  19. package/dist/cli/main.js.map +1 -1
  20. package/dist/dashboard/assets/{index-BXTNQAg1.css → index-BehzsQOa.css} +1 -1
  21. package/dist/dashboard/assets/{index-BEjtLLYq.js → index-Clsfddp8.js} +9 -9
  22. package/dist/dashboard/index.html +2 -2
  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/deployments.d.ts +1 -1
  27. package/dist/platform/server.js +5 -3
  28. package/dist/platform/server.js.map +1 -1
  29. package/dist/react/auth.js +3 -2
  30. package/dist/react/auth.js.map +1 -1
  31. package/dist/runtime/agent.d.ts +14 -0
  32. package/dist/runtime/agent.js +59 -9
  33. package/dist/runtime/agent.js.map +1 -1
  34. package/dist/runtime/application-authority.d.ts +54 -0
  35. package/dist/runtime/application-authority.js +55 -0
  36. package/dist/runtime/application-authority.js.map +1 -0
  37. package/dist/runtime/authboundry.d.ts +25 -13
  38. package/dist/runtime/authboundry.js +15 -7
  39. package/dist/runtime/authboundry.js.map +1 -1
  40. package/dist/runtime/browser-inference.d.ts +2 -2
  41. package/dist/runtime/browser-inference.js +2 -2
  42. package/dist/runtime/content.d.ts +1 -0
  43. package/dist/runtime/context.d.ts +80 -0
  44. package/dist/runtime/data.d.ts +1 -24
  45. package/dist/runtime/data.js +4 -67
  46. package/dist/runtime/data.js.map +1 -1
  47. package/dist/runtime/job-context.d.ts +26 -0
  48. package/dist/runtime/job-context.js +24 -0
  49. package/dist/runtime/job-context.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.js +111 -13
  54. package/dist/runtime/runtime.js.map +1 -1
  55. package/dist/runtime/services.d.ts +39 -35
  56. package/dist/runtime/services.js +155 -8
  57. package/dist/runtime/services.js.map +1 -1
  58. package/dist/runtime/sha256.d.ts +1 -0
  59. package/dist/runtime/sha256.js +91 -0
  60. package/dist/runtime/sha256.js.map +1 -0
  61. package/dist/runtime/tenancy.d.ts +34 -1
  62. package/dist/runtime/tenancy.js +62 -11
  63. package/dist/runtime/tenancy.js.map +1 -1
  64. package/dist/runtime/transactions.d.ts +11 -2
  65. package/dist/runtime/transactions.js +6 -3
  66. package/dist/runtime/transactions.js.map +1 -1
  67. package/dist/server/admin.js +56 -3
  68. package/dist/server/admin.js.map +1 -1
  69. package/dist/server/index.d.ts +7 -0
  70. package/dist/server/index.js +38 -14
  71. package/dist/server/index.js.map +1 -1
  72. package/dist/server/ports.d.ts +43 -0
  73. package/dist/server/ports.js +96 -0
  74. package/dist/server/ports.js.map +1 -0
  75. package/dist/server/project.d.ts +8 -1
  76. package/dist/server/project.js +6 -9
  77. package/dist/server/project.js.map +1 -1
  78. package/dist/server/tenancy.js +2 -1
  79. package/dist/server/tenancy.js.map +1 -1
  80. package/dist/testing/index.d.ts +36 -2
  81. package/dist/testing/index.js +17 -4
  82. package/dist/testing/index.js.map +1 -1
  83. package/dist/words.d.ts +9 -0
  84. package/dist/words.js +15 -0
  85. package/dist/words.js.map +1 -0
  86. package/docs/APPBOUNDRY.md +15 -6
  87. package/docs/AUTH.md +16 -3
  88. package/docs/GUARANTEES.md +31 -0
  89. package/docs/PATH-TO-PRODUCTION.md +1 -1
  90. package/docs/README.md +2 -2
  91. package/docs/TRANSACTIONS.md +4 -0
  92. package/package.json +7 -7
  93. package/skills/.claude-plugin/marketplace.json +1 -1
  94. package/skills/.claude-plugin/plugin.json +1 -1
  95. package/skills/feltkit-services/SKILL.md +1 -1
@@ -36,7 +36,7 @@ import { IDEMPOTENCY_OUTCOME_UNKNOWN, idempotencyErrorReason, isIdempotencyClaim
36
36
  import { grantsPermission } from "@appport/authorization";
37
37
  import { createHash, randomUUID } from "node:crypto";
38
38
  import { FeltKitError, isFeltKitError } from "../errors.js";
39
- import { authContext } from "./authority.js";
39
+ import { authContext, toAppPortPrincipal } from "./authority.js";
40
40
  import { readAll } from "./data.js";
41
41
  export const AGENT_NAME = "feltkit";
42
42
  export const AGENT_VERSION = 1;
@@ -235,13 +235,16 @@ export class AgentHost {
235
235
  .map((c) => {
236
236
  const fn = functions.get(c.name);
237
237
  const integration = this.#runtime.integrations.operationFor(c.name);
238
+ const status = integration ? this.#runtime.integrations.status(integration.integration) : null;
238
239
  return {
239
240
  name: c.name,
240
241
  source: "application",
241
242
  effect: (c.effect === "observation" ? "observation" : "consequential"),
242
243
  ...(c.description ? { description: c.description } : {}),
243
244
  ...(fn?.approval ? { approval: fn.approval } : {}),
244
- ...(schemas.get(c.name) ? { inputSchema: schemas.get(c.name) } : {}),
245
+ ...(schemas.get(c.name) ? { inputSchema: schemas.get(c.name) } : integration ? { inputSchema: integration.op.inputSchema.toJSONSchema() } : {}),
246
+ ...(integration ? { integration: integration.integration.name } : {}),
247
+ readiness: status ? { ready: status.problems.length === 0, problems: status.problems } : { ready: true, problems: [] },
245
248
  permission: integration ? [integration.op.access] : fn && fn.access !== "public" && fn.access !== "authenticated" ? [fn.access] : [],
246
249
  };
247
250
  });
@@ -273,6 +276,8 @@ export class AgentHost {
273
276
  ...(decision.allowed ? { invoke: proposeOnly ? "propose" : "direct" } : {}),
274
277
  ...(tool.approval ? { approval: tool.approval } : {}),
275
278
  ...(tool.inputSchema ? { inputSchema: tool.inputSchema } : {}),
279
+ ...(tool.integration ? { integration: tool.integration } : {}),
280
+ ...(tool.readiness ? { readiness: tool.readiness } : {}),
276
281
  });
277
282
  }
278
283
  return out;
@@ -315,7 +320,8 @@ export class AgentHost {
315
320
  await this.#state.createTask({
316
321
  taskId,
317
322
  objective,
318
- scope: { project: this.#runtime.app.name },
323
+ // The workspace the task belongs to (G-02): it is visible, approvable and runs only there.
324
+ scope: { project: this.#runtime.app.name, ...(principal.tenant ? { workspace: principal.tenant.id } : {}) },
319
325
  actor,
320
326
  status: "running",
321
327
  constraints: [`playbook:${playbook}`, ...(input.target ? [`target:${input.target}`] : []), ...(input.subject ? [`subject:${input.subject.collection}/${input.subject.id}`] : [])],
@@ -359,11 +365,12 @@ export class AgentHost {
359
365
  }
360
366
  async list(principal, limit = 50) {
361
367
  this.#read(principal);
362
- const rows = await this.#tasks({ limit });
368
+ const rows = (await this.#tasks({ limit: principal === "admin" ? limit : Math.max(limit, 500) })).filter((t) => this.#visible(t, principal)).slice(0, limit);
363
369
  return Promise.all(rows.map(async (task) => ({ task, execution: await this.#executionRecord(task), pending: (await this.#heads(task.task_id)).filter((h) => h.record.state === "proposed").length })));
364
370
  }
365
371
  async get(taskId, principal) {
366
372
  this.#read(principal);
373
+ await this.#inScope(taskId, principal);
367
374
  const found = await this.#state.getTask(taskId);
368
375
  if (!found || found.task.scope?.project !== this.#runtime.app.name)
369
376
  throw new FeltKitError("NOT_FOUND", `No agent task ${taskId}.`);
@@ -380,6 +387,7 @@ export class AgentHost {
380
387
  /** The FeltDB context bundle for a task, plus this application's context. Redacted. */
381
388
  async context(taskId, principal) {
382
389
  const p = this.#require(principal, AGENT_PERMISSIONS.read);
390
+ await this.#inScope(taskId, p);
383
391
  const bundle = await this.#state.assembleContext(taskId, { maxBytes: 24_000 });
384
392
  return redact({ task: bundle, application: await this.applicationContext(p) });
385
393
  }
@@ -421,6 +429,7 @@ export class AgentHost {
421
429
  */
422
430
  async propose(taskId, proposal, principal) {
423
431
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
432
+ await this.#inScope(taskId, p);
424
433
  const { task } = await this.#owned(taskId, p);
425
434
  const tool = this.#catalog().find((t) => t.name === proposal.capability);
426
435
  if (!tool)
@@ -527,6 +536,7 @@ export class AgentHost {
527
536
  */
528
537
  async beginGeneration(taskId, principal, input) {
529
538
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
539
+ await this.#inScope(taskId, p);
530
540
  const { task } = await this.#owned(taskId, p);
531
541
  const generationId = `gen-${randomUUID().replace(/-/g, "").slice(0, 16)}`;
532
542
  const at = new Date().toISOString();
@@ -606,6 +616,7 @@ export class AgentHost {
606
616
  this.#read("admin");
607
617
  else
608
618
  await this.#ownedOrNotFound(taskId, this.#require(principal, AGENT_PERMISSIONS.read));
619
+ await this.#inScope(taskId, principal);
609
620
  const heads = await this.#generationHeads(taskId);
610
621
  const actions = await this.#heads(taskId);
611
622
  const observed = (await this.#taskMemories(taskId)).filter((m) => m.kind === "outcome").map((m) => m.content);
@@ -635,7 +646,7 @@ export class AgentHost {
635
646
  const me = actorOf(p);
636
647
  const out = [];
637
648
  for (const task of await this.#tasks({ limit: 500 })) {
638
- if (task.owner !== me)
649
+ if (task.owner !== me || !this.#visible(task, p))
639
650
  continue;
640
651
  for (const { record } of await this.#heads(task.task_id)) {
641
652
  if (filter.state && record.state !== filter.state)
@@ -652,6 +663,7 @@ export class AgentHost {
652
663
  */
653
664
  async proposalOutcome(taskId, idempotencyKey, principal) {
654
665
  const p = this.#require(principal, AGENT_PERMISSIONS.read);
666
+ await this.#inScope(taskId, p);
655
667
  await this.#ownedOrNotFound(taskId, p);
656
668
  const actionId = `act-${createHash("sha256").update(`${taskId}\u0000${idempotencyKey}`).digest("hex").slice(0, 20)}`;
657
669
  const head = (await this.#heads(taskId)).find((h) => h.record.actionId === actionId);
@@ -668,6 +680,7 @@ export class AgentHost {
668
680
  /** Every action of one of your turns: consequential ones (with their state) and observations that ran, oldest first. */
669
681
  async turnActions(taskId, principal) {
670
682
  const p = this.#require(principal, AGENT_PERMISSIONS.read);
683
+ await this.#inScope(taskId, p);
671
684
  await this.#ownedOrNotFound(taskId, p);
672
685
  const consequential = (await this.#heads(taskId)).map(({ record: r }) => ({ taskId, actionId: r.actionId, capability: r.capability, effect: r.effect, state: r.state, ...(r.outcome?.ok && r.outcome.output !== undefined ? { output: r.outcome.output } : {}), ...(r.outcome && !r.outcome.ok && r.outcome.error ? { error: r.outcome.error } : {}), at: r.proposedAt }));
673
686
  const observed = (await this.#taskMemories(taskId))
@@ -699,6 +712,7 @@ export class AgentHost {
699
712
  */
700
713
  async approve(taskId, actionId, approver, reviewed) {
701
714
  const p = this.#require(approver, AGENT_PERMISSIONS.write);
715
+ await this.#inScope(taskId, p);
702
716
  if (p.type !== "user")
703
717
  throw new FeltKitError("FORBIDDEN", "Only a person can approve a consequential action; agents and services cannot.");
704
718
  const { task } = await this.#loaded(taskId);
@@ -761,6 +775,7 @@ export class AgentHost {
761
775
  * (the same checks approve() makes; nothing changes). Studio shows Approve only when it may.
762
776
  */
763
777
  async approvability(taskId, principal) {
778
+ await this.#inScope(taskId, principal);
764
779
  const { task } = await this.#loaded(taskId);
765
780
  const out = {};
766
781
  const writer = grantsPermission(this.#runtime.authority.permissionsFor(principal), AGENT_PERMISSIONS.write);
@@ -830,6 +845,7 @@ export class AgentHost {
830
845
  /** Reject a proposed action. */
831
846
  async reject(taskId, actionId, principal, reason = "rejected") {
832
847
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
848
+ await this.#inScope(taskId, p);
833
849
  const { task } = await this.#loaded(taskId);
834
850
  const head = await this.#head(taskId, actionId);
835
851
  if (head.record.state !== "proposed")
@@ -846,6 +862,7 @@ export class AgentHost {
846
862
  */
847
863
  async retry(taskId, actionId, principal) {
848
864
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
865
+ await this.#inScope(taskId, p);
849
866
  const { task } = await this.#loaded(taskId);
850
867
  if (p.type !== "user" && actorOf(p) !== task.owner)
851
868
  throw new FeltKitError("FORBIDDEN", "Only the task owner or a person can retry an action.");
@@ -864,6 +881,7 @@ export class AgentHost {
864
881
  */
865
882
  async resolve(taskId, actionId, input, principal) {
866
883
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
884
+ await this.#inScope(taskId, p);
867
885
  if (p.type !== "user")
868
886
  throw new FeltKitError("FORBIDDEN", "Only a person can settle an action whose outcome is unknown.");
869
887
  if (input?.outcome !== "succeeded" && input?.outcome !== "failed")
@@ -968,6 +986,7 @@ export class AgentHost {
968
986
  /** Finish a task. The summary is the owner's; evidence is what the checkpoints cite. */
969
987
  async complete(taskId, summary, principal) {
970
988
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
989
+ await this.#inScope(taskId, p);
971
990
  const { task } = await this.#owned(taskId, p);
972
991
  const open = (await this.#heads(taskId)).filter((h) => OPEN_STATES.includes(h.record.state));
973
992
  if (open.length)
@@ -987,6 +1006,7 @@ export class AgentHost {
987
1006
  */
988
1007
  async cancel(taskId, principal, reason = "cancelled") {
989
1008
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
1009
+ await this.#inScope(taskId, p);
990
1010
  const { task } = await this.#loaded(taskId);
991
1011
  if (p.type !== "user" && actorOf(p) !== task.owner)
992
1012
  throw new FeltKitError("FORBIDDEN", "Only the task owner or a person can cancel it.");
@@ -1031,7 +1051,8 @@ export class AgentHost {
1031
1051
  cursor = page.nextCursor;
1032
1052
  for (const h of page.handoffs) {
1033
1053
  const handoff = await this.#state.getHandoff(h.handoff_id);
1034
- if (handoff && handoff.status === "open" && handoff.scope?.project === this.#runtime.app.name)
1054
+ const inScope = principal === "admin" || (handoff ? this.#visible((await this.#state.getTask(handoff.task_id))?.task ?? { scope: {} }, principal) : false);
1055
+ if (handoff && inScope && handoff.status === "open" && handoff.scope?.project === this.#runtime.app.name)
1035
1056
  out.push({ handoffId: handoff.handoff_id, taskId: handoff.task_id, objective: handoff.objective, from: handoff.from, note: handoff.note ?? null, createdAt: handoff.created_at });
1036
1057
  }
1037
1058
  } while (cursor);
@@ -1041,6 +1062,9 @@ export class AgentHost {
1041
1062
  async claim(handoffId, principal) {
1042
1063
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
1043
1064
  const actor = actorOf(p);
1065
+ const pending = await this.#state.getHandoff(handoffId);
1066
+ if (pending)
1067
+ await this.#inScope(pending.task_id, p);
1044
1068
  const claim = await this.#state.claimHandoff(handoffId, { claimant: actor });
1045
1069
  const handoff = await this.#state.acceptHandoff(handoffId, { claimant: actor, leaseId: claim.leaseId });
1046
1070
  await this.#state.checkpoint(handoff.task_id, { actor, summary: `Claimed by ${actor}.`, status: "running" });
@@ -1055,6 +1079,7 @@ export class AgentHost {
1055
1079
  /** A note from the owner: decisions and progress, recorded as a checkpoint. */
1056
1080
  async note(taskId, input, principal) {
1057
1081
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
1082
+ await this.#inScope(taskId, p);
1058
1083
  const { task } = await this.#owned(taskId, p);
1059
1084
  await this.#state.checkpoint(taskId, {
1060
1085
  actor: task.owner,
@@ -1151,6 +1176,7 @@ export class AgentHost {
1151
1176
  */
1152
1177
  async decide(taskId, principal) {
1153
1178
  const p = this.#require(principal, AGENT_PERMISSIONS.write);
1179
+ await this.#inScope(taskId, p);
1154
1180
  const { task } = await this.#loaded(taskId);
1155
1181
  if (p.type !== "user" && actorOf(p) !== task.owner)
1156
1182
  throw new FeltKitError("FORBIDDEN", "Only the task owner or a person can ask for a decision.");
@@ -1595,11 +1621,34 @@ export class AgentHost {
1595
1621
  const failed = rows.find((r) => r.outcome !== "succeeded");
1596
1622
  return { ok: false, error: { code: failed.failureCode ?? String(failed.outcome).toUpperCase(), message: `AppPort Services recorded ${failed.outcome}` }, determinedBy: "service-evidence" };
1597
1623
  }
1598
- /** The task owner as they are now, or null. Never a guess. */
1624
+ /**
1625
+ * The task owner as they are now, or null. Never a guess. A task in a workspace is owned there:
1626
+ * the owner joins it through the live membership only, and without one cannot be resolved.
1627
+ */
1599
1628
  async #resolveOwner(task) {
1600
1629
  const [type, ...rest] = task.owner.split(":");
1601
1630
  const resolved = await this.#runtime.resolvePrincipal(rest.join(":"), { devUsers: true });
1602
- return resolved && resolved.type === type ? resolved : null;
1631
+ if (!resolved || resolved.type !== type)
1632
+ return null;
1633
+ const workspace = task.scope?.workspace;
1634
+ if (!workspace)
1635
+ return resolved;
1636
+ const inWorkspace = await this.#runtime.withTenant(resolved, workspace);
1637
+ return inWorkspace.tenant?.id === workspace ? inWorkspace : null;
1638
+ }
1639
+ /** Is `task` in the caller's workspace? Studio ("admin") sees every task; anyone else only their workspace's (none: only tasks in none). */
1640
+ #visible(task, principal) {
1641
+ if (principal === "admin")
1642
+ return true;
1643
+ return (task.scope?.workspace ?? null) === (principal?.tenant?.id ?? null);
1644
+ }
1645
+ /** A task outside the caller's workspace does not exist for them (NOT_FOUND), as a tenant record. */
1646
+ async #inScope(taskId, principal) {
1647
+ if (principal === "admin")
1648
+ return;
1649
+ const found = await this.#state.getTask(taskId);
1650
+ if (found && found.task.scope?.project === this.#runtime.app.name && !this.#visible(found.task, principal))
1651
+ throw new FeltKitError("NOT_FOUND", `No agent task ${taskId}.`);
1603
1652
  }
1604
1653
  async #loaded(taskId) {
1605
1654
  const found = await this.#state.getTask(taskId);
@@ -1736,7 +1785,8 @@ function legacy(memory) {
1736
1785
  const content = memory.content;
1737
1786
  return { ...content, state: "proposed", seq: 1, attempt: 1, history: [{ state: "proposed", at: content.proposedAt, by: content.proposedBy }] };
1738
1787
  }
1788
+ /** As toAppPortPrincipal: the workspace travels with the principal (dropping it ran agent actions with no workspace, G-02). */
1739
1789
  function toAppPort(principal) {
1740
- return { id: principal.id, type: principal.type === "agent" ? "application" : principal.type, attributes: { roles: principal.roles, feltkitType: principal.type } };
1790
+ return toAppPortPrincipal(principal);
1741
1791
  }
1742
1792
  //# sourceMappingURL=agent.js.map