@powerhousedao/workflow 6.2.3-dev.83 → 6.2.3-dev.85

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 (142) hide show
  1. package/README.md +3 -1
  2. package/dist/browser/{BlockSelector-DHVzUGjW.js → BlockSelector-BKAJwJ4Y.js} +77 -8
  3. package/dist/browser/BlockSelector-BKAJwJ4Y.js.map +1 -0
  4. package/dist/browser/{PieceMarkdown-U6OUTwRi.js → PieceMarkdown-DSdZd-Jc.js} +34 -8
  5. package/dist/browser/PieceMarkdown-DSdZd-Jc.js.map +1 -0
  6. package/dist/browser/{connection-form-D2qAEHsl.js → connection-form-DltdMa8F.js} +3 -3
  7. package/dist/browser/{connection-form-D2qAEHsl.js.map → connection-form-DltdMa8F.js.map} +1 -1
  8. package/dist/browser/{data-tree-BOuPR-2J.js → data-tree-DAw8e0j8.js} +25 -12
  9. package/dist/browser/data-tree-DAw8e0j8.js.map +1 -0
  10. package/dist/browser/document-models/index.js +2 -2
  11. package/dist/browser/document-models/workflow/index.js +2 -2
  12. package/dist/browser/{document-models-DSK5cn8B.js → document-models-C2SAP1SX.js} +2 -2
  13. package/dist/browser/{document-models-DSK5cn8B.js.map → document-models-C2SAP1SX.js.map} +1 -1
  14. package/dist/{node/editor-C_eWGGi8.mjs → browser/editor--J61vLSC.js} +630 -72
  15. package/dist/browser/editor--J61vLSC.js.map +1 -0
  16. package/dist/browser/{editor-0XPrGeLT.js → editor-CZLe6CAF.js} +5 -5
  17. package/dist/browser/{editor-0XPrGeLT.js.map → editor-CZLe6CAF.js.map} +1 -1
  18. package/dist/browser/{editor--59WtNaj.js → editor-Dl6lzxkM.js} +158 -2676
  19. package/dist/browser/editor-Dl6lzxkM.js.map +1 -0
  20. package/dist/browser/editors/connection-editor/module.js +1 -1
  21. package/dist/browser/editors/runtime/index.js +1 -1
  22. package/dist/browser/editors/workflow-editor/module.js +1 -1
  23. package/dist/browser/editors/workflow-studio/module.js +1 -1
  24. package/dist/browser/index.js +3 -3
  25. package/dist/browser/{module-eOpxJVIl.js → module-mFCt9WHJ.js} +2 -2
  26. package/dist/browser/module-mFCt9WHJ.js.map +1 -0
  27. package/dist/browser/reactor/index.js +2 -2
  28. package/dist/browser/{runtime-queries-LAcyniYz.js → runtime-queries-D81Ghpok.js} +105 -4
  29. package/dist/browser/runtime-queries-D81Ghpok.js.map +1 -0
  30. package/dist/browser/trigger-text-BSVi5oGZ.js +3045 -0
  31. package/dist/browser/trigger-text-BSVi5oGZ.js.map +1 -0
  32. package/dist/browser/{upgrade-manifests-CLYUPqBs.js → upgrade-manifests-C2Qa6myy.js} +2 -2
  33. package/dist/browser/{upgrade-manifests-CLYUPqBs.js.map → upgrade-manifests-C2Qa6myy.js.map} +1 -1
  34. package/dist/browser/{workflow-Cn1UP-eJ.js → workflow-BFdnSGRD.js} +2 -2
  35. package/dist/browser/{workflow-Cn1UP-eJ.js.map → workflow-BFdnSGRD.js.map} +1 -1
  36. package/dist/node/{BlockSelector-D2UAnFpN.mjs → BlockSelector-Bcb5NJ_X.mjs} +77 -8
  37. package/dist/node/BlockSelector-Bcb5NJ_X.mjs.map +1 -0
  38. package/dist/node/{PieceMarkdown-DwpCBISY.mjs → PieceMarkdown-CUSdTMH4.mjs} +34 -8
  39. package/dist/node/{PieceMarkdown-DwpCBISY.mjs.map → PieceMarkdown-CUSdTMH4.mjs.map} +1 -1
  40. package/dist/node/{connection-form-Btmejfyn.mjs → connection-form-DF5418sz.mjs} +3 -3
  41. package/dist/node/{connection-form-Btmejfyn.mjs.map → connection-form-DF5418sz.mjs.map} +1 -1
  42. package/dist/node/{data-tree-rZiK2Ev-.mjs → data-tree-CebWVI_P.mjs} +25 -12
  43. package/dist/node/{data-tree-rZiK2Ev-.mjs.map → data-tree-CebWVI_P.mjs.map} +1 -1
  44. package/dist/node/document-models/index.mjs +2 -2
  45. package/dist/node/document-models/workflow/index.mjs +2 -2
  46. package/dist/{browser/editor-BD-5ClkW.js → node/editor-BmRWQvRs.mjs} +629 -72
  47. package/dist/node/editor-BmRWQvRs.mjs.map +1 -0
  48. package/dist/node/{editor-ChJMxbeM.mjs → editor-J0op3mM7.mjs} +5 -5
  49. package/dist/node/{editor-ChJMxbeM.mjs.map → editor-J0op3mM7.mjs.map} +1 -1
  50. package/dist/node/{editor-U6trS0QO.mjs → editor-UzRtZp-A.mjs} +276 -2793
  51. package/dist/node/editor-UzRtZp-A.mjs.map +1 -0
  52. package/dist/node/editors/connection-editor/module.mjs +1 -1
  53. package/dist/node/editors/runtime/index.mjs +1 -1
  54. package/dist/node/editors/workflow-editor/module.mjs +1 -1
  55. package/dist/node/editors/workflow-studio/module.mjs +1 -1
  56. package/dist/node/index.mjs +3 -3
  57. package/dist/node/{module-D9Zx5Zow.mjs → module-CuTg45ct.mjs} +2 -2
  58. package/dist/{browser/module-eOpxJVIl.js.map → node/module-CuTg45ct.mjs.map} +1 -1
  59. package/dist/node/pieces/ai/descriptor.json +1 -1
  60. package/dist/node/pieces/ai/package.json +1 -1
  61. package/dist/node/pieces/reactor/descriptor.json +1 -1
  62. package/dist/node/pieces/reactor/package.json +1 -1
  63. package/dist/node/{runtime-queries-CmrHBPRw.mjs → runtime-queries-VXJsWno5.mjs} +263 -7
  64. package/dist/node/runtime-queries-VXJsWno5.mjs.map +1 -0
  65. package/dist/node/trigger-text-BvEzEani.mjs +3045 -0
  66. package/dist/node/trigger-text-BvEzEani.mjs.map +1 -0
  67. package/dist/node/{upgrade-manifests-C4akaA_X.mjs → upgrade-manifests-BA5OaR4H.mjs} +2 -2
  68. package/dist/node/{upgrade-manifests-C4akaA_X.mjs.map → upgrade-manifests-BA5OaR4H.mjs.map} +1 -1
  69. package/dist/node/{workflow-DqF9VsBQ.mjs → workflow-BgURVzdc.mjs} +2 -2
  70. package/dist/node/{workflow-DqF9VsBQ.mjs.map → workflow-BgURVzdc.mjs.map} +1 -1
  71. package/dist/powerhouse.manifest.json +2 -2
  72. package/dist/style.css +1 -1
  73. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts +1 -1
  74. package/dist/types/document-models/workflow/v1/gen/schema/types.d.ts.map +1 -1
  75. package/dist/types/editors/shared/controls.d.ts.map +1 -1
  76. package/dist/types/editors/shared/data-tree.d.ts.map +1 -1
  77. package/dist/types/editors/shared/icons.d.ts +1 -0
  78. package/dist/types/editors/shared/icons.d.ts.map +1 -1
  79. package/dist/types/editors/workflow-editor/editor.d.ts.map +1 -1
  80. package/dist/types/editors/workflow-editor/runtime-client.d.ts +39 -0
  81. package/dist/types/editors/workflow-editor/runtime-client.d.ts.map +1 -1
  82. package/dist/types/editors/workflow-editor/runtime-context.d.ts +10 -1
  83. package/dist/types/editors/workflow-editor/runtime-context.d.ts.map +1 -1
  84. package/dist/types/editors/workflow-editor/runtime-queries.d.ts +21 -1
  85. package/dist/types/editors/workflow-editor/runtime-queries.d.ts.map +1 -1
  86. package/dist/types/editors/workflow-editor/ui/BlockSelector.d.ts.map +1 -1
  87. package/dist/types/editors/workflow-editor/ui/PieceMarkdown.d.ts +2 -1
  88. package/dist/types/editors/workflow-editor/ui/PieceMarkdown.d.ts.map +1 -1
  89. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts +4 -0
  90. package/dist/types/editors/workflow-editor/ui/PropertyForm.d.ts.map +1 -1
  91. package/dist/types/editors/workflow-editor/ui/block-meta.d.ts.map +1 -1
  92. package/dist/types/editors/workflow-editor/ui/blocks.d.ts +4 -0
  93. package/dist/types/editors/workflow-editor/ui/blocks.d.ts.map +1 -1
  94. package/dist/types/editors/workflow-editor/ui/manual-inputs.d.ts +7 -0
  95. package/dist/types/editors/workflow-editor/ui/manual-inputs.d.ts.map +1 -0
  96. package/dist/types/editors/workflow-editor/ui/manual-inputs.test.d.ts +2 -0
  97. package/dist/types/editors/workflow-editor/ui/manual-inputs.test.d.ts.map +1 -0
  98. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts +9 -0
  99. package/dist/types/editors/workflow-editor/ui/query-keys.d.ts.map +1 -1
  100. package/dist/types/editors/workflow-studio/components/RunDialog.d.ts +7 -0
  101. package/dist/types/editors/workflow-studio/components/RunDialog.d.ts.map +1 -0
  102. package/dist/types/editors/workflow-studio/components/RunsTable.d.ts.map +1 -1
  103. package/dist/types/editors/workflow-studio/components/RunsView.d.ts +3 -1
  104. package/dist/types/editors/workflow-studio/components/RunsView.d.ts.map +1 -1
  105. package/dist/types/editors/workflow-studio/components/Sidebar.d.ts +3 -0
  106. package/dist/types/editors/workflow-studio/components/Sidebar.d.ts.map +1 -1
  107. package/dist/types/editors/workflow-studio/components/Waitpoints.d.ts +49 -0
  108. package/dist/types/editors/workflow-studio/components/Waitpoints.d.ts.map +1 -0
  109. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts +3 -0
  110. package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts.map +1 -1
  111. package/dist/types/editors/workflow-studio/components/WorkflowStudio.d.ts.map +1 -1
  112. package/dist/types/editors/workflow-studio/components/run-dialog.test.d.ts +2 -0
  113. package/dist/types/editors/workflow-studio/components/run-dialog.test.d.ts.map +1 -0
  114. package/dist/types/editors/workflow-studio/components/run-format.d.ts +2 -1
  115. package/dist/types/editors/workflow-studio/components/run-format.d.ts.map +1 -1
  116. package/dist/types/editors/workflow-studio/components/waitpoints-view.test.d.ts +2 -0
  117. package/dist/types/editors/workflow-studio/components/waitpoints-view.test.d.ts.map +1 -0
  118. package/dist/types/editors/workflow-studio/components/waitpoints.test.d.ts +2 -0
  119. package/dist/types/editors/workflow-studio/components/waitpoints.test.d.ts.map +1 -0
  120. package/dist/types/test/graphql-server.d.ts +9 -0
  121. package/dist/types/test/graphql-server.d.ts.map +1 -0
  122. package/dist/types/test/ui/manual-inputs.spec.d.ts +2 -0
  123. package/dist/types/test/ui/manual-inputs.spec.d.ts.map +1 -0
  124. package/dist/types/test/waitpoint-record.d.ts +3 -0
  125. package/dist/types/test/waitpoint-record.d.ts.map +1 -0
  126. package/dist/workflow.css +2 -0
  127. package/package.json +9 -9
  128. package/dist/browser/BlockSelector-DHVzUGjW.js.map +0 -1
  129. package/dist/browser/PieceMarkdown-U6OUTwRi.js.map +0 -1
  130. package/dist/browser/data-tree-BOuPR-2J.js.map +0 -1
  131. package/dist/browser/editor--59WtNaj.js.map +0 -1
  132. package/dist/browser/editor-BD-5ClkW.js.map +0 -1
  133. package/dist/browser/runtime-queries-LAcyniYz.js.map +0 -1
  134. package/dist/browser/trigger-text-Co-dn9x-.js +0 -513
  135. package/dist/browser/trigger-text-Co-dn9x-.js.map +0 -1
  136. package/dist/node/BlockSelector-D2UAnFpN.mjs.map +0 -1
  137. package/dist/node/editor-C_eWGGi8.mjs.map +0 -1
  138. package/dist/node/editor-U6trS0QO.mjs.map +0 -1
  139. package/dist/node/module-D9Zx5Zow.mjs.map +0 -1
  140. package/dist/node/runtime-queries-CmrHBPRw.mjs.map +0 -1
  141. package/dist/node/trigger-text-CAiRCG2X.mjs +0 -512
  142. package/dist/node/trigger-text-CAiRCG2X.mjs.map +0 -1
@@ -0,0 +1,3045 @@
1
+ import { i as __toESM } from "./rolldown-runtime-B4iAMlE-.mjs";
2
+ import { Ot as parseScheduleConfig, St as expandDocumentRefs, dt as stepBlock, et as MANUAL_TRIGGER, gt as DOCUMENT_REF_KEY, nt as SCHEDULE_TRIGGER, pt as triggerBlock, st as WEBHOOK_TRIGGER, wt as isDocumentRefMarker, xt as documentRefsIn } from "./runtime-queries-VXJsWno5.mjs";
3
+ import { t as blockKey } from "./block-type-kX-27vVt.mjs";
4
+ import { Bt as textAreaClass, Ft as Switch, Ht as Icon, It as Tabs, Lt as Toggle, Mt as IconButton, Nt as Segmented, Ot as Button, Pt as Select, Q as useResolvedProp, Rt as Tooltip, Ut as isIconName, Vt as textInputClass, Z as useOptionSearch, at as isPropVisible, ct as settingFor, f as blockMeta, ft as withSetting, it as isEmptyValue, jt as Hint, kt as FieldError, ot as parsePropList, q as useDynamicCache, st as resolverInputFor, t as BlockLogo, ut as stripOptions, zt as invalidClass } from "./BlockSelector-Bcb5NJ_X.mjs";
5
+ import { useSetSelectedNode } from "@powerhousedao/reactor-browser";
6
+ import { Fragment, Suspense, createContext, lazy, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
7
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
+ import { createPortal } from "react-dom";
9
+ //#region editors/shared/pending-echo.ts
10
+ function keyOf(value) {
11
+ return JSON.stringify(value, (_, entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? Object.fromEntries(Object.entries(entry).sort(([a], [b]) => a.localeCompare(b))) : entry);
12
+ }
13
+ function usePendingEcho(saved, onChange) {
14
+ const savedKey = keyOf(saved);
15
+ const [sent, setSent] = useState([]);
16
+ const [seen, setSeen] = useState(savedKey);
17
+ let pending = sent;
18
+ if (seen !== savedKey) {
19
+ const echo = sent.findIndex((value) => keyOf(value) === savedKey);
20
+ pending = echo === -1 ? [] : sent.slice(echo + 1);
21
+ setSeen(savedKey);
22
+ setSent(pending);
23
+ }
24
+ const value = pending.length > 0 ? pending[pending.length - 1] : saved;
25
+ return {
26
+ value,
27
+ commit: (next) => {
28
+ if (keyOf(next) === keyOf(value)) return;
29
+ setSent([...pending, next]);
30
+ onChange(next, value);
31
+ },
32
+ onBlur: (event) => {
33
+ const inside = event.currentTarget.contains(event.relatedTarget);
34
+ if (pending.length > 0 && !inside && keyOf(value) === savedKey) setSent([]);
35
+ }
36
+ };
37
+ }
38
+ //#endregion
39
+ //#region editors/workflow-editor/ui/canvas-menu.ts
40
+ function hasNextPort(model, id, portsOf) {
41
+ if (model.trigger?.id === id) return true;
42
+ const step = model.steps.find((entry) => entry.id === id);
43
+ return step ? portsOf(stepBlock(step))?.includes("next") ?? false : false;
44
+ }
45
+ function contextMenuItems(target, model, portsOf) {
46
+ switch (target.kind) {
47
+ case "step": {
48
+ const skipped = model.steps.find((entry) => entry.id === target.id)?.skip === true;
49
+ return [
50
+ {
51
+ id: "open",
52
+ label: "Open settings"
53
+ },
54
+ {
55
+ id: "addBelow",
56
+ label: "Add step below",
57
+ disabled: !hasNextPort(model, target.id, portsOf)
58
+ },
59
+ {
60
+ id: "duplicate",
61
+ label: "Duplicate step"
62
+ },
63
+ {
64
+ id: "toggleSkip",
65
+ label: skipped ? "Stop skipping this step" : "Skip this step"
66
+ },
67
+ {
68
+ id: "removeStep",
69
+ label: "Remove step"
70
+ }
71
+ ];
72
+ }
73
+ case "trigger": return [
74
+ {
75
+ id: "open",
76
+ label: "Open settings"
77
+ },
78
+ {
79
+ id: "addBelow",
80
+ label: "Add step below",
81
+ disabled: !model.trigger
82
+ },
83
+ {
84
+ id: "changeTrigger",
85
+ label: "Change trigger"
86
+ },
87
+ {
88
+ id: "removeTrigger",
89
+ label: "Remove trigger"
90
+ }
91
+ ];
92
+ case "edge": return [{
93
+ id: "insertStep",
94
+ label: "Insert step here"
95
+ }, {
96
+ id: "removeEdge",
97
+ label: "Remove edge"
98
+ }];
99
+ case "pane": return [
100
+ {
101
+ id: "addStep",
102
+ label: "Add step here"
103
+ },
104
+ {
105
+ id: "selectAll",
106
+ label: "Select all steps",
107
+ disabled: model.steps.length === 0
108
+ },
109
+ {
110
+ id: "fitView",
111
+ label: "Fit view"
112
+ }
113
+ ];
114
+ }
115
+ }
116
+ const MENU_ITEM_HEIGHT = 28;
117
+ const VIEWPORT_MARGIN = 8;
118
+ function menuHeight(items) {
119
+ return items * MENU_ITEM_HEIGHT + 8;
120
+ }
121
+ function clampToViewport(at, extent, available) {
122
+ return Math.max(VIEWPORT_MARGIN, Math.min(at, available - extent - VIEWPORT_MARGIN));
123
+ }
124
+ function menuPosition(point, size, viewport) {
125
+ const place = (at, extent, available) => clampToViewport(at + extent > available - VIEWPORT_MARGIN ? at - extent : at, extent, available);
126
+ return {
127
+ x: place(point.x, size.width, viewport.width),
128
+ y: place(point.y, size.height, viewport.height)
129
+ };
130
+ }
131
+ const ANCHOR_GAP = 8;
132
+ function anchorLeftPosition(anchor, size, viewport) {
133
+ const left = anchor.left - ANCHOR_GAP - size.width;
134
+ return {
135
+ x: clampToViewport(left >= VIEWPORT_MARGIN ? left : anchor.right + ANCHOR_GAP, size.width, viewport.width),
136
+ y: clampToViewport(anchor.top, size.height, viewport.height)
137
+ };
138
+ }
139
+ //#endregion
140
+ //#region editors/workflow-editor/ui/document-shape.ts
141
+ const MAX_DEPTH$1 = 6;
142
+ const normalize = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, "");
143
+ function typeName(node, kind) {
144
+ if (node.kind === kind.NON_NULL_TYPE) {
145
+ const inner = typeName(node.type, kind);
146
+ return {
147
+ name: inner.name,
148
+ display: `${inner.display}!`
149
+ };
150
+ }
151
+ if (node.kind === kind.LIST_TYPE) {
152
+ const inner = typeName(node.type, kind);
153
+ return {
154
+ name: inner.name,
155
+ display: `[${inner.display}]`
156
+ };
157
+ }
158
+ return {
159
+ name: node.name.value,
160
+ display: node.name.value
161
+ };
162
+ }
163
+ async function stateFieldsFromSdl(model) {
164
+ if (!model.schema) return {};
165
+ const { Kind, parse } = await import("./graphql-D76E1YiQ.mjs").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
166
+ let definitions;
167
+ try {
168
+ definitions = parse(model.schema).definitions;
169
+ } catch {
170
+ return {};
171
+ }
172
+ const types = /* @__PURE__ */ new Map();
173
+ for (const def of definitions) {
174
+ if (def.kind !== Kind.OBJECT_TYPE_DEFINITION && def.kind !== Kind.INPUT_OBJECT_TYPE_DEFINITION) continue;
175
+ types.set(normalize(def.name.value), (def.fields ?? []).map((field) => ({
176
+ name: field.name.value,
177
+ type: field.type
178
+ })));
179
+ }
180
+ const root = [`${normalize(model.name)}state`, `${normalize(model.name)}globalstate`].map((candidate) => types.get(candidate)).find((fields) => fields !== void 0);
181
+ const build = (fields, depth) => Object.fromEntries(fields.map((field) => {
182
+ const { name, display } = typeName(field.type, Kind);
183
+ const inner = types.get(normalize(name));
184
+ return [field.name, inner && inner.length > 0 && depth < MAX_DEPTH$1 ? build(inner, depth + 1) : display];
185
+ }));
186
+ return root ? build(root, 0) : {};
187
+ }
188
+ function documentShape(reference, globalState) {
189
+ return {
190
+ header: {
191
+ id: reference.documentId,
192
+ documentType: reference.documentType,
193
+ name: "String",
194
+ slug: "String",
195
+ branch: reference.branch,
196
+ revision: reference.revision,
197
+ createdAtUtcIso: "DateTime!",
198
+ lastModifiedAtUtcIso: "DateTime!"
199
+ },
200
+ state: { global: globalState }
201
+ };
202
+ }
203
+ //#endregion
204
+ //#region editors/workflow-editor/ui/variable-types.ts
205
+ const VARIABLE_TYPE_LABEL = {
206
+ TEXT: "Text",
207
+ NUMBER: "Number",
208
+ BOOLEAN: "True or false",
209
+ JSON: "JSON",
210
+ SECRET: "Secret"
211
+ };
212
+ const VARIABLE_TYPES = Object.keys(VARIABLE_TYPE_LABEL);
213
+ const DECIMAL$1 = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
214
+ function parseTypedValue(type, raw) {
215
+ const trimmed = raw.trim();
216
+ switch (type) {
217
+ case "TEXT": return {
218
+ ok: true,
219
+ value: raw === "" ? null : raw
220
+ };
221
+ case "NUMBER":
222
+ if (trimmed === "") return {
223
+ ok: true,
224
+ value: null
225
+ };
226
+ return DECIMAL$1.test(trimmed) ? {
227
+ ok: true,
228
+ value: Number(trimmed)
229
+ } : {
230
+ ok: false,
231
+ error: "Not a number"
232
+ };
233
+ case "BOOLEAN":
234
+ if (trimmed === "true") return {
235
+ ok: true,
236
+ value: true
237
+ };
238
+ if (trimmed === "false") return {
239
+ ok: true,
240
+ value: false
241
+ };
242
+ return {
243
+ ok: false,
244
+ error: "Not true or false"
245
+ };
246
+ case "JSON":
247
+ if (trimmed === "") return {
248
+ ok: true,
249
+ value: null
250
+ };
251
+ try {
252
+ return {
253
+ ok: true,
254
+ value: JSON.parse(trimmed)
255
+ };
256
+ } catch (error) {
257
+ return {
258
+ ok: false,
259
+ error: `Not valid JSON: ${error instanceof Error ? error.message : String(error)}`
260
+ };
261
+ }
262
+ case "SECRET": return {
263
+ ok: false,
264
+ error: "Secrets are set through the secret field"
265
+ };
266
+ }
267
+ }
268
+ function valueMismatch(type, value) {
269
+ if (value === null || value === void 0) return null;
270
+ switch (type) {
271
+ case "TEXT": return typeof value === "string" ? null : "Not text";
272
+ case "NUMBER": return typeof value === "number" ? null : "Not a number";
273
+ case "BOOLEAN": return typeof value === "boolean" ? null : "Not true or false";
274
+ case "JSON": return null;
275
+ case "SECRET": return typeof value === "string" ? null : "Not a secret reference";
276
+ }
277
+ }
278
+ function convertVariableValue(value, from, to) {
279
+ if (from === to) return value;
280
+ if (from === "SECRET" || to === "SECRET") return null;
281
+ if (to === "JSON" || value === null || value === void 0) return value ?? null;
282
+ if (to === "TEXT") return typeof value === "string" ? value : JSON.stringify(value);
283
+ if (typeof value === "string") {
284
+ const parsed = parseTypedValue(to, value);
285
+ if (parsed.ok) return parsed.value;
286
+ }
287
+ return value;
288
+ }
289
+ //#endregion
290
+ //#region editors/workflow-editor/ui/expression-scope.ts
291
+ const EMPTY_SCOPE = {
292
+ value: {},
293
+ captions: {}
294
+ };
295
+ const MAX_DEPTH = 6;
296
+ const MAX_ARRAY_ITEMS = 25;
297
+ function capValue(value, depth = 0) {
298
+ if (value === null || typeof value !== "object") return value;
299
+ if (depth >= MAX_DEPTH) return Array.isArray(value) ? "[…]" : "{…}";
300
+ if (Array.isArray(value)) return value.slice(0, MAX_ARRAY_ITEMS).map((item) => capValue(item, depth + 1));
301
+ return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, capValue(entry, depth + 1)]));
302
+ }
303
+ function upstreamStepIds(model, stepId) {
304
+ const incoming = /* @__PURE__ */ new Map();
305
+ for (const edge of model.edges) incoming.set(edge.to, [...incoming.get(edge.to) ?? [], edge.from]);
306
+ const upstream = /* @__PURE__ */ new Set();
307
+ const queue = [stepId];
308
+ while (queue.length > 0) for (const from of incoming.get(queue.pop()) ?? []) if (!upstream.has(from)) {
309
+ upstream.add(from);
310
+ queue.push(from);
311
+ }
312
+ return upstream;
313
+ }
314
+ function formatRunTime(startedAt, now = /* @__PURE__ */ new Date()) {
315
+ const date = new Date(startedAt);
316
+ if (Number.isNaN(date.getTime())) return startedAt;
317
+ const sameDay = date.toDateString() === now.toDateString();
318
+ const time = date.toLocaleTimeString([], {
319
+ hour: "2-digit",
320
+ minute: "2-digit"
321
+ });
322
+ return sameDay ? time : `${date.toLocaleDateString([], {
323
+ month: "short",
324
+ day: "numeric"
325
+ })} ${time}`;
326
+ }
327
+ const hasOutput = (step) => (step.status === "SUCCEEDED" || step.status === "REPLAYED") && step.output !== void 0 && step.output !== null;
328
+ async function withDocuments(value, documentOutput) {
329
+ const references = documentRefsIn(value);
330
+ if (references.length === 0) return value;
331
+ const key = (reference) => `${reference.branch}:${reference.documentId}`;
332
+ const shapeOf = async (reference) => {
333
+ try {
334
+ if (documentOutput) return await documentOutput(reference);
335
+ } catch {}
336
+ return documentShape(reference, {});
337
+ };
338
+ const shapes = new Map(await Promise.all(references.map(async (reference) => [key(reference), await shapeOf(reference)])));
339
+ return expandDocumentRefs(value, (reference) => shapes.get(key(reference)));
340
+ }
341
+ async function buildExpressionScope(options) {
342
+ const { model, latestRun } = options;
343
+ const documents = (value) => withDocuments(value, options.documentOutput);
344
+ const runCaption = latestRun ? `from run ${formatRunTime(latestRun.startedAt, options.now)}` : void 0;
345
+ const runSteps = new Map((latestRun?.steps ?? []).filter(hasOutput).map((step) => [step.stepKey, step]));
346
+ const value = {};
347
+ const captions = {};
348
+ const testCaption = (sample) => `from test ${formatRunTime(sample.testedAt, options.now)}`;
349
+ const tested = async (block) => block.lastTest && options.testOutput ? options.testOutput(block.id).catch(() => void 0) : void 0;
350
+ if (model.trigger) {
351
+ const sample = await tested(model.trigger);
352
+ if (sample) {
353
+ value.trigger = { payload: capValue(await documents(sample.value)) };
354
+ captions["trigger.payload"] = testCaption(sample);
355
+ } else if (runCaption && latestRun?.triggerPayload !== void 0 && latestRun.triggerPayload !== null) {
356
+ value.trigger = { payload: capValue(await documents(latestRun.triggerPayload)) };
357
+ captions["trigger.payload"] = runCaption;
358
+ } else {
359
+ value.trigger = { payload: await options.authoredOutput(triggerBlock(model.trigger), model.trigger.config) };
360
+ captions["trigger.payload"] = "declared type";
361
+ }
362
+ }
363
+ const upstream = upstreamStepIds(model, options.stepId);
364
+ const steps = {};
365
+ await Promise.all(model.steps.filter((step) => upstream.has(step.id)).map(async (step) => {
366
+ const sample = await tested(step);
367
+ if (sample) {
368
+ steps[step.key] = { output: capValue(await documents(sample.value)) };
369
+ captions[`steps.${step.key}.output`] = testCaption(sample);
370
+ return;
371
+ }
372
+ const journaled = runSteps.get(step.key);
373
+ if (runCaption && journaled && journaled.pieceName === step.pieceName && journaled.blockName === step.actionName) {
374
+ steps[step.key] = { output: capValue(await documents(journaled.output)) };
375
+ captions[`steps.${step.key}.output`] = runCaption;
376
+ return;
377
+ }
378
+ steps[step.key] = { output: await options.authoredOutput(stepBlock(step), step.config) };
379
+ captions[`steps.${step.key}.output`] = "declared type";
380
+ }));
381
+ if (Object.keys(steps).length > 0) value.steps = steps;
382
+ if (model.variables.length > 0) {
383
+ value.variables = Object.fromEntries(model.variables.map((variable) => [variable.key, variable.type === "SECRET" ? "secret" : variable.value ?? null]));
384
+ captions.variables = "workflow variables";
385
+ for (const variable of model.variables) if (variable.type) captions[`variables.${variable.key}`] = VARIABLE_TYPE_LABEL[variable.type].toLowerCase();
386
+ }
387
+ return {
388
+ value,
389
+ captions
390
+ };
391
+ }
392
+ const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
393
+ function childPath(parent, key, parentIsArray) {
394
+ if (parentIsArray) return `${parent}[${key}]`;
395
+ if (!parent) return key;
396
+ return IDENTIFIER.test(key) ? `${parent}.${key}` : `${parent}[${JSON.stringify(key)}]`;
397
+ }
398
+ //#endregion
399
+ //#region editors/workflow-editor/ui/expression-tokens.ts
400
+ const EMBEDDED_EXPRESSION = /(?<!\\)\{\{\s*([^{}]+?)\s*\}\}/g;
401
+ function splitExpressionTokens(value) {
402
+ const tokens = [];
403
+ let last = 0;
404
+ for (const match of value.matchAll(EMBEDDED_EXPRESSION)) {
405
+ const index = match.index;
406
+ if (index > last) tokens.push({
407
+ kind: "text",
408
+ text: value.slice(last, index)
409
+ });
410
+ tokens.push({
411
+ kind: "expression",
412
+ text: match[0],
413
+ expression: match[1]
414
+ });
415
+ last = index + match[0].length;
416
+ }
417
+ if (last < value.length) tokens.push({
418
+ kind: "text",
419
+ text: value.slice(last)
420
+ });
421
+ return tokens;
422
+ }
423
+ function hasExpressions(value) {
424
+ return typeof value === "string" && new RegExp(EMBEDDED_EXPRESSION).test(value);
425
+ }
426
+ function describeExpression(expression) {
427
+ const terms = expression.split("||");
428
+ const path = terms[0].trim();
429
+ const hasFallback = terms.length > 1;
430
+ const segments = path.split(".");
431
+ switch (segments[0]) {
432
+ case "steps": return {
433
+ root: "steps",
434
+ stepKey: segments[1] ?? "",
435
+ rest: segments.slice(2).join("."),
436
+ hasFallback
437
+ };
438
+ case "trigger": return {
439
+ root: "trigger",
440
+ rest: segments.slice(1).join("."),
441
+ hasFallback
442
+ };
443
+ case "variables": return {
444
+ root: "variables",
445
+ rest: segments.slice(1).join("."),
446
+ hasFallback
447
+ };
448
+ default: return {
449
+ root: "other",
450
+ rest: path,
451
+ hasFallback
452
+ };
453
+ }
454
+ }
455
+ //#endregion
456
+ //#region editors/workflow-editor/ui/ExpressionPicker.tsx
457
+ const ScopeSourceContext = createContext(void 0);
458
+ const ExpressionScopeSourceProvider = ScopeSourceContext.Provider;
459
+ function useScopeSource() {
460
+ return useContext(ScopeSourceContext);
461
+ }
462
+ const TargetContext = createContext(null);
463
+ function ExpressionTargetProvider(props) {
464
+ const [target, setTarget] = useState(null);
465
+ const value = useMemo(() => ({
466
+ target,
467
+ setTarget,
468
+ stepBlocks: props.stepBlocks,
469
+ triggerBlock: props.triggerBlock
470
+ }), [
471
+ target,
472
+ props.stepBlocks,
473
+ props.triggerBlock
474
+ ]);
475
+ return /* @__PURE__ */ jsx(TargetContext.Provider, {
476
+ value,
477
+ children: props.children
478
+ });
479
+ }
480
+ function useExpressionTarget() {
481
+ return useContext(TargetContext);
482
+ }
483
+ function fieldAnchor(element) {
484
+ const rect = (element?.closest("label,div") ?? element)?.getBoundingClientRect();
485
+ if (!rect) return {
486
+ left: window.innerWidth,
487
+ right: window.innerWidth,
488
+ top: 0
489
+ };
490
+ return {
491
+ left: rect.left,
492
+ right: rect.right,
493
+ top: rect.top
494
+ };
495
+ }
496
+ function useExpressionField(options) {
497
+ const id = useId();
498
+ const context = useExpressionTarget();
499
+ const insertRef = useRef(options.insert);
500
+ useEffect(() => {
501
+ insertRef.current = options.insert;
502
+ });
503
+ const { stepId, label } = options;
504
+ return {
505
+ active: context?.target?.id === id,
506
+ focus: (event) => {
507
+ context?.setTarget({
508
+ id,
509
+ stepId,
510
+ label,
511
+ anchor: fieldAnchor(event?.currentTarget),
512
+ insert: (expression) => insertRef.current(expression)
513
+ });
514
+ }
515
+ };
516
+ }
517
+ function preview(value) {
518
+ if (value === null) return "null";
519
+ if (value === void 0) return "";
520
+ if (Array.isArray(value)) return `[${value.length}]`;
521
+ if (typeof value === "object") return "{…}";
522
+ const text = typeof value === "string" ? value : JSON.stringify(value) ?? "";
523
+ return text.length > 28 ? `${text.slice(0, 28)}…` : text;
524
+ }
525
+ function isExpandable(value) {
526
+ return value !== null && typeof value === "object" && Object.keys(value).length > 0;
527
+ }
528
+ function entriesOf(value) {
529
+ if (Array.isArray(value)) return value.map((item, i) => [String(i), item]);
530
+ if (value !== null && typeof value === "object") return Object.entries(value);
531
+ return [];
532
+ }
533
+ function Caption(props) {
534
+ if (!props.text) return null;
535
+ return /* @__PURE__ */ jsx("span", {
536
+ className: "ml-auto shrink-0 pl-2 text-[10px] italic text-muted-foreground/80",
537
+ children: props.text
538
+ });
539
+ }
540
+ function ValueNode(props) {
541
+ const context = useExpressionTarget();
542
+ const [open, setOpen] = useState(props.depth < 2);
543
+ const expandable = isExpandable(props.value);
544
+ const stepKey = /^steps\.([^.]+)$/.exec(props.path)?.[1];
545
+ const nodeBlock = stepKey ? context?.stepBlocks[stepKey] : props.path === "trigger" ? context?.triggerBlock : void 0;
546
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
547
+ className: "flex items-center gap-1 rounded px-1 py-0.5 hover:bg-muted/50",
548
+ style: { paddingLeft: props.depth * 14 + 4 },
549
+ children: [
550
+ expandable ? /* @__PURE__ */ jsx("button", {
551
+ type: "button",
552
+ className: "w-3 shrink-0 text-[10px] text-muted-foreground/80",
553
+ onClick: () => setOpen((value) => !value),
554
+ children: open ? "▾" : "▸"
555
+ }) : /* @__PURE__ */ jsx("span", { className: "w-3 shrink-0" }),
556
+ /* @__PURE__ */ jsxs("button", {
557
+ type: "button",
558
+ className: "flex min-w-0 flex-1 items-baseline gap-2 text-left",
559
+ title: `{{${props.path}}}`,
560
+ onClick: () => props.onPick(props.path),
561
+ children: [nodeBlock ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(BlockLogo, {
562
+ block: nodeBlock,
563
+ size: 16
564
+ }), /* @__PURE__ */ jsx("span", {
565
+ className: "shrink-0 text-xs font-medium text-foreground",
566
+ children: blockMeta(nodeBlock).displayName
567
+ })] }) : /* @__PURE__ */ jsx("span", {
568
+ className: "shrink-0 font-mono text-xs text-foreground",
569
+ children: props.name
570
+ }), /* @__PURE__ */ jsx("span", {
571
+ className: "truncate text-[11px] text-muted-foreground/80",
572
+ children: preview(props.value)
573
+ })]
574
+ }),
575
+ /* @__PURE__ */ jsx(Caption, { text: props.captions[props.path] })
576
+ ]
577
+ }), expandable && open ? entriesOf(props.value).map(([key, child]) => /* @__PURE__ */ jsx(ValueNode, {
578
+ name: key,
579
+ path: childPath(props.path, key, Array.isArray(props.value)),
580
+ value: child,
581
+ depth: props.depth + 1,
582
+ captions: props.captions,
583
+ onPick: props.onPick
584
+ }, key)) : null] });
585
+ }
586
+ const SEARCH_DEPTH = 6;
587
+ const SEARCH_LIMIT = 200;
588
+ function flatten(value, path, depth, out) {
589
+ for (const [key, child] of entriesOf(value)) {
590
+ const nested = childPath(path, key, Array.isArray(value));
591
+ out.push({
592
+ path: nested,
593
+ value: child
594
+ });
595
+ if (depth < SEARCH_DEPTH && isExpandable(child)) flatten(child, nested, depth + 1, out);
596
+ }
597
+ }
598
+ function SearchResults(props) {
599
+ const matches = useMemo(() => {
600
+ const all = [];
601
+ flatten(props.scope.value, "", 0, all);
602
+ const lowered = props.query.toLowerCase();
603
+ return all.filter((entry) => entry.path.toLowerCase().includes(lowered)).slice(0, SEARCH_LIMIT);
604
+ }, [props.scope, props.query]);
605
+ if (matches.length === 0) return /* @__PURE__ */ jsx("div", {
606
+ className: "px-2 py-1 text-xs text-muted-foreground/80",
607
+ children: "No matches"
608
+ });
609
+ return /* @__PURE__ */ jsx(Fragment$1, { children: matches.map((entry) => /* @__PURE__ */ jsxs("button", {
610
+ type: "button",
611
+ className: "flex w-full items-baseline gap-2 rounded px-2 py-0.5 text-left hover:bg-muted/50",
612
+ title: `{{${entry.path}}}`,
613
+ onClick: () => props.onPick(entry.path),
614
+ children: [/* @__PURE__ */ jsx("span", {
615
+ className: "min-w-0 truncate font-mono text-[11px] text-foreground",
616
+ children: entry.path
617
+ }), /* @__PURE__ */ jsx("span", {
618
+ className: "truncate text-[10px] text-muted-foreground/80",
619
+ children: preview(entry.value)
620
+ })]
621
+ }, entry.path)) });
622
+ }
623
+ const POPUP_SIZE = {
624
+ width: 420,
625
+ height: 520
626
+ };
627
+ function ExpressionPickerPopup() {
628
+ const context = useExpressionTarget();
629
+ const target = context?.target ?? null;
630
+ const [query, setQuery] = useState("");
631
+ const [state, setState] = useState({ kind: "idle" });
632
+ const scopeSource = useScopeSource();
633
+ const containerRef = useRef(null);
634
+ const stepId = target?.stepId;
635
+ const hasTarget = target !== null;
636
+ useEffect(() => {
637
+ if (!hasTarget || !scopeSource) return;
638
+ let alive = true;
639
+ setState((current) => current.kind === "ready" && current.stepId === stepId ? current : { kind: "loading" });
640
+ scopeSource.load({ stepId }).then((scope) => {
641
+ if (alive) setState({
642
+ kind: "ready",
643
+ scope,
644
+ stepId
645
+ });
646
+ }, (error) => {
647
+ if (alive) setState({
648
+ kind: "error",
649
+ message: error instanceof Error ? error.message : String(error)
650
+ });
651
+ });
652
+ return () => {
653
+ alive = false;
654
+ };
655
+ }, [
656
+ hasTarget,
657
+ stepId,
658
+ scopeSource
659
+ ]);
660
+ const targetId = target?.id;
661
+ useEffect(() => setQuery(""), [targetId]);
662
+ const close = context?.setTarget;
663
+ useEffect(() => {
664
+ if (!hasTarget || !close) return;
665
+ const dismiss = () => close(null);
666
+ const outside = (event) => !containerRef.current?.contains(event.target);
667
+ const onMouseDown = (event) => {
668
+ if (outside(event)) dismiss();
669
+ };
670
+ const onKeyDown = (event) => {
671
+ if (event.key === "Escape") dismiss();
672
+ };
673
+ const onScroll = (event) => {
674
+ if (outside(event)) dismiss();
675
+ };
676
+ window.addEventListener("mousedown", onMouseDown);
677
+ window.addEventListener("keydown", onKeyDown);
678
+ window.addEventListener("scroll", onScroll, true);
679
+ return () => {
680
+ window.removeEventListener("mousedown", onMouseDown);
681
+ window.removeEventListener("keydown", onKeyDown);
682
+ window.removeEventListener("scroll", onScroll, true);
683
+ };
684
+ }, [hasTarget, close]);
685
+ if (!context || !scopeSource || !target) return null;
686
+ const pick = (path) => {
687
+ target.insert(`{{${path}}}`);
688
+ context.setTarget(null);
689
+ };
690
+ const scope = state.kind === "ready" && state.stepId === stepId ? state.scope : EMPTY_SCOPE;
691
+ const empty = entriesOf(scope.value).length === 0;
692
+ const position = anchorLeftPosition(target.anchor, POPUP_SIZE, {
693
+ width: window.innerWidth,
694
+ height: window.innerHeight
695
+ });
696
+ return createPortal(/* @__PURE__ */ jsxs("div", {
697
+ ref: containerRef,
698
+ className: "workflow-expression-popup fixed flex flex-col rounded-md border border-solid border-foreground/10 bg-card shadow-lg",
699
+ onMouseDown: (event) => {
700
+ if (!(event.target instanceof HTMLInputElement)) event.preventDefault();
701
+ },
702
+ style: {
703
+ left: position.x,
704
+ top: position.y,
705
+ width: POPUP_SIZE.width,
706
+ maxHeight: POPUP_SIZE.height
707
+ },
708
+ children: [
709
+ /* @__PURE__ */ jsxs("div", {
710
+ className: "flex items-center gap-2 px-3 py-1.5",
711
+ children: [
712
+ /* @__PURE__ */ jsx("span", {
713
+ className: "font-mono text-[11px] text-muted-foreground",
714
+ children: "{}"
715
+ }),
716
+ /* @__PURE__ */ jsxs("span", {
717
+ className: "min-w-0 truncate text-xs text-muted-foreground",
718
+ children: [
719
+ "Insert into",
720
+ " ",
721
+ /* @__PURE__ */ jsx("span", {
722
+ className: "font-semibold text-foreground",
723
+ children: target.label
724
+ })
725
+ ]
726
+ }),
727
+ /* @__PURE__ */ jsx("button", {
728
+ type: "button",
729
+ className: "ml-auto text-[11px] text-muted-foreground/80 hover:text-muted-foreground",
730
+ title: "Close",
731
+ onClick: () => context.setTarget(null),
732
+ children: "✕"
733
+ })
734
+ ]
735
+ }),
736
+ /* @__PURE__ */ jsx("div", {
737
+ className: "px-3 pb-1.5",
738
+ children: /* @__PURE__ */ jsx("input", {
739
+ className: "w-full rounded border border-foreground/10 px-2 py-1.5 text-sm",
740
+ placeholder: "Search paths…",
741
+ value: query,
742
+ onChange: (event) => setQuery(event.target.value)
743
+ })
744
+ }),
745
+ /* @__PURE__ */ jsx("div", {
746
+ className: "min-h-0 flex-1 overflow-y-auto px-1 pb-1",
747
+ children: state.kind === "error" ? /* @__PURE__ */ jsx("div", {
748
+ className: "px-2 py-1 text-xs text-wf-fail",
749
+ children: state.message
750
+ }) : state.kind === "loading" ? /* @__PURE__ */ jsx("div", {
751
+ className: "px-2 py-1 text-xs text-muted-foreground/80",
752
+ children: "Loading…"
753
+ }) : empty ? /* @__PURE__ */ jsx("div", {
754
+ className: "px-2 py-1 text-xs text-muted-foreground/80",
755
+ children: "No values available for this field yet."
756
+ }) : query.trim() ? /* @__PURE__ */ jsx(SearchResults, {
757
+ scope,
758
+ query: query.trim(),
759
+ onPick: pick
760
+ }) : entriesOf(scope.value).map(([key, value]) => /* @__PURE__ */ jsx(ValueNode, {
761
+ name: key,
762
+ path: key,
763
+ value,
764
+ depth: 0,
765
+ captions: scope.captions,
766
+ onPick: pick
767
+ }, key))
768
+ })
769
+ ]
770
+ }), document.body);
771
+ }
772
+ function ExpressionPickerButton(props) {
773
+ if (!useScopeSource()) return null;
774
+ return /* @__PURE__ */ jsxs("button", {
775
+ type: "button",
776
+ title: "Insert data from the trigger or an earlier step",
777
+ className: `inline-flex h-6 shrink-0 items-center gap-1 rounded-md px-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 ${props.active ? "bg-wf-run/10 text-wf-run" : "text-muted-foreground opacity-0 hover:bg-accent hover:text-foreground focus-visible:opacity-100 group-focus-within/field:opacity-100 group-hover/field:opacity-100 [@media(hover:none)]:opacity-100"}`,
778
+ onClick: props.onFocusField,
779
+ children: [/* @__PURE__ */ jsx(Icon, {
780
+ name: "braces",
781
+ className: "h-3.5 w-3.5"
782
+ }), "Insert data"]
783
+ });
784
+ }
785
+ function Chip(props) {
786
+ const ref = describeExpression(props.expression);
787
+ const block = ref.stepKey ? props.stepBlocks[ref.stepKey] : void 0;
788
+ const head = ref.root === "steps" ? ref.stepKey : ref.root === "trigger" ? "trigger" : ref.root === "variables" ? "var" : "";
789
+ return /* @__PURE__ */ jsxs("span", {
790
+ className: "inline-flex max-w-full items-center gap-1 rounded border border-solid border-wf-run/20 bg-wf-run/10 px-1 py-px font-mono text-[11px] text-wf-run",
791
+ title: `{{${props.expression}}}`,
792
+ children: [
793
+ block ? /* @__PURE__ */ jsx(BlockLogo, {
794
+ block,
795
+ size: 12
796
+ }) : null,
797
+ head ? /* @__PURE__ */ jsx("span", {
798
+ className: "font-semibold",
799
+ children: head
800
+ }) : null,
801
+ /* @__PURE__ */ jsx("span", {
802
+ className: "truncate",
803
+ children: ref.root === "other" ? ref.rest : ref.rest || "*"
804
+ }),
805
+ ref.hasFallback ? /* @__PURE__ */ jsx("span", {
806
+ className: "text-wf-run",
807
+ children: "||…"
808
+ }) : null
809
+ ]
810
+ });
811
+ }
812
+ function ExpressionTokenLine(props) {
813
+ const context = useExpressionTarget();
814
+ const tokens = splitExpressionTokens(props.value);
815
+ if (!tokens.some((token) => token.kind === "expression")) return null;
816
+ return /* @__PURE__ */ jsx("div", {
817
+ className: "mt-1.5 flex flex-wrap items-center gap-1 text-xs text-muted-foreground",
818
+ children: tokens.map((token, index) => token.kind === "text" ? /* @__PURE__ */ jsx("span", {
819
+ className: "max-w-40 truncate whitespace-pre",
820
+ children: token.text
821
+ }, index) : /* @__PURE__ */ jsx(Chip, {
822
+ expression: token.expression,
823
+ stepBlocks: context?.stepBlocks ?? {}
824
+ }, index))
825
+ });
826
+ }
827
+ //#endregion
828
+ //#region editors/workflow-editor/ui/secret-ref.ts
829
+ const SECRET_REF_PREFIX = "secret://v1:";
830
+ function useSecretRef(options) {
831
+ const { secrets } = options;
832
+ const ref = typeof options.value === "string" ? options.value : "";
833
+ const managed = ref.startsWith(SECRET_REF_PREFIX);
834
+ const [draft, setDraft] = useState("");
835
+ const [busy, setBusy] = useState(false);
836
+ const [error, setError] = useState(null);
837
+ const [stat, setStat] = useState(null);
838
+ useEffect(() => {
839
+ setStat(null);
840
+ if (!managed || !secrets) return;
841
+ let cancelled = false;
842
+ secrets.stat(ref).then((result) => {
843
+ if (!cancelled) setStat(result);
844
+ }, () => void 0);
845
+ return () => {
846
+ cancelled = true;
847
+ };
848
+ }, [
849
+ ref,
850
+ managed,
851
+ secrets
852
+ ]);
853
+ const commit = () => {
854
+ if (draft === "" || busy || !secrets) return;
855
+ setBusy(true);
856
+ setError(null);
857
+ secrets.save({
858
+ ref: managed ? ref : void 0,
859
+ value: draft,
860
+ label: options.label
861
+ }).then((result) => {
862
+ setDraft("");
863
+ if (result.ref !== ref) options.onCommit(result.ref);
864
+ else setStat(result);
865
+ }).catch((requestError) => {
866
+ setError(requestError instanceof Error ? requestError.message : String(requestError));
867
+ }).finally(() => setBusy(false));
868
+ };
869
+ return {
870
+ ref,
871
+ managed,
872
+ draft,
873
+ setDraft,
874
+ busy,
875
+ error,
876
+ stat,
877
+ commit
878
+ };
879
+ }
880
+ //#endregion
881
+ //#region editors/workflow-editor/ui/prop-defaults.ts
882
+ function asRecord(value) {
883
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
884
+ }
885
+ function withPropDefaults(props, config) {
886
+ const next = { ...asRecord(config) };
887
+ for (const prop of props) {
888
+ if (prop.type === "MARKDOWN" || prop.defaultValue === void 0) continue;
889
+ if (next[prop.name] === void 0) next[prop.name] = prop.defaultValue;
890
+ }
891
+ return next;
892
+ }
893
+ function lacksDefaults(props, config) {
894
+ const record = asRecord(config);
895
+ return props.some((prop) => prop.type !== "MARKDOWN" && prop.defaultValue !== void 0 && record[prop.name] === void 0);
896
+ }
897
+ //#endregion
898
+ //#region editors/workflow-editor/ui/prop-controls.tsx
899
+ const CALLOUT = {
900
+ INFO: { box: "rounded bg-muted px-2 py-1.5" },
901
+ WARNING: {
902
+ box: "rounded border border-solid border-wf-warn/40 bg-wf-warn/10 px-2 py-1.5",
903
+ icon: "alert"
904
+ },
905
+ TIP: {
906
+ box: "rounded border border-solid border-wf-ok/30 bg-wf-ok/10 px-2 py-1.5",
907
+ icon: "bolt"
908
+ },
909
+ BORDERLESS: { box: "" }
910
+ };
911
+ /** A MARKDOWN prop's text, styled by the piece's `variant` (INFO default). */
912
+ function MarkdownCallout(props) {
913
+ const callout = CALLOUT[props.variant ?? "INFO"] ?? CALLOUT.INFO;
914
+ return /* @__PURE__ */ jsxs("div", {
915
+ className: `flex gap-2 ${callout.box}`,
916
+ "data-variant": props.variant ?? "INFO",
917
+ children: [callout.icon ? /* @__PURE__ */ jsx(Icon, {
918
+ name: callout.icon,
919
+ className: `mt-0.5 h-3.5 w-3.5 shrink-0 ${callout.icon === "alert" ? "text-wf-warn" : "text-wf-ok"}`
920
+ }) : null, /* @__PURE__ */ jsx("div", {
921
+ className: "min-w-0 flex-1",
922
+ children: props.children
923
+ })]
924
+ });
925
+ }
926
+ /** An option's icon, when the piece names one this editor draws. */
927
+ function optionIcon(name) {
928
+ return isIconName(name) ? /* @__PURE__ */ jsx(Icon, {
929
+ name,
930
+ className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
931
+ }) : void 0;
932
+ }
933
+ /** STATIC_DROPDOWN with `display: 'cards'`: one selectable card per option. */
934
+ function OptionCards(props) {
935
+ const current = props.keyOf(props.value);
936
+ return /* @__PURE__ */ jsx("div", {
937
+ id: props.id,
938
+ role: "radiogroup",
939
+ className: `grid grid-cols-2 gap-2 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/60" : ""}`,
940
+ children: props.options.map((option) => {
941
+ const key = props.keyOf(option.value);
942
+ const selected = key === current;
943
+ return /* @__PURE__ */ jsxs("button", {
944
+ type: "button",
945
+ role: "radio",
946
+ "aria-checked": selected,
947
+ className: `flex min-w-0 flex-col items-start gap-1 rounded-lg border border-solid p-3 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 ${selected ? "border-foreground/40 bg-accent" : "border-foreground/10 hover:border-foreground/25"}`,
948
+ onClick: () => props.onChange(selected && props.clearable ? void 0 : option.value),
949
+ children: [/* @__PURE__ */ jsxs("span", {
950
+ className: "flex items-center gap-1.5 text-[13px] font-medium text-foreground",
951
+ children: [optionIcon(option.icon), option.label]
952
+ }), option.description ? /* @__PURE__ */ jsx("span", {
953
+ className: "text-xs leading-snug text-muted-foreground",
954
+ children: option.description
955
+ }) : null]
956
+ }, key);
957
+ })
958
+ });
959
+ }
960
+ /** The declared bounds, for the hint and the check: "Between 0 and 5". */
961
+ function numberRangeText(min, max) {
962
+ if (min !== void 0 && max !== void 0) return `Between ${min} and ${max}`;
963
+ if (min !== void 0) return `At least ${min}`;
964
+ if (max !== void 0) return `At most ${max}`;
965
+ return null;
966
+ }
967
+ function numberRangeError(value, min, max) {
968
+ if (typeof value !== "number") return null;
969
+ if (min !== void 0 && value < min || max !== void 0 && value > max) return `${numberRangeText(min, max)}.`;
970
+ return null;
971
+ }
972
+ /** NUMBER with `display: 'stepper'`: − value +, still accepting expressions. */
973
+ function NumberStepper(props) {
974
+ const step = props.step ?? 1;
975
+ const numeric = typeof props.value === "number" ? props.value : void 0;
976
+ const clamp = (next) => Math.min(props.max ?? Infinity, Math.max(props.min ?? -Infinity, next));
977
+ const bump = (direction) => props.onCommit(clamp((numeric ?? props.min ?? 0) + direction * step));
978
+ const text = props.value === void 0 || props.value === null ? "" : String(props.value);
979
+ return /* @__PURE__ */ jsxs("div", {
980
+ className: "flex items-center gap-1",
981
+ children: [
982
+ /* @__PURE__ */ jsx(IconButton, {
983
+ icon: "minus",
984
+ label: "Decrease",
985
+ disabled: numeric !== void 0 && props.min !== void 0 && numeric <= props.min,
986
+ onClick: () => bump(-1)
987
+ }),
988
+ /* @__PURE__ */ jsx("input", {
989
+ id: props.id,
990
+ className: `${textInputClass} w-24 text-center tabular-nums ${props.invalid ? invalidClass : ""}`,
991
+ defaultValue: text,
992
+ inputMode: "decimal",
993
+ spellCheck: false,
994
+ onFocus: props.onFocus,
995
+ onBlur: (event) => props.onCommitText(event.target.value)
996
+ }, text),
997
+ /* @__PURE__ */ jsx(IconButton, {
998
+ icon: "plus",
999
+ label: "Increase",
1000
+ disabled: numeric !== void 0 && props.max !== void 0 && numeric >= props.max,
1001
+ onClick: () => bump(1)
1002
+ })
1003
+ ]
1004
+ });
1005
+ }
1006
+ const DATE_PRESETS = Object.entries({
1007
+ any_time: "Any time",
1008
+ last_24_hours: "Last 24 hours",
1009
+ last_7_days: "Last 7 days",
1010
+ last_30_days: "Last 30 days",
1011
+ last_90_days: "Last 90 days",
1012
+ this_month: "This month",
1013
+ custom: "Custom"
1014
+ }).map(([value, label]) => ({
1015
+ value,
1016
+ label
1017
+ }));
1018
+ function toLocalInput(iso) {
1019
+ if (!iso) return "";
1020
+ const date = new Date(iso);
1021
+ if (Number.isNaN(date.getTime())) return "";
1022
+ const pad = (n) => String(n).padStart(2, "0");
1023
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
1024
+ }
1025
+ function fromLocalInput(local) {
1026
+ if (!local) return void 0;
1027
+ const date = new Date(local);
1028
+ return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
1029
+ }
1030
+ function asDateRange(value) {
1031
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
1032
+ }
1033
+ function DateRangeField(props) {
1034
+ const range = asDateRange(props.value);
1035
+ const setPreset = (preset) => props.onCommit(preset === "" ? void 0 : preset === "custom" ? {
1036
+ preset,
1037
+ after: range.after,
1038
+ before: range.before
1039
+ } : { preset });
1040
+ return /* @__PURE__ */ jsxs("div", {
1041
+ className: "flex flex-col gap-2",
1042
+ children: [props.dropdown ? /* @__PURE__ */ jsx(Select, {
1043
+ id: props.id,
1044
+ options: DATE_PRESETS,
1045
+ value: range.preset ?? "",
1046
+ onChange: setPreset,
1047
+ invalid: props.invalid,
1048
+ clearable: props.clearable,
1049
+ placeholder: "Choose a range"
1050
+ }) : /* @__PURE__ */ jsx("div", {
1051
+ id: props.id,
1052
+ role: "radiogroup",
1053
+ className: "flex flex-wrap gap-1.5",
1054
+ children: DATE_PRESETS.map((preset) => {
1055
+ const selected = range.preset === preset.value;
1056
+ return /* @__PURE__ */ jsx("button", {
1057
+ type: "button",
1058
+ role: "radio",
1059
+ "aria-checked": selected,
1060
+ className: `h-7 rounded-full border border-solid px-2.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 ${selected ? "border-foreground bg-foreground text-background" : "border-foreground/15 text-muted-foreground hover:text-foreground"}`,
1061
+ onClick: () => setPreset(selected && props.clearable ? "" : preset.value),
1062
+ children: preset.label
1063
+ }, preset.value);
1064
+ })
1065
+ }), range.preset === "custom" ? /* @__PURE__ */ jsx("div", {
1066
+ className: "grid grid-cols-2 gap-2",
1067
+ children: ["after", "before"].map((edge) => /* @__PURE__ */ jsxs("label", {
1068
+ className: "flex flex-col gap-1 text-xs text-muted-foreground",
1069
+ children: [edge === "after" ? "From" : "To", /* @__PURE__ */ jsx("input", {
1070
+ type: "datetime-local",
1071
+ className: textInputClass,
1072
+ defaultValue: toLocalInput(range[edge]),
1073
+ onBlur: (event) => props.onCommit({
1074
+ ...range,
1075
+ [edge]: fromLocalInput(event.target.value)
1076
+ })
1077
+ })]
1078
+ }, edge))
1079
+ }) : null]
1080
+ });
1081
+ }
1082
+ const HEX = /^#[0-9a-f]{6}$/i;
1083
+ /** COLOR: a swatch picker beside a text field that also takes expressions. */
1084
+ function ColorField(props) {
1085
+ const text = typeof props.value === "string" ? props.value : "";
1086
+ const [draft, setDraft] = useState(null);
1087
+ const swatchRef = useRef(null);
1088
+ const onCommit = props.onCommit;
1089
+ useEffect(() => {
1090
+ const swatch = swatchRef.current;
1091
+ if (!swatch) return;
1092
+ const commit = () => {
1093
+ setDraft(null);
1094
+ onCommit(swatch.value);
1095
+ };
1096
+ swatch.addEventListener("change", commit);
1097
+ return () => swatch.removeEventListener("change", commit);
1098
+ }, [onCommit]);
1099
+ return /* @__PURE__ */ jsxs("div", {
1100
+ className: "flex items-center gap-2",
1101
+ children: [/* @__PURE__ */ jsx("input", {
1102
+ ref: swatchRef,
1103
+ type: "color",
1104
+ "aria-label": "Pick a colour",
1105
+ className: "h-9 w-10 shrink-0 cursor-pointer rounded-md border border-solid border-foreground/15 bg-card p-1",
1106
+ value: draft ?? (HEX.test(text) ? text : "#000000"),
1107
+ onChange: (event) => setDraft(event.target.value)
1108
+ }), /* @__PURE__ */ jsx("input", {
1109
+ id: props.id,
1110
+ className: `${textInputClass} font-mono text-xs ${props.invalid ? invalidClass : ""}`,
1111
+ defaultValue: text,
1112
+ placeholder: "#1d63d6 or {{steps.…}}",
1113
+ spellCheck: false,
1114
+ onFocus: props.onFocus,
1115
+ onBlur: (event) => {
1116
+ const raw = event.target.value.trim();
1117
+ props.onCommit(raw === "" ? void 0 : raw);
1118
+ }
1119
+ }, text)]
1120
+ });
1121
+ }
1122
+ function richTextMode(format) {
1123
+ if (format === "html") return "html";
1124
+ if (format === "markdown" || format === "md") return "markdown";
1125
+ return "plain";
1126
+ }
1127
+ //#endregion
1128
+ //#region editors/workflow-editor/ui/prop-layout.tsx
1129
+ const PLACED = /* @__PURE__ */ new Set([
1130
+ "section",
1131
+ "tabs",
1132
+ "builder",
1133
+ "footer"
1134
+ ]);
1135
+ function chipText(value) {
1136
+ if (typeof value === "string") return value;
1137
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
1138
+ if (Array.isArray(value)) return value.map(chipText).join(", ");
1139
+ return "set";
1140
+ }
1141
+ /** Consecutive `width: 'half'` fields share a row, two at a time. */
1142
+ function Rows(props) {
1143
+ const rows = [];
1144
+ let pending = null;
1145
+ const flush = () => {
1146
+ if (pending) rows.push(/* @__PURE__ */ jsx(Fragment, { children: pending.node }, pending.prop.name));
1147
+ pending = null;
1148
+ };
1149
+ for (const item of props.items) {
1150
+ if (item.prop.width !== "half") {
1151
+ flush();
1152
+ rows.push(/* @__PURE__ */ jsx(Fragment, { children: item.node }, item.prop.name));
1153
+ continue;
1154
+ }
1155
+ if (!pending) {
1156
+ pending = item;
1157
+ continue;
1158
+ }
1159
+ const first = pending;
1160
+ pending = null;
1161
+ rows.push(/* @__PURE__ */ jsxs("div", {
1162
+ className: "grid grid-cols-1 gap-4 min-[420px]:grid-cols-2",
1163
+ children: [/* @__PURE__ */ jsx("div", {
1164
+ className: "min-w-0",
1165
+ children: first.node
1166
+ }), /* @__PURE__ */ jsx("div", {
1167
+ className: "min-w-0",
1168
+ children: item.node
1169
+ })]
1170
+ }, `${first.prop.name}+${item.prop.name}`));
1171
+ }
1172
+ flush();
1173
+ return /* @__PURE__ */ jsx(Fragment$1, { children: rows });
1174
+ }
1175
+ function RevealCard(props) {
1176
+ const open = props.layout.values[props.checkbox.name] === true;
1177
+ return /* @__PURE__ */ jsxs("div", {
1178
+ className: "flex flex-col gap-4",
1179
+ children: [props.layout.renderField(props.checkbox), open && props.revealed.length > 0 ? /* @__PURE__ */ jsx("div", {
1180
+ className: "flex flex-col gap-4 border-l-2 border-solid border-foreground/10 pl-3",
1181
+ children: /* @__PURE__ */ jsx(Rows, { items: props.revealed.map((prop) => ({
1182
+ prop,
1183
+ node: props.layout.renderField(prop)
1184
+ })) })
1185
+ }) : null]
1186
+ });
1187
+ }
1188
+ function FieldList(props) {
1189
+ const byName = new Map(props.members.map((prop) => [prop.name, prop]));
1190
+ const revealedBy = /* @__PURE__ */ new Map();
1191
+ for (const prop of props.members) for (const name of prop.reveals ?? []) if (byName.has(name)) revealedBy.set(name, prop);
1192
+ const items = props.members.filter((prop) => !revealedBy.has(prop.name)).map((prop) => {
1193
+ const revealed = (prop.reveals ?? []).map((name) => byName.get(name)).filter((entry) => entry !== void 0);
1194
+ return {
1195
+ prop,
1196
+ node: revealed.length > 0 ? /* @__PURE__ */ jsx(RevealCard, {
1197
+ checkbox: prop,
1198
+ revealed,
1199
+ layout: props.layout
1200
+ }) : props.layout.renderField(prop)
1201
+ };
1202
+ });
1203
+ return /* @__PURE__ */ jsx(Rows, { items });
1204
+ }
1205
+ function GroupHeading(props) {
1206
+ const { group } = props;
1207
+ if (!group.label && !group.description) return null;
1208
+ return /* @__PURE__ */ jsxs("div", {
1209
+ className: "flex flex-col gap-0.5",
1210
+ children: [group.label ? /* @__PURE__ */ jsxs("span", {
1211
+ className: "flex items-center gap-1.5 text-[13px] font-semibold text-foreground",
1212
+ children: [isIconName(group.icon) ? /* @__PURE__ */ jsx(Icon, {
1213
+ name: group.icon,
1214
+ className: "h-3.5 w-3.5 text-muted-foreground"
1215
+ }) : null, group.label]
1216
+ }) : null, group.description ? /* @__PURE__ */ jsx("span", {
1217
+ className: "text-xs text-muted-foreground",
1218
+ children: group.description
1219
+ }) : null]
1220
+ });
1221
+ }
1222
+ function Section(props) {
1223
+ return /* @__PURE__ */ jsxs("section", {
1224
+ "aria-label": props.group.label,
1225
+ className: "flex flex-col gap-4 rounded-lg border border-solid border-foreground/10 p-4",
1226
+ children: [/* @__PURE__ */ jsx(GroupHeading, { group: props.group }), /* @__PURE__ */ jsx(FieldList, {
1227
+ members: props.members,
1228
+ layout: props.layout
1229
+ })]
1230
+ });
1231
+ }
1232
+ function TabbedGroup(props) {
1233
+ const [active, setActive] = useState(props.members[0]?.name ?? "");
1234
+ const current = props.members.find((prop) => prop.name === active) ?? props.members[0];
1235
+ if (!current) return null;
1236
+ return /* @__PURE__ */ jsxs("div", {
1237
+ className: "flex flex-col gap-3",
1238
+ children: [
1239
+ /* @__PURE__ */ jsx(GroupHeading, { group: props.group }),
1240
+ /* @__PURE__ */ jsx("div", {
1241
+ className: "border-b border-solid border-foreground/10",
1242
+ children: /* @__PURE__ */ jsx(Tabs, {
1243
+ value: current.name,
1244
+ onChange: setActive,
1245
+ tabs: props.members.map((prop) => ({
1246
+ value: prop.name,
1247
+ label: prop.displayName,
1248
+ badge: isEmptyValue(props.layout.values[prop.name]) ? void 0 : /* @__PURE__ */ jsx("span", {
1249
+ "aria-label": "has a value",
1250
+ className: "h-1.5 w-1.5 rounded-full bg-wf-run"
1251
+ })
1252
+ }))
1253
+ })
1254
+ }),
1255
+ props.layout.renderField(current)
1256
+ ]
1257
+ });
1258
+ }
1259
+ function BuilderGroups(props) {
1260
+ const members = props.groups.flatMap((group) => group.props.map((name) => props.byName.get(name)).filter((prop) => prop !== void 0));
1261
+ const [added, setAdded] = useState([]);
1262
+ const inUse = members.filter((prop) => prop.required || added.includes(prop.name) || !isEmptyValue(props.layout.values[prop.name]));
1263
+ const available = members.filter((prop) => !inUse.includes(prop));
1264
+ return /* @__PURE__ */ jsxs("div", {
1265
+ className: "flex flex-col gap-3",
1266
+ children: [
1267
+ props.groups.map((group) => /* @__PURE__ */ jsx(GroupHeading, { group }, group.key)),
1268
+ inUse.map((prop) => /* @__PURE__ */ jsxs("div", {
1269
+ className: "flex items-start gap-1",
1270
+ children: [/* @__PURE__ */ jsx("div", {
1271
+ className: "min-w-0 flex-1",
1272
+ children: props.layout.renderField(prop)
1273
+ }), prop.required ? null : /* @__PURE__ */ jsx(IconButton, {
1274
+ icon: "close",
1275
+ label: `Remove ${prop.displayName}`,
1276
+ className: "mt-7",
1277
+ onClick: () => {
1278
+ setAdded((names) => names.filter((name) => name !== prop.name));
1279
+ props.layout.onCommit(prop.name, void 0);
1280
+ }
1281
+ })]
1282
+ }, prop.name)),
1283
+ available.length > 0 ? /* @__PURE__ */ jsx("div", {
1284
+ className: "max-w-60",
1285
+ children: /* @__PURE__ */ jsx(Select, {
1286
+ options: available.map((prop) => ({
1287
+ value: prop.name,
1288
+ label: prop.displayName,
1289
+ description: prop.description
1290
+ })),
1291
+ value: "",
1292
+ placeholder: "Add filter",
1293
+ onChange: (name) => {
1294
+ if (name) setAdded((names) => [...names, name]);
1295
+ }
1296
+ })
1297
+ }) : null
1298
+ ]
1299
+ });
1300
+ }
1301
+ function Summary(props) {
1302
+ const set = props.members.filter((prop) => !isEmptyValue(props.layout.values[prop.name]));
1303
+ if (set.length === 0) return null;
1304
+ return /* @__PURE__ */ jsx("div", {
1305
+ className: "flex flex-wrap gap-1.5",
1306
+ "aria-label": "Filters in use",
1307
+ children: set.map((prop) => /* @__PURE__ */ jsxs("span", {
1308
+ className: "inline-flex h-6 max-w-full items-center gap-1 rounded-full bg-muted pl-2.5 pr-1 text-xs text-foreground",
1309
+ children: [/* @__PURE__ */ jsxs("span", {
1310
+ className: "truncate",
1311
+ children: [
1312
+ prop.displayName,
1313
+ ": ",
1314
+ chipText(props.layout.values[prop.name])
1315
+ ]
1316
+ }), /* @__PURE__ */ jsx("button", {
1317
+ type: "button",
1318
+ "aria-label": `Clear ${prop.displayName}`,
1319
+ className: "flex h-4 w-4 items-center justify-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground",
1320
+ onClick: () => props.layout.onCommit(prop.name, void 0),
1321
+ children: /* @__PURE__ */ jsx(Icon, {
1322
+ name: "close",
1323
+ className: "h-3 w-3"
1324
+ })
1325
+ })]
1326
+ }, prop.name))
1327
+ });
1328
+ }
1329
+ function PropLayout(props) {
1330
+ const groups = (props.groups ?? []).filter((group) => PLACED.has(group.display) || group.display === "summary");
1331
+ const byName = new Map(props.props.map((prop) => [prop.name, prop]));
1332
+ const groupOf = /* @__PURE__ */ new Map();
1333
+ for (const group of groups) {
1334
+ if (!PLACED.has(group.display)) continue;
1335
+ for (const name of group.props) if (byName.has(name) && !groupOf.has(name)) groupOf.set(name, group);
1336
+ }
1337
+ const membersOf = (group) => group.props.map((name) => byName.get(name)).filter((prop) => prop !== void 0);
1338
+ const builderGroups = groups.filter((group) => group.display === "builder");
1339
+ const summaries = groups.filter((group) => group.display === "summary");
1340
+ const sectionMembers = groups.filter((group) => group.display === "section").flatMap(membersOf);
1341
+ const blocks = [];
1342
+ let loose = [];
1343
+ const flushLoose = () => {
1344
+ if (loose.length === 0) return;
1345
+ blocks.push(/* @__PURE__ */ jsx(FieldList, {
1346
+ members: loose,
1347
+ layout: props
1348
+ }, `loose:${loose[0].name}`));
1349
+ loose = [];
1350
+ };
1351
+ const summarised = summaries.length > 0 && sectionMembers.length > 0;
1352
+ const placed = /* @__PURE__ */ new Set();
1353
+ for (const prop of props.props) {
1354
+ const group = groupOf.get(prop.name);
1355
+ if (!group) {
1356
+ loose.push(prop);
1357
+ continue;
1358
+ }
1359
+ const key = group.display === "builder" ? "builder" : group.key;
1360
+ if (placed.has(key)) continue;
1361
+ placed.add(key);
1362
+ flushLoose();
1363
+ if (group.display === "builder") blocks.push(/* @__PURE__ */ jsx(BuilderGroups, {
1364
+ groups: builderGroups,
1365
+ byName,
1366
+ layout: props
1367
+ }, "builder"));
1368
+ else if (group.display === "tabs") blocks.push(/* @__PURE__ */ jsx(TabbedGroup, {
1369
+ group,
1370
+ members: membersOf(group),
1371
+ layout: props
1372
+ }, group.key));
1373
+ else if (group.display === "footer") blocks.push(/* @__PURE__ */ jsxs("div", {
1374
+ className: "flex flex-col gap-4 border-t border-solid border-foreground/10 pt-4",
1375
+ children: [/* @__PURE__ */ jsx(GroupHeading, { group }), /* @__PURE__ */ jsx(FieldList, {
1376
+ members: membersOf(group),
1377
+ layout: props
1378
+ })]
1379
+ }, group.key));
1380
+ else {
1381
+ if (summarised && !placed.has("summary")) {
1382
+ placed.add("summary");
1383
+ blocks.push(/* @__PURE__ */ jsx(Summary, {
1384
+ members: sectionMembers,
1385
+ layout: props
1386
+ }, "summary"));
1387
+ }
1388
+ blocks.push(/* @__PURE__ */ jsx(Section, {
1389
+ group,
1390
+ members: membersOf(group),
1391
+ layout: props
1392
+ }, group.key));
1393
+ }
1394
+ }
1395
+ flushLoose();
1396
+ return /* @__PURE__ */ jsx(Fragment$1, { children: blocks });
1397
+ }
1398
+ //#endregion
1399
+ //#region editors/workflow-editor/ui/PropertyForm.tsx
1400
+ function insertAtCursor(element, text) {
1401
+ const start = element.selectionStart ?? element.value.length;
1402
+ const end = element.selectionEnd ?? start;
1403
+ element.value = element.value.slice(0, start) + text + element.value.slice(end);
1404
+ return element.value;
1405
+ }
1406
+ const WHOLE_EXPRESSION = /^\{\{\s*[^{}]+?\s*\}\}$/;
1407
+ const DECIMAL = /^-?(?:\d+(?:\.\d*)?|\.\d+)$/;
1408
+ function parseDecimal(raw) {
1409
+ const trimmed = raw.trim();
1410
+ return DECIMAL.test(trimmed) ? Number(trimmed) : void 0;
1411
+ }
1412
+ function stringifyValue(value) {
1413
+ if (value === void 0 || value === null) return "";
1414
+ if (typeof value === "string") return value;
1415
+ try {
1416
+ return JSON.stringify(value, null, 2);
1417
+ } catch {
1418
+ return String(value);
1419
+ }
1420
+ }
1421
+ function parseDropdownResult(result) {
1422
+ const record = result;
1423
+ if (!record || !Array.isArray(record.options)) throw new Error("Unexpected options result");
1424
+ return {
1425
+ options: record.options.map((option) => ({
1426
+ label: stringifyValue(option.label ?? option.value),
1427
+ value: option.value,
1428
+ ...typeof option.description === "string" && option.description ? { description: option.description } : {},
1429
+ ...typeof option.icon === "string" ? { icon: option.icon } : {}
1430
+ })),
1431
+ placeholder: record.placeholder,
1432
+ disabled: record.disabled
1433
+ };
1434
+ }
1435
+ const RELOAD_DEBOUNCE_MS = 400;
1436
+ const PieceMarkdown = lazy(() => import("./PieceMarkdown-CUSdTMH4.mjs"));
1437
+ const NO_ENDPOINT = "[no endpoint yet — see Endpoint URL above]";
1438
+ function fillPiecePlaceholders(text, values) {
1439
+ return text.replace(/\{\{\s*webhookUrl\s*\}\}/g, values.webhookUrl ?? NO_ENDPOINT).replace(/\{\{\s*webhookTimeoutSeconds\s*\}\}/g, values.webhookTimeoutSeconds === void 0 ? "{{webhookTimeoutSeconds}}" : String(values.webhookTimeoutSeconds)).replace(/\{\{\s*pausedFlowTimeoutDays\s*\}\}/g, values.pausedFlowTimeoutDays === void 0 ? "the workflow's maximum suspension" : String(values.pausedFlowTimeoutDays));
1440
+ }
1441
+ const PiecePlaceholderContext = createContext({});
1442
+ function AvailableSoon(props) {
1443
+ return /* @__PURE__ */ jsxs("span", {
1444
+ className: "inline-flex items-center gap-1 rounded-full bg-wf-warn/10 px-2 py-0.5 text-[11px] font-medium normal-case tracking-normal text-wf-warn",
1445
+ title: "Not supported by the runtime yet",
1446
+ children: ["Available soon", props.children ? /* @__PURE__ */ jsxs("span", { children: [": ", props.children] }) : null]
1447
+ });
1448
+ }
1449
+ function FieldShell(props) {
1450
+ const { prop } = props;
1451
+ const LabelTag = props.htmlFor ? "label" : "span";
1452
+ return /* @__PURE__ */ jsxs("div", {
1453
+ className: "group/field",
1454
+ children: [
1455
+ /* @__PURE__ */ jsxs("div", {
1456
+ className: "mb-1.5 flex min-h-6 items-center justify-between gap-2",
1457
+ children: [/* @__PURE__ */ jsxs(LabelTag, {
1458
+ htmlFor: props.htmlFor,
1459
+ className: "flex min-w-0 items-baseline gap-1.5 text-[13px] font-medium text-foreground",
1460
+ children: [
1461
+ optionIcon(prop.icon),
1462
+ /* @__PURE__ */ jsx("span", {
1463
+ className: "truncate",
1464
+ children: prop.displayName
1465
+ }),
1466
+ !prop.required ? /* @__PURE__ */ jsx("span", {
1467
+ className: "shrink-0 text-xs font-normal text-muted-foreground",
1468
+ children: "Optional"
1469
+ }) : null,
1470
+ props.invalid ? /* @__PURE__ */ jsx("span", {
1471
+ className: "shrink-0 text-xs font-normal text-wf-warn",
1472
+ children: "Needs a value"
1473
+ }) : null
1474
+ ]
1475
+ }), props.picker ? /* @__PURE__ */ jsx("span", {
1476
+ className: "flex shrink-0 items-center gap-0.5",
1477
+ children: props.picker
1478
+ }) : null]
1479
+ }),
1480
+ props.children,
1481
+ /* @__PURE__ */ jsx(FieldError, { children: props.error }),
1482
+ /* @__PURE__ */ jsx(Hint, { text: prop.description })
1483
+ ]
1484
+ });
1485
+ }
1486
+ function OptionList(props) {
1487
+ const keyOf = (value) => stringifyValue(value);
1488
+ const byKey = new Map(props.options.map((option) => [keyOf(option.value), option]));
1489
+ return /* @__PURE__ */ jsx(Select, {
1490
+ id: props.id,
1491
+ multiple: true,
1492
+ options: props.options.map((option) => ({
1493
+ value: keyOf(option.value),
1494
+ label: option.label
1495
+ })),
1496
+ value: props.selected.map(keyOf),
1497
+ onChange: (keys) => props.onChange(keys.map((key) => byKey.get(key)?.value ?? key)),
1498
+ invalid: props.invalid,
1499
+ loading: props.loading,
1500
+ onRefresh: props.onRefresh,
1501
+ placeholder: props.placeholder ?? "Choose any"
1502
+ });
1503
+ }
1504
+ function OptionSelect(props) {
1505
+ const keyOf = (value) => stringifyValue(value);
1506
+ const byKey = new Map(props.options.map((option) => [keyOf(option.value), option]));
1507
+ return /* @__PURE__ */ jsx(Select, {
1508
+ id: props.id,
1509
+ options: props.options.map((option) => ({
1510
+ value: keyOf(option.value),
1511
+ label: option.label,
1512
+ description: option.description,
1513
+ icon: optionIcon(option.icon)
1514
+ })),
1515
+ value: keyOf(props.value),
1516
+ onChange: (key) => props.onChange(key === "" ? void 0 : byKey.get(key)?.value ?? key),
1517
+ invalid: props.invalid,
1518
+ placeholder: props.placeholder,
1519
+ loading: props.loading,
1520
+ disabled: props.disabled,
1521
+ onRefresh: props.onRefresh,
1522
+ clearable: props.clearable,
1523
+ emptyText: props.emptyText,
1524
+ searchable: props.searchable,
1525
+ actions: props.actions,
1526
+ onQueryChange: props.onQueryChange
1527
+ });
1528
+ }
1529
+ const SUMMARY_CHARS = 60;
1530
+ function itemSummary(fields, row) {
1531
+ const parts = [];
1532
+ for (const field of fields) {
1533
+ const value = row[field.name];
1534
+ if (value === true) {
1535
+ parts.push(field.displayName.toLowerCase());
1536
+ continue;
1537
+ }
1538
+ if (value === void 0 || value === null || value === false) continue;
1539
+ const option = field.staticOptions?.find((o) => o.value === value);
1540
+ const text = option ? option.label : stringifyValue(value).trim();
1541
+ if (!text) continue;
1542
+ parts.push(text.length > SUMMARY_CHARS ? `${text.slice(0, SUMMARY_CHARS)}…` : text);
1543
+ }
1544
+ return parts.join(" · ");
1545
+ }
1546
+ function ArrayRows(props) {
1547
+ const fields = props.prop.properties ?? [];
1548
+ const rows = Array.isArray(props.value) ? props.value.map((item) => item !== null && typeof item === "object" ? item : {}) : [];
1549
+ const [open, setOpen] = useState(() => /* @__PURE__ */ new Set());
1550
+ const toggle = (index) => setOpen((current) => {
1551
+ const next = new Set(current);
1552
+ if (!next.delete(index)) next.add(index);
1553
+ return next;
1554
+ });
1555
+ const update = (next) => props.onCommit(next.length > 0 ? next : void 0);
1556
+ const remove = (index) => {
1557
+ update(rows.filter((_, i) => i !== index));
1558
+ setOpen((current) => new Set([...current].filter((i) => i !== index).map((i) => i > index ? i - 1 : i)));
1559
+ };
1560
+ return /* @__PURE__ */ jsxs("div", {
1561
+ className: `flex flex-col gap-1.5 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/50" : ""}`,
1562
+ children: [rows.map((row, index) => {
1563
+ const expanded = open.has(index);
1564
+ const summary = itemSummary(fields, row);
1565
+ return /* @__PURE__ */ jsxs("div", {
1566
+ className: "rounded-md border border-solid border-foreground/10 bg-muted/40",
1567
+ children: [/* @__PURE__ */ jsxs("div", {
1568
+ className: "flex items-center gap-1 py-1 pl-1 pr-1",
1569
+ children: [/* @__PURE__ */ jsxs("button", {
1570
+ type: "button",
1571
+ "aria-expanded": expanded,
1572
+ onClick: () => toggle(index),
1573
+ className: "flex min-w-0 flex-1 items-center gap-1.5 rounded px-1 py-0.5 text-left text-[13px] hover:bg-foreground/5",
1574
+ children: [/* @__PURE__ */ jsx(Icon, {
1575
+ name: expanded ? "chevronDown" : "chevron",
1576
+ className: "h-3.5 w-3.5 shrink-0 text-muted-foreground"
1577
+ }), /* @__PURE__ */ jsx("span", {
1578
+ className: `truncate ${summary ? "text-foreground" : "text-muted-foreground"}`,
1579
+ children: summary || `Item ${index + 1}`
1580
+ })]
1581
+ }), /* @__PURE__ */ jsx(IconButton, {
1582
+ icon: "trash",
1583
+ label: `Remove item ${index + 1}`,
1584
+ onClick: () => remove(index)
1585
+ })]
1586
+ }), expanded ? /* @__PURE__ */ jsx("div", {
1587
+ className: "border-t border-solid border-foreground/10 px-3 pb-3 pt-2",
1588
+ children: /* @__PURE__ */ jsx(PropertyForm, {
1589
+ props: fields,
1590
+ value: row,
1591
+ onChange: (next) => update(rows.map((entry, i) => i === index ? next : entry)),
1592
+ scopeStepId: props.scopeStepId,
1593
+ nested: true
1594
+ })
1595
+ }) : null]
1596
+ }, index);
1597
+ }), /* @__PURE__ */ jsxs(Button, {
1598
+ size: "sm",
1599
+ className: "self-start",
1600
+ onClick: () => {
1601
+ update([...rows, withPropDefaults(fields, {})]);
1602
+ setOpen((current) => new Set(current).add(rows.length));
1603
+ },
1604
+ children: [/* @__PURE__ */ jsx(Icon, {
1605
+ name: "plus",
1606
+ className: "h-3.5 w-3.5"
1607
+ }), "Add item"]
1608
+ })]
1609
+ });
1610
+ }
1611
+ function rowsOf(value) {
1612
+ return Object.entries(value).map(([key, entry]) => ({
1613
+ key,
1614
+ value: stringifyValue(entry)
1615
+ }));
1616
+ }
1617
+ function recordOf(rows) {
1618
+ const record = {};
1619
+ for (const row of rows) if (row.key.trim() !== "") record[row.key.trim()] = row.value;
1620
+ return record;
1621
+ }
1622
+ function ObjectRows(props) {
1623
+ const [rows, setRows] = useState(() => rowsOf(props.value));
1624
+ const valueKey = keyOf(props.value);
1625
+ const [seen, setSeen] = useState(valueKey);
1626
+ if (seen !== valueKey) {
1627
+ setSeen(valueKey);
1628
+ if (keyOf(recordOf(rows)) !== valueKey) setRows(rowsOf(props.value));
1629
+ }
1630
+ const commit = (next) => {
1631
+ setRows(next);
1632
+ const record = recordOf(next);
1633
+ props.onCommit(Object.keys(record).length > 0 ? record : void 0);
1634
+ };
1635
+ return /* @__PURE__ */ jsxs("div", {
1636
+ className: `flex flex-col gap-1.5 ${props.invalid ? "rounded-md ring-1 ring-wf-warn/50" : ""}`,
1637
+ children: [rows.map((row, index) => /* @__PURE__ */ jsxs("div", {
1638
+ className: "flex items-center gap-1",
1639
+ children: [
1640
+ /* @__PURE__ */ jsx("input", {
1641
+ className: `${textInputClass} font-mono text-xs`,
1642
+ placeholder: "Key",
1643
+ value: row.key,
1644
+ onChange: (event) => setRows(rows.map((entry, i) => i === index ? {
1645
+ ...entry,
1646
+ key: event.target.value
1647
+ } : entry)),
1648
+ onBlur: () => commit(rows)
1649
+ }),
1650
+ /* @__PURE__ */ jsx("input", {
1651
+ className: `${textInputClass} font-mono text-xs`,
1652
+ placeholder: "Value",
1653
+ value: row.value,
1654
+ onChange: (event) => setRows(rows.map((entry, i) => i === index ? {
1655
+ ...entry,
1656
+ value: event.target.value
1657
+ } : entry)),
1658
+ onBlur: () => commit(rows)
1659
+ }),
1660
+ /* @__PURE__ */ jsx(IconButton, {
1661
+ icon: "close",
1662
+ label: "Remove entry",
1663
+ onClick: () => commit(rows.filter((_, i) => i !== index))
1664
+ })
1665
+ ]
1666
+ }, index)), /* @__PURE__ */ jsxs(Button, {
1667
+ size: "sm",
1668
+ className: "self-start",
1669
+ onClick: () => setRows([...rows, {
1670
+ key: "",
1671
+ value: ""
1672
+ }]),
1673
+ children: [/* @__PURE__ */ jsx(Icon, {
1674
+ name: "plus",
1675
+ className: "h-3.5 w-3.5"
1676
+ }), "Add entry"]
1677
+ })]
1678
+ });
1679
+ }
1680
+ function isoToLocalInput(value) {
1681
+ if (typeof value !== "string" || value === "") return "";
1682
+ const date = new Date(value);
1683
+ if (Number.isNaN(date.getTime())) return "";
1684
+ const pad = (n) => String(n).padStart(2, "0");
1685
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
1686
+ }
1687
+ function localInputToIso(value) {
1688
+ if (value === "") return void 0;
1689
+ const date = new Date(value);
1690
+ return Number.isNaN(date.getTime()) ? value : date.toISOString();
1691
+ }
1692
+ function isDropdownType(type) {
1693
+ return type === "DROPDOWN" || type === "MULTI_SELECT_DROPDOWN";
1694
+ }
1695
+ const SEARCH_DEBOUNCE_MS = 300;
1696
+ const FLIPS_TO_TEXT = /* @__PURE__ */ new Set([
1697
+ "DATE_TIME",
1698
+ "OBJECT",
1699
+ "DROPDOWN",
1700
+ "CHECKBOX",
1701
+ "NUMBER"
1702
+ ]);
1703
+ const TEXT_MODE_TYPES = /* @__PURE__ */ new Set([
1704
+ "SHORT_TEXT",
1705
+ "LONG_TEXT",
1706
+ "NUMBER",
1707
+ "SECRET_TEXT",
1708
+ "FILE",
1709
+ "JSON",
1710
+ "DATE_TIME",
1711
+ "OBJECT",
1712
+ "DROPDOWN",
1713
+ "CHECKBOX"
1714
+ ]);
1715
+ function SecretRefField(props) {
1716
+ const { secrets } = props;
1717
+ const fieldId = useId();
1718
+ const { ref, managed, draft, setDraft, busy, error, stat, commit } = useSecretRef({
1719
+ value: props.value,
1720
+ secrets,
1721
+ label: props.prop.displayName,
1722
+ onCommit: props.onCommit
1723
+ });
1724
+ if (!secrets) return /* @__PURE__ */ jsx(FieldShell, {
1725
+ htmlFor: fieldId,
1726
+ prop: props.prop,
1727
+ invalid: props.invalid,
1728
+ children: /* @__PURE__ */ jsx("p", {
1729
+ className: "text-xs text-muted-foreground",
1730
+ children: "Managed secrets are unavailable in this session."
1731
+ })
1732
+ });
1733
+ return /* @__PURE__ */ jsxs(FieldShell, {
1734
+ htmlFor: fieldId,
1735
+ prop: props.prop,
1736
+ invalid: props.invalid,
1737
+ error,
1738
+ children: [managed ? /* @__PURE__ */ jsxs("p", {
1739
+ className: "mb-1.5 flex items-center gap-1.5 text-xs text-muted-foreground",
1740
+ children: [
1741
+ /* @__PURE__ */ jsx("span", {
1742
+ className: "font-medium text-foreground",
1743
+ children: stat?.label ?? ref
1744
+ }),
1745
+ stat ? /* @__PURE__ */ jsxs("span", { children: ["version ", stat.version] }) : null,
1746
+ stat?.status === "DELETED" ? /* @__PURE__ */ jsx("span", {
1747
+ className: "font-medium text-wf-fail",
1748
+ children: "deleted"
1749
+ }) : null
1750
+ ]
1751
+ }) : null, /* @__PURE__ */ jsxs("div", {
1752
+ className: "flex items-center gap-1",
1753
+ children: [/* @__PURE__ */ jsx("input", {
1754
+ id: fieldId,
1755
+ className: `${textInputClass} ${props.invalid ? invalidClass : ""}`,
1756
+ type: "password",
1757
+ value: draft,
1758
+ disabled: busy,
1759
+ placeholder: managed ? "Paste a new value to replace it" : "Paste the secret value",
1760
+ autoComplete: "off",
1761
+ spellCheck: false,
1762
+ onChange: (event) => setDraft(event.target.value),
1763
+ onKeyDown: (event) => {
1764
+ if (event.key === "Enter") commit();
1765
+ },
1766
+ onBlur: commit
1767
+ }), ref ? /* @__PURE__ */ jsx(IconButton, {
1768
+ icon: "close",
1769
+ label: "Remove secret",
1770
+ onClick: () => props.onCommit(void 0)
1771
+ }) : null]
1772
+ })]
1773
+ });
1774
+ }
1775
+ function ModeButton(props) {
1776
+ return /* @__PURE__ */ jsx("button", {
1777
+ type: "button",
1778
+ className: "inline-flex h-6 shrink-0 items-center rounded-md px-1.5 text-xs font-medium text-muted-foreground hover:bg-accent hover:text-foreground",
1779
+ onClick: props.onClick,
1780
+ children: props.label
1781
+ });
1782
+ }
1783
+ function PropField(props) {
1784
+ const { prop, value } = props;
1785
+ const placeholders = useContext(PiecePlaceholderContext);
1786
+ const fieldId = useId();
1787
+ const optionsUnavailable = Boolean(props.nested && prop.hasDynamicResolver && !props.loadOptions);
1788
+ const fieldRef = useRef(null);
1789
+ const invalid = prop.required && prop.type !== "MARKDOWN" && isEmptyValue(value);
1790
+ const [draft, setDraft] = useState(() => stringifyValue(value));
1791
+ const [prevValue, setPrevValue] = useState(value);
1792
+ if (value !== prevValue) {
1793
+ setPrevValue(value);
1794
+ setDraft(stringifyValue(value));
1795
+ }
1796
+ const [jsonError, setJsonError] = useState(null);
1797
+ const [textMode, setTextMode] = useState(props.mode === "EXPRESSION");
1798
+ const [prevMode, setPrevMode] = useState(props.mode);
1799
+ if (props.mode !== prevMode) {
1800
+ setPrevMode(props.mode);
1801
+ if (props.mode) setTextMode(props.mode === "EXPRESSION");
1802
+ }
1803
+ const onCommit = (next, mode) => props.onCommit(next, mode ?? (textMode ? "EXPRESSION" : "MANUAL"));
1804
+ const toMode = (expression) => {
1805
+ setTextMode(expression);
1806
+ props.onMode?.(expression ? "EXPRESSION" : "MANUAL");
1807
+ };
1808
+ const [numberError, setNumberError] = useState(null);
1809
+ const commitsOnInsert = prop.type !== "JSON";
1810
+ const field = useExpressionField({
1811
+ stepId: props.scopeStepId,
1812
+ label: prop.displayName,
1813
+ insert: (expression) => {
1814
+ if (FLIPS_TO_TEXT.has(prop.type) && !textMode) {
1815
+ setTextMode(true);
1816
+ setDraft(expression);
1817
+ setNumberError(null);
1818
+ onCommit(expression, "EXPRESSION");
1819
+ return;
1820
+ }
1821
+ if (!fieldRef.current) return;
1822
+ const next = insertAtCursor(fieldRef.current, expression);
1823
+ setDraft(next);
1824
+ if (commitsOnInsert) onCommit(next);
1825
+ }
1826
+ });
1827
+ const picker = TEXT_MODE_TYPES.has(prop.type) ? /* @__PURE__ */ jsx(ExpressionPickerButton, {
1828
+ active: field.active,
1829
+ onFocusField: field.focus
1830
+ }) : void 0;
1831
+ const dynamicLoad = props.loadOptions && prop.hasDynamicResolver && !props.optionsBlocked ? () => props.loadOptions(prop.name) : void 0;
1832
+ const isDropdown = prop.type === "DROPDOWN" || prop.type === "MULTI_SELECT_DROPDOWN";
1833
+ const dropdown = useResolvedProp({
1834
+ kind: "options",
1835
+ input: props.resolverInput,
1836
+ load: isDropdown ? dynamicLoad : void 0,
1837
+ parse: parseDropdownResult,
1838
+ debounceMs: RELOAD_DEBOUNCE_MS
1839
+ });
1840
+ const dynamic = useResolvedProp({
1841
+ kind: "dynamic",
1842
+ input: props.resolverInput,
1843
+ load: prop.type === "DYNAMIC" ? dynamicLoad : void 0,
1844
+ parse: parsePropList,
1845
+ debounceMs: RELOAD_DEBOUNCE_MS
1846
+ });
1847
+ const dynamicFields = dynamic.state.kind === "ready" ? dynamic.state.result : null;
1848
+ useEffect(() => {
1849
+ if (value !== void 0 || !dynamicFields) return;
1850
+ if (lacksDefaults(dynamicFields, {})) props.onCommit(withPropDefaults(dynamicFields, {}), "MANUAL");
1851
+ }, [dynamicFields]);
1852
+ const [searchQuery, setSearchQuery] = useState("");
1853
+ const [picked, setPicked] = useState(null);
1854
+ const loadOptions = props.loadOptions;
1855
+ const searchable = Boolean(prop.refreshOnSearch && loadOptions);
1856
+ const searchResult = useOptionSearch({
1857
+ input: props.resolverInput,
1858
+ query: searchQuery,
1859
+ load: searchable && loadOptions ? (searchValue) => loadOptions(prop.name, searchValue) : void 0,
1860
+ parse: parseDropdownResult,
1861
+ debounceMs: SEARCH_DEBOUNCE_MS
1862
+ });
1863
+ const onSearch = searchable ? setSearchQuery : void 0;
1864
+ const retryButton = (state, reload) => /* @__PURE__ */ jsx(IconButton, {
1865
+ icon: "retry",
1866
+ label: "Reload",
1867
+ disabled: state.kind === "loading",
1868
+ onClick: reload
1869
+ });
1870
+ const blocked = prop.hasDynamicResolver ? props.optionsBlocked : void 0;
1871
+ const loadError = (state) => blocked ?? (state.kind === "error" ? props.explainOptionsError?.(state.message) ?? state.message : null);
1872
+ const textInput = (extra) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
1873
+ className: "flex items-center gap-1",
1874
+ children: /* @__PURE__ */ jsx("input", {
1875
+ id: fieldId,
1876
+ ref: fieldRef,
1877
+ type: extra.type ?? "text",
1878
+ className: `${textInputClass} ${extra.mono ? "font-mono text-xs" : ""} ${invalid ? invalidClass : ""}`,
1879
+ defaultValue: stringifyValue(value),
1880
+ placeholder: extra.placeholder ?? prop.placeholder,
1881
+ spellCheck: false,
1882
+ onFocus: field.focus,
1883
+ onChange: (event) => setDraft(event.target.value),
1884
+ onBlur: (event) => extra.commit(event.target.value)
1885
+ })
1886
+ }), extra.type === "password" ? null : /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })] });
1887
+ switch (prop.type) {
1888
+ case "PH_SECRET_REF": return /* @__PURE__ */ jsx(SecretRefField, {
1889
+ prop,
1890
+ value,
1891
+ onCommit,
1892
+ invalid,
1893
+ secrets: props.secrets
1894
+ });
1895
+ case "MARKDOWN": {
1896
+ const markdown = fillPiecePlaceholders(stringifyValue(prop.description ?? prop.defaultValue ?? prop.displayName), {
1897
+ ...placeholders,
1898
+ webhookUrl: props.webhookUrl
1899
+ });
1900
+ return /* @__PURE__ */ jsx(MarkdownCallout, {
1901
+ variant: prop.variant,
1902
+ children: /* @__PURE__ */ jsx(Suspense, {
1903
+ fallback: /* @__PURE__ */ jsx("p", {
1904
+ className: "whitespace-pre-wrap text-xs text-muted-foreground",
1905
+ children: markdown
1906
+ }),
1907
+ children: /* @__PURE__ */ jsx(PieceMarkdown, { text: markdown })
1908
+ })
1909
+ });
1910
+ }
1911
+ case "CHECKBOX":
1912
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
1913
+ htmlFor: fieldId,
1914
+ prop,
1915
+ invalid,
1916
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [picker, /* @__PURE__ */ jsx(ModeButton, {
1917
+ label: "Use a switch",
1918
+ onClick: () => {
1919
+ setTextMode(false);
1920
+ onCommit(void 0, "MANUAL");
1921
+ }
1922
+ })] }),
1923
+ children: textInput({
1924
+ mono: true,
1925
+ placeholder: "{{steps.…}} yielding true or false",
1926
+ commit: (raw) => {
1927
+ const trimmed = raw.trim();
1928
+ if (trimmed === "") {
1929
+ setTextMode(false);
1930
+ return onCommit(void 0, "MANUAL");
1931
+ }
1932
+ onCommit(trimmed, "EXPRESSION");
1933
+ }
1934
+ })
1935
+ });
1936
+ return /* @__PURE__ */ jsxs("div", {
1937
+ className: "group/field flex items-start gap-1",
1938
+ children: [/* @__PURE__ */ jsx("div", {
1939
+ className: "min-w-0 flex-1",
1940
+ children: /* @__PURE__ */ jsx(Switch, {
1941
+ checked: value === true,
1942
+ onChange: (checked) => onCommit(checked, "MANUAL"),
1943
+ label: prop.displayName,
1944
+ description: prop.description
1945
+ })
1946
+ }), picker]
1947
+ });
1948
+ case "NUMBER": {
1949
+ const rangeError = numberRangeError(value, prop.min, prop.max);
1950
+ const commitNumber = (raw) => {
1951
+ const trimmed = raw.trim();
1952
+ if (trimmed === "") {
1953
+ setNumberError(null);
1954
+ if (!textMode) return onCommit(void 0);
1955
+ setTextMode(false);
1956
+ return onCommit(void 0, "MANUAL");
1957
+ }
1958
+ if (textMode || hasExpressions(trimmed)) {
1959
+ setNumberError(null);
1960
+ setTextMode(true);
1961
+ return onCommit(trimmed, "EXPRESSION");
1962
+ }
1963
+ const parsed = parseDecimal(trimmed);
1964
+ if (parsed === void 0) {
1965
+ setNumberError("Not a number");
1966
+ return;
1967
+ }
1968
+ setNumberError(null);
1969
+ onCommit(parsed);
1970
+ };
1971
+ if (prop.display === "stepper" && !textMode) return /* @__PURE__ */ jsx(FieldShell, {
1972
+ htmlFor: fieldId,
1973
+ prop,
1974
+ invalid,
1975
+ picker,
1976
+ error: numberError ?? rangeError,
1977
+ children: /* @__PURE__ */ jsx(NumberStepper, {
1978
+ id: fieldId,
1979
+ value,
1980
+ min: prop.min,
1981
+ max: prop.max,
1982
+ step: prop.step,
1983
+ invalid: invalid || rangeError !== null || numberError !== null,
1984
+ onCommit: (next) => {
1985
+ setNumberError(null);
1986
+ onCommit(next);
1987
+ },
1988
+ onCommitText: commitNumber,
1989
+ onFocus: field.focus
1990
+ })
1991
+ });
1992
+ return /* @__PURE__ */ jsx(FieldShell, {
1993
+ htmlFor: fieldId,
1994
+ prop,
1995
+ invalid,
1996
+ picker,
1997
+ error: numberError ?? (textMode ? null : rangeError),
1998
+ children: textInput({
1999
+ mono: textMode,
2000
+ placeholder: textMode ? "{{expression}} yielding a number" : prop.placeholder ?? numberRangeText(prop.min, prop.max) ?? void 0,
2001
+ commit: commitNumber
2002
+ })
2003
+ });
2004
+ }
2005
+ case "SECRET_TEXT": return /* @__PURE__ */ jsx(FieldShell, {
2006
+ htmlFor: fieldId,
2007
+ prop,
2008
+ invalid,
2009
+ picker,
2010
+ children: textInput({
2011
+ type: "password",
2012
+ commit: (raw) => onCommit(raw === "" ? void 0 : raw)
2013
+ })
2014
+ });
2015
+ case "FILE": return /* @__PURE__ */ jsx(FieldShell, {
2016
+ htmlFor: fieldId,
2017
+ prop,
2018
+ invalid,
2019
+ picker,
2020
+ children: textInput({
2021
+ mono: true,
2022
+ placeholder: prop.placeholder ?? "https://… or data:…;base64,…",
2023
+ commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw.trim())
2024
+ })
2025
+ });
2026
+ case "DATE_TIME":
2027
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2028
+ htmlFor: fieldId,
2029
+ prop,
2030
+ invalid,
2031
+ picker,
2032
+ children: textInput({
2033
+ mono: true,
2034
+ placeholder: "ISO 8601 or {{expression}}",
2035
+ commit: (raw) => {
2036
+ const trimmed = raw.trim();
2037
+ if (trimmed === "") {
2038
+ setTextMode(false);
2039
+ return onCommit(void 0, "MANUAL");
2040
+ }
2041
+ onCommit(hasExpressions(trimmed) ? trimmed : localInputToIso(trimmed));
2042
+ }
2043
+ })
2044
+ });
2045
+ return /* @__PURE__ */ jsx(FieldShell, {
2046
+ htmlFor: fieldId,
2047
+ prop,
2048
+ invalid,
2049
+ picker,
2050
+ children: /* @__PURE__ */ jsx("input", {
2051
+ id: fieldId,
2052
+ type: "datetime-local",
2053
+ className: `${textInputClass} ${invalid ? invalidClass : ""}`,
2054
+ defaultValue: isoToLocalInput(value),
2055
+ onFocus: field.focus,
2056
+ onBlur: (event) => onCommit(localInputToIso(event.target.value))
2057
+ })
2058
+ });
2059
+ case "STATIC_DROPDOWN": {
2060
+ const options = prop.staticOptions ?? [];
2061
+ if (prop.display === "cards") return /* @__PURE__ */ jsx(FieldShell, {
2062
+ htmlFor: fieldId,
2063
+ prop,
2064
+ invalid,
2065
+ children: /* @__PURE__ */ jsx(OptionCards, {
2066
+ id: fieldId,
2067
+ options,
2068
+ value,
2069
+ keyOf: stringifyValue,
2070
+ onChange: onCommit,
2071
+ invalid,
2072
+ clearable: !prop.required
2073
+ })
2074
+ });
2075
+ if (!prop.staticDisabled && prop.required !== true && prop.defaultValue !== void 0 && options.length >= 2 && options.length <= 3 && options.every((option) => option.label.length <= 22)) return /* @__PURE__ */ jsx(FieldShell, {
2076
+ htmlFor: fieldId,
2077
+ prop,
2078
+ invalid: false,
2079
+ children: /* @__PURE__ */ jsx(Segmented, {
2080
+ value: stringifyValue(value),
2081
+ options: options.map((option) => ({
2082
+ value: stringifyValue(option.value),
2083
+ label: option.label
2084
+ })),
2085
+ onChange: (key) => onCommit(options.find((option) => stringifyValue(option.value) === key)?.value ?? key)
2086
+ })
2087
+ });
2088
+ return /* @__PURE__ */ jsx(FieldShell, {
2089
+ htmlFor: fieldId,
2090
+ prop,
2091
+ invalid,
2092
+ children: /* @__PURE__ */ jsx(OptionSelect, {
2093
+ id: fieldId,
2094
+ options: prop.staticOptions ?? [],
2095
+ value,
2096
+ onChange: onCommit,
2097
+ invalid,
2098
+ placeholder: prop.staticPlaceholder ?? prop.placeholder,
2099
+ disabled: prop.staticDisabled && isEmptyValue(value),
2100
+ clearable: !prop.required
2101
+ })
2102
+ });
2103
+ }
2104
+ case "STATIC_MULTI_SELECT_DROPDOWN": return /* @__PURE__ */ jsx(FieldShell, {
2105
+ htmlFor: fieldId,
2106
+ prop,
2107
+ invalid,
2108
+ children: /* @__PURE__ */ jsx(OptionList, {
2109
+ id: fieldId,
2110
+ options: prop.staticOptions ?? [],
2111
+ selected: Array.isArray(value) ? value : [],
2112
+ onChange: (next) => onCommit(next.length > 0 ? next : void 0),
2113
+ invalid
2114
+ })
2115
+ });
2116
+ case "DROPDOWN": {
2117
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2118
+ htmlFor: fieldId,
2119
+ prop,
2120
+ invalid,
2121
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [picker, /* @__PURE__ */ jsx(ModeButton, {
2122
+ label: "Pick from list",
2123
+ onClick: () => {
2124
+ if (hasExpressions(value)) {
2125
+ setTextMode(false);
2126
+ onCommit(void 0, "MANUAL");
2127
+ } else toMode(false);
2128
+ }
2129
+ })] }),
2130
+ children: textInput({
2131
+ mono: true,
2132
+ placeholder: "{{steps.…}} or an id",
2133
+ commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw)
2134
+ })
2135
+ });
2136
+ const result = searchResult ?? (dropdown.state.kind === "ready" ? dropdown.state.result : null);
2137
+ const listed = result?.options ?? [];
2138
+ const options = picked !== null && stringifyValue(picked.value) === stringifyValue(value) && !listed.some((option) => stringifyValue(option.value) === stringifyValue(value)) ? [...listed, picked] : listed;
2139
+ return /* @__PURE__ */ jsx(FieldShell, {
2140
+ htmlFor: fieldId,
2141
+ prop,
2142
+ invalid,
2143
+ error: loadError(dropdown.state),
2144
+ picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : picker,
2145
+ children: /* @__PURE__ */ jsx(OptionSelect, {
2146
+ id: fieldId,
2147
+ options,
2148
+ value,
2149
+ onChange: (next) => {
2150
+ setPicked(listed.find((option) => stringifyValue(option.value) === stringifyValue(next)) ?? null);
2151
+ onCommit(next);
2152
+ },
2153
+ invalid,
2154
+ loading: dropdown.state.kind === "loading",
2155
+ disabled: result?.disabled && !stringifyValue(value) || optionsUnavailable,
2156
+ onRefresh: dynamicLoad ? dropdown.reload : void 0,
2157
+ clearable: !prop.required,
2158
+ searchable: true,
2159
+ onQueryChange: onSearch,
2160
+ actions: [{
2161
+ label: "Use data from an earlier step",
2162
+ icon: "braces",
2163
+ onSelect: () => {
2164
+ toMode(true);
2165
+ field.focus();
2166
+ }
2167
+ }],
2168
+ emptyText: result?.placeholder ?? "Nothing to choose from yet. Some lists need a connection first.",
2169
+ placeholder: optionsUnavailable ? "Options for nested fields are available soon" : dropdown.syncing ? "Waiting for the Switchboard…" : result?.placeholder ?? prop.placeholder ?? "Choose…"
2170
+ })
2171
+ });
2172
+ }
2173
+ case "MULTI_SELECT_DROPDOWN": {
2174
+ const result = dropdown.state.kind === "ready" ? dropdown.state.result : null;
2175
+ const selected = Array.isArray(value) ? value : [];
2176
+ const listed = new Set((result?.options ?? []).map((o) => stringifyValue(o.value)));
2177
+ const extra = selected.filter((entry) => !listed.has(stringifyValue(entry))).map((entry) => ({
2178
+ label: stringifyValue(entry),
2179
+ value: entry
2180
+ }));
2181
+ return /* @__PURE__ */ jsx(FieldShell, {
2182
+ htmlFor: fieldId,
2183
+ prop,
2184
+ invalid,
2185
+ error: loadError(dropdown.state),
2186
+ picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : void 0,
2187
+ children: optionsUnavailable ? /* @__PURE__ */ jsx("p", {
2188
+ className: "text-xs text-muted-foreground",
2189
+ children: "Options for nested fields are available soon."
2190
+ }) : /* @__PURE__ */ jsx(OptionList, {
2191
+ id: fieldId,
2192
+ options: [...extra, ...result?.options ?? []],
2193
+ selected,
2194
+ onChange: (next) => onCommit(next.length > 0 ? next : void 0),
2195
+ invalid,
2196
+ loading: dropdown.state.kind === "loading",
2197
+ onRefresh: dynamicLoad ? dropdown.reload : void 0,
2198
+ placeholder: result?.placeholder ?? prop.placeholder
2199
+ })
2200
+ });
2201
+ }
2202
+ case "DYNAMIC": {
2203
+ const fields = dynamic.state.kind === "ready" ? dynamic.state.result : null;
2204
+ const record = value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
2205
+ return /* @__PURE__ */ jsx(FieldShell, {
2206
+ htmlFor: fieldId,
2207
+ prop,
2208
+ invalid: invalid && fields !== null && fields.length > 0,
2209
+ error: loadError(dynamic.state),
2210
+ picker: optionsUnavailable ? /* @__PURE__ */ jsx(AvailableSoon, {}) : dynamicLoad ? retryButton(dynamic.state, dynamic.reload) : void 0,
2211
+ children: optionsUnavailable ? /* @__PURE__ */ jsx("p", {
2212
+ className: "text-xs text-muted-foreground",
2213
+ children: "Nested dynamic properties are available soon."
2214
+ }) : dynamic.state.kind === "loading" && !fields ? /* @__PURE__ */ jsx("p", {
2215
+ className: "text-xs text-muted-foreground",
2216
+ children: "Resolving properties…"
2217
+ }) : !dynamicLoad ? /* @__PURE__ */ jsx("p", {
2218
+ className: "text-xs text-muted-foreground",
2219
+ children: "Properties resolve once the runtime is reachable."
2220
+ }) : fields && fields.length > 0 ? /* @__PURE__ */ jsx("div", {
2221
+ className: "rounded-lg border border-solid border-foreground/10 bg-muted/40 p-3",
2222
+ children: /* @__PURE__ */ jsx(PropertyForm, {
2223
+ props: fields,
2224
+ value: record,
2225
+ onChange: (next) => onCommit(Object.keys(next).length > 0 ? next : void 0),
2226
+ scopeStepId: props.scopeStepId,
2227
+ nested: true
2228
+ })
2229
+ }) : fields ? /* @__PURE__ */ jsx("p", {
2230
+ className: "text-xs text-muted-foreground",
2231
+ children: props.waitingOn ? `Pick ${props.waitingOn} first; its fields show here.` : "No properties for the current selection."
2232
+ }) : null
2233
+ });
2234
+ }
2235
+ case "ARRAY": {
2236
+ if (prop.properties && prop.properties.length > 0) return /* @__PURE__ */ jsx(FieldShell, {
2237
+ htmlFor: fieldId,
2238
+ prop,
2239
+ invalid,
2240
+ children: /* @__PURE__ */ jsx(ArrayRows, {
2241
+ prop,
2242
+ value,
2243
+ onCommit,
2244
+ scopeStepId: props.scopeStepId,
2245
+ invalid
2246
+ })
2247
+ });
2248
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2249
+ htmlFor: fieldId,
2250
+ prop,
2251
+ invalid,
2252
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ExpressionPickerButton, {
2253
+ active: field.active,
2254
+ onFocusField: field.focus
2255
+ }), /* @__PURE__ */ jsx(ModeButton, {
2256
+ label: "Enter items",
2257
+ onClick: () => {
2258
+ setTextMode(false);
2259
+ const bound = stringifyValue(value).trim();
2260
+ onCommit(bound ? [bound] : void 0, "MANUAL");
2261
+ }
2262
+ })] }),
2263
+ children: textInput({
2264
+ mono: true,
2265
+ placeholder: "{{steps.…}} yielding a list",
2266
+ commit: (raw) => onCommit(raw.trim() === "" ? void 0 : raw.trim(), "EXPRESSION")
2267
+ })
2268
+ });
2269
+ const lines = Array.isArray(value) ? value.map((item) => stringifyValue(item)).join("\n") : stringifyValue(value);
2270
+ return /* @__PURE__ */ jsxs(FieldShell, {
2271
+ htmlFor: fieldId,
2272
+ prop,
2273
+ invalid,
2274
+ picker: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ExpressionPickerButton, {
2275
+ active: field.active,
2276
+ onFocusField: field.focus
2277
+ }), /* @__PURE__ */ jsx(ModeButton, {
2278
+ label: "Bind the whole list",
2279
+ onClick: () => {
2280
+ setTextMode(true);
2281
+ onCommit(void 0, "EXPRESSION");
2282
+ }
2283
+ })] }),
2284
+ children: [/* @__PURE__ */ jsx("textarea", {
2285
+ id: fieldId,
2286
+ ref: fieldRef,
2287
+ className: `${textAreaClass} font-mono text-xs ${invalid ? invalidClass : ""}`,
2288
+ defaultValue: lines,
2289
+ placeholder: prop.placeholder ?? "One item per line",
2290
+ spellCheck: false,
2291
+ onFocus: field.focus,
2292
+ onChange: (event) => setDraft(event.target.value),
2293
+ onBlur: (event) => {
2294
+ const items = event.target.value.split("\n").map((line) => line.trim()).filter((line) => line !== "");
2295
+ if (items.length === 0) return onCommit(void 0);
2296
+ onCommit(items);
2297
+ }
2298
+ }), /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })]
2299
+ });
2300
+ }
2301
+ case "OBJECT":
2302
+ if (textMode) return /* @__PURE__ */ jsx(FieldShell, {
2303
+ htmlFor: fieldId,
2304
+ prop,
2305
+ invalid,
2306
+ picker,
2307
+ children: textInput({
2308
+ mono: true,
2309
+ placeholder: "{{expression}} yielding an object",
2310
+ commit: (raw) => {
2311
+ const trimmed = raw.trim();
2312
+ if (trimmed === "") {
2313
+ setTextMode(false);
2314
+ return onCommit(void 0, "MANUAL");
2315
+ }
2316
+ onCommit(trimmed);
2317
+ }
2318
+ })
2319
+ });
2320
+ return /* @__PURE__ */ jsx(FieldShell, {
2321
+ htmlFor: fieldId,
2322
+ prop,
2323
+ invalid,
2324
+ picker,
2325
+ children: /* @__PURE__ */ jsx(ObjectRows, {
2326
+ value: value !== null && typeof value === "object" && !Array.isArray(value) ? value : {},
2327
+ onCommit,
2328
+ invalid
2329
+ })
2330
+ });
2331
+ case "DATE_RANGE": return /* @__PURE__ */ jsx(FieldShell, {
2332
+ htmlFor: fieldId,
2333
+ prop,
2334
+ invalid,
2335
+ children: /* @__PURE__ */ jsx(DateRangeField, {
2336
+ id: fieldId,
2337
+ value,
2338
+ dropdown: prop.display === "dropdown",
2339
+ invalid,
2340
+ clearable: !prop.required,
2341
+ onCommit
2342
+ })
2343
+ });
2344
+ case "COLOR": return /* @__PURE__ */ jsx(FieldShell, {
2345
+ htmlFor: fieldId,
2346
+ prop,
2347
+ invalid,
2348
+ picker,
2349
+ children: /* @__PURE__ */ jsx(ColorField, {
2350
+ id: fieldId,
2351
+ value,
2352
+ invalid,
2353
+ onCommit,
2354
+ onFocus: field.focus
2355
+ })
2356
+ });
2357
+ case "RICH_TEXT":
2358
+ case "LONG_TEXT":
2359
+ case "CUSTOM":
2360
+ case "JSON": {
2361
+ const isJson = prop.type === "JSON" || prop.type === "CUSTOM";
2362
+ const mode = prop.type === "RICH_TEXT" ? richTextMode(prop.formatProperty ? props.config?.[prop.formatProperty] : "") : null;
2363
+ return /* @__PURE__ */ jsxs(FieldShell, {
2364
+ htmlFor: fieldId,
2365
+ prop,
2366
+ invalid,
2367
+ picker: mode ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
2368
+ className: "rounded bg-muted px-1.5 text-[11px] text-muted-foreground",
2369
+ children: mode === "html" ? "HTML" : mode === "markdown" ? "Markdown" : "Plain text"
2370
+ }), picker] }) : picker,
2371
+ error: jsonError,
2372
+ children: [/* @__PURE__ */ jsx("textarea", {
2373
+ id: fieldId,
2374
+ ref: fieldRef,
2375
+ className: `${textAreaClass} ${isJson || mode === "html" || prop.display === "code" ? "font-mono text-xs" : ""} ${mode ? "min-h-32" : ""} ${invalid ? invalidClass : ""}`,
2376
+ defaultValue: stringifyValue(value),
2377
+ placeholder: prop.placeholder,
2378
+ spellCheck: false,
2379
+ onFocus: field.focus,
2380
+ onChange: (event) => setDraft(event.target.value),
2381
+ onBlur: (event) => {
2382
+ const raw = event.target.value;
2383
+ if (!isJson) return onCommit(raw === "" ? void 0 : raw);
2384
+ const trimmed = raw.trim();
2385
+ if (trimmed === "") {
2386
+ setJsonError(null);
2387
+ return onCommit(void 0);
2388
+ }
2389
+ if (WHOLE_EXPRESSION.test(trimmed)) {
2390
+ setJsonError(null);
2391
+ return onCommit(trimmed);
2392
+ }
2393
+ try {
2394
+ onCommit(JSON.parse(trimmed));
2395
+ setJsonError(null);
2396
+ } catch {
2397
+ setJsonError("Not valid JSON, so it wasn't saved.");
2398
+ }
2399
+ }
2400
+ }), /* @__PURE__ */ jsx(ExpressionTokenLine, { value: draft })]
2401
+ });
2402
+ }
2403
+ default: return /* @__PURE__ */ jsxs(FieldShell, {
2404
+ htmlFor: fieldId,
2405
+ prop,
2406
+ invalid,
2407
+ picker,
2408
+ children: [prop.emptyChoice && value === "" ? null : textInput({ commit: (raw) => onCommit(raw === "" ? void 0 : raw) }), prop.emptyChoice ? /* @__PURE__ */ jsxs("label", {
2409
+ className: "mt-1.5 flex items-center gap-2 text-xs text-muted-foreground",
2410
+ children: [/* @__PURE__ */ jsx("input", {
2411
+ type: "checkbox",
2412
+ className: "h-3.5 w-3.5 accent-current",
2413
+ checked: value === "",
2414
+ onChange: (event) => onCommit(event.target.checked ? "" : void 0, "MANUAL")
2415
+ }), prop.emptyChoice]
2416
+ }) : null]
2417
+ });
2418
+ }
2419
+ }
2420
+ const NO_BLOCK = {
2421
+ pieceName: "",
2422
+ pieceVersion: "",
2423
+ kind: "action",
2424
+ name: ""
2425
+ };
2426
+ function PropertyForm(props) {
2427
+ const echo = usePendingEcho({
2428
+ value: props.value,
2429
+ settings: props.settings ?? null
2430
+ }, (next, shown) => {
2431
+ if (next.settings !== shown.settings) props.onChange(next.value, next.settings ?? []);
2432
+ else props.onChange(next.value);
2433
+ });
2434
+ const { value: current, settings } = echo.value;
2435
+ const tracksSettings = props.writesSettings === true;
2436
+ const readDynamic = useDynamicCache();
2437
+ const withResolvedSchemas = (list, config) => {
2438
+ let next = list;
2439
+ for (const prop of props.props) {
2440
+ if (prop.type !== "DYNAMIC") continue;
2441
+ if (settingFor(next, prop.name)?.mode === "EXPRESSION") continue;
2442
+ const fields = readDynamic(resolverInputFor(props.block ?? NO_BLOCK, prop, config, props.connectionId, props.reactorConnectionId));
2443
+ if (!fields) continue;
2444
+ const schema = stripOptions(fields);
2445
+ const stored = settingFor(next, prop.name)?.schema ?? null;
2446
+ if (JSON.stringify(stored) === JSON.stringify(schema)) continue;
2447
+ next = withSetting(next, prop.name, { schema });
2448
+ }
2449
+ return next;
2450
+ };
2451
+ const commitField = (name, value, mode) => {
2452
+ const next = { ...current };
2453
+ if (value === void 0) delete next[name];
2454
+ else next[name] = value;
2455
+ let nextSettings = settings;
2456
+ const nextMode = mode ?? settingFor(settings, name)?.mode ?? "MANUAL";
2457
+ if (tracksSettings && settingFor(settings, name)?.mode !== nextMode) nextSettings = withSetting(nextSettings, name, { mode: nextMode });
2458
+ if (value !== current[name]) for (const dependent of props.props) {
2459
+ if (!dependent.refreshers?.includes(name)) continue;
2460
+ if (isDropdownType(dependent.type)) delete next[dependent.name];
2461
+ if (tracksSettings && dependent.type === "DYNAMIC" && settingFor(nextSettings, dependent.name)?.schema != null) nextSettings = withSetting(nextSettings, dependent.name, { schema: null });
2462
+ }
2463
+ if (tracksSettings) nextSettings = withResolvedSchemas(nextSettings, next);
2464
+ echo.commit({
2465
+ value: next,
2466
+ settings: nextSettings
2467
+ });
2468
+ };
2469
+ const setMode = (name, mode) => {
2470
+ if (!tracksSettings || settingFor(settings, name)?.mode === mode) return;
2471
+ echo.commit({
2472
+ value: current,
2473
+ settings: withResolvedSchemas(withSetting(settings, name, { mode }), current)
2474
+ });
2475
+ };
2476
+ const visible = props.props.filter((prop) => isPropVisible(prop, current));
2477
+ const essential = visible.filter((prop) => !prop.advanced);
2478
+ const advanced = visible.filter((prop) => prop.advanced);
2479
+ const [showAdvanced, setShowAdvanced] = useState(false);
2480
+ const advancedSet = advanced.filter((prop) => current[prop.name] !== void 0).length;
2481
+ const field = (prop) => /* @__PURE__ */ jsx(PropField, {
2482
+ prop,
2483
+ value: current[prop.name],
2484
+ onCommit: (value, mode) => commitField(prop.name, value, mode),
2485
+ mode: settingFor(settings, prop.name)?.mode,
2486
+ onMode: (mode) => setMode(prop.name, mode),
2487
+ loadOptions: props.loadOptions ? (propName, searchValue) => props.loadOptions(propName, current, searchValue) : void 0,
2488
+ config: current,
2489
+ secrets: props.secrets,
2490
+ scopeStepId: props.scopeStepId,
2491
+ optionsBlocked: props.optionsBlocked,
2492
+ explainOptionsError: props.explainOptionsError,
2493
+ resolverInput: resolverInputFor(props.block ?? NO_BLOCK, prop, current, props.connectionId, props.reactorConnectionId),
2494
+ waitingOn: props.props.find((sibling) => prop.refreshers?.includes(sibling.name) && isEmptyValue(current[sibling.name]))?.displayName,
2495
+ nested: props.nested,
2496
+ webhookUrl: props.webhookUrl
2497
+ }, prop.name);
2498
+ return /* @__PURE__ */ jsxs("div", {
2499
+ className: `flex flex-col ${props.nested ? "gap-3" : "gap-5"}`,
2500
+ onBlur: echo.onBlur,
2501
+ children: [/* @__PURE__ */ jsx(PropLayout, {
2502
+ props: essential,
2503
+ groups: props.groups,
2504
+ values: current,
2505
+ renderField: field,
2506
+ onCommit: commitField
2507
+ }), advanced.length > 0 ? /* @__PURE__ */ jsxs("div", {
2508
+ className: "flex flex-col gap-5 border-t border-solid border-foreground/10 pt-4",
2509
+ children: [/* @__PURE__ */ jsxs("button", {
2510
+ type: "button",
2511
+ className: "-mx-1 flex items-center gap-1.5 self-start rounded px-1 text-[13px] font-medium text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40",
2512
+ "aria-expanded": showAdvanced,
2513
+ onClick: () => setShowAdvanced((open) => !open),
2514
+ children: [
2515
+ /* @__PURE__ */ jsx(Icon, {
2516
+ name: "chevron",
2517
+ className: `h-3.5 w-3.5 transition-transform ${showAdvanced ? "rotate-90" : ""}`
2518
+ }),
2519
+ "More options",
2520
+ /* @__PURE__ */ jsx("span", {
2521
+ className: "font-normal",
2522
+ children: advancedSet > 0 ? `${advanced.length} fields, ${advancedSet} set` : `${advanced.length} fields`
2523
+ })
2524
+ ]
2525
+ }), /* @__PURE__ */ jsx("div", {
2526
+ hidden: !showAdvanced,
2527
+ className: "flex flex-col gap-5",
2528
+ children: /* @__PURE__ */ jsx(PropLayout, {
2529
+ props: advanced,
2530
+ groups: props.groups,
2531
+ values: current,
2532
+ renderField: field,
2533
+ onCommit: commitField
2534
+ })
2535
+ })]
2536
+ }) : null]
2537
+ });
2538
+ }
2539
+ //#endregion
2540
+ //#region editors/workflow-editor/ui/model.ts
2541
+ const VARIABLES_VIEW = "__variables";
2542
+ /** Query params of the editor's view: the open panel and its tab. */
2543
+ const STEP_PARAM = "step";
2544
+ function hasDraftChanges(model) {
2545
+ return !model.published || model.published.version !== model.version;
2546
+ }
2547
+ function uniqueStepKey(taken, label) {
2548
+ const base = label.toLowerCase().replaceAll(/[^a-z0-9]+/g, "_").replaceAll(/^_+|_+$/g, "") || "step";
2549
+ const keys = new Set(taken);
2550
+ let key = base;
2551
+ let suffix = 2;
2552
+ while (keys.has(key)) key = `${base}_${suffix++}`;
2553
+ return key;
2554
+ }
2555
+ //#endregion
2556
+ //#region editors/workflow-editor/ui/PublishControls.tsx
2557
+ function blockedReason(readiness) {
2558
+ if (!readiness.hasTrigger) return "Add a trigger first";
2559
+ if (readiness.firstIncomplete) return "You have incomplete steps";
2560
+ return "Checking the steps…";
2561
+ }
2562
+ function usePublish(callbacks) {
2563
+ const [publishing, setPublishing] = useState(false);
2564
+ const [error, setError] = useState(null);
2565
+ const publish = () => {
2566
+ if (publishing) return;
2567
+ setPublishing(true);
2568
+ setError(null);
2569
+ callbacks.publish().catch((cause) => setError(cause instanceof Error ? cause.message : String(cause))).finally(() => setPublishing(false));
2570
+ };
2571
+ return {
2572
+ publishing,
2573
+ error,
2574
+ publish
2575
+ };
2576
+ }
2577
+ function PublishButton(props) {
2578
+ const { model, readiness } = props;
2579
+ if (props.signIn?.required) return /* @__PURE__ */ jsx(Tooltip, {
2580
+ content: "This Switchboard enforces document permissions, so a publish must be signed",
2581
+ children: /* @__PURE__ */ jsx(Button, {
2582
+ size: props.size ?? "sm",
2583
+ variant: "primary",
2584
+ disabled: props.signIn.pending,
2585
+ onClick: props.signIn.login,
2586
+ children: "Sign in to publish"
2587
+ })
2588
+ });
2589
+ const incomplete = !readiness.ready;
2590
+ const changes = hasDraftChanges(model);
2591
+ const target = readiness.firstIncomplete;
2592
+ const select = () => {
2593
+ if (target) props.onSelect(target);
2594
+ };
2595
+ return /* @__PURE__ */ jsx(Tooltip, {
2596
+ enabled: incomplete,
2597
+ content: /* @__PURE__ */ jsx("button", {
2598
+ type: "button",
2599
+ className: "font-medium text-wf-warn hover:underline",
2600
+ onClick: select,
2601
+ children: blockedReason(readiness)
2602
+ }),
2603
+ children: /* @__PURE__ */ jsx("span", {
2604
+ className: "inline-flex",
2605
+ onClick: incomplete ? select : void 0,
2606
+ children: /* @__PURE__ */ jsx(Button, {
2607
+ size: props.size ?? "sm",
2608
+ variant: "primary",
2609
+ disabled: incomplete || !changes || props.publishing,
2610
+ title: !changes && !incomplete ? "No unpublished changes" : void 0,
2611
+ onClick: props.onPublish,
2612
+ children: props.publishing ? "Publishing…" : "Publish"
2613
+ })
2614
+ })
2615
+ });
2616
+ }
2617
+ function PublishState(props) {
2618
+ const draft = hasDraftChanges(props.model);
2619
+ return /* @__PURE__ */ jsxs("span", {
2620
+ className: "flex shrink-0 items-center gap-1.5 whitespace-nowrap text-xs text-muted-foreground",
2621
+ title: props.model.published ? `Published ${new Date(props.model.published.publishedAt).toLocaleString()}` : "Never published",
2622
+ children: [
2623
+ /* @__PURE__ */ jsx("span", {
2624
+ "aria-hidden": true,
2625
+ className: `h-2 w-2 rounded-full ${draft ? "bg-wf-warn" : "bg-wf-ok"}`
2626
+ }),
2627
+ /* @__PURE__ */ jsx("span", { children: !props.model.published ? "Draft" : draft ? "Unpublished changes" : "Published" }),
2628
+ props.model.published && draft ? /* @__PURE__ */ jsxs("span", {
2629
+ className: "text-muted-foreground/80",
2630
+ children: [
2631
+ "· v",
2632
+ props.model.published.version,
2633
+ " live"
2634
+ ]
2635
+ }) : null
2636
+ ]
2637
+ });
2638
+ }
2639
+ function StatusToggle(props) {
2640
+ const allowed = props.published;
2641
+ const on = props.status === "ENABLED";
2642
+ return /* @__PURE__ */ jsx(Tooltip, {
2643
+ enabled: !allowed,
2644
+ content: "Publish the workflow first",
2645
+ align: "end",
2646
+ side: props.tooltipSide,
2647
+ children: /* @__PURE__ */ jsxs("span", {
2648
+ className: "flex items-center gap-2 text-xs text-muted-foreground",
2649
+ children: [/* @__PURE__ */ jsx(Toggle, {
2650
+ checked: on,
2651
+ disabled: !allowed,
2652
+ label: on ? "Turn the workflow off" : "Turn the workflow on",
2653
+ onChange: (checked) => props.onChange(checked ? "ENABLED" : "DISABLED")
2654
+ }), /* @__PURE__ */ jsx("span", {
2655
+ className: "w-6",
2656
+ children: on ? "On" : "Off"
2657
+ })]
2658
+ })
2659
+ });
2660
+ }
2661
+ function PublishedMissingNote(props) {
2662
+ if (props.missing.length === 0) return null;
2663
+ return /* @__PURE__ */ jsx("span", {
2664
+ role: "alert",
2665
+ "aria-label": "Published version incomplete",
2666
+ className: "shrink-0 whitespace-nowrap rounded-full bg-wf-warn/12 px-2 py-0.5 text-xs text-wf-warn",
2667
+ title: `The published version is missing a reactor connection on: ${props.missing.join(", ")}`,
2668
+ children: "Live version incomplete"
2669
+ });
2670
+ }
2671
+ function ReactorDenialNote(props) {
2672
+ if (!props.denial) return null;
2673
+ return /* @__PURE__ */ jsxs("span", {
2674
+ role: "alert",
2675
+ "aria-label": "Reactor access denied",
2676
+ className: "max-w-80 truncate rounded-full bg-wf-warn/12 px-2 py-0.5 text-xs text-wf-warn",
2677
+ title: props.denial,
2678
+ children: ["No reactor access: ", props.denial]
2679
+ });
2680
+ }
2681
+ /** Instead of the draft banner on a managed workflow: who keeps it, and that edits here are not saved. */
2682
+ function ManagedBanner(props) {
2683
+ const manager = props.model.managedBy;
2684
+ if (!manager) return null;
2685
+ return /* @__PURE__ */ jsxs("div", {
2686
+ role: "status",
2687
+ className: "pointer-events-auto flex max-w-xl items-center gap-3 rounded-lg border border-solid border-foreground/10 bg-card px-3 py-1.5 text-[13px] shadow-sm",
2688
+ children: [/* @__PURE__ */ jsx("span", {
2689
+ className: "h-2 w-2 shrink-0 rounded-full bg-muted-foreground",
2690
+ "aria-hidden": true
2691
+ }), /* @__PURE__ */ jsxs("span", {
2692
+ className: "text-foreground",
2693
+ children: [
2694
+ "Managed by ",
2695
+ /* @__PURE__ */ jsx("strong", { children: manager.label || manager.documentType }),
2696
+ ". Change it there: edits here are not saved."
2697
+ ]
2698
+ })]
2699
+ });
2700
+ }
2701
+ function DraftBanner(props) {
2702
+ if (!hasDraftChanges(props.model)) return null;
2703
+ const { readiness } = props;
2704
+ const target = readiness.firstIncomplete;
2705
+ return /* @__PURE__ */ jsxs("div", {
2706
+ role: "status",
2707
+ className: "pointer-events-auto flex items-center gap-3 rounded-lg border border-solid border-foreground/10 bg-card py-1.5 pl-3 pr-1.5 text-[13px] shadow-sm",
2708
+ children: [
2709
+ /* @__PURE__ */ jsx("span", {
2710
+ className: "h-2 w-2 shrink-0 rounded-full bg-wf-warn",
2711
+ "aria-hidden": true
2712
+ }),
2713
+ /* @__PURE__ */ jsx("span", {
2714
+ className: "text-foreground",
2715
+ children: "You have unpublished changes"
2716
+ }),
2717
+ props.error ? /* @__PURE__ */ jsx("span", {
2718
+ className: "text-xs text-wf-fail",
2719
+ children: props.error
2720
+ }) : null,
2721
+ !readiness.hasTrigger || target ? /* @__PURE__ */ jsxs("span", {
2722
+ className: "flex items-center gap-1.5 text-xs text-wf-warn",
2723
+ children: [/* @__PURE__ */ jsx("span", { children: target ? "Incomplete steps" : "No trigger yet" }), target ? /* @__PURE__ */ jsx("button", {
2724
+ type: "button",
2725
+ className: "font-medium underline underline-offset-2 hover:no-underline",
2726
+ onClick: () => props.onSelect(target),
2727
+ children: "Show"
2728
+ }) : null]
2729
+ }) : null,
2730
+ /* @__PURE__ */ jsxs("span", {
2731
+ className: "flex items-center gap-1",
2732
+ children: [props.model.published ? /* @__PURE__ */ jsx(Button, {
2733
+ size: "sm",
2734
+ variant: "ghost",
2735
+ onClick: props.onDiscard,
2736
+ children: "Discard changes"
2737
+ }) : null, /* @__PURE__ */ jsx(PublishButton, {
2738
+ model: props.model,
2739
+ readiness,
2740
+ publishing: props.publishing,
2741
+ onPublish: props.onPublish,
2742
+ onSelect: props.onSelect,
2743
+ signIn: props.signIn
2744
+ })]
2745
+ })
2746
+ ]
2747
+ });
2748
+ }
2749
+ //#endregion
2750
+ //#region editors/workflow-editor/ui/StepError.tsx
2751
+ function StepError(props) {
2752
+ return /* @__PURE__ */ jsx("pre", {
2753
+ className: "overflow-auto whitespace-pre-wrap rounded-md bg-wf-fail/10 p-2.5 text-xs text-wf-fail",
2754
+ children: props.error
2755
+ });
2756
+ }
2757
+ //#endregion
2758
+ //#region editors/shared/document-ref.tsx
2759
+ const SHOWN = 3;
2760
+ function shortId(id) {
2761
+ return id.length > 16 ? `${id.slice(0, 6)}…${id.slice(-6)}` : id;
2762
+ }
2763
+ function revisionText(reference) {
2764
+ const scopes = Object.entries(reference.revision).map(([scope, count]) => `${scope} ${count}`).join(" · ");
2765
+ return reference.branch === "main" ? scopes : `${reference.branch}: ${scopes}`;
2766
+ }
2767
+ function DocumentRefRow(props) {
2768
+ const { reference } = props;
2769
+ const setSelectedNode = useSetSelectedNode();
2770
+ return /* @__PURE__ */ jsxs("li", {
2771
+ "aria-label": `Document ${reference.documentId}`,
2772
+ className: "flex items-center gap-2",
2773
+ children: [/* @__PURE__ */ jsxs("div", {
2774
+ className: "min-w-0 flex-1 text-xs",
2775
+ children: [/* @__PURE__ */ jsxs("div", {
2776
+ className: "flex min-w-0 items-baseline gap-1.5",
2777
+ children: [/* @__PURE__ */ jsx("span", {
2778
+ className: "truncate font-medium text-foreground",
2779
+ children: reference.documentType
2780
+ }), /* @__PURE__ */ jsx("span", {
2781
+ className: "shrink-0 font-mono text-[11px] text-muted-foreground",
2782
+ title: reference.documentId,
2783
+ children: shortId(reference.documentId)
2784
+ })]
2785
+ }), /* @__PURE__ */ jsxs("div", {
2786
+ className: "truncate text-[11px] text-muted-foreground",
2787
+ children: ["Revision ", revisionText(reference)]
2788
+ })]
2789
+ }), /* @__PURE__ */ jsx(Button, {
2790
+ size: "sm",
2791
+ onClick: () => setSelectedNode(reference.documentId),
2792
+ "aria-label": `Open document ${reference.documentId}`,
2793
+ children: "Open document"
2794
+ })]
2795
+ });
2796
+ }
2797
+ function DocumentRefs(props) {
2798
+ const { references } = props;
2799
+ const hidden = references.length - SHOWN;
2800
+ return /* @__PURE__ */ jsxs("div", {
2801
+ role: "group",
2802
+ "aria-label": "Document references",
2803
+ className: "flex flex-col gap-1.5",
2804
+ children: [
2805
+ /* @__PURE__ */ jsx("ul", {
2806
+ className: "m-0 flex list-none flex-col gap-1.5 p-0",
2807
+ children: references.slice(0, SHOWN).map((reference, index) => /* @__PURE__ */ jsx(DocumentRefRow, { reference }, `${reference.documentId}-${index}`))
2808
+ }),
2809
+ hidden > 0 ? /* @__PURE__ */ jsxs("p", {
2810
+ className: "text-[11px] text-muted-foreground",
2811
+ children: [
2812
+ "and ",
2813
+ hidden,
2814
+ " more in the data below"
2815
+ ]
2816
+ }) : null,
2817
+ /* @__PURE__ */ jsx("p", {
2818
+ className: "text-[11px] text-muted-foreground",
2819
+ children: "The run kept a reference, not the state. Opening shows the document as it is now: past revisions can't be read yet (#3179)."
2820
+ })
2821
+ ]
2822
+ });
2823
+ }
2824
+ //#endregion
2825
+ //#region editors/shared/data-viewer.tsx
2826
+ const DataTree = lazy(() => import("./data-tree-CebWVI_P.mjs"));
2827
+ function stringify(value) {
2828
+ try {
2829
+ return JSON.stringify(value, null, 2) ?? "";
2830
+ } catch {
2831
+ return String(value);
2832
+ }
2833
+ }
2834
+ function isEmpty(value) {
2835
+ if (value === void 0 || value === null) return true;
2836
+ if (typeof value === "object") return Object.keys(value).length === 0;
2837
+ return false;
2838
+ }
2839
+ function RawJson(props) {
2840
+ return /* @__PURE__ */ jsx("pre", {
2841
+ className: "max-h-72 overflow-auto whitespace-pre-wrap break-words font-mono text-xs text-foreground",
2842
+ children: props.text
2843
+ });
2844
+ }
2845
+ function TreeSkeleton() {
2846
+ return /* @__PURE__ */ jsx("div", {
2847
+ role: "status",
2848
+ "aria-label": "Loading data",
2849
+ className: "flex animate-pulse flex-col gap-2 py-1",
2850
+ children: [
2851
+ "w-2/5",
2852
+ "w-3/5",
2853
+ "w-1/2",
2854
+ "w-1/3"
2855
+ ].map((width, index) => /* @__PURE__ */ jsx("span", {
2856
+ className: `h-2.5 rounded bg-muted ${width}`,
2857
+ style: { marginLeft: index === 0 ? 0 : 16 }
2858
+ }, width))
2859
+ });
2860
+ }
2861
+ function DataViewer(props) {
2862
+ const [raw, setRaw] = useState(false);
2863
+ const [copied, setCopied] = useState(false);
2864
+ const empty = isEmpty(props.value);
2865
+ const text = stringify(props.value);
2866
+ const tree = typeof props.value === "object" && props.value !== null;
2867
+ const references = tree ? documentRefsIn(props.value) : [];
2868
+ const treeValue = isDocumentRefMarker(props.value) ? Object.fromEntries(Object.entries(props.value).filter(([key]) => key !== DOCUMENT_REF_KEY)) : props.value;
2869
+ return /* @__PURE__ */ jsxs("section", {
2870
+ "aria-label": props.label,
2871
+ className: "min-w-0 rounded-md border border-solid border-border bg-card",
2872
+ children: [/* @__PURE__ */ jsxs("header", {
2873
+ className: "flex h-8 items-center gap-1 border-b border-solid border-border pl-3 pr-1",
2874
+ children: [
2875
+ /* @__PURE__ */ jsx("h4", {
2876
+ className: "mr-auto text-xs font-medium text-foreground",
2877
+ children: props.label
2878
+ }),
2879
+ !empty && tree ? /* @__PURE__ */ jsx("button", {
2880
+ type: "button",
2881
+ "aria-pressed": raw,
2882
+ className: "rounded px-1.5 py-0.5 text-[11px] text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40",
2883
+ onClick: () => setRaw((value) => !value),
2884
+ children: raw ? "Tree" : "JSON"
2885
+ }) : null,
2886
+ !empty ? /* @__PURE__ */ jsx(IconButton, {
2887
+ icon: copied ? "check" : "copy",
2888
+ label: `Copy ${props.label.toLowerCase()} as JSON`,
2889
+ onClick: () => {
2890
+ navigator.clipboard.writeText(text).then(() => {
2891
+ setCopied(true);
2892
+ setTimeout(() => setCopied(false), 1500);
2893
+ });
2894
+ }
2895
+ }) : null
2896
+ ]
2897
+ }), /* @__PURE__ */ jsx("div", {
2898
+ className: "px-3 py-2",
2899
+ children: empty ? /* @__PURE__ */ jsx("p", {
2900
+ className: "text-xs text-muted-foreground",
2901
+ children: props.emptyText ?? "Nothing"
2902
+ }) : !tree ? /* @__PURE__ */ jsx("p", {
2903
+ className: "break-words font-mono text-xs text-foreground",
2904
+ children: text
2905
+ }) : raw ? /* @__PURE__ */ jsx(RawJson, { text }) : /* @__PURE__ */ jsxs("div", {
2906
+ className: "flex flex-col gap-2",
2907
+ children: [references.length > 0 ? /* @__PURE__ */ jsx(DocumentRefs, { references }) : null, isEmpty(treeValue) ? null : /* @__PURE__ */ jsx("div", {
2908
+ className: "max-h-72 overflow-auto",
2909
+ children: /* @__PURE__ */ jsx(Suspense, {
2910
+ fallback: /* @__PURE__ */ jsx(TreeSkeleton, {}),
2911
+ children: /* @__PURE__ */ jsx(DataTree, {
2912
+ value: treeValue,
2913
+ root: props.root
2914
+ })
2915
+ })
2916
+ })]
2917
+ })
2918
+ })]
2919
+ });
2920
+ }
2921
+ //#endregion
2922
+ //#region editors/workflow-editor/ui/trigger-text.ts
2923
+ const WEEKDAYS = [
2924
+ "Sunday",
2925
+ "Monday",
2926
+ "Tuesday",
2927
+ "Wednesday",
2928
+ "Thursday",
2929
+ "Friday",
2930
+ "Saturday"
2931
+ ];
2932
+ const UNIT_LABEL = {
2933
+ minutes: ["minute", "minutes"],
2934
+ hours: ["hour", "hours"],
2935
+ days: ["day", "days"]
2936
+ };
2937
+ function isInt(field) {
2938
+ return /^\d+$/.test(field);
2939
+ }
2940
+ function clock(hour, minute) {
2941
+ return `${hour.padStart(2, "0")}:${minute.padStart(2, "0")}`;
2942
+ }
2943
+ function dayList(field) {
2944
+ if (field === "1-5") return "on weekdays";
2945
+ if (field === "0,6" || field === "6,0") return "at weekends";
2946
+ const days = field.split(",");
2947
+ if (!days.every((day) => isInt(day) && Number(day) <= 7)) return void 0;
2948
+ const names = days.map((day) => WEEKDAYS[Number(day) % 7]);
2949
+ if (names.length === 1) return `every ${names[0]}`;
2950
+ return `on ${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
2951
+ }
2952
+ /** Describes a five-field cron expression, or returns undefined. */
2953
+ function describeCron(cron) {
2954
+ const fields = cron.trim().split(/\s+/);
2955
+ if (fields.length !== 5) return void 0;
2956
+ const [minute, hour, dayOfMonth, month, dayOfWeek] = fields;
2957
+ if (month !== "*") return void 0;
2958
+ const everyMinutes = /^\*\/(\d+)$/.exec(minute);
2959
+ if (everyMinutes && hour === "*" && dayOfMonth === "*" && dayOfWeek === "*") {
2960
+ const n = Number(everyMinutes[1]);
2961
+ return n === 1 ? "Every minute" : `Every ${n} minutes`;
2962
+ }
2963
+ if (minute === "*" && hour === "*" && dayOfMonth === "*" && dayOfWeek === "*") return "Every minute";
2964
+ if (isInt(minute) && hour === "*" && dayOfMonth === "*" && dayOfWeek === "*") return minute === "0" ? "Every hour, on the hour" : `Every hour at ${minute.padStart(2, "0")} past`;
2965
+ const everyHours = /^\*\/(\d+)$/.exec(hour);
2966
+ if (isInt(minute) && everyHours && dayOfMonth === "*" && dayOfWeek === "*") return `Every ${everyHours[1]} hours`;
2967
+ if (!isInt(minute) || !isInt(hour)) return void 0;
2968
+ const at = clock(hour, minute);
2969
+ if (dayOfMonth === "*" && dayOfWeek === "*") return `Every day at ${at}`;
2970
+ if (dayOfMonth === "*") {
2971
+ const days = dayList(dayOfWeek);
2972
+ return days ? `${days.charAt(0).toUpperCase()}${days.slice(1)} at ${at}` : void 0;
2973
+ }
2974
+ if (isInt(dayOfMonth) && dayOfWeek === "*") return `Every month on day ${dayOfMonth} at ${at}`;
2975
+ }
2976
+ function describeSchedule(config) {
2977
+ let schedule;
2978
+ try {
2979
+ schedule = parseScheduleConfig(config);
2980
+ } catch {
2981
+ return "On a schedule that does not parse";
2982
+ }
2983
+ if (schedule.mode === "interval") {
2984
+ const unit = UNIT_LABEL[schedule.unit];
2985
+ return schedule.every === 1 ? `Every ${unit[0]}` : `Every ${schedule.every} ${unit[1]}`;
2986
+ }
2987
+ const described = describeCron(schedule.cron);
2988
+ return described ? `${described} ${schedule.timezone}` : `On schedule ${schedule.cron}`;
2989
+ }
2990
+ function literal(config, key) {
2991
+ if (!config || typeof config !== "object") return void 0;
2992
+ const value = config[key];
2993
+ if (typeof value !== "string") return void 0;
2994
+ const text = value.trim();
2995
+ return text && !text.includes("{{") ? text : void 0;
2996
+ }
2997
+ function documentTypeLabel(documentType) {
2998
+ return (documentType.split("/").pop() ?? documentType).split(/[-_\s]+/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
2999
+ }
3000
+ function actionTypeLabel(actionType) {
3001
+ const text = actionType.toLowerCase().split(/[_\s]+/).filter(Boolean).join(" ");
3002
+ return text.charAt(0).toUpperCase() + text.slice(1);
3003
+ }
3004
+ /** Describes a reactor document trigger by what it filters on. */
3005
+ function describeDocumentTrigger(triggerName, config) {
3006
+ const documentType = literal(config, "documentType");
3007
+ const label = documentType ? documentTypeLabel(documentType) : "";
3008
+ const subject = label ? `${/^[AEIOU]/.test(label) ? "an" : "a"} ${label}` : literal(config, "documentId") ? "its document" : "a document";
3009
+ switch (triggerName) {
3010
+ case "document-event": {
3011
+ const actionType = literal(config, "actionType");
3012
+ return actionType ? `When ${actionTypeLabel(actionType)} runs on ${subject}` : `When ${subject} changes`;
3013
+ }
3014
+ case "document-created": return `When ${subject} is created`;
3015
+ case "document-deleted": return `When ${subject} is deleted`;
3016
+ default: return;
3017
+ }
3018
+ }
3019
+ /** When a workflow starts, from its trigger. */
3020
+ function describeTrigger(trigger) {
3021
+ if (!trigger) return "Never starts: no trigger";
3022
+ const block = {
3023
+ pieceName: trigger.pieceName,
3024
+ kind: "trigger",
3025
+ name: trigger.triggerName
3026
+ };
3027
+ switch (blockKey(block)) {
3028
+ case blockKey(MANUAL_TRIGGER): return "Manual";
3029
+ case blockKey(WEBHOOK_TRIGGER): return "When its webhook is called";
3030
+ case blockKey(SCHEDULE_TRIGGER): return describeSchedule(trigger.config);
3031
+ default: {
3032
+ if (trigger.pieceName === "@powerhousedao/piece-reactor") {
3033
+ const described = describeDocumentTrigger(trigger.triggerName, trigger.config);
3034
+ if (described) return described;
3035
+ }
3036
+ const meta = blockMeta(block);
3037
+ const piece = meta.subtitle.replace(/ · Trigger$/, "");
3038
+ return `${meta.displayName} in ${piece}`;
3039
+ }
3040
+ }
3041
+ }
3042
+ //#endregion
3043
+ export { EMPTY_SCOPE as A, menuHeight as B, useSecretRef as C, ExpressionTargetProvider as D, ExpressionScopeSourceProvider as E, parseTypedValue as F, usePendingEcho as H, valueMismatch as I, documentShape as L, VARIABLE_TYPES as M, VARIABLE_TYPE_LABEL as N, ExpressionTokenLine as O, convertVariableValue as P, stateFieldsFromSdl as R, withPropDefaults as S, ExpressionPickerPopup as T, menuPosition as V, uniqueStepKey as _, StepError as a, PropertyForm as b, PublishButton as c, ReactorDenialNote as d, StatusToggle as f, hasDraftChanges as g, VARIABLES_VIEW as h, DataViewer as i, buildExpressionScope as j, useExpressionField as k, PublishState as l, STEP_PARAM as m, describeSchedule as n, DraftBanner as o, usePublish as p, describeTrigger as r, ManagedBanner as s, describeCron as t, PublishedMissingNote as u, AvailableSoon as v, ExpressionPickerButton as w, lacksDefaults as x, PiecePlaceholderContext as y, contextMenuItems as z };
3044
+
3045
+ //# sourceMappingURL=trigger-text-BvEzEani.mjs.map