@feltdb/feltkit 0.4.0 → 0.5.1

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 (132) hide show
  1. package/dist/agent-engine.d.ts +93 -0
  2. package/dist/agent-engine.js +40 -0
  3. package/dist/agent-engine.js.map +1 -0
  4. package/dist/app.d.ts +153 -4
  5. package/dist/app.js +134 -25
  6. package/dist/app.js.map +1 -1
  7. package/dist/appboundry/build.d.ts +9 -1
  8. package/dist/appboundry/build.js +7 -7
  9. package/dist/appboundry/build.js.map +1 -1
  10. package/dist/appboundry/guest.js +82 -0
  11. package/dist/appboundry/guest.js.map +1 -1
  12. package/dist/appboundry/host.d.ts +21 -0
  13. package/dist/appboundry/host.js +83 -2
  14. package/dist/appboundry/host.js.map +1 -1
  15. package/dist/appboundry/runtime.js +2 -0
  16. package/dist/appboundry/runtime.js.map +1 -1
  17. package/dist/boards/index.d.ts +1258 -0
  18. package/dist/boards/index.js +1410 -0
  19. package/dist/boards/index.js.map +1 -0
  20. package/dist/boards/model.d.ts +177 -0
  21. package/dist/boards/model.js +177 -0
  22. package/dist/boards/model.js.map +1 -0
  23. package/dist/boards/react.d.ts +18 -0
  24. package/dist/boards/react.js +339 -0
  25. package/dist/boards/react.js.map +1 -0
  26. package/dist/cli/deploy-appboundry-self-hosted.js +2 -2
  27. package/dist/cli/deploy.js +19 -6
  28. package/dist/cli/deploy.js.map +1 -1
  29. package/dist/cli/main.js +70 -5
  30. package/dist/cli/main.js.map +1 -1
  31. package/dist/client/index.d.ts +265 -4
  32. package/dist/client/index.js +170 -3
  33. package/dist/client/index.js.map +1 -1
  34. package/dist/cron.d.ts +18 -0
  35. package/dist/cron.js +67 -0
  36. package/dist/cron.js.map +1 -0
  37. package/dist/dashboard/assets/index-CLzg0fuZ.js +14 -0
  38. package/dist/dashboard/assets/index-D2XOWzK9.css +1 -0
  39. package/dist/dashboard/index.html +2 -2
  40. package/dist/docs.d.ts +1 -1
  41. package/dist/docs.js +3 -0
  42. package/dist/docs.js.map +1 -1
  43. package/dist/eve/index.d.ts +77 -0
  44. package/dist/eve/index.js +128 -0
  45. package/dist/eve/index.js.map +1 -0
  46. package/dist/index.d.ts +7 -2
  47. package/dist/index.js +2 -1
  48. package/dist/index.js.map +1 -1
  49. package/dist/native/build.d.ts +112 -0
  50. package/dist/native/build.js +472 -0
  51. package/dist/native/build.js.map +1 -0
  52. package/dist/native/index.d.ts +67 -0
  53. package/dist/native/index.js +113 -0
  54. package/dist/native/index.js.map +1 -0
  55. package/dist/native/instance.d.ts +3 -0
  56. package/dist/native/instance.js +18 -0
  57. package/dist/native/instance.js.map +1 -0
  58. package/dist/react/agent-control.d.ts +2 -0
  59. package/dist/react/agent-control.js +1 -1
  60. package/dist/react/agent-control.js.map +1 -1
  61. package/dist/react/auth.d.ts +15 -1
  62. package/dist/react/auth.js +28 -5
  63. package/dist/react/auth.js.map +1 -1
  64. package/dist/react/hooks.d.ts +88 -0
  65. package/dist/react/hooks.js +188 -0
  66. package/dist/react/hooks.js.map +1 -0
  67. package/dist/react/index.d.ts +5 -88
  68. package/dist/react/index.js +3 -185
  69. package/dist/react/index.js.map +1 -1
  70. package/dist/runtime/agent-control.d.ts +10 -0
  71. package/dist/runtime/agent-control.js +9 -1
  72. package/dist/runtime/agent-control.js.map +1 -1
  73. package/dist/runtime/agent-run.d.ts +166 -0
  74. package/dist/runtime/agent-run.js +431 -0
  75. package/dist/runtime/agent-run.js.map +1 -0
  76. package/dist/runtime/agent.d.ts +158 -1
  77. package/dist/runtime/agent.js +329 -8
  78. package/dist/runtime/agent.js.map +1 -1
  79. package/dist/runtime/assemble.js +14 -1
  80. package/dist/runtime/assemble.js.map +1 -1
  81. package/dist/runtime/authority.d.ts +9 -0
  82. package/dist/runtime/authority.js.map +1 -1
  83. package/dist/runtime/context.d.ts +9 -0
  84. package/dist/runtime/required-capabilities.d.ts +73 -0
  85. package/dist/runtime/required-capabilities.js +69 -0
  86. package/dist/runtime/required-capabilities.js.map +1 -0
  87. package/dist/runtime/runtime.d.ts +70 -1
  88. package/dist/runtime/runtime.js +261 -9
  89. package/dist/runtime/runtime.js.map +1 -1
  90. package/dist/runtime/sessions.d.ts +1 -0
  91. package/dist/runtime/sessions.js +1 -1
  92. package/dist/runtime/sessions.js.map +1 -1
  93. package/dist/runtime/tenancy.d.ts +9 -1
  94. package/dist/runtime/tenancy.js +22 -0
  95. package/dist/runtime/tenancy.js.map +1 -1
  96. package/dist/runtime/transactions.d.ts +3 -1
  97. package/dist/runtime/transactions.js.map +1 -1
  98. package/dist/server/eve.d.ts +287 -0
  99. package/dist/server/eve.js +1071 -0
  100. package/dist/server/eve.js.map +1 -0
  101. package/dist/server/index.d.ts +2 -0
  102. package/dist/server/index.js +61 -4
  103. package/dist/server/index.js.map +1 -1
  104. package/dist/server/mcp.d.ts +7 -7
  105. package/dist/server/project.js +20 -3
  106. package/dist/server/project.js.map +1 -1
  107. package/dist/server/session-http.d.ts +7 -1
  108. package/dist/server/session-http.js +11 -1
  109. package/dist/server/session-http.js.map +1 -1
  110. package/dist/server/tenancy.d.ts +2 -0
  111. package/dist/server/tenancy.js +31 -1
  112. package/dist/server/tenancy.js.map +1 -1
  113. package/dist/testing/index.d.ts +1 -4
  114. package/dist/testing/index.js +2 -1
  115. package/dist/testing/index.js.map +1 -1
  116. package/docs/AGENT-CONTROL.md +36 -0
  117. package/docs/APPBOUNDRY.md +68 -2
  118. package/docs/AUTH.md +2 -0
  119. package/docs/EVE-COMPOSITION.md +75 -0
  120. package/docs/NATIVE-AGENTS.md +353 -0
  121. package/docs/NATIVE.md +137 -0
  122. package/docs/README.md +5 -2
  123. package/package.json +35 -9
  124. package/skills/.claude-plugin/marketplace.json +1 -1
  125. package/skills/.claude-plugin/plugin.json +1 -1
  126. package/skills/feltkit-agent/SKILL.md +1 -1
  127. package/skills/feltkit-build/SKILL.md +1 -1
  128. package/skills/feltkit-data/SKILL.md +1 -1
  129. package/skills/feltkit-operations/SKILL.md +1 -1
  130. package/skills/feltkit-services/SKILL.md +1 -1
  131. package/dist/dashboard/assets/index-BhxrvY37.js +0 -15
  132. package/dist/dashboard/assets/index-CSzYeCo_.css +0 -1
@@ -34,9 +34,17 @@ type RefFor<D> = D extends {
34
34
  $args?: infer A;
35
35
  $result?: infer R;
36
36
  } ? FunctionReference<K, A, R> : never;
37
- type ModuleRefs<M> = {
37
+ type OwnRefs<M> = {
38
38
  [E in keyof M as M[E] extends Definition ? E : never]: RefFor<M[E]>;
39
39
  };
40
+ type UnionToIntersection<U> = (U extends unknown ? (u: U) => void : never) extends (i: infer I) => void ? I : never;
41
+ /** Function groups (`functionGroup`, e.g. Boards): their members are the module's functions too. */
42
+ type GroupRefs<M> = UnionToIntersection<{
43
+ [E in keyof M]: M[E] extends {
44
+ readonly $functionGroup: true;
45
+ } ? OwnRefs<M[E]> : never;
46
+ }[keyof M]>;
47
+ type ModuleRefs<M> = [GroupRefs<M>] extends [never] ? OwnRefs<M> : OwnRefs<M> & GroupRefs<M>;
40
48
  export type Api<Modules> = {
41
49
  [K in keyof Modules]: ModuleRefs<Modules[K]>;
42
50
  };
@@ -68,6 +76,10 @@ export interface SessionInfo {
68
76
  type: string;
69
77
  displayName?: string;
70
78
  roles: string[];
79
+ preview?: {
80
+ role: string;
81
+ actualRole: string;
82
+ };
71
83
  } | null;
72
84
  permissions: string[];
73
85
  application: string;
@@ -184,7 +196,7 @@ export interface InvitationInfo {
184
196
  id: string;
185
197
  email: string;
186
198
  role: string;
187
- status: "open" | "accepted" | "revoked" | "expired";
199
+ status: "open" | "accepted" | "revoked" | "declined" | "expired";
188
200
  invitedBy: string;
189
201
  inviterName?: string;
190
202
  createdAt: string;
@@ -196,7 +208,7 @@ export interface InvitationPreview {
196
208
  role: string;
197
209
  inviterName?: string;
198
210
  email: string;
199
- status: "open" | "accepted" | "revoked" | "expired";
211
+ status: "open" | "accepted" | "revoked" | "declined" | "expired";
200
212
  expiresAt: string;
201
213
  }
202
214
  export interface AccountInfo {
@@ -303,6 +315,40 @@ export type InvocationStatusQuery = {
303
315
  export declare function isOutcomeUnknown(error: unknown): boolean;
304
316
  /** The call an unknown outcome is about (its request id), when the error names it. */
305
317
  export declare function unknownCallId(error: unknown): string | undefined;
318
+ /**
319
+ * A proposal by one of the application's agents (app.agent), as /api/agent/approvals shows it to a person who may
320
+ * decide it. Send `attempt` and `inputDigest` back with decideAgentApproval: the decision binds to what you reviewed.
321
+ */
322
+ export interface AgentApproval extends Omit<OwnAction, "objective"> {
323
+ /** The proposal's attempt: a retry after a failure is a new attempt, reviewed and approved again. */
324
+ attempt: number;
325
+ agent: {
326
+ name: string;
327
+ displayName?: string;
328
+ };
329
+ run: {
330
+ taskId: string;
331
+ objective: string;
332
+ status: string;
333
+ workspace: string | null;
334
+ };
335
+ /** Whether you may approve it now, and if not, why (the server decides again when you do). */
336
+ approvable: {
337
+ allowed: boolean;
338
+ reason?: string;
339
+ };
340
+ }
341
+ /** One proposal with what you need to decide it: the agent's own words for the call, the run's input, its history. */
342
+ export interface AgentApprovalDetail extends AgentApproval {
343
+ explanation: string | null;
344
+ runInput: unknown;
345
+ history: Array<{
346
+ state: string;
347
+ at: string;
348
+ by: string;
349
+ note?: string;
350
+ }>;
351
+ }
306
352
  export interface OwnAction {
307
353
  taskId: string;
308
354
  objective?: string;
@@ -413,6 +459,12 @@ export declare class FeltKitClient {
413
459
  /** "cookie" or "bearer": see ClientOptions.session. */
414
460
  readonly mode: "cookie" | "bearer";
415
461
  constructor(options?: ClientOptions);
462
+ /**
463
+ * Reconnect the live streams now instead of after their back-off. A browser tells the client itself (`online`,
464
+ * `visibilitychange`); a host with no such events (React Native: the app returning to the foreground, the network
465
+ * coming back) calls this. Harmless when nothing is waiting.
466
+ */
467
+ wake(): void;
416
468
  get connected(): boolean;
417
469
  /** The absolute URL of a file link (`ctx.services.files.link`), for `<a href>` or `<img src>`. */
418
470
  fileUrl(link: {
@@ -491,6 +543,25 @@ export declare class FeltKitClient {
491
543
  watchOwnActions(filter: {
492
544
  state?: OwnAction["state"];
493
545
  }, listener: (actions: OwnAction[]) => void, onError?: (error: FeltKitClientError) => void): () => void;
546
+ /**
547
+ * Proposals by the application's agents that you may decide: in your workspace, for capabilities you may perform
548
+ * yourself. Default: those waiting (`state: "proposed"`); `"all"` includes decided ones.
549
+ */
550
+ agentApprovals(filter?: {
551
+ state?: AgentApproval["state"] | "all";
552
+ limit?: number;
553
+ }): Promise<AgentApproval[]>;
554
+ /** One agent proposal, with the agent's explanation, the run's input and the proposal's history. NOT_FOUND unless you may decide it. */
555
+ agentApproval(taskId: string, actionId: string): Promise<AgentApprovalDetail>;
556
+ /**
557
+ * Approve or reject an agent's proposal, as you, bound to what you reviewed (`attempt`, and `inputDigest` to
558
+ * approve). Approving runs it (as the agent, through AppPort) before this resolves; the agent's run then resumes.
559
+ * Deciding what is already decided answers its current state. A different attempt or input is refused
560
+ * (FAILED_PRECONDITION): review it again.
561
+ */
562
+ decideAgentApproval(approval: Pick<AgentApproval, "taskId" | "actionId" | "attempt"> & {
563
+ inputDigest?: string;
564
+ }, decision: "approve" | "reject", reason?: string): Promise<AgentApproval>;
494
565
  /** Approve one of your own proposed actions. It runs (as you, through AppPort) before this resolves. */
495
566
  approveAction(taskId: string, actionId: string, reviewed?: {
496
567
  inputDigest?: string;
@@ -577,12 +648,33 @@ export declare class FeltKitClient {
577
648
  signOutEverywhere(options?: {
578
649
  keepCurrent?: boolean;
579
650
  }): Promise<number>;
651
+ /**
652
+ * An agent this application runs on the agent runtime (`app.agent(name, { project })`), as the signed-in person in
653
+ * their workspace: its state, activating it, the workspace's sessions with it, sending messages, reading and
654
+ * following a session's history (messages, calls, approvals, turns), and answering an approval (recorded as an
655
+ * AppPort approval of exactly the call waiting).
656
+ */
657
+ agent(name: string): AgentClient;
658
+ /**
659
+ * The same as `agent(name)`, under the runtime's internal name.
660
+ * @deprecated Use `agent(name)`.
661
+ * An eve agent this application runs (`feltkit({ eve })`), as the signed-in person in their workspace: its state,
662
+ * activating it, the workspace's sessions with it, sending messages, reading and following a session's history
663
+ * (eve's facts: messages, calls, approvals, turns), and answering an approval (recorded as an AppPort approval of
664
+ * exactly the call waiting).
665
+ */
666
+ eve(agent: string): EveAgentClient;
580
667
  /** Your tenants, the one this session works in, and what you may do there. */
581
668
  tenants(): Promise<TenantsInfo>;
582
669
  /** Create a tenant (you hold its top role) and switch to it. */
583
670
  createTenant(name: string): Promise<TenantInfo>;
584
671
  /** Work in another of your tenants (null: none). Every live query re-runs for it. */
585
672
  switchTenant(tenantId: string | null): Promise<TenantInfo | null>;
673
+ /**
674
+ * See the application as a lower role of yours in this tenant (`role`), read-only: the server answers every call as
675
+ * that role, and refuses every change until the preview ends (`null`). Owners use it to check what each role sees.
676
+ */
677
+ previewRole(role: string | null): Promise<TenantInfo | null>;
586
678
  members(): Promise<TenantMember[]>;
587
679
  setMemberRole(principalId: string, role: string): Promise<void>;
588
680
  /** Add an agent or service (an operator-issued identity) to the current tenant. People are invited instead. */
@@ -634,6 +726,8 @@ export declare class FeltKitClient {
634
726
  revokeInvitation(id: string): Promise<void>;
635
727
  /** What an invitation link is for, before accepting it (no sign-in needed). */
636
728
  previewInvitation(token: string): Promise<InvitationPreview>;
729
+ /** Decline an invitation (its holder; no sign-in needed). A declined invitation cannot be accepted. */
730
+ declineInvitation(token: string): Promise<void>;
637
731
  /** Accept an invitation (signed in with the invited address) and switch to its tenant. */
638
732
  acceptInvitation(token: string): Promise<TenantInfo | null>;
639
733
  /** Magic link: e-mail a sign-in link and code to this address (same answer whether or not it can sign in). */
@@ -707,7 +801,7 @@ export declare function waitOrWake(ms: number, signal: AbortSignal, target?: {
707
801
  visibilityState?: string;
708
802
  addEventListener?: (t: string, l: () => void) => void;
709
803
  removeEventListener?: (t: string, l: () => void) => void;
710
- } | undefined): Promise<boolean>;
804
+ } | undefined, wakers?: Set<() => void>): Promise<boolean>;
711
805
  export declare function createClient(options?: ClientOptions): FeltKitClient;
712
806
  /**
713
807
  * Which control frames to show. A revision is a digest, not a counter, so order comes from the state itself: the
@@ -717,4 +811,171 @@ export declare function createClient(options?: ClientOptions): FeltKitClient;
717
811
  export declare function controlRevisions(): {
718
812
  accept(state: AgentControlState): boolean;
719
813
  };
814
+ /** One fact of an eve session's history (`type`: e.g. `turn.started`, `call.requested`, `interaction.opened`). */
815
+ export interface EveFact {
816
+ type: string;
817
+ data?: Record<string, unknown>;
818
+ scope?: {
819
+ runId?: string;
820
+ turnId?: string;
821
+ };
822
+ }
823
+ export interface EveAgentStatus {
824
+ agent: string;
825
+ displayName: string;
826
+ state: "starting" | "ready" | "restarting" | "failed" | "stopped";
827
+ detail?: string;
828
+ activated: boolean;
829
+ worker: string;
830
+ capabilities: Array<{
831
+ capability: string;
832
+ approval: "required" | "none";
833
+ allowed: boolean;
834
+ }>;
835
+ }
836
+ export interface EveSessionInfo {
837
+ id: string;
838
+ agent: string;
839
+ tenantId: string | null;
840
+ createdBy: string;
841
+ createdAt: number;
842
+ title: string;
843
+ /** The agent task this session is: steer it with useAgentControl(taskId), <AgentControlBar>, <AgentUpdateComposer>. */
844
+ taskId?: string;
845
+ }
846
+ /** `client.eve(name)`: an eve agent of the application, as the signed-in person. */
847
+ export interface EveAgentClient {
848
+ status(): Promise<EveAgentStatus>;
849
+ /** Make the agent a member of your workspace (needs tenant.members.manage and feltkit.workers.write). */
850
+ activate(): Promise<{
851
+ worker: string;
852
+ activated: boolean;
853
+ }>;
854
+ sessions(): Promise<EveSessionInfo[]>;
855
+ start(message: string): Promise<{
856
+ sessionId: string;
857
+ deliveryId: string;
858
+ }>;
859
+ send(sessionId: string, message: string): Promise<{
860
+ deliveryId: string;
861
+ }>;
862
+ /** The session's history so far. */
863
+ history(sessionId: string): Promise<EveFact[]>;
864
+ /** Follow the session: `onFacts` gets its whole history each time it grows. Returns stop(). */
865
+ follow(sessionId: string, onFacts: (facts: EveFact[]) => void, onError?: (error: unknown) => void): () => void;
866
+ /** Approve or deny a call the agent is waiting on. */
867
+ answer(sessionId: string, interactionId: string, decision: "approve" | "deny"): Promise<{
868
+ approval?: string;
869
+ }>;
870
+ /**
871
+ * Everything recorded about a session, readable after it ended: its state now, the timeline (messages, updates,
872
+ * model steps, tool calls with whether they changed anything, approvals, replies, turns), the lifecycle's history,
873
+ * each update's progress, and who answered which approval.
874
+ */
875
+ evidence(sessionId: string): Promise<AgentEvidence>;
876
+ }
877
+ /** What a session is doing now, from the runtime's facts and the lifecycle's record. */
878
+ export type AgentExecutionState = "idle" | "submitted" | "running" | "model" | "tool" | "approval" | "pausing" | "paused" | "interrupting" | "interrupted" | "resuming" | "completed" | "failed" | "stopped";
879
+ /** One entry of a session's evidence timeline (never the model's reasoning). */
880
+ export type AgentEvidenceEntry = {
881
+ kind: "message";
882
+ at?: string;
883
+ text: string;
884
+ from?: string;
885
+ } | {
886
+ kind: "update";
887
+ at?: string;
888
+ instructionId: string;
889
+ text: string;
890
+ } | {
891
+ kind: "model";
892
+ at?: string;
893
+ runId: string;
894
+ outcome?: string;
895
+ } | {
896
+ kind: "tool";
897
+ at?: string;
898
+ callId: string;
899
+ tool: string;
900
+ capability: string | null;
901
+ input: unknown;
902
+ outcome?: string;
903
+ output?: unknown;
904
+ effect: "changed" | "attempted" | "not-run" | "read" | "outside" | "unknown";
905
+ approved?: string;
906
+ started?: boolean;
907
+ } | {
908
+ kind: "approval";
909
+ at?: string;
910
+ interactionId: string;
911
+ prompt: string;
912
+ outcome?: string;
913
+ } | {
914
+ kind: "held";
915
+ at?: string;
916
+ boundary?: string;
917
+ reason?: string;
918
+ } | {
919
+ kind: "reply";
920
+ at?: string;
921
+ text: string;
922
+ } | {
923
+ kind: "turn";
924
+ at?: string;
925
+ turnId?: string;
926
+ outcome?: string;
927
+ };
928
+ /** `client.agent(name).evidence(sessionId)`. */
929
+ export interface AgentEvidence {
930
+ session: {
931
+ id: string;
932
+ title: string;
933
+ createdBy: string;
934
+ createdAt: number;
935
+ taskId: string | null;
936
+ };
937
+ state: AgentExecutionState;
938
+ ended: boolean;
939
+ /** Whether the runtime still holds the session's history ("gone" only for sessions ended before history was kept). */
940
+ runtimeHistory: "available" | "gone" | "unavailable";
941
+ control: {
942
+ phase: string;
943
+ mode: string;
944
+ reason: string | null;
945
+ revision: string;
946
+ } | null;
947
+ controlHistory: Array<{
948
+ mode: string;
949
+ at: string;
950
+ by: string;
951
+ note?: string;
952
+ }>;
953
+ /** Who stopped it and when (pause, interrupt and resume are in `controlHistory`). */
954
+ stopped: {
955
+ by: string;
956
+ at: number;
957
+ reason?: string;
958
+ } | null;
959
+ updates: Array<AgentUpdate & {
960
+ turnId?: string;
961
+ turn?: string;
962
+ }>;
963
+ answers: Array<{
964
+ interactionId: string;
965
+ decision: "approve" | "deny";
966
+ by: string;
967
+ at: number;
968
+ capability?: string;
969
+ approval?: string;
970
+ }>;
971
+ timeline: AgentEvidenceEntry[];
972
+ }
973
+ /** A recorded fact of an agent session (a message, a call, an approval, a turn). */
974
+ export type AgentFact = EveFact;
975
+ /** An agent's state for the signed-in person: running, activated in their workspace, its capabilities. */
976
+ export type AgentStatus = EveAgentStatus;
977
+ /** One of the workspace's sessions with an agent. */
978
+ export type AgentSessionInfo = EveSessionInfo;
979
+ /** `client.agent(name)`: an agent this application runs on the agent runtime. */
980
+ export type AgentClient = EveAgentClient;
720
981
  export {};
@@ -196,6 +196,16 @@ export class FeltKitClient {
196
196
  if (notify)
197
197
  this.#notifySession();
198
198
  }
199
+ #wakers = new Set();
200
+ /**
201
+ * Reconnect the live streams now instead of after their back-off. A browser tells the client itself (`online`,
202
+ * `visibilitychange`); a host with no such events (React Native: the app returning to the foreground, the network
203
+ * coming back) calls this. Harmless when nothing is waiting.
204
+ */
205
+ wake() {
206
+ for (const wake of [...this.#wakers])
207
+ wake();
208
+ }
199
209
  get connected() {
200
210
  return this.#connected;
201
211
  }
@@ -456,6 +466,38 @@ export class FeltKitClient {
456
466
  void run();
457
467
  return () => controller.abort();
458
468
  }
469
+ /**
470
+ * Proposals by the application's agents that you may decide: in your workspace, for capabilities you may perform
471
+ * yourself. Default: those waiting (`state: "proposed"`); `"all"` includes decided ones.
472
+ */
473
+ async agentApprovals(filter = {}) {
474
+ await this.#upgrade;
475
+ const query = new URLSearchParams({ ...(filter.state ? { state: filter.state } : {}), ...(filter.limit ? { limit: String(filter.limit) } : {}) });
476
+ const response = await this.#fetch(`${this.url}/api/agent/approvals${query.size ? `?${query}` : ""}`, { credentials: "same-origin", headers: this.#headers() });
477
+ const payload = (await response.json());
478
+ if (!payload.ok)
479
+ throw new FeltKitClientError(payload.error ?? { code: "INTERNAL", message: "Could not list approvals." });
480
+ return payload.approvals;
481
+ }
482
+ /** One agent proposal, with the agent's explanation, the run's input and the proposal's history. NOT_FOUND unless you may decide it. */
483
+ async agentApproval(taskId, actionId) {
484
+ await this.#upgrade;
485
+ const response = await this.#fetch(`${this.url}/api/agent/approvals/${encodeURIComponent(taskId)}/${encodeURIComponent(actionId)}`, { credentials: "same-origin", headers: this.#headers() });
486
+ const payload = (await response.json());
487
+ if (!payload.ok)
488
+ throw new FeltKitClientError(payload.error ?? { code: "INTERNAL", message: "Could not read the approval." });
489
+ return payload.approval;
490
+ }
491
+ /**
492
+ * Approve or reject an agent's proposal, as you, bound to what you reviewed (`attempt`, and `inputDigest` to
493
+ * approve). Approving runs it (as the agent, through AppPort) before this resolves; the agent's run then resumes.
494
+ * Deciding what is already decided answers its current state. A different attempt or input is refused
495
+ * (FAILED_PRECONDITION): review it again.
496
+ */
497
+ async decideAgentApproval(approval, decision, reason) {
498
+ const payload = await this.#post("/api/agent/approvals/decide", { taskId: approval.taskId, actionId: approval.actionId, attempt: approval.attempt, decision, ...(approval.inputDigest ? { inputDigest: approval.inputDigest } : {}), ...(reason ? { reason } : {}) });
499
+ return payload.approval;
500
+ }
459
501
  /** Approve one of your own proposed actions. It runs (as you, through AppPort) before this resolves. */
460
502
  async approveAction(taskId, actionId, reviewed) {
461
503
  const payload = await this.#post("/api/agent/actions/approve", { taskId, actionId, ...(reviewed?.inputDigest ? { inputDigest: reviewed.inputDigest } : {}) });
@@ -672,6 +714,116 @@ export class FeltKitClient {
672
714
  this.#notifySession();
673
715
  }
674
716
  // ── Tenancy (auth.tenant) ────────────────────────────────────────────────────
717
+ /**
718
+ * An agent this application runs on the agent runtime (`app.agent(name, { project })`), as the signed-in person in
719
+ * their workspace: its state, activating it, the workspace's sessions with it, sending messages, reading and
720
+ * following a session's history (messages, calls, approvals, turns), and answering an approval (recorded as an
721
+ * AppPort approval of exactly the call waiting).
722
+ */
723
+ agent(name) {
724
+ return this.eve(name);
725
+ }
726
+ /**
727
+ * The same as `agent(name)`, under the runtime's internal name.
728
+ * @deprecated Use `agent(name)`.
729
+ * An eve agent this application runs (`feltkit({ eve })`), as the signed-in person in their workspace: its state,
730
+ * activating it, the workspace's sessions with it, sending messages, reading and following a session's history
731
+ * (eve's facts: messages, calls, approvals, turns), and answering an approval (recorded as an AppPort approval of
732
+ * exactly the call waiting).
733
+ */
734
+ eve(agent) {
735
+ const root = `/api/eve/${encodeURIComponent(agent)}`;
736
+ const forward = `/eve/${encodeURIComponent(agent)}/eve/v1/session`;
737
+ const readFacts = async (sessionId, follow, signal, onLine) => {
738
+ await this.#upgrade;
739
+ const response = await this.#fetch(`${this.url}${forward}/${encodeURIComponent(sessionId)}/stream?startIndex=0&follow=${follow}`, { credentials: "same-origin", headers: this.#headers(), ...(signal ? { signal } : {}) });
740
+ if (!response.ok) {
741
+ const payload = (await response.json().catch(() => null));
742
+ throw new FeltKitClientError(payload?.error ?? { code: "UNAVAILABLE", message: `The agent answered ${response.status}.` });
743
+ }
744
+ const facts = [];
745
+ const take = (line) => {
746
+ const text = line.trim();
747
+ if (!text.startsWith("{"))
748
+ return;
749
+ try {
750
+ const parsed = JSON.parse(text);
751
+ if (Array.isArray(parsed.facts) && parsed.facts.length) {
752
+ facts.push(...parsed.facts);
753
+ onLine?.(facts.slice());
754
+ }
755
+ }
756
+ catch {
757
+ /* a partial or foreign line */
758
+ }
759
+ };
760
+ if (!response.body || !follow) {
761
+ for (const line of (await response.text()).split("\n"))
762
+ take(line);
763
+ return facts;
764
+ }
765
+ const reader = response.body.getReader();
766
+ const decoder = new TextDecoder();
767
+ let buffered = "";
768
+ for (;;) {
769
+ const { done, value } = await reader.read();
770
+ if (done)
771
+ break;
772
+ buffered += decoder.decode(value, { stream: true });
773
+ const lines = buffered.split("\n");
774
+ buffered = lines.pop() ?? "";
775
+ for (const line of lines)
776
+ take(line);
777
+ }
778
+ take(buffered);
779
+ return facts;
780
+ };
781
+ return {
782
+ status: async () => {
783
+ const { ok: _ok, ...status } = await this.#get(root);
784
+ return status;
785
+ },
786
+ activate: async () => {
787
+ const { worker, activated } = await this.#post(`${root}/activate`, {});
788
+ return { worker, activated };
789
+ },
790
+ sessions: async () => (await this.#get(`${root}/sessions`)).sessions,
791
+ start: async (message) => {
792
+ const payload = await this.#post(forward, { message });
793
+ return { sessionId: String(payload.sessionId), deliveryId: String(payload.deliveryId ?? "") };
794
+ },
795
+ send: async (sessionId, message) => {
796
+ const payload = await this.#post(`${forward}/${encodeURIComponent(sessionId)}`, { message });
797
+ return { deliveryId: String(payload.deliveryId ?? "") };
798
+ },
799
+ history: (sessionId) => readFacts(sessionId, false, undefined),
800
+ follow: (sessionId, onFacts, onError) => {
801
+ const controller = new AbortController();
802
+ void (async () => {
803
+ let delay = 500;
804
+ while (!controller.signal.aborted) {
805
+ try {
806
+ await readFacts(sessionId, true, controller.signal, onFacts);
807
+ delay = 500;
808
+ }
809
+ catch (error) {
810
+ if (controller.signal.aborted)
811
+ return;
812
+ onError?.(error);
813
+ delay = Math.min(delay * 2, 10_000);
814
+ }
815
+ await new Promise((r) => setTimeout(r, delay));
816
+ }
817
+ })();
818
+ return () => controller.abort();
819
+ },
820
+ evidence: async (sessionId) => (await this.#get(`${root}/sessions/${encodeURIComponent(sessionId)}/evidence`)).evidence,
821
+ answer: async (sessionId, interactionId, decision) => {
822
+ const { approval } = await this.#post(`${root}/answer`, { sessionId, interactionId, decision });
823
+ return { ...(approval ? { approval: String(approval) } : {}) };
824
+ },
825
+ };
826
+ }
675
827
  async #get(path) {
676
828
  await this.#upgrade;
677
829
  const response = await this.#fetch(`${this.url}${path}`, { credentials: "same-origin", headers: this.#headers() });
@@ -697,6 +849,15 @@ export class FeltKitClient {
697
849
  this.#accept(payload);
698
850
  return payload.tenant;
699
851
  }
852
+ /**
853
+ * See the application as a lower role of yours in this tenant (`role`), read-only: the server answers every call as
854
+ * that role, and refuses every change until the preview ends (`null`). Owners use it to check what each role sees.
855
+ */
856
+ async previewRole(role) {
857
+ const payload = await this.#post("/api/tenants/current/preview", { role });
858
+ this.#accept(payload);
859
+ return payload.tenant;
860
+ }
700
861
  async members() {
701
862
  return (await this.#get("/api/tenants/current/members")).members;
702
863
  }
@@ -768,6 +929,10 @@ export class FeltKitClient {
768
929
  async previewInvitation(token) {
769
930
  return (await this.#post("/api/invitations/preview", { token })).invitation;
770
931
  }
932
+ /** Decline an invitation (its holder; no sign-in needed). A declined invitation cannot be accepted. */
933
+ async declineInvitation(token) {
934
+ await this.#post("/api/invitations/decline", { token });
935
+ }
771
936
  /** Accept an invitation (signed in with the invited address) and switch to its tenant. */
772
937
  async acceptInvitation(token) {
773
938
  const payload = await this.#post("/api/invitations/accept", { token });
@@ -1045,7 +1210,7 @@ export class FeltKitClient {
1045
1210
  break;
1046
1211
  // Back off, but reconnect at once when the browser says the network is back or the page is
1047
1212
  // visible again: a client that comes back online catches up in ~one round trip, not ~10 s.
1048
- const woken = await waitOrWake(delay, controller.signal);
1213
+ const woken = await waitOrWake(delay, controller.signal, undefined, undefined, this.#wakers);
1049
1214
  delay = woken ? 500 : Math.min(delay * 2, 10_000);
1050
1215
  this.#emit(["*"]);
1051
1216
  }
@@ -1118,7 +1283,7 @@ export class FeltKitClient {
1118
1283
  }
1119
1284
  if (controller.signal.aborted)
1120
1285
  break;
1121
- const woken = await waitOrWake(delay, controller.signal);
1286
+ const woken = await waitOrWake(delay, controller.signal, undefined, undefined, this.#wakers);
1122
1287
  delay = woken ? 500 : Math.min(delay * 2, 10_000);
1123
1288
  }
1124
1289
  })();
@@ -1170,7 +1335,7 @@ export class FeltKitClient {
1170
1335
  * Wait `ms`, or less: resolves true early on `online`, or on `visibilitychange` to visible, where the
1171
1336
  * environment has them (browsers); false after the full wait or on abort. No-op listeners elsewhere.
1172
1337
  */
1173
- export function waitOrWake(ms, signal, target = globalThis, doc = globalThis.document) {
1338
+ export function waitOrWake(ms, signal, target = globalThis, doc = globalThis.document, wakers) {
1174
1339
  return new Promise((resolve) => {
1175
1340
  let done = false;
1176
1341
  const finish = (woken) => {
@@ -1180,6 +1345,7 @@ export function waitOrWake(ms, signal, target = globalThis, doc = globalThis.doc
1180
1345
  clearTimeout(timer);
1181
1346
  target?.removeEventListener?.("online", online);
1182
1347
  doc?.removeEventListener?.("visibilitychange", visible);
1348
+ wakers?.delete(online);
1183
1349
  signal.removeEventListener("abort", aborted);
1184
1350
  resolve(woken);
1185
1351
  };
@@ -1190,6 +1356,7 @@ export function waitOrWake(ms, signal, target = globalThis, doc = globalThis.doc
1190
1356
  const timer = setTimeout(() => finish(false), ms);
1191
1357
  target?.addEventListener?.("online", online);
1192
1358
  doc?.addEventListener?.("visibilitychange", visible);
1359
+ wakers?.add(online);
1193
1360
  signal.addEventListener("abort", aborted, { once: true });
1194
1361
  });
1195
1362
  }