@burdenoff/microfe-stewards 2026.1201.3 → 2026.1201.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/dev/fixturesEditors.d.ts +4 -0
  2. package/dist/generated/wspace-operations.d.ts +1259 -6
  3. package/dist/generated/wspace-operations.js +493 -62
  4. package/dist/generated/wspace-operations.js.map +1 -1
  5. package/dist/generated/wspace-types.js +12 -4
  6. package/dist/generated/wspace-types.js.map +1 -1
  7. package/dist/stewards/StewardsRoutes.d.ts +2 -2
  8. package/dist/stewards/StewardsRoutes.js +41 -26
  9. package/dist/stewards/StewardsRoutes.js.map +1 -1
  10. package/dist/stewards/components/DutyEditor.d.ts +8 -0
  11. package/dist/stewards/components/DutyEditor.js +151 -0
  12. package/dist/stewards/components/DutyEditor.js.map +1 -0
  13. package/dist/stewards/components/FormField.d.ts +8 -0
  14. package/dist/stewards/components/FormField.js +23 -0
  15. package/dist/stewards/components/FormField.js.map +1 -0
  16. package/dist/stewards/components/MemoryDiffView.d.ts +6 -0
  17. package/dist/stewards/components/MemoryDiffView.js +81 -0
  18. package/dist/stewards/components/MemoryDiffView.js.map +1 -0
  19. package/dist/stewards/components/ProposalsQueue.d.ts +5 -0
  20. package/dist/stewards/components/ProposalsQueue.js +106 -0
  21. package/dist/stewards/components/ProposalsQueue.js.map +1 -0
  22. package/dist/stewards/components/TeachRecorder.d.ts +12 -0
  23. package/dist/stewards/components/TeachRecorder.js +288 -0
  24. package/dist/stewards/components/TeachRecorder.js.map +1 -0
  25. package/dist/stewards/i18n/en.d.ts +230 -6
  26. package/dist/stewards/i18n/en.js +8 -3
  27. package/dist/stewards/i18n/en.js.map +1 -1
  28. package/dist/stewards/i18n/enEditors.d.ts +230 -0
  29. package/dist/stewards/i18n/enEditors.js +233 -0
  30. package/dist/stewards/i18n/enEditors.js.map +1 -0
  31. package/dist/stewards/index.js +4 -4
  32. package/dist/stewards/pages/StewardDutiesPage.d.ts +1 -0
  33. package/dist/stewards/pages/StewardDutiesPage.js +221 -0
  34. package/dist/stewards/pages/StewardDutiesPage.js.map +1 -0
  35. package/dist/stewards/pages/StewardLayout.js +62 -45
  36. package/dist/stewards/pages/StewardLayout.js.map +1 -1
  37. package/dist/stewards/pages/StewardMemoryPage.d.ts +1 -0
  38. package/dist/stewards/pages/StewardMemoryPage.js +294 -0
  39. package/dist/stewards/pages/StewardMemoryPage.js.map +1 -0
  40. package/dist/stewards/pages/StewardPlaybooksPage.d.ts +1 -0
  41. package/dist/stewards/pages/StewardPlaybooksPage.js +360 -0
  42. package/dist/stewards/pages/StewardPlaybooksPage.js.map +1 -0
  43. package/dist/stewards/utils/dutyForm.d.ts +37 -0
  44. package/dist/stewards/utils/dutyForm.js +84 -0
  45. package/dist/stewards/utils/dutyForm.js.map +1 -0
  46. package/dist/stewards/utils/memory.d.ts +21 -0
  47. package/dist/stewards/utils/memory.js +29 -0
  48. package/dist/stewards/utils/memory.js.map +1 -0
  49. package/dist/stewards/utils/playbookForm.d.ts +41 -0
  50. package/dist/stewards/utils/playbookForm.js +67 -0
  51. package/dist/stewards/utils/playbookForm.js.map +1 -0
  52. package/dist/stewards/utils/recorder.d.ts +31 -0
  53. package/dist/stewards/utils/recorder.js +106 -0
  54. package/dist/stewards/utils/recorder.js.map +1 -0
  55. package/package.json +1 -1
@@ -0,0 +1,360 @@
1
+ import { useCreateBotmanorStewardPlaybookMutation as e, useGetBotmanorStewardPlaybookQuery as t, useListBotmanorStewardPlaybooksQuery as n, useSaveBotmanorStewardPlaybookVersionMutation as r, useSetBotmanorStewardPlaybookStatusMutation as i } from "../../generated/wspace-operations.js";
2
+ import { BotmanorStewardPlaybookStatus as a } from "../../generated/wspace-types.js";
3
+ import { FIELD_CLASS as o } from "../components/fieldClasses.js";
4
+ import { FormField as s } from "../components/FormField.js";
5
+ import { TeachRecorder as c } from "../components/TeachRecorder.js";
6
+ import { Alert as l, Badge as u, Button as d, Card as f, StateMessage as p } from "../components/ui.js";
7
+ import { useStewardsT as m } from "../i18n/useStewardsT.js";
8
+ import { useStewardAbilities as h } from "../permissions/useStewardPermissions.js";
9
+ import { relativeTime as g } from "../utils/dates.js";
10
+ import { buildManifest as _, buildVersionInput as v, emptyPlaybookForm as y, playbookToForm as b, splitLines as x, validatePlaybook as S } from "../utils/playbookForm.js";
11
+ import { useStewardOutlet as C } from "./StewardLayout.js";
12
+ import { jsx as w, jsxs as T } from "react/jsx-runtime";
13
+ import { useState as E } from "react";
14
+ import { CombinedGraphQLErrors as D } from "@apollo/client";
15
+ // src/stewards/pages/StewardPlaybooksPage.tsx
16
+ var O = ["ListBotmanorStewardPlaybooks", "GetBotmanorStewardPlaybook"];
17
+ function k(e) {
18
+ return !e || !D.is(e) ? !1 : e.errors.some((e) => e.extensions?.code === "CONFLICT");
19
+ }
20
+ function A({ stewardId: n, playbook: c, canUpdate: u, onSaved: p, onTeach: h, onCancel: C }) {
21
+ let D = m(), A = c === null, { data: j } = t({
22
+ variables: { id: c?.id ?? "" },
23
+ skip: A,
24
+ fetchPolicy: "cache-and-network"
25
+ }), M = j?.getBotmanorStewardPlaybook ?? c, [N, P] = E(null), [F, I] = E(!0), [L, R] = E(!1), [z, B] = e({ refetchQueries: O }), [V, H] = r({ refetchQueries: O }), [U, W] = i({ refetchQueries: O }), G = M?.currentVersion ?? 0, K = N && N.version === G ? N.value : M ? b(M.name, M.current) : y(), q = (e) => P({
26
+ version: G,
27
+ value: {
28
+ ...K,
29
+ ...e
30
+ }
31
+ }), J = S(K, A), Y = (e) => L && J.includes(e) ? D(`stewards.playbooks.errors.${e}`) : null, X = B.error ?? H.error ?? W.error, Z = M?.current?.recordedStepCount ?? 0, Q = j?.getBotmanorStewardPlaybook?.versions ?? [], $ = async () => {
32
+ if (R(!0), !(J.length > 0)) {
33
+ if (M) {
34
+ let { data: e } = await V({ variables: {
35
+ id: M.id,
36
+ input: v(K, F),
37
+ expectedVersion: M.currentVersion
38
+ } });
39
+ e && p(e.saveBotmanorStewardPlaybookVersion.id);
40
+ } else {
41
+ let { data: e } = await z({ variables: { input: {
42
+ stewardId: n,
43
+ name: K.name.trim(),
44
+ skillMd: K.skillMd,
45
+ manifest: _(K),
46
+ toolKeys: x(K.toolKeys)
47
+ } } });
48
+ e && p(e.createBotmanorStewardPlaybook.id);
49
+ }
50
+ }
51
+ };
52
+ return /* @__PURE__ */ T(f, {
53
+ title: A ? D("stewards.playbooks.new") : M?.name ?? "",
54
+ hint: M ? `${D("stewards.playbooks.colVersion")} ${M.currentVersion} · ${D(`stewards.playbooks.status.${M.status}`)}` : void 0,
55
+ children: [/* @__PURE__ */ T("form", {
56
+ className: "flex flex-col gap-3",
57
+ onSubmit: (e) => {
58
+ e.preventDefault(), $().catch(() => void 0);
59
+ },
60
+ children: [
61
+ A && /* @__PURE__ */ w(s, {
62
+ label: D("stewards.playbooks.fieldName"),
63
+ error: Y("name") ?? Y("nameLength"),
64
+ children: /* @__PURE__ */ w("input", {
65
+ className: "w-full rounded-md border border-(color:--color-border-seam) bg-(--color-bg-surface) px-2 py-1.5 text-sm text-(color:--color-text-primary) placeholder:text-(color:--color-text-placeholder) focus-visible:outline-2 focus-visible:outline-(color:--color-focus-ring)",
66
+ maxLength: 255,
67
+ value: K.name,
68
+ onChange: (e) => q({ name: e.target.value })
69
+ })
70
+ }),
71
+ /* @__PURE__ */ w(s, {
72
+ label: D("stewards.playbooks.fieldSkill"),
73
+ error: Y("skillMd") ?? Y("skillMdLength"),
74
+ children: /* @__PURE__ */ w("textarea", {
75
+ className: `${o} min-h-48 font-mono`,
76
+ readOnly: !u,
77
+ value: K.skillMd,
78
+ onChange: (e) => q({ skillMd: e.target.value })
79
+ })
80
+ }),
81
+ /* @__PURE__ */ w(s, {
82
+ label: D("stewards.playbooks.fieldWhen"),
83
+ children: /* @__PURE__ */ w("input", {
84
+ className: o,
85
+ value: K.whenToUse,
86
+ onChange: (e) => q({ whenToUse: e.target.value })
87
+ })
88
+ }),
89
+ /* @__PURE__ */ w(s, {
90
+ label: D("stewards.playbooks.fieldReturns"),
91
+ children: /* @__PURE__ */ w("input", {
92
+ className: o,
93
+ value: K.returns,
94
+ onChange: (e) => q({ returns: e.target.value })
95
+ })
96
+ }),
97
+ /* @__PURE__ */ w(s, {
98
+ label: D("stewards.playbooks.fieldFailure"),
99
+ children: /* @__PURE__ */ w("input", {
100
+ className: o,
101
+ value: K.failureHandling,
102
+ onChange: (e) => q({ failureHandling: e.target.value })
103
+ })
104
+ }),
105
+ /* @__PURE__ */ T("div", {
106
+ className: "grid grid-cols-1 gap-3 sm:grid-cols-2",
107
+ children: [/* @__PURE__ */ w(s, {
108
+ label: D("stewards.playbooks.fieldChecks"),
109
+ children: /* @__PURE__ */ w("textarea", {
110
+ className: `${o} min-h-20`,
111
+ value: K.checks,
112
+ onChange: (e) => q({ checks: e.target.value })
113
+ })
114
+ }), /* @__PURE__ */ w(s, {
115
+ label: D("stewards.playbooks.fieldBoundaries"),
116
+ children: /* @__PURE__ */ w("textarea", {
117
+ className: `${o} min-h-20`,
118
+ value: K.approvalBoundaries,
119
+ onChange: (e) => q({ approvalBoundaries: e.target.value })
120
+ })
121
+ })]
122
+ }),
123
+ /* @__PURE__ */ w(s, {
124
+ label: D("stewards.playbooks.fieldTools"),
125
+ help: D("stewards.playbooks.fieldToolsHelp"),
126
+ children: /* @__PURE__ */ w("textarea", {
127
+ className: `${o} min-h-20 font-mono`,
128
+ value: K.toolKeys,
129
+ onChange: (e) => q({ toolKeys: e.target.value })
130
+ })
131
+ }),
132
+ /* @__PURE__ */ T("fieldset", {
133
+ className: "flex flex-col gap-2",
134
+ children: [
135
+ /* @__PURE__ */ w("legend", {
136
+ className: "text-sm font-medium text-(color:--color-text-primary)",
137
+ children: D("stewards.playbooks.inputsTitle")
138
+ }),
139
+ K.inputs.map((e, t) => /* @__PURE__ */ T("div", {
140
+ className: "grid grid-cols-1 items-end gap-2 sm:grid-cols-[1fr_2fr_auto_auto]",
141
+ children: [
142
+ /* @__PURE__ */ w(s, {
143
+ label: D("stewards.playbooks.inputName"),
144
+ children: /* @__PURE__ */ w("input", {
145
+ className: o,
146
+ value: e.name,
147
+ onChange: (e) => q({ inputs: K.inputs.map((n, r) => r === t ? {
148
+ ...n,
149
+ name: e.target.value
150
+ } : n) })
151
+ })
152
+ }),
153
+ /* @__PURE__ */ w(s, {
154
+ label: D("stewards.playbooks.inputDescription"),
155
+ children: /* @__PURE__ */ w("input", {
156
+ className: o,
157
+ value: e.description,
158
+ onChange: (e) => q({ inputs: K.inputs.map((n, r) => r === t ? {
159
+ ...n,
160
+ description: e.target.value
161
+ } : n) })
162
+ })
163
+ }),
164
+ /* @__PURE__ */ T("label", {
165
+ className: "flex items-center gap-2 pb-2 text-sm text-(color:--color-text-primary)",
166
+ children: [/* @__PURE__ */ w("input", {
167
+ type: "checkbox",
168
+ checked: e.required,
169
+ onChange: (e) => q({ inputs: K.inputs.map((n, r) => r === t ? {
170
+ ...n,
171
+ required: e.target.checked
172
+ } : n) })
173
+ }), D("stewards.playbooks.inputRequired")]
174
+ }),
175
+ /* @__PURE__ */ w(d, {
176
+ onClick: () => q({ inputs: K.inputs.filter((e, n) => n !== t) }),
177
+ children: D("stewards.playbooks.removeInput")
178
+ })
179
+ ]
180
+ }, t)),
181
+ Y("inputName") && /* @__PURE__ */ w(l, { children: Y("inputName") }),
182
+ /* @__PURE__ */ w("div", { children: /* @__PURE__ */ w(d, {
183
+ onClick: () => q({ inputs: [...K.inputs, {
184
+ name: "",
185
+ description: "",
186
+ required: !1
187
+ }] }),
188
+ children: D("stewards.playbooks.addInput")
189
+ }) })
190
+ ]
191
+ }),
192
+ Z > 0 && /* @__PURE__ */ T("div", {
193
+ className: "flex flex-col gap-1",
194
+ children: [/* @__PURE__ */ T("label", {
195
+ className: "flex items-center gap-2 text-sm text-(color:--color-text-primary)",
196
+ children: [
197
+ /* @__PURE__ */ w("input", {
198
+ type: "checkbox",
199
+ checked: F,
200
+ onChange: (e) => I(e.target.checked)
201
+ }),
202
+ D("stewards.playbooks.keepSteps"),
203
+ " (",
204
+ D("stewards.playbooks.savedSteps", { count: Z }),
205
+ ")"
206
+ ]
207
+ }), /* @__PURE__ */ w("p", {
208
+ className: "text-xs text-(color:--color-text-secondary)",
209
+ children: D("stewards.playbooks.maskedNote")
210
+ })]
211
+ }),
212
+ k(H.error) ? /* @__PURE__ */ w(l, { children: D("stewards.playbooks.conflict") }) : X && /* @__PURE__ */ T(l, { children: [
213
+ D("stewards.playbooks.saveError"),
214
+ " ",
215
+ X.message
216
+ ] }),
217
+ u && /* @__PURE__ */ T("div", {
218
+ className: "flex flex-wrap gap-2",
219
+ children: [
220
+ /* @__PURE__ */ w(d, {
221
+ type: "submit",
222
+ variant: "primary",
223
+ disabled: B.loading || H.loading,
224
+ children: B.loading || H.loading ? D("stewards.playbooks.saving") : D(A ? "stewards.playbooks.create" : "stewards.playbooks.save")
225
+ }),
226
+ M && M.status !== a.Active && /* @__PURE__ */ w(d, {
227
+ disabled: W.loading,
228
+ onClick: () => void U({ variables: {
229
+ id: M.id,
230
+ status: a.Active
231
+ } }).catch(() => void 0),
232
+ children: D("stewards.playbooks.activate")
233
+ }),
234
+ M && M.status !== a.Archived && /* @__PURE__ */ w(d, {
235
+ disabled: W.loading,
236
+ onClick: () => void U({ variables: {
237
+ id: M.id,
238
+ status: a.Archived
239
+ } }).catch(() => void 0),
240
+ children: D("stewards.playbooks.archive")
241
+ }),
242
+ /* @__PURE__ */ w(d, {
243
+ onClick: h,
244
+ children: D("stewards.playbooks.teach")
245
+ }),
246
+ /* @__PURE__ */ w(d, {
247
+ onClick: C,
248
+ children: D("stewards.common.cancel")
249
+ })
250
+ ]
251
+ })
252
+ ]
253
+ }), Q.length > 0 && /* @__PURE__ */ T("div", {
254
+ className: "mt-4",
255
+ children: [/* @__PURE__ */ w("h3", {
256
+ className: "mb-2 text-sm font-semibold text-(color:--color-text-primary)",
257
+ children: D("stewards.playbooks.versions")
258
+ }), /* @__PURE__ */ w("ul", {
259
+ className: "flex flex-col gap-1 text-sm text-(color:--color-text-secondary)",
260
+ children: Q.map((e) => /* @__PURE__ */ T("li", { children: [D("stewards.playbooks.versionRow", {
261
+ version: e.version,
262
+ author: D(`stewards.playbooks.authoredBy.${e.authoredBy}`),
263
+ when: g(e.createdAt)
264
+ }), e.recordedStepCount > 0 && ` · ${D("stewards.playbooks.savedSteps", { count: e.recordedStepCount })}`] }, e.id))
265
+ })]
266
+ })]
267
+ });
268
+ }
269
+ function j() {
270
+ let e = m(), { steward: t } = C(), { canUpdate: r } = h(), [i, o] = E(null), [s, l] = E({ kind: "none" }), { data: g, loading: _, error: v } = n({
271
+ variables: { stewardId: t.id },
272
+ fetchPolicy: "cache-and-network"
273
+ }), y = g?.listBotmanorStewardPlaybooks ?? [], b = y.find((e) => e.id === i) ?? null, x = (e) => {
274
+ o(e), l({ kind: "open" });
275
+ };
276
+ return /* @__PURE__ */ T("div", {
277
+ className: "grid grid-cols-1 gap-4 lg:grid-cols-3",
278
+ children: [/* @__PURE__ */ T(f, {
279
+ title: e("stewards.playbooks.title"),
280
+ hint: e("stewards.playbooks.hint"),
281
+ children: [r && /* @__PURE__ */ T("div", {
282
+ className: "mb-3 flex flex-wrap gap-2",
283
+ children: [/* @__PURE__ */ w(d, {
284
+ variant: "primary",
285
+ onClick: () => {
286
+ o(null), l({ kind: "new" });
287
+ },
288
+ children: e("stewards.playbooks.new")
289
+ }), /* @__PURE__ */ w(d, {
290
+ onClick: () => {
291
+ o(null), l({ kind: "teach" });
292
+ },
293
+ children: e("stewards.playbooks.teach")
294
+ })]
295
+ }), v ? /* @__PURE__ */ w(p, {
296
+ kind: "error",
297
+ title: e("stewards.common.errorTitle"),
298
+ body: v.message
299
+ }) : _ && y.length === 0 ? /* @__PURE__ */ w(p, {
300
+ kind: "loading",
301
+ title: e("stewards.common.loading")
302
+ }) : y.length === 0 ? /* @__PURE__ */ w("p", {
303
+ className: "text-sm text-(color:--color-text-secondary)",
304
+ children: e("stewards.playbooks.empty")
305
+ }) : /* @__PURE__ */ w("ul", {
306
+ className: "flex flex-col gap-1",
307
+ children: y.map((t) => /* @__PURE__ */ w("li", { children: /* @__PURE__ */ T("button", {
308
+ type: "button",
309
+ "aria-current": t.id === i ? "true" : void 0,
310
+ onClick: () => x(t.id),
311
+ className: `flex w-full flex-col items-start gap-1 rounded-md px-3 py-2 text-left text-sm focus-visible:outline-2 focus-visible:outline-(color:--color-focus-ring) ${t.id === i ? "bg-(--color-bg-muted)" : "hover:bg-(--color-bg-muted)"}`,
312
+ children: [/* @__PURE__ */ w("span", {
313
+ className: "text-(color:--color-text-primary)",
314
+ children: t.name
315
+ }), /* @__PURE__ */ T("span", {
316
+ className: "flex flex-wrap items-center gap-2 text-xs text-(color:--color-text-secondary)",
317
+ children: [
318
+ /* @__PURE__ */ w(u, {
319
+ tone: t.status === a.Active ? "success" : "neutral",
320
+ children: e(`stewards.playbooks.status.${t.status}`)
321
+ }),
322
+ t.stewardId ? e("stewards.playbooks.scopeSteward") : e("stewards.playbooks.scopeWorkspace"),
323
+ " ",
324
+ "· v",
325
+ t.currentVersion
326
+ ]
327
+ })]
328
+ }) }, t.id))
329
+ })]
330
+ }), /* @__PURE__ */ w("div", {
331
+ className: "lg:col-span-2",
332
+ children: s.kind === "teach" ? /* @__PURE__ */ w(c, {
333
+ stewardId: t.id,
334
+ playbook: b,
335
+ onSaved: x,
336
+ onClose: () => l(b ? { kind: "open" } : { kind: "none" })
337
+ }, b?.id ?? "new") : s.kind === "new" ? /* @__PURE__ */ w(A, {
338
+ stewardId: t.id,
339
+ playbook: null,
340
+ canUpdate: r,
341
+ onSaved: x,
342
+ onTeach: () => l({ kind: "teach" }),
343
+ onCancel: () => l({ kind: "none" })
344
+ }, "new") : s.kind === "open" && b ? /* @__PURE__ */ w(A, {
345
+ stewardId: t.id,
346
+ playbook: b,
347
+ canUpdate: r,
348
+ onSaved: x,
349
+ onTeach: () => l({ kind: "teach" }),
350
+ onCancel: () => l({ kind: "none" })
351
+ }, b.id) : /* @__PURE__ */ w(p, {
352
+ kind: "empty",
353
+ title: e("stewards.playbooks.pick")
354
+ })
355
+ })]
356
+ });
357
+ }
358
+ export { j as StewardPlaybooksPage };
359
+
360
+ //# sourceMappingURL=StewardPlaybooksPage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StewardPlaybooksPage.js","names":["REFETCH","isConflict","error","CombinedGraphQLErrors","PlaybookEditor","t","useStewardsT","creating","playbook","useGetBotmanorStewardPlaybookQuery","full","data","form","setForm","useState","keepSteps","setKeepSteps","show","setShow","create","createState","useCreateBotmanorStewardPlaybookMutation","saveVersion","saveState","useSaveBotmanorStewardPlaybookVersionMutation","setStatus","statusState","useSetBotmanorStewardPlaybookStatusMutation","version","value","playbookToForm","emptyPlaybookForm","set","patch","errors","validatePlaybook","err","code","failure","steps","versions","submit","saved","buildVersionInput","onSaved","made","buildManifest","splitLines","Card","FormField","FIELD_CLASS","canUpdate","row","j","i","r","Button","Alert","BotmanorStewardPlaybookStatus","onTeach","onCancel","v","relativeTime","StewardPlaybooksPage","useStewardOutlet","useStewardAbilities","selected","setSelected","mode","setMode","useListBotmanorStewardPlaybooksQuery","steward","playbooks","current","p","open","id","StateMessage","loading","Badge","TeachRecorder"],"sources":["../../../src/stewards/pages/StewardPlaybooksPage.tsx"],"sourcesContent":["import { CombinedGraphQLErrors } from '@apollo/client';\nimport { useState } from 'react';\nimport {\n useCreateBotmanorStewardPlaybookMutation,\n useGetBotmanorStewardPlaybookQuery,\n useListBotmanorStewardPlaybooksQuery,\n useSaveBotmanorStewardPlaybookVersionMutation,\n useSetBotmanorStewardPlaybookStatusMutation,\n type StewardPlaybookFieldsFragment,\n type StewardPlaybookVersionFieldsFragment,\n} from '../../generated/wspace-operations';\nimport { BotmanorStewardPlaybookStatus } from '../../generated/wspace-types';\nimport { FIELD_CLASS } from '../components/fieldClasses';\nimport { FormField } from '../components/FormField';\nimport { TeachRecorder } from '../components/TeachRecorder';\nimport { Alert, Badge, Button, Card, StateMessage } from '../components/ui';\nimport { useStewardsT } from '../i18n/useStewardsT';\nimport { useStewardAbilities } from '../permissions/useStewardPermissions';\nimport { relativeTime } from '../utils/dates';\nimport {\n buildManifest,\n buildVersionInput,\n emptyPlaybookForm,\n playbookToForm,\n splitLines,\n validatePlaybook,\n type PlaybookForm,\n} from '../utils/playbookForm';\nimport { useStewardOutlet } from './StewardLayout';\n\nconst REFETCH = ['ListBotmanorStewardPlaybooks', 'GetBotmanorStewardPlaybook'];\n\nfunction isConflict(error: Error | undefined): boolean {\n if (!error || !CombinedGraphQLErrors.is(error)) return false;\n return error.errors.some((e) => e.extensions?.code === 'CONFLICT');\n}\n\nfunction PlaybookEditor({\n stewardId,\n playbook,\n canUpdate,\n onSaved,\n onTeach,\n onCancel,\n}: {\n stewardId: string;\n playbook: StewardPlaybookFieldsFragment | null;\n canUpdate: boolean;\n onSaved: (id: string) => void;\n onTeach: () => void;\n onCancel: () => void;\n}) {\n const t = useStewardsT();\n const creating = playbook === null;\n const { data } = useGetBotmanorStewardPlaybookQuery({\n variables: { id: playbook?.id ?? '' },\n skip: creating,\n fetchPolicy: 'cache-and-network',\n });\n const full = data?.getBotmanorStewardPlaybook ?? playbook;\n const [form, setForm] = useState<{ version: number; value: PlaybookForm } | null>(null);\n const [keepSteps, setKeepSteps] = useState(true);\n const [show, setShow] = useState(false);\n const [create, createState] = useCreateBotmanorStewardPlaybookMutation({\n refetchQueries: REFETCH,\n });\n const [saveVersion, saveState] = useSaveBotmanorStewardPlaybookVersionMutation({\n refetchQueries: REFETCH,\n });\n const [setStatus, statusState] = useSetBotmanorStewardPlaybookStatusMutation({\n refetchQueries: REFETCH,\n });\n\n const version = full?.currentVersion ?? 0;\n const value =\n form && form.version === version\n ? form.value\n : full\n ? playbookToForm(full.name, full.current)\n : emptyPlaybookForm();\n const set = (patch: Partial<PlaybookForm>) => setForm({ version, value: { ...value, ...patch } });\n const errors = validatePlaybook(value, creating);\n const err = (code: (typeof errors)[number]) =>\n show && errors.includes(code) ? t(`stewards.playbooks.errors.${code}`) : null;\n const failure = createState.error ?? saveState.error ?? statusState.error;\n const steps = full?.current?.recordedStepCount ?? 0;\n const versions: StewardPlaybookVersionFieldsFragment[] =\n data?.getBotmanorStewardPlaybook?.versions ?? [];\n\n const submit = async () => {\n setShow(true);\n if (errors.length > 0) return;\n if (full) {\n const { data: saved } = await saveVersion({\n variables: {\n id: full.id,\n input: buildVersionInput(value, keepSteps),\n expectedVersion: full.currentVersion,\n },\n });\n if (saved) onSaved(saved.saveBotmanorStewardPlaybookVersion.id);\n } else {\n const { data: made } = await create({\n variables: {\n input: {\n stewardId,\n name: value.name.trim(),\n skillMd: value.skillMd,\n manifest: buildManifest(value),\n toolKeys: splitLines(value.toolKeys),\n },\n },\n });\n if (made) onSaved(made.createBotmanorStewardPlaybook.id);\n }\n };\n\n return (\n <Card\n title={creating ? t('stewards.playbooks.new') : (full?.name ?? '')}\n hint={\n full\n ? `${t('stewards.playbooks.colVersion')} ${full.currentVersion} · ${t(`stewards.playbooks.status.${full.status}`)}`\n : undefined\n }\n >\n <form\n className=\"flex flex-col gap-3\"\n onSubmit={(e) => {\n e.preventDefault();\n void submit().catch(() => undefined);\n }}\n >\n {creating && (\n <FormField\n label={t('stewards.playbooks.fieldName')}\n error={err('name') ?? err('nameLength')}\n >\n <input\n className={FIELD_CLASS}\n maxLength={255}\n value={value.name}\n onChange={(e) => set({ name: e.target.value })}\n />\n </FormField>\n )}\n <FormField\n label={t('stewards.playbooks.fieldSkill')}\n error={err('skillMd') ?? err('skillMdLength')}\n >\n <textarea\n className={`${FIELD_CLASS} min-h-48 font-mono`}\n readOnly={!canUpdate}\n value={value.skillMd}\n onChange={(e) => set({ skillMd: e.target.value })}\n />\n </FormField>\n <FormField label={t('stewards.playbooks.fieldWhen')}>\n <input\n className={FIELD_CLASS}\n value={value.whenToUse}\n onChange={(e) => set({ whenToUse: e.target.value })}\n />\n </FormField>\n <FormField label={t('stewards.playbooks.fieldReturns')}>\n <input\n className={FIELD_CLASS}\n value={value.returns}\n onChange={(e) => set({ returns: e.target.value })}\n />\n </FormField>\n <FormField label={t('stewards.playbooks.fieldFailure')}>\n <input\n className={FIELD_CLASS}\n value={value.failureHandling}\n onChange={(e) => set({ failureHandling: e.target.value })}\n />\n </FormField>\n <div className=\"grid grid-cols-1 gap-3 sm:grid-cols-2\">\n <FormField label={t('stewards.playbooks.fieldChecks')}>\n <textarea\n className={`${FIELD_CLASS} min-h-20`}\n value={value.checks}\n onChange={(e) => set({ checks: e.target.value })}\n />\n </FormField>\n <FormField label={t('stewards.playbooks.fieldBoundaries')}>\n <textarea\n className={`${FIELD_CLASS} min-h-20`}\n value={value.approvalBoundaries}\n onChange={(e) => set({ approvalBoundaries: e.target.value })}\n />\n </FormField>\n </div>\n <FormField\n label={t('stewards.playbooks.fieldTools')}\n help={t('stewards.playbooks.fieldToolsHelp')}\n >\n <textarea\n className={`${FIELD_CLASS} min-h-20 font-mono`}\n value={value.toolKeys}\n onChange={(e) => set({ toolKeys: e.target.value })}\n />\n </FormField>\n <fieldset className=\"flex flex-col gap-2\">\n <legend className=\"text-sm font-medium text-(color:--color-text-primary)\">\n {t('stewards.playbooks.inputsTitle')}\n </legend>\n {value.inputs.map((row, i) => (\n <div\n key={i}\n className=\"grid grid-cols-1 items-end gap-2 sm:grid-cols-[1fr_2fr_auto_auto]\"\n >\n <FormField label={t('stewards.playbooks.inputName')}>\n <input\n className={FIELD_CLASS}\n value={row.name}\n onChange={(e) =>\n set({\n inputs: value.inputs.map((r, j) =>\n j === i ? { ...r, name: e.target.value } : r\n ),\n })\n }\n />\n </FormField>\n <FormField label={t('stewards.playbooks.inputDescription')}>\n <input\n className={FIELD_CLASS}\n value={row.description}\n onChange={(e) =>\n set({\n inputs: value.inputs.map((r, j) =>\n j === i ? { ...r, description: e.target.value } : r\n ),\n })\n }\n />\n </FormField>\n <label className=\"flex items-center gap-2 pb-2 text-sm text-(color:--color-text-primary)\">\n <input\n type=\"checkbox\"\n checked={row.required}\n onChange={(e) =>\n set({\n inputs: value.inputs.map((r, j) =>\n j === i ? { ...r, required: e.target.checked } : r\n ),\n })\n }\n />\n {t('stewards.playbooks.inputRequired')}\n </label>\n <Button onClick={() => set({ inputs: value.inputs.filter((_, j) => j !== i) })}>\n {t('stewards.playbooks.removeInput')}\n </Button>\n </div>\n ))}\n {err('inputName') && <Alert>{err('inputName')}</Alert>}\n <div>\n <Button\n onClick={() =>\n set({ inputs: [...value.inputs, { name: '', description: '', required: false }] })\n }\n >\n {t('stewards.playbooks.addInput')}\n </Button>\n </div>\n </fieldset>\n {steps > 0 && (\n <div className=\"flex flex-col gap-1\">\n <label className=\"flex items-center gap-2 text-sm text-(color:--color-text-primary)\">\n <input\n type=\"checkbox\"\n checked={keepSteps}\n onChange={(e) => setKeepSteps(e.target.checked)}\n />\n {t('stewards.playbooks.keepSteps')} (\n {t('stewards.playbooks.savedSteps', { count: steps })})\n </label>\n <p className=\"text-xs text-(color:--color-text-secondary)\">\n {t('stewards.playbooks.maskedNote')}\n </p>\n </div>\n )}\n {isConflict(saveState.error) ? (\n <Alert>{t('stewards.playbooks.conflict')}</Alert>\n ) : (\n failure && (\n <Alert>\n {t('stewards.playbooks.saveError')} {failure.message}\n </Alert>\n )\n )}\n {canUpdate && (\n <div className=\"flex flex-wrap gap-2\">\n <Button\n type=\"submit\"\n variant=\"primary\"\n disabled={createState.loading || saveState.loading}\n >\n {createState.loading || saveState.loading\n ? t('stewards.playbooks.saving')\n : creating\n ? t('stewards.playbooks.create')\n : t('stewards.playbooks.save')}\n </Button>\n {full && full.status !== BotmanorStewardPlaybookStatus.Active && (\n <Button\n disabled={statusState.loading}\n onClick={() =>\n void setStatus({\n variables: { id: full.id, status: BotmanorStewardPlaybookStatus.Active },\n }).catch(() => undefined)\n }\n >\n {t('stewards.playbooks.activate')}\n </Button>\n )}\n {full && full.status !== BotmanorStewardPlaybookStatus.Archived && (\n <Button\n disabled={statusState.loading}\n onClick={() =>\n void setStatus({\n variables: { id: full.id, status: BotmanorStewardPlaybookStatus.Archived },\n }).catch(() => undefined)\n }\n >\n {t('stewards.playbooks.archive')}\n </Button>\n )}\n <Button onClick={onTeach}>{t('stewards.playbooks.teach')}</Button>\n <Button onClick={onCancel}>{t('stewards.common.cancel')}</Button>\n </div>\n )}\n </form>\n {versions.length > 0 && (\n <div className=\"mt-4\">\n <h3 className=\"mb-2 text-sm font-semibold text-(color:--color-text-primary)\">\n {t('stewards.playbooks.versions')}\n </h3>\n <ul className=\"flex flex-col gap-1 text-sm text-(color:--color-text-secondary)\">\n {versions.map((v) => (\n <li key={v.id}>\n {t('stewards.playbooks.versionRow', {\n version: v.version,\n author: t(`stewards.playbooks.authoredBy.${v.authoredBy}`),\n when: relativeTime(v.createdAt),\n })}\n {v.recordedStepCount > 0 &&\n ` · ${t('stewards.playbooks.savedSteps', { count: v.recordedStepCount })}`}\n </li>\n ))}\n </ul>\n </div>\n )}\n </Card>\n );\n}\n\ntype Mode = { kind: 'none' } | { kind: 'new' } | { kind: 'open' } | { kind: 'teach' };\n\nexport function StewardPlaybooksPage() {\n const t = useStewardsT();\n const { steward } = useStewardOutlet();\n const { canUpdate } = useStewardAbilities();\n const [selected, setSelected] = useState<string | null>(null);\n const [mode, setMode] = useState<Mode>({ kind: 'none' });\n const { data, loading, error } = useListBotmanorStewardPlaybooksQuery({\n variables: { stewardId: steward.id },\n fetchPolicy: 'cache-and-network',\n });\n const playbooks: StewardPlaybookFieldsFragment[] = data?.listBotmanorStewardPlaybooks ?? [];\n const current = playbooks.find((p) => p.id === selected) ?? null;\n const open = (id: string) => {\n setSelected(id);\n setMode({ kind: 'open' });\n };\n\n return (\n <div className=\"grid grid-cols-1 gap-4 lg:grid-cols-3\">\n <Card title={t('stewards.playbooks.title')} hint={t('stewards.playbooks.hint')}>\n {canUpdate && (\n <div className=\"mb-3 flex flex-wrap gap-2\">\n <Button\n variant=\"primary\"\n onClick={() => {\n setSelected(null);\n setMode({ kind: 'new' });\n }}\n >\n {t('stewards.playbooks.new')}\n </Button>\n <Button\n onClick={() => {\n setSelected(null);\n setMode({ kind: 'teach' });\n }}\n >\n {t('stewards.playbooks.teach')}\n </Button>\n </div>\n )}\n {error ? (\n <StateMessage kind=\"error\" title={t('stewards.common.errorTitle')} body={error.message} />\n ) : loading && playbooks.length === 0 ? (\n <StateMessage kind=\"loading\" title={t('stewards.common.loading')} />\n ) : playbooks.length === 0 ? (\n <p className=\"text-sm text-(color:--color-text-secondary)\">\n {t('stewards.playbooks.empty')}\n </p>\n ) : (\n <ul className=\"flex flex-col gap-1\">\n {playbooks.map((p) => (\n <li key={p.id}>\n <button\n type=\"button\"\n aria-current={p.id === selected ? 'true' : undefined}\n onClick={() => open(p.id)}\n className={`flex w-full flex-col items-start gap-1 rounded-md px-3 py-2 text-left text-sm focus-visible:outline-2 focus-visible:outline-(color:--color-focus-ring) ${p.id === selected ? 'bg-(--color-bg-muted)' : 'hover:bg-(--color-bg-muted)'}`}\n >\n <span className=\"text-(color:--color-text-primary)\">{p.name}</span>\n <span className=\"flex flex-wrap items-center gap-2 text-xs text-(color:--color-text-secondary)\">\n <Badge\n tone={\n p.status === BotmanorStewardPlaybookStatus.Active ? 'success' : 'neutral'\n }\n >\n {t(`stewards.playbooks.status.${p.status}`)}\n </Badge>\n {p.stewardId\n ? t('stewards.playbooks.scopeSteward')\n : t('stewards.playbooks.scopeWorkspace')}{' '}\n · v{p.currentVersion}\n </span>\n </button>\n </li>\n ))}\n </ul>\n )}\n </Card>\n <div className=\"lg:col-span-2\">\n {mode.kind === 'teach' ? (\n <TeachRecorder\n key={current?.id ?? 'new'}\n stewardId={steward.id}\n playbook={current}\n onSaved={open}\n onClose={() => setMode(current ? { kind: 'open' } : { kind: 'none' })}\n />\n ) : mode.kind === 'new' ? (\n <PlaybookEditor\n key=\"new\"\n stewardId={steward.id}\n playbook={null}\n canUpdate={canUpdate}\n onSaved={open}\n onTeach={() => setMode({ kind: 'teach' })}\n onCancel={() => setMode({ kind: 'none' })}\n />\n ) : mode.kind === 'open' && current ? (\n <PlaybookEditor\n key={current.id}\n stewardId={steward.id}\n playbook={current}\n canUpdate={canUpdate}\n onSaved={open}\n onTeach={() => setMode({ kind: 'teach' })}\n onCancel={() => setMode({ kind: 'none' })}\n />\n ) : (\n <StateMessage kind=\"empty\" title={t('stewards.playbooks.pick')} />\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8BA,IAAMA,IAAU,CAAC,gCAAgC,4BAA4B;AAE7E,SAASC,EAAW,GAAmC;CAErD,OADI,CAACC,KAAS,CAACC,EAAsB,GAAGD,CAAK,IAAU,KAChDA,EAAM,OAAO,MAAM,MAAM,EAAE,YAAY,SAAS,UAAU;AACnE;AAEA,SAASE,EAAe,EACtB,cACA,aACA,cACA,YACA,YACA,eAQC;CACD,IAAMC,IAAIC,EAAa,GACjBC,IAAWC,MAAa,MACxB,EAAE,YAASC,EAAmC;EAClD,WAAW,EAAE,IAAID,GAAU,MAAM,GAAG;EACpC,MAAMD;EACN,aAAa;CACf,CAAC,GACKG,IAAOC,GAAM,8BAA8BH,GAC3C,CAACI,GAAMC,KAAWC,EAA0D,IAAI,GAChF,CAACC,GAAWC,KAAgBF,EAAS,EAAI,GACzC,CAACG,GAAMC,KAAWJ,EAAS,EAAK,GAChC,CAACK,GAAQC,KAAeC,EAAyC,EACrE,gBAAgBrB,EAClB,CAAC,GACK,CAACsB,GAAaC,KAAaC,EAA8C,EAC7E,gBAAgBxB,EAClB,CAAC,GACK,CAACyB,GAAWC,KAAeC,EAA4C,EAC3E,gBAAgB3B,EAClB,CAAC,GAEK4B,IAAUlB,GAAM,kBAAkB,GAClCmB,IACJjB,KAAQA,EAAK,YAAYgB,IACrBhB,EAAK,QACLF,IACEoB,EAAepB,EAAK,MAAMA,EAAK,OAAO,IACtCqB,EAAkB,GACpBC,KAAO,MAAiCnB,EAAQ;EAAE;EAAS,OAAO;GAAE,GAAGgB;GAAO,GAAGI;EAAM;CAAE,CAAC,GAC1F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;IACnB,UAAU;IACC;IACX,SAASI;IACT,eAAeN,EAAQ,EAAE,MAAM,QAAQ,CAAC;IACxC,gBAAgBA,EAAQ,EAAE,MAAM,OAAO,CAAC;GACzC,GAPK,KAOL,IACCD,EAAK,SAAS,UAAUK,IAC1B,kBAACrE,GAAD;IAEE,WAAWmE,EAAQ;IACnB,UAAUE;IACC;IACX,SAASE;IACT,eAAeN,EAAQ,EAAE,MAAM,QAAQ,CAAC;IACxC,gBAAgBA,EAAQ,EAAE,MAAM,OAAO,CAAC;GACzC,GAPMI,EAAQ,EAOd,IAED,kBAACI,GAAD;IAAc,MAAK;IAAQ,OAAOxE,EAAE,yBAAyB;GAAI,CAAA;EAEhE,CAAA,CACF;;AAET"}
@@ -0,0 +1,37 @@
1
+ import { UpsertBotmanorStewardDutyInput, BotmanorStewardDutyKind } from '../../generated/wspace-types';
2
+ export declare const DUTY_KINDS: readonly BotmanorStewardDutyKind[];
3
+ /** Kinds that carry a `{ cron, timezone }` schedule. */
4
+ export declare function usesSchedule(kind: BotmanorStewardDutyKind): boolean;
5
+ /** Kinds that fire from an event and may filter by event type. */
6
+ export declare function usesEventType(kind: BotmanorStewardDutyKind): boolean;
7
+ export interface DutyForm {
8
+ id: string | null;
9
+ name: string;
10
+ kind: BotmanorStewardDutyKind;
11
+ prompt: string;
12
+ playbookId: string;
13
+ cron: string;
14
+ timezone: string;
15
+ url: string;
16
+ eventType: string;
17
+ dryRun: boolean;
18
+ }
19
+ export type DutyFormError = 'name' | 'nameLength' | 'promptOrPlaybook' | 'promptLength' | 'cron' | 'url' | 'eventTypeLength';
20
+ export declare function emptyDutyForm(timezone: string): DutyForm;
21
+ interface DutyLike {
22
+ id: string;
23
+ name: string;
24
+ kind: BotmanorStewardDutyKind;
25
+ prompt?: string | null;
26
+ playbookId?: string | null;
27
+ schedule?: Record<string, unknown> | null;
28
+ triggerConfig?: Record<string, unknown> | null;
29
+ dryRun: boolean;
30
+ }
31
+ export declare function dutyToForm(duty: DutyLike, defaultTimezone: string): DutyForm;
32
+ /** A five-field cron expression; the server owns the exact semantics. */
33
+ export declare function isCron(value: string): boolean;
34
+ export declare function validateDuty(form: DutyForm): DutyFormError[];
35
+ /** The mutation input; null when the form has errors. */
36
+ export declare function buildDutyInput(form: DutyForm, stewardId: string): UpsertBotmanorStewardDutyInput | null;
37
+ export {};
@@ -0,0 +1,84 @@
1
+ import { BotmanorStewardDutyKind as e } from "../../generated/wspace-types.js";
2
+ // src/stewards/utils/dutyForm.ts
3
+ var t = [
4
+ e.Schedule,
5
+ e.Watch,
6
+ e.Webhook,
7
+ e.AppEvent,
8
+ e.PlatformEvent,
9
+ e.ChannelMessage,
10
+ e.Proactive
11
+ ];
12
+ function n(t) {
13
+ return t === e.Schedule || t === e.Watch || t === e.Proactive;
14
+ }
15
+ function r(t) {
16
+ return t === e.Webhook || t === e.AppEvent || t === e.PlatformEvent || t === e.ChannelMessage;
17
+ }
18
+ var i = 255, a = 2e4, o = 128;
19
+ function s(t) {
20
+ return {
21
+ id: null,
22
+ name: "",
23
+ kind: e.Schedule,
24
+ prompt: "",
25
+ playbookId: "",
26
+ cron: "0 9 * * 1-5",
27
+ timezone: t,
28
+ url: "",
29
+ eventType: "",
30
+ dryRun: !1
31
+ };
32
+ }
33
+ function c(e) {
34
+ return typeof e == "string" ? e : "";
35
+ }
36
+ function l(e, t) {
37
+ return {
38
+ id: e.id,
39
+ name: e.name,
40
+ kind: e.kind,
41
+ prompt: e.prompt ?? "",
42
+ playbookId: e.playbookId ?? "",
43
+ cron: c(e.schedule?.cron),
44
+ timezone: c(e.schedule?.timezone) || t,
45
+ url: c(e.triggerConfig?.url),
46
+ eventType: c(e.triggerConfig?.eventType),
47
+ dryRun: e.dryRun
48
+ };
49
+ }
50
+ var u = /^(\*|\d+|\d+-\d+|\*\/\d+|\d+-\d+\/\d+|\d+(,\d+)+)(,(\*|\d+|\d+-\d+|\*\/\d+))*$/;
51
+ function d(e) {
52
+ let t = e.trim().split(/\s+/);
53
+ return t.length === 5 && t.every((e) => u.test(e));
54
+ }
55
+ function f(e) {
56
+ try {
57
+ let t = new URL(e);
58
+ return t.protocol === "https:" && t.hostname.length > 0;
59
+ } catch {
60
+ return !1;
61
+ }
62
+ }
63
+ function p(t) {
64
+ let s = [], c = t.name.trim();
65
+ return c === "" ? s.push("name") : c.length > i && s.push("nameLength"), t.prompt.trim() === "" && t.playbookId === "" && s.push("promptOrPlaybook"), t.prompt.length > a && s.push("promptLength"), n(t.kind) && !d(t.cron) && s.push("cron"), t.kind === e.Watch && !f(t.url.trim()) && s.push("url"), r(t.kind) && t.eventType.trim().length > o && s.push("eventTypeLength"), s;
66
+ }
67
+ function m(t, i) {
68
+ if (p(t).length > 0) return null;
69
+ let a = {
70
+ stewardId: i,
71
+ kind: t.kind,
72
+ name: t.name.trim(),
73
+ dryRun: t.dryRun,
74
+ prompt: t.prompt.trim() === "" ? null : t.prompt.trim(),
75
+ playbookId: t.playbookId === "" ? null : t.playbookId
76
+ };
77
+ return t.id && (a.id = t.id), n(t.kind) && (a.schedule = {
78
+ cron: t.cron.trim().replace(/\s+/g, " "),
79
+ timezone: t.timezone
80
+ }), t.kind === e.Watch ? a.triggerConfig = { url: t.url.trim() } : r(t.kind) && t.eventType.trim() !== "" && (a.triggerConfig = { eventType: t.eventType.trim() }), a;
81
+ }
82
+ export { t as DUTY_KINDS, m as buildDutyInput, l as dutyToForm, s as emptyDutyForm, d as isCron, r as usesEventType, n as usesSchedule, p as validateDuty };
83
+
84
+ //# sourceMappingURL=dutyForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dutyForm.js","names":["DUTY_KINDS","BotmanorStewardDutyKind","usesSchedule","kind","usesEventType","MAX_NAME","MAX_PROMPT","MAX_EVENT_TYPE","emptyDutyForm","text","value","dutyToForm","duty","\"cron\"","\"timezone\"","defaultTimezone","\"url\"","\"eventType\"","CRON_FIELD","isCron","fields","f","isPublicHttps","u","validateDuty","errors","name","form","buildDutyInput","input"],"sources":["../../../src/stewards/utils/dutyForm.ts"],"sourcesContent":["import type { UpsertBotmanorStewardDutyInput } from '../../generated/wspace-types';\nimport { BotmanorStewardDutyKind } from '../../generated/wspace-types';\n\nexport const DUTY_KINDS: readonly BotmanorStewardDutyKind[] = [\n BotmanorStewardDutyKind.Schedule,\n BotmanorStewardDutyKind.Watch,\n BotmanorStewardDutyKind.Webhook,\n BotmanorStewardDutyKind.AppEvent,\n BotmanorStewardDutyKind.PlatformEvent,\n BotmanorStewardDutyKind.ChannelMessage,\n BotmanorStewardDutyKind.Proactive,\n];\n\n/** Kinds that carry a `{ cron, timezone }` schedule. */\nexport function usesSchedule(kind: BotmanorStewardDutyKind): boolean {\n return (\n kind === BotmanorStewardDutyKind.Schedule ||\n kind === BotmanorStewardDutyKind.Watch ||\n kind === BotmanorStewardDutyKind.Proactive\n );\n}\n\n/** Kinds that fire from an event and may filter by event type. */\nexport function usesEventType(kind: BotmanorStewardDutyKind): boolean {\n return (\n kind === BotmanorStewardDutyKind.Webhook ||\n kind === BotmanorStewardDutyKind.AppEvent ||\n kind === BotmanorStewardDutyKind.PlatformEvent ||\n kind === BotmanorStewardDutyKind.ChannelMessage\n );\n}\n\nexport interface DutyForm {\n id: string | null;\n name: string;\n kind: BotmanorStewardDutyKind;\n prompt: string;\n playbookId: string;\n cron: string;\n timezone: string;\n url: string;\n eventType: string;\n dryRun: boolean;\n}\n\nexport type DutyFormError =\n 'name' | 'nameLength' | 'promptOrPlaybook' | 'promptLength' | 'cron' | 'url' | 'eventTypeLength';\n\nconst MAX_NAME = 255;\nconst MAX_PROMPT = 20_000;\nconst MAX_EVENT_TYPE = 128;\n\nexport function emptyDutyForm(timezone: string): DutyForm {\n return {\n id: null,\n name: '',\n kind: BotmanorStewardDutyKind.Schedule,\n prompt: '',\n playbookId: '',\n cron: '0 9 * * 1-5',\n timezone,\n url: '',\n eventType: '',\n dryRun: false,\n };\n}\n\ninterface DutyLike {\n id: string;\n name: string;\n kind: BotmanorStewardDutyKind;\n prompt?: string | null;\n playbookId?: string | null;\n schedule?: Record<string, unknown> | null;\n triggerConfig?: Record<string, unknown> | null;\n dryRun: boolean;\n}\n\nfunction text(value: unknown): string {\n return typeof value === 'string' ? value : '';\n}\n\nexport function dutyToForm(duty: DutyLike, defaultTimezone: string): DutyForm {\n return {\n id: duty.id,\n name: duty.name,\n kind: duty.kind,\n prompt: duty.prompt ?? '',\n playbookId: duty.playbookId ?? '',\n cron: text(duty.schedule?.['cron']),\n timezone: text(duty.schedule?.['timezone']) || defaultTimezone,\n url: text(duty.triggerConfig?.['url']),\n eventType: text(duty.triggerConfig?.['eventType']),\n dryRun: duty.dryRun,\n };\n}\n\nconst CRON_FIELD = /^(\\*|\\d+|\\d+-\\d+|\\*\\/\\d+|\\d+-\\d+\\/\\d+|\\d+(,\\d+)+)(,(\\*|\\d+|\\d+-\\d+|\\*\\/\\d+))*$/;\n\n/** A five-field cron expression; the server owns the exact semantics. */\nexport function isCron(value: string): boolean {\n const fields = value.trim().split(/\\s+/);\n return fields.length === 5 && fields.every((f) => CRON_FIELD.test(f));\n}\n\nfunction isPublicHttps(value: string): boolean {\n try {\n const u = new URL(value);\n return u.protocol === 'https:' && u.hostname.length > 0;\n } catch {\n return false;\n }\n}\n\nexport function validateDuty(form: DutyForm): DutyFormError[] {\n const errors: DutyFormError[] = [];\n const name = form.name.trim();\n if (name === '') errors.push('name');\n else if (name.length > MAX_NAME) errors.push('nameLength');\n if (form.prompt.trim() === '' && form.playbookId === '') errors.push('promptOrPlaybook');\n if (form.prompt.length > MAX_PROMPT) errors.push('promptLength');\n if (usesSchedule(form.kind) && !isCron(form.cron)) errors.push('cron');\n if (form.kind === BotmanorStewardDutyKind.Watch && !isPublicHttps(form.url.trim()))\n errors.push('url');\n if (usesEventType(form.kind) && form.eventType.trim().length > MAX_EVENT_TYPE)\n errors.push('eventTypeLength');\n return errors;\n}\n\n/** The mutation input; null when the form has errors. */\nexport function buildDutyInput(\n form: DutyForm,\n stewardId: string\n): UpsertBotmanorStewardDutyInput | null {\n if (validateDuty(form).length > 0) return null;\n const input: UpsertBotmanorStewardDutyInput = {\n stewardId,\n kind: form.kind,\n name: form.name.trim(),\n dryRun: form.dryRun,\n prompt: form.prompt.trim() === '' ? null : form.prompt.trim(),\n playbookId: form.playbookId === '' ? null : form.playbookId,\n };\n if (form.id) input.id = form.id;\n if (usesSchedule(form.kind)) {\n input.schedule = { cron: form.cron.trim().replace(/\\s+/g, ' '), timezone: form.timezone };\n }\n if (form.kind === BotmanorStewardDutyKind.Watch) {\n input.triggerConfig = { url: form.url.trim() };\n } else if (usesEventType(form.kind) && form.eventType.trim() !== '') {\n input.triggerConfig = { eventType: form.eventType.trim() };\n }\n return input;\n}\n"],"mappings":";;AAGA,IAAaA,IAAiD;CAC5DC,EAAwB;CACxBA,EAAwB;CACxBA,EAAwB;CACxBA,EAAwB;CACxBA,EAAwB;CACxBA,EAAwB;CACxBA,EAAwB;AAC1B;AAGA,SAAgBC,EAAa,GAAwC;CACnE,OACEC,MAASF,EAAwB,YACjCE,MAASF,EAAwB,SACjCE,MAASF,EAAwB;AAErC;AAGA,SAAgBG,EAAc,GAAwC;CACpE,OACED,MAASF,EAAwB,WACjCE,MAASF,EAAwB,YACjCE,MAASF,EAAwB,iBACjCE,MAASF,EAAwB;AAErC;AAkBA,IAAMI,IAAW,KACXC,IAAa,KACbC,IAAiB;AAEvB,SAAgBC,EAAc,GAA4B;CACxD,OAAO;EACL,IAAI;EACJ,MAAM;EACN,MAAMP,EAAwB;EAC9B,QAAQ;EACR,YAAY;EACZ,MAAM;EACN;EACA,KAAK;EACL,WAAW;EACX,QAAQ;CACV;AACF;AAaA,SAASQ,EAAK,GAAwB;CACpC,OAAO,OAAOC,KAAU,WAAWA,IAAQ;AAC7C;AAEA,SAAgBC,EAAW,GAAgB,GAAmC;CAC5E,OAAO;EACL,IAAIC,EAAK;EACT,MAAMA,EAAK;EACX,MAAMA,EAAK;EACX,QAAQA,EAAK,UAAU;EACvB,YAAYA,EAAK,cAA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SAAS,GAAG,OAAO;CAC1C,IAAME,IAAwC;EAC5C;EACA,MAAMF,EAAK;EACX,MAAMA,EAAK,KAAK,KAAK;EACrB,QAAQA,EAAK;EACb,QAAQA,EAAK,OAAO,KAAK,MAAM,KAAK,OAAOA,EAAK,OAAO,KAAK;EAC5D,YAAYA,EAAK,eAAe,KAAK,OAAOA,EAAK;CACnD;CAUA,OATIA,EAAK,OAAI,EAAM,KAAKA,EAAK,KACzBzB,EAAayB,EAAK,IAAI,MACxB,EAAM,WAAW;EAAE,MAAMA,EAAK,KAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG;EAAG,UAAUA,EAAK;CAAS,IAEtFA,EAAK,SAAS1B,EAAwB,QACxC,EAAM,gBAAgB,EAAE,KAAK0B,EAAK,IAAI,KAAK,EAAE,IACpCvB,EAAcuB,EAAK,IAAI,KAAKA,EAAK,UAAU,KAAK,MAAM,OAC/D,EAAM,gBAAgB,EAAE,WAAWA,EAAK,UAAU,KAAK,EAAE,IAEpDE;AACT"}
@@ -0,0 +1,21 @@
1
+ import { BotmanorStewardMemoryDiffOp } from '../../generated/wspace-types';
2
+ export type MemoryFormError = 'key' | 'body' | 'bodyLength';
3
+ export declare function validateMemory(key: string, body: string, creating: boolean): MemoryFormError[];
4
+ export interface DiffLine {
5
+ op: BotmanorStewardMemoryDiffOp;
6
+ oldLine?: number | null;
7
+ newLine?: number | null;
8
+ text: string;
9
+ }
10
+ export type DiffRow = {
11
+ kind: 'line';
12
+ line: DiffLine;
13
+ } | {
14
+ kind: 'gap';
15
+ hidden: number;
16
+ };
17
+ /**
18
+ * Collapses long unchanged runs: keeps `context` equal lines around each change
19
+ * and replaces the rest with a gap row stating how many lines are hidden.
20
+ */
21
+ export declare function collapseDiff(lines: readonly DiffLine[], context?: number): DiffRow[];
@@ -0,0 +1,29 @@
1
+ import { BotmanorStewardMemoryDiffOp as e } from "../../generated/wspace-types.js";
2
+ // src/stewards/utils/memory.ts
3
+ var t = /^[a-z0-9][a-z0-9._-]{0,127}$/, n = 5e4;
4
+ function r(e, r, i) {
5
+ let a = [];
6
+ return i && !t.test(e) && a.push("key"), r.trim() === "" && a.push("body"), r.length > n && a.push("bodyLength"), a;
7
+ }
8
+ function i(t, n = 2) {
9
+ let r = Array(t.length).fill(!1);
10
+ t.forEach((i, a) => {
11
+ if (i.op !== e.Equal) for (let e = Math.max(0, a - n); e <= Math.min(t.length - 1, a + n); e++) r[e] = !0;
12
+ });
13
+ let i = [], a = 0;
14
+ return t.forEach((e, t) => {
15
+ r[t] ? (a > 0 && i.push({
16
+ kind: "gap",
17
+ hidden: a
18
+ }), a = 0, i.push({
19
+ kind: "line",
20
+ line: e
21
+ })) : a += 1;
22
+ }), a > 0 && i.push({
23
+ kind: "gap",
24
+ hidden: a
25
+ }), i;
26
+ }
27
+ export { i as collapseDiff, r as validateMemory };
28
+
29
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","names":["MEMORY_KEY_PATTERN","MEMORY_MAX_BODY","validateMemory","errors","creating","key","body","collapseDiff","keep","lines","line","BotmanorStewardMemoryDiffOp","j","i","context","rows","hidden"],"sources":["../../../src/stewards/utils/memory.ts"],"sourcesContent":["import { BotmanorStewardMemoryDiffOp } from '../../generated/wspace-types';\n\nconst MEMORY_KEY_PATTERN = /^[a-z0-9][a-z0-9._-]{0,127}$/;\nconst MEMORY_MAX_BODY = 50_000;\n\nexport type MemoryFormError = 'key' | 'body' | 'bodyLength';\n\nexport function validateMemory(key: string, body: string, creating: boolean): MemoryFormError[] {\n const errors: MemoryFormError[] = [];\n if (creating && !MEMORY_KEY_PATTERN.test(key)) errors.push('key');\n if (body.trim() === '') errors.push('body');\n if (body.length > MEMORY_MAX_BODY) errors.push('bodyLength');\n return errors;\n}\n\nexport interface DiffLine {\n op: BotmanorStewardMemoryDiffOp;\n oldLine?: number | null;\n newLine?: number | null;\n text: string;\n}\n\nexport type DiffRow = { kind: 'line'; line: DiffLine } | { kind: 'gap'; hidden: number };\n\n/**\n * Collapses long unchanged runs: keeps `context` equal lines around each change\n * and replaces the rest with a gap row stating how many lines are hidden.\n */\nexport function collapseDiff(lines: readonly DiffLine[], context = 2): DiffRow[] {\n const keep = new Array<boolean>(lines.length).fill(false);\n lines.forEach((line, i) => {\n if (line.op === BotmanorStewardMemoryDiffOp.Equal) return;\n for (let j = Math.max(0, i - context); j <= Math.min(lines.length - 1, i + context); j++)\n keep[j] = true;\n });\n const rows: DiffRow[] = [];\n let hidden = 0;\n lines.forEach((line, i) => {\n if (keep[i]) {\n if (hidden > 0) rows.push({ kind: 'gap', hidden });\n hidden = 0;\n rows.push({ kind: 'line', line });\n } else {\n hidden += 1;\n }\n });\n if (hidden > 0) rows.push({ kind: 'gap', hidden });\n return rows;\n}\n"],"mappings":";;AAEA,IAAMA,IAAqB,gCACrBC,IAAkB;AAIxB,SAAgBC,EAAe,GAAa,GAAc,GAAsC;CAC9F,IAAMC,IAA4B,CAAC;CAInC,OAHIC,KAAY,CAACJ,EAAmB,KAAKK,CAAG,KAAGF,EAAO,KAAK,KAAK,GAC5DG,EAAK,KAAK,MAAM,MAAIH,EAAO,KAAK,MAAM,GACtCG,EAAK,SAASL,KAAiBE,EAAO,KAAK,YAAY,GACpDA;AACT;AAeA,SAAgBI,EAAa,GAA4B,IAAU,GAAc;CAC/E,IAAMC,IAAW,MAAeC,EAAM,MAAM,CAAC,CAAC,KAAK,EAAK;CACxD,EAAM,SAAS,GAAM,MAAM;EACzB,IAAIC,EAAK,OAAOC,EAA4B,OAC5C,KAAK,IAAIC,IAAI,KAAK,IAAI,GAAGC,IAAIC,CAAO,GAAGF,KAAK,KAAK,IAAIH,EAAM,SAAS,GAAGI,IAAIC,CAAO,GAAG,KACnF,EAAKF,KAAK;CACd,CAAC;CACD,IAAMG,IAAkB,CAAC,GACrBC,IAAS;CAWb,OAVAP,EAAM,SAAS,GAAM,MAAM;EACzB,AAAID,EAAKK,MACHG,IAAS,KAAGD,EAAK,KAAK;GAAE,MAAM;GAAO;EAAO,CAAC,GACjD,IAAS,GACTA,EAAK,KAAK;GAAE,MAAM;GAAQ;EAAK,CAAC,KAEhC,KAAU;CAEd,CAAC,GACGC,IAAS,KAAGD,EAAK,KAAK;EAAE,MAAM;EAAO;CAAO,CAAC,GAC1CA;AACT"}