@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,298 @@
1
+ /**
2
+ * The cadence model behind {@link CadenceField} — a pure, dependency-free
3
+ * bridge between human-friendly schedule presets and the 5-field cron
4
+ * grammar the Schedule spec stores.
5
+ *
6
+ * Deliberately NOT a cron parser. The platform owns no cron parsing in
7
+ * either edition — calendar and DST semantics live in the Temporal server
8
+ * (see stigmer-server's schedule/controller/cron.go, DD-008 D2). This
9
+ * module only:
10
+ *
11
+ * 1. GENERATES cron strings from presets (`cadenceToCron`) — trivial
12
+ * string construction, always valid by construction.
13
+ * 2. RECOGNIZES the exact shapes the builder emits (`cronToCadence`)
14
+ * so a stored cron round-trips back into the preset UI; anything
15
+ * else falls back to the `custom` preset showing the raw string.
16
+ * 3. MIRRORS the server's purely lexical validation (`validateCron`,
17
+ * `validateTimeZone`) with the same user-facing wording, so the
18
+ * form can reject bad input instantly. The server remains the
19
+ * authority — its errors surface verbatim on submit.
20
+ */
21
+
22
+ // ---------------------------------------------------------------------------
23
+ // Preset model
24
+ // ---------------------------------------------------------------------------
25
+
26
+ /** A human-friendly cadence, convertible to/from a cron expression. */
27
+ export type CadencePreset =
28
+ | { readonly kind: "hourly"; readonly minute: number }
29
+ | { readonly kind: "daily"; readonly hour: number; readonly minute: number }
30
+ | {
31
+ readonly kind: "weekly";
32
+ /** Days of week, cron numbering: 0 = Sunday … 6 = Saturday. */
33
+ readonly days: readonly number[];
34
+ readonly hour: number;
35
+ readonly minute: number;
36
+ }
37
+ | {
38
+ readonly kind: "monthly";
39
+ /** Day of month, 1–31. Days 29–31 skip months without that day. */
40
+ readonly day: number;
41
+ readonly hour: number;
42
+ readonly minute: number;
43
+ }
44
+ | { readonly kind: "custom"; readonly cron: string };
45
+
46
+ /** Discriminant of {@link CadencePreset}. */
47
+ export type CadenceKind = CadencePreset["kind"];
48
+
49
+ /** Day-of-week labels indexed by cron numbering (0 = Sunday). */
50
+ export const WEEKDAY_LABELS = [
51
+ "Sunday",
52
+ "Monday",
53
+ "Tuesday",
54
+ "Wednesday",
55
+ "Thursday",
56
+ "Friday",
57
+ "Saturday",
58
+ ] as const;
59
+
60
+ // ---------------------------------------------------------------------------
61
+ // Preset → cron
62
+ // ---------------------------------------------------------------------------
63
+
64
+ /**
65
+ * Build the 5-field cron expression for a preset.
66
+ *
67
+ * Output is always valid by construction: numeric fields only,
68
+ * day-of-week in cron numbering (0 = Sunday). For `custom`, the raw
69
+ * string is returned as-is — validate it with {@link validateCron}.
70
+ */
71
+ export function cadenceToCron(preset: CadencePreset): string {
72
+ switch (preset.kind) {
73
+ case "hourly":
74
+ return `${preset.minute} * * * *`;
75
+ case "daily":
76
+ return `${preset.minute} ${preset.hour} * * *`;
77
+ case "weekly": {
78
+ // Sorted, deduplicated day list keeps the output canonical so
79
+ // cronToCadence round-trips regardless of selection order.
80
+ const days = [...new Set(preset.days)].sort((a, b) => a - b);
81
+ return `${preset.minute} ${preset.hour} * * ${days.join(",")}`;
82
+ }
83
+ case "monthly":
84
+ return `${preset.minute} ${preset.hour} ${preset.day} * *`;
85
+ case "custom":
86
+ return preset.cron;
87
+ }
88
+ }
89
+
90
+ // ---------------------------------------------------------------------------
91
+ // Cron → preset (recognition, not parsing)
92
+ // ---------------------------------------------------------------------------
93
+
94
+ const HOURLY_RE = /^(\d{1,2}) \* \* \* \*$/;
95
+ const DAILY_RE = /^(\d{1,2}) (\d{1,2}) \* \* \*$/;
96
+ const WEEKLY_RE = /^(\d{1,2}) (\d{1,2}) \* \* (\d(?:,\d)*)$/;
97
+ const MONTHLY_RE = /^(\d{1,2}) (\d{1,2}) (\d{1,2}) \* \*$/;
98
+
99
+ /**
100
+ * Recognize a cron expression as one of the builder's presets.
101
+ *
102
+ * Only the exact shapes {@link cadenceToCron} emits (plus the
103
+ * calendar shorthands `@hourly`/`@daily`/`@weekly`/`@monthly`) map to a
104
+ * structured preset. Everything else — ranges, steps, names, `@yearly`
105
+ * — is a perfectly valid schedule that this UI simply cannot decompose,
106
+ * so it round-trips as `custom` with the raw string intact.
107
+ */
108
+ export function cronToCadence(cron: string): CadencePreset {
109
+ const normalized = cron.trim().replace(/\s+/g, " ");
110
+
111
+ switch (normalized) {
112
+ case "@hourly":
113
+ return { kind: "hourly", minute: 0 };
114
+ case "@daily":
115
+ return { kind: "daily", hour: 0, minute: 0 };
116
+ case "@weekly":
117
+ return { kind: "weekly", days: [0], hour: 0, minute: 0 };
118
+ case "@monthly":
119
+ return { kind: "monthly", day: 1, hour: 0, minute: 0 };
120
+ }
121
+
122
+ let m = HOURLY_RE.exec(normalized);
123
+ if (m) {
124
+ const minute = Number(m[1]);
125
+ if (isMinute(minute)) return { kind: "hourly", minute };
126
+ }
127
+
128
+ m = DAILY_RE.exec(normalized);
129
+ if (m) {
130
+ const minute = Number(m[1]);
131
+ const hour = Number(m[2]);
132
+ if (isMinute(minute) && isHour(hour)) return { kind: "daily", hour, minute };
133
+ }
134
+
135
+ m = WEEKLY_RE.exec(normalized);
136
+ if (m) {
137
+ const minute = Number(m[1]);
138
+ const hour = Number(m[2]);
139
+ const days = m[3].split(",").map(Number);
140
+ if (
141
+ isMinute(minute) &&
142
+ isHour(hour) &&
143
+ days.length > 0 &&
144
+ days.every((d) => d >= 0 && d <= 6) &&
145
+ new Set(days).size === days.length
146
+ ) {
147
+ return { kind: "weekly", days: [...days].sort((a, b) => a - b), hour, minute };
148
+ }
149
+ }
150
+
151
+ m = MONTHLY_RE.exec(normalized);
152
+ if (m) {
153
+ const minute = Number(m[1]);
154
+ const hour = Number(m[2]);
155
+ const day = Number(m[3]);
156
+ if (isMinute(minute) && isHour(hour) && day >= 1 && day <= 31) {
157
+ return { kind: "monthly", day, hour, minute };
158
+ }
159
+ }
160
+
161
+ return { kind: "custom", cron };
162
+ }
163
+
164
+ function isMinute(n: number): boolean {
165
+ return Number.isInteger(n) && n >= 0 && n <= 59;
166
+ }
167
+
168
+ function isHour(n: number): boolean {
169
+ return Number.isInteger(n) && n >= 0 && n <= 23;
170
+ }
171
+
172
+ // ---------------------------------------------------------------------------
173
+ // Plain-English summary
174
+ // ---------------------------------------------------------------------------
175
+
176
+ /**
177
+ * Human-readable summary of a cadence, e.g.
178
+ * `"Every day at 09:00 (Asia/Kolkata)"`.
179
+ *
180
+ * This is a description of the chosen preset, not a computed fire-time
181
+ * forecast — the platform's next fire time is published by the server
182
+ * as `status.next_fire_at` after apply.
183
+ */
184
+ export function describeCadence(
185
+ preset: CadencePreset,
186
+ timeZone?: string,
187
+ ): string {
188
+ const zone = timeZone ? ` (${timeZone})` : "";
189
+ switch (preset.kind) {
190
+ case "hourly":
191
+ return `Every hour at minute ${preset.minute}${zone}`;
192
+ case "daily":
193
+ return `Every day at ${formatTime(preset.hour, preset.minute)}${zone}`;
194
+ case "weekly": {
195
+ const days = [...new Set(preset.days)].sort((a, b) => a - b);
196
+ const names =
197
+ days.length === 7
198
+ ? "day"
199
+ : listWithAnd(days.map((d) => WEEKDAY_LABELS[d]));
200
+ return `Every ${names} at ${formatTime(preset.hour, preset.minute)}${zone}`;
201
+ }
202
+ case "monthly":
203
+ return `On day ${preset.day} of every month at ${formatTime(preset.hour, preset.minute)}${zone}`;
204
+ case "custom":
205
+ return `Cron “${preset.cron.trim()}”${zone}`;
206
+ }
207
+ }
208
+
209
+ /** `9, 5` → `"09:05"` (24-hour clock, zero-padded). */
210
+ export function formatTime(hour: number, minute: number): string {
211
+ return `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
212
+ }
213
+
214
+ function listWithAnd(items: readonly string[]): string {
215
+ if (items.length === 1) return items[0];
216
+ return `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
217
+ }
218
+
219
+ // ---------------------------------------------------------------------------
220
+ // Lexical validation — mirrors stigmer-server schedule/controller/cron.go
221
+ // ---------------------------------------------------------------------------
222
+
223
+ // The accepted @-shorthands, the field character set, the rejection
224
+ // cases AND the message wording below mirror the server byte-for-byte
225
+ // (Go: cron.go / cron_test.go; Java: ValidateScheduleSpec). A change on
226
+ // any side must change all three, or the instant client feedback drifts
227
+ // from what the server enforces on submit.
228
+
229
+ const CRON_SHORTHANDS = new Set([
230
+ "@hourly",
231
+ "@daily",
232
+ "@weekly",
233
+ "@monthly",
234
+ "@yearly",
235
+ ]);
236
+
237
+ const CRON_FIELD_PATTERN = /^[0-9A-Za-z*,/-]+$/;
238
+
239
+ /**
240
+ * Validate a cron expression against the platform's lexical grammar.
241
+ *
242
+ * Returns the user-facing error message (identical wording to the
243
+ * server's) or `null` when the expression is acceptable. Purely
244
+ * lexical — it does not evaluate calendar semantics.
245
+ */
246
+ export function validateCron(cron: string): string | null {
247
+ if (cron.startsWith("CRON_TZ=") || cron.startsWith("TZ=")) {
248
+ return "spec.cron must not carry a timezone prefix (CRON_TZ=/TZ=) — spec.time_zone is the single timezone authority";
249
+ }
250
+
251
+ if (cron.includes("#")) {
252
+ return "spec.cron must not contain a comment (#)";
253
+ }
254
+
255
+ if (cron.startsWith("@")) {
256
+ if (cron.startsWith("@every")) {
257
+ return "spec.cron must be a calendar expression — @every intervals are not supported";
258
+ }
259
+ if (!CRON_SHORTHANDS.has(cron)) {
260
+ return `spec.cron shorthand "${cron}" is not supported — use @hourly, @daily, @weekly, @monthly, or @yearly, or a 5-field cron expression`;
261
+ }
262
+ return null;
263
+ }
264
+
265
+ // Matches Go's strings.Fields: split on runs of whitespace, so
266
+ // surrounding/duplicate whitespace never produces empty fields.
267
+ const fields = cron.split(/\s+/).filter((f) => f.length > 0);
268
+ if (fields.length !== 5) {
269
+ return `spec.cron must have exactly 5 fields (minute hour day-of-month month day-of-week); got ${fields.length}`;
270
+ }
271
+
272
+ for (const field of fields) {
273
+ if (!CRON_FIELD_PATTERN.test(field)) {
274
+ return `spec.cron field "${field}" contains unsupported characters — allowed: digits, names, '*', ',', '-', '/'`;
275
+ }
276
+ }
277
+
278
+ return null;
279
+ }
280
+
281
+ /**
282
+ * Validate an IANA time zone name using the runtime's own tz database
283
+ * (`Intl`), mirroring the server's check against the platform tz
284
+ * database. Returns the user-facing error message or `null`.
285
+ *
286
+ * `"Local"` is rejected explicitly for the same reason the server
287
+ * rejects it: it is host-dependent, not a zone.
288
+ */
289
+ export function validateTimeZone(timeZone: string): string | null {
290
+ const invalid = `spec.time_zone "${timeZone}" is not a valid IANA time zone (e.g. "Asia/Kolkata")`;
291
+ if (timeZone === "Local") return invalid;
292
+ try {
293
+ new Intl.DateTimeFormat("en-US", { timeZone });
294
+ return null;
295
+ } catch {
296
+ return invalid;
297
+ }
298
+ }
@@ -0,0 +1,69 @@
1
+ export { deriveScheduleState, formatNextFire } from "./scheduleState.js";
2
+ export type { ScheduleState, ScheduleStateInfo } from "./scheduleState.js";
3
+
4
+ export { createScheduleListFn, listSchedulesPage } from "./scheduleListFn.js";
5
+ export type { ScheduleListClient, SchedulePage } from "./scheduleListFn.js";
6
+
7
+ export { useSchedule } from "./useSchedule.js";
8
+ export type { UseScheduleReturn } from "./useSchedule.js";
9
+
10
+ export { useScheduleRuns } from "./useScheduleRuns.js";
11
+ export type {
12
+ UseScheduleRunsOptions,
13
+ UseScheduleRunsReturn,
14
+ } from "./useScheduleRuns.js";
15
+
16
+ export { useScheduleList } from "./useScheduleList.js";
17
+ export type {
18
+ UseScheduleListOptions,
19
+ UseScheduleListReturn,
20
+ } from "./useScheduleList.js";
21
+
22
+ export { useScheduleCount } from "./useScheduleCount.js";
23
+ export type {
24
+ UseScheduleCountOptions,
25
+ UseScheduleCountReturn,
26
+ } from "./useScheduleCount.js";
27
+
28
+ export { useResumeSchedule } from "./useResumeSchedule.js";
29
+ export type { UseResumeScheduleReturn } from "./useResumeSchedule.js";
30
+
31
+ export { useTriggerSchedule } from "./useTriggerSchedule.js";
32
+ export type { UseTriggerScheduleReturn } from "./useTriggerSchedule.js";
33
+
34
+ export { useSetScheduleEnabled } from "./useSetScheduleEnabled.js";
35
+ export type { UseSetScheduleEnabledReturn } from "./useSetScheduleEnabled.js";
36
+
37
+ export { useUpdateScheduleSpec } from "./useUpdateScheduleSpec.js";
38
+ export type { UseUpdateScheduleSpecReturn } from "./useUpdateScheduleSpec.js";
39
+
40
+ export { createScheduleColumns } from "./scheduleColumns.js";
41
+ export type { ScheduleColumnsOptions } from "./scheduleColumns.js";
42
+
43
+ export { ScheduleRowActions } from "./ScheduleRowActions.js";
44
+ export type { ScheduleRowActionsProps } from "./ScheduleRowActions.js";
45
+
46
+ export { ScheduleDetailView, ScheduleIcon } from "./ScheduleDetailView.js";
47
+ export type { ScheduleDetailViewProps } from "./ScheduleDetailView.js";
48
+
49
+ export { ScheduleRunsTable } from "./ScheduleRunsTable.js";
50
+ export type { ScheduleRunsTableProps } from "./ScheduleRunsTable.js";
51
+
52
+ export {
53
+ cadenceToCron,
54
+ cronToCadence,
55
+ describeCadence,
56
+ validateCron,
57
+ validateTimeZone,
58
+ WEEKDAY_LABELS,
59
+ } from "./cadence.js";
60
+ export type { CadencePreset, CadenceKind } from "./cadence.js";
61
+
62
+ export { useCreateSchedule } from "./useCreateSchedule.js";
63
+ export type { UseCreateScheduleReturn } from "./useCreateSchedule.js";
64
+
65
+ export { CadenceField } from "./CadenceField.js";
66
+ export type { CadenceFieldProps } from "./CadenceField.js";
67
+
68
+ export { ScheduleForm } from "./ScheduleForm.js";
69
+ export type { ScheduleFormProps } from "./ScheduleForm.js";
@@ -0,0 +1,118 @@
1
+ "use client";
2
+
3
+ import { timestampDate } from "@bufbuild/protobuf/wkt";
4
+ import type { Schedule } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/api_pb";
5
+ import { formatRelativeTime } from "../activity/format-relative-time.js";
6
+ import { StatusBadge } from "../resource-workbench/components/StatusBadge.js";
7
+ import type { WorkbenchColumnDef } from "../resource-workbench/types.js";
8
+ import { deriveScheduleState, formatNextFire } from "./scheduleState.js";
9
+
10
+ /** Options for {@link createScheduleColumns}. */
11
+ export interface ScheduleColumnsOptions {
12
+ /**
13
+ * Clock provider for the "next fire" and "last run" columns.
14
+ * Injectable for deterministic tests and Scenar fixtures.
15
+ * @default () => new Date()
16
+ */
17
+ readonly now?: () => Date;
18
+ }
19
+
20
+ /**
21
+ * Column set for a schedule workbench — shared by every console so the
22
+ * list renders identically everywhere (DD-016).
23
+ *
24
+ * The columns exist because schedules are listed via the direct query:
25
+ * each row is a full `Schedule` proto, so the operational fields the
26
+ * issue calls for (next fire, last run, enabled/paused state) render
27
+ * straight from the row — no generic `SearchResult` limitations.
28
+ *
29
+ * Columns are not sortable: the direct query has one fixed server-side
30
+ * order (newest first), and a sort affordance that silently does
31
+ * nothing would lie.
32
+ */
33
+ export function createScheduleColumns(
34
+ options?: ScheduleColumnsOptions,
35
+ ): WorkbenchColumnDef<Schedule>[] {
36
+ const now = options?.now ?? (() => new Date());
37
+
38
+ return [
39
+ {
40
+ id: "name",
41
+ header: "Name",
42
+ cell: (item) => (
43
+ <span className="font-medium text-foreground">
44
+ {item.metadata?.name || item.metadata?.slug}
45
+ </span>
46
+ ),
47
+ flex: 2,
48
+ },
49
+ {
50
+ id: "state",
51
+ header: "State",
52
+ cell: (item) => {
53
+ const info = deriveScheduleState(item.spec, item.status);
54
+ return <StatusBadge phase={info.phase} label={info.label} />;
55
+ },
56
+ flex: 1,
57
+ },
58
+ {
59
+ id: "cron",
60
+ header: "Cadence",
61
+ cell: (item) => (
62
+ <span className="inline-flex items-baseline gap-1.5">
63
+ <code className="font-mono text-xs text-foreground">
64
+ {item.spec?.cron || "—"}
65
+ </code>
66
+ <span className="text-xs text-muted-foreground">
67
+ {item.spec?.timeZone}
68
+ </span>
69
+ </span>
70
+ ),
71
+ flex: 1.5,
72
+ },
73
+ {
74
+ id: "next-fire",
75
+ header: "Next fire",
76
+ cell: (item) => {
77
+ const info = deriveScheduleState(item.spec, item.status);
78
+ const nextFireAt = item.status?.nextFireAt;
79
+ return (
80
+ <span className="text-muted-foreground">
81
+ {info.state === "active" && nextFireAt
82
+ ? formatNextFire(timestampDate(nextFireAt), now())
83
+ : "—"}
84
+ </span>
85
+ );
86
+ },
87
+ flex: 1,
88
+ },
89
+ {
90
+ id: "last-run",
91
+ header: "Last run",
92
+ cell: (item) => (
93
+ <span className="text-muted-foreground">
94
+ {item.status?.lastFireAt
95
+ ? formatRelativeTime(timestampDate(item.status.lastFireAt), now())
96
+ : "Never"}
97
+ </span>
98
+ ),
99
+ flex: 1,
100
+ },
101
+ {
102
+ id: "target",
103
+ header: "Target agent",
104
+ cell: (item) => {
105
+ const target =
106
+ item.spec?.target?.case === "agent" ? item.spec.target.value : undefined;
107
+ return (
108
+ <span className="text-muted-foreground">
109
+ {target?.agentRef
110
+ ? `${target.agentRef.org}/${target.agentRef.slug}`
111
+ : "—"}
112
+ </span>
113
+ );
114
+ },
115
+ flex: 1.5,
116
+ },
117
+ ];
118
+ }
@@ -0,0 +1,108 @@
1
+ // Schedule list fetching — the direct-query core plus the workbench adapter.
2
+ //
3
+ // Schedules are the one Library kind NOT backed by the search service: the
4
+ // generic `SearchResult` summary cannot carry the operational fields a
5
+ // schedule list exists to show (`next_fire_at`, enabled/paused state, last
6
+ // run), while the direct `listSchedules` query returns full `Schedule`
7
+ // protos and was explicitly shaped for "the org-context view a console tab
8
+ // needs". Both consoles consume this single implementation — inlining it
9
+ // per-app would duplicate correctness-bearing pagination logic (DD-016).
10
+
11
+ import { create } from "@bufbuild/protobuf";
12
+ import type { Schedule } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/api_pb";
13
+ import {
14
+ ListSchedulesRequestSchema,
15
+ type ListSchedulesRequest,
16
+ type ScheduleList,
17
+ } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/io_pb";
18
+ import type { SearchResult } from "@stigmer/protos/ai/stigmer/search/v1/io_pb";
19
+ import type { ListParams, ListResult } from "@stigmer/sdk";
20
+
21
+ /** The slice of the Stigmer client this module needs (mockable in tests). */
22
+ export interface ScheduleListClient {
23
+ readonly schedule: {
24
+ list(input: ListSchedulesRequest): Promise<ScheduleList>;
25
+ };
26
+ }
27
+
28
+ /** One page of schedules, with pagination totals. */
29
+ export interface SchedulePage {
30
+ /** Full `Schedule` protos (spec + status) for the requested page. */
31
+ readonly items: readonly Schedule[];
32
+ /** Total schedules in the org (across all pages). */
33
+ readonly totalCount: number;
34
+ /** Total pages at the requested page size. */
35
+ readonly totalPages: number;
36
+ }
37
+
38
+ const DEFAULT_PAGE_SIZE = 20;
39
+
40
+ /**
41
+ * Fetch one page of an organization's schedules via the direct query.
42
+ *
43
+ * Handles a verified split between the two server editions: cloud slices
44
+ * pages server-side, while the OSS server documents that it ignores
45
+ * `page_info` and returns every matching schedule. A server that
46
+ * paginated can never return more rows than the requested size, so an
47
+ * overflowing response is the tell that the server ignored pagination —
48
+ * only then is the page sliced locally (absolute indices into the full
49
+ * list). A cloud page passes through untouched.
50
+ */
51
+ export async function listSchedulesPage(
52
+ client: ScheduleListClient,
53
+ org: string,
54
+ page: { readonly num?: number; readonly size?: number } = {},
55
+ ): Promise<SchedulePage> {
56
+ const size = page.size && page.size > 0 ? page.size : DEFAULT_PAGE_SIZE;
57
+ const num = page.num && page.num > 0 ? page.num : 1;
58
+
59
+ const result = await client.schedule.list(
60
+ create(ListSchedulesRequestSchema, {
61
+ org,
62
+ pageInfo: { num, size },
63
+ }),
64
+ );
65
+
66
+ const items =
67
+ result.items.length > size
68
+ ? result.items.slice((num - 1) * size, num * size)
69
+ : result.items;
70
+
71
+ return {
72
+ items,
73
+ totalCount: result.totalCount,
74
+ totalPages: Math.ceil(result.totalCount / size),
75
+ };
76
+ }
77
+
78
+ /**
79
+ * Build a `ResourceWorkbench`-compatible `listFn` over the direct
80
+ * schedule query.
81
+ *
82
+ * The returned entries are full `Schedule` protos occupying the
83
+ * `SearchResult` slot of `ListResult` — `ResourceWorkbench` is generic
84
+ * over its row type (`useResourceCollection` casts entries through to
85
+ * `TData`), and this is the one documented place where that cast
86
+ * happens. Consumers type their workbench as
87
+ * `ResourceWorkbench<Schedule>` and pass `getItemId={(s) => s.metadata?.id}`.
88
+ *
89
+ * `params.query` and `params.crossOrgPublic` are ignored: schedules have
90
+ * no server-side text search (render the workbench with
91
+ * `searchable={false}`) and are never public/cross-org.
92
+ */
93
+ export function createScheduleListFn(
94
+ client: ScheduleListClient,
95
+ ): (params: ListParams) => Promise<ListResult> {
96
+ return async (params: ListParams): Promise<ListResult> => {
97
+ const { items, totalCount, totalPages } = await listSchedulesPage(
98
+ client,
99
+ params.org,
100
+ params.page ?? {},
101
+ );
102
+ return {
103
+ entries: items as unknown as SearchResult[],
104
+ totalCount,
105
+ totalPages,
106
+ };
107
+ };
108
+ }
@@ -0,0 +1,96 @@
1
+ // Pure schedule-state derivation — the disabled-vs-paused vocabulary,
2
+ // computed on read.
3
+ //
4
+ // A schedule that is not firing is stopped by one of two levers with two
5
+ // different writers and two different remedies (the backend pins this
6
+ // vocabulary in its controller docs):
7
+ //
8
+ // - "disabled" — the OWNER's switch (`spec.enabled = false`), cleared
9
+ // by re-applying the manifest or the console's Enable action.
10
+ // - "paused" — the PLATFORM's failure-streak latch
11
+ // (`status.paused_reason` non-empty), cleared only by Resume.
12
+ //
13
+ // The console must never collapse these into one badge (stigmer/stigmer#352):
14
+ // each state names its own remedy. When both levers are set, "disabled"
15
+ // wins for display — the owner's intent dominates — but callers should
16
+ // keep the paused reason visible alongside (the banner does).
17
+
18
+ import type { ScheduleSpec } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/spec_pb";
19
+ import type { ScheduleStatus } from "@stigmer/protos/ai/stigmer/agentic/schedule/v1/status_pb";
20
+ import type { StatusPhase } from "../resource-workbench/types.js";
21
+
22
+ /** The three mutually-exclusive display states of a schedule. */
23
+ export type ScheduleState = "active" | "disabled" | "paused";
24
+
25
+ /** Derived display state: the tri-state plus its shared-badge rendering. */
26
+ export interface ScheduleStateInfo {
27
+ /** The display state ("disabled" wins when both levers are set). */
28
+ readonly state: ScheduleState;
29
+ /** `StatusPhase` for the shared `StatusBadge` (`--stgm-status-*` tokens). */
30
+ readonly phase: StatusPhase;
31
+ /** Human-readable badge label. */
32
+ readonly label: string;
33
+ /**
34
+ * `true` when the platform pause latch is set — independent of the
35
+ * display state, so a disabled-AND-paused schedule can still surface
36
+ * its `status.pausedReason`.
37
+ */
38
+ readonly isPaused: boolean;
39
+ }
40
+
41
+ /**
42
+ * Derive a schedule's display state from its spec and status.
43
+ *
44
+ * A missing spec derives as "disabled" — the same fail-closed reading the
45
+ * server applies to a manifest that omits `enabled`.
46
+ */
47
+ export function deriveScheduleState(
48
+ spec: ScheduleSpec | undefined,
49
+ status: ScheduleStatus | undefined,
50
+ ): ScheduleStateInfo {
51
+ const isPaused = (status?.pausedReason ?? "") !== "";
52
+
53
+ if (!spec?.enabled) {
54
+ return { state: "disabled", phase: "disabled", label: "Disabled", isPaused };
55
+ }
56
+ if (isPaused) {
57
+ return { state: "paused", phase: "degraded", label: "Paused", isPaused };
58
+ }
59
+ return { state: "active", phase: "ready", label: "Active", isPaused };
60
+ }
61
+
62
+ /**
63
+ * Compact future-instant formatter for a schedule's next fire time:
64
+ * `now`, `in 5m`, `in 3h`, `in 6d`, then a short date once "days from
65
+ * now" stops being how people think about it.
66
+ *
67
+ * The schedule-local sibling of the activity module's past-only
68
+ * `formatRelativeTime` (same compact units, same date tail) — kept
69
+ * separate because that util's contract is deliberately past-only.
70
+ * A fire time slightly in the past (a tick mid-flight, clock skew)
71
+ * renders as `now` rather than a nonsense negative countdown.
72
+ *
73
+ * `now` is injected, never read from the live clock — required for
74
+ * deterministic tests and Scenar fixtures.
75
+ */
76
+ export function formatNextFire(date: Date, now: Date): string {
77
+ const deltaMs = date.getTime() - now.getTime();
78
+
79
+ if (deltaMs < 60_000) return "now";
80
+
81
+ const minutes = Math.floor(deltaMs / 60_000);
82
+ if (minutes < 60) return `in ${minutes}m`;
83
+
84
+ const hours = Math.floor(minutes / 60);
85
+ if (hours < 24) return `in ${hours}h`;
86
+
87
+ const days = Math.floor(hours / 24);
88
+ if (days < 7) return `in ${days}d`;
89
+
90
+ const sameYear = date.getFullYear() === now.getFullYear();
91
+ return date.toLocaleDateString(undefined, {
92
+ month: "short",
93
+ day: "numeric",
94
+ ...(sameYear ? {} : { year: "numeric" }),
95
+ });
96
+ }