@stigmer/react 3.5.3 → 3.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/agent/AgentPicker.d.ts +10 -1
  2. package/agent/AgentPicker.d.ts.map +1 -1
  3. package/agent/AgentPicker.js +2 -2
  4. package/agent/AgentPicker.js.map +1 -1
  5. package/billing/CreditLedgerTable.d.ts.map +1 -1
  6. package/billing/CreditLedgerTable.js +2 -7
  7. package/billing/CreditLedgerTable.js.map +1 -1
  8. package/channel/AgentChannelsPanel.d.ts.map +1 -1
  9. package/channel/AgentChannelsPanel.js +22 -5
  10. package/channel/AgentChannelsPanel.js.map +1 -1
  11. package/channel/ChannelTemplatesDialog.d.ts +53 -0
  12. package/channel/ChannelTemplatesDialog.d.ts.map +1 -0
  13. package/channel/ChannelTemplatesDialog.js +150 -0
  14. package/channel/ChannelTemplatesDialog.js.map +1 -0
  15. package/channel/index.d.ts +8 -0
  16. package/channel/index.d.ts.map +1 -1
  17. package/channel/index.js +4 -0
  18. package/channel/index.js.map +1 -1
  19. package/channel/providers.d.ts +12 -0
  20. package/channel/providers.d.ts.map +1 -1
  21. package/channel/providers.js +14 -2
  22. package/channel/providers.js.map +1 -1
  23. package/channel/templatePresentation.d.ts +37 -0
  24. package/channel/templatePresentation.d.ts.map +1 -0
  25. package/channel/templatePresentation.js +69 -0
  26. package/channel/templatePresentation.js.map +1 -0
  27. package/channel/useChannelTemplateList.d.ts +64 -0
  28. package/channel/useChannelTemplateList.d.ts.map +1 -0
  29. package/channel/useChannelTemplateList.js +69 -0
  30. package/channel/useChannelTemplateList.js.map +1 -0
  31. package/channel/useChannelTemplateReadiness.d.ts +53 -0
  32. package/channel/useChannelTemplateReadiness.d.ts.map +1 -0
  33. package/channel/useChannelTemplateReadiness.js +42 -0
  34. package/channel/useChannelTemplateReadiness.js.map +1 -0
  35. package/composer/ComposerToolbar.d.ts +6 -1
  36. package/composer/ComposerToolbar.d.ts.map +1 -1
  37. package/composer/ComposerToolbar.js +2 -2
  38. package/composer/ComposerToolbar.js.map +1 -1
  39. package/composer/SessionComposer.d.ts +9 -0
  40. package/composer/SessionComposer.d.ts.map +1 -1
  41. package/composer/SessionComposer.js +13 -2
  42. package/composer/SessionComposer.js.map +1 -1
  43. package/dashboard/useDashboardFailedRuns.d.ts.map +1 -1
  44. package/dashboard/useDashboardFailedRuns.js +2 -0
  45. package/dashboard/useDashboardFailedRuns.js.map +1 -1
  46. package/execution/useCreateAgentExecution.d.ts +14 -0
  47. package/execution/useCreateAgentExecution.d.ts.map +1 -1
  48. package/execution/useCreateAgentExecution.js +5 -0
  49. package/execution/useCreateAgentExecution.js.map +1 -1
  50. package/index.d.ts +4 -2
  51. package/index.d.ts.map +1 -1
  52. package/index.js +10 -1
  53. package/index.js.map +1 -1
  54. package/internal/Pagination.d.ts +15 -0
  55. package/internal/Pagination.d.ts.map +1 -0
  56. package/internal/Pagination.js +20 -0
  57. package/internal/Pagination.js.map +1 -0
  58. package/library/useExportResource.d.ts +4 -3
  59. package/library/useExportResource.d.ts.map +1 -1
  60. package/library/useExportResource.js +1 -1
  61. package/library/useExportResource.js.map +1 -1
  62. package/models/ModelSelector.d.ts +26 -1
  63. package/models/ModelSelector.d.ts.map +1 -1
  64. package/models/ModelSelector.js +27 -6
  65. package/models/ModelSelector.js.map +1 -1
  66. package/models/index.d.ts +2 -0
  67. package/models/index.d.ts.map +1 -1
  68. package/models/index.js +1 -0
  69. package/models/index.js.map +1 -1
  70. package/models/registry.d.ts +10 -0
  71. package/models/registry.d.ts.map +1 -1
  72. package/models/registry.js +3 -0
  73. package/models/registry.js.map +1 -1
  74. package/models/service-tier.d.ts +27 -0
  75. package/models/service-tier.d.ts.map +1 -0
  76. package/models/service-tier.js +34 -0
  77. package/models/service-tier.js.map +1 -0
  78. package/organization/OrgProvider.d.ts +11 -4
  79. package/organization/OrgProvider.d.ts.map +1 -1
  80. package/organization/OrgProvider.js +28 -4
  81. package/organization/OrgProvider.js.map +1 -1
  82. package/package.json +4 -4
  83. package/resource-detail/useDeleteResource.d.ts +1 -1
  84. package/resource-detail/useDeleteResource.d.ts.map +1 -1
  85. package/resource-detail/useDeleteResource.js +5 -0
  86. package/resource-detail/useDeleteResource.js.map +1 -1
  87. package/resource-workbench/components/ResourceWorkbench.d.ts +10 -1
  88. package/resource-workbench/components/ResourceWorkbench.d.ts.map +1 -1
  89. package/resource-workbench/components/ResourceWorkbench.js +6 -2
  90. package/resource-workbench/components/ResourceWorkbench.js.map +1 -1
  91. package/resource-workbench/hooks/useResourceCollection.d.ts +8 -0
  92. package/resource-workbench/hooks/useResourceCollection.d.ts.map +1 -1
  93. package/resource-workbench/hooks/useResourceCollection.js +2 -2
  94. package/resource-workbench/hooks/useResourceCollection.js.map +1 -1
  95. package/schedule/CadenceField.d.ts +31 -0
  96. package/schedule/CadenceField.d.ts.map +1 -0
  97. package/schedule/CadenceField.js +116 -0
  98. package/schedule/CadenceField.js.map +1 -0
  99. package/schedule/ScheduleDetailView.d.ts +81 -0
  100. package/schedule/ScheduleDetailView.d.ts.map +1 -0
  101. package/schedule/ScheduleDetailView.js +648 -0
  102. package/schedule/ScheduleDetailView.js.map +1 -0
  103. package/schedule/ScheduleForm.d.ts +46 -0
  104. package/schedule/ScheduleForm.d.ts.map +1 -0
  105. package/schedule/ScheduleForm.js +214 -0
  106. package/schedule/ScheduleForm.js.map +1 -0
  107. package/schedule/ScheduleRowActions.d.ts +20 -0
  108. package/schedule/ScheduleRowActions.d.ts.map +1 -0
  109. package/schedule/ScheduleRowActions.js +54 -0
  110. package/schedule/ScheduleRowActions.js.map +1 -0
  111. package/schedule/ScheduleRunsTable.d.ts +72 -0
  112. package/schedule/ScheduleRunsTable.d.ts.map +1 -0
  113. package/schedule/ScheduleRunsTable.js +161 -0
  114. package/schedule/ScheduleRunsTable.js.map +1 -0
  115. package/schedule/TimeZoneField.d.ts +32 -0
  116. package/schedule/TimeZoneField.d.ts.map +1 -0
  117. package/schedule/TimeZoneField.js +104 -0
  118. package/schedule/TimeZoneField.js.map +1 -0
  119. package/schedule/cadence.d.ts +95 -0
  120. package/schedule/cadence.d.ts.map +1 -0
  121. package/schedule/cadence.js +242 -0
  122. package/schedule/cadence.js.map +1 -0
  123. package/schedule/index.d.ts +37 -0
  124. package/schedule/index.d.ts.map +1 -0
  125. package/schedule/index.js +19 -0
  126. package/schedule/index.js.map +1 -0
  127. package/schedule/scheduleColumns.d.ts +26 -0
  128. package/schedule/scheduleColumns.d.ts.map +1 -0
  129. package/schedule/scheduleColumns.js +77 -0
  130. package/schedule/scheduleColumns.js.map +1 -0
  131. package/schedule/scheduleListFn.d.ts +50 -0
  132. package/schedule/scheduleListFn.d.ts.map +1 -0
  133. package/schedule/scheduleListFn.js +65 -0
  134. package/schedule/scheduleListFn.js.map +1 -0
  135. package/schedule/scheduleState.d.ts +43 -0
  136. package/schedule/scheduleState.d.ts.map +1 -0
  137. package/schedule/scheduleState.js +67 -0
  138. package/schedule/scheduleState.js.map +1 -0
  139. package/schedule/useCreateSchedule.d.ts +57 -0
  140. package/schedule/useCreateSchedule.d.ts.map +1 -0
  141. package/schedule/useCreateSchedule.js +61 -0
  142. package/schedule/useCreateSchedule.js.map +1 -0
  143. package/schedule/useResumeSchedule.d.ts +30 -0
  144. package/schedule/useResumeSchedule.d.ts.map +1 -0
  145. package/schedule/useResumeSchedule.js +45 -0
  146. package/schedule/useResumeSchedule.js.map +1 -0
  147. package/schedule/useSchedule.d.ts +39 -0
  148. package/schedule/useSchedule.d.ts.map +1 -0
  149. package/schedule/useSchedule.js +44 -0
  150. package/schedule/useSchedule.js.map +1 -0
  151. package/schedule/useScheduleCount.d.ts +38 -0
  152. package/schedule/useScheduleCount.d.ts.map +1 -0
  153. package/schedule/useScheduleCount.js +30 -0
  154. package/schedule/useScheduleCount.js.map +1 -0
  155. package/schedule/useScheduleList.d.ts +48 -0
  156. package/schedule/useScheduleList.d.ts.map +1 -0
  157. package/schedule/useScheduleList.js +43 -0
  158. package/schedule/useScheduleList.js.map +1 -0
  159. package/schedule/useScheduleRuns.d.ts +44 -0
  160. package/schedule/useScheduleRuns.d.ts.map +1 -0
  161. package/schedule/useScheduleRuns.js +48 -0
  162. package/schedule/useScheduleRuns.js.map +1 -0
  163. package/schedule/useSetScheduleEnabled.d.ts +31 -0
  164. package/schedule/useSetScheduleEnabled.d.ts.map +1 -0
  165. package/schedule/useSetScheduleEnabled.js +53 -0
  166. package/schedule/useSetScheduleEnabled.js.map +1 -0
  167. package/schedule/useTriggerSchedule.d.ts +41 -0
  168. package/schedule/useTriggerSchedule.d.ts.map +1 -0
  169. package/schedule/useTriggerSchedule.js +62 -0
  170. package/schedule/useTriggerSchedule.js.map +1 -0
  171. package/schedule/useUpdateScheduleSpec.d.ts +49 -0
  172. package/schedule/useUpdateScheduleSpec.d.ts.map +1 -0
  173. package/schedule/useUpdateScheduleSpec.js +70 -0
  174. package/schedule/useUpdateScheduleSpec.js.map +1 -0
  175. package/search/useResourceCount.d.ts +2 -1
  176. package/search/useResourceCount.d.ts.map +1 -1
  177. package/search/useResourceCount.js +6 -1
  178. package/search/useResourceCount.js.map +1 -1
  179. package/session/useNewSessionFlow.d.ts.map +1 -1
  180. package/session/useNewSessionFlow.js +1 -0
  181. package/session/useNewSessionFlow.js.map +1 -1
  182. package/session/useSessionConversation.d.ts +11 -0
  183. package/session/useSessionConversation.d.ts.map +1 -1
  184. package/session/useSessionConversation.js +1 -0
  185. package/session/useSessionConversation.js.map +1 -1
  186. package/session/useSessionPageFlow.d.ts.map +1 -1
  187. package/session/useSessionPageFlow.js +1 -0
  188. package/session/useSessionPageFlow.js.map +1 -1
  189. package/src/agent/AgentPicker.tsx +13 -1
  190. package/src/billing/CreditLedgerTable.tsx +3 -42
  191. package/src/channel/AgentChannelsPanel.tsx +43 -1
  192. package/src/channel/ChannelTemplatesDialog.tsx +433 -0
  193. package/src/channel/__tests__/AgentChannelsPanel.test.tsx +73 -0
  194. package/src/channel/__tests__/ChannelTemplatesDialog.test.tsx +292 -0
  195. package/src/channel/__tests__/providers.test.ts +9 -0
  196. package/src/channel/__tests__/templatePresentation.test.ts +96 -0
  197. package/src/channel/__tests__/useChannelTemplateList.test.tsx +216 -0
  198. package/src/channel/__tests__/useChannelTemplateReadiness.test.tsx +124 -0
  199. package/src/channel/index.ts +15 -0
  200. package/src/channel/providers.ts +26 -2
  201. package/src/channel/templatePresentation.ts +82 -0
  202. package/src/channel/useChannelTemplateList.ts +123 -0
  203. package/src/channel/useChannelTemplateReadiness.ts +69 -0
  204. package/src/composer/ComposerToolbar.tsx +9 -0
  205. package/src/composer/SessionComposer.tsx +24 -1
  206. package/src/composer/__tests__/SessionComposer-serviceTier.test.tsx +156 -0
  207. package/src/dashboard/__tests__/useDashboardFailedRuns.test.tsx +106 -0
  208. package/src/dashboard/useDashboardFailedRuns.ts +2 -0
  209. package/src/execution/useCreateAgentExecution.ts +18 -0
  210. package/src/index.ts +70 -0
  211. package/src/internal/Pagination.tsx +72 -0
  212. package/src/library/useExportResource.ts +4 -3
  213. package/src/models/ModelSelector.tsx +100 -3
  214. package/src/models/__tests__/ModelSelector-serviceTier.test.tsx +172 -0
  215. package/src/models/__tests__/useModelRegistry.test.tsx +15 -0
  216. package/src/models/index.ts +2 -0
  217. package/src/models/registry.ts +16 -0
  218. package/src/models/service-tier.ts +49 -0
  219. package/src/organization/OrgProvider.tsx +29 -4
  220. package/src/organization/__tests__/OrgProvider.orgSwitch.test.tsx +89 -0
  221. package/src/resource-detail/useDeleteResource.ts +11 -1
  222. package/src/resource-workbench/__tests__/ResourceWorkbench.test.tsx +112 -0
  223. package/src/resource-workbench/components/ResourceWorkbench.tsx +32 -15
  224. package/src/resource-workbench/hooks/useResourceCollection.ts +11 -1
  225. package/src/schedule/CadenceField.tsx +365 -0
  226. package/src/schedule/ScheduleDetailView.tsx +1651 -0
  227. package/src/schedule/ScheduleForm.tsx +615 -0
  228. package/src/schedule/ScheduleRowActions.tsx +124 -0
  229. package/src/schedule/ScheduleRunsTable.tsx +424 -0
  230. package/src/schedule/TimeZoneField.tsx +199 -0
  231. package/src/schedule/__tests__/ScheduleDetailView.test.tsx +683 -0
  232. package/src/schedule/__tests__/cadence.test.ts +278 -0
  233. package/src/schedule/__tests__/scheduleColumnsRowActions.test.tsx +176 -0
  234. package/src/schedule/__tests__/scheduleCreation.test.tsx +537 -0
  235. package/src/schedule/__tests__/scheduleHooks.test.tsx +399 -0
  236. package/src/schedule/__tests__/scheduleListFn.test.ts +128 -0
  237. package/src/schedule/__tests__/scheduleState.test.ts +133 -0
  238. package/src/schedule/cadence.ts +298 -0
  239. package/src/schedule/index.ts +69 -0
  240. package/src/schedule/scheduleColumns.tsx +118 -0
  241. package/src/schedule/scheduleListFn.ts +108 -0
  242. package/src/schedule/scheduleState.ts +96 -0
  243. package/src/schedule/useCreateSchedule.ts +88 -0
  244. package/src/schedule/useResumeSchedule.ts +67 -0
  245. package/src/schedule/useSchedule.ts +67 -0
  246. package/src/schedule/useScheduleCount.ts +57 -0
  247. package/src/schedule/useScheduleList.ts +83 -0
  248. package/src/schedule/useScheduleRuns.ts +93 -0
  249. package/src/schedule/useSetScheduleEnabled.ts +84 -0
  250. package/src/schedule/useTriggerSchedule.ts +90 -0
  251. package/src/schedule/useUpdateScheduleSpec.ts +108 -0
  252. package/src/search/__tests__/useResourceCount.test.tsx +89 -0
  253. package/src/search/useResourceCount.ts +8 -2
  254. package/src/session/useNewSessionFlow.ts +1 -0
  255. package/src/session/useSessionConversation.ts +12 -0
  256. package/src/session/useSessionPageFlow.ts +1 -0
  257. package/src/workflow/WorkflowDashboard.tsx +1 -0
  258. package/src/workflow/__tests__/inspector-forms.test.tsx +119 -2
  259. package/src/workflow/inspector/forms/AgentCallForm.tsx +260 -37
  260. package/src/workflow/inspector/tabs/RuntimeTab.tsx +72 -33
  261. package/src/workflow/starter-workflow-yaml.ts +2 -1
  262. package/src/workflow/useWorkflowExecutionList.ts +13 -2
  263. package/styles.css +1 -1
  264. package/workflow/CanvasTransitionEdge.d.ts +1 -1
  265. package/workflow/WorkflowDashboard.d.ts.map +1 -1
  266. package/workflow/WorkflowDashboard.js +1 -0
  267. package/workflow/WorkflowDashboard.js.map +1 -1
  268. package/workflow/inspector/forms/AgentCallForm.d.ts +18 -2
  269. package/workflow/inspector/forms/AgentCallForm.d.ts.map +1 -1
  270. package/workflow/inspector/forms/AgentCallForm.js +87 -9
  271. package/workflow/inspector/forms/AgentCallForm.js.map +1 -1
  272. package/workflow/inspector/tabs/RuntimeTab.d.ts +2 -1
  273. package/workflow/inspector/tabs/RuntimeTab.d.ts.map +1 -1
  274. package/workflow/inspector/tabs/RuntimeTab.js +31 -5
  275. package/workflow/inspector/tabs/RuntimeTab.js.map +1 -1
  276. package/workflow/starter-workflow-yaml.d.ts +1 -1
  277. package/workflow/starter-workflow-yaml.d.ts.map +1 -1
  278. package/workflow/starter-workflow-yaml.js +2 -1
  279. package/workflow/starter-workflow-yaml.js.map +1 -1
  280. package/workflow/useWorkflowExecutionList.d.ts +10 -0
  281. package/workflow/useWorkflowExecutionList.d.ts.map +1 -1
  282. package/workflow/useWorkflowExecutionList.js +3 -2
  283. package/workflow/useWorkflowExecutionList.js.map +1 -1
@@ -0,0 +1,648 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useMemo, useState } from "react";
4
+ import { cn } from "@stigmer/theme";
5
+ import { create } from "@bufbuild/protobuf";
6
+ import { timestampDate } from "@bufbuild/protobuf/wkt";
7
+ import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
8
+ import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
9
+ import { ApiResourceReferenceSchema } from "@stigmer/protos/ai/stigmer/commons/apiresource/io_pb";
10
+ import { formatRelativeTime } from "../activity/format-relative-time.js";
11
+ import { ErrorMessage } from "../error/ErrorMessage.js";
12
+ import { InlineEditTextarea } from "../inline-edit/InlineEditTextarea.js";
13
+ import { EditResourceYamlDialog } from "../manifest/EditResourceYamlDialog.js";
14
+ import { ConfirmDialog } from "../resource-detail/ConfirmDialog.js";
15
+ import { ResourceDetailShell } from "../resource-detail/ResourceDetailShell.js";
16
+ import { Section } from "../resource-detail/Section.js";
17
+ import { useConfirmAction } from "../resource-detail/useConfirmAction.js";
18
+ import { useCopyResource } from "../resource-detail/useCopyResource.js";
19
+ import { useDeleteResource } from "../resource-detail/useDeleteResource.js";
20
+ import { useDetailTabs } from "../resource-detail/useDetailTabs.js";
21
+ import { useExportResource } from "../library/useExportResource.js";
22
+ import { ScheduleRunOutcome } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/io_pb";
23
+ import { RunConfigSchema, } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/invocation_pb";
24
+ import { Harness } from "@stigmer/protos/ai/stigmer/agentic/session/v1/enum_pb";
25
+ import { ServiceTier } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
26
+ import { cadenceToCron, cronToCadence, describeCadence, validateCron, } from "./cadence.js";
27
+ import { CadenceField } from "./CadenceField.js";
28
+ import { EnvironmentPicker } from "../environment/EnvironmentPicker.js";
29
+ import { ModelSelector } from "../models/ModelSelector.js";
30
+ import { HARNESS_META, fromProtoHarness, toProtoHarness, } from "../models/harness.js";
31
+ import { fromProtoServiceTier, toProtoServiceTier, } from "../models/service-tier.js";
32
+ import { deriveScheduleState, formatNextFire } from "./scheduleState.js";
33
+ import { ScheduleRunsCompactList, ScheduleRunsTable, } from "./ScheduleRunsTable.js";
34
+ import { TimeZoneField, browserTimeZone } from "./TimeZoneField.js";
35
+ import { useSchedule } from "./useSchedule.js";
36
+ import { useScheduleRuns } from "./useScheduleRuns.js";
37
+ import { useResumeSchedule } from "./useResumeSchedule.js";
38
+ import { useSetScheduleEnabled } from "./useSetScheduleEnabled.js";
39
+ import { useTriggerSchedule } from "./useTriggerSchedule.js";
40
+ import { useUpdateScheduleSpec } from "./useUpdateScheduleSpec.js";
41
+ const OVERVIEW_TAB_ID = "overview";
42
+ const RUNS_TAB_ID = "runs";
43
+ // The Overview strip shows the newest handful of fires; the Runs tab
44
+ // owns the full paginated history.
45
+ const RECENT_RUNS_OPTIONS = { pageSize: 5 };
46
+ /** invocation.proto pins AgentInvocation.message to 8192 characters. */
47
+ const MESSAGE_MAX_LEN = 8192;
48
+ /**
49
+ * Self-contained detail view for a Schedule (stigmer/stigmer#352),
50
+ * split into an Overview tab (definition + status + recent runs) and a
51
+ * Runs tab (the full paginated fire ledger).
52
+ *
53
+ * The view's one non-negotiable is rendering the two stop-levers
54
+ * distinctly, each with its inline remedy:
55
+ *
56
+ * - **Disabled** (owner's `spec.enabled` switch) — banner with an
57
+ * Enable action (a lossless full-proto re-apply).
58
+ * - **Paused** (platform's failure-streak latch,
59
+ * `status.paused_reason`) — banner showing the reason with a Resume
60
+ * action (the one path that clears the pause).
61
+ *
62
+ * Trigger ("Run now") starts a real, billable execution and is gated
63
+ * behind a confirmation; it is disabled while the schedule cannot fire
64
+ * (the banner names the remedy). With `editable`, the mutable spec
65
+ * fields edit inline; Edit YAML, Export, and Delete round out the
66
+ * action set.
67
+ *
68
+ * Handles loading, error, and not-found states automatically.
69
+ * Zero Console dependencies — safe for platform builder embedding.
70
+ * All visual properties flow through `--stgm-*` design tokens.
71
+ */
72
+ export function ScheduleDetailView({ org, slug, onNavigateToAgent, onNavigateToExecution, onDeleted, onResourceLoad, editable = false, additionalTabs, activeTab, onTabChange, defaultTab, now, className, }) {
73
+ const { schedule, isLoading, error, refetch } = useSchedule(org, slug);
74
+ // The recent-runs fetch stays mounted regardless of the active tab:
75
+ // it feeds the Runs tab badge (total count), the Overview strip, and
76
+ // post-trigger freshness. The Runs tab's full table owns its own
77
+ // paginated fetch inside ScheduleRunsTable.
78
+ const { runs: recentRuns, totalCount: totalRunCount, isLoading: recentRunsLoading, refetch: refetchRecentRuns, } = useScheduleRuns(schedule?.metadata?.id ?? null, RECENT_RUNS_OPTIONS);
79
+ const { resumeSchedule, isResuming } = useResumeSchedule();
80
+ const { triggerSchedule, isTriggering } = useTriggerSchedule();
81
+ const { setEnabled, isPending: isToggling } = useSetScheduleEnabled();
82
+ const { updateSpec, isUpdating } = useUpdateScheduleSpec();
83
+ const { deleteResource, isDeleting } = useDeleteResource("schedule", schedule?.metadata?.id ?? null, schedule?.metadata?.name);
84
+ const { confirmState, confirm, handleConfirm, handleCancel } = useConfirmAction();
85
+ const { copyId, copyQualifiedSlug } = useCopyResource();
86
+ const [editOpen, setEditOpen] = useState(false);
87
+ // Remount key for the Runs tab's table: a manual trigger bumps it so
88
+ // the table refetches and returns to page 1, where the new fire
89
+ // appears (the key-remount reset idiom, DD-014).
90
+ const [runsVersion, setRunsVersion] = useState(0);
91
+ // Last failed inline save, attributed to the field that was edited so
92
+ // only that editor shows the message. The backend's message is the
93
+ // UX (DD-006) — e.g. the cron validator's copy surfaces verbatim.
94
+ const [saveError, setSaveError] = useState(null);
95
+ const saveSpecField = useCallback(async (field, mutate) => {
96
+ if (!schedule)
97
+ return false;
98
+ setSaveError(null);
99
+ try {
100
+ await updateSpec(schedule, mutate);
101
+ refetch();
102
+ return true;
103
+ }
104
+ catch (err) {
105
+ setSaveError({
106
+ field,
107
+ message: err instanceof Error ? err.message : String(err),
108
+ });
109
+ return false;
110
+ }
111
+ }, [schedule, updateSpec, refetch]);
112
+ const builtInTabs = useMemo(() => [
113
+ { id: OVERVIEW_TAB_ID, label: "Overview" },
114
+ {
115
+ id: RUNS_TAB_ID,
116
+ label: "Runs",
117
+ ...(totalRunCount > 0 ? { badge: totalRunCount } : {}),
118
+ },
119
+ ], [totalRunCount]);
120
+ const { effectiveTabs, effectiveActiveTab, effectiveOnTabChange, activeAdditionalTab, } = useDetailTabs({
121
+ builtInTabs,
122
+ additionalTabs,
123
+ activeTab,
124
+ onTabChange,
125
+ defaultTab,
126
+ });
127
+ const { copyYaml, downloadYaml } = useExportResource({
128
+ kind: "Schedule",
129
+ resource: schedule,
130
+ });
131
+ useEffect(() => {
132
+ if (schedule)
133
+ onResourceLoad?.(schedule);
134
+ }, [schedule, onResourceLoad]);
135
+ if (isLoading)
136
+ return _jsx(LoadingSkeleton, { className: className });
137
+ if (error)
138
+ return _jsx(ErrorMessage, { error: error, retry: refetch, className: className });
139
+ if (!schedule)
140
+ return _jsx(NotFoundState, { className: className });
141
+ const meta = schedule.metadata;
142
+ const spec = schedule.spec;
143
+ const status = schedule.status;
144
+ const specAudit = status?.audit?.specAudit;
145
+ const stateInfo = deriveScheduleState(spec, status);
146
+ const renderNow = now ?? new Date();
147
+ const scheduleId = meta?.id ?? "";
148
+ const scheduleOrg = meta?.org || org;
149
+ const target = spec?.target?.case === "agent" ? spec.target.value : undefined;
150
+ const handleResume = async () => {
151
+ await resumeSchedule(scheduleId);
152
+ refetch();
153
+ };
154
+ const handleToggleEnabled = async () => {
155
+ await setEnabled(schedule, !spec?.enabled);
156
+ refetch();
157
+ };
158
+ // One fire: trigger, refresh the schedule and its run history, and — on
159
+ // a started run — hand the execution to the host so it can navigate
160
+ // straight to it (the whole point of the synchronous trigger, DD-017
161
+ // D-6). A refused run resolves too; its reason is toasted by the hook
162
+ // and lands in the run history below.
163
+ const fireNow = async () => {
164
+ const result = await triggerSchedule(scheduleId);
165
+ refetch();
166
+ refetchRecentRuns();
167
+ setRunsVersion((v) => v + 1);
168
+ if (result.outcome === ScheduleRunOutcome.STARTED &&
169
+ result.executionId &&
170
+ onNavigateToExecution) {
171
+ onNavigateToExecution(result.executionId);
172
+ }
173
+ };
174
+ const handleTrigger = async () => {
175
+ const confirmed = await confirm({
176
+ title: "Run this schedule now?",
177
+ description: "This starts a real agent execution immediately, outside the cron " +
178
+ "cadence. The run is recorded in this schedule's run history.",
179
+ confirmLabel: "Start run",
180
+ variant: "default",
181
+ });
182
+ if (!confirmed)
183
+ return;
184
+ await fireNow();
185
+ };
186
+ // A disabled schedule refuses to fire at the server — ScheduleBlueprintAccess
187
+ // requires spec.enabled at the create gate AND the mid-run read (DD-017
188
+ // D-5), so a disabled run would die mid-execution after billing. The
189
+ // staged-disabled test flow the creation form promises is therefore
190
+ // "enable, then fire", and this makes it one click.
191
+ const handleEnableAndRun = async () => {
192
+ const confirmed = await confirm({
193
+ title: "Enable and run this schedule now?",
194
+ description: "This schedule is staged disabled. Enabling it lets it fire on its " +
195
+ "cron cadence going forward, and starts one real run immediately so " +
196
+ "you can see the result. You can disable it again afterwards.",
197
+ confirmLabel: "Enable & run",
198
+ variant: "default",
199
+ });
200
+ if (!confirmed)
201
+ return;
202
+ await setEnabled(schedule, true);
203
+ await fireNow();
204
+ };
205
+ const handleDelete = async () => {
206
+ const confirmed = await confirm({
207
+ title: "Delete this schedule?",
208
+ description: `"${meta?.name ?? slug}" will stop firing and be permanently ` +
209
+ "removed. Past executions are not affected. This cannot be undone.",
210
+ confirmLabel: "Delete",
211
+ variant: "destructive",
212
+ });
213
+ if (!confirmed)
214
+ return;
215
+ await deleteResource();
216
+ onDeleted?.();
217
+ };
218
+ // Disabled → "Enable & run now" (the one-click staged-test flow);
219
+ // active and paused → "Run now" (a paused schedule's owner needs a
220
+ // test fire to verify a fix before resuming — DD-017 D-5).
221
+ const primaryAction = stateInfo.state === "disabled"
222
+ ? {
223
+ id: "enable-and-run",
224
+ label: "Enable & run now",
225
+ onAction: () => void handleEnableAndRun(),
226
+ disabled: isTriggering || isToggling,
227
+ }
228
+ : {
229
+ id: "trigger",
230
+ label: "Run now",
231
+ onAction: () => void handleTrigger(),
232
+ disabled: isTriggering,
233
+ };
234
+ const actions = [
235
+ ...(stateInfo.isPaused
236
+ ? [
237
+ {
238
+ id: "resume",
239
+ label: "Resume schedule",
240
+ onAction: () => void handleResume(),
241
+ disabled: isResuming,
242
+ group: "state",
243
+ },
244
+ ]
245
+ : []),
246
+ {
247
+ id: "toggle-enabled",
248
+ label: spec?.enabled ? "Disable schedule" : "Enable schedule",
249
+ onAction: () => void handleToggleEnabled(),
250
+ disabled: isToggling,
251
+ group: "state",
252
+ },
253
+ {
254
+ id: "copy-id",
255
+ label: "Copy ID",
256
+ onAction: () => void copyId(scheduleId),
257
+ group: "clipboard",
258
+ },
259
+ {
260
+ id: "copy-slug",
261
+ label: "Copy slug",
262
+ onAction: () => void copyQualifiedSlug(org, slug),
263
+ group: "clipboard",
264
+ },
265
+ {
266
+ id: "edit-yaml",
267
+ label: "Edit YAML",
268
+ onAction: () => setEditOpen(true),
269
+ group: "edit",
270
+ },
271
+ {
272
+ id: "copy-yaml",
273
+ label: "Copy YAML",
274
+ onAction: () => void copyYaml(),
275
+ group: "export",
276
+ },
277
+ {
278
+ id: "download-yaml",
279
+ label: "Download YAML",
280
+ onAction: downloadYaml,
281
+ group: "export",
282
+ },
283
+ {
284
+ id: "delete",
285
+ label: "Delete",
286
+ variant: "destructive",
287
+ onAction: () => void handleDelete(),
288
+ disabled: isDeleting,
289
+ group: "danger",
290
+ },
291
+ ];
292
+ const headerMeta = {
293
+ name: meta?.name || meta?.slug || "Untitled",
294
+ id: scheduleId,
295
+ org: meta?.org,
296
+ slug: meta?.slug,
297
+ icon: _jsx(ScheduleIcon, { className: "size-6 text-muted-foreground" }),
298
+ createdAt: specAudit?.createdAt ? timestampDate(specAudit.createdAt) : null,
299
+ updatedAt: specAudit?.updatedAt ? timestampDate(specAudit.updatedAt) : null,
300
+ status: stateInfo.phase,
301
+ statusLabel: stateInfo.label,
302
+ };
303
+ const headerBanner = stateInfo.state === "disabled" ? (_jsxs(StateBanner, { title: "Schedule is disabled", onAction: () => void handleToggleEnabled(), actionLabel: "Enable schedule", actionBusy: isToggling, children: ["This schedule is staged disabled (", _jsx("code", { className: "font-mono", children: "spec.enabled" }), " is off) \u2014 it will not fire on its cron cadence. Use", " ", _jsx("span", { className: "font-medium text-foreground", children: "Enable & run now" }), " ", "to enable it and start one test run, or Enable it here to hand it to the cadence.", stateInfo.isPaused && (_jsxs(_Fragment, { children: [" ", "It is also paused by the platform (", status?.pausedReason, "); after enabling, use Resume to clear the pause."] }))] })) : stateInfo.state === "paused" ? (_jsxs(StateBanner, { title: "Paused by the platform", onAction: () => void handleResume(), actionLabel: "Resume schedule", actionBusy: isResuming, children: [status?.pausedReason, " \u2014 resuming clears the pause and the failure streak. Re-applying the manifest does not."] })) : undefined;
304
+ const overviewContent = (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(Section, { title: "Definition", children: _jsxs("dl", { className: "divide-y divide-border", children: [_jsx(DetailRow, { label: "Cadence", children: editable ? (_jsx(CadenceInlineEditor, { cron: spec?.cron ?? "", timeZone: spec?.timeZone ?? "", onSave: (cron, timeZone) => saveSpecField("cadence", (s) => {
305
+ s.cron = cron;
306
+ s.timeZone = timeZone;
307
+ }), isSaving: isUpdating, error: saveError?.field === "cadence" ? saveError.message : undefined })) : (_jsx(CadenceSummary, { cron: spec?.cron ?? "", timeZone: spec?.timeZone ?? "" })) }), _jsx(DetailRow, { label: "Target agent", children: target?.agentRef ? (_jsx(ReferenceLink, { label: `${target.agentRef.org}/${target.agentRef.slug}`, onNavigate: onNavigateToAgent
308
+ ? () => onNavigateToAgent(target.agentRef.org, target.agentRef.slug)
309
+ : undefined })) : (_jsx("span", { className: "text-sm text-muted-foreground", children: "\u2014" })) }), _jsx(DetailRow, { label: "Message", children: editable && target ? (_jsx(InlineEditTextarea, { value: target.message ?? "", placeholder: "The instruction the agent receives on every fire \u2014 write it for a run with no human present.", onSave: (v) => saveSpecField("message", (s) => {
310
+ if (s.target.case === "agent") {
311
+ s.target.value.message = v.trim();
312
+ }
313
+ }), isSaving: isUpdating, error: saveError?.field === "message" ? saveError.message : undefined, validate: validateMessage })) : (_jsx("p", { className: "whitespace-pre-wrap break-words text-sm text-foreground", children: target?.message || "—" })) }), _jsx(DetailRow, { label: "Environments", children: editable && target ? (_jsx(EnvironmentsInlineEditor, { org: scheduleOrg, refs: target.environmentRefs ?? [], onSave: (refs) => saveSpecField("environments", (s) => {
314
+ if (s.target.case === "agent") {
315
+ s.target.value.environmentRefs = refs.map((r) => create(ApiResourceReferenceSchema, {
316
+ org: r.org,
317
+ slug: r.slug,
318
+ kind: ApiResourceKind.environment,
319
+ }));
320
+ }
321
+ }), isSaving: isUpdating, error: saveError?.field === "environments"
322
+ ? saveError.message
323
+ : undefined })) : (_jsx(EnvironmentRefList, { refs: target?.environmentRefs ?? [] })) }), _jsx(DetailRow, { label: "Workspace", children: _jsx(WorkspaceSummary, { entries: target?.workspaceEntries ?? [] }) }), _jsx(DetailRow, { label: "Engine & model", children: editable && target ? (_jsx(EngineModelInlineEditor, { invocation: target, onSave: (harness, modelName, serviceTier) => saveSpecField("engine-model", (s) => {
324
+ if (s.target.case === "agent") {
325
+ applyEngineModel(s.target.value, harness, modelName, serviceTier);
326
+ }
327
+ }), isSaving: isUpdating, error: saveError?.field === "engine-model"
328
+ ? saveError.message
329
+ : undefined })) : (_jsx(EngineModelSummary, { invocation: target })) }), _jsx(DetailRow, { label: "Budget per run", children: editable && target ? (_jsx(BudgetInlineEditor, { config: target.runConfig, onSave: (maxCostUsd) => saveSpecField("budget", (s) => {
330
+ if (s.target.case === "agent") {
331
+ applyBudget(s.target.value, maxCostUsd);
332
+ }
333
+ }), isSaving: isUpdating, error: saveError?.field === "budget" ? saveError.message : undefined })) : (_jsx(BudgetSummary, { config: target?.runConfig })) })] }) }), _jsx(Section, { title: "Status", children: _jsxs("dl", { className: "divide-y divide-border", children: [_jsx(DetailRow, { label: "Next fire", children: _jsx("span", { className: "text-sm text-foreground", children: stateInfo.state === "active" && status?.nextFireAt
334
+ ? formatNextFire(timestampDate(status.nextFireAt), renderNow)
335
+ : "—" }) }), _jsx(DetailRow, { label: "Last fired", children: _jsx("span", { className: "text-sm text-foreground", children: status?.lastFireAt
336
+ ? formatRelativeTime(timestampDate(status.lastFireAt), renderNow)
337
+ : "Never" }) }), _jsx(DetailRow, { label: "Last execution", children: status?.lastExecutionId ? (_jsx(ReferenceLink, { label: status.lastExecutionId, mono: true, onNavigate: onNavigateToExecution
338
+ ? () => onNavigateToExecution(status.lastExecutionId)
339
+ : undefined })) : (_jsx("span", { className: "text-sm text-muted-foreground", children: "\u2014" })) }), _jsx(DetailRow, { label: "Failure streak", children: _jsx(FailureStreak, { count: status?.consecutiveFailures ?? 0 }) })] }) }), _jsx(Section, { title: "Recent runs", headerActions: totalRunCount > recentRuns.length ? (_jsxs("button", { type: "button", onClick: () => effectiveOnTabChange(RUNS_TAB_ID), className: cn("text-xs font-medium text-primary underline-offset-2 hover:underline", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm"), children: ["View all ", totalRunCount, " runs"] })) : undefined, children: _jsx(ScheduleRunsCompactList, { runs: recentRuns, isLoading: recentRunsLoading, now: renderNow, onNavigateToExecution: onNavigateToExecution }) })] }));
340
+ let tabContent;
341
+ if (activeAdditionalTab) {
342
+ tabContent = activeAdditionalTab.content;
343
+ }
344
+ else if (effectiveActiveTab === RUNS_TAB_ID) {
345
+ tabContent = (_jsx(ScheduleRunsTable, { scheduleId: scheduleId, now: now, onNavigateToExecution: onNavigateToExecution }, runsVersion));
346
+ }
347
+ else {
348
+ tabContent = overviewContent;
349
+ }
350
+ return (_jsxs(_Fragment, { children: [_jsx(ResourceDetailShell, { header: headerMeta, headerBanner: headerBanner, primaryAction: primaryAction, actions: actions, tabs: effectiveTabs, activeTab: effectiveTabs ? effectiveActiveTab : undefined, onTabChange: effectiveTabs ? effectiveOnTabChange : undefined, tabsAriaLabel: "Schedule detail sections", className: className, children: tabContent }), _jsx(ConfirmDialog, { state: confirmState, onConfirm: handleConfirm, onCancel: handleCancel }), editOpen && (_jsx(EditResourceYamlDialog, { open: editOpen, onOpenChange: setEditOpen, resource: schedule, onApplied: () => refetch() }))] }));
351
+ }
352
+ // ---------------------------------------------------------------------------
353
+ // State banner — one lever, one remedy, inline
354
+ // ---------------------------------------------------------------------------
355
+ function StateBanner({ title, children, actionLabel, onAction, actionBusy, }) {
356
+ return (_jsxs("div", { role: "status", className: "flex items-start gap-2.5 rounded-lg border border-warning/30 bg-warning/5 px-4 py-3", children: [_jsx(WarningIcon, { className: "mt-0.5 size-4 shrink-0 text-warning" }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("p", { className: "text-sm font-medium text-foreground", children: title }), _jsx("p", { className: "mt-0.5 text-xs text-muted-foreground", children: children })] }), _jsx("button", { type: "button", onClick: onAction, disabled: actionBusy, className: cn("shrink-0 rounded-md border border-input bg-background px-3 py-1.5 text-xs font-medium text-foreground", "hover:bg-accent hover:text-accent-foreground", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50"), children: actionLabel })] }));
357
+ }
358
+ // ---------------------------------------------------------------------------
359
+ // Cadence summary — plain English first, raw cron as the precise record
360
+ // ---------------------------------------------------------------------------
361
+ /**
362
+ * Render a schedule's cadence for reading: the plain-English sentence
363
+ * first ("Every day at 09:00 (Asia/Kolkata)"), the raw cron beneath it
364
+ * in muted mono as the precise record.
365
+ *
366
+ * `cronToCadence` RECOGNIZES rather than parses (the platform owns no
367
+ * cron parser in either edition — see cadence.ts): expressions outside
368
+ * the builder's shapes come back as `custom`, for which the raw cron IS
369
+ * the primary display, with the time zone alongside so nothing the
370
+ * spec stores is hidden.
371
+ */
372
+ function CadenceSummary({ cron, timeZone, }) {
373
+ if (!cron)
374
+ return _jsx("span", { className: "text-sm text-muted-foreground", children: "\u2014" });
375
+ const preset = cronToCadence(cron);
376
+ if (preset.kind === "custom") {
377
+ return (_jsxs("div", { className: "flex flex-col gap-0.5", children: [_jsx("code", { className: "font-mono text-sm text-foreground", children: cron }), timeZone && (_jsx("span", { className: "text-xs text-muted-foreground", children: timeZone }))] }));
378
+ }
379
+ return (_jsxs("div", { className: "flex flex-col gap-0.5", children: [_jsx("span", { className: "text-sm text-foreground", children: describeCadence(preset, timeZone || undefined) }), _jsx("code", { className: "font-mono text-xs text-muted-foreground", children: cron })] }));
380
+ }
381
+ // ---------------------------------------------------------------------------
382
+ // Inline editors — per-field click-to-edit over the lossless write path
383
+ // ---------------------------------------------------------------------------
384
+ //
385
+ // Each editor follows the InlineEdit* family's contract: read mode is a
386
+ // click target with a hover pencil; edit mode holds a local draft with
387
+ // explicit Save/Cancel; a failed save keeps the editor open with the
388
+ // server's message rendered verbatim beneath it (DD-006). The editors
389
+ // stay in this file (the AgentDetailView single-organism precedent) and
390
+ // reuse the creation form's field components — CadenceField,
391
+ // TimeZoneField, EnvironmentPicker — so creating and editing a schedule
392
+ // are the same experience.
393
+ /** Cadence + time zone edit in one panel — they form one sentence. */
394
+ function CadenceInlineEditor({ cron, timeZone, onSave, isSaving, error, }) {
395
+ const [isEditing, setIsEditing] = useState(false);
396
+ const [draftCadence, setDraftCadence] = useState(() => cronToCadence(cron));
397
+ const [draftZone, setDraftZone] = useState(timeZone);
398
+ const startEdit = () => {
399
+ // cronToCadence round-trips the stored cron into the preset picker;
400
+ // unrecognized shapes land on the Custom escape hatch with the raw
401
+ // string intact.
402
+ setDraftCadence(cronToCadence(cron));
403
+ setDraftZone(timeZone || browserTimeZone());
404
+ setIsEditing(true);
405
+ };
406
+ if (!isEditing) {
407
+ return (_jsx(InlineReadButton, { onEdit: startEdit, ariaLabel: "Edit cadence", children: _jsx(CadenceSummary, { cron: cron, timeZone: timeZone }) }));
408
+ }
409
+ const draftCron = cadenceToCron(draftCadence).trim();
410
+ const canSave = draftCron !== "" && validateCron(draftCron) === null;
411
+ return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(CadenceField, { value: draftCadence, onChange: setDraftCadence, timeZone: draftZone, disabled: isSaving }), _jsxs("div", { className: "space-y-1", children: [_jsx("span", { className: editorLabelClasses, children: "Time zone" }), _jsx(TimeZoneField, { value: draftZone, onChange: setDraftZone, disabled: isSaving })] }), _jsx(InlineEditActions, { onCancel: () => setIsEditing(false), onSave: async () => {
412
+ const ok = await onSave(draftCron, draftZone);
413
+ if (ok)
414
+ setIsEditing(false);
415
+ }, isSaving: isSaving, canSave: canSave, error: error })] }));
416
+ }
417
+ /** Environment bindings edit — org-shared credentials only (DD-017 D-2). */
418
+ function EnvironmentsInlineEditor({ org, refs, onSave, isSaving, error, }) {
419
+ const [isEditing, setIsEditing] = useState(false);
420
+ const [draft, setDraft] = useState([]);
421
+ const startEdit = () => {
422
+ setDraft(refs.map((r) => ({ org: r.org, slug: r.slug })));
423
+ setIsEditing(true);
424
+ };
425
+ if (!isEditing) {
426
+ return (_jsx(InlineReadButton, { onEdit: startEdit, ariaLabel: "Edit environments", children: _jsx(EnvironmentRefList, { refs: refs }) }));
427
+ }
428
+ return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(EnvironmentPicker, { org: org, value: draft, onChange: setDraft, disabled: isSaving,
429
+ // Only org-shared environments resolve for a schedule fire (the
430
+ // same credential surface a channel binding uses), so offering
431
+ // anything else could only produce refused runs.
432
+ filterEnvironment: isOrgSharedEnvironment }), _jsx("p", { className: "text-[0.65rem] text-muted-foreground", children: "Bind org-shared credentials so the agent\u2019s tools work on an unattended fire. Without this, an agent whose tools need credentials will be refused every run." }), _jsx(InlineEditActions, { onCancel: () => setIsEditing(false), onSave: async () => {
433
+ const ok = await onSave(draft);
434
+ if (ok)
435
+ setIsEditing(false);
436
+ }, isSaving: isSaving, canSave: true, error: error })] }));
437
+ }
438
+ function isOrgSharedEnvironment(env) {
439
+ return env.metadata?.visibility === ApiResourceVisibility.visibility_org;
440
+ }
441
+ /**
442
+ * Engine & model edit — the composer's own picker, with the creation
443
+ * form's atomic semantics (DD-018 D-5): picking a model pins BOTH the
444
+ * harness and the model (the registry scopes models per harness);
445
+ * clearing the model unpins both, and the platform defaults apply.
446
+ */
447
+ function EngineModelInlineEditor({ invocation, onSave, isSaving, error, }) {
448
+ const [isEditing, setIsEditing] = useState(false);
449
+ const [modelName, setModelName] = useState("");
450
+ const [harness, setHarness] = useState("cursor");
451
+ const [serviceTier, setServiceTier] = useState("standard");
452
+ const startEdit = () => {
453
+ setModelName(invocation.runConfig?.modelName ?? "");
454
+ setHarness(invocation.harness !== Harness.UNSPECIFIED
455
+ ? fromProtoHarness(invocation.harness)
456
+ : "cursor");
457
+ setServiceTier(fromProtoServiceTier(invocation.runConfig?.serviceTier) ?? "standard");
458
+ setIsEditing(true);
459
+ };
460
+ if (!isEditing) {
461
+ return (_jsx(InlineReadButton, { onEdit: startEdit, ariaLabel: "Edit engine and model", children: _jsx(EngineModelSummary, { invocation: invocation }) }));
462
+ }
463
+ return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(ModelSelector, { value: modelName, onValueChange: setModelName, initialHarness: harness, onHarnessChange: setHarness, serviceTier: serviceTier, onServiceTierChange: setServiceTier, placeholderLabel: "Platform default", disabled: isSaving }), modelName !== "" && (_jsx("button", { type: "button", onClick: () => {
464
+ setModelName("");
465
+ setServiceTier("standard");
466
+ }, disabled: isSaving, className: "rounded-md px-2 py-1 text-[0.65rem] text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50", children: "Reset to platform default" }))] }), _jsx("p", { className: "text-[0.65rem] text-muted-foreground", children: "Runs use the platform\u2019s default engine and model unless you pick one here. Picking a model pins the engine it belongs to." }), _jsx(InlineEditActions, { onCancel: () => setIsEditing(false), onSave: async () => {
467
+ const ok = await onSave(modelName !== "" ? toProtoHarness(harness) : Harness.UNSPECIFIED, modelName, serviceTier);
468
+ if (ok)
469
+ setIsEditing(false);
470
+ }, isSaving: isSaving, canSave: true, error: error })] }));
471
+ }
472
+ /** Budget edit — blank inherits the platform default (DD-018 D-2). */
473
+ function BudgetInlineEditor({ config, onSave, isSaving, error, }) {
474
+ const [isEditing, setIsEditing] = useState(false);
475
+ const [budgetUsd, setBudgetUsd] = useState("");
476
+ const startEdit = () => {
477
+ setBudgetUsd(config && config.maxCostUsd > 0 ? String(config.maxCostUsd) : "");
478
+ setIsEditing(true);
479
+ };
480
+ if (!isEditing) {
481
+ return (_jsx(InlineReadButton, { onEdit: startEdit, ariaLabel: "Edit budget", children: _jsx(BudgetSummary, { config: config }) }));
482
+ }
483
+ const cost = Number.parseFloat(budgetUsd);
484
+ const parsedBudget = Number.isFinite(cost) && cost > 0 ? cost : undefined;
485
+ return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("input", { type: "number", min: "0", step: "any", "aria-label": "Budget per run (USD)", value: budgetUsd, onChange: (e) => setBudgetUsd(e.target.value), placeholder: "platform default", disabled: isSaving, className: cn(editorInputClasses, "sm:max-w-48") }), _jsx("p", { className: "text-[0.65rem] text-muted-foreground", children: "Each run stops when it reaches this spend. You can lower the platform\u2019s per-run cap, never raise it past the platform\u2019s ceiling. Blank inherits the platform default." }), _jsx(InlineEditActions, { onCancel: () => setIsEditing(false), onSave: async () => {
486
+ const ok = await onSave(parsedBudget);
487
+ if (ok)
488
+ setIsEditing(false);
489
+ }, isSaving: isSaving, canSave: true, error: error })] }));
490
+ }
491
+ /**
492
+ * Write the engine+model choice onto the invocation, preserving the
493
+ * run-config fields the editor does not own (budget; the API-only tool
494
+ * rounds), and dropping an all-empty run_config — the proto's "empty =
495
+ * inherit" contract (DD-017 D-3 as carried into DD-018 D-2).
496
+ */
497
+ function applyEngineModel(invocation, harness, modelName, serviceTier) {
498
+ invocation.harness = harness;
499
+ invocation.runConfig = normalizeRunConfig(modelName, invocation.runConfig?.maxCostUsd ?? 0, invocation.runConfig?.maxToolRounds ?? 0,
500
+ // The tier rides the model choice: no model, no tier (#357).
501
+ modelName.trim() !== "" ? serviceTier : "standard");
502
+ }
503
+ /** Budget twin of {@link applyEngineModel} — writes only the cost cap. */
504
+ function applyBudget(invocation, maxCostUsd) {
505
+ invocation.runConfig = normalizeRunConfig(invocation.runConfig?.modelName ?? "", maxCostUsd ?? 0, invocation.runConfig?.maxToolRounds ?? 0, fromProtoServiceTier(invocation.runConfig?.serviceTier) ?? "standard");
506
+ }
507
+ function normalizeRunConfig(modelName, maxCostUsd, maxToolRounds, serviceTier) {
508
+ const fields = {};
509
+ if (modelName.trim() !== "")
510
+ fields.modelName = modelName.trim();
511
+ if (maxCostUsd > 0)
512
+ fields.maxCostUsd = maxCostUsd;
513
+ if (maxToolRounds > 0)
514
+ fields.maxToolRounds = maxToolRounds;
515
+ // Only an active fast choice is carried — an untouched toggle stays
516
+ // absent, preserving the unspecified-vs-explicit ledger distinction (#357).
517
+ if (serviceTier === "fast")
518
+ fields.serviceTier = toProtoServiceTier(serviceTier);
519
+ return Object.keys(fields).length > 0
520
+ ? create(RunConfigSchema, fields)
521
+ : undefined;
522
+ }
523
+ /** Mirrors the server's constraint so the editor rejects bad input instantly. */
524
+ function validateMessage(value) {
525
+ if (!value.trim()) {
526
+ return "Message is required — the agent receives it on every fire.";
527
+ }
528
+ if (value.length > MESSAGE_MAX_LEN) {
529
+ return `Message must be at most ${MESSAGE_MAX_LEN} characters.`;
530
+ }
531
+ return null;
532
+ }
533
+ // ---------------------------------------------------------------------------
534
+ // Inline-edit chrome shared by the bespoke editors above
535
+ // ---------------------------------------------------------------------------
536
+ const editorLabelClasses = "block text-xs font-medium text-foreground";
537
+ const editorInputClasses = cn("w-full rounded-md border border-input bg-background px-2.5 py-1.5 text-xs text-foreground", "placeholder:text-muted-foreground", "focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring", "disabled:pointer-events-none disabled:opacity-50");
538
+ /** Read-mode click target with the family's hover pencil. */
539
+ function InlineReadButton({ onEdit, ariaLabel, children, }) {
540
+ return (_jsx("div", { className: "group/inline-edit", children: _jsx("button", { type: "button", onClick: onEdit, "aria-label": ariaLabel, className: cn("-mx-2 w-full rounded-md px-2 py-1.5 text-left transition-colors", "hover:bg-accent-hover cursor-pointer", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"), children: _jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: children }), _jsx(PencilIcon, { className: "mt-0.5 size-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover/inline-edit:opacity-100" })] }) }) }));
541
+ }
542
+ /** Save/Cancel footer with the field-attributed error line. */
543
+ function InlineEditActions({ onCancel, onSave, isSaving, canSave, error, }) {
544
+ return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs("div", { className: "flex items-center justify-end gap-1.5", children: [_jsx("button", { type: "button", onClick: onCancel, disabled: isSaving, className: cn("rounded-md px-2.5 py-1 text-xs font-medium", "border border-border bg-background text-foreground hover:bg-accent hover:text-accent-foreground", "disabled:opacity-50", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"), children: "Cancel" }), _jsxs("button", { type: "button", onClick: onSave, disabled: !canSave || isSaving, className: cn("inline-flex items-center gap-1 rounded-md px-2.5 py-1 text-xs font-medium", "bg-primary text-primary-foreground hover:bg-primary-hover", "disabled:pointer-events-none disabled:opacity-50", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"), children: [isSaving && _jsx(SpinnerIcon, {}), "Save"] })] }), error && (_jsx("p", { className: "text-xs text-destructive", role: "alert", children: error }))] }));
545
+ }
546
+ // ---------------------------------------------------------------------------
547
+ // Detail rows and references
548
+ // ---------------------------------------------------------------------------
549
+ function DetailRow({ label, children, }) {
550
+ return (_jsxs("div", { className: "flex items-start gap-4 px-4 py-2.5", children: [_jsx("dt", { className: "w-40 shrink-0 pt-0.5 text-xs font-medium text-muted-foreground", children: label }), _jsx("dd", { className: "min-w-0 flex-1", children: children })] }));
551
+ }
552
+ /** The bound environment references, or the em-dash when there are none. */
553
+ function EnvironmentRefList({ refs, }) {
554
+ if (refs.length === 0) {
555
+ return _jsx("span", { className: "text-sm text-muted-foreground", children: "\u2014" });
556
+ }
557
+ return (_jsx("ul", { className: "flex flex-col gap-0.5", children: refs.map((ref, i) => (_jsx("li", { className: "font-mono text-xs text-foreground", children: ref.org ? `${ref.org}/${ref.slug}` : ref.slug }, `${ref.org}/${ref.slug}-${i}`))) }));
558
+ }
559
+ // ---------------------------------------------------------------------------
560
+ // Failure streak — status.consecutive_failures, explained
561
+ // ---------------------------------------------------------------------------
562
+ /**
563
+ * The platform's failure streak: how many SCHEDULED runs in a row ended
564
+ * badly. The server increments it per failed cron fire, resets it on a
565
+ * successful run (or Resume), and auto-pauses the schedule when the
566
+ * streak crosses its threshold. Manual "Run now" fires never count.
567
+ *
568
+ * The threshold itself is server configuration not exposed through the
569
+ * API, so the copy stays qualitative — a hardcoded "of 5" here could
570
+ * silently drift from what the platform actually enforces.
571
+ */
572
+ function FailureStreak({ count }) {
573
+ if (count === 0) {
574
+ return _jsx("span", { className: "text-sm text-foreground", children: "0" });
575
+ }
576
+ return (_jsxs("div", { className: "flex flex-col gap-0.5", children: [_jsxs("span", { className: "text-sm font-medium text-warning", children: [count, " consecutive failed ", count === 1 ? "run" : "runs"] }), _jsx("p", { className: "text-xs text-muted-foreground", children: "Failed scheduled runs raise this streak; too many in a row and the platform pauses the schedule automatically. One successful run resets it to 0. Manual runs never count." })] }));
577
+ }
578
+ // ---------------------------------------------------------------------------
579
+ // The invocation's run shape — engine+model, budget, workspace summaries
580
+ // ---------------------------------------------------------------------------
581
+ /** "Cursor · composer-2.5", either half falling back to the platform default. */
582
+ function EngineModelSummary({ invocation, }) {
583
+ const harness = invocation?.harness ?? Harness.UNSPECIFIED;
584
+ const modelName = invocation?.runConfig?.modelName ?? "";
585
+ if (harness === Harness.UNSPECIFIED && modelName === "") {
586
+ return (_jsx("span", { className: "text-sm text-muted-foreground", children: "Platform default" }));
587
+ }
588
+ const parts = [];
589
+ if (harness !== Harness.UNSPECIFIED) {
590
+ parts.push(HARNESS_META[fromProtoHarness(harness)].label);
591
+ }
592
+ parts.push(modelName !== "" ? modelName : "platform-default model");
593
+ if (invocation?.runConfig?.serviceTier === ServiceTier.FAST) {
594
+ parts.push("Fast tier");
595
+ }
596
+ return _jsx("span", { className: "text-sm text-foreground", children: parts.join(" · ") });
597
+ }
598
+ /** The per-run cost cap, plus the API-only tool-round bound when set. */
599
+ function BudgetSummary({ config, }) {
600
+ const maxCostUsd = config?.maxCostUsd ?? 0;
601
+ const maxToolRounds = config?.maxToolRounds ?? 0;
602
+ return (_jsxs("div", { className: "flex flex-col gap-0.5", children: [maxCostUsd > 0 ? (_jsxs("span", { className: "text-sm text-foreground", children: ["\u2264 $", maxCostUsd.toFixed(2), " per run"] })) : (_jsx("span", { className: "text-sm text-muted-foreground", children: "Platform default" })), maxToolRounds > 0 && (_jsxs("span", { className: "text-xs text-muted-foreground", children: ["\u2264 ", maxToolRounds, " tool rounds"] }))] }));
603
+ }
604
+ /** The git workspace each fire clones, or the em-dash when none. */
605
+ function WorkspaceSummary({ entries, }) {
606
+ if (entries.length === 0) {
607
+ return _jsx("span", { className: "text-sm text-muted-foreground", children: "\u2014" });
608
+ }
609
+ return (_jsx("ul", { className: "flex flex-col gap-0.5", children: entries.map((entry, i) => {
610
+ const git = entry.source?.source?.case === "gitRepo"
611
+ ? entry.source.source.value
612
+ : undefined;
613
+ return (_jsxs("li", { className: "text-xs text-foreground", children: [_jsx("span", { className: "font-medium", children: entry.name }), git?.url && (_jsxs("span", { className: "ml-1.5 font-mono text-muted-foreground", children: [git.url, git.branch ? `@${git.branch}` : ""] }))] }, `${entry.name}-${i}`));
614
+ }) }));
615
+ }
616
+ function ReferenceLink({ label, onNavigate, mono, }) {
617
+ const textClass = cn("text-sm", mono && "font-mono text-xs");
618
+ if (!onNavigate) {
619
+ return _jsx("span", { className: cn(textClass, "text-foreground"), children: label });
620
+ }
621
+ return (_jsx("button", { type: "button", onClick: onNavigate, className: cn(textClass, "text-primary underline-offset-2 hover:underline", "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm"), children: label }));
622
+ }
623
+ // ---------------------------------------------------------------------------
624
+ // Non-happy states
625
+ // ---------------------------------------------------------------------------
626
+ function LoadingSkeleton({ className }) {
627
+ return (_jsxs("div", { className: cn("flex flex-col gap-6", className), "aria-busy": "true", "aria-label": "Loading schedule details", children: [_jsxs("div", { className: "flex items-start gap-3", children: [_jsx("div", { className: "mt-1 size-6 shrink-0 animate-pulse rounded bg-muted" }), _jsxs("div", { className: "flex-1 space-y-2", children: [_jsx("div", { className: "h-5 w-48 animate-pulse rounded bg-muted" }), _jsx("div", { className: "h-3 w-64 animate-pulse rounded bg-muted" })] })] }), _jsxs("div", { className: "space-y-2", children: [_jsx("div", { className: "h-3 w-28 animate-pulse rounded bg-muted" }), _jsx("div", { className: "animate-pulse rounded-lg border border-border bg-muted-faint", style: { height: "160px" } })] }), _jsxs("div", { className: "space-y-2", children: [_jsx("div", { className: "h-3 w-20 animate-pulse rounded bg-muted" }), _jsx("div", { className: "animate-pulse rounded-lg border border-border bg-muted-faint", style: { height: "160px" } })] })] }));
628
+ }
629
+ function NotFoundState({ className }) {
630
+ return (_jsxs("div", { role: "status", className: cn("flex flex-col items-center gap-2 py-12 text-center", className), children: [_jsx(ScheduleIcon, { className: "size-10 text-muted-foreground-faint" }), _jsx("p", { className: "text-sm font-medium text-muted-foreground", children: "Schedule not found" }), _jsx("p", { className: "text-xs text-muted-foreground-subtle", children: "This schedule doesn't exist or you don't have access to it." })] }));
631
+ }
632
+ // ---------------------------------------------------------------------------
633
+ // Icons (inline SVG — no icon-library dependency)
634
+ // ---------------------------------------------------------------------------
635
+ /** Clock-with-arrow icon shared by the schedule views. */
636
+ export function ScheduleIcon({ className }) {
637
+ return (_jsxs("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M21 12a9 9 0 1 1-2.64-6.36" }), _jsx("path", { d: "M21 3v5h-5" }), _jsx("path", { d: "M12 7v5l3 3" })] }));
638
+ }
639
+ function WarningIcon({ className }) {
640
+ return (_jsxs("svg", { className: className, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M8 1.5 15 14H1L8 1.5Z" }), _jsx("path", { d: "M8 6v4" }), _jsx("path", { d: "M8 12.2v.05" })] }));
641
+ }
642
+ function PencilIcon({ className }) {
643
+ return (_jsx("svg", { className: className, viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "M11.5 1.5a2.121 2.121 0 0 1 3 3L5 14l-4 1 1-4Z" }) }));
644
+ }
645
+ function SpinnerIcon() {
646
+ return (_jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", className: "animate-spin", "aria-hidden": "true", children: _jsx("path", { d: "M8 2a6 6 0 1 0 6 6" }) }));
647
+ }
648
+ //# sourceMappingURL=ScheduleDetailView.js.map