@antelopejs/dms-automation 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -22
- package/dist/cluster/bus.js +8 -6
- package/dist/cluster/bus.js.map +1 -1
- package/dist/cluster/leader.js.map +1 -1
- package/dist/data/procedures-query.d.ts +19 -0
- package/dist/data/procedures-query.js +105 -0
- package/dist/data/procedures-query.js.map +1 -0
- package/dist/data/procedures-table.d.ts +5 -20
- package/dist/data/procedures-table.js +10 -106
- package/dist/data/procedures-table.js.map +1 -1
- package/dist/data/runs-table.d.ts +3 -3
- package/dist/data/runs-table.js.map +1 -1
- package/dist/db/models/automation_template.model.d.ts +13 -13
- package/dist/db/models/automation_template.model.js +13 -14
- package/dist/db/models/automation_template.model.js.map +1 -1
- package/dist/db/models/procedure.model.d.ts +7 -5
- package/dist/db/models/procedure_run.model.d.ts +9 -6
- package/dist/db/models/procedure_run.model.js +8 -8
- package/dist/db/models/procedure_run.model.js.map +1 -1
- package/dist/db/models/stats.model.js.map +1 -1
- package/dist/db/models/type_switch.model.d.ts +7 -5
- package/dist/db/tables/procedure_run.table.d.ts +2 -1
- package/dist/db/tables/procedure_run.table.js.map +1 -1
- package/dist/implementations/dms-automation/index.d.ts +2 -2
- package/dist/implementations/dms-automation/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pages/category.js.map +1 -1
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/procedures.js.map +1 -1
- package/dist/pages/runs.js.map +1 -1
- package/dist/pages/shared.js +1 -1
- package/dist/pages/shared.js.map +1 -1
- package/dist/realtime.d.ts +2 -1
- package/dist/realtime.js.map +1 -1
- package/dist/routes/action-types.d.ts +3 -2
- package/dist/routes/action-types.js.map +1 -1
- package/dist/routes/data-node-types.d.ts +1 -1
- package/dist/routes/deleteConfirm.js +4 -3
- package/dist/routes/deleteConfirm.js.map +1 -1
- package/dist/routes/graphSchema.d.ts +2 -1
- package/dist/routes/graphSchema.js +13 -10
- package/dist/routes/graphSchema.js.map +1 -1
- package/dist/routes/library.d.ts +12 -1
- package/dist/routes/library.js +38 -34
- package/dist/routes/library.js.map +1 -1
- package/dist/routes/procedureChecks.js +5 -5
- package/dist/routes/procedureChecks.js.map +1 -1
- package/dist/routes/procedureRuns.d.ts +3 -3
- package/dist/routes/procedureRuns.js +1 -1
- package/dist/routes/procedureRuns.js.map +1 -1
- package/dist/routes/procedureSchemas.d.ts +7 -6
- package/dist/routes/procedureSchemas.js +4 -2
- package/dist/routes/procedureSchemas.js.map +1 -1
- package/dist/routes/procedures.d.ts +15 -14
- package/dist/routes/procedures.js +2 -1
- package/dist/routes/procedures.js.map +1 -1
- package/dist/routes/requests.d.ts +12 -6
- package/dist/routes/requests.js +2 -1
- package/dist/routes/requests.js.map +1 -1
- package/dist/routes/runs.d.ts +9 -8
- package/dist/routes/runs.js +5 -3
- package/dist/routes/runs.js.map +1 -1
- package/dist/routes/stats.js.map +1 -1
- package/dist/routes/templates.d.ts +5 -4
- package/dist/routes/templates.js +2 -1
- package/dist/routes/templates.js.map +1 -1
- package/dist/routes/trigger-types.d.ts +3 -2
- package/dist/routes/trigger-types.js.map +1 -1
- package/dist/routes/typeConfigShared.d.ts +2 -1
- package/dist/routes/typeConfigShared.js.map +1 -1
- package/dist/routes/zodJson.d.ts +3 -0
- package/dist/routes/zodJson.js +21 -0
- package/dist/routes/zodJson.js.map +1 -0
- package/dist/runtime/armErrors.d.ts +0 -1
- package/dist/runtime/armErrors.js +5 -12
- package/dist/runtime/armErrors.js.map +1 -1
- package/dist/runtime/boundRunLog.d.ts +7 -5
- package/dist/runtime/boundRunLog.js +24 -20
- package/dist/runtime/boundRunLog.js.map +1 -1
- package/dist/runtime/builtins/actions/http.d.ts +7 -3
- package/dist/runtime/builtins/actions/http.js +33 -22
- package/dist/runtime/builtins/actions/http.js.map +1 -1
- package/dist/runtime/builtins/actions/log.d.ts +5 -4
- package/dist/runtime/builtins/actions/log.js.map +1 -1
- package/dist/runtime/builtins/data/boolean.d.ts +2 -1
- package/dist/runtime/builtins/data/boolean.js +4 -5
- package/dist/runtime/builtins/data/boolean.js.map +1 -1
- package/dist/runtime/builtins/data/compare.js +8 -10
- package/dist/runtime/builtins/data/compare.js.map +1 -1
- package/dist/runtime/builtins/data/constant.js +1 -1
- package/dist/runtime/builtins/data/constant.js.map +1 -1
- package/dist/runtime/builtins/data/json.js +4 -5
- package/dist/runtime/builtins/data/json.js.map +1 -1
- package/dist/runtime/builtins/data/math.js +4 -4
- package/dist/runtime/builtins/data/math.js.map +1 -1
- package/dist/runtime/builtins/data/object.js +27 -27
- package/dist/runtime/builtins/data/object.js.map +1 -1
- package/dist/runtime/builtins/data/string.js +13 -18
- package/dist/runtime/builtins/data/string.js.map +1 -1
- package/dist/runtime/builtins/nodes/action.js +16 -5
- package/dist/runtime/builtins/nodes/action.js.map +1 -1
- package/dist/runtime/builtins/nodes/data.js +2 -2
- package/dist/runtime/builtins/nodes/data.js.map +1 -1
- package/dist/runtime/builtins/nodes/delay.js +2 -2
- package/dist/runtime/builtins/nodes/delay.js.map +1 -1
- package/dist/runtime/builtins/nodes/forRange.js +2 -2
- package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
- package/dist/runtime/builtins/nodes/foreach.js +2 -2
- package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupInput.js +2 -2
- package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
- package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
- package/dist/runtime/builtins/nodes/if.js +2 -2
- package/dist/runtime/builtins/nodes/if.js.map +1 -1
- package/dist/runtime/builtins/nodes/parallel.js +2 -2
- package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
- package/dist/runtime/builtins/nodes/retry.js +13 -5
- package/dist/runtime/builtins/nodes/retry.js.map +1 -1
- package/dist/runtime/builtins/nodes/setVariable.js +2 -2
- package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
- package/dist/runtime/builtins/nodes/switch.js +8 -3
- package/dist/runtime/builtins/nodes/switch.js.map +1 -1
- package/dist/runtime/builtins/nodes/trigger.js +2 -2
- package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
- package/dist/runtime/builtins/nodes/tryCatch.js +2 -2
- package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
- package/dist/runtime/builtins/triggers/cron.d.ts +4 -3
- package/dist/runtime/builtins/triggers/cron.js +5 -7
- package/dist/runtime/builtins/triggers/cron.js.map +1 -1
- package/dist/runtime/builtins/triggers/webhook.d.ts +11 -7
- package/dist/runtime/builtins/triggers/webhook.js +15 -12
- package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
- package/dist/runtime/declaredProcedures.d.ts +2 -2
- package/dist/runtime/declaredProcedures.js +3 -2
- package/dist/runtime/declaredProcedures.js.map +1 -1
- package/dist/runtime/describe.d.ts +3 -1
- package/dist/runtime/describe.js +14 -13
- package/dist/runtime/describe.js.map +1 -1
- package/dist/runtime/executor.d.ts +2 -1
- package/dist/runtime/executor.js +18 -13
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/flatten.d.ts +1 -1
- package/dist/runtime/flatten.js +1 -1
- package/dist/runtime/flatten.js.map +1 -1
- package/dist/runtime/graphIssues.d.ts +2 -2
- package/dist/runtime/graphIssues.js +39 -32
- package/dist/runtime/graphIssues.js.map +1 -1
- package/dist/runtime/graphVersion.d.ts +1 -1
- package/dist/runtime/graphVersion.js +4 -3
- package/dist/runtime/graphVersion.js.map +1 -1
- package/dist/runtime/nodeKinds.d.ts +6 -5
- package/dist/runtime/nodeKinds.js.map +1 -1
- package/dist/runtime/reconcile.d.ts +3 -0
- package/dist/runtime/reconcile.js +178 -0
- package/dist/runtime/reconcile.js.map +1 -0
- package/dist/runtime/registry.d.ts +3 -3
- package/dist/runtime/resolveInputs.d.ts +13 -8
- package/dist/runtime/resolveInputs.js +18 -18
- package/dist/runtime/resolveInputs.js.map +1 -1
- package/dist/runtime/resolveSubgraph.js +4 -5
- package/dist/runtime/resolveSubgraph.js.map +1 -1
- package/dist/runtime/retention.js.map +1 -1
- package/dist/runtime/runProcedure.d.ts +3 -2
- package/dist/runtime/runProcedure.js +2 -1
- package/dist/runtime/runProcedure.js.map +1 -1
- package/dist/runtime/schedule.js +3 -0
- package/dist/runtime/schedule.js.map +1 -1
- package/dist/runtime/schemaProperties.d.ts +3 -0
- package/dist/runtime/schemaProperties.js +7 -0
- package/dist/runtime/schemaProperties.js.map +1 -0
- package/dist/runtime/serialQueue.d.ts +1 -1
- package/dist/runtime/serialQueue.js +4 -4
- package/dist/runtime/serialQueue.js.map +1 -1
- package/dist/runtime/sideEffects.d.ts +2 -2
- package/dist/runtime/subscriptions.d.ts +6 -4
- package/dist/runtime/subscriptions.js +21 -180
- package/dist/runtime/subscriptions.js.map +1 -1
- package/dist/runtime/subwalk.js.map +1 -1
- package/dist/runtime/templateCacheState.d.ts +6 -0
- package/dist/runtime/templateCacheState.js +10 -0
- package/dist/runtime/templateCacheState.js.map +1 -0
- package/dist/runtime/templateUsages.js +4 -5
- package/dist/runtime/templateUsages.js.map +1 -1
- package/dist/runtime/topo.js +2 -4
- package/dist/runtime/topo.js.map +1 -1
- package/dist/runtime/trace.d.ts +5 -2
- package/dist/runtime/trace.js +27 -17
- package/dist/runtime/trace.js.map +1 -1
- package/dist/runtime/triggerHandles.d.ts +4 -3
- package/dist/runtime/triggerHandles.js +9 -1
- package/dist/runtime/triggerHandles.js.map +1 -1
- package/dist/runtime/typeOrigin.js +12 -1
- package/dist/runtime/typeOrigin.js.map +1 -1
- package/dist/runtime/validate.js.map +1 -1
- package/dist/runtime/validateTemplate.js.map +1 -1
- package/dist/runtime/withTimeout.js.map +1 -1
- package/dist/runtime/wording.js +12 -8
- package/dist/runtime/wording.js.map +1 -1
- package/dist/stats/health-banner.js.map +1 -1
- package/dist/stats/health.js.map +1 -1
- package/dist/stats/kpi.js +1 -1
- package/dist/stats/kpi.js.map +1 -1
- package/dist/stats/overview.js +2 -1
- package/dist/stats/overview.js.map +1 -1
- package/dist/types/dataValue.d.ts +7 -0
- package/dist/types/dataValue.js +56 -0
- package/dist/types/dataValue.js.map +1 -0
- package/dist/types/graph.d.ts +19 -13
- package/dist/types/graph.js +8 -0
- package/dist/types/graph.js.map +1 -1
- package/dist/types/guards.d.ts +8 -0
- package/dist/types/guards.js +35 -0
- package/dist/types/guards.js.map +1 -0
- package/dist/types/runLog.d.ts +8 -7
- package/dist/types/runLog.js.map +1 -1
- package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
- package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
- package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
- package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
- package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
- package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
- package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
- package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
- package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
- package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
- package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
- package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
- package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
- package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
- package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
- package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
- package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
- package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
- package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
- package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
- package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
- package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
- package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
- package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
- package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
- package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
- package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
- package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
- package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
- package/frontend-vue/app/build/types/editor.ts +94 -0
- package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
- package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
- package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
- package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
- package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
- package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
- package/frontend-vue/app/build/utils/templates.ts +88 -0
- package/frontend-vue/app/components/AttentionList.vue +2 -6
- package/frontend-vue/app/components/Catalog.vue +2 -1
- package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
- package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
- package/frontend-vue/app/components/Editor.vue +134 -3484
- package/frontend-vue/app/components/Templates.vue +14 -84
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +2 -0
- package/frontend-vue/eslint-rules/index.mjs +103 -0
- package/frontend-vue/eslint.config.mjs +15 -0
- package/frontend-vue/package.json +8 -5
- package/frontend-vue/pnpm-lock.yaml +168 -139
- package/frontend-vue/tests/api-error-presentation.test.cjs +254 -0
- package/frontend-vue/tests/helpers/setup.cjs +44 -0
- package/package.json +18 -15
- package/skills/dms-automation/SKILL.md +2 -2
- package/skills/dms-automation/cases.json +58 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { EditorContext } from "./useEditorContext";
|
|
2
|
+
import type {
|
|
3
|
+
GroupPort,
|
|
4
|
+
ProcedureGraph,
|
|
5
|
+
} from "../../../composables/useGraphConnect";
|
|
6
|
+
import type { ProcedureRecord } from "../../types/editor";
|
|
7
|
+
|
|
8
|
+
/** Reads what the builder opens, the procedure list or the template `?template=` names, and opens it. */
|
|
9
|
+
export function useEditorLoad(ctx: EditorContext) {
|
|
10
|
+
const {
|
|
11
|
+
editorMode,
|
|
12
|
+
editorTemplateId,
|
|
13
|
+
loadError,
|
|
14
|
+
loading,
|
|
15
|
+
missingProcedureId,
|
|
16
|
+
procedures,
|
|
17
|
+
queryValue,
|
|
18
|
+
selectedId,
|
|
19
|
+
t,
|
|
20
|
+
templateIcon,
|
|
21
|
+
templateNotFound,
|
|
22
|
+
templatePorts,
|
|
23
|
+
} = ctx;
|
|
24
|
+
|
|
25
|
+
const PROCEDURES_PAGE_SIZE = 200;
|
|
26
|
+
|
|
27
|
+
// What the builder opens, read with the page: every procedure, or the
|
|
28
|
+
// template `?template=` names. The editor works on its own copy of what they
|
|
29
|
+
// answered (`procedures`), which its drafts change.
|
|
30
|
+
const procedureListRead = useApiData<ProcedureRecord[]>(
|
|
31
|
+
() =>
|
|
32
|
+
editorMode.value === "procedure"
|
|
33
|
+
? "dms-automation-builder-procedures"
|
|
34
|
+
: null,
|
|
35
|
+
async ({ $authFetch, signal }) => {
|
|
36
|
+
// The API serves pages of PROCEDURES_PAGE_SIZE at most: read them all.
|
|
37
|
+
const list: ProcedureRecord[] = [];
|
|
38
|
+
for (let page = 0; ; page++) {
|
|
39
|
+
const { results } = await $authFetch<{ results: ProcedureRecord[] }>(
|
|
40
|
+
`/api/automation/procedures?limit=${PROCEDURES_PAGE_SIZE}&page=${page}`,
|
|
41
|
+
{ signal },
|
|
42
|
+
);
|
|
43
|
+
list.push(...results);
|
|
44
|
+
if (results.length < PROCEDURES_PAGE_SIZE) break;
|
|
45
|
+
}
|
|
46
|
+
return list;
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
interface AutomationTemplateApi {
|
|
51
|
+
_id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
icon?: string;
|
|
55
|
+
ports: GroupPort[];
|
|
56
|
+
subgraph: ProcedureGraph;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const templateRead = useApiData<AutomationTemplateApi>(() =>
|
|
60
|
+
editorTemplateId.value
|
|
61
|
+
? `/api/automation/templates/${editorTemplateId.value}`
|
|
62
|
+
: null,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
/** Opens what the procedure list answered: `?selected=`, else the procedure open, else the first. */
|
|
66
|
+
function openList() {
|
|
67
|
+
const error = procedureListRead.error.value;
|
|
68
|
+
if (error) {
|
|
69
|
+
loadError.value = describeApiError(error);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
loadError.value = null;
|
|
73
|
+
// Copies: a draft changes the editor's records, not the read's.
|
|
74
|
+
procedures.value = (procedureListRead.data.value ?? []).map((p) => ({
|
|
75
|
+
...p,
|
|
76
|
+
}));
|
|
77
|
+
if (
|
|
78
|
+
selectedId.value &&
|
|
79
|
+
!procedures.value.some((p) => p._id === selectedId.value)
|
|
80
|
+
) {
|
|
81
|
+
selectedId.value = null;
|
|
82
|
+
}
|
|
83
|
+
const requested = queryValue("selected");
|
|
84
|
+
if (requested && procedures.value.some((p) => p._id === requested)) {
|
|
85
|
+
selectedId.value = requested;
|
|
86
|
+
} else if (requested && !selectedId.value) {
|
|
87
|
+
// A link to a deleted procedure opens none: the builder says so
|
|
88
|
+
// and offers the switcher (see onMounted).
|
|
89
|
+
missingProcedureId.value = requested;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!selectedId.value && procedures.value.length > 0) {
|
|
93
|
+
const first = procedures.value[0];
|
|
94
|
+
selectedId.value = first ? first._id : null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Reads the procedure list again (one was created) and opens it. */
|
|
99
|
+
async function loadList() {
|
|
100
|
+
loading.value = true;
|
|
101
|
+
await procedureListRead.refresh();
|
|
102
|
+
loading.value = false;
|
|
103
|
+
openList();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Opens what the template read answered, or says why there is none. */
|
|
107
|
+
function openTemplate() {
|
|
108
|
+
const id = editorTemplateId.value;
|
|
109
|
+
if (!id) {
|
|
110
|
+
templateNotFound.value = true;
|
|
111
|
+
loadError.value = t("dms_automation.editor.templateNotFound");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const error = templateRead.error.value;
|
|
115
|
+
const tpl = templateRead.data.value;
|
|
116
|
+
if (error || !tpl) {
|
|
117
|
+
// Worded for users, the same on the server and in the browser (the
|
|
118
|
+
// raw fetch error names an internal URL that differs between them).
|
|
119
|
+
templateNotFound.value = apiErrorStatus(error) === 404;
|
|
120
|
+
loadError.value = templateNotFound.value
|
|
121
|
+
? t("dms_automation.editor.templateNotFound")
|
|
122
|
+
: describeApiError(error);
|
|
123
|
+
procedures.value = [];
|
|
124
|
+
selectedId.value = null;
|
|
125
|
+
templatePorts.value = [];
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
templateNotFound.value = false;
|
|
129
|
+
loadError.value = null;
|
|
130
|
+
// Adapt the template into the ProcedureRecord shape so the rest of
|
|
131
|
+
// the editor (history, dirty-tracking, sentinel sync, group toolbar)
|
|
132
|
+
// keeps working unchanged. `enabled` is meaningless for templates;
|
|
133
|
+
// pin it to true so the "disabled" warning banner never appears.
|
|
134
|
+
const adapted: ProcedureRecord = {
|
|
135
|
+
_id: tpl._id,
|
|
136
|
+
name: tpl.name,
|
|
137
|
+
description: tpl.description ?? "",
|
|
138
|
+
enabled: true,
|
|
139
|
+
graph: tpl.subgraph,
|
|
140
|
+
};
|
|
141
|
+
procedures.value = [adapted];
|
|
142
|
+
selectedId.value = adapted._id;
|
|
143
|
+
templateIcon.value = tpl.icon || "i-ph-package";
|
|
144
|
+
templatePorts.value = Array.isArray(tpl.ports)
|
|
145
|
+
? tpl.ports.map((p) => ({ ...p }))
|
|
146
|
+
: [];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
procedureListRead,
|
|
151
|
+
templateRead,
|
|
152
|
+
openList,
|
|
153
|
+
loadList,
|
|
154
|
+
openTemplate,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type EditorLoad = ReturnType<typeof useEditorLoad>;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import type { EditorContext } from "./useEditorContext";
|
|
3
|
+
import type {
|
|
4
|
+
GraphNode,
|
|
5
|
+
GroupPort,
|
|
6
|
+
ProcedureGraph,
|
|
7
|
+
} from "../../../composables/useGraphConnect";
|
|
8
|
+
import type { SubgraphNavigation } from "./useSubgraphNavigation";
|
|
9
|
+
|
|
10
|
+
/** Turning a template instance back into a local group. */
|
|
11
|
+
export function useForkToLocal(ctx: EditorContext, nav: SubgraphNavigation) {
|
|
12
|
+
const { resolveError } = useApiErrorPresenter();
|
|
13
|
+
const {
|
|
14
|
+
$authFetch,
|
|
15
|
+
currentGraph,
|
|
16
|
+
isCurrentGraphReadOnly,
|
|
17
|
+
selected,
|
|
18
|
+
selectedNode,
|
|
19
|
+
selectedNodeId,
|
|
20
|
+
subgraphFrames,
|
|
21
|
+
subgraphPath,
|
|
22
|
+
t,
|
|
23
|
+
toast,
|
|
24
|
+
} = ctx;
|
|
25
|
+
const { onUpdateNode } = nav;
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Fork-to-local-group
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Visible when a template-instance group node is selected — i.e. kind === 'group'
|
|
31
|
+
// AND templateId is set. The fork is the escape hatch from the live-link
|
|
32
|
+
// model: it converts the instance back to a local group by deep-cloning the
|
|
33
|
+
// template's current subgraph into the node and dropping templateId.
|
|
34
|
+
//
|
|
35
|
+
// Selection rules:
|
|
36
|
+
// • Allowed even from the read-only inner-subgraph view of a template
|
|
37
|
+
// instance — this is the "Fork to edit" CTA flow. The action mutates
|
|
38
|
+
// the OUTER graph (the procedure root or whichever container holds
|
|
39
|
+
// the template instance), not the inner subgraph being viewed.
|
|
40
|
+
// • To make that work, the selection target for the fork is the deepest
|
|
41
|
+
// currentParentGroup when we're inside a template-instance subgraph,
|
|
42
|
+
// OR the selectedNode otherwise.
|
|
43
|
+
//
|
|
44
|
+
// The deep-clone uses a JSON parse/stringify round-trip: structuredClone
|
|
45
|
+
// throws on Vue's reactive proxies (see the inline note at the clone site).
|
|
46
|
+
//
|
|
47
|
+
// Edge case: if the template was deleted between selection and confirm,
|
|
48
|
+
// GET /:id returns 404 → we surface that as an error in the modal so the
|
|
49
|
+
// user can dismiss and stop trying.
|
|
50
|
+
interface ForkTarget {
|
|
51
|
+
// The group node to convert (the template instance).
|
|
52
|
+
node: GraphNode;
|
|
53
|
+
// The graph in which that node lives. May be the procedure root or any
|
|
54
|
+
// outer subgraph (when the user is viewing the inner read-only graph of
|
|
55
|
+
// an instance, the instance node lives one frame up).
|
|
56
|
+
containerGraph: ProcedureGraph;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const forkTarget = computed<ForkTarget | null>(() => {
|
|
60
|
+
if (!selected.value) return null;
|
|
61
|
+
const frames = subgraphFrames.value;
|
|
62
|
+
// Case A: user is INSIDE a template-instance subgraph (read-only view).
|
|
63
|
+
// The instance node is the parent group; its container is the previous
|
|
64
|
+
// frame's graph.
|
|
65
|
+
if (isCurrentGraphReadOnly.value && frames.length >= 2) {
|
|
66
|
+
const parent = frames[frames.length - 1]!.groupNode;
|
|
67
|
+
const container = frames[frames.length - 2]!.graph;
|
|
68
|
+
if (parent && parent.kind === "group" && parent.templateId) {
|
|
69
|
+
return { node: parent, containerGraph: container };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Case B: user has a template-instance node selected in the current
|
|
73
|
+
// (editable) graph.
|
|
74
|
+
const sel = selectedNode.value;
|
|
75
|
+
const g = currentGraph.value;
|
|
76
|
+
if (sel && g && sel.kind === "group" && sel.templateId) {
|
|
77
|
+
return { node: sel, containerGraph: g };
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const canForkToLocal = computed<boolean>(() => forkTarget.value !== null);
|
|
83
|
+
|
|
84
|
+
const forkOpen = ref<boolean>(false);
|
|
85
|
+
const forkSubmitting = ref<boolean>(false);
|
|
86
|
+
const forkError = ref<ReturnType<typeof resolveError>>(null);
|
|
87
|
+
|
|
88
|
+
function openFork() {
|
|
89
|
+
if (!canForkToLocal.value) return;
|
|
90
|
+
forkError.value = null;
|
|
91
|
+
forkSubmitting.value = false;
|
|
92
|
+
forkOpen.value = true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
interface FetchedTemplate {
|
|
96
|
+
_id: string;
|
|
97
|
+
name: string;
|
|
98
|
+
description: string;
|
|
99
|
+
icon: string;
|
|
100
|
+
ports: GroupPort[];
|
|
101
|
+
subgraph: ProcedureGraph;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Replace the template instance node with a forked local copy. Mirrors the
|
|
105
|
+
// shape of convertLocalGroupToTemplateInstance but in reverse: drops
|
|
106
|
+
// templateId, installs subgraph from the fetched template, and writes back
|
|
107
|
+
// through onUpdateNode / onGraphUpdate (so history + dirty-snapshot stay
|
|
108
|
+
// consistent). The replacement uses a fresh node object so Vue reactivity
|
|
109
|
+
// sees a real change.
|
|
110
|
+
function convertTemplateInstanceToLocal(
|
|
111
|
+
target: ForkTarget,
|
|
112
|
+
template: FetchedTemplate,
|
|
113
|
+
): void {
|
|
114
|
+
const { node, containerGraph } = target;
|
|
115
|
+
const idx = containerGraph.nodes.findIndex(
|
|
116
|
+
(n) => n.id === node.id && n.kind === "group",
|
|
117
|
+
);
|
|
118
|
+
if (idx === -1) return;
|
|
119
|
+
const updated: GraphNode = {
|
|
120
|
+
...node,
|
|
121
|
+
// Deep-clone the template's subgraph so subsequent edits to the
|
|
122
|
+
// template (or to this fork) don't alias each other. JSON round-trip
|
|
123
|
+
// strips Vue's reactive proxy — structuredClone throws on proxies.
|
|
124
|
+
subgraph: JSON.parse(JSON.stringify(template.subgraph)) as ProcedureGraph,
|
|
125
|
+
// Preserve the local ports if the instance carries them (it should
|
|
126
|
+
// — palette drops clone template.ports onto the instance); fall back
|
|
127
|
+
// to the template's port list otherwise.
|
|
128
|
+
ports:
|
|
129
|
+
Array.isArray(node.ports) && node.ports.length > 0
|
|
130
|
+
? node.ports.map((p) => ({ ...p }))
|
|
131
|
+
: template.ports.map((p) => ({ ...p })),
|
|
132
|
+
};
|
|
133
|
+
delete updated.templateId;
|
|
134
|
+
|
|
135
|
+
// If the user was inside the template instance's subgraph (Case A in
|
|
136
|
+
// forkTarget), pop the read-only path segment first so the canvas
|
|
137
|
+
// re-binds to the (now editable) outer graph. The user can re-enter
|
|
138
|
+
// the local subgraph fresh via dblclick if they want.
|
|
139
|
+
if (isCurrentGraphReadOnly.value && subgraphPath.value.length > 1) {
|
|
140
|
+
subgraphPath.value = subgraphPath.value.slice(0, -1);
|
|
141
|
+
selectedNodeId.value = updated.id;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Use onUpdateNode — it walks subgraphPath and rewrites the correct
|
|
145
|
+
// container graph (root or any depth). Because we just popped above
|
|
146
|
+
// when needed, currentGraph now points at containerGraph.
|
|
147
|
+
onUpdateNode(updated);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function submitFork() {
|
|
151
|
+
const target = forkTarget.value;
|
|
152
|
+
if (!target) return;
|
|
153
|
+
const templateId = target.node.templateId;
|
|
154
|
+
if (!templateId) return;
|
|
155
|
+
forkSubmitting.value = true;
|
|
156
|
+
forkError.value = null;
|
|
157
|
+
try {
|
|
158
|
+
const tpl = await $authFetch<FetchedTemplate>(
|
|
159
|
+
`/api/automation/templates/${templateId}`,
|
|
160
|
+
);
|
|
161
|
+
convertTemplateInstanceToLocal(target, tpl);
|
|
162
|
+
forkOpen.value = false;
|
|
163
|
+
toast.add({
|
|
164
|
+
title: t("dms_automation.editor.forked", {
|
|
165
|
+
name:
|
|
166
|
+
target.node.label ||
|
|
167
|
+
(target.node.config?.name as string | undefined) ||
|
|
168
|
+
tpl.name,
|
|
169
|
+
}),
|
|
170
|
+
color: "success",
|
|
171
|
+
icon: "i-ph-check-circle",
|
|
172
|
+
});
|
|
173
|
+
} catch (e) {
|
|
174
|
+
forkError.value = resolveError(e, {
|
|
175
|
+
fallbackKey: "dms_automation.editor.forkModal.error",
|
|
176
|
+
});
|
|
177
|
+
} finally {
|
|
178
|
+
forkSubmitting.value = false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
forkTarget,
|
|
184
|
+
canForkToLocal,
|
|
185
|
+
forkOpen,
|
|
186
|
+
forkSubmitting,
|
|
187
|
+
forkError,
|
|
188
|
+
openFork,
|
|
189
|
+
submitFork,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export type ForkToLocal = ReturnType<typeof useForkToLocal>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import type { EditorContext } from "./useEditorContext";
|
|
3
|
+
import type { ProcedureGraph } from "../../../composables/useGraphConnect";
|
|
4
|
+
import { cloneGraph, repeatableChangeKey } from "../../utils/editor/graphShape";
|
|
5
|
+
import type { ProcedureRecord, ProcedureSnapshot } from "../../types/editor";
|
|
6
|
+
|
|
7
|
+
/** The draft's undo history, and the snapshot a save is compared against. */
|
|
8
|
+
export function useGraphHistory(ctx: EditorContext) {
|
|
9
|
+
const { editorMode, savedSnapshot, selected, templatePorts } = ctx;
|
|
10
|
+
|
|
11
|
+
const graphHistory = ref<ProcedureGraph[]>([]);
|
|
12
|
+
const graphHistoryIndex = ref<number>(-1);
|
|
13
|
+
|
|
14
|
+
const HISTORY_LIMIT = 100;
|
|
15
|
+
|
|
16
|
+
function takeSnapshot(p: ProcedureRecord): ProcedureSnapshot {
|
|
17
|
+
return {
|
|
18
|
+
name: p.name,
|
|
19
|
+
enabled: p.enabled,
|
|
20
|
+
graph: cloneGraph(p.graph),
|
|
21
|
+
...(editorMode.value === "template"
|
|
22
|
+
? { ports: templatePorts.value.map((port) => ({ ...port })) }
|
|
23
|
+
: {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// A drag emits a graph per frame and a text field one per keystroke: the
|
|
28
|
+
// changes of one burst make one undo step (the last one is replaced while
|
|
29
|
+
// the same nodes move, or the same field is typed in, without a pause).
|
|
30
|
+
const HISTORY_MERGE_MS = 1000;
|
|
31
|
+
let lastChange: { key: string | null; at: number } = { key: null, at: 0 };
|
|
32
|
+
|
|
33
|
+
function pushHistory(g: ProcedureGraph, merge = false) {
|
|
34
|
+
const current = graphHistory.value[graphHistoryIndex.value];
|
|
35
|
+
if (current && JSON.stringify(current) === JSON.stringify(g)) return;
|
|
36
|
+
const key = merge && current ? repeatableChangeKey(current, g) : null;
|
|
37
|
+
const now = Date.now();
|
|
38
|
+
const sameBurst =
|
|
39
|
+
key !== null &&
|
|
40
|
+
key === lastChange.key &&
|
|
41
|
+
now - lastChange.at < HISTORY_MERGE_MS;
|
|
42
|
+
lastChange = { key, at: now };
|
|
43
|
+
// A new action, a drag included, drops what Redo could bring back.
|
|
44
|
+
graphHistory.value = graphHistory.value.slice(
|
|
45
|
+
0,
|
|
46
|
+
graphHistoryIndex.value + 1,
|
|
47
|
+
);
|
|
48
|
+
if (sameBurst) {
|
|
49
|
+
graphHistory.value[graphHistoryIndex.value] = cloneGraph(g);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
graphHistory.value.push(cloneGraph(g));
|
|
53
|
+
graphHistoryIndex.value = graphHistory.value.length - 1;
|
|
54
|
+
if (graphHistory.value.length > HISTORY_LIMIT) {
|
|
55
|
+
graphHistory.value.shift();
|
|
56
|
+
graphHistoryIndex.value--;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function initHistoryAndSaved() {
|
|
61
|
+
lastChange = { key: null, at: 0 };
|
|
62
|
+
if (selected.value) {
|
|
63
|
+
graphHistory.value = [cloneGraph(selected.value.graph)];
|
|
64
|
+
graphHistoryIndex.value = 0;
|
|
65
|
+
savedSnapshot.value = takeSnapshot(selected.value);
|
|
66
|
+
} else {
|
|
67
|
+
graphHistory.value = [];
|
|
68
|
+
graphHistoryIndex.value = -1;
|
|
69
|
+
savedSnapshot.value = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const canUndo = computed<boolean>(() => graphHistoryIndex.value > 0);
|
|
74
|
+
const canRedo = computed<boolean>(
|
|
75
|
+
() => graphHistoryIndex.value < graphHistory.value.length - 1,
|
|
76
|
+
);
|
|
77
|
+
const isDirty = computed<boolean>(() => {
|
|
78
|
+
if (!selected.value || !savedSnapshot.value) return false;
|
|
79
|
+
return (
|
|
80
|
+
JSON.stringify(takeSnapshot(selected.value)) !==
|
|
81
|
+
JSON.stringify(savedSnapshot.value)
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
function onUndo() {
|
|
86
|
+
if (!canUndo.value || !selected.value) return;
|
|
87
|
+
lastChange = { key: null, at: 0 };
|
|
88
|
+
graphHistoryIndex.value--;
|
|
89
|
+
const g = graphHistory.value[graphHistoryIndex.value];
|
|
90
|
+
if (g) selected.value.graph = cloneGraph(g);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function onRedo() {
|
|
94
|
+
if (!canRedo.value || !selected.value) return;
|
|
95
|
+
lastChange = { key: null, at: 0 };
|
|
96
|
+
graphHistoryIndex.value++;
|
|
97
|
+
const g = graphHistory.value[graphHistoryIndex.value];
|
|
98
|
+
if (g) selected.value.graph = cloneGraph(g);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
takeSnapshot,
|
|
103
|
+
pushHistory,
|
|
104
|
+
initHistoryAndSaved,
|
|
105
|
+
canUndo,
|
|
106
|
+
canRedo,
|
|
107
|
+
isDirty,
|
|
108
|
+
onUndo,
|
|
109
|
+
onRedo,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type GraphHistory = ReturnType<typeof useGraphHistory>;
|