@overvis/hmi-workspace-ui 0.1.0 → 0.1.2

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 (130) hide show
  1. package/dist/alarm-list-DKFio0hg.js +414 -0
  2. package/dist/alarm-rule-dialog-mb4_nHRW.js +417 -0
  3. package/dist/{alarm-rule-lists-C5v1Kf7A.js → alarm-rule-lists-CfZXTWkK.js} +123 -125
  4. package/dist/{alarm-rules-page-CqFzofPd.js → alarm-rules-page-DBLSkrrG.js} +15 -18
  5. package/dist/alert-dialog-D_iDv2lQ.js +891 -0
  6. package/dist/{base-revision-YCO27zR4.js → base-revision-DLF9EnGV.js} +26 -29
  7. package/dist/{breadcrumbs-0cjsV2cq.js → breadcrumbs-D5R6Fz74.js} +6 -7
  8. package/dist/{catalog-list-DjZojYLJ.js → catalog-list-BkWosvh1.js} +2 -4
  9. package/dist/{code-editor-BVimvjDV.js → code-editor-DCM0KdMJ.js} +9 -6
  10. package/dist/dashboard-bindings.js +1 -2
  11. package/dist/{dashboards-page-BlrJguNz.js → dashboards-page-DLc11Vzu.js} +335 -359
  12. package/dist/{de-14WdmJxZ.js → de-Z2er-E5v.js} +4 -2
  13. package/dist/diagnostic-text-CYZFPiND.js +116 -0
  14. package/dist/{dialogs-D_v1LeH4.js → dialogs-BX023zml.js} +2523 -2590
  15. package/dist/{dialogs-B6BRnf3Q.js → dialogs-DEOg9lxy.js} +219 -227
  16. package/dist/{display-DmOo23mi.js → display-VYGzneE0.js} +4 -6
  17. package/dist/{editor-language-To9MxloY.js → editor-language-CGENZxbI.js} +3 -5
  18. package/dist/editor-page-CaN52OQh.js +1337 -0
  19. package/dist/{en-BgercpT0.js → en-CKPPL6bQ.js} +4 -2
  20. package/dist/entity-controls-DJT47yeV.js +71 -0
  21. package/dist/errors-BAWoH_5w.js +25 -0
  22. package/dist/{footer-DC-Q0052.js → footer-CbPMP8aq.js} +2404 -2515
  23. package/dist/host.js +8254 -675
  24. package/dist/{i18n-BgzakKoC.js → i18n-ChjEbYEg.js} +77 -90
  25. package/dist/i18n.js +1 -2
  26. package/dist/index.js +5168 -5353
  27. package/dist/{lat-lng-B12P7QyY.js → lat-lng-Bl77AGSO.js} +1 -2
  28. package/dist/{list-page-CvsdZb86.js → list-page-Fa29SkaJ.js} +116 -123
  29. package/dist/{location-map-renderer-DO5yfdSU.js → location-map-renderer-DvXIYc1Z.js} +6 -6
  30. package/dist/{location-picker-renderer-CjCxg6ai.js → location-picker-renderer-B1_-n8lf.js} +3 -4
  31. package/dist/{model-B8gGi4OK.js → model-tpg_xpFB.js} +1 -2
  32. package/dist/{notice-card-DyGywFsW.js → notice-card-V_0K0lO0.js} +54 -58
  33. package/dist/page-B5te_1Lc.js +449 -0
  34. package/dist/{page-v6LCwswN.js → page-BorlLnMX.js} +92 -100
  35. package/dist/page-DxF7FOve.js +507 -0
  36. package/dist/panel-DuZD-cBP.js +949 -0
  37. package/dist/parameter-values.js +3 -16
  38. package/dist/{pl-lQ9HXV9k.js → pl-DVABrn5G.js} +4 -2
  39. package/dist/presence-code-DsabLTZs.js +73 -0
  40. package/dist/{query-gate-DVhNIkge.js → query-gate-BbIo1Xrj.js} +6 -6
  41. package/dist/{provider-DoEpKcQ-.js → quick-report-BcZsfkCZ.js} +9423 -5102
  42. package/dist/{retention-BYXNpYmR.js → retention-C7EZsq8u.js} +4 -6
  43. package/dist/retention-note-CmMeHV_u.js +40 -0
  44. package/dist/{rolldown-runtime-Dy4uBu1J.js → rolldown-runtime-CGnMp29N.js} +1 -2
  45. package/dist/{ru-qTKINoUj.js → ru-CBRLC_xM.js} +8 -6
  46. package/dist/run-text-CDdfbKbg.js +112 -0
  47. package/dist/{search-D4rDnE9T.js → search-C6xQ_Hvo.js} +26 -29
  48. package/dist/{sections-kCOyc4NR.js → sections-D_SBfVzV.js} +2 -3
  49. package/dist/{select-BKiOWdSr.js → select-nNLG-AMz.js} +17 -23
  50. package/dist/{spinner-C-HPNxOc.js → spinner-B-KLtBjp.js} +182 -201
  51. package/dist/src/code-editor/code-editor.d.ts +3 -0
  52. package/dist/src/code-editor/taskfile-language.d.ts +22 -2
  53. package/dist/src/i18n/catalogs/de/edge-program.d.ts +3 -0
  54. package/dist/src/i18n/catalogs/de.d.ts +3 -0
  55. package/dist/src/i18n/catalogs/en/edge-program.d.ts +3 -0
  56. package/dist/src/i18n/catalogs/en.d.ts +3 -0
  57. package/dist/src/i18n/catalogs/pl/edge-program.d.ts +3 -0
  58. package/dist/src/i18n/catalogs/pl.d.ts +3 -0
  59. package/dist/src/i18n/catalogs/ru/edge-program.d.ts +5 -2
  60. package/dist/src/i18n/catalogs/ru/graphics.d.ts +2 -2
  61. package/dist/src/i18n/catalogs/ru.d.ts +7 -4
  62. package/dist/src/i18n/catalogs/uk/edge-program.d.ts +5 -2
  63. package/dist/src/i18n/catalogs/uk/graphics.d.ts +2 -2
  64. package/dist/src/i18n/catalogs/uk.d.ts +7 -4
  65. package/dist/src/version.d.ts +1 -1
  66. package/dist/src/workspace/graphics/inspector/item.d.ts +6 -6
  67. package/dist/src/workspace/local-workspace-app.d.ts +1 -1
  68. package/dist/src/workspace/routes.d.ts +1 -1
  69. package/dist/{starter-fields-BRLX0z-v.js → starter-fields-7S3LmtGa.js} +154 -157
  70. package/dist/{starter-handoff-BA3ucMKL.js → starter-handoff-BaK8Ss8I.js} +1 -2
  71. package/dist/styles.css +1 -1
  72. package/dist/ui.js +334 -374
  73. package/dist/{uk-CwpJAxmx.js → uk-17pbVYZa.js} +8 -6
  74. package/dist/{wireguard-docs-AfU6NzTL.js → wireguard-docs-Clb-7xRY.js} +14 -17
  75. package/package.json +15 -9
  76. package/dist/alarm-list-BL3xQ5Lf.js +0 -423
  77. package/dist/alarm-rule-dialog-S1ZUg-74.js +0 -423
  78. package/dist/alert-B8MAoIO8.js +0 -45
  79. package/dist/alert-dialog-CYkuMg5D.js +0 -129
  80. package/dist/api-error-9rQmUN5L.js +0 -93
  81. package/dist/breadcrumb-DzVL1yHa.js +0 -74
  82. package/dist/button-6SxPBYMz.js +0 -44
  83. package/dist/context-u9KJQmdB.js +0 -102
  84. package/dist/copyable-id-DYGiAcnq.js +0 -40
  85. package/dist/dashboard-context-CBfG6DoT.js +0 -191
  86. package/dist/date-time-picker-C3FhMXk6.js +0 -266
  87. package/dist/diagnostic-text-BAkzW0SE.js +0 -111
  88. package/dist/diagnostic-text-DiKd2i1w.js +0 -76
  89. package/dist/dialog-BIhQXcZC.js +0 -237
  90. package/dist/dialog-BqyIxMD-.js +0 -54
  91. package/dist/dropdown-menu-DSzbBq3v.js +0 -136
  92. package/dist/editor-page-BiSZJz5b.js +0 -1353
  93. package/dist/empty-B-QJ-06w.js +0 -59
  94. package/dist/entity-controls-D1K4Ot3O.js +0 -76
  95. package/dist/errors-CcsvDHu8.js +0 -26
  96. package/dist/history-page-sAAhG54V.js +0 -1400
  97. package/dist/icon-D-pR9htW.js +0 -57
  98. package/dist/index-page-DMH82fZe.js +0 -214
  99. package/dist/item-B5SaTFQU.js +0 -120
  100. package/dist/mutation-form-validators-BNz5bsv1.js +0 -2408
  101. package/dist/mutations-THtGG6Ai.js +0 -240
  102. package/dist/page-2KPemaAj.js +0 -328
  103. package/dist/page-6rIoTg2L.js +0 -459
  104. package/dist/page-C6giEoEd.js +0 -1935
  105. package/dist/page-DCbTxKsi.js +0 -313
  106. package/dist/page-DWO427hT.js +0 -208
  107. package/dist/page-LXu_2zm3.js +0 -137
  108. package/dist/page-aaUiVOnk.js +0 -513
  109. package/dist/page-header-RB2YFWlE.js +0 -55
  110. package/dist/page-title-CdCbiLt8.js +0 -14
  111. package/dist/panel-DDy8tUNR.js +0 -338
  112. package/dist/presence-code-BfSXr50g.js +0 -83
  113. package/dist/progress-C7cxNJA1.js +0 -83
  114. package/dist/provider-BOeYHi0n.js +0 -134
  115. package/dist/quick-report-CUVJnbKP.js +0 -416
  116. package/dist/radio-group-CZGqVbkJ.js +0 -26
  117. package/dist/retention-note-CHhA6gjY.js +0 -42
  118. package/dist/run-text-DvaO8LDF.js +0 -113
  119. package/dist/select-eNgZdZ30.js +0 -521
  120. package/dist/skeleton-6yk8Tdh5.js +0 -19
  121. package/dist/slider-DorDsoF8.js +0 -37
  122. package/dist/status-page-DAHiKM9P.js +0 -3286
  123. package/dist/switch-BqD0RH_G.js +0 -18
  124. package/dist/table-Q2-voLuw.js +0 -65
  125. package/dist/tabs-CSIucYFP.js +0 -57
  126. package/dist/theme-provider-BkRohQFU.js +0 -61
  127. package/dist/toggle-group-9Bs0Mm3r.js +0 -82
  128. package/dist/trpc-CvJUuUXp.js +0 -153
  129. package/dist/utils-CX-Pz5p6.js +0 -8
  130. package/dist/writability-BuH-spxv.js +0 -57
@@ -1,1353 +0,0 @@
1
- import { r as e } from "./trpc-CvJUuUXp.js";
2
- import { h as t, m as n, n as r } from "./i18n-BgzakKoC.js";
3
- import { a as i, d as a, et as o, t as s } from "./mutation-form-validators-BNz5bsv1.js";
4
- import { t as c } from "./utils-CX-Pz5p6.js";
5
- import { A as l, H as u, L as d, M as f, Y as p, j as m, l as h, t as g } from "./spinner-C-HPNxOc.js";
6
- import { t as _ } from "./button-6SxPBYMz.js";
7
- import { r as v, t as y } from "./dialog-BIhQXcZC.js";
8
- import { n as b } from "./skeleton-6yk8Tdh5.js";
9
- import { o as x } from "./context-u9KJQmdB.js";
10
- import { n as S } from "./api-error-9rQmUN5L.js";
11
- import { a as C, i as w, o as T, r as E, t as D } from "./empty-B-QJ-06w.js";
12
- import { a as O, c as k, d as A, i as j, n as M, r as N, s as P, u as F } from "./notice-card-DyGywFsW.js";
13
- import { r as I, t as L } from "./alert-B8MAoIO8.js";
14
- import { t as ee } from "./switch-BqD0RH_G.js";
15
- import { t as R } from "./diagnostic-text-BAkzW0SE.js";
16
- import { n as te } from "./mutations-THtGG6Ai.js";
17
- import { t as ne } from "./page-header-RB2YFWlE.js";
18
- import { i as re, r as ie, t as ae } from "./tabs-CSIucYFP.js";
19
- import { n as oe, r as se, t as z } from "./query-gate-DVhNIkge.js";
20
- import { t as ce } from "./breadcrumbs-0cjsV2cq.js";
21
- import { n as le, t as ue } from "./base-revision-YCO27zR4.js";
22
- import { t as de } from "./code-editor-BVimvjDV.js";
23
- import { a as fe, i as pe, n as me, o as B, r as he, t as ge } from "./run-text-DvaO8LDF.js";
24
- import { n as _e, t as ve } from "./editor-language-To9MxloY.js";
25
- import { n as ye } from "./starter-handoff-BA3ucMKL.js";
26
- import { n as be, t as xe } from "./entity-controls-D1K4Ot3O.js";
27
- import { useCallback as Se, useDeferredValue as Ce, useEffect as we, useId as Te, useMemo as V, useRef as Ee, useState as H } from "react";
28
- import { Fragment as De, jsx as U, jsxs as W } from "react/jsx-runtime";
29
- import G from "typebox";
30
- import { ChevronRightIcon as Oe, CircleAlertIcon as ke, CircleCheckIcon as Ae, FlaskConicalIcon as je, HistoryIcon as Me, RefreshCwIcon as Ne, SparklesIcon as Pe, Trash2Icon as Fe, TriangleAlertIcon as Ie, WorkflowIcon as Le } from "lucide-react";
31
- import { formatAppDateTime as Re, resolveLocalized as K, schema as ze } from "@overvis/hmi-shared";
32
- import { Value as Be } from "typebox/value";
33
- import { automationCatalog as Ve, automationContextOf as He, automationLanguageService as Ue, automationTextsInLocale as We, automationType as Ge, automationTypedValueType as Ke, maxProcedureSteps as qe, restoreAutomationTexts as Je, validateAutomation as Ye } from "@overvis/hmi-shared/automation";
34
- import { useNavigate as Xe, useRouter as Ze } from "@tanstack/react-router";
35
- import { formatExpressionValue as Qe } from "@overvis/hmi-shared/expression";
36
- import { json as $e, jsonLanguage as et } from "@codemirror/lang-json";
37
- //#region src/code-editor/json-positions.ts
38
- var tt = /* @__PURE__ */ new Set([
39
- "{",
40
- "}",
41
- "[",
42
- "]",
43
- ",",
44
- ":"
45
- ]);
46
- function q(e) {
47
- return et.parser.parse(e);
48
- }
49
- function J(e) {
50
- let t = [];
51
- for (let n = e.firstChild; n !== null; n = n.nextSibling) !tt.has(n.name) && !n.type.isError && t.push(n);
52
- return t;
53
- }
54
- function nt(e) {
55
- return e.replaceAll("~1", "/").replaceAll("~0", "~");
56
- }
57
- function rt(e, t) {
58
- try {
59
- let n = JSON.parse(e.slice(t.from, t.to));
60
- return typeof n == "string" ? n : null;
61
- } catch {
62
- return null;
63
- }
64
- }
65
- function it(e) {
66
- return e.name === "Property" ? J(e)[1] ?? null : e;
67
- }
68
- function at(e, t, n) {
69
- let r = J(e.topNode)[0];
70
- if (r === void 0) return null;
71
- let i = n === "" ? [] : n.split("/").slice(1).map(nt);
72
- for (let e of i) {
73
- let n = null;
74
- if (r.name === "Object") {
75
- let i = [...J(r)].reverse().find((n) => {
76
- let r = n.firstChild;
77
- return r !== null && rt(t, r) === e;
78
- });
79
- n = i === void 0 ? null : it(i);
80
- } else r.name === "Array" && /^\d+$/.test(e) && (n = J(r)[Number(e)] ?? null);
81
- if (n === null) return {
82
- node: r,
83
- exact: !1
84
- };
85
- r = n;
86
- }
87
- return {
88
- node: r,
89
- exact: !0
90
- };
91
- }
92
- function ot(e) {
93
- if (e.name !== "Object" && e.name !== "Array") return {
94
- from: e.from,
95
- to: e.to
96
- };
97
- let t = e.parent, n = t?.name === "Property" ? t.firstChild : null;
98
- return n === null ? {
99
- from: e.from,
100
- to: Math.min(e.from + 1, e.to)
101
- } : {
102
- from: n.from,
103
- to: n.to
104
- };
105
- }
106
- function st(e, t, n) {
107
- let r = [], i = t + 1, a = Math.max(i, n - 1);
108
- for (; i < a;) r.push(i), e[i] === "\\" ? i += e[i + 1] === "u" ? 6 : 2 : i += 1;
109
- return r.push(a), r;
110
- }
111
- function Y(e, t, n, r) {
112
- let i = at(e, t, n);
113
- if (i === null) return {
114
- from: 0,
115
- to: Math.min(1, t.length)
116
- };
117
- let { node: a, exact: o } = i;
118
- if (o && r !== void 0 && a.name === "String") {
119
- let e = st(t, a.from, a.to), n = e.length - 1, i = e[Math.min(Math.max(r.start, 0), n)] ?? a.from, o = e[Math.min(Math.max(r.end, r.start), n)] ?? a.to;
120
- return o > i ? {
121
- from: i,
122
- to: o
123
- } : {
124
- from: i,
125
- to: Math.min(i + 1, a.to)
126
- };
127
- }
128
- return ot(a);
129
- }
130
- function ct(e, t) {
131
- let n = { span: null };
132
- if (e.iterate({ enter: (e) => {
133
- if (n.span !== null) return !1;
134
- if (!e.type.isError) return;
135
- let r = Math.max(0, Math.min(e.from, t.length - 1));
136
- return n.span = {
137
- from: r,
138
- to: Math.min(Math.max(e.to, r + 1), t.length)
139
- }, !1;
140
- } }), n.span !== null) return n.span;
141
- try {
142
- return JSON.parse(t), null;
143
- } catch {
144
- return {
145
- from: 0,
146
- to: Math.min(1, t.length)
147
- };
148
- }
149
- }
150
- //#endregion
151
- //#region src/workspace/automations/use-catalog.ts
152
- function lt(n) {
153
- let r = t(), i = e.parameter.listTree.useQuery({ workspaceId: n }), a = e.endpoint.listSummaries.useQuery({ workspaceId: n }), o = e.alarmRule.list.useQuery({ workspaceId: n }), s = e.automation.list.useQuery({ workspaceId: n }), c = e.automation.members.useQuery({ workspaceId: n });
154
- return V(() => Ve({
155
- locale: r,
156
- branches: i.data?.branches ?? [],
157
- parameters: i.data?.parameters ?? [],
158
- endpoints: a.data?.endpoints ?? [],
159
- alarmRules: o.data?.items ?? [],
160
- automations: s.data?.items ?? [],
161
- members: c.data?.members ?? []
162
- }), [
163
- r,
164
- i.data,
165
- a.data,
166
- o.data,
167
- s.data,
168
- c.data
169
- ]);
170
- }
171
- function ut(e) {
172
- let t = Ze();
173
- return Se((n, r) => {
174
- let i = (() => {
175
- switch (n) {
176
- case "parameter": return t.buildLocation({
177
- to: "/workspace/$workspaceId/setup/parameters/$parameterId",
178
- params: {
179
- workspaceId: e,
180
- parameterId: r
181
- }
182
- }).publicHref;
183
- case "endpoint": return t.buildLocation({
184
- to: "/workspace/$workspaceId/setup/endpoints/$endpointId",
185
- params: {
186
- workspaceId: e,
187
- endpointId: r
188
- }
189
- }).publicHref;
190
- case "alarmRule": return t.buildLocation({
191
- to: "/workspace/$workspaceId/setup/automations/alarm-rules/$alarmRuleId",
192
- params: {
193
- workspaceId: e,
194
- alarmRuleId: r
195
- }
196
- }).publicHref;
197
- case "automation": return t.buildLocation({
198
- to: "/workspace/$workspaceId/setup/automations/$automationId",
199
- params: {
200
- workspaceId: e,
201
- automationId: r
202
- }
203
- }).publicHref;
204
- case "member": return null;
205
- }
206
- })();
207
- i !== null && window.open(i, "_blank", "noopener");
208
- }, [t, e]);
209
- }
210
- var dt = ze(G.Object({
211
- text: G.String(),
212
- dashboardId: G.String()
213
- })), ft = /* @__PURE__ */ "kind.name.description.pollIntervalMs.minRunIntervalMs.writeLimit.count.periodMs.type.lifetime.source.parameterId.endpointId.alarm.alarmRuleId.automationId.key.initial.formula.event.offsetMs.everyMs.times.weekdays.inputs.transitions.command.minRole.run.variable.procedure.max.counter.value.level.severity.message.title.body.params.latching.recipients.roles.userIds.notifyDelayMs.excludeChannels.delayMs.cancelKey.branches.when.heldForMs.once.steps.else.triggers.variables.procedures.onInit".split("."), pt = new Map(ft.map((e, t) => [e, t]));
214
- function X(e) {
215
- if (Array.isArray(e)) return e.map(X);
216
- if (typeof e != "object" || !e) return e;
217
- let t = Object.entries(e), n = (e) => pt.get(e) ?? ft.length;
218
- return Object.fromEntries(t.map(([e, t], n) => ({
219
- key: e,
220
- inner: t,
221
- index: n
222
- })).sort((e, t) => n(e.key) - n(t.key) || e.index - t.index).map(({ key: e, inner: t }) => [e, X(t)]));
223
- }
224
- function mt(e) {
225
- return `${JSON.stringify(X(e), null, 2)}\n`;
226
- }
227
- function ht(e, t) {
228
- let n = Math.max(6e4, t.minTriggerIntervalMs);
229
- return {
230
- name: e,
231
- pollIntervalMs: Math.max(1e4, t.minTriggerIntervalMs),
232
- minRunIntervalMs: Math.max(1e4, t.minTriggerIntervalMs),
233
- writeLimit: {
234
- count: Math.min(10, t.maxWritesPerMinute),
235
- periodMs: 6e4
236
- },
237
- triggers: [{
238
- kind: "period",
239
- everyMs: n,
240
- run: "main"
241
- }],
242
- variables: [],
243
- procedures: [{
244
- name: "main",
245
- steps: [{
246
- kind: "writeLog",
247
- level: "info",
248
- message: "\"Hello\""
249
- }]
250
- }]
251
- };
252
- }
253
- var gt = /^(?:\/name|\/description|.*\/message\/(?:title|body))$/;
254
- function _t(e, t, n, r = (e) => e) {
255
- let i = q(e), a = ct(i, e);
256
- if (a !== null) return {
257
- value: null,
258
- automation: null,
259
- problems: [{
260
- span: a,
261
- severity: "error",
262
- diagnostic: null
263
- }],
264
- errorCount: 1,
265
- stepBudget: /* @__PURE__ */ new Map(),
266
- maxSteps: null
267
- };
268
- let o = r(JSON.parse(e)), s = Ye(o, He(t, n), t.limits), c = s.diagnostics.map((t) => ({
269
- span: Y(i, e, t.path, gt.test(t.path) ? void 0 : t.range),
270
- severity: t.severity,
271
- diagnostic: t
272
- })).sort((e, t) => (e.severity === t.severity ? 0 : e.severity === "error" ? -1 : 1) || e.span.from - t.span.from), l = Be.Check(Ge, o) ? o : null;
273
- return {
274
- value: o,
275
- automation: l,
276
- problems: c,
277
- errorCount: c.filter((e) => e.severity === "error").length,
278
- stepBudget: l === null ? /* @__PURE__ */ new Map() : qe(l.procedures),
279
- maxSteps: s.maxSteps
280
- };
281
- }
282
- //#endregion
283
- //#region src/workspace/automations/parameter-names.ts
284
- function vt(n) {
285
- let r = t(), i = e.parameter.listTree.useQuery({ workspaceId: n }), a = V(() => new Map((i.data?.parameters ?? []).map((e) => [e.id, K(e.name, r)])), [i.data, r]);
286
- return (e) => a.get(e) ?? null;
287
- }
288
- //#endregion
289
- //#region src/workspace/automations/trace-view.tsx
290
- function yt(e) {
291
- if (typeof e != "object" || !e || !("procedures" in e)) return [];
292
- let t = e.procedures;
293
- return Array.isArray(t) ? t.map((e) => typeof e == "object" && e && "name" in e && typeof e.name == "string" ? e.name : "") : [];
294
- }
295
- function bt() {
296
- let e = n();
297
- return (t, n) => {
298
- let r = t.split("/").slice(1);
299
- if (r[0] !== "procedures" || r[1] === void 0) return t;
300
- let i = Number(r[1]), a = [n[i] ?? `#${String(i + 1)}`];
301
- for (let t = 2; t < r.length; t += 2) {
302
- let n = r[t], i = Number(r[t + 1]);
303
- if (n === "steps") a.push(String(i + 1));
304
- else if (n === "branches") a.push(e("automation_location_branch", { n: String(i + 1) }));
305
- else if (n === "else") a.push(e("automation_location_else")), --t;
306
- else break;
307
- }
308
- return a.join(" › ");
309
- };
310
- }
311
- function Z(e) {
312
- return typeof e == "object" && !!e && !Array.isArray(e);
313
- }
314
- function xt() {
315
- let e = t();
316
- return (t) => {
317
- if (!Z(t)) return "";
318
- let n = t.title, r;
319
- if (typeof n == "string") r = n;
320
- else if (Z(n)) r = K(Object.fromEntries(Object.entries(n).filter((e) => typeof e[1] == "string")), e);
321
- else return "";
322
- let i = Z(t.params) ? t.params : {};
323
- return r.replace(/\{([A-Za-z][A-Za-z0-9_]*)\}/g, (e, t) => {
324
- let n = i[t];
325
- return Be.Check(Ke, n) ? typeof n.value == "string" ? n.value : (n.type === "duration" || n.type === "timeOfDay") && n.value !== null ? Qe(n.value, n.type, "UTC") ?? e : he(n) : e;
326
- });
327
- };
328
- }
329
- function Q({ values: e, empty: t }) {
330
- let n = Object.entries(e).sort(([e], [t]) => e.localeCompare(t));
331
- return n.length === 0 ? /* @__PURE__ */ U("p", {
332
- className: "text-sm text-muted-foreground",
333
- children: t
334
- }) : /* @__PURE__ */ U("dl", {
335
- className: "grid grid-cols-[minmax(0,auto)_minmax(0,1fr)] gap-x-4 gap-y-1 text-sm",
336
- children: n.map(([e, t]) => /* @__PURE__ */ W("div", {
337
- className: "contents",
338
- children: [/* @__PURE__ */ U("dt", {
339
- className: "truncate font-mono text-muted-foreground",
340
- children: e
341
- }), /* @__PURE__ */ U("dd", {
342
- className: "truncate font-mono",
343
- children: he(t)
344
- })]
345
- }, e))
346
- });
347
- }
348
- function St(e) {
349
- if (e.kind === "writeLog") switch (e.detail.level) {
350
- case "error": return "destructive";
351
- case "warn": return "warning";
352
- case "info": return "secondary";
353
- default: return "outline";
354
- }
355
- return e.kind === "fail" || e.kind === "writeFailed" || e.kind === "writeDropped" || e.kind === "writeLimited" ? "destructive" : "outline";
356
- }
357
- function Ct({ step: e }) {
358
- let t = e.detail.level;
359
- return /* @__PURE__ */ U(h, {
360
- variant: St(e),
361
- className: "shrink-0 font-mono",
362
- children: e.kind === "writeLog" && typeof t == "string" ? `${B(e.kind)} · ${t}` : B(e.kind)
363
- });
364
- }
365
- function wt({ steps: e, procedures: t, parameterName: n, onReveal: r }) {
366
- let i = bt();
367
- return /* @__PURE__ */ U("ol", {
368
- className: "divide-y rounded-md border text-sm",
369
- children: e.map((e, a) => {
370
- let o = fe(e, n);
371
- return /* @__PURE__ */ W("li", {
372
- className: "\n flex flex-col gap-1 px-3 py-1.5\n sm:flex-row sm:items-center sm:gap-3\n ",
373
- children: [/* @__PURE__ */ W("div", {
374
- className: "flex min-w-0 flex-1 items-center gap-2",
375
- children: [
376
- /* @__PURE__ */ U("span", {
377
- className: "w-8 shrink-0 text-right text-xs text-muted-foreground tabular-nums",
378
- children: a + 1
379
- }),
380
- /* @__PURE__ */ U(Ct, { step: e }),
381
- o === "" ? null : /* @__PURE__ */ U("span", {
382
- className: "min-w-0 truncate font-mono",
383
- children: o
384
- })
385
- ]
386
- }), e.path === "" ? null : r == null ? /* @__PURE__ */ U("span", {
387
- className: "shrink-0 text-xs text-muted-foreground",
388
- children: i(e.path, t)
389
- }) : /* @__PURE__ */ U(_, {
390
- type: "button",
391
- variant: "link",
392
- size: "sm",
393
- className: "\n h-auto shrink-0 self-start p-0 text-xs\n sm:self-auto\n ",
394
- onClick: () => {
395
- r(e.path);
396
- },
397
- children: i(e.path, t)
398
- })]
399
- }, a);
400
- })
401
- });
402
- }
403
- function Tt({ effects: e, parameterName: t, empty: r }) {
404
- let i = n(), a = xt();
405
- if (e.length === 0) return /* @__PURE__ */ U("p", {
406
- className: "text-sm text-muted-foreground",
407
- children: r
408
- });
409
- let o = (e) => typeof e == "string" ? e : "";
410
- return /* @__PURE__ */ U("ul", {
411
- className: "divide-y rounded-md border text-sm",
412
- children: e.map((e, n) => {
413
- let r = e.detail, s;
414
- switch (e.kind) {
415
- case "writeParameter": {
416
- let e = o(r.parameterId);
417
- s = `${t(e) ?? e} ← ${o(r.value)}`;
418
- break;
419
- }
420
- case "notify":
421
- case "reply":
422
- s = a(r.message);
423
- break;
424
- case "raiseAlarm":
425
- s = i("automation_effect_alarm", {
426
- key: o(r.key),
427
- title: a(r.message)
428
- });
429
- break;
430
- case "clearAlarm":
431
- s = o(r.key);
432
- break;
433
- case "cancelNotify":
434
- s = o(r.cancelKey);
435
- break;
436
- default: s = "";
437
- }
438
- let c = o(r.severity);
439
- return /* @__PURE__ */ W("li", {
440
- className: "flex items-center gap-2 px-3 py-1.5",
441
- children: [
442
- /* @__PURE__ */ U(h, {
443
- variant: "outline",
444
- className: "shrink-0",
445
- children: B(e.kind)
446
- }),
447
- r.limited === !0 ? /* @__PURE__ */ U(h, {
448
- variant: "destructive",
449
- className: "shrink-0",
450
- children: B("writeLimited")
451
- }) : null,
452
- c === "" ? null : /* @__PURE__ */ U(h, {
453
- variant: c === "urgent" ? "destructive" : "secondary",
454
- children: pe(c)
455
- }),
456
- /* @__PURE__ */ U("span", {
457
- className: "min-w-0 truncate",
458
- children: s
459
- })
460
- ]
461
- }, n);
462
- })
463
- });
464
- }
465
- //#endregion
466
- //#region src/workspace/setup/automations/dry-run.tsx
467
- function Et(e) {
468
- return e.triggers[0]?.run ?? e.procedures[0]?.name ?? "";
469
- }
470
- function $({ title: e, children: t }) {
471
- return /* @__PURE__ */ W("section", {
472
- className: "flex min-w-0 flex-col gap-2",
473
- children: [/* @__PURE__ */ U("h4", {
474
- className: "text-sm font-medium",
475
- children: e
476
- }), t]
477
- });
478
- }
479
- function Dt({ workspaceId: t, automationId: r, automation: i, onReveal: a }) {
480
- let o = n(), s = Te(), c = Te(), [m, v] = H(null), [y, b] = H(!1), x = vt(t), C = e.automation.dryRun.useMutation(), w = i?.procedures.map((e) => e.name) ?? [], T = m !== null && w.includes(m) ? m : i === null ? "" : Et(i), E = i?.triggers.some((e) => e.kind === "telegram" && e.run === T) ?? !1, D = C.data, j = C.variables;
481
- return /* @__PURE__ */ W(O, { children: [/* @__PURE__ */ W(F, { children: [/* @__PURE__ */ W(A, {
482
- className: "flex items-center gap-2",
483
- children: [/* @__PURE__ */ U(je, { className: "size-4" }), o("automation_dry_run_title")]
484
- }), /* @__PURE__ */ U(k, { children: o("automation_dry_run_description") })] }), /* @__PURE__ */ W(P, {
485
- className: "flex flex-col gap-4",
486
- children: [
487
- /* @__PURE__ */ W("div", {
488
- className: "\n flex flex-col gap-3\n sm:flex-row sm:items-end\n ",
489
- children: [
490
- /* @__PURE__ */ W(d, {
491
- className: "sm:max-w-64",
492
- children: [/* @__PURE__ */ U(u, {
493
- htmlFor: s,
494
- children: o("automation_dry_run_procedure")
495
- }), /* @__PURE__ */ U(l, {
496
- id: s,
497
- value: T,
498
- disabled: i === null,
499
- onChange: (e) => {
500
- v(e.target.value);
501
- },
502
- children: w.map((e) => /* @__PURE__ */ U(f, {
503
- value: e,
504
- children: e
505
- }, e))
506
- })]
507
- }),
508
- E ? /* @__PURE__ */ W("div", {
509
- className: "\n flex items-center gap-2\n sm:pb-2\n ",
510
- children: [/* @__PURE__ */ U(p, {
511
- id: c,
512
- checked: y,
513
- onCheckedChange: (e) => {
514
- b(e);
515
- }
516
- }), /* @__PURE__ */ U("label", {
517
- htmlFor: c,
518
- className: "text-sm",
519
- children: o("automation_dry_run_command")
520
- })]
521
- }) : null,
522
- /* @__PURE__ */ W(_, {
523
- type: "button",
524
- variant: "outline",
525
- disabled: i === null || T === "" || C.isPending,
526
- onClick: () => {
527
- i !== null && C.mutate({
528
- workspaceId: t,
529
- ...r === void 0 ? {} : { automationId: r },
530
- document: i,
531
- procedure: T,
532
- ...E && y ? { command: !0 } : {}
533
- });
534
- },
535
- children: [C.isPending ? /* @__PURE__ */ U(g, { "data-icon": "inline-start" }) : null, o("automation_dry_run_submit")]
536
- })
537
- ]
538
- }),
539
- i === null ? /* @__PURE__ */ U("p", {
540
- className: "text-sm text-muted-foreground",
541
- children: o("automation_dry_run_needs_valid")
542
- }) : null,
543
- C.isError ? /* @__PURE__ */ U(L, {
544
- variant: "destructive",
545
- children: /* @__PURE__ */ U(I, { children: S(C.error) })
546
- }) : null,
547
- D != null && j != null && i !== null ? /* @__PURE__ */ W("div", {
548
- className: "flex flex-col gap-4",
549
- children: [
550
- /* @__PURE__ */ W("div", {
551
- className: "flex flex-wrap items-center gap-2 text-sm",
552
- children: [/* @__PURE__ */ U(h, {
553
- variant: D.status === "ok" ? "success" : "destructive",
554
- children: D.status === "ok" ? o("automation_run_ok") : o("automation_run_failed")
555
- }), /* @__PURE__ */ U("span", {
556
- className: "text-muted-foreground",
557
- children: o("automation_dry_run_summary", {
558
- procedure: j.procedure,
559
- at: Re(D.startedAt),
560
- steps: String(D.steps),
561
- limit: String(D.maxSteps)
562
- })
563
- })]
564
- }),
565
- D.errorCode === null ? null : /* @__PURE__ */ U(L, {
566
- variant: "destructive",
567
- children: /* @__PURE__ */ U(I, { children: ge(D.errorCode, D.error) })
568
- }),
569
- /* @__PURE__ */ U("p", {
570
- className: "text-sm text-muted-foreground",
571
- children: o("automation_dry_run_applied_nothing")
572
- }),
573
- /* @__PURE__ */ W("div", {
574
- className: "\n grid grid-cols-1 gap-4\n lg:grid-cols-2\n ",
575
- children: [
576
- /* @__PURE__ */ U($, {
577
- title: o("automation_run_inputs"),
578
- children: /* @__PURE__ */ U(Q, {
579
- values: D.inputs,
580
- empty: o("automation_run_no_inputs")
581
- })
582
- }),
583
- /* @__PURE__ */ W($, {
584
- title: o("automation_dry_run_effects"),
585
- children: [D.status === "failed" && D.effects.length > 0 ? /* @__PURE__ */ U("p", {
586
- className: "text-sm text-muted-foreground",
587
- children: o("automation_dry_run_failed_applies_nothing")
588
- }) : null, /* @__PURE__ */ U(Tt, {
589
- effects: D.effects,
590
- parameterName: x,
591
- empty: o("automation_dry_run_no_effects")
592
- })]
593
- }),
594
- /* @__PURE__ */ U($, {
595
- title: o("automation_dry_run_state_before"),
596
- children: /* @__PURE__ */ U(Q, {
597
- values: D.stateBefore,
598
- empty: o("automation_run_no_state")
599
- })
600
- }),
601
- /* @__PURE__ */ U($, {
602
- title: o("automation_dry_run_state_after"),
603
- children: /* @__PURE__ */ U(Q, {
604
- values: D.stateAfter,
605
- empty: o("automation_run_no_state")
606
- })
607
- })
608
- ]
609
- }),
610
- /* @__PURE__ */ U($, {
611
- title: o("automation_run_steps"),
612
- children: D.trace.length === 0 ? /* @__PURE__ */ U("p", {
613
- className: "text-sm text-muted-foreground",
614
- children: o("automation_run_no_steps")
615
- }) : /* @__PURE__ */ U(wt, {
616
- steps: D.trace,
617
- procedures: yt(j.document),
618
- parameterName: x,
619
- ...JSON.stringify(j.document) === JSON.stringify(i) ? { onReveal: a } : {}
620
- })
621
- })
622
- ]
623
- }) : null
624
- ]
625
- })] });
626
- }
627
- //#endregion
628
- //#region src/workspace/setup/automations/editor-form.tsx
629
- var Ot = [];
630
- function kt(e) {
631
- return String(e / 1e3);
632
- }
633
- function At({ workspaceId: e, detail: o, context: c, editorRef: l, onCreated: u, onReload: d, onDirtyChange: f, starter: p }) {
634
- let m = n(), h = r(), [g] = H(t()), _ = te(e), v = le(o?.revision), y = o?.id, [b, x] = H(o?.document ?? p ?? null), [S, C] = H(o?.dashboardId ?? ""), [w, T] = H(() => {
635
- let e = o?.document ?? p;
636
- return mt(e === void 0 ? ht(m("automation_new_name"), c.limits) : We(e, g));
637
- }), E = i({
638
- defaultValues: {
639
- text: w,
640
- dashboardId: o?.dashboardId ?? ""
641
- },
642
- validators: s({
643
- schema: dt,
644
- submit: async (t) => {
645
- let n = _t(t.text, c, y, (e) => Je(b, e, g));
646
- if (n.errorCount > 0 || n.automation === null) return {
647
- form: () => m("automation_editor_save_has_errors"),
648
- fields: {}
649
- };
650
- let r = n.automation, i = t.dashboardId === "" ? null : t.dashboardId;
651
- if (y == null) {
652
- let t = await _.create.mutateAsync({
653
- workspaceId: e,
654
- document: r,
655
- dashboardId: i
656
- });
657
- u?.(t.id);
658
- } else {
659
- let e = await _.update.mutateAsync({
660
- id: y,
661
- document: r,
662
- dashboardId: i,
663
- ...v.baseRevision === void 0 ? {} : { baseRevision: v.baseRevision }
664
- });
665
- v.rebase(e.revision), x(r), T(t.text), C(t.dashboardId);
666
- }
667
- return null;
668
- },
669
- mapError: v.mapError(),
670
- onError: v.onError
671
- }),
672
- onSubmitInvalid: a,
673
- onSubmit: () => {
674
- h.success(m(y == null ? "automation_create_toast" : "automation_save_toast"));
675
- }
676
- }), [D, O] = H(o?.revision), [k, A] = H(null);
677
- if (o !== void 0 && o.revision !== D && (O(o.revision), o.revision !== v.baseRevision && E.state.values.text === w && E.state.values.dashboardId === S)) {
678
- let e = mt(We(o.document, g));
679
- x(o.document), T(e), v.rebase(o.revision), C(o.dashboardId ?? ""), A({
680
- text: e,
681
- dashboardId: o.dashboardId ?? ""
682
- });
683
- }
684
- return we(() => {
685
- k !== null && E.reset(k);
686
- }, [k, E]), /* @__PURE__ */ U(E.AppForm, { children: /* @__PURE__ */ W(E.FormRoot, {
687
- banner: !1,
688
- className: "flex flex-col gap-4",
689
- children: [/* @__PURE__ */ U(E.Subscribe, {
690
- selector: (e) => e.values.text,
691
- children: (t) => /* @__PURE__ */ U(Lt, {
692
- automationName: o == null ? m("automation_new_name") : K(o.name, g),
693
- text: t,
694
- savedText: w,
695
- original: b,
696
- locale: g,
697
- ...f === void 0 ? {} : { onDirtyChange: f },
698
- context: c,
699
- automationId: y,
700
- workspaceId: e,
701
- onText: (e) => {
702
- E.setFieldValue("text", e);
703
- },
704
- editorRef: l,
705
- dashboardField: /* @__PURE__ */ U(E.AppField, {
706
- name: "dashboardId",
707
- children: (t) => /* @__PURE__ */ U(t.DashboardPickerField, {
708
- label: m("automation_field_dashboard"),
709
- workspaceId: e,
710
- description: m("automation_field_dashboard_description")
711
- })
712
- })
713
- })
714
- }), /* @__PURE__ */ W("div", {
715
- className: "flex flex-col gap-2",
716
- children: [
717
- /* @__PURE__ */ U(ue, {
718
- base: v,
719
- onReload: d
720
- }),
721
- /* @__PURE__ */ U(E.FormErrorBanner, {}),
722
- /* @__PURE__ */ U("div", {
723
- className: "flex justify-end",
724
- children: /* @__PURE__ */ U(E.SubmitButton, {
725
- label: m(y == null ? "automation_create_submit" : "action_save"),
726
- pendingLabel: m("action_saving")
727
- })
728
- })
729
- ]
730
- })]
731
- }) });
732
- }
733
- var jt = 30;
734
- function Mt(e, t) {
735
- let n = t.span.from, r = e.lastIndexOf("\n", n - 1) + 1, i = e.indexOf("\n", n);
736
- return {
737
- line: String(e.slice(0, n).split("\n").length),
738
- column: String(n - r + 1),
739
- excerpt: e.slice(r, i === -1 ? e.length : i).trim(),
740
- code: t.diagnostic?.code ?? "json_syntax",
741
- path: t.diagnostic?.path ?? ""
742
- };
743
- }
744
- function Nt({ actions: e, onApply: t }) {
745
- return e.length === 0 ? null : /* @__PURE__ */ U("div", {
746
- className: "flex flex-wrap gap-x-1 gap-y-0.5 pb-1 pl-8",
747
- children: e.map((e, n) => /* @__PURE__ */ W(_, {
748
- type: "button",
749
- variant: "link",
750
- size: "xs",
751
- className: "h-auto max-w-full px-0 py-0.5 text-left text-xs whitespace-normal",
752
- onClick: () => {
753
- t(e);
754
- },
755
- children: [e.run !== void 0 && e.edit === void 0 ? /* @__PURE__ */ U(Pe, { "data-icon": "inline-start" }) : null, e.label]
756
- }, n))
757
- });
758
- }
759
- var Pt = [
760
- "trigger",
761
- "variable",
762
- "procedure",
763
- "field"
764
- ];
765
- function Ft({ outline: e, onPick: t }) {
766
- let r = n(), i = (e) => {
767
- switch (e) {
768
- case "trigger": return r("automation_outline_triggers");
769
- case "variable": return r("automation_outline_variables");
770
- case "procedure": return r("automation_outline_procedures");
771
- case "field": return r("automation_outline_fields");
772
- }
773
- };
774
- return /* @__PURE__ */ W(l, {
775
- size: "sm",
776
- "aria-label": r("automation_outline_label"),
777
- value: "",
778
- disabled: e.length === 0,
779
- className: "\n w-full\n sm:w-72\n ",
780
- onChange: (n) => {
781
- let r = e[Number(n.target.value)];
782
- r !== void 0 && t(r);
783
- },
784
- children: [/* @__PURE__ */ U(f, {
785
- value: "",
786
- children: r("automation_outline_placeholder")
787
- }), Pt.map((t) => {
788
- let n = e.map((e, t) => ({
789
- item: e,
790
- index: t
791
- })).filter(({ item: e }) => e.kind === t);
792
- return n.length === 0 ? null : /* @__PURE__ */ U(m, {
793
- label: i(t),
794
- children: n.map(({ item: e, index: t }) => /* @__PURE__ */ U(f, {
795
- value: String(t),
796
- children: e.detail === void 0 ? e.label : `${e.label} → ${e.detail}`
797
- }, t))
798
- }, t);
799
- })]
800
- });
801
- }
802
- function It({ problem: e }) {
803
- return e.severity === "error" ? /* @__PURE__ */ U(ke, { className: "mt-0.5 size-4 shrink-0 text-destructive" }) : /* @__PURE__ */ U(Ie, { className: "\n mt-0.5 size-4 shrink-0 text-amber-600\n dark:text-amber-400\n " });
804
- }
805
- function Lt({ text: e, savedText: t, original: r, locale: i, context: a, automationId: s, workspaceId: l, onText: u, editorRef: d, dashboardField: f, onDirtyChange: p, automationName: m }) {
806
- let h = n(), g = e !== t;
807
- we(() => {
808
- p?.(g);
809
- }, [g, p]);
810
- let _ = Ce(e), v = V(() => _t(_, a, s, (e) => Je(r, e, i)), [
811
- _,
812
- a,
813
- s,
814
- r,
815
- i
816
- ]), y = lt(l), b = ut(l), S = V(() => Ue({
817
- document: "automation",
818
- context: He(a, s),
819
- catalog: y
820
- }), [
821
- a,
822
- s,
823
- y
824
- ]), C = h("automation_language_docs"), w = V(() => [$e(), o(ve(S, b, C))], [
825
- S,
826
- b,
827
- C
828
- ]), { openAssistant: T } = x(), E = (e) => e.diagnostic === null ? h("automation_editor_json_syntax") : R(e.diagnostic), D = V(() => v.problems.map((e, t) => {
829
- let n = T === void 0 ? [] : [{
830
- label: h("automation_ask_assistant"),
831
- run: () => {
832
- T(h("automation_ask_assistant_message", {
833
- ...Mt(_, e),
834
- automation: s === void 0 ? m : `${m} (${s})`,
835
- problem: e.diagnostic === null ? h("automation_editor_json_syntax") : R(e.diagnostic)
836
- }));
837
- }
838
- }];
839
- return [...e.diagnostic === null || t >= jt ? [] : _e(S, _, e.diagnostic), ...n];
840
- }), [
841
- v,
842
- _,
843
- S,
844
- T,
845
- m,
846
- s,
847
- h
848
- ]), k = V(() => v.problems.map((e, t) => ({
849
- from: e.span.from,
850
- to: e.span.to,
851
- severity: e.severity,
852
- message: e.diagnostic === null ? h("automation_editor_json_syntax") : R(e.diagnostic),
853
- actions: D[t] ?? []
854
- })), [
855
- v,
856
- D,
857
- h
858
- ]), j = V(() => S.outline(_), [S, _]), M = v.problems.length - v.errorCount, N = (e, t) => {
859
- d.current?.reveal(e, t);
860
- }, I = a.limits.maxStepsPerRun, L = v.automation?.procedures ?? [];
861
- return /* @__PURE__ */ W("div", {
862
- className: "flex flex-col gap-4",
863
- children: [/* @__PURE__ */ W("div", {
864
- className: "\n grid grid-cols-1 gap-4\n lg:grid-cols-[minmax(0,1fr)_20rem]\n ",
865
- children: [/* @__PURE__ */ W("div", {
866
- className: "flex min-w-0 flex-col gap-2",
867
- children: [
868
- /* @__PURE__ */ U(Ft, {
869
- outline: j,
870
- onPick: (e) => {
871
- N(e.from, e.from);
872
- }
873
- }),
874
- /* @__PURE__ */ U(de, {
875
- ref: d,
876
- id: "automation-document",
877
- ariaLabel: h("automation_editor_document"),
878
- ariaDescribedBy: "automation-document-status",
879
- value: e,
880
- onChange: u,
881
- extensions: w,
882
- diagnostics: _ === e ? k : Ot,
883
- invalid: v.errorCount > 0,
884
- className: "h-[60vh] min-h-80"
885
- }),
886
- /* @__PURE__ */ W("p", {
887
- id: "automation-document-status",
888
- className: "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",
889
- children: [
890
- /* @__PURE__ */ U("span", { children: v.problems.length === 0 ? h("automation_editor_no_problems") : h("automation_editor_problem_counts", {
891
- errors: String(v.errorCount),
892
- warnings: String(M)
893
- }) }),
894
- e === t ? null : /* @__PURE__ */ U("span", { children: h("automation_editor_unsaved") }),
895
- /* @__PURE__ */ U("span", { children: h("automation_editor_keyboard_hint") })
896
- ]
897
- })
898
- ]
899
- }), /* @__PURE__ */ W("div", {
900
- className: "flex min-w-0 flex-col gap-4",
901
- children: [
902
- /* @__PURE__ */ W(O, {
903
- size: "sm",
904
- children: [/* @__PURE__ */ U(F, { children: /* @__PURE__ */ U(A, { children: h("automation_editor_problems") }) }), /* @__PURE__ */ U(P, { children: v.problems.length === 0 ? /* @__PURE__ */ W("p", {
905
- className: "flex items-center gap-2 text-sm text-muted-foreground",
906
- children: [/* @__PURE__ */ U(Ae, { className: "\n size-4 text-emerald-600\n dark:text-emerald-400\n " }), h("automation_editor_no_problems")]
907
- }) : /* @__PURE__ */ U("ul", {
908
- className: "-mx-2 flex max-h-72 flex-col overflow-y-auto",
909
- children: v.problems.map((t, n) => /* @__PURE__ */ W("li", { children: [/* @__PURE__ */ W("button", {
910
- type: "button",
911
- className: "\n flex w-full gap-2 rounded-md px-2 py-1.5 text-left text-sm\n hover:bg-muted\n focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none\n ",
912
- onClick: () => {
913
- N(t.span.from, t.span.to);
914
- },
915
- children: [/* @__PURE__ */ U(It, { problem: t }), /* @__PURE__ */ U("span", {
916
- className: "min-w-0 wrap-break-word",
917
- children: E(t)
918
- })]
919
- }), /* @__PURE__ */ U(Nt, {
920
- actions: (D[n] ?? []).filter((t) => t.edit === void 0 || _ === e),
921
- onApply: (e) => {
922
- let t = d.current;
923
- if (e.edit !== void 0) {
924
- if (t?.text() !== _) return;
925
- t.apply(e.edit);
926
- }
927
- e.run?.();
928
- }
929
- })] }, n))
930
- }) })]
931
- }),
932
- /* @__PURE__ */ W(O, {
933
- size: "sm",
934
- children: [/* @__PURE__ */ U(F, { children: /* @__PURE__ */ U(A, { children: h("automation_editor_step_budget") }) }), /* @__PURE__ */ W(P, {
935
- className: "flex flex-col gap-2 text-sm",
936
- children: [/* @__PURE__ */ U("p", {
937
- className: "text-muted-foreground",
938
- children: h("automation_editor_step_budget_description", { limit: String(I) })
939
- }), L.length === 0 ? null : /* @__PURE__ */ U("dl", {
940
- className: "grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1",
941
- children: L.map((e) => {
942
- let t = v.stepBudget.get(e.name);
943
- return /* @__PURE__ */ W("div", {
944
- className: "contents",
945
- children: [/* @__PURE__ */ U("dt", {
946
- className: "truncate font-mono",
947
- children: e.name
948
- }), /* @__PURE__ */ U("dd", {
949
- className: c("text-right tabular-nums", t !== void 0 && t > I && "text-destructive"),
950
- children: t === void 0 ? "—" : `${String(t)} / ${String(I)}`
951
- })]
952
- }, e.name);
953
- })
954
- })]
955
- })]
956
- }),
957
- /* @__PURE__ */ W(O, {
958
- size: "sm",
959
- children: [/* @__PURE__ */ U(F, { children: /* @__PURE__ */ U(A, { children: h("automation_editor_limits") }) }), /* @__PURE__ */ U(P, { children: /* @__PURE__ */ W("dl", {
960
- className: "grid grid-cols-[minmax(0,1fr)_auto] gap-x-4 gap-y-1 text-sm",
961
- children: [
962
- /* @__PURE__ */ U("dt", {
963
- className: "text-muted-foreground",
964
- children: h("automation_limit_steps")
965
- }),
966
- /* @__PURE__ */ U("dd", {
967
- className: "text-right tabular-nums",
968
- children: a.limits.maxStepsPerRun
969
- }),
970
- /* @__PURE__ */ U("dt", {
971
- className: "text-muted-foreground",
972
- children: h("automation_limit_interval")
973
- }),
974
- /* @__PURE__ */ U("dd", {
975
- className: "text-right tabular-nums",
976
- children: h("automation_seconds", { seconds: kt(a.limits.minTriggerIntervalMs) })
977
- }),
978
- /* @__PURE__ */ U("dt", {
979
- className: "text-muted-foreground",
980
- children: h("automation_limit_writes")
981
- }),
982
- /* @__PURE__ */ U("dd", {
983
- className: "text-right tabular-nums",
984
- children: a.limits.maxWritesPerMinute
985
- })
986
- ]
987
- }) })]
988
- }),
989
- f
990
- ]
991
- })]
992
- }), /* @__PURE__ */ U(Dt, {
993
- workspaceId: l,
994
- automationId: s,
995
- automation: v.errorCount === 0 ? v.automation : null,
996
- onReveal: (t) => {
997
- let n = Y(q(e), e, t);
998
- N(n.from, n.to);
999
- }
1000
- })]
1001
- });
1002
- }
1003
- //#endregion
1004
- //#region src/workspace/setup/automations/history.tsx
1005
- var Rt = 50;
1006
- function zt(e) {
1007
- return e < 1e3 ? `${String(e)} µs` : `${(e / 1e3).toFixed(e < 1e4 ? 2 : 0)} ms`;
1008
- }
1009
- function Bt({ automationId: t, workspaceId: r, run: i, procedures: a, onReveal: o, sameVersion: s }) {
1010
- let c = n(), l = vt(r), u = e.automation.runTrace.useQuery({
1011
- id: t,
1012
- runId: i.runId
1013
- });
1014
- if (u.isPending) return /* @__PURE__ */ U(b, { className: "h-24 w-full" });
1015
- if (u.isError) return /* @__PURE__ */ U(z, { message: S(u.error) });
1016
- let { inputs: d, steps: f } = u.data;
1017
- return d === null && f.length === 0 ? /* @__PURE__ */ U("p", {
1018
- className: "text-sm text-muted-foreground",
1019
- children: i.steps === 0 ? c("automation_run_no_steps") : c("automation_run_trace_expired")
1020
- }) : /* @__PURE__ */ W("div", {
1021
- className: "flex flex-col gap-4",
1022
- children: [d === null ? null : /* @__PURE__ */ W("section", {
1023
- className: "flex flex-col gap-2",
1024
- children: [/* @__PURE__ */ U("h4", {
1025
- className: "text-sm font-medium",
1026
- children: c("automation_run_inputs")
1027
- }), /* @__PURE__ */ U(Q, {
1028
- values: d,
1029
- empty: c("automation_run_no_inputs")
1030
- })]
1031
- }), /* @__PURE__ */ W("section", {
1032
- className: "flex flex-col gap-2",
1033
- children: [
1034
- /* @__PURE__ */ U("h4", {
1035
- className: "text-sm font-medium",
1036
- children: c("automation_run_steps")
1037
- }),
1038
- f.length === 0 ? /* @__PURE__ */ U("p", {
1039
- className: "text-sm text-muted-foreground",
1040
- children: c("automation_run_no_steps")
1041
- }) : /* @__PURE__ */ U(wt, {
1042
- steps: f,
1043
- procedures: s ? a : [],
1044
- parameterName: l,
1045
- ...o === void 0 ? {} : { onReveal: o }
1046
- }),
1047
- s ? null : /* @__PURE__ */ U("p", {
1048
- className: "text-xs text-muted-foreground",
1049
- children: c("automation_run_earlier_version")
1050
- }),
1051
- i.traceTruncated ? /* @__PURE__ */ U("p", {
1052
- className: "text-xs text-muted-foreground",
1053
- children: c("automation_run_trace_truncated", { steps: String(i.steps) })
1054
- }) : null
1055
- ]
1056
- })]
1057
- });
1058
- }
1059
- function Vt({ automationId: e, workspaceId: t, run: r, procedures: i, onReveal: a, savedRevision: o, editorShowsSaved: s }) {
1060
- let l = n(), [u, d] = H(!1), f = r.procedure === "";
1061
- return /* @__PURE__ */ W(M, {
1062
- open: u,
1063
- onOpenChange: d,
1064
- render: /* @__PURE__ */ U("li", {}),
1065
- children: [/* @__PURE__ */ W(j, {
1066
- className: "\n flex w-full items-start gap-2 px-3 py-2 text-left text-sm\n hover:bg-muted/40\n focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none\n ",
1067
- children: [/* @__PURE__ */ U(Oe, { className: c("mt-0.5 size-4 shrink-0 text-muted-foreground transition-transform", u && "rotate-90") }), /* @__PURE__ */ W("div", {
1068
- className: "flex min-w-0 flex-1 flex-col gap-1",
1069
- children: [
1070
- /* @__PURE__ */ W("div", {
1071
- className: "flex flex-wrap items-center gap-x-3 gap-y-1",
1072
- children: [
1073
- /* @__PURE__ */ U("span", {
1074
- className: "tabular-nums",
1075
- children: Re(r.startedAt)
1076
- }),
1077
- /* @__PURE__ */ U(h, {
1078
- variant: r.status === "ok" ? "success" : "destructive",
1079
- children: r.status === "ok" ? l("automation_run_ok") : l("automation_run_failed")
1080
- }),
1081
- /* @__PURE__ */ U("span", {
1082
- className: "min-w-0 truncate text-muted-foreground",
1083
- children: me(r.triggerKind, r.trigger)
1084
- }),
1085
- f ? null : /* @__PURE__ */ U("span", {
1086
- className: "font-mono text-xs",
1087
- children: r.procedure
1088
- })
1089
- ]
1090
- }),
1091
- f ? null : /* @__PURE__ */ W("div", {
1092
- className: "flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground",
1093
- children: [
1094
- /* @__PURE__ */ U("span", { children: l("automation_run_duration", { duration: zt(r.durationUs) }) }),
1095
- /* @__PURE__ */ U("span", { children: l("automation_run_step_count", { steps: String(r.steps) }) }),
1096
- /* @__PURE__ */ U("span", { children: l("automation_run_write_count", { writes: String(r.writes) }) }),
1097
- r.writesLimited > 0 ? /* @__PURE__ */ U("span", {
1098
- className: "text-destructive",
1099
- children: l("automation_run_limited_count", { writes: String(r.writesLimited) })
1100
- }) : null,
1101
- /* @__PURE__ */ U("span", { children: l("automation_run_notification_count", { notifications: String(r.notifications) }) })
1102
- ]
1103
- }),
1104
- r.errorCode === null ? null : /* @__PURE__ */ U("p", {
1105
- className: "text-destructive",
1106
- children: ge(r.errorCode, r.error)
1107
- })
1108
- ]
1109
- })]
1110
- }), /* @__PURE__ */ U(N, {
1111
- className: "\n border-t bg-muted/20 p-3\n sm:pl-9\n ",
1112
- children: u ? /* @__PURE__ */ U(Bt, {
1113
- automationId: e,
1114
- workspaceId: t,
1115
- run: r,
1116
- procedures: i,
1117
- sameVersion: r.revision === o,
1118
- onReveal: r.revision === o && s ? a : void 0
1119
- }) : null
1120
- })]
1121
- });
1122
- }
1123
- function Ht({ workspaceId: t, automationId: r, document: i, savedRevision: a, editorShowsSaved: o, onReveal: s }) {
1124
- let c = n(), [l, u] = H(!1), [d, f] = H(null), [p, m] = H(!1), [h, g] = H(null), v = e.useUtils(), y = e.automation.runs.useQuery({
1125
- id: r,
1126
- failedOnly: l,
1127
- limit: Rt
1128
- }), x = yt(i), O = Ee(0), k = () => {
1129
- O.current += 1, f(null), g(null), m(!1);
1130
- }, A = y.data?.next ?? null, j = A === null ? "" : `${A.startedAt}|${A.runId}`, M = d?.after === j ? d : null, N = M === null ? A : M.next, P = [...y.data?.items ?? [], ...M?.items ?? []];
1131
- return /* @__PURE__ */ W("div", {
1132
- className: "flex flex-col gap-3",
1133
- children: [
1134
- /* @__PURE__ */ W("div", {
1135
- className: "flex flex-wrap items-center justify-between gap-2",
1136
- children: [/* @__PURE__ */ U("p", {
1137
- className: "text-sm text-muted-foreground",
1138
- children: c("automation_history_description")
1139
- }), /* @__PURE__ */ W("div", {
1140
- className: "flex items-center gap-3",
1141
- children: [/* @__PURE__ */ W("label", {
1142
- className: "flex items-center gap-2 text-sm",
1143
- children: [/* @__PURE__ */ U(ee, {
1144
- size: "sm",
1145
- checked: l,
1146
- onCheckedChange: (e) => {
1147
- u(e), k();
1148
- }
1149
- }), c("automation_history_failed_only")]
1150
- }), /* @__PURE__ */ W(_, {
1151
- type: "button",
1152
- variant: "outline",
1153
- size: "sm",
1154
- disabled: y.isFetching,
1155
- onClick: () => {
1156
- k(), y.refetch();
1157
- },
1158
- children: [/* @__PURE__ */ U(Ne, { "data-icon": "inline-start" }), c("automation_history_refresh")]
1159
- })]
1160
- })]
1161
- }),
1162
- y.isPending ? /* @__PURE__ */ W("div", {
1163
- className: "flex flex-col gap-2",
1164
- children: [/* @__PURE__ */ U(b, { className: "h-12 w-full" }), /* @__PURE__ */ U(b, { className: "h-12 w-full" })]
1165
- }) : y.isError ? /* @__PURE__ */ U(z, { message: S(y.error) }) : P.length === 0 ? /* @__PURE__ */ U(D, {
1166
- className: "border",
1167
- children: /* @__PURE__ */ W(w, { children: [
1168
- /* @__PURE__ */ U(C, {
1169
- variant: "icon",
1170
- children: /* @__PURE__ */ U(Me, {})
1171
- }),
1172
- /* @__PURE__ */ U(T, { children: c("automation_history_empty_title") }),
1173
- /* @__PURE__ */ U(E, { children: c("automation_history_empty_description") })
1174
- ] })
1175
- }) : /* @__PURE__ */ U("ul", {
1176
- className: "divide-y rounded-lg border bg-card",
1177
- children: P.map((e) => /* @__PURE__ */ U(Vt, {
1178
- automationId: r,
1179
- workspaceId: t,
1180
- run: e,
1181
- procedures: x,
1182
- onReveal: s,
1183
- savedRevision: a,
1184
- editorShowsSaved: o
1185
- }, e.runId))
1186
- }),
1187
- h === null ? null : /* @__PURE__ */ U(z, { message: S(h) }),
1188
- N === null || y.isPending ? null : /* @__PURE__ */ U(_, {
1189
- type: "button",
1190
- variant: "outline",
1191
- className: "self-center",
1192
- disabled: p,
1193
- onClick: () => {
1194
- let e = O.current, t = j, n = () => O.current === e;
1195
- m(!0), g(null), v.client.automation.runs.query({
1196
- id: r,
1197
- failedOnly: l,
1198
- limit: Rt,
1199
- before: N
1200
- }).then((e) => {
1201
- n() && f((n) => ({
1202
- after: t,
1203
- items: [...n?.after === t ? n.items : [], ...e.items],
1204
- next: e.next
1205
- }));
1206
- }, (e) => {
1207
- n() && g(e);
1208
- }).finally(() => {
1209
- n() && m(!1);
1210
- });
1211
- },
1212
- children: c("automation_history_older")
1213
- })
1214
- ]
1215
- });
1216
- }
1217
- //#endregion
1218
- //#region src/workspace/setup/automations/editor-page.tsx
1219
- function Ut({ workspaceId: i, automationId: a, tab: o = "editor", onTabChange: s, onCreated: l, starterHandoff: u }) {
1220
- let d = n(), f = r(), p = t(), m = Xe(), h = e.useUtils(), g = Ee(null), [x, C] = H(0), [w, T] = H(!1), [E, D] = H(!1), O = a != null, [k] = H(() => O ? void 0 : ye(u)), A = e.automation.validationContext.useQuery({ workspaceId: i }), j = e.automation.get.useQuery({ id: a ?? "" }, { enabled: O }), M = A.data, N = j.data, P = M != null && (!O || N != null), F = {
1221
- isLoading: A.isLoading || O && j.isLoading,
1222
- isError: !P && (A.isError || O && j.isError),
1223
- error: O ? j.error : A.error,
1224
- data: P ? {
1225
- context: M,
1226
- detail: N
1227
- } : void 0
1228
- }, I = P && (A.isError || O && j.isError), L = O ? o : "editor", ee = () => {
1229
- m({
1230
- to: "/workspace/$workspaceId/setup/automations",
1231
- params: { workspaceId: i }
1232
- });
1233
- };
1234
- return /* @__PURE__ */ W("div", {
1235
- className: "flex size-full min-h-0 flex-col",
1236
- children: [
1237
- /* @__PURE__ */ U(ne, {
1238
- icon: /* @__PURE__ */ U(Le, {}),
1239
- breadcrumbs: /* @__PURE__ */ U(ce, {
1240
- workspaceId: i,
1241
- section: "automations"
1242
- }),
1243
- title: N == null ? d("automation_create_title") : K(N.name, p),
1244
- actions: N == null ? null : /* @__PURE__ */ W("div", {
1245
- className: "flex items-center gap-2",
1246
- children: [/* @__PURE__ */ U(be, {
1247
- workspaceId: i,
1248
- entity: N,
1249
- kind: "automation"
1250
- }), /* @__PURE__ */ U(_, {
1251
- type: "button",
1252
- variant: "ghost",
1253
- size: "icon-sm",
1254
- "aria-label": d("automation_delete_action"),
1255
- onClick: () => {
1256
- T(!0);
1257
- },
1258
- children: /* @__PURE__ */ U(Fe, {})
1259
- })]
1260
- })
1261
- }),
1262
- /* @__PURE__ */ U("div", {
1263
- className: "flex w-full max-w-7xl flex-1 flex-col gap-4 p-4",
1264
- children: /* @__PURE__ */ U(se, {
1265
- query: F,
1266
- loading: /* @__PURE__ */ W("div", {
1267
- className: "flex flex-col gap-4",
1268
- children: [/* @__PURE__ */ U(b, { className: "h-8 w-64" }), /* @__PURE__ */ U(b, { className: "h-96 w-full" })]
1269
- }),
1270
- error: (e) => /* @__PURE__ */ U(oe, {
1271
- className: "flex-1 justify-center p-8",
1272
- message: S(e ?? "automation_not_found"),
1273
- onRetry: () => Promise.all([A.refetch(), j.refetch()])
1274
- }),
1275
- children: (e) => /* @__PURE__ */ W(De, { children: [
1276
- I ? /* @__PURE__ */ U(z, {
1277
- message: S(j.error ?? A.error),
1278
- onRetry: () => Promise.all([A.refetch(), j.refetch()])
1279
- }) : null,
1280
- O ? /* @__PURE__ */ U(ae, {
1281
- value: L,
1282
- onValueChange: (e) => {
1283
- (e === "editor" || e === "history") && s?.(e);
1284
- },
1285
- children: /* @__PURE__ */ W(ie, {
1286
- variant: "line",
1287
- children: [/* @__PURE__ */ U(re, {
1288
- value: "editor",
1289
- children: d("automation_tab_editor")
1290
- }), /* @__PURE__ */ U(re, {
1291
- value: "history",
1292
- children: d("automation_tab_history")
1293
- })]
1294
- })
1295
- }) : null,
1296
- /* @__PURE__ */ U("div", {
1297
- className: c(L !== "editor" && "hidden"),
1298
- children: /* @__PURE__ */ U(At, {
1299
- onDirtyChange: D,
1300
- ...k === void 0 ? {} : { starter: k },
1301
- workspaceId: i,
1302
- detail: e.detail,
1303
- context: e.context,
1304
- editorRef: g,
1305
- ...l == null ? {} : { onCreated: l },
1306
- onReload: async () => {
1307
- if (a == null) return;
1308
- let e = await h.client.automation.get.query({ id: a });
1309
- h.automation.get.setData({ id: a }, e), C((e) => e + 1);
1310
- }
1311
- }, `${a ?? "new"}-${String(x)}`)
1312
- }),
1313
- O && L === "history" && e.detail != null ? /* @__PURE__ */ U(Ht, {
1314
- workspaceId: i,
1315
- automationId: e.detail.id,
1316
- document: e.detail.document,
1317
- savedRevision: e.detail.revision,
1318
- editorShowsSaved: !E,
1319
- onReveal: (e) => {
1320
- s?.("editor"), requestAnimationFrame(() => {
1321
- let t = g.current;
1322
- if (t == null) return;
1323
- let n = t.text(), r = Y(q(n), n, e);
1324
- t.reveal(r.from, r.to);
1325
- });
1326
- }
1327
- }) : null
1328
- ] })
1329
- })
1330
- }),
1331
- /* @__PURE__ */ U(y, {
1332
- open: w && N != null,
1333
- onOpenChange: (e) => {
1334
- e || T(!1);
1335
- },
1336
- children: /* @__PURE__ */ U(v, { children: N == null ? null : /* @__PURE__ */ U(xe, {
1337
- workspaceId: i,
1338
- kind: "automation",
1339
- id: N.id,
1340
- baseRevision: N.revision,
1341
- onCancel: () => {
1342
- T(!1);
1343
- },
1344
- onDeleted: () => {
1345
- T(!1), f.success(d("automation_delete_toast")), ee();
1346
- }
1347
- }) })
1348
- })
1349
- ]
1350
- });
1351
- }
1352
- //#endregion
1353
- export { Ut as SetupAutomationEditorPage };