@botmanor/fe-sdk 2026.1205.3 → 2026.1205.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,20 +1,41 @@
1
1
  "use client";
2
2
  import { createContext, use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { C as GUIDED_ENTRIES, D as permissionLabelKey, E as PERMISSION_LABELS, S as AGENT_STATUS_SHORT_LABELS, T as GUIDED_PERMISSIONS, _ as isDefiniteRefusal, a as fillGuidedParams, b as extractGuidedSource, c as guidedTranslateFrom, d as botmanorPath, f as crossShellUrl, g as guidedI18nBase, h as describeGuidedError, i as englishGuidedTranslate, l as planGuidedActions, m as buildGuidedError, n as stepReasonCode, o as guidedParams, p as resolveGuidedLocation, r as stopReasonLabel, s as guidedText, t as describeRunFailure, u as DEFAULT_BOTMANOR_APP_URL, v as isStaleStateError, w as STOP_REASON_LABELS, x as AGENT_STATUS_LABELS, y as reasonCamel } from "./guided-errors-D5vT9owt.js";
4
5
 
5
6
  // src/graphql/client.ts
6
7
  /** Failure from the gateway: a transport status or a GraphQL error code. */
7
8
  var StewardsRequestError = class extends Error {
8
9
  code;
9
10
  status;
10
- /** The plan quota a `QUOTA_EXHAUSTED` refusal names, e.g. `botmanor.stewards.runs`. */
11
+ /**
12
+ * The plan quota a `QUOTA_EXHAUSTED` refusal names, e.g.
13
+ * `botmanor.stewards.runs` (`extensions.quotaKey`, or the older `quotaName`).
14
+ */
11
15
  quotaName;
12
- constructor(message, code, status, quotaName) {
16
+ /**
17
+ * The GraphQL error's whole `extensions` object: `reason`, `i18nKey` and the
18
+ * context fields the guided-error catalog reads (BOFF-18785). Empty for a
19
+ * transport failure.
20
+ */
21
+ extensions;
22
+ constructor(message, code, status, quotaName, extensions = {}) {
13
23
  super(message);
14
24
  this.name = "StewardsRequestError";
15
25
  this.code = code;
16
26
  this.status = status;
17
27
  if (quotaName) this.quotaName = quotaName;
28
+ this.extensions = extensions;
29
+ }
30
+ /** `extensions.reason`, the catalog's guided code, when the service sent one. */
31
+ get reason() {
32
+ const reason = this.extensions.reason;
33
+ return typeof reason === "string" ? reason : void 0;
34
+ }
35
+ /** `extensions.i18nKey`, the service's translation key, when it sent one. */
36
+ get i18nKey() {
37
+ const key = this.extensions.i18nKey;
38
+ return typeof key === "string" ? key : void 0;
18
39
  }
19
40
  };
20
41
  const LOOPBACK_HOSTS = /* @__PURE__ */ new Set([
@@ -112,17 +133,23 @@ function createStewardsClient(options) {
112
133
  if (first) {
113
134
  const code = typeof first.extensions?.code === "string" ? first.extensions.code : "GRAPHQL_ERROR";
114
135
  if (code === "UNAUTHENTICATED") options.reportAuthExpired("gateway rejected the token");
115
- const quotaName = typeof first.extensions?.quotaName === "string" ? first.extensions.quotaName : void 0;
116
- throw new StewardsRequestError(first.message ?? "Request failed", code, response.status, quotaName);
136
+ else if (code === "FORBIDDEN" && typeof first.extensions?.authFailure === "string") options.reportAuthExpired(`gateway refused the session: ${first.extensions.authFailure}`);
137
+ const headerWait = Number(response.headers.get("retry-after"));
138
+ const extensions = first.extensions?.retryAfter === void 0 && Number.isFinite(headerWait) && headerWait > 0 ? {
139
+ ...first.extensions ?? {},
140
+ retryAfter: headerWait
141
+ } : first.extensions ?? {};
142
+ const quotaName = typeof extensions.quotaKey === "string" ? extensions.quotaKey : typeof extensions.quotaName === "string" ? extensions.quotaName : void 0;
143
+ throw new StewardsRequestError(first.message ?? "Request failed", code, response.status, quotaName, extensions);
117
144
  }
118
145
  if (!response.ok || body.data == null) throw new StewardsRequestError(`Unexpected response from the Stewards service (${response.status})`, "BAD_RESPONSE", response.status);
119
146
  return body.data;
120
147
  };
121
- return { async request(document, variables = {}, signal) {
148
+ return { async request(document, variables = {}, signal, requestOptions = {}) {
122
149
  try {
123
150
  return await send(document, variables, signal);
124
151
  } catch (err) {
125
- if (err instanceof StewardsRequestError && !signal?.aborted) options.reportFailure?.(err);
152
+ if (err instanceof StewardsRequestError && !signal?.aborted && !requestOptions.silent) options.reportFailure?.(err);
126
153
  throw err;
127
154
  }
128
155
  } };
@@ -212,13 +239,16 @@ function StewardsSdkProvider({ children, ...config }) {
212
239
  code: error.code,
213
240
  message: error.message,
214
241
  ...error.status !== void 0 ? { status: error.status } : {},
215
- ...error.quotaName ? { quotaName: error.quotaName } : {}
242
+ ...error.quotaName ? { quotaName: error.quotaName } : {},
243
+ ...error.reason ? { reason: error.reason } : {},
244
+ ...error.i18nKey ? { i18nKey: error.i18nKey } : {},
245
+ ...Object.keys(error.extensions).length > 0 ? { extensions: error.extensions } : {}
216
246
  });
217
247
  }
218
248
  })
219
249
  };
220
250
  });
221
- const { gatewayUrl, workspaceId, getAccessToken, getWorkspaceToken, sameOriginCredentials, onTokenExpired, theme } = config;
251
+ const { gatewayUrl, workspaceId, getAccessToken, getWorkspaceToken, sameOriginCredentials, onTokenExpired, theme, resolveTarget, navigate, hasPermission, viewerActorId, resolveActorName, translate, onUpgrade } = config;
222
252
  const value = useMemo(() => ({
223
253
  config: {
224
254
  gatewayUrl,
@@ -228,7 +258,14 @@ function StewardsSdkProvider({ children, ...config }) {
228
258
  ...sameOriginCredentials ? { sameOriginCredentials } : {},
229
259
  ...onTokenExpired ? { onTokenExpired } : {},
230
260
  ...onEvent ? { onEvent } : {},
231
- ...theme ? { theme } : {}
261
+ ...theme ? { theme } : {},
262
+ ...resolveTarget ? { resolveTarget } : {},
263
+ ...navigate ? { navigate } : {},
264
+ ...hasPermission ? { hasPermission } : {},
265
+ ...viewerActorId !== void 0 ? { viewerActorId } : {},
266
+ ...resolveActorName ? { resolveActorName } : {},
267
+ ...translate ? { translate } : {},
268
+ ...onUpgrade ? { onUpgrade } : {}
232
269
  },
233
270
  events,
234
271
  ...services
@@ -241,6 +278,13 @@ function StewardsSdkProvider({ children, ...config }) {
241
278
  onTokenExpired,
242
279
  onEvent,
243
280
  theme,
281
+ resolveTarget,
282
+ navigate,
283
+ hasPermission,
284
+ viewerActorId,
285
+ resolveActorName,
286
+ translate,
287
+ onUpgrade,
244
288
  events,
245
289
  services
246
290
  ]);
@@ -322,7 +366,7 @@ const RUN_SUMMARY = `
322
366
  const STEWARD_DETAIL = `
323
367
  id agentId ownerActorId status defaultDeskKind pendingApprovalCount
324
368
  createdAt updatedAt
325
- agent { id name capabilities }
369
+ agent { id name capabilities status llmModelId }
326
370
  charter {
327
371
  autonomyLevel charterText charterVersion allowedToolKeys
328
372
  allowedConnectionIds timezone dryRunDefault
@@ -335,7 +379,7 @@ const STEWARD_DETAIL = `
335
379
  const LIST_STEWARDS = `query ListBotmanorStewards($filter: BotmanorStewardFilterInput, $pagination: PaginationInput) {
336
380
  listBotmanorStewards(filter: $filter, pagination: $pagination) {
337
381
  id agentId status defaultDeskKind pendingApprovalCount
338
- agent { id name }
382
+ agent { id name status }
339
383
  charter { autonomyLevel budgetPerDay { credits } }
340
384
  usageToday { credits }
341
385
  lastRun { id status startedAt }
@@ -372,11 +416,16 @@ const CREATE_STEWARD = `mutation CreateBotmanorSteward($input: CreateBotmanorSte
372
416
  const UPDATE_STEWARD_CHARTER = `mutation UpdateBotmanorStewardCharter($id: ID!, $input: UpdateBotmanorStewardCharterInput!) {
373
417
  updateBotmanorStewardCharter(id: $id, input: $input) { ${STEWARD_DETAIL} }
374
418
  }`;
375
- const SET_STEWARD_STATUS = `mutation SetBotmanorStewardStatus($id: ID!, $status: BotmanorStewardStatus!) {
376
- setBotmanorStewardStatus(id: $id, status: $status) { id status }
377
- }`;
378
- const LIST_AGENT_CANDIDATES = `query ListStewardAgentCandidates($filters: BotmanorAgentFilterInput) {
379
- listBotmanorAgents(filters: $filters) { id name description status capabilities }
419
+ const CANDIDATE = `id name description status capabilities llmModelId`;
420
+ /**
421
+ * The agents that can become a steward, one filtered list per status, so a
422
+ * workspace with many archived or training agents never pushes an active one
423
+ * off the first page (BOFF-18785).
424
+ */
425
+ const LIST_PICKABLE_AGENTS = `query ListStewardPickableAgents($pagination: PaginationInput) {
426
+ active: listBotmanorAgents(filters: { status: ACTIVE }, pagination: $pagination) { ${CANDIDATE} }
427
+ draft: listBotmanorAgents(filters: { status: DRAFT }, pagination: $pagination) { ${CANDIDATE} }
428
+ paused: listBotmanorAgents(filters: { status: PAUSED }, pagination: $pagination) { ${CANDIDATE} }
380
429
  }`;
381
430
  const LIST_STEWARD_APPROVALS = `query ListBotmanorToolApprovals($filter: BotmanorToolApprovalFilterInput, $pagination: PaginationInput) {
382
431
  listBotmanorToolApprovals(filter: $filter, pagination: $pagination) {
@@ -425,6 +474,48 @@ const GRANT_OWN_MACHINE = `mutation GrantStewardOwnMachine($input: GrantVibecont
425
474
  const REVOKE_OWN_MACHINE_GRANT = `mutation RevokeStewardOwnMachineGrant($id: ID!) {
426
475
  revokeVibecontrolsStewardGrant(id: $id) { ${OWN_MACHINE_GRANT} }
427
476
  }`;
477
+ /**
478
+ * Guided-error fixes (BOFF-18785). The agent's status and model pick the
479
+ * right guidance when an older service does not send them with the error;
480
+ * publishing, requesting activation and activating are the inline fixes.
481
+ */
482
+ const GET_AGENT_STATUS = `query GetStewardAgentStatus($id: ID!) {
483
+ getBotmanorAgent(id: $id) { id name status llmModelId }
484
+ }`;
485
+ /** Publish (or resume) an agent: `updateBotmanorAgent` with status ACTIVE. */
486
+ const PUBLISH_AGENT = `mutation PublishStewardAgent($id: ID!) {
487
+ updateBotmanorAgent(id: $id, input: { status: ACTIVE }) { id status llmModelId }
488
+ }`;
489
+ const REQUEST_AGENT_ACTIVATION = `mutation RequestStewardAgentActivation($agentId: ID!) {
490
+ requestBotmanorAgentActivation(agentId: $agentId) { id status }
491
+ }`;
492
+ /** One activation request's status: PENDING until a reviewer decides or it is withdrawn. */
493
+ const GET_AGENT_ACTIVATION_REQUEST = `query GetStewardAgentActivationRequest($id: ID!) {
494
+ getBotmanorAgentApprovalRequest(id: $id) { id status isStale }
495
+ }`;
496
+ const SET_STEWARD_STATUS = `mutation SetBotmanorStewardStatus($id: ID!, $status: BotmanorStewardStatus!) {
497
+ setBotmanorStewardStatus(id: $id, status: $status) { id status }
498
+ }`;
499
+ /** The plan's cloud desk minutes: no assignment means the plan has none. */
500
+ const CHECK_DESK_MINUTES = `query StewardDeskMinutes($workspaceId: ID!) {
501
+ checkWorkspaceQuota(quotaName: "botmanor.stewards.desk-minutes", workspaceId: $workspaceId) {
502
+ allowed assignmentId limitLeft noLimit
503
+ }
504
+ }`;
505
+ /**
506
+ * A run's structured failure (guided-error catalog section 1.2). A separate,
507
+ * silent query: a service that does not expose `failure` yet refuses the field,
508
+ * and the run view then reads the stop reason and the steps instead.
509
+ */
510
+ const GET_STEWARD_RUN_FAILURE = `query GetBotmanorStewardRunFailure($id: ID!) {
511
+ getBotmanorStewardRun(id: $id) {
512
+ id
513
+ failure {
514
+ code message agentId toolKey connectionId machineId budgetLevel budgetKey
515
+ budgetCap stepCode
516
+ }
517
+ }
518
+ }`;
428
519
 
429
520
  // src/graphql/hooks.ts
430
521
  function asError(err) {
@@ -467,12 +558,13 @@ function useStewardsQuery(document, variables, options = {}) {
467
558
  variablesKey
468
559
  ]);
469
560
  const skip = options.skip === true;
561
+ const silent = options.silent === true;
470
562
  useEffect(() => {
471
563
  if (skip) return void 0;
472
564
  let active = true;
473
565
  const controller = new AbortController();
474
566
  const vars = JSON.parse(variablesKey);
475
- client.request(document, vars, controller.signal).then((data) => {
567
+ client.request(document, vars, controller.signal, { silent }).then((data) => {
476
568
  if (!active) return;
477
569
  setResult({
478
570
  key: requestKey,
@@ -499,6 +591,7 @@ function useStewardsQuery(document, variables, options = {}) {
499
591
  variablesKey,
500
592
  requestKey,
501
593
  skip,
594
+ silent,
502
595
  nonce
503
596
  ]);
504
597
  const current = result?.key === requestKey ? result : void 0;
@@ -547,25 +640,6 @@ function useStewardsMutation(document) {
547
640
  };
548
641
  }
549
642
 
550
- // src/theme/ScopedTheme.tsx
551
- /** The SDK's only styling root: theme variables live on this element alone. */
552
- function ScopedTheme({ theme, label, component, children }) {
553
- return /* @__PURE__ */ jsx("section", {
554
- "aria-label": label,
555
- "data-botmanor-sdk": component,
556
- style: {
557
- ...themeToStyle(theme),
558
- background: themeVar("surface"),
559
- color: themeVar("text"),
560
- border: `1px solid ${themeVar("border")}`,
561
- borderRadius: themeVar("radius"),
562
- fontFamily: themeVar("fontFamily"),
563
- padding: "16px"
564
- },
565
- children
566
- });
567
- }
568
-
569
643
  // src/components/ui.tsx
570
644
  /** Shared, token-only building blocks for the four SDK surfaces. */
571
645
  const headingStyle = {
@@ -690,6 +764,452 @@ function humanize(value) {
690
764
  return s.charAt(0).toUpperCase() + s.slice(1);
691
765
  }
692
766
 
767
+ // src/components/GuidedErrorNote.tsx
768
+ /** VibeControls in production, the default target of "Open VibeControls". */
769
+ const VIBECONTROLS_APP_URL = "https://app.vibecontrols.com";
770
+ /** The inline fixes the SDK runs itself; others fall back to a link. */
771
+ const SDK_MUTATIONS = /* @__PURE__ */ new Set([
772
+ "PUBLISH_AGENT",
773
+ "REQUEST_AGENT_ACTIVATION",
774
+ "ACTIVATE_STEWARD"
775
+ ]);
776
+ const boxStyle = {
777
+ border: `1px solid ${themeVar("danger")}`,
778
+ borderRadius: themeVar("radius"),
779
+ margin: "8px 0 0",
780
+ padding: "8px 12px",
781
+ fontSize: "14px"
782
+ };
783
+ const lineStyle = { margin: "4px 0 0" };
784
+ const mutedLineStyle = {
785
+ ...lineStyle,
786
+ color: themeVar("textMuted")
787
+ };
788
+ const linkStyle = {
789
+ color: themeVar("accent"),
790
+ fontSize: "13px",
791
+ fontWeight: 500
792
+ };
793
+ /**
794
+ * Where the SDK sends a guided action: the host's resolver when it gave one,
795
+ * else BotManor's own pages on app.botmanor.com and VibeControls.
796
+ */
797
+ function useGuidedEnvironment(canRetry, mutations = SDK_MUTATIONS) {
798
+ const { config } = useStewardsSdk();
799
+ const { resolveTarget, hasPermission, viewerActorId, translate, onUpgrade } = config;
800
+ return useMemo(() => {
801
+ const href = (location) => {
802
+ if (location.kind === "href") return location.href;
803
+ if (location.kind === "route") return location.path;
804
+ return crossShellUrl(location.product === "vibecontrols" ? VIBECONTROLS_APP_URL : DEFAULT_BOTMANOR_APP_URL, location.product === "vibecontrols" ? "/" : location.path);
805
+ };
806
+ return {
807
+ shell: { kind: "other" },
808
+ locate: (target, params) => {
809
+ if (resolveTarget) {
810
+ const resolved = resolveTarget(target, params);
811
+ return resolved ? {
812
+ kind: "href",
813
+ href: resolved
814
+ } : void 0;
815
+ }
816
+ if (target === "VIBECONTROLS") return {
817
+ kind: "href",
818
+ href: `${VIBECONTROLS_APP_URL}/`
819
+ };
820
+ const path = botmanorPath(target, params);
821
+ return path ? {
822
+ kind: "href",
823
+ href: crossShellUrl(DEFAULT_BOTMANOR_APP_URL, path)
824
+ } : void 0;
825
+ },
826
+ mutations,
827
+ canRetry,
828
+ canUpgrade: !!onUpgrade || !!resolveTarget?.("BILLING_PLANS", {}),
829
+ ...hasPermission ? { hasPermission } : {},
830
+ ...viewerActorId !== void 0 ? { viewerActorId } : {},
831
+ ...translate ? { t: translate } : {},
832
+ href
833
+ };
834
+ }, [
835
+ resolveTarget,
836
+ hasPermission,
837
+ viewerActorId,
838
+ translate,
839
+ onUpgrade,
840
+ canRetry,
841
+ mutations
842
+ ]);
843
+ }
844
+ /**
845
+ * An error, explained (BOFF-18785): what happened, why, the next step, up to
846
+ * two actions the viewer may take, and who can fix it when they cannot. A
847
+ * local validation error (no code) reads as its own message, as before.
848
+ */
849
+ function GuidedErrorNote({ error, guided: given, context, onRetry, onFixed, tone = "error", canActivateSteward = true }) {
850
+ const [fixError, setFixError] = useState(void 0);
851
+ const fixFailed = !!fixError && fixError.for === (given ?? error);
852
+ const mounted = useRef(true);
853
+ useEffect(() => {
854
+ mounted.current = true;
855
+ return () => {
856
+ mounted.current = false;
857
+ };
858
+ }, []);
859
+ const isMounted = useCallback(() => mounted.current, []);
860
+ const subjectRef = useRef(given ?? error);
861
+ useEffect(() => {
862
+ subjectRef.current = given ?? error;
863
+ });
864
+ const isCurrent = useCallback((subject) => mounted.current && subjectRef.current === subject, []);
865
+ const [requestedFor, setRequestedFor] = useState(void 0);
866
+ const shownError = fixError && fixError.for === (given ?? error) ? fixError.error : error;
867
+ const base = useMemo(() => fixError && fixError.for === (given ?? error) ? describeGuidedError(fixError.error, context) : given ?? (error ? describeGuidedError(error, context) : void 0), [
868
+ given,
869
+ error,
870
+ fixError,
871
+ context
872
+ ]);
873
+ const agentId = base?.params.agentId ? String(base.params.agentId) : void 0;
874
+ const needsAgent = base?.reason === "AGENT_NOT_ACTIVE" && !!agentId && (!context?.agent?.status || context.agent.status === "ACTIVE") && typeof extractGuidedSource(shownError)?.extensions?.agentStatus !== "string";
875
+ const fetchedAgent = useStewardsQuery("query GetStewardAgentStatus($id: ID!) {\n getBotmanorAgent(id: $id) { id name status llmModelId }\n}", { id: agentId ?? "" }, {
876
+ skip: !needsAgent,
877
+ silent: true
878
+ }).data?.getBotmanorAgent ?? void 0;
879
+ const guided = useMemo(() => {
880
+ if (!base || !needsAgent || !fetchedAgent || !shownError) return base;
881
+ return describeGuidedError(shownError, {
882
+ ...context,
883
+ agent: fetchedAgent
884
+ }) ?? base;
885
+ }, [
886
+ base,
887
+ needsAgent,
888
+ fetchedAgent,
889
+ shownError,
890
+ context
891
+ ]);
892
+ if (!guided) return null;
893
+ const guidedAgent = guided.params.agentId ? String(guided.params.agentId) : void 0;
894
+ const activationGuidance = guided.reason === "AGENT_NOT_ACTIVE" || guided.reason === "AGENT_APPROVAL_REQUIRED" || guided.reason === "ACTIVATION_ALREADY_PENDING" || guided.reason === "ACTIVATION_REQUEST_STALE";
895
+ if (requestedFor && activationGuidance && guidedAgent === requestedFor.agentId) return /* @__PURE__ */ jsx(RequestedNote, {
896
+ agentId: requestedFor.agentId,
897
+ ...requestedFor.requestId ? { requestId: requestedFor.requestId } : {},
898
+ isCurrent: () => isCurrent(given ?? error),
899
+ onSettled: (published) => {
900
+ setRequestedFor(void 0);
901
+ if (published) Promise.resolve(onRetry?.());
902
+ }
903
+ });
904
+ if (guided.reason === "UNKNOWN" && !guided.code && guided.serverMessage) return /* @__PURE__ */ jsx(PlainNote, { message: guided.serverMessage });
905
+ return /* @__PURE__ */ jsx(GuidedBody, {
906
+ canActivateSteward,
907
+ guided,
908
+ tone,
909
+ onRetry,
910
+ onFixed: (mutation, params) => {
911
+ if (mutation === "REQUEST_AGENT_ACTIVATION" && params.agentId) setRequestedFor({
912
+ agentId: String(params.agentId),
913
+ ...params.activationRequestId ? { requestId: String(params.activationRequestId) } : {}
914
+ });
915
+ setFixError(void 0);
916
+ onFixed?.(mutation);
917
+ },
918
+ ...fixFailed && fixError ? { retryFix: {
919
+ mutation: fixError.mutation,
920
+ params: fixError.params
921
+ } } : {},
922
+ isMounted,
923
+ isCurrent: () => isCurrent(given ?? error),
924
+ onFixFailed: (err, mutation, params) => setFixError({
925
+ for: given ?? error,
926
+ error: err,
927
+ mutation,
928
+ params
929
+ })
930
+ }, `${guided.i18nKey}|${String(guided.params.agentId ?? "")}|${String(guided.params.stewardId ?? "")}`);
931
+ }
932
+ /**
933
+ * An activation request is waiting for a reviewer. "Check again" reads the
934
+ * agent: once it is published the note gives way to the screen (reloaded);
935
+ * while it is not, the note says it is still waiting.
936
+ */
937
+ function RequestedNote({ agentId, requestId, isCurrent, onSettled }) {
938
+ const { client, config } = useStewardsSdk();
939
+ const t = config.translate ?? englishGuidedTranslate;
940
+ const [checking, setChecking] = useState(false);
941
+ const [stillWaiting, setStillWaiting] = useState(false);
942
+ const check = async () => {
943
+ setChecking(true);
944
+ try {
945
+ const agent = await client.request(GET_AGENT_STATUS, { id: agentId }, void 0, { silent: true });
946
+ const request = agent.getBotmanorAgent?.status !== "ACTIVE" && requestId ? await client.request(GET_AGENT_ACTIVATION_REQUEST, { id: requestId }, void 0, { silent: true }) : void 0;
947
+ if (!isCurrent()) return;
948
+ const published = agent.getBotmanorAgent?.status === "ACTIVE";
949
+ const open = request?.getBotmanorAgentApprovalRequest;
950
+ const pending = !request || open?.status === "PENDING" && !open.isStale;
951
+ if (published || !pending) onSettled(published);
952
+ else setStillWaiting(true);
953
+ } catch {
954
+ if (isCurrent()) setStillWaiting(true);
955
+ } finally {
956
+ setChecking(false);
957
+ }
958
+ };
959
+ return /* @__PURE__ */ jsxs("p", {
960
+ role: "status",
961
+ style: {
962
+ ...themeToStyle(config.theme),
963
+ ...mutedLineStyle
964
+ },
965
+ children: [
966
+ stillWaiting ? t("guidedErrors.done.activationStillPending", "Still waiting for a reviewer to approve the agent.") : t("guidedErrors.done.activationRequested", "Activation requested. You can continue once a reviewer approves the agent."),
967
+ " ",
968
+ /* @__PURE__ */ jsx(Button, {
969
+ onClick: () => void check(),
970
+ disabled: checking,
971
+ children: t("guidedErrors.actions.checkAgain", "Check again")
972
+ })
973
+ ]
974
+ });
975
+ }
976
+ function PlainNote({ message }) {
977
+ const { config } = useStewardsSdk();
978
+ return /* @__PURE__ */ jsx("p", {
979
+ role: "alert",
980
+ style: {
981
+ ...themeToStyle(config.theme),
982
+ ...lineStyle,
983
+ margin: "8px 0 0",
984
+ color: themeVar("danger"),
985
+ fontWeight: 500
986
+ },
987
+ children: message
988
+ });
989
+ }
990
+ /** The SDK's fixes without activating the steward. */
991
+ const SDK_MUTATIONS_NO_ACTIVATE = /* @__PURE__ */ new Set(["PUBLISH_AGENT", "REQUEST_AGENT_ACTIVATION"]);
992
+ function GuidedBody({ canActivateSteward, guided, tone, onRetry, onFixed, retryFix, onFixFailed, isMounted, isCurrent }) {
993
+ const { client, config } = useStewardsSdk();
994
+ const requestIdRef = useRef(void 0);
995
+ const env = useGuidedEnvironment(!!onRetry || !!retryFix, canActivateSteward ? SDK_MUTATIONS : SDK_MUTATIONS_NO_ACTIVATE);
996
+ const [busy, setBusy] = useState(false);
997
+ const retryRef = useRef(onRetry);
998
+ useEffect(() => {
999
+ retryRef.current = onRetry;
1000
+ });
1001
+ const waitUntil = useMemo(() => guided.retryAfterSeconds ? Date.now() + guided.retryAfterSeconds * 1e3 : 0, [guided]);
1002
+ const [now, setNow] = useState(() => Date.now());
1003
+ const waitLeft = Math.max(0, Math.ceil((waitUntil - now) / 1e3));
1004
+ useEffect(() => {
1005
+ if (waitLeft <= 0) return void 0;
1006
+ const timer = setTimeout(() => setNow(Date.now()), 1e3);
1007
+ return () => clearTimeout(timer);
1008
+ }, [waitLeft, now]);
1009
+ const [copied, setCopied] = useState(void 0);
1010
+ const extraParams = useMemo(() => {
1011
+ const ownerId = guided.params.ownerActorId;
1012
+ const machineOwnerId = guided.params.machineOwnerActorId;
1013
+ return {
1014
+ ownerName: ownerId !== void 0 ? config.resolveActorName?.(String(ownerId)) : void 0,
1015
+ machineOwner: machineOwnerId !== void 0 ? config.resolveActorName?.(String(machineOwnerId)) : void 0
1016
+ };
1017
+ }, [guided.params, config]);
1018
+ const t = env.t ?? englishGuidedTranslate;
1019
+ const text = guidedText(guided, t, extraParams);
1020
+ const plan = planGuidedActions(guided, {
1021
+ ...env,
1022
+ extraParams
1023
+ });
1024
+ /** Runs one fix; false when it only queued something (an activation request). */
1025
+ const perform = useCallback(async (mutation, params) => {
1026
+ const agentId = params.agentId ? String(params.agentId) : void 0;
1027
+ const stewardId = params.stewardId ? String(params.stewardId) : void 0;
1028
+ if (mutation === "PUBLISH_AGENT" && agentId) {
1029
+ await client.request(PUBLISH_AGENT, { id: agentId });
1030
+ return true;
1031
+ }
1032
+ if (mutation === "REQUEST_AGENT_ACTIVATION" && agentId) {
1033
+ const made = await client.request(REQUEST_AGENT_ACTIVATION, { agentId });
1034
+ requestIdRef.current = made.requestBotmanorAgentActivation.id;
1035
+ return false;
1036
+ }
1037
+ if (mutation === "ACTIVATE_STEWARD" && stewardId) {
1038
+ await client.request(SET_STEWARD_STATUS, {
1039
+ id: stewardId,
1040
+ status: "ACTIVE"
1041
+ });
1042
+ return true;
1043
+ }
1044
+ return false;
1045
+ }, [client]);
1046
+ const runFix = useCallback(async (mutation, params = guided.params) => {
1047
+ const interrupted = retryFix && retryFix.mutation !== mutation ? retryFix : void 0;
1048
+ setBusy(true);
1049
+ let step = {
1050
+ mutation,
1051
+ params
1052
+ };
1053
+ try {
1054
+ const continues = await perform(mutation, params);
1055
+ if (!isCurrent()) return;
1056
+ if (!continues) {
1057
+ onFixed?.(mutation, requestIdRef.current ? {
1058
+ ...params,
1059
+ activationRequestId: requestIdRef.current
1060
+ } : params);
1061
+ return;
1062
+ }
1063
+ if (interrupted) {
1064
+ step = interrupted;
1065
+ const next = await perform(interrupted.mutation, interrupted.params);
1066
+ if (!isCurrent()) return;
1067
+ if (!next) {
1068
+ onFixed?.(interrupted.mutation, interrupted.params);
1069
+ return;
1070
+ }
1071
+ }
1072
+ onFixed?.(step.mutation, step.params);
1073
+ try {
1074
+ await retryRef.current?.();
1075
+ } catch {}
1076
+ } catch (err) {
1077
+ onFixFailed(err instanceof Error ? err : new Error(String(err)), step.mutation, step.params);
1078
+ } finally {
1079
+ if (isMounted()) setBusy(false);
1080
+ }
1081
+ }, [
1082
+ guided.params,
1083
+ retryFix,
1084
+ perform,
1085
+ onFixed,
1086
+ onFixFailed,
1087
+ isMounted,
1088
+ isCurrent
1089
+ ]);
1090
+ const act = (planned) => {
1091
+ const { action } = planned;
1092
+ if (action.kind === "retry") {
1093
+ if (retryFix) runFix(retryFix.mutation, retryFix.params);
1094
+ else Promise.resolve(onRetry?.());
1095
+ return;
1096
+ }
1097
+ if (action.kind === "mutation" && action.mutation) {
1098
+ runFix(action.mutation);
1099
+ return;
1100
+ }
1101
+ if (action.kind === "upgrade" && config.onUpgrade) {
1102
+ config.onUpgrade(guided);
1103
+ return;
1104
+ }
1105
+ if (planned.location) {
1106
+ const href = env.href(planned.location);
1107
+ if (href.startsWith("/") && config.navigate) config.navigate(href);
1108
+ else if (typeof window !== "undefined") window.location.assign(href);
1109
+ }
1110
+ };
1111
+ const details = [
1112
+ guided.reason,
1113
+ guided.code,
1114
+ guided.traceId ? `trace ${guided.traceId}` : void 0
1115
+ ].filter(Boolean).join(" · ");
1116
+ const copyDetails = () => {
1117
+ globalThis.navigator?.clipboard?.writeText(details).then(() => setCopied(details), () => void 0);
1118
+ };
1119
+ return /* @__PURE__ */ jsxs("div", {
1120
+ role: tone === "error" ? "alert" : "status",
1121
+ "data-guided-reason": guided.reason,
1122
+ ...guided.variant ? { "data-guided-variant": guided.variant } : {},
1123
+ style: {
1124
+ ...themeToStyle(config.theme),
1125
+ ...boxStyle,
1126
+ ...tone === "error" ? {} : { border: `1px solid ${themeVar("border")}` }
1127
+ },
1128
+ children: [
1129
+ /* @__PURE__ */ jsx("strong", {
1130
+ style: tone === "error" ? { color: themeVar("danger") } : void 0,
1131
+ children: text.title
1132
+ }),
1133
+ text.cause && text.cause !== text.title ? /* @__PURE__ */ jsx("p", {
1134
+ style: lineStyle,
1135
+ children: text.cause
1136
+ }) : null,
1137
+ text.next ? /* @__PURE__ */ jsx("p", {
1138
+ style: lineStyle,
1139
+ children: text.next
1140
+ }) : null,
1141
+ plan.askAdmin.map((line) => /* @__PURE__ */ jsx("p", {
1142
+ style: mutedLineStyle,
1143
+ children: line
1144
+ }, line)),
1145
+ plan.actions.length > 0 ? /* @__PURE__ */ jsx("div", {
1146
+ style: {
1147
+ alignItems: "center",
1148
+ display: "flex",
1149
+ flexWrap: "wrap",
1150
+ gap: "8px",
1151
+ marginTop: "8px"
1152
+ },
1153
+ children: plan.actions.map((planned, index) => planned.action.kind === "navigate" && planned.location ? /* @__PURE__ */ jsx("a", {
1154
+ href: env.href(planned.location),
1155
+ style: linkStyle,
1156
+ onClick: (e) => {
1157
+ const href = env.href(planned.location);
1158
+ if (e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey && href.startsWith("/") && config.navigate) {
1159
+ e.preventDefault();
1160
+ config.navigate(href);
1161
+ }
1162
+ },
1163
+ children: planned.label
1164
+ }, planned.action.id) : /* @__PURE__ */ jsx(Button, {
1165
+ kind: index === 0 ? "primary" : "secondary",
1166
+ disabled: busy || planned.action.kind === "retry" && waitLeft > 0,
1167
+ onClick: () => act(planned),
1168
+ children: planned.action.kind === "retry" && waitLeft > 0 ? t("guidedErrors.actions.retryIn", "{{label}} in {{seconds}}s", {
1169
+ label: planned.label,
1170
+ seconds: waitLeft
1171
+ }) : planned.label
1172
+ }, planned.action.id))
1173
+ }) : null,
1174
+ guided.traceId ? /* @__PURE__ */ jsx("p", {
1175
+ style: mutedLineStyle,
1176
+ children: /* @__PURE__ */ jsx("button", {
1177
+ type: "button",
1178
+ onClick: copyDetails,
1179
+ style: {
1180
+ ...linkStyle,
1181
+ background: "transparent",
1182
+ border: 0,
1183
+ cursor: "pointer",
1184
+ padding: 0,
1185
+ fontWeight: 400
1186
+ },
1187
+ children: copied === details ? t("guidedErrors.actions.copied", "Copied") : t("guidedErrors.actions.copyDetails", "Copy details")
1188
+ })
1189
+ }) : null
1190
+ ]
1191
+ });
1192
+ }
1193
+
1194
+ // src/theme/ScopedTheme.tsx
1195
+ /** The SDK's only styling root: theme variables live on this element alone. */
1196
+ function ScopedTheme({ theme, label, component, children }) {
1197
+ return /* @__PURE__ */ jsx("section", {
1198
+ "aria-label": label,
1199
+ "data-botmanor-sdk": component,
1200
+ style: {
1201
+ ...themeToStyle(theme),
1202
+ background: themeVar("surface"),
1203
+ color: themeVar("text"),
1204
+ border: `1px solid ${themeVar("border")}`,
1205
+ borderRadius: themeVar("radius"),
1206
+ fontFamily: themeVar("fontFamily"),
1207
+ padding: "16px"
1208
+ },
1209
+ children
1210
+ });
1211
+ }
1212
+
693
1213
  // src/components/StewardOwnMachineDesk.tsx
694
1214
  /** Where the person manages their VibeControls machines, by default. */
695
1215
  const DEFAULT_VIBECONTROLS_URL = "https://app.vibecontrols.com/";
@@ -1127,7 +1647,13 @@ function StewardOwnMachineDeskPanel({ stewardId, ownerActorId, vibecontrolsUrl =
1127
1647
  onGrant: (agentId) => void onGrant(agentId),
1128
1648
  onRevoke: (agentId) => void onRevoke(agentId)
1129
1649
  }) : /* @__PURE__ */ jsx(Muted, { children: "Your role cannot see VibeControls machines in this workspace." }),
1130
- /* @__PURE__ */ jsx(ErrorNote, { error: actionError })
1650
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
1651
+ error: actionError,
1652
+ context: {
1653
+ stewardId,
1654
+ ownerActorId
1655
+ }
1656
+ })
1131
1657
  ]
1132
1658
  });
1133
1659
  }
@@ -1190,7 +1716,7 @@ function GrantOptions({ stewardId, days, onDays, appsText, onAppsText }) {
1190
1716
  function CurrentMachine({ loading, loaded, error, current, name, canClear, busy, onClear }) {
1191
1717
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1192
1718
  loading ? /* @__PURE__ */ jsx(Muted, { children: "Loading the desk…" }) : null,
1193
- /* @__PURE__ */ jsx(ErrorNote, { error }),
1719
+ /* @__PURE__ */ jsx(GuidedErrorNote, { error }),
1194
1720
  current ? /* @__PURE__ */ jsxs("p", {
1195
1721
  style: { margin: "8px 0 0" },
1196
1722
  children: [
@@ -1213,7 +1739,7 @@ function CurrentMachine({ loading, loaded, error, current, name, canClear, busy,
1213
1739
  function MachineList({ loading, listed, truncated, error, rows, ...actions }) {
1214
1740
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1215
1741
  loading ? /* @__PURE__ */ jsx(Muted, { children: "Loading your machines…" }) : null,
1216
- /* @__PURE__ */ jsx(ErrorNote, { error }),
1742
+ /* @__PURE__ */ jsx(GuidedErrorNote, { error }),
1217
1743
  listed && rows.length === 0 ? /* @__PURE__ */ jsx(Muted, { children: "You have no VibeControls machines in this workspace." }) : null,
1218
1744
  truncated ? /* @__PURE__ */ jsx(Muted, { children: "Only the first machines in this workspace are listed." }) : null,
1219
1745
  rows.length > 0 ? /* @__PURE__ */ jsx("ul", {
@@ -1275,6 +1801,12 @@ function MachineRow({ row: { agent, granted, chosen }, unchecked, ownerActorId,
1275
1801
  }
1276
1802
 
1277
1803
  // src/components/StewardRunView.tsx
1804
+ /** Statuses after which a run's failure, if any, is known. */
1805
+ const UNFINISHED = /* @__PURE__ */ new Set([
1806
+ "FAILED",
1807
+ "STOPPED",
1808
+ "PAUSED_BUDGET"
1809
+ ]);
1278
1810
  const WAITING_REASON = {
1279
1811
  WAITING_APPROVAL: "APPROVAL",
1280
1812
  WAITING_TAKEOVER: "TAKEOVER",
@@ -1323,12 +1855,33 @@ function useRunTransitionEvents(runId, run) {
1323
1855
  * while the run is active (the embed session is not a subscription actor) and
1324
1856
  * emits `run.waiting`, `run.completed` and `run.failed` as the status changes.
1325
1857
  */
1326
- function StewardRunView({ runId, pollIntervalMs = 3e3 }) {
1858
+ function StewardRunView({ runId, pollIntervalMs = 3e3, onRunAgain, onStewardChanged, deskKind, canUpdateSteward = true }) {
1327
1859
  const { config } = useStewardsSdk();
1328
1860
  const { data, error, loading, refetch } = useStewardsQuery(GET_STEWARD_RUN, { id: runId }, { pollMs: (d) => d.getBotmanorStewardRun && !isTerminalRunStatus(d.getBotmanorStewardRun.status) ? pollIntervalMs : false });
1329
1861
  const cancel = useStewardsMutation(CANCEL_STEWARD_RUN);
1330
1862
  const run = data?.getBotmanorStewardRun ?? void 0;
1331
1863
  useRunTransitionEvents(runId, run);
1864
+ const unfinished = !!run && UNFINISHED.has(run.status);
1865
+ const failureQuery = useStewardsQuery(GET_STEWARD_RUN_FAILURE, { id: runId }, {
1866
+ skip: !unfinished,
1867
+ silent: true
1868
+ });
1869
+ const failure = failureQuery.data?.getBotmanorStewardRun?.failure ?? null;
1870
+ const guidedFailure = useMemo(() => run && !failureQuery.loading ? describeRunFailure({
1871
+ id: run.id,
1872
+ stewardId: run.stewardId,
1873
+ status: run.status,
1874
+ stopReason: run.stopReason,
1875
+ failure,
1876
+ steps: run.steps,
1877
+ stepCount: run.stepCount,
1878
+ ...deskKind ? { deskKind } : {}
1879
+ }) : void 0, [
1880
+ run,
1881
+ failure,
1882
+ failureQuery.loading,
1883
+ deskKind
1884
+ ]);
1332
1885
  const onCancel = async () => {
1333
1886
  if (await cancel.mutate({ id: runId })) refetch();
1334
1887
  };
@@ -1342,7 +1895,22 @@ function StewardRunView({ runId, pollIntervalMs = 3e3 }) {
1342
1895
  children: "Steward run"
1343
1896
  }),
1344
1897
  loading && !run ? /* @__PURE__ */ jsx(Muted, { children: "Loading the run…" }) : null,
1345
- /* @__PURE__ */ jsx(ErrorNote, { error: error ?? cancel.error }),
1898
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
1899
+ error,
1900
+ context: {
1901
+ runId,
1902
+ ...run ? { stewardId: run.stewardId } : {}
1903
+ },
1904
+ onRetry: refetch
1905
+ }),
1906
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
1907
+ error: error ? void 0 : cancel.error,
1908
+ context: {
1909
+ runId,
1910
+ ...run ? { stewardId: run.stewardId } : {}
1911
+ },
1912
+ ...isStaleStateError(cancel.error) ? { onRetry: refetch } : {}
1913
+ }),
1346
1914
  !loading && !error && !run ? /* @__PURE__ */ jsx(Muted, { children: "This run was not found." }) : null,
1347
1915
  run ? /* @__PURE__ */ jsxs(Fragment, { children: [
1348
1916
  /* @__PURE__ */ jsx(RunHeader, {
@@ -1350,6 +1918,16 @@ function StewardRunView({ runId, pollIntervalMs = 3e3 }) {
1350
1918
  cancelling: cancel.loading,
1351
1919
  onCancel: () => void onCancel()
1352
1920
  }),
1921
+ guidedFailure ? /* @__PURE__ */ jsx(GuidedErrorNote, {
1922
+ guided: guidedFailure,
1923
+ context: {
1924
+ runId,
1925
+ stewardId: run.stewardId
1926
+ },
1927
+ ...onRunAgain ? { onRetry: onRunAgain } : {},
1928
+ ...onStewardChanged ? { onFixed: onStewardChanged } : {},
1929
+ canActivateSteward: canUpdateSteward
1930
+ }) : null,
1353
1931
  /* @__PURE__ */ jsx(RunSteps, { steps: run.steps }),
1354
1932
  /* @__PURE__ */ jsx(RunApprovals, { approvals: run.approvals })
1355
1933
  ] }) : null
@@ -1363,7 +1941,8 @@ const subheadingStyle = {
1363
1941
  };
1364
1942
  function runTimeline(run) {
1365
1943
  const finished = run.finishedAt ? `, finished ${formatDate(run.finishedAt)}` : "";
1366
- const reason = run.stopReason ? ` — ${humanize(run.stopReason)}` : "";
1944
+ const label = stopReasonLabel(run.stopReason);
1945
+ const reason = label ? ` — ${label}` : "";
1367
1946
  return `Started ${formatDate(run.startedAt)}${finished}${reason}`;
1368
1947
  }
1369
1948
  function runUsage(run) {
@@ -1464,11 +2043,14 @@ function StewardConsole({ stewardId, onSelectSteward, vibecontrolsUrl, ownMachin
1464
2043
  });
1465
2044
  }
1466
2045
  function StewardList({ onSelect }) {
1467
- const { data, error, loading } = useStewardsQuery(LIST_STEWARDS, { pagination: { limit: 50 } });
2046
+ const { data, error, loading, refetch } = useStewardsQuery(LIST_STEWARDS, { pagination: { limit: 50 } });
1468
2047
  const stewards = data?.listBotmanorStewards;
1469
2048
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1470
2049
  loading && !stewards ? /* @__PURE__ */ jsx(Muted, { children: "Loading stewards…" }) : null,
1471
- /* @__PURE__ */ jsx(ErrorNote, { error }),
2050
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2051
+ error,
2052
+ onRetry: refetch
2053
+ }),
1472
2054
  stewards && stewards.length === 0 ? /* @__PURE__ */ jsx(Muted, { children: "No stewards yet." }) : null,
1473
2055
  stewards && stewards.length > 0 ? /* @__PURE__ */ jsx("ul", {
1474
2056
  style: listStyle,
@@ -1479,6 +2061,7 @@ function StewardList({ onSelect }) {
1479
2061
  /* @__PURE__ */ jsx("strong", { children: s.agent?.name ?? s.agentId }),
1480
2062
  " ",
1481
2063
  /* @__PURE__ */ jsx(Badge, { children: humanize(s.status) }),
2064
+ s.agent?.status && s.agent.status !== "ACTIVE" ? /* @__PURE__ */ jsx(Badge, { children: agentStateLabel(s.agent.status) }) : null,
1482
2065
  s.charter ? /* @__PURE__ */ jsx(Badge, { children: humanize(s.charter.autonomyLevel) }) : null,
1483
2066
  s.pendingApprovalCount > 0 ? /* @__PURE__ */ jsxs(Badge, { children: [s.pendingApprovalCount, " awaiting approval"] }) : null,
1484
2067
  " ",
@@ -1506,11 +2089,21 @@ function StewardPanel({ stewardId, onBack, vibecontrolsUrl, ownMachineAccess })
1506
2089
  const loaded = steward.data?.getBotmanorSteward ?? void 0;
1507
2090
  const override = confirmed && confirmed.stewardId === stewardId && loaded?.id === stewardId && steward.data === confirmed.answer ? confirmed.status : void 0;
1508
2091
  if (confirmed && !override) setConfirmed(void 0);
1509
- const detail = loaded && override ? {
2092
+ const detail = useMemo(() => loaded && override ? {
1510
2093
  ...loaded,
1511
2094
  status: override
1512
- } : loaded;
2095
+ } : loaded, [loaded, override]);
1513
2096
  const notFound = !steward.loading && !steward.error && !detail;
2097
+ const context = useMemo(() => stewardContext(stewardId, detail), [stewardId, detail]);
2098
+ const onStatusChanged = (id, status) => {
2099
+ if (id !== stewardId) return;
2100
+ setConfirmed({
2101
+ stewardId: id,
2102
+ status,
2103
+ answer: latestAnswer.current
2104
+ });
2105
+ steward.refetch();
2106
+ };
1514
2107
  const onStarted = (runId) => {
1515
2108
  setSelectedRun(runId);
1516
2109
  runs.refetch();
@@ -1524,40 +2117,56 @@ function StewardPanel({ stewardId, onBack, vibecontrolsUrl, ownMachineAccess })
1524
2117
  })
1525
2118
  }) : null,
1526
2119
  steward.loading && !detail ? /* @__PURE__ */ jsx(Muted, { children: "Loading the steward…" }) : null,
1527
- /* @__PURE__ */ jsx(ErrorNote, { error: steward.error }),
2120
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2121
+ error: steward.error,
2122
+ context,
2123
+ onRetry: steward.refetch
2124
+ }),
1528
2125
  notFound ? /* @__PURE__ */ jsx(Muted, { children: "This steward was not found." }) : null,
1529
2126
  detail ? /* @__PURE__ */ jsxs(Fragment, { children: [
1530
2127
  /* @__PURE__ */ jsx(StewardSummary, { detail }),
1531
2128
  /* @__PURE__ */ jsx(StatusActions, {
1532
2129
  detail,
2130
+ context,
1533
2131
  canUpdate: ownMachineAccess?.canUpdateSteward !== false,
1534
- onChanged: (id, status) => {
1535
- if (id !== stewardId) return;
1536
- setConfirmed({
1537
- stewardId: id,
1538
- status,
1539
- answer: latestAnswer.current
1540
- });
1541
- steward.refetch();
1542
- }
2132
+ onChanged: onStatusChanged,
2133
+ onReload: steward.refetch
1543
2134
  }),
1544
2135
  /* @__PURE__ */ jsx(OwnMachineSection, {
1545
2136
  detail,
1546
2137
  vibecontrolsUrl,
1547
2138
  access: ownMachineAccess
1548
2139
  }),
1549
- detail.status === "ACTIVE" ? /* @__PURE__ */ jsx(StartRunForm, {
2140
+ /* @__PURE__ */ jsx(AgentGuidance, {
2141
+ detail,
2142
+ context,
2143
+ canUpdate: ownMachineAccess?.canUpdateSteward !== false,
2144
+ onChanged: onStatusChanged,
2145
+ onReload: steward.refetch
2146
+ }),
2147
+ detail.status === "ACTIVE" && agentIsActive(detail) ? /* @__PURE__ */ jsx(StartRunForm, {
1550
2148
  stewardId,
1551
- onStarted
1552
- }) : /* @__PURE__ */ jsx(Muted, { children: "Only an active steward can start a run." }),
2149
+ context,
2150
+ canActivateSteward: ownMachineAccess?.canUpdateSteward !== false,
2151
+ onStarted,
2152
+ onStewardChanged: steward.refetch,
2153
+ onRunsChanged: runs.refetch
2154
+ }) : detail.status === "ARCHIVED" || !agentIsActive(detail) ? null : /* @__PURE__ */ jsx(Muted, { children: "Only an active steward can start a run." }),
1553
2155
  /* @__PURE__ */ jsx(RecentRuns, {
1554
2156
  runs: runs.data?.listBotmanorStewardRuns,
1555
2157
  error: runs.error,
1556
- onView: setSelectedRun
2158
+ onView: setSelectedRun,
2159
+ onRetry: runs.refetch
1557
2160
  }),
1558
2161
  selectedRun ? /* @__PURE__ */ jsx("div", {
1559
2162
  style: { marginTop: "16px" },
1560
- children: /* @__PURE__ */ jsx(StewardRunView, { runId: selectedRun })
2163
+ children: /* @__PURE__ */ jsx(StewardRunView, {
2164
+ runId: selectedRun,
2165
+ ...detail.status === "ACTIVE" && agentIsActive(detail) ? { onRunAgain: () => focusPrompt(stewardId) } : {},
2166
+ onStewardChanged: steward.refetch,
2167
+ deskKind: detail.defaultDeskKind,
2168
+ canUpdateSteward: ownMachineAccess?.canUpdateSteward !== false
2169
+ })
1561
2170
  }) : null
1562
2171
  ] }) : null
1563
2172
  ] });
@@ -1584,10 +2193,11 @@ const NEXT_STATUS = {
1584
2193
  * Shown to a viewer with botmanor-steward:update (`canUpdateSteward`); without
1585
2194
  * an access answer the gateway decides.
1586
2195
  */
1587
- function StatusActions({ detail, canUpdate, onChanged }) {
2196
+ function StatusActions({ detail, context, canUpdate, onChanged, onReload }) {
1588
2197
  const change = useStewardsMutation(SET_STEWARD_STATUS);
1589
2198
  const next = NEXT_STATUS[detail.status];
1590
2199
  if (!next || !canUpdate) return null;
2200
+ if (next.to === "ACTIVE" && !agentIsActive(detail)) return null;
1591
2201
  const onClick = async () => {
1592
2202
  const result = await change.mutate({
1593
2203
  id: detail.id,
@@ -1601,9 +2211,95 @@ function StatusActions({ detail, canUpdate, onChanged }) {
1601
2211
  onClick: () => void onClick(),
1602
2212
  disabled: change.loading,
1603
2213
  children: next.label
1604
- }), /* @__PURE__ */ jsx(ErrorNote, { error: change.error })]
2214
+ }), /* @__PURE__ */ jsx(GuidedErrorNote, {
2215
+ error: change.error,
2216
+ context,
2217
+ ...isStaleStateError(change.error) ? { onRetry: onReload } : isDefiniteRefusal(change.error) ? { onRetry: () => void onClick() } : {},
2218
+ onFixed: onReload
2219
+ })]
1605
2220
  });
1606
2221
  }
2222
+ /**
2223
+ * What blocks a steward whose agent is not published (or is gone), or that is
2224
+ * archived, with the fix (catalog A1, A3 and A5 prevention). After the agent
2225
+ * is published here, a draft or paused steward is activated.
2226
+ */
2227
+ function AgentGuidance({ detail, context, canUpdate, onChanged, onReload }) {
2228
+ const { config } = useStewardsSdk();
2229
+ const activate = useStewardsMutation(SET_STEWARD_STATUS);
2230
+ const archived = detail.status === "ARCHIVED";
2231
+ const blocked = !detail.agent || !agentIsActive(detail);
2232
+ const preview = useMemo(() => {
2233
+ if (!archived && !blocked) return void 0;
2234
+ const reason = archived ? "STEWARD_ARCHIVED" : detail.agent ? "AGENT_NOT_ACTIVE" : "AGENT_UNAVAILABLE";
2235
+ return describeGuidedError({
2236
+ code: "BAD_USER_INPUT",
2237
+ extensions: {
2238
+ reason,
2239
+ stewardId: detail.id,
2240
+ agentId: detail.agentId
2241
+ }
2242
+ }, context);
2243
+ }, [
2244
+ archived,
2245
+ blocked,
2246
+ detail,
2247
+ context
2248
+ ]);
2249
+ const canActivate = canUpdate && config.hasPermission?.(GUIDED_PERMISSIONS.STEWARD_UPDATE) !== false;
2250
+ const afterPublish = async (mutation) => {
2251
+ if (mutation !== "PUBLISH_AGENT" || archived || detail.status === "ACTIVE" || !canActivate) {
2252
+ onReload();
2253
+ return;
2254
+ }
2255
+ const result = await activate.mutate({
2256
+ id: detail.id,
2257
+ status: "ACTIVE"
2258
+ });
2259
+ if (result) onChanged(result.setBotmanorStewardStatus.id, result.setBotmanorStewardStatus.status);
2260
+ else onReload();
2261
+ };
2262
+ return /* @__PURE__ */ jsxs(Fragment, { children: [preview ? /* @__PURE__ */ jsx(GuidedErrorNote, {
2263
+ guided: preview,
2264
+ context,
2265
+ tone: "info",
2266
+ onRetry: onReload,
2267
+ onFixed: (mutation) => void afterPublish(mutation)
2268
+ }) : null, /* @__PURE__ */ jsx(GuidedErrorNote, {
2269
+ error: activate.error,
2270
+ context,
2271
+ ...isStaleStateError(activate.error) ? { onRetry: onReload } : {},
2272
+ onFixed: onReload
2273
+ })] });
2274
+ }
2275
+ /** What the console knows about a steward and its agent, for guided errors. */
2276
+ function stewardContext(stewardId, detail) {
2277
+ return {
2278
+ stewardId,
2279
+ ...detail ? {
2280
+ stewardStatus: detail.status,
2281
+ ownerActorId: detail.ownerActorId
2282
+ } : {},
2283
+ ...detail?.agent ? { agent: {
2284
+ id: detail.agent.id,
2285
+ ...detail.agent.status ? { status: detail.agent.status } : {},
2286
+ ..."llmModelId" in detail.agent ? { llmModelId: detail.agent.llmModelId ?? null } : {}
2287
+ } } : detail ? { agent: { id: detail.agentId } } : {}
2288
+ };
2289
+ }
2290
+ /** An agent whose status is not known (an older service) counts as active. */
2291
+ function agentIsActive(detail) {
2292
+ if (!detail.agent) return false;
2293
+ const status = detail.agent.status;
2294
+ return !status || status === "ACTIVE";
2295
+ }
2296
+ function agentStateLabel(status) {
2297
+ return `Agent: ${(AGENT_STATUS_SHORT_LABELS[status] ?? humanize(status)).toLowerCase()}`;
2298
+ }
2299
+ function focusPrompt(stewardId) {
2300
+ if (typeof document === "undefined") return;
2301
+ document.getElementById(`prompt-${stewardId}`)?.focus();
2302
+ }
1607
2303
  /** The machine picker, for a steward whose desk kind is OWN_MACHINE. */
1608
2304
  function OwnMachineSection({ detail, vibecontrolsUrl, access }) {
1609
2305
  if (detail.defaultDeskKind !== "OWN_MACHINE") return null;
@@ -1633,6 +2329,7 @@ function StewardSummary({ detail }) {
1633
2329
  " ",
1634
2330
  /* @__PURE__ */ jsx(Badge, { children: humanize(detail.status) }),
1635
2331
  " ",
2332
+ detail.agent?.status ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Badge, { children: agentStateLabel(detail.agent.status) }), " "] }) : null,
1636
2333
  detail.charter ? /* @__PURE__ */ jsx(Badge, { children: humanize(detail.charter.autonomyLevel) }) : null,
1637
2334
  " ",
1638
2335
  /* @__PURE__ */ jsxs(Badge, { children: ["Desk ", humanize(detail.defaultDeskKind)] })
@@ -1646,19 +2343,22 @@ function StewardSummary({ detail }) {
1646
2343
  * Prompt box that starts a run. Emits `run.started` and hands the new run id
1647
2344
  * to the parent, which selects it and refreshes the run list.
1648
2345
  */
1649
- function StartRunForm({ stewardId, onStarted }) {
2346
+ function StartRunForm({ stewardId, context, onStarted, onStewardChanged, onRunsChanged, canActivateSteward }) {
1650
2347
  const { events } = useStewardsSdk();
1651
2348
  const start = useStewardsMutation(RUN_STEWARD);
1652
2349
  const [prompt, setPrompt] = useState("");
1653
2350
  const onSubmit = async (e) => {
1654
- e.preventDefault();
2351
+ e?.preventDefault();
1655
2352
  const text = prompt.trim();
1656
- if (!text) return;
2353
+ if (!text || start.loading) return;
1657
2354
  const result = await start.mutate({ input: {
1658
2355
  stewardId,
1659
2356
  prompt: text
1660
2357
  } });
1661
- if (!result) return;
2358
+ if (!result) {
2359
+ onRunsChanged();
2360
+ return;
2361
+ }
1662
2362
  const run = result.runBotmanorSteward;
1663
2363
  events.emit("run.started", {
1664
2364
  runId: run.id,
@@ -1691,12 +2391,18 @@ function StartRunForm({ stewardId, onStarted }) {
1691
2391
  children: "Run"
1692
2392
  })
1693
2393
  }),
1694
- /* @__PURE__ */ jsx(ErrorNote, { error: start.error })
2394
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2395
+ error: start.error,
2396
+ context,
2397
+ ...isDefiniteRefusal(start.error) && !isStaleStateError(start.error) ? { onRetry: () => void onSubmit() } : {},
2398
+ onFixed: onStewardChanged,
2399
+ canActivateSteward
2400
+ })
1695
2401
  ]
1696
2402
  });
1697
2403
  }
1698
2404
  /** The steward's latest runs, each with a button that opens it below. */
1699
- function RecentRuns({ runs, error, onView }) {
2405
+ function RecentRuns({ runs, error, onView, onRetry }) {
1700
2406
  return /* @__PURE__ */ jsxs(Fragment, { children: [
1701
2407
  /* @__PURE__ */ jsx("h3", {
1702
2408
  style: {
@@ -1706,7 +2412,10 @@ function RecentRuns({ runs, error, onView }) {
1706
2412
  },
1707
2413
  children: "Recent runs"
1708
2414
  }),
1709
- /* @__PURE__ */ jsx(ErrorNote, { error }),
2415
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2416
+ error,
2417
+ onRetry
2418
+ }),
1710
2419
  runs && runs.length === 0 ? /* @__PURE__ */ jsx(Muted, { children: "No runs yet." }) : null,
1711
2420
  /* @__PURE__ */ jsx("ul", {
1712
2421
  style: listStyle,
@@ -1745,6 +2454,43 @@ const DESKS = [
1745
2454
  "CLOUD",
1746
2455
  "OWN_MACHINE"
1747
2456
  ];
2457
+ /** Agents that can become a steward: drafts are published before the steward runs. */
2458
+ const PICKABLE_AGENT_STATUSES = /* @__PURE__ */ new Set([
2459
+ "ACTIVE",
2460
+ "DRAFT",
2461
+ "PAUSED"
2462
+ ]);
2463
+ /** What the picker says next to an agent's name. */
2464
+ function agentPickerLabel(agent, alreadySteward) {
2465
+ if (alreadySteward) return `${agent.name} (already a steward)`;
2466
+ if (agent.status === "DRAFT") return `${agent.name} (draft, publish before running)`;
2467
+ if (agent.status === "PAUSED") return `${agent.name} (paused, resume before running)`;
2468
+ return agent.name;
2469
+ }
2470
+ /**
2471
+ * The picker's agents, sorted so published agents come first: active, draft
2472
+ * and paused agents only (training, archived and deleted agents cannot become
2473
+ * a steward), each marked when it is already a steward.
2474
+ */
2475
+ function pickableAgents(agents, stewardAgentIds) {
2476
+ const order = (status) => status === "ACTIVE" ? 0 : status === "DRAFT" ? 1 : 2;
2477
+ return agents.filter((a) => PICKABLE_AGENT_STATUSES.has(a.status)).map((agent) => ({
2478
+ agent,
2479
+ alreadySteward: stewardAgentIds.has(agent.id)
2480
+ })).sort((a, b) => Number(a.alreadySteward) - Number(b.alreadySteward) || order(a.agent.status) - order(b.agent.status) || a.agent.name.localeCompare(b.agent.name));
2481
+ }
2482
+ /**
2483
+ * What the desk picker says about desks that use the plan's desk minutes
2484
+ * (browser and cloud), from the plan: `notInPlan` (no assignment), `usedUp`,
2485
+ * `available`, or `unknown` when the viewer may not check the plan.
2486
+ */
2487
+ function cloudDeskAvailability(check) {
2488
+ if (!check) return "unknown";
2489
+ if (check.noLimit) return "available";
2490
+ if (!check.assignmentId) return "notInPlan";
2491
+ if (!check.allowed || check.limitLeft != null && check.limitLeft <= 0) return "usedUp";
2492
+ return "available";
2493
+ }
1748
2494
  /** Parses a non-negative credits value; empty means "no cap". `null` is invalid. */
1749
2495
  function parseCredits(raw) {
1750
2496
  const text = raw.trim();
@@ -1836,7 +2582,12 @@ function CharterFields(p) {
1836
2582
  ] });
1837
2583
  }
1838
2584
  function CreateForm({ agentId, onCreated }) {
1839
- const agents = useStewardsQuery(LIST_AGENT_CANDIDATES, { filters: { status: "ACTIVE" } }, { skip: agentId !== void 0 });
2585
+ const { config } = useStewardsSdk();
2586
+ const agents = useStewardsQuery(LIST_PICKABLE_AGENTS, { pagination: { limit: 100 } }, { skip: agentId !== void 0 });
2587
+ const stewards = useStewardsQuery(LIST_STEWARDS, { pagination: { limit: 100 } }, {
2588
+ skip: agentId !== void 0,
2589
+ silent: true
2590
+ });
1840
2591
  const create = useStewardsMutation(CREATE_STEWARD);
1841
2592
  const [pickedAgent, setPickedAgent] = useState("");
1842
2593
  const [charterText, setCharterText] = useState("");
@@ -1846,8 +2597,21 @@ function CreateForm({ agentId, onCreated }) {
1846
2597
  const [validation, setValidation] = useState();
1847
2598
  const [createdId, setCreatedId] = useState();
1848
2599
  const chosenAgent = agentId ?? pickedAgent;
2600
+ const stewardAgentIds = useMemo(() => new Set((stewards.data?.listBotmanorStewards ?? []).map((st) => st.agentId)), [stewards.data]);
2601
+ const options = useMemo(() => pickableAgents([
2602
+ ...agents.data?.active ?? [],
2603
+ ...agents.data?.draft ?? [],
2604
+ ...agents.data?.paused ?? []
2605
+ ], stewardAgentIds), [agents.data, stewardAgentIds]);
2606
+ const picked = options.find((o) => o.agent.id === chosenAgent)?.agent;
2607
+ const context = useMemo(() => picked ? { agent: {
2608
+ id: picked.id,
2609
+ status: picked.status,
2610
+ ...picked.llmModelId !== void 0 ? { llmModelId: picked.llmModelId } : {}
2611
+ } } : chosenAgent ? { agent: { id: chosenAgent } } : {}, [picked, chosenAgent]);
2612
+ const workspaceId = config.workspaceId;
1849
2613
  const onSubmit = async (e) => {
1850
- e.preventDefault();
2614
+ e?.preventDefault();
1851
2615
  const parsed = parseCredits(credits);
1852
2616
  if (!chosenAgent) return setValidation("Choose an agent.");
1853
2617
  if (charterText.trim() === "") return setValidation("Write the charter first.");
@@ -1870,23 +2634,35 @@ function CreateForm({ agentId, onCreated }) {
1870
2634
  onSubmit: (e) => void onSubmit(e),
1871
2635
  noValidate: true,
1872
2636
  children: [
1873
- agentId ? null : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Field, {
1874
- label: "Agent",
1875
- htmlFor: "steward-agent",
1876
- children: /* @__PURE__ */ jsxs("select", {
1877
- id: "steward-agent",
1878
- value: pickedAgent,
1879
- onChange: (e) => setPickedAgent(e.target.value),
1880
- style: fieldStyle,
1881
- children: [/* @__PURE__ */ jsx("option", {
1882
- value: "",
1883
- children: "Choose an agent…"
1884
- }), (agents.data?.listBotmanorAgents ?? []).map((a) => /* @__PURE__ */ jsx("option", {
1885
- value: a.id,
1886
- children: a.name
1887
- }, a.id))]
2637
+ agentId ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
2638
+ /* @__PURE__ */ jsx(Field, {
2639
+ label: "Agent",
2640
+ htmlFor: "steward-agent",
2641
+ children: /* @__PURE__ */ jsxs("select", {
2642
+ id: "steward-agent",
2643
+ value: pickedAgent,
2644
+ onChange: (e) => setPickedAgent(e.target.value),
2645
+ style: fieldStyle,
2646
+ children: [/* @__PURE__ */ jsx("option", {
2647
+ value: "",
2648
+ children: "Choose an agent…"
2649
+ }), options.map(({ agent, alreadySteward }) => /* @__PURE__ */ jsx("option", {
2650
+ value: agent.id,
2651
+ disabled: alreadySteward,
2652
+ children: agentPickerLabel(agent, alreadySteward)
2653
+ }, agent.id))]
2654
+ })
2655
+ }),
2656
+ agents.data && options.length === 0 ? /* @__PURE__ */ jsx(Muted, { children: "No agent can become a steward yet. Create an agent first, then come back." }) : null,
2657
+ picked ? /* @__PURE__ */ jsx(AgentStateNotice, {
2658
+ agent: picked,
2659
+ onChanged: agents.refetch
2660
+ }) : null,
2661
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2662
+ error: agents.error,
2663
+ onRetry: agents.refetch
1888
2664
  })
1889
- }), /* @__PURE__ */ jsx(ErrorNote, { error: agents.error })] }),
2665
+ ] }),
1890
2666
  /* @__PURE__ */ jsx(CharterFields, {
1891
2667
  idPrefix: "create",
1892
2668
  charterText,
@@ -1910,8 +2686,18 @@ function CreateForm({ agentId, onCreated }) {
1910
2686
  }, d))
1911
2687
  })
1912
2688
  }),
2689
+ desk === "CLOUD" || desk === "BROWSER" ? /* @__PURE__ */ jsx(DeskMinutesHint, {
2690
+ workspaceId,
2691
+ desk,
2692
+ onChooseDesk: setDesk
2693
+ }) : null,
1913
2694
  validation ? /* @__PURE__ */ jsx(ErrorNote, { error: new Error(validation) }) : null,
1914
- /* @__PURE__ */ jsx(ErrorNote, { error: create.error }),
2695
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2696
+ error: create.error,
2697
+ context,
2698
+ onRetry: () => void onSubmit(),
2699
+ onFixed: agents.refetch
2700
+ }),
1915
2701
  /* @__PURE__ */ jsx("p", {
1916
2702
  style: { margin: "16px 0 0" },
1917
2703
  children: /* @__PURE__ */ jsx(Button, {
@@ -1928,7 +2714,11 @@ function EditForm({ stewardId, onSaved }) {
1928
2714
  const steward = useStewardsQuery(GET_STEWARD, { id: stewardId });
1929
2715
  const detail = steward.data?.getBotmanorSteward;
1930
2716
  if (steward.loading && !detail) return /* @__PURE__ */ jsx(Muted, { children: "Loading the charter…" });
1931
- if (!detail?.charter) return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ErrorNote, { error: steward.error }), steward.error ? null : /* @__PURE__ */ jsx(Muted, { children: "This steward was not found." })] });
2717
+ if (!detail?.charter) return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(GuidedErrorNote, {
2718
+ error: steward.error,
2719
+ context: { stewardId },
2720
+ onRetry: steward.refetch
2721
+ }), steward.error ? null : /* @__PURE__ */ jsx(Muted, { children: "This steward was not found." })] });
1932
2722
  return /* @__PURE__ */ jsx(EditCharter, {
1933
2723
  detail,
1934
2724
  onSaved,
@@ -1950,9 +2740,10 @@ function EditCharter({ detail, onSaved, onReload, reloading, reloadError }) {
1950
2740
  const [validation, setValidation] = useState();
1951
2741
  const [saved, setSaved] = useState(false);
1952
2742
  const [conflict, setConflict] = useState(false);
1953
- if (update.error instanceof StewardsRequestError && update.error.code === "CONFLICT" && !conflict) setConflict(true);
2743
+ const refusedAsStale = update.error instanceof StewardsRequestError && update.error.code === "CONFLICT";
2744
+ if (refusedAsStale && !conflict) setConflict(true);
1954
2745
  const onSubmit = async (e) => {
1955
- e.preventDefault();
2746
+ e?.preventDefault();
1956
2747
  const parsed = parseCredits(credits);
1957
2748
  if (charterText.trim() === "") return setValidation("The charter cannot be empty.");
1958
2749
  if (parsed === null) return setValidation("The daily budget must be a number, 0 or more.");
@@ -2009,12 +2800,20 @@ function EditCharter({ detail, onSaved, onReload, reloading, reloadError }) {
2009
2800
  }
2010
2801
  }),
2011
2802
  validation ? /* @__PURE__ */ jsx(ErrorNote, { error: new Error(validation) }) : null,
2012
- /* @__PURE__ */ jsx(ErrorNote, { error: update.error }),
2803
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2804
+ error: refusedAsStale ? void 0 : update.error,
2805
+ context: {
2806
+ stewardId: detail.id,
2807
+ stewardStatus: detail.status,
2808
+ ownerActorId: detail.ownerActorId
2809
+ },
2810
+ ...isDefiniteRefusal(update.error) ? { onRetry: () => void onSubmit() } : {}
2811
+ }),
2013
2812
  conflict ? /* @__PURE__ */ jsxs("div", {
2014
2813
  style: { margin: "8px 0 0" },
2015
2814
  children: [
2016
2815
  /* @__PURE__ */ jsx(Muted, { children: "This charter was changed elsewhere. Reload it to edit the latest version; your unsaved changes here are discarded." }),
2017
- /* @__PURE__ */ jsx(ErrorNote, { error: reloadError }),
2816
+ /* @__PURE__ */ jsx(GuidedErrorNote, { error: reloadError }),
2018
2817
  /* @__PURE__ */ jsx(Button, {
2019
2818
  type: "button",
2020
2819
  onClick: onReload,
@@ -2036,6 +2835,59 @@ function EditCharter({ detail, onSaved, onReload, reloading, reloadError }) {
2036
2835
  })
2037
2836
  });
2038
2837
  }
2838
+ /**
2839
+ * What a draft or paused agent needs before its steward can run (catalog A1
2840
+ * prevention): publish it here when the viewer may, choose a model first when
2841
+ * it has none, or open the agent (or ask its owner) otherwise.
2842
+ */
2843
+ function AgentStateNotice({ agent, onChanged }) {
2844
+ const guided = useMemo(() => agent.status === "ACTIVE" ? void 0 : describeGuidedError({
2845
+ code: "BAD_USER_INPUT",
2846
+ extensions: {
2847
+ reason: "AGENT_NOT_ACTIVE",
2848
+ agentId: agent.id
2849
+ }
2850
+ }, { agent: {
2851
+ id: agent.id,
2852
+ status: agent.status,
2853
+ ...agent.llmModelId !== void 0 ? { llmModelId: agent.llmModelId } : {}
2854
+ } }), [agent]);
2855
+ if (!guided) return null;
2856
+ const state = (AGENT_STATUS_SHORT_LABELS[agent.status] ?? humanize(agent.status)).toLowerCase();
2857
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Muted, { children: `This agent is ${state === "draft" ? "still a draft" : state}. You can create the steward now; it runs once the agent is published.` }), /* @__PURE__ */ jsx(GuidedErrorNote, {
2858
+ guided,
2859
+ tone: "info",
2860
+ onRetry: onChanged
2861
+ })] });
2862
+ }
2863
+ /**
2864
+ * Browser and cloud desks run on BotManor's machines and spend the plan's desk
2865
+ * minutes (a steward on either needs at least one minute left to start). On a
2866
+ * plan without them, or with none left, the hint says so and offers the desks
2867
+ * that use none: the person's own machine, or no desk.
2868
+ */
2869
+ function DeskMinutesHint({ workspaceId, desk, onChooseDesk }) {
2870
+ const availability = cloudDeskAvailability(useStewardsQuery(CHECK_DESK_MINUTES, { workspaceId }, { silent: true }).data?.checkWorkspaceQuota);
2871
+ const kind = desk === "CLOUD" ? "cloud" : "browser";
2872
+ const message = availability === "notInPlan" ? `Desk minutes aren't part of this workspace's plan, so a steward on a ${kind} desk can't run. Choose your own machine instead, or no desk.` : availability === "usedUp" ? `This workspace's plan has no desk minutes left this month, so a steward on a ${kind} desk can't run now. Choose your own machine instead, or no desk.` : `A ${kind} desk uses the plan's desk minutes. If the plan has none, choose your own machine instead.`;
2873
+ return /* @__PURE__ */ jsxs("div", {
2874
+ role: "status",
2875
+ children: [/* @__PURE__ */ jsx(Muted, { children: message }), availability === "notInPlan" || availability === "usedUp" ? /* @__PURE__ */ jsxs("p", {
2876
+ style: {
2877
+ display: "flex",
2878
+ gap: "8px",
2879
+ margin: "8px 0 0"
2880
+ },
2881
+ children: [/* @__PURE__ */ jsx(Button, {
2882
+ onClick: () => onChooseDesk("OWN_MACHINE"),
2883
+ children: "Use my own machine"
2884
+ }), /* @__PURE__ */ jsx(Button, {
2885
+ onClick: () => onChooseDesk("NONE"),
2886
+ children: "No desk"
2887
+ })]
2888
+ }) : null]
2889
+ });
2890
+ }
2039
2891
 
2040
2892
  // src/components/ApprovalInbox.tsx
2041
2893
  const SCOPES = [
@@ -2101,7 +2953,14 @@ function ApprovalInbox({ stewardId, pollIntervalMs = 15e3 }) {
2101
2953
  children: "Approvals"
2102
2954
  }),
2103
2955
  loading && !approvals ? /* @__PURE__ */ jsx(Muted, { children: "Loading approvals…" }) : null,
2104
- /* @__PURE__ */ jsx(ErrorNote, { error: error ?? decide.error }),
2956
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2957
+ error,
2958
+ onRetry: refetch
2959
+ }),
2960
+ /* @__PURE__ */ jsx(GuidedErrorNote, {
2961
+ error: error ? void 0 : decide.error,
2962
+ ...isStaleStateError(decide.error) ? { onRetry: refetch } : {}
2963
+ }),
2105
2964
  approvals && approvals.length === 0 ? /* @__PURE__ */ jsx(Muted, { children: "Nothing is waiting for your approval." }) : null,
2106
2965
  approvals && approvals.length > 0 ? /* @__PURE__ */ jsx("ul", {
2107
2966
  style: listStyle,
@@ -2167,4 +3026,4 @@ function ApprovalInbox({ stewardId, pollIntervalMs = 15e3 }) {
2167
3026
  });
2168
3027
  }
2169
3028
 
2170
- 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 };
3029
+ export { AGENT_STATUS_LABELS, AGENT_STATUS_SHORT_LABELS, ApprovalInbox, DEFAULT_BOTMANOR_APP_URL, DEFAULT_STEWARDS_THEME, DEFAULT_VIBECONTROLS_URL, GUIDED_ENTRIES, GUIDED_PERMISSIONS, GuidedErrorNote, OWN_MACHINE_GRANT_DAYS, OWN_MACHINE_MAX_PAGES, OWN_MACHINE_PAGE_SIZE, PERMISSION_LABELS, STOP_REASON_LABELS, StewardBuilder, StewardConsole, StewardOwnMachineDesk, StewardOwnMachineDeskPanel, StewardRunView, StewardsRequestError, StewardsSdkProvider, agentPickerLabel, botmanorPath, buildGuidedError, cloudDeskAvailability, createStewardsEventBus, crossShellUrl, describeGuidedError, describeRunFailure, englishGuidedTranslate, extractGuidedSource, fillGuidedParams, guidedI18nBase, guidedParams, guidedText, guidedTranslateFrom, isDefiniteRefusal, isStaleStateError, nextOwnMachineGrantExpiry, ownMachineAbilities, ownMachineAllowedApps, ownMachineAppCount, ownMachineGrantExpiry, ownMachineRows, permissionLabelKey, pickableAgents, planGuidedActions, reasonCamel, resolveGuidedLocation, stepReasonCode, stopReasonLabel, themeToStyle, useStewardsEvent, useStewardsSdk };