@botmanor/fe-sdk 2026.1204.4 → 2026.1205.2

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/README.md CHANGED
@@ -3,7 +3,11 @@
3
3
  Embed BotManor **Stewards** (🗺️ in development — BOFF-15352).
4
4
 
5
5
  ```tsx
6
- import { StewardsSdkProvider, StewardConsole, useStewardsEvent } from '@botmanor/fe-sdk';
6
+ import {
7
+ StewardsSdkProvider,
8
+ StewardConsole,
9
+ useStewardsEvent,
10
+ } from "@botmanor/fe-sdk";
7
11
 
8
12
  <StewardsSdkProvider
9
13
  gatewayUrl={gatewayUrl}
@@ -12,10 +16,10 @@ import { StewardsSdkProvider, StewardConsole, useStewardsEvent } from '@botmanor
12
16
  getWorkspaceToken={() => auth.currentWorkspaceToken()} // app shells only
13
17
  onTokenExpired={() => auth.refresh()}
14
18
  onEvent={(e) => analytics.track(e.type)}
15
- theme={{ accent: 'var(--my-brand)' }}
19
+ theme={{ accent: "var(--my-brand)" }}
16
20
  >
17
21
  <StewardConsole stewardId={stewardId} />
18
- </StewardsSdkProvider>
22
+ </StewardsSdkProvider>;
19
23
  ```
20
24
 
21
25
  Theme variables are scoped to the SDK's wrapper; the SDK never styles your page.
@@ -32,7 +36,11 @@ cookies, no referrer. Inside a Burdenoff app shell, also pass
32
36
  (sent as `X-Workspace-Authorization`) beside the access token for
33
37
  workspace-scoped fields. An embed on a third-party page leaves it out. A 401 or
34
38
  `UNAUTHENTICATED` (or a `getWorkspaceToken` that throws) raises `onTokenExpired`
35
- and the `auth.expired` event. Operations match `@burdenoff/microfe-stewards` and use the
39
+ and the `auth.expired` event. Requests never follow a redirect. An app
40
+ shell behind Cloudflare Access that serves the gateway through a same-origin
41
+ proxy sets `sameOriginCredentials` so the Access session cookie reaches it;
42
+ cookies then go only to the page's own origin, never to a cross-origin
43
+ gateway. Operations match `@burdenoff/microfe-stewards` and use the
36
44
  `Botmanor*` schema; the SDK does not depend on that package because it pulls in
37
45
  Apollo and the fe-libs shell.
38
46
 
package/dist/index.d.ts CHANGED
@@ -129,6 +129,14 @@ interface StewardsSdkConfig {
129
129
  * it: its single embed session token already names the workspace.
130
130
  */
131
131
  getWorkspaceToken?: () => string | null | undefined | Promise<string | null | undefined>;
132
+ /**
133
+ * Send the browser's cookies when `gatewayUrl` is on the page's own origin
134
+ * (`credentials: "same-origin"`). Off by default: requests carry no cookies.
135
+ * A Burdenoff app shell behind Cloudflare Access (alpha) turns it on, because
136
+ * it serves the gateway through a same-origin proxy and the Access session
137
+ * cookie must reach it. A cross-origin gateway never gets cookies.
138
+ */
139
+ sameOriginCredentials?: boolean;
132
140
  /** Called when the token getter throws or the gateway answers 401. */
133
141
  onTokenExpired?: (reason: string) => void;
134
142
  /** Every SDK event, for hosts that prefer one callback to `useStewardsEvent`. */
@@ -157,49 +165,6 @@ export declare function StewardsSdkProvider({ children, ...config }: StewardsSdk
157
165
  export declare function useStewardsSdk(): StewardsSdkContextValue;
158
166
  /** Subscribe to one SDK event for the lifetime of the calling component. */
159
167
  export declare function useStewardsEvent<K extends StewardsEventType>(type: K, handler: (payload: StewardsEventMap[K]) => void): void;
160
- interface StewardConsoleProps {
161
- /**
162
- * The steward to show. Omitted lists the workspace's stewards and lets the
163
- * viewer open one (the host can follow along through `onSelectSteward`).
164
- */
165
- stewardId?: string;
166
- onSelectSteward?: (stewardId: string) => void;
167
- /**
168
- * Link to VibeControls, where a machine's owner grants it to a steward
169
- * (shown for a steward whose desk kind is OWN_MACHINE).
170
- */
171
- vibecontrolsUrl?: string;
172
- }
173
- /** List stewards, or open one: its charter summary, start a run, recent runs. */
174
- export declare function StewardConsole({ stewardId, onSelectSteward, vibecontrolsUrl }: StewardConsoleProps): import("react").JSX.Element;
175
- interface StewardBuilderProps {
176
- /** Start from an existing agent; omitted shows the agent picker. */
177
- agentId?: string;
178
- /** Edit the charter of this steward instead of creating one. */
179
- stewardId?: string;
180
- /** Called with the new steward's id once it is created. */
181
- onCreated?: (stewardId: string) => void;
182
- /** Called with the steward's id once its charter is saved. */
183
- onSaved?: (stewardId: string) => void;
184
- }
185
- /**
186
- * Create a steward from an agent and a charter, or edit an existing charter:
187
- * the charter text, the autonomy level and a daily credit budget. Duties and
188
- * playbooks live in the full Stewards app.
189
- */
190
- export declare function StewardBuilder(props: StewardBuilderProps): import("react").JSX.Element;
191
- interface StewardRunViewProps {
192
- /** The run to show. */
193
- runId: string;
194
- /** Poll interval while the run is active. Defaults to 3000 ms. */
195
- pollIntervalMs?: number;
196
- }
197
- /**
198
- * One run: its steps, approvals, trust level and budget. Polls the gateway
199
- * while the run is active (the embed session is not a subscription actor) and
200
- * emits `run.waiting`, `run.completed` and `run.failed` as the status changes.
201
- */
202
- export declare function StewardRunView({ runId, pollIntervalMs }: StewardRunViewProps): import("react").JSX.Element;
203
168
  /**
204
169
  * The slice of the workspace gateway schema the SDK reads and writes. Names
205
170
  * follow the `Botmanor*` types of the Hive production supergraph (the same
@@ -364,18 +329,39 @@ interface OwnMachineGrant {
364
329
  expiresAt: string;
365
330
  scopes: string[];
366
331
  }
367
- /** Where the person grants a machine to a steward, by default. */
332
+ /** Where the person manages their VibeControls machines, by default. */
368
333
  export declare const DEFAULT_VIBECONTROLS_URL = "https://app.vibecontrols.com/";
369
334
  /** Machines per page when listing the workspace's VibeControls machines. */
370
335
  export declare const OWN_MACHINE_PAGE_SIZE = 100;
371
336
  /** Pages read at most (10 000 machines); the list says when it stopped early. */
372
337
  export declare const OWN_MACHINE_MAX_PAGES = 100;
338
+ /** The grant lengths the owner can pick, in days. */
339
+ export declare const OWN_MACHINE_GRANT_DAYS: readonly [1, 7, 30];
340
+ type OwnMachineGrantDays = (typeof OWN_MACHINE_GRANT_DAYS)[number];
341
+ /**
342
+ * What the host knows about the viewer, so the picker offers only what the
343
+ * gateway would allow. Every field is optional: an omitted one is not checked
344
+ * here and the gateway decides (an embed without permission data keeps
345
+ * working). The gateway stays the enforcement point either way.
346
+ */
347
+ interface OwnMachineAccess {
348
+ /** The signed-in person. Choosing, clearing and granting are the steward owner's only. */
349
+ viewerActorId?: string | null;
350
+ /** botmanor-steward:update, on a steward that is not archived. */
351
+ canUpdateSteward?: boolean;
352
+ /** agent:read: list the workspace's machines and the steward's grants. */
353
+ canReadMachines?: boolean;
354
+ /** agent:update: grant a machine to the steward, or revoke the grant. */
355
+ canGrantMachines?: boolean;
356
+ }
373
357
  interface StewardOwnMachineDeskProps {
374
358
  stewardId: string;
375
359
  /** The steward's owner: only their machines are offered. */
376
360
  ownerActorId: string;
377
- /** Link to VibeControls, where a machine's owner grants it to a steward. */
361
+ /** Link to VibeControls, where a person manages their machines. Pass the current environment's app. */
378
362
  vibecontrolsUrl?: string;
363
+ /** What the viewer may do; see {@link OwnMachineAccess}. */
364
+ access?: OwnMachineAccess;
379
365
  /** Called after the machine is chosen or cleared. */
380
366
  onChanged?: (desk: StewardOwnMachineDesk$1 | null) => void;
381
367
  }
@@ -392,6 +378,23 @@ interface OwnMachineRow {
392
378
  * past its expiry (`now`, for tests).
393
379
  */
394
380
  export declare function ownMachineRows(agents: readonly OwnMachineCandidate[], grants: readonly OwnMachineGrant[], ownerActorId: string, chosenAgentId: string | null, now?: number): OwnMachineRow[];
381
+ /** The expiry to send for a grant of `days`, never past the service's 30-day limit. */
382
+ export declare function ownMachineGrantExpiry(days: OwnMachineGrantDays, now?: number): string;
383
+ /**
384
+ * The app names to send on a grant: one per line, trimmed, lower-cased
385
+ * (VibeControls compares lower-case names), de-duplicated and capped at 64.
386
+ */
387
+ export declare function ownMachineAllowedApps(text: string): string[];
388
+ /** How many distinct app names the text holds, before the 64-name cap. */
389
+ export declare function ownMachineAppCount(text: string): number;
390
+ /** When the earliest live grant expires (epoch ms), or null. */
391
+ export declare function nextOwnMachineGrantExpiry(grants: readonly OwnMachineGrant[], now?: number): number | null;
392
+ /** What the viewer may do with the picker, from {@link OwnMachineAccess}. */
393
+ export declare function ownMachineAbilities(ownerActorId: string, access?: OwnMachineAccess): {
394
+ manage: boolean;
395
+ read: boolean;
396
+ grant: boolean;
397
+ };
395
398
  /**
396
399
  * The desk settings of a steward whose desk kind is OWN_MACHINE, inside the
397
400
  * SDK's themed wrapper: use it on its own. `StewardConsole` renders
@@ -400,14 +403,64 @@ export declare function ownMachineRows(agents: readonly OwnMachineCandidate[], g
400
403
  export declare function StewardOwnMachineDesk(props: StewardOwnMachineDeskProps): import("react").JSX.Element;
401
404
  /**
402
405
  * The owner's VibeControls machines, which ones have granted this steward,
403
- * and the one it works on. Choosing calls `setBotmanorStewardOwnMachineDesk`,
404
- * clearing calls `clearBotmanorStewardOwnMachineDesk`; the service's refusals
405
- * (no grant, machine in use, changed concurrently, check unavailable) are
406
- * shown with the service's own message. The list refreshes when the tab gets
407
- * focus again (the owner may have just granted a machine in VibeControls) and
408
- * on "Refresh". The gateway stays the enforcement point.
406
+ * and the one it works on. The owner can grant a machine to the steward
407
+ * (`grantVibecontrolsAgentToSteward`), revoke the grant, choose a granted
408
+ * machine (`setBotmanorStewardOwnMachineDesk`) or clear the choice
409
+ * (`clearBotmanorStewardOwnMachineDesk`). Controls follow `access`; the
410
+ * service's refusals (no grant, machine in use, changed concurrently, check
411
+ * unavailable) are shown with the service's own message. Refresh and the tab
412
+ * regaining focus reload the desk, the machines and the grants, and a row
413
+ * re-renders when its grant expires. The gateway stays the enforcement point.
414
+ */
415
+ export declare function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl, access, onChanged }: StewardOwnMachineDeskProps): import("react").JSX.Element;
416
+ interface StewardConsoleProps {
417
+ /**
418
+ * The steward to show. Omitted lists the workspace's stewards and lets the
419
+ * viewer open one (the host can follow along through `onSelectSteward`).
420
+ */
421
+ stewardId?: string;
422
+ onSelectSteward?: (stewardId: string) => void;
423
+ /**
424
+ * Link to VibeControls, where a machine's owner grants it to a steward
425
+ * (shown for a steward whose desk kind is OWN_MACHINE).
426
+ */
427
+ vibecontrolsUrl?: string;
428
+ /**
429
+ * What the viewer may do with an own-machine steward's machine (ownership
430
+ * and permissions). Omitted fields are left to the gateway.
431
+ */
432
+ ownMachineAccess?: OwnMachineAccess;
433
+ }
434
+ /** List stewards, or open one: its charter summary, start a run, recent runs. */
435
+ export declare function StewardConsole({ stewardId, onSelectSteward, vibecontrolsUrl, ownMachineAccess }: StewardConsoleProps): import("react").JSX.Element;
436
+ interface StewardBuilderProps {
437
+ /** Start from an existing agent; omitted shows the agent picker. */
438
+ agentId?: string;
439
+ /** Edit the charter of this steward instead of creating one. */
440
+ stewardId?: string;
441
+ /** Called with the new steward's id once it is created. */
442
+ onCreated?: (stewardId: string) => void;
443
+ /** Called with the steward's id once its charter is saved. */
444
+ onSaved?: (stewardId: string) => void;
445
+ }
446
+ /**
447
+ * Create a steward from an agent and a charter, or edit an existing charter:
448
+ * the charter text, the autonomy level and a daily credit budget. Duties and
449
+ * playbooks live in the full Stewards app.
409
450
  */
410
- export declare function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl, onChanged }: StewardOwnMachineDeskProps): import("react").JSX.Element;
451
+ export declare function StewardBuilder(props: StewardBuilderProps): import("react").JSX.Element;
452
+ interface StewardRunViewProps {
453
+ /** The run to show. */
454
+ runId: string;
455
+ /** Poll interval while the run is active. Defaults to 3000 ms. */
456
+ pollIntervalMs?: number;
457
+ }
458
+ /**
459
+ * One run: its steps, approvals, trust level and budget. Polls the gateway
460
+ * while the run is active (the embed session is not a subscription actor) and
461
+ * emits `run.waiting`, `run.completed` and `run.failed` as the status changes.
462
+ */
463
+ export declare function StewardRunView({ runId, pollIntervalMs }: StewardRunViewProps): import("react").JSX.Element;
411
464
  interface ApprovalInboxProps {
412
465
  /** Limit to one steward; omitted shows every steward approval the viewer can decide. */
413
466
  stewardId?: string;
@@ -420,4 +473,4 @@ interface ApprovalInboxProps {
420
473
  * `mine: true`) rather than a parallel one.
421
474
  */
422
475
  export declare function ApprovalInbox({ stewardId, pollIntervalMs }: ApprovalInboxProps): import("react").JSX.Element;
423
- export type { ApprovalInboxProps, OwnMachineCandidate, OwnMachineGrant, OwnMachineRow, StewardApprovalRequest, StewardBuilderProps, StewardConsoleProps, StewardDetail, StewardListItem, StewardOwnMachineDeskProps, StewardOwnMachineDesk$1 as StewardOwnMachineDeskRecord, StewardRunDetail, StewardRunSummary, StewardRunViewProps, StewardsClient, StewardsEvent, StewardsEventBus, StewardsEventMap, StewardsEventType, StewardsSdkConfig, StewardsSdkContextValue, StewardsTheme };
476
+ export type { ApprovalInboxProps, OwnMachineAccess, OwnMachineCandidate, OwnMachineGrant, OwnMachineGrantDays, OwnMachineRow, StewardApprovalRequest, StewardBuilderProps, StewardConsoleProps, StewardDetail, StewardListItem, StewardOwnMachineDeskProps, StewardOwnMachineDesk$1 as StewardOwnMachineDeskRecord, StewardRunDetail, StewardRunSummary, StewardRunViewProps, StewardsClient, StewardsEvent, StewardsEventBus, StewardsEventMap, StewardsEventType, StewardsSdkConfig, StewardsSdkContextValue, StewardsTheme };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { createContext, use, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2
+ import { createContext, use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
4
 
5
5
  // src/graphql/client.ts
@@ -55,8 +55,18 @@ async function resolveWorkspaceToken(config, options) {
55
55
  /**
56
56
  * GraphQL transport over the public workspace gateway. The access token goes
57
57
  * in the `Authorization` header only (never in the URL or body), the host's
58
- * workspace token, when it gives one, in `X-Workspace-Authorization`; cookies are
59
- * not sent (`credentials: "omit"`), and no referrer leaks the embedding page.
58
+ * workspace token, when it gives one, in `X-Workspace-Authorization`, and no
59
+ * referrer leaks the embedding page.
60
+ *
61
+ * Cookies are not sent (`credentials: "omit"`) unless the host sets
62
+ * `sameOriginCredentials`; then they go only to the page's own origin
63
+ * (`credentials: "same-origin"`). An app shell behind Cloudflare Access on
64
+ * alpha serves the gateway through a same-origin proxy, and the Access session
65
+ * cookie must reach it (BOFF-18393).
66
+ *
67
+ * Redirects are refused (`redirect: "error"`). Fetch drops `Authorization` on a
68
+ * cross-origin redirect but keeps custom headers, so following one could carry
69
+ * the workspace token past the configured gateway (BOFF-18393).
60
70
  */
61
71
  function createStewardsClient(options) {
62
72
  const send = async (document, variables, signal) => {
@@ -79,7 +89,8 @@ function createStewardsClient(options) {
79
89
  query: document,
80
90
  variables
81
91
  }),
82
- credentials: "omit",
92
+ credentials: config.sameOriginCredentials ? "same-origin" : "omit",
93
+ redirect: "error",
83
94
  referrerPolicy: "no-referrer",
84
95
  signal
85
96
  });
@@ -207,13 +218,14 @@ function StewardsSdkProvider({ children, ...config }) {
207
218
  })
208
219
  };
209
220
  });
210
- const { gatewayUrl, workspaceId, getAccessToken, getWorkspaceToken, onTokenExpired, theme } = config;
221
+ const { gatewayUrl, workspaceId, getAccessToken, getWorkspaceToken, sameOriginCredentials, onTokenExpired, theme } = config;
211
222
  const value = useMemo(() => ({
212
223
  config: {
213
224
  gatewayUrl,
214
225
  workspaceId,
215
226
  getAccessToken,
216
227
  ...getWorkspaceToken ? { getWorkspaceToken } : {},
228
+ ...sameOriginCredentials ? { sameOriginCredentials } : {},
217
229
  ...onTokenExpired ? { onTokenExpired } : {},
218
230
  ...onEvent ? { onEvent } : {},
219
231
  ...theme ? { theme } : {}
@@ -225,6 +237,7 @@ function StewardsSdkProvider({ children, ...config }) {
225
237
  workspaceId,
226
238
  getAccessToken,
227
239
  getWorkspaceToken,
240
+ sameOriginCredentials,
228
241
  onTokenExpired,
229
242
  onEvent,
230
243
  theme,
@@ -394,11 +407,20 @@ const LIST_OWN_MACHINE_AGENTS = `query StewardOwnMachineAgents($pagination: Pagi
394
407
  id name hostname platform isActive ownerUserId lastHeartbeat
395
408
  }
396
409
  }`;
397
- /** The steward's active grants (VibeControls returns at most 100, newest first). */
398
- const LIST_OWN_MACHINE_GRANTS = `query StewardOwnMachineGrants($stewardId: ID!) {
399
- vibecontrolsStewardGrants(filter: { stewardId: $stewardId }) {
400
- id agentId status expiresAt scopes
401
- }
410
+ const OWN_MACHINE_GRANT = `id agentId status expiresAt scopes`;
411
+ /**
412
+ * The steward's active grants (VibeControls returns at most 100, newest
413
+ * first). Pass `agentId` to look one machine up when the list may be cut off.
414
+ */
415
+ const LIST_OWN_MACHINE_GRANTS = `query StewardOwnMachineGrants($stewardId: ID!, $agentId: ID) {
416
+ vibecontrolsStewardGrants(filter: { stewardId: $stewardId, agentId: $agentId }) { ${OWN_MACHINE_GRANT} }
417
+ }`;
418
+ /** Only the machine's owner can grant it; granting again extends the same grant. */
419
+ const GRANT_OWN_MACHINE = `mutation GrantStewardOwnMachine($input: GrantVibecontrolsAgentToStewardInput!) {
420
+ grantVibecontrolsAgentToSteward(input: $input) { ${OWN_MACHINE_GRANT} }
421
+ }`;
422
+ const REVOKE_OWN_MACHINE_GRANT = `mutation RevokeStewardOwnMachineGrant($id: ID!) {
423
+ revokeVibecontrolsStewardGrant(id: $id) { ${OWN_MACHINE_GRANT} }
402
424
  }`;
403
425
 
404
426
  // src/graphql/hooks.ts
@@ -666,19 +688,34 @@ function humanize(value) {
666
688
  }
667
689
 
668
690
  // src/components/StewardOwnMachineDesk.tsx
669
- /** Where the person grants a machine to a steward, by default. */
691
+ /** Where the person manages their VibeControls machines, by default. */
670
692
  const DEFAULT_VIBECONTROLS_URL = "https://app.vibecontrols.com/";
671
693
  /** Machines per page when listing the workspace's VibeControls machines. */
672
694
  const OWN_MACHINE_PAGE_SIZE = 100;
673
695
  /** Pages read at most (10 000 machines); the list says when it stopped early. */
674
696
  const OWN_MACHINE_MAX_PAGES = 100;
697
+ /** The owner's machines looked up one by one when the grant list may miss them. */
698
+ const OWN_MACHINE_GRANT_LOOKUPS = 50;
699
+ /** The grant lengths the owner can pick, in days. */
700
+ const OWN_MACHINE_GRANT_DAYS = [
701
+ 1,
702
+ 7,
703
+ 30
704
+ ];
705
+ /** VibeControls accepts at most this many app names on a grant. */
706
+ const OWN_MACHINE_MAX_APPS = 64;
707
+ const DAY_MS = 864e5;
708
+ /** A grant counts while it is ACTIVE and not past its expiry. */
709
+ function isLive(grant, now) {
710
+ return grant.status === "ACTIVE" && new Date(grant.expiresAt).getTime() > now;
711
+ }
675
712
  /**
676
713
  * The owner's machines for the picker: the owner's agents, chosen one first,
677
714
  * then granted ones, then by name. A grant counts while it is ACTIVE and not
678
715
  * past its expiry (`now`, for tests).
679
716
  */
680
717
  function ownMachineRows(agents, grants, ownerActorId, chosenAgentId, now = Date.now()) {
681
- const granted = new Set(grants.filter((g) => g.status === "ACTIVE" && new Date(g.expiresAt).getTime() > now).map((g) => g.agentId));
718
+ const granted = new Set(grants.filter((g) => isLive(g, now)).map((g) => g.agentId));
682
719
  const rank = (row) => row.chosen ? 0 : row.granted ? 1 : 2;
683
720
  return agents.filter((a) => a.ownerUserId === ownerActorId || a.id === chosenAgentId).map((agent) => ({
684
721
  agent,
@@ -686,62 +723,191 @@ function ownMachineRows(agents, grants, ownerActorId, chosenAgentId, now = Date.
686
723
  chosen: agent.id === chosenAgentId
687
724
  })).sort((a, b) => rank(a) - rank(b) || a.agent.name.localeCompare(b.agent.name));
688
725
  }
726
+ /** The expiry to send for a grant of `days`, never past the service's 30-day limit. */
727
+ function ownMachineGrantExpiry(days, now = Date.now()) {
728
+ return new Date(now + Math.min(days * DAY_MS, 25917e5)).toISOString();
729
+ }
730
+ /**
731
+ * The app names to send on a grant: one per line, trimmed, lower-cased
732
+ * (VibeControls compares lower-case names), de-duplicated and capped at 64.
733
+ */
734
+ function ownMachineAllowedApps(text) {
735
+ const seen = /* @__PURE__ */ new Set();
736
+ for (const line of text.split(/\r?\n/)) {
737
+ const name = line.trim().toLowerCase();
738
+ if (name) seen.add(name);
739
+ }
740
+ return [...seen].slice(0, 64);
741
+ }
742
+ /** How many distinct app names the text holds, before the 64-name cap. */
743
+ function ownMachineAppCount(text) {
744
+ return new Set(text.split(/\r?\n/).map((line) => line.trim().toLowerCase()).filter(Boolean)).size;
745
+ }
746
+ /** When the earliest live grant expires (epoch ms), or null. */
747
+ function nextOwnMachineGrantExpiry(grants, now = Date.now()) {
748
+ let next = null;
749
+ for (const g of grants) {
750
+ if (!isLive(g, now)) continue;
751
+ const at = new Date(g.expiresAt).getTime();
752
+ if (next === null || at < next) next = at;
753
+ }
754
+ return next;
755
+ }
756
+ /** What the viewer may do with the picker, from {@link OwnMachineAccess}. */
757
+ function ownMachineAbilities(ownerActorId, access = {}) {
758
+ const manage = (access.viewerActorId === void 0 || access.viewerActorId === ownerActorId) && access.canUpdateSteward !== false;
759
+ return {
760
+ manage,
761
+ read: access.canReadMachines !== false,
762
+ grant: manage && access.canGrantMachines !== false
763
+ };
764
+ }
765
+ const EMPTY_MACHINES = {
766
+ agents: void 0,
767
+ grants: void 0,
768
+ error: void 0,
769
+ loading: false,
770
+ truncated: false,
771
+ unchecked: /* @__PURE__ */ new Set()
772
+ };
773
+ /** Grant lookups sent at once. */
774
+ const GRANT_LOOKUP_CONCURRENCY = 8;
689
775
  /**
690
776
  * Every VibeControls machine the viewer can see in the workspace, page by
691
- * page. The agents query has no owner filter, so the owner's machines can sit
692
- * on any page; reading only the first would hide them in a large workspace.
777
+ * page, and the steward's live grants. The agents query has no owner filter,
778
+ * so the owner's machines can sit on any page. The grants list is capped by
779
+ * the service before it drops expired rows, so a shorter list can still miss
780
+ * a live grant: each of the owner's machines without a live grant in the list
781
+ * is looked up on its own (at most OWN_MACHINE_GRANT_LOOKUPS). Data is keyed
782
+ * by gateway, workspace, steward and owner, so another scope's machines and
783
+ * grants are never shown or acted on; a superseded load is aborted.
693
784
  */
694
- function useWorkspaceMachines(nonce) {
695
- const { client } = useStewardsSdk();
696
- const [state, setState] = useState({
697
- agents: void 0,
698
- error: void 0,
699
- loading: true,
700
- truncated: false
701
- });
702
- useEffect(() => {
703
- const controller = new AbortController();
704
- setState((prev) => ({
785
+ function useOwnMachineData(stewardId, ownerActorId, viewerActorId, enabled) {
786
+ const { client, config: { gatewayUrl, workspaceId } } = useStewardsSdk();
787
+ const scope = JSON.stringify([
788
+ gatewayUrl,
789
+ workspaceId,
790
+ stewardId,
791
+ ownerActorId,
792
+ viewerActorId ?? null
793
+ ]);
794
+ const [nonce, setNonce] = useState(0);
795
+ const [state, setState] = useState(void 0);
796
+ const reload = useCallback(() => {
797
+ if (!enabled) return;
798
+ setState((prev) => prev ? {
705
799
  ...prev,
706
800
  loading: true
707
- }));
801
+ } : prev);
802
+ setNonce((n) => n + 1);
803
+ }, [enabled]);
804
+ useEffect(() => {
805
+ if (!enabled) return void 0;
806
+ const controller = new AbortController();
807
+ const grantsOf = async (agentId) => (await client.request(LIST_OWN_MACHINE_GRANTS, {
808
+ stewardId,
809
+ ...agentId ? { agentId } : {}
810
+ }, controller.signal)).vibecontrolsStewardGrants;
708
811
  const load = async () => {
709
812
  const agents = [];
813
+ let truncated = true;
710
814
  for (let page = 0; page < 100; page += 1) {
711
815
  const data = await client.request(LIST_OWN_MACHINE_AGENTS, { pagination: {
712
816
  limit: 100,
713
817
  offset: page * 100
714
818
  } }, controller.signal);
715
819
  agents.push(...data.vibecontrolsAgents);
716
- if (data.vibecontrolsAgents.length < 100) return {
717
- agents,
718
- truncated: false
719
- };
820
+ if (data.vibecontrolsAgents.length < 100) {
821
+ truncated = false;
822
+ break;
823
+ }
824
+ }
825
+ const grants = [...await grantsOf()];
826
+ const now = Date.now();
827
+ const live = new Set(grants.filter((g) => isLive(g, now)).map((g) => g.agentId));
828
+ const missing = agents.filter((a) => a.ownerUserId === ownerActorId && !live.has(a.id)).map((a) => a.id);
829
+ const checked = missing.slice(0, 50);
830
+ const unchecked = new Set(missing.slice(50));
831
+ for (let i = 0; i < checked.length; i += GRANT_LOOKUP_CONCURRENCY) {
832
+ const ids = checked.slice(i, i + GRANT_LOOKUP_CONCURRENCY);
833
+ const batch = await Promise.allSettled(ids.map((id) => grantsOf(id)));
834
+ if (controller.signal.aborted) break;
835
+ batch.forEach((result, n) => {
836
+ if (result.status === "fulfilled") grants.push(...result.value);
837
+ else unchecked.add(ids[n]);
838
+ });
720
839
  }
721
840
  return {
722
841
  agents,
723
- truncated: true
842
+ grants,
843
+ truncated,
844
+ unchecked
724
845
  };
725
846
  };
726
- load().then(({ agents, truncated }) => {
847
+ load().then(({ agents, grants, truncated, unchecked }) => {
727
848
  if (controller.signal.aborted) return;
728
849
  setState({
850
+ scope,
729
851
  agents,
852
+ grants,
730
853
  error: void 0,
731
854
  loading: false,
732
- truncated
855
+ truncated,
856
+ unchecked
733
857
  });
734
858
  }, (err) => {
735
859
  if (controller.signal.aborted) return;
736
- setState((prev) => ({
737
- ...prev,
738
- error: err instanceof Error ? err : new Error(String(err)),
739
- loading: false
740
- }));
860
+ setState({
861
+ ...EMPTY_MACHINES,
862
+ scope,
863
+ error: err instanceof Error ? err : new Error(String(err))
864
+ });
741
865
  });
742
866
  return () => controller.abort();
743
- }, [client, nonce]);
744
- return state;
867
+ }, [
868
+ client,
869
+ scope,
870
+ stewardId,
871
+ ownerActorId,
872
+ enabled,
873
+ nonce
874
+ ]);
875
+ const checkAgent = useCallback(async (agentId) => {
876
+ const found = (await client.request(LIST_OWN_MACHINE_GRANTS, {
877
+ stewardId,
878
+ agentId
879
+ })).vibecontrolsStewardGrants;
880
+ setState((prev) => {
881
+ if (!prev || prev.scope !== scope) return prev;
882
+ const unchecked = new Set(prev.unchecked);
883
+ unchecked.delete(agentId);
884
+ return {
885
+ ...prev,
886
+ grants: [...prev.grants ?? [], ...found],
887
+ unchecked
888
+ };
889
+ });
890
+ }, [
891
+ client,
892
+ stewardId,
893
+ scope
894
+ ]);
895
+ if (!enabled) return {
896
+ ...EMPTY_MACHINES,
897
+ reload,
898
+ checkAgent
899
+ };
900
+ if (!state || state.scope !== scope) return {
901
+ ...EMPTY_MACHINES,
902
+ loading: true,
903
+ reload,
904
+ checkAgent
905
+ };
906
+ return {
907
+ ...state,
908
+ reload,
909
+ checkAgent
910
+ };
745
911
  }
746
912
  /**
747
913
  * The desk settings of a steward whose desk kind is OWN_MACHINE, inside the
@@ -759,27 +925,54 @@ function StewardOwnMachineDesk(props) {
759
925
  }
760
926
  /**
761
927
  * The owner's VibeControls machines, which ones have granted this steward,
762
- * and the one it works on. Choosing calls `setBotmanorStewardOwnMachineDesk`,
763
- * clearing calls `clearBotmanorStewardOwnMachineDesk`; the service's refusals
764
- * (no grant, machine in use, changed concurrently, check unavailable) are
765
- * shown with the service's own message. The list refreshes when the tab gets
766
- * focus again (the owner may have just granted a machine in VibeControls) and
767
- * on "Refresh". The gateway stays the enforcement point.
928
+ * and the one it works on. The owner can grant a machine to the steward
929
+ * (`grantVibecontrolsAgentToSteward`), revoke the grant, choose a granted
930
+ * machine (`setBotmanorStewardOwnMachineDesk`) or clear the choice
931
+ * (`clearBotmanorStewardOwnMachineDesk`). Controls follow `access`; the
932
+ * service's refusals (no grant, machine in use, changed concurrently, check
933
+ * unavailable) are shown with the service's own message. Refresh and the tab
934
+ * regaining focus reload the desk, the machines and the grants, and a row
935
+ * re-renders when its grant expires. The gateway stays the enforcement point.
768
936
  */
769
- function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl = DEFAULT_VIBECONTROLS_URL, onChanged }) {
937
+ function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl = DEFAULT_VIBECONTROLS_URL, access, onChanged }) {
938
+ const abilities = ownMachineAbilities(ownerActorId, access);
939
+ const { client, config } = useStewardsSdk();
770
940
  const desk = useStewardsQuery(GET_STEWARD_OWN_MACHINE_DESK, { stewardId });
771
- const grants = useStewardsQuery(LIST_OWN_MACHINE_GRANTS, { stewardId });
772
- const [machinesNonce, setMachinesNonce] = useState(0);
773
- const machines = useWorkspaceMachines(machinesNonce);
941
+ const machines = useOwnMachineData(stewardId, ownerActorId, access?.viewerActorId, abilities.read);
774
942
  const choose = useStewardsMutation(SET_STEWARD_OWN_MACHINE_DESK);
775
943
  const clear = useStewardsMutation(CLEAR_STEWARD_OWN_MACHINE_DESK);
944
+ const grant = useStewardsMutation(GRANT_OWN_MACHINE);
945
+ const revoke = useStewardsMutation(REVOKE_OWN_MACHINE_GRANT);
946
+ const [grantDays, setGrantDays] = useState(7);
947
+ const [appsText, setAppsText] = useState("");
776
948
  const [lastAction, setLastAction] = useState(null);
777
- const actionError = lastAction === "choose" ? choose.error : lastAction === "clear" ? clear.error : void 0;
778
- const refetchGrants = grants.refetch;
949
+ const [grantNotice, setGrantNotice] = useState(void 0);
950
+ const [granting, setGranting] = useState(false);
951
+ const scopeRef = useRef("");
952
+ useEffect(() => {
953
+ scopeRef.current = JSON.stringify([
954
+ config.gatewayUrl,
955
+ config.workspaceId,
956
+ stewardId,
957
+ ownerActorId,
958
+ access?.viewerActorId ?? null,
959
+ abilities.grant
960
+ ]);
961
+ });
962
+ useEffect(() => () => {
963
+ scopeRef.current = "";
964
+ }, []);
965
+ const actionError = lastAction ? lastAction === "check" ? grantNotice : lastAction === "grant" ? grantNotice ?? grant.error : {
966
+ choose,
967
+ clear,
968
+ revoke
969
+ }[lastAction].error : void 0;
970
+ const refetchDesk = desk.refetch;
971
+ const reloadMachines = machines.reload;
779
972
  const refresh = useCallback(() => {
780
- refetchGrants();
781
- setMachinesNonce((n) => n + 1);
782
- }, [refetchGrants]);
973
+ refetchDesk();
974
+ reloadMachines();
975
+ }, [refetchDesk, reloadMachines]);
783
976
  useEffect(() => {
784
977
  if (typeof window === "undefined") return void 0;
785
978
  const onFocus = () => refresh();
@@ -787,24 +980,86 @@ function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl =
787
980
  return () => window.removeEventListener("focus", onFocus);
788
981
  }, [refresh]);
789
982
  const current = desk.data?.botmanorStewardOwnMachineDesk ?? null;
790
- const rows = ownMachineRows(machines.agents ?? [], grants.data?.vibecontrolsStewardGrants ?? [], ownerActorId, current?.agentId ?? null);
791
- const busy = choose.loading || clear.loading;
792
- const listed = machines.agents !== void 0 && grants.data !== void 0;
983
+ const grants = machines.grants ?? [];
984
+ const rows = ownMachineRows(machines.agents ?? [], grants, ownerActorId, current?.agentId ?? null);
985
+ const [expiryTick, setExpiryTick] = useState(0);
986
+ const nextExpiry = nextOwnMachineGrantExpiry(grants);
987
+ useEffect(() => {
988
+ if (nextExpiry === null) return void 0;
989
+ const delay = Math.min(Math.max(nextExpiry - Date.now(), 0) + 1e3, 2 ** 31 - 1);
990
+ const id = setTimeout(() => setExpiryTick((n) => n + 1), delay);
991
+ return () => clearTimeout(id);
992
+ }, [nextExpiry, expiryTick]);
993
+ const deskBusy = choose.loading || clear.loading;
994
+ const busy = deskBusy || granting || grant.loading || revoke.loading || machines.loading;
995
+ const listed = machines.agents !== void 0 && machines.grants !== void 0;
793
996
  const onChoose = async (agentId) => {
794
997
  setLastAction("choose");
795
998
  const result = await choose.mutate({ input: {
796
999
  stewardId,
797
1000
  agentId
798
1001
  } });
799
- if (!result) return;
800
- desk.refetch();
801
- onChanged?.(result.setBotmanorStewardOwnMachineDesk);
1002
+ refresh();
1003
+ if (result) onChanged?.(result.setBotmanorStewardOwnMachineDesk);
802
1004
  };
803
1005
  const onClear = async () => {
804
1006
  setLastAction("clear");
805
- if (!await clear.mutate({ stewardId })) return;
806
- desk.refetch();
807
- onChanged?.(null);
1007
+ const result = await clear.mutate({ stewardId });
1008
+ refresh();
1009
+ if (result) onChanged?.(null);
1010
+ };
1011
+ const onGrant = async (agentId) => {
1012
+ if (granting) return;
1013
+ setGranting(true);
1014
+ setLastAction("grant");
1015
+ setGrantNotice(void 0);
1016
+ const startedIn = scopeRef.current;
1017
+ if (ownMachineAppCount(appsText) > 64) {
1018
+ setGrantNotice(/* @__PURE__ */ new Error(`A grant allows at most ${64} apps. Shorten the list and grant again.`));
1019
+ setGranting(false);
1020
+ return;
1021
+ }
1022
+ try {
1023
+ const existing = (await client.request(LIST_OWN_MACHINE_GRANTS, {
1024
+ stewardId,
1025
+ agentId
1026
+ })).vibecontrolsStewardGrants;
1027
+ if (!startedIn || scopeRef.current !== startedIn) return;
1028
+ if (existing.some((g) => g.status === "ACTIVE")) {
1029
+ setGrantNotice(/* @__PURE__ */ new Error("This machine already has a live grant for this steward. Revoke it first to change its apps or length."));
1030
+ return;
1031
+ }
1032
+ await grant.mutate({ input: {
1033
+ stewardId,
1034
+ agentId,
1035
+ allowedApps: ownMachineAllowedApps(appsText),
1036
+ expiresAt: ownMachineGrantExpiry(grantDays)
1037
+ } });
1038
+ } catch (err) {
1039
+ setGrantNotice(err instanceof Error ? err : new Error(String(err)));
1040
+ } finally {
1041
+ setGranting(false);
1042
+ refresh();
1043
+ }
1044
+ };
1045
+ const checkAgent = machines.checkAgent;
1046
+ const onCheck = async (agentId) => {
1047
+ setLastAction("check");
1048
+ setGrantNotice(void 0);
1049
+ try {
1050
+ await checkAgent(agentId);
1051
+ } catch (err) {
1052
+ setGrantNotice(err instanceof Error ? err : new Error(String(err)));
1053
+ }
1054
+ };
1055
+ const onRevoke = async (agentId) => {
1056
+ const now = Date.now();
1057
+ const live = grants.find((g) => g.agentId === agentId && isLive(g, now));
1058
+ if (live) {
1059
+ setLastAction("revoke");
1060
+ await revoke.mutate({ id: live.id });
1061
+ }
1062
+ refresh();
808
1063
  };
809
1064
  return /* @__PURE__ */ jsxs("section", {
810
1065
  "aria-label": "Own machine",
@@ -818,8 +1073,7 @@ function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl =
818
1073
  children: "Own machine"
819
1074
  }),
820
1075
  /* @__PURE__ */ jsxs(Muted, { children: [
821
- "The steward works on one of your VibeControls machines. A machine can be chosen once you have granted it to this steward in",
822
- " ",
1076
+ abilities.manage ? "The steward works on one of your VibeControls machines. Grant a machine to this steward, then choose it. Your machines are also managed in " : "The steward works on one of its owner's VibeControls machines. Only the steward's owner can grant or choose a machine. Machines are managed in ",
823
1077
  /* @__PURE__ */ jsx("a", {
824
1078
  href: vibecontrolsUrl,
825
1079
  target: "_blank",
@@ -834,33 +1088,103 @@ function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl =
834
1088
  error: desk.error,
835
1089
  current,
836
1090
  name: rows.find((r) => r.chosen)?.agent.name,
837
- busy,
1091
+ canClear: abilities.manage,
1092
+ busy: deskBusy,
838
1093
  onClear: () => void onClear()
839
1094
  }),
840
1095
  /* @__PURE__ */ jsx("p", {
841
1096
  style: { margin: "8px 0 0" },
842
1097
  children: /* @__PURE__ */ jsx(Button, {
843
1098
  onClick: refresh,
844
- disabled: machines.loading || grants.loading,
1099
+ disabled: machines.loading || desk.loading,
845
1100
  label: "Refresh your machines",
846
1101
  children: "Refresh"
847
1102
  })
848
1103
  }),
849
- /* @__PURE__ */ jsx(MachineList, {
850
- loading: !listed && (machines.loading || grants.loading),
1104
+ abilities.grant ? /* @__PURE__ */ jsx(GrantOptions, {
1105
+ stewardId,
1106
+ days: grantDays,
1107
+ onDays: setGrantDays,
1108
+ appsText,
1109
+ onAppsText: setAppsText
1110
+ }) : null,
1111
+ abilities.read ? /* @__PURE__ */ jsx(MachineList, {
1112
+ loading: !listed && machines.loading,
851
1113
  listed,
852
1114
  truncated: machines.truncated,
853
- error: machines.error ?? grants.error,
1115
+ error: machines.error,
854
1116
  rows,
1117
+ unchecked: machines.unchecked,
1118
+ ownerActorId,
855
1119
  busy,
856
- onChoose: (agentId) => void onChoose(agentId)
857
- }),
1120
+ canChoose: abilities.manage,
1121
+ canGrant: abilities.grant,
1122
+ onCheck: (agentId) => void onCheck(agentId),
1123
+ onChoose: (agentId) => void onChoose(agentId),
1124
+ onGrant: (agentId) => void onGrant(agentId),
1125
+ onRevoke: (agentId) => void onRevoke(agentId)
1126
+ }) : /* @__PURE__ */ jsx(Muted, { children: "Your role cannot see VibeControls machines in this workspace." }),
858
1127
  /* @__PURE__ */ jsx(ErrorNote, { error: actionError })
859
1128
  ]
860
1129
  });
861
1130
  }
862
- /** The machine the steward works on now, with Clear. */
863
- function CurrentMachine({ loading, loaded, error, current, name, busy, onClear }) {
1131
+ /** How long a new grant lasts, and the apps it allows. */
1132
+ function GrantOptions({ stewardId, days, onDays, appsText, onAppsText }) {
1133
+ const instance = useId();
1134
+ const daysId = `own-machine-days-${stewardId}-${instance}`;
1135
+ const appsId = `own-machine-apps-${stewardId}-${instance}`;
1136
+ return /* @__PURE__ */ jsxs("div", {
1137
+ style: {
1138
+ display: "grid",
1139
+ gap: "4px",
1140
+ marginTop: "8px"
1141
+ },
1142
+ children: [
1143
+ /* @__PURE__ */ jsx("label", {
1144
+ htmlFor: daysId,
1145
+ style: {
1146
+ fontSize: "13px",
1147
+ fontWeight: 500
1148
+ },
1149
+ children: "A new grant lasts"
1150
+ }),
1151
+ /* @__PURE__ */ jsx("select", {
1152
+ id: daysId,
1153
+ value: days,
1154
+ onChange: (e) => {
1155
+ const next = OWN_MACHINE_GRANT_DAYS.find((d) => d === Number(e.target.value));
1156
+ if (next) onDays(next);
1157
+ },
1158
+ style: {
1159
+ ...fieldStyle,
1160
+ width: "auto"
1161
+ },
1162
+ children: OWN_MACHINE_GRANT_DAYS.map((d) => /* @__PURE__ */ jsx("option", {
1163
+ value: d,
1164
+ children: d === 1 ? "1 day" : `${d} days`
1165
+ }, d))
1166
+ }),
1167
+ /* @__PURE__ */ jsx("label", {
1168
+ htmlFor: appsId,
1169
+ style: {
1170
+ fontSize: "13px",
1171
+ fontWeight: 500
1172
+ },
1173
+ children: "Apps the steward may use on a granted machine"
1174
+ }),
1175
+ /* @__PURE__ */ jsx("textarea", {
1176
+ id: appsId,
1177
+ value: appsText,
1178
+ onChange: (e) => onAppsText(e.target.value),
1179
+ rows: 3,
1180
+ style: fieldStyle
1181
+ }),
1182
+ /* @__PURE__ */ jsx(Muted, { children: "One app name or platform id per line (for example a macOS bundle id). Desktop actions in other apps are refused; browser and workspace-folder actions are not limited by this list." })
1183
+ ]
1184
+ });
1185
+ }
1186
+ /** The machine the steward works on now, with Clear for the owner. */
1187
+ function CurrentMachine({ loading, loaded, error, current, name, canClear, busy, onClear }) {
864
1188
  return /* @__PURE__ */ jsxs(Fragment, { children: [
865
1189
  loading ? /* @__PURE__ */ jsx(Muted, { children: "Loading the desk…" }) : null,
866
1190
  /* @__PURE__ */ jsx(ErrorNote, { error }),
@@ -871,19 +1195,19 @@ function CurrentMachine({ loading, loaded, error, current, name, busy, onClear }
871
1195
  " ",
872
1196
  name ?? current.agentId,
873
1197
  " ",
874
- /* @__PURE__ */ jsx(Button, {
1198
+ canClear ? /* @__PURE__ */ jsx(Button, {
875
1199
  kind: "danger",
876
1200
  onClick: onClear,
877
1201
  disabled: busy,
878
1202
  label: "Clear the machine",
879
1203
  children: "Clear"
880
- })
1204
+ }) : null
881
1205
  ]
882
1206
  }) : loaded ? /* @__PURE__ */ jsx(Muted, { children: "No machine chosen yet." }) : null
883
1207
  ] });
884
1208
  }
885
- /** The owner's machines, each with its grant and a way to choose it. */
886
- function MachineList({ loading, listed, truncated, error, rows, busy, onChoose }) {
1209
+ /** The owner's machines, each with its grant and what the viewer may do. */
1210
+ function MachineList({ loading, listed, truncated, error, rows, ...actions }) {
887
1211
  return /* @__PURE__ */ jsxs(Fragment, { children: [
888
1212
  loading ? /* @__PURE__ */ jsx(Muted, { children: "Loading your machines…" }) : null,
889
1213
  /* @__PURE__ */ jsx(ErrorNote, { error }),
@@ -894,13 +1218,13 @@ function MachineList({ loading, listed, truncated, error, rows, busy, onChoose }
894
1218
  "aria-label": "Your machines",
895
1219
  children: rows.map((row) => /* @__PURE__ */ jsx(MachineRow, {
896
1220
  row,
897
- busy,
898
- onChoose
1221
+ ...actions
899
1222
  }, row.agent.id))
900
1223
  }) : null
901
1224
  ] });
902
1225
  }
903
- function MachineRow({ row: { agent, granted, chosen }, busy, onChoose }) {
1226
+ function MachineRow({ row: { agent, granted, chosen }, unchecked, ownerActorId, onCheck, busy, canChoose, canGrant, onChoose, onGrant, onRevoke }) {
1227
+ const unknown = !granted && unchecked.has(agent.id);
904
1228
  return /* @__PURE__ */ jsxs("li", {
905
1229
  style: rowStyle,
906
1230
  children: [
@@ -908,17 +1232,40 @@ function MachineRow({ row: { agent, granted, chosen }, busy, onChoose }) {
908
1232
  " ",
909
1233
  /* @__PURE__ */ jsx(Muted, { children: agent.hostname }),
910
1234
  " ",
911
- /* @__PURE__ */ jsx(Badge, { children: agent.isActive ? "Online" : "Offline" }),
1235
+ /* @__PURE__ */ jsx(Badge, { children: agent.isActive ? "Active" : "Inactive" }),
1236
+ " ",
1237
+ /* @__PURE__ */ jsx(Badge, { children: granted ? "Granted" : unknown ? "Grant not checked" : "Not granted" }),
1238
+ " ",
1239
+ chosen ? /* @__PURE__ */ jsx(Badge, { children: "Chosen" }) : null,
912
1240
  " ",
913
- /* @__PURE__ */ jsx(Badge, { children: granted ? "Granted" : "Not granted" }),
1241
+ (canGrant || canChoose) && unknown ? /* @__PURE__ */ jsx(Button, {
1242
+ onClick: () => onCheck(agent.id),
1243
+ disabled: busy,
1244
+ label: `Check the grant on ${agent.name}`,
1245
+ children: "Check grant"
1246
+ }) : null,
914
1247
  " ",
915
- chosen ? /* @__PURE__ */ jsx(Badge, { children: "Chosen" }) : /* @__PURE__ */ jsx(Button, {
1248
+ canGrant && !granted && !unknown && agent.ownerUserId === ownerActorId ? /* @__PURE__ */ jsx(Button, {
1249
+ onClick: () => onGrant(agent.id),
1250
+ disabled: busy,
1251
+ label: `Grant ${agent.name} to this steward`,
1252
+ children: "Grant to this steward"
1253
+ }) : null,
1254
+ " ",
1255
+ canChoose && granted && !chosen ? /* @__PURE__ */ jsx(Button, {
916
1256
  kind: "primary",
917
1257
  onClick: () => onChoose(agent.id),
918
- disabled: busy || !granted,
1258
+ disabled: busy,
919
1259
  label: `Use ${agent.name}`,
920
1260
  children: "Use this machine"
921
- }),
1261
+ }) : null,
1262
+ " ",
1263
+ canGrant && granted ? /* @__PURE__ */ jsx(Button, {
1264
+ onClick: () => onRevoke(agent.id),
1265
+ disabled: busy,
1266
+ label: `Revoke the grant on ${agent.name}`,
1267
+ children: "Revoke grant"
1268
+ }) : null,
922
1269
  /* @__PURE__ */ jsxs(Muted, { children: ["Last seen ", formatDate(agent.lastHeartbeat)] })
923
1270
  ]
924
1271
  });
@@ -1091,7 +1438,7 @@ function RunApprovals({ approvals }) {
1091
1438
 
1092
1439
  // src/components/StewardConsole.tsx
1093
1440
  /** List stewards, or open one: its charter summary, start a run, recent runs. */
1094
- function StewardConsole({ stewardId, onSelectSteward, vibecontrolsUrl }) {
1441
+ function StewardConsole({ stewardId, onSelectSteward, vibecontrolsUrl, ownMachineAccess }) {
1095
1442
  const { config } = useStewardsSdk();
1096
1443
  const [opened, setOpened] = useState(void 0);
1097
1444
  const current = stewardId ?? opened;
@@ -1105,7 +1452,8 @@ function StewardConsole({ stewardId, onSelectSteward, vibecontrolsUrl }) {
1105
1452
  }), current ? /* @__PURE__ */ jsx(StewardPanel, {
1106
1453
  stewardId: current,
1107
1454
  onBack: stewardId ? void 0 : () => setOpened(void 0),
1108
- vibecontrolsUrl
1455
+ vibecontrolsUrl,
1456
+ ownMachineAccess
1109
1457
  }) : /* @__PURE__ */ jsx(StewardList, { onSelect: (id) => {
1110
1458
  setOpened(id);
1111
1459
  onSelectSteward?.(id);
@@ -1142,7 +1490,7 @@ function StewardList({ onSelect }) {
1142
1490
  }) : null
1143
1491
  ] });
1144
1492
  }
1145
- function StewardPanel({ stewardId, onBack, vibecontrolsUrl }) {
1493
+ function StewardPanel({ stewardId, onBack, vibecontrolsUrl, ownMachineAccess }) {
1146
1494
  const steward = useStewardsQuery(GET_STEWARD, { id: stewardId });
1147
1495
  const runs = useStewardsQuery(LIST_STEWARD_RUNS, {
1148
1496
  filter: { stewardId },
@@ -1170,7 +1518,8 @@ function StewardPanel({ stewardId, onBack, vibecontrolsUrl }) {
1170
1518
  /* @__PURE__ */ jsx(StewardSummary, { detail }),
1171
1519
  /* @__PURE__ */ jsx(OwnMachineSection, {
1172
1520
  detail,
1173
- vibecontrolsUrl
1521
+ vibecontrolsUrl,
1522
+ access: ownMachineAccess
1174
1523
  }),
1175
1524
  detail.status === "ACTIVE" ? /* @__PURE__ */ jsx(StartRunForm, {
1176
1525
  stewardId,
@@ -1189,11 +1538,16 @@ function StewardPanel({ stewardId, onBack, vibecontrolsUrl }) {
1189
1538
  ] });
1190
1539
  }
1191
1540
  /** The machine picker, for a steward whose desk kind is OWN_MACHINE. */
1192
- function OwnMachineSection({ detail, vibecontrolsUrl }) {
1541
+ function OwnMachineSection({ detail, vibecontrolsUrl, access }) {
1193
1542
  if (detail.defaultDeskKind !== "OWN_MACHINE") return null;
1543
+ const effective = detail.status === "ARCHIVED" ? {
1544
+ ...access,
1545
+ canUpdateSteward: false
1546
+ } : access ?? {};
1194
1547
  return /* @__PURE__ */ jsx(StewardOwnMachineDeskPanel, {
1195
1548
  stewardId: detail.id,
1196
1549
  ownerActorId: detail.ownerActorId,
1550
+ access: effective,
1197
1551
  ...vibecontrolsUrl ? { vibecontrolsUrl } : {}
1198
1552
  });
1199
1553
  }
@@ -1688,4 +2042,4 @@ function ApprovalInbox({ stewardId, pollIntervalMs = 15e3 }) {
1688
2042
  });
1689
2043
  }
1690
2044
 
1691
- export { ApprovalInbox, DEFAULT_STEWARDS_THEME, DEFAULT_VIBECONTROLS_URL, OWN_MACHINE_MAX_PAGES, OWN_MACHINE_PAGE_SIZE, StewardBuilder, StewardConsole, StewardOwnMachineDesk, StewardOwnMachineDeskPanel, StewardRunView, StewardsRequestError, StewardsSdkProvider, createStewardsEventBus, ownMachineRows, themeToStyle, useStewardsEvent, useStewardsSdk };
2045
+ export { ApprovalInbox, DEFAULT_STEWARDS_THEME, DEFAULT_VIBECONTROLS_URL, OWN_MACHINE_GRANT_DAYS, OWN_MACHINE_MAX_PAGES, OWN_MACHINE_PAGE_SIZE, StewardBuilder, StewardConsole, StewardOwnMachineDesk, StewardOwnMachineDeskPanel, StewardRunView, StewardsRequestError, StewardsSdkProvider, createStewardsEventBus, nextOwnMachineGrantExpiry, ownMachineAbilities, ownMachineAllowedApps, ownMachineAppCount, ownMachineGrantExpiry, ownMachineRows, themeToStyle, useStewardsEvent, useStewardsSdk };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botmanor/fe-sdk",
3
- "version": "2026.1204.4",
3
+ "version": "2026.1205.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Algoshred/botmanor-fe-sdk.git"