@omnidim-ai/mcp-server 0.15.0 → 0.16.1
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/build/index.d.ts +1 -1
- package/build/index.js +3 -2
- package/build/index.js.map +1 -1
- package/build/procedures.js +8 -5
- package/build/procedures.js.map +1 -1
- package/build/tool-annotations.js +1 -0
- package/build/tool-annotations.js.map +1 -1
- package/build/workflow-canvas.d.ts +15 -1
- package/build/workflow-canvas.js +378 -116
- package/build/workflow-canvas.js.map +1 -1
- package/package.json +3 -1
- package/src/index.ts +3 -2
- package/src/procedures.ts +8 -5
- package/src/tool-annotations.ts +1 -0
- package/src/workflow-canvas.ts +389 -117
package/src/workflow-canvas.ts
CHANGED
|
@@ -1,30 +1,97 @@
|
|
|
1
|
-
// MCP Apps view (ui:// resource) that
|
|
1
|
+
// MCP Apps view (ui:// resource) that shows and edits a workflow draft inside the chat.
|
|
2
2
|
// The page holds no API key: every read and edit goes back through this
|
|
3
3
|
// server's own tools via the host, so it runs on the user's existing login.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// Where the canvas lived before its address carried a hash. Chats that showed it still ask for it there.
|
|
8
|
+
export const LEGACY_CANVAS_URI = "ui://omnidim/workflow-canvas";
|
|
8
9
|
|
|
10
|
+
// Only showWorkflow draws the canvas. Linking get/create/edit posted one canvas per build step.
|
|
9
11
|
export function toolMeta(name: string): { ui: { resourceUri: string } } | undefined {
|
|
10
|
-
return
|
|
12
|
+
return name === "showWorkflow" ? { ui: { resourceUri: WORKFLOW_CANVAS_URI } } : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const SHOW_WORKFLOW_DESCRIPTION = `Show a workflow to the user as an interactive canvas in the chat, where they can move, rename, edit and delete nodes. Call it when the user asks to see a workflow, and once after you finish building or changing one. Do not call it before every edit: use \`getWorkflow\` to read the draft.
|
|
16
|
+
|
|
17
|
+
(Tags: Workflows)`;
|
|
18
|
+
|
|
19
|
+
interface ToolDef {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
inputSchema: any;
|
|
23
|
+
executionParameters: Array<{ name: string; in: string }>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// showWorkflow reads the same endpoint as getWorkflow; it exists so the canvas has one trigger.
|
|
27
|
+
export function addShowWorkflow<T extends ToolDef>(map: Map<string, T>): void {
|
|
28
|
+
const get = map.get("getWorkflow");
|
|
29
|
+
if (!get) return;
|
|
30
|
+
map.set("showWorkflow", {
|
|
31
|
+
...get,
|
|
32
|
+
name: "showWorkflow",
|
|
33
|
+
description: SHOW_WORKFLOW_DESCRIPTION,
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: "object",
|
|
36
|
+
properties: { workflow_id: get.inputSchema.properties.workflow_id },
|
|
37
|
+
required: ["workflow_id"],
|
|
38
|
+
},
|
|
39
|
+
executionParameters: get.executionParameters.filter((p) => p.name === "workflow_id"),
|
|
40
|
+
});
|
|
11
41
|
}
|
|
12
42
|
|
|
13
43
|
interface ToolResult { isError?: boolean; content?: Array<{ type: string; text?: string }>; }
|
|
14
44
|
|
|
15
|
-
//
|
|
16
|
-
|
|
45
|
+
// The three helpers below are embedded into the page with toString(), so they must not
|
|
46
|
+
// reference anything outside themselves.
|
|
47
|
+
export function readWorkflow(result: ToolResult): { workflow: any; workflowId: number | null; issues: any[]; error: string | null } {
|
|
17
48
|
const text = (result.content || []).filter((c) => c.type === "text").map((c) => c.text || "").join("\n");
|
|
18
|
-
if (result.isError) return { workflow: null, workflowId: null, error: text };
|
|
49
|
+
if (result.isError) return { workflow: null, workflowId: null, issues: [], error: text };
|
|
19
50
|
const body = text.startsWith("API Response") ? text.slice(text.indexOf("\n") + 1) : text;
|
|
20
51
|
let data: any;
|
|
21
|
-
try { data = JSON.parse(body); } catch { return { workflow: null, workflowId: null, error: text }; }
|
|
52
|
+
try { data = JSON.parse(body); } catch { return { workflow: null, workflowId: null, issues: [], error: text }; }
|
|
22
53
|
const wf = data && (data.workflow || data);
|
|
23
54
|
const id = wf && (wf.id ?? wf.workflow_id);
|
|
24
55
|
const workflowId = typeof id === "number" ? id : null;
|
|
25
|
-
|
|
56
|
+
const src = data && data.issues ? data.issues : data;
|
|
57
|
+
const issues = src && Array.isArray(src.errors) ? src.errors : [];
|
|
58
|
+
return { workflow: wf && wf.draft ? wf : null, workflowId, issues, error: null };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The hosted server takes edit fields flat; the npm server takes them under requestBody.
|
|
62
|
+
// Each drops the shape it does not use, and the API ignores the extra key.
|
|
63
|
+
export function editArgs(workflowId: number, revision: string, ops: any[]): Record<string, unknown> {
|
|
64
|
+
return { workflow_id: workflowId, revision, ops, requestBody: { revision, ops } };
|
|
26
65
|
}
|
|
27
66
|
|
|
67
|
+
export function errorText(text: string): string {
|
|
68
|
+
const start = text.indexOf("{");
|
|
69
|
+
if (start >= 0) {
|
|
70
|
+
try {
|
|
71
|
+
const data = JSON.parse(text.slice(start));
|
|
72
|
+
const msg = data.error_description || data.message || data.detail || data.error;
|
|
73
|
+
if (typeof msg === "string" && msg) return msg;
|
|
74
|
+
} catch { /* not JSON: fall through to the plain text */ }
|
|
75
|
+
}
|
|
76
|
+
return text.length > 160 ? text.slice(0, 157) + "..." : text;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Icon shapes copied from lucide (the set the dashboard's workflow editor uses).
|
|
80
|
+
const ICONS: Record<string, string> = {
|
|
81
|
+
zap: '<path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"/>',
|
|
82
|
+
phone: '<path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"/>',
|
|
83
|
+
clock: '<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',
|
|
84
|
+
branch: '<line x1="6" x2="6" y1="3" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/>',
|
|
85
|
+
mail: '<rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>',
|
|
86
|
+
globe: '<circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/>',
|
|
87
|
+
braces: '<path d="M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1"/><path d="M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1"/>',
|
|
88
|
+
workflow: '<rect width="8" height="8" x="3" y="3" rx="2"/><path d="M7 11v4a2 2 0 0 0 2 2h4"/><rect width="8" height="8" x="13" y="13" rx="2"/>',
|
|
89
|
+
message: '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>',
|
|
90
|
+
sparkles: '<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/>',
|
|
91
|
+
user: '<path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><line x1="19" x2="19" y1="8" y2="14"/><line x1="22" x2="16" y1="11" y2="11"/>',
|
|
92
|
+
note: '<path d="M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z"/><path d="M15 3v4a2 2 0 0 0 2 2h4"/>',
|
|
93
|
+
};
|
|
94
|
+
|
|
28
95
|
export const WORKFLOW_CANVAS_HTML = `<!doctype html>
|
|
29
96
|
<html lang="en">
|
|
30
97
|
<head>
|
|
@@ -32,68 +99,99 @@ export const WORKFLOW_CANVAS_HTML = `<!doctype html>
|
|
|
32
99
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
33
100
|
<title>Workflow canvas</title>
|
|
34
101
|
<style>
|
|
102
|
+
/* Colors follow the dashboard's workflow editor tokens. */
|
|
35
103
|
:root {
|
|
36
|
-
--bg:
|
|
37
|
-
--
|
|
38
|
-
--
|
|
104
|
+
--bg: hsl(210 30% 96%); --card: hsl(210 30% 99%); --fg: hsl(222 47% 9%); --muted: hsl(215 19% 36%);
|
|
105
|
+
--line: hsl(214 25% 87%); --edge: #94a3b8; --dot: hsl(214 25% 84%); --primary: hsl(172.5 66% 40.4%);
|
|
106
|
+
--primary-soft: hsl(172.5 66% 40.4% / .12); --sel: #fbbf24; --err: #dc2626; --err-soft: hsl(0 84% 60% / .08);
|
|
39
107
|
color-scheme: light;
|
|
40
108
|
}
|
|
41
109
|
:root[data-theme="dark"] {
|
|
42
|
-
--bg:
|
|
43
|
-
--
|
|
44
|
-
--
|
|
110
|
+
--bg: hsl(0 0% 3.9%); --card: hsl(0 0% 7%); --fg: hsl(0 0% 98%); --muted: hsl(0 0% 64%);
|
|
111
|
+
--line: hsl(0 0% 16%); --edge: #64748b; --dot: hsl(0 0% 14%); --primary: hsl(180 100% 35.1%);
|
|
112
|
+
--primary-soft: hsl(180 100% 35.1% / .16); --sel: #fbbf24; --err: #f87171; --err-soft: hsl(0 91% 71% / .1);
|
|
45
113
|
color-scheme: dark;
|
|
46
114
|
}
|
|
47
115
|
* { box-sizing: border-box; }
|
|
48
|
-
body { margin: 0; font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--
|
|
49
|
-
header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
|
|
116
|
+
body { margin: 0; font: 13px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--fg); background: var(--bg); }
|
|
117
|
+
header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; background: var(--card); }
|
|
50
118
|
header h1 { font-size: 14px; margin: 0; font-weight: 600; flex: 1 1 200px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
51
119
|
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
|
|
52
|
-
|
|
120
|
+
.pill.bad { color: var(--err); border-color: var(--err); }
|
|
121
|
+
button, input, textarea { font: inherit; font-size: 12px; color: var(--fg); }
|
|
122
|
+
button { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
|
|
53
123
|
button:hover { border-color: var(--edge); }
|
|
54
|
-
button:
|
|
55
|
-
|
|
56
|
-
:
|
|
124
|
+
button:disabled { opacity: .6; cursor: progress; }
|
|
125
|
+
button.danger { color: var(--err); }
|
|
126
|
+
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
|
|
127
|
+
#stage { overflow: auto; background-color: var(--bg); background-image: radial-gradient(var(--dot) 1px, transparent 1px); background-size: 16px 16px; }
|
|
128
|
+
:root[data-mode="fullscreen"] #stage { height: calc(100vh - 52px - var(--panel-h, 0px)); }
|
|
57
129
|
svg { display: block; touch-action: none; }
|
|
58
|
-
.
|
|
59
|
-
.node
|
|
130
|
+
.card { fill: var(--card); stroke: var(--line); stroke-width: 1; }
|
|
131
|
+
.node:hover .card { stroke: var(--primary); }
|
|
132
|
+
.node.selected .card { stroke: var(--sel); stroke-width: 2; }
|
|
133
|
+
.node.invalid .card { stroke: var(--err); stroke-width: 1.5; }
|
|
60
134
|
.node { cursor: grab; }
|
|
61
|
-
.node.dragging { cursor: grabbing;
|
|
62
|
-
.
|
|
63
|
-
.
|
|
64
|
-
.
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
135
|
+
.node.dragging { cursor: grabbing; }
|
|
136
|
+
.icon-box { fill: var(--primary-soft); }
|
|
137
|
+
.icon { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
|
|
138
|
+
.label { font-size: 13px; font-weight: 600; fill: var(--fg); }
|
|
139
|
+
.sub { font-size: 11.5px; fill: var(--muted); }
|
|
140
|
+
.handle { fill: var(--edge); stroke: var(--card); stroke-width: 2; }
|
|
141
|
+
.edge { fill: none; stroke: var(--edge); stroke-width: 2; }
|
|
142
|
+
.chip rect { fill: var(--card); stroke: var(--line); }
|
|
143
|
+
.chip text { font-size: 10px; font-weight: 700; letter-spacing: .04em; fill: var(--muted); text-transform: uppercase; }
|
|
144
|
+
.skel { fill: var(--card); stroke: var(--line); }
|
|
145
|
+
@media (prefers-reduced-motion: no-preference) { .skel { animation: pulse 1.2s ease-in-out infinite; } }
|
|
146
|
+
@keyframes pulse { 50% { opacity: .5; } }
|
|
147
|
+
#panel { padding: 10px 12px; border-top: 1px solid var(--line); background: var(--card); display: grid; gap: 8px; }
|
|
148
|
+
#panel[hidden] { display: none; }
|
|
149
|
+
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
|
69
150
|
.muted { color: var(--muted); }
|
|
70
|
-
#
|
|
71
|
-
#
|
|
151
|
+
#n-label { flex: 1 1 180px; min-width: 0; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
|
|
152
|
+
#n-config { width: 100%; min-height: 120px; max-height: 240px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
|
|
153
|
+
#n-errors { color: var(--err); background: var(--err-soft); border-radius: 6px; padding: 6px 8px; font-size: 12px; }
|
|
154
|
+
#n-errors[hidden] { display: none; }
|
|
155
|
+
#notice { font-size: 12px; color: var(--err); padding: 6px 12px; border-top: 1px solid var(--line); background: var(--err-soft); }
|
|
156
|
+
#notice.info { color: var(--muted); background: var(--card); }
|
|
157
|
+
#notice[hidden] { display: none; }
|
|
72
158
|
</style>
|
|
73
159
|
</head>
|
|
74
160
|
<body>
|
|
75
161
|
<header>
|
|
76
162
|
<h1 id="title">Loading workflow</h1>
|
|
77
163
|
<span class="pill" id="state" hidden></span>
|
|
78
|
-
<
|
|
164
|
+
<span class="pill bad" id="issues" hidden></span>
|
|
165
|
+
<button id="refresh" type="button">Reload</button>
|
|
79
166
|
<button id="full" type="button">Full screen</button>
|
|
80
167
|
<button id="open" type="button">Open in dashboard</button>
|
|
81
168
|
</header>
|
|
82
169
|
<div id="stage"><svg id="canvas" role="img" aria-label="Workflow graph"></svg></div>
|
|
83
|
-
<div id="
|
|
84
|
-
|
|
85
|
-
<div
|
|
86
|
-
<
|
|
87
|
-
|
|
88
|
-
<
|
|
170
|
+
<div id="notice" role="status" hidden></div>
|
|
171
|
+
<div id="panel" hidden>
|
|
172
|
+
<div class="row">
|
|
173
|
+
<input id="n-label" aria-label="Node name">
|
|
174
|
+
<span class="pill" id="n-type"></span>
|
|
175
|
+
<span class="muted" id="n-id"></span>
|
|
176
|
+
</div>
|
|
177
|
+
<div id="n-errors" hidden></div>
|
|
178
|
+
<textarea id="n-config" aria-label="Node settings (JSON)" spellcheck="false"></textarea>
|
|
179
|
+
<div class="row">
|
|
180
|
+
<button id="save" type="button">Save changes</button>
|
|
181
|
+
<button id="delete" type="button" class="danger">Delete node</button>
|
|
182
|
+
<button id="ask" type="button">Ask Claude about this node</button>
|
|
89
183
|
</div>
|
|
90
184
|
</div>
|
|
91
185
|
<script>
|
|
92
186
|
const readWorkflow = ${readWorkflow.toString()};
|
|
93
|
-
const
|
|
187
|
+
const editArgs = ${editArgs.toString()};
|
|
188
|
+
const errorText = ${errorText.toString()};
|
|
189
|
+
const ICONS = ${JSON.stringify(ICONS)};
|
|
190
|
+
// Card size and handles match the dashboard editor: inputs on top, outputs at the bottom.
|
|
191
|
+
const NODE_W = 220, NODE_H = 62, PAD = 40, MIN_SCALE = 0.7, FALLBACK_MS = 800;
|
|
94
192
|
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
95
193
|
const $ = (id) => document.getElementById(id);
|
|
96
|
-
const state = { wf: null, id: null, selected: null, busy: false };
|
|
194
|
+
const state = { wf: null, id: null, issues: [], selected: null, busy: false, dirty: false, dragging: false, redraw: false, form: null };
|
|
97
195
|
|
|
98
196
|
// JSON-RPC over postMessage to the host (MCP Apps protocol 2026-01-26).
|
|
99
197
|
let nextId = 1;
|
|
@@ -118,6 +216,8 @@ window.addEventListener("message", (event) => {
|
|
|
118
216
|
if (msg.method === "ui/notifications/tool-input") {
|
|
119
217
|
const id = msg.params && msg.params.arguments && msg.params.arguments.workflow_id;
|
|
120
218
|
if (typeof id === "number") state.id = id;
|
|
219
|
+
// Some hosts hand over the result late; load it ourselves instead of sitting empty.
|
|
220
|
+
setTimeout(() => { if (!state.wf) refresh(); }, FALLBACK_MS);
|
|
121
221
|
} else if (msg.method === "ui/notifications/tool-result") {
|
|
122
222
|
applyResult(msg.params);
|
|
123
223
|
} else if (msg.method === "ui/notifications/host-context-changed") {
|
|
@@ -135,42 +235,89 @@ function applyContext(ctx) {
|
|
|
135
235
|
if (ctx.displayMode) document.documentElement.dataset.mode = ctx.displayMode;
|
|
136
236
|
}
|
|
137
237
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
$("
|
|
238
|
+
// The bar under the canvas stays hidden unless something needs the user's attention.
|
|
239
|
+
function notice(text, kind) {
|
|
240
|
+
const el = $("notice");
|
|
241
|
+
el.hidden = !text;
|
|
242
|
+
el.textContent = text || "";
|
|
243
|
+
el.className = kind === "info" ? "info" : "";
|
|
141
244
|
}
|
|
142
245
|
|
|
143
|
-
|
|
144
|
-
return request("tools/call", { name, arguments: args });
|
|
145
|
-
}
|
|
246
|
+
function callTool(name, args) { return request("tools/call", { name, arguments: args }); }
|
|
146
247
|
|
|
147
248
|
async function refresh() {
|
|
148
249
|
if (state.id == null || state.busy) return;
|
|
149
|
-
state.busy = true;
|
|
150
|
-
try {
|
|
151
|
-
|
|
250
|
+
state.busy = true;
|
|
251
|
+
try {
|
|
252
|
+
const r = readWorkflow(await callTool("getWorkflow", { workflow_id: state.id }));
|
|
253
|
+
if (r.error) notice("Could not load the workflow: " + errorText(r.error));
|
|
254
|
+
else if (r.workflow) show(r.workflow, null);
|
|
255
|
+
} catch (e) { notice("Could not load the workflow: " + e.message); }
|
|
152
256
|
finally { state.busy = false; }
|
|
153
257
|
}
|
|
154
258
|
|
|
155
259
|
function applyResult(result) {
|
|
156
260
|
const r = readWorkflow(result || {});
|
|
157
|
-
if (r.error) {
|
|
261
|
+
if (r.error) { notice(errorText(r.error)); return; }
|
|
158
262
|
if (r.workflowId != null) state.id = r.workflowId;
|
|
159
263
|
if (!r.workflow) { refresh(); return; }
|
|
160
|
-
|
|
264
|
+
show(r.workflow, r.issues);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function show(wf, issues) {
|
|
268
|
+
state.wf = wf;
|
|
269
|
+
if (issues) state.issues = issues;
|
|
270
|
+
notice("");
|
|
161
271
|
render();
|
|
162
|
-
|
|
272
|
+
validate();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// getWorkflow carries no problems, so ask validateWorkflow which nodes to mark, like the dashboard does.
|
|
276
|
+
async function validate() {
|
|
277
|
+
try {
|
|
278
|
+
const r = readWorkflow(await callTool("validateWorkflow", { workflow_id: state.id }));
|
|
279
|
+
if (!r.error) { state.issues = r.issues; render(); }
|
|
280
|
+
} catch { /* the marks are a hint; the canvas works without them */ }
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function iconFor(type) {
|
|
284
|
+
if (type === "trigger" || type.endsWith("_trigger") || type.endsWith("_inbound")) return "zap";
|
|
285
|
+
if (type === "voice_ai" || type.includes("dialer")) return "phone";
|
|
286
|
+
if (type === "wait" || type === "wait_for_time" || type === "time_condition") return "clock";
|
|
287
|
+
if (type === "switch_condition" || type === "conditional") return "branch";
|
|
288
|
+
if (type.includes("email")) return "mail";
|
|
289
|
+
if (type === "custom_api") return "globe";
|
|
290
|
+
if (type === "code") return "braces";
|
|
291
|
+
if (type === "sub_workflow") return "workflow";
|
|
292
|
+
if (type.includes("whatsapp") || type.includes("sms") || type === "slack") return "message";
|
|
293
|
+
if (type === "ai_assistant" || type === "photo_analyzer") return "sparkles";
|
|
294
|
+
if (type.includes("contact") || type.includes("crm")) return "user";
|
|
295
|
+
if (type === "notes") return "note";
|
|
296
|
+
return "branch";
|
|
163
297
|
}
|
|
164
298
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
299
|
+
// Mirrors the subtitles the dashboard editor shows under each node name.
|
|
300
|
+
function subtitle(n) {
|
|
301
|
+
const c = n.config || {};
|
|
302
|
+
switch (n.type) {
|
|
303
|
+
case "trigger": return c.webhook_enabled ? "Webhook enabled" : "Configure webhook";
|
|
304
|
+
case "voice_ai": return c.bot_name || (c.bot_id ? "Agent " + c.bot_id : "Choose an agent");
|
|
305
|
+
case "wait": return (c.delay_seconds || 0) + " seconds";
|
|
306
|
+
case "whatsapp": return c.template_name || "Choose a template";
|
|
307
|
+
case "send_email": return c.email_to || "Configure email";
|
|
308
|
+
case "custom_api": return c.url || "Configure request";
|
|
309
|
+
case "switch_condition": return ((c.cases || []).length) + " cases + else";
|
|
310
|
+
case "time_condition": return "Time window";
|
|
311
|
+
case "code": return c.code ? "Python snippet" : "Write a snippet";
|
|
312
|
+
case "sub_workflow": return c.target_workflow_name || "Choose a workflow";
|
|
313
|
+
case "slack": return c.message ? String(c.message).slice(0, 60) : "Configure message";
|
|
314
|
+
default: return n.type;
|
|
315
|
+
}
|
|
172
316
|
}
|
|
173
317
|
|
|
318
|
+
// Workflow text is data, not instructions: one line, capped, quoted, before it goes into the chat.
|
|
319
|
+
function quoted(s) { return JSON.stringify(String(s).replace(/\\s+/g, " ").slice(0, 80)); }
|
|
320
|
+
|
|
174
321
|
function el(tag, attrs, text) {
|
|
175
322
|
const e = document.createElementNS(SVG_NS, tag);
|
|
176
323
|
for (const k in attrs) e.setAttribute(k, attrs[k]);
|
|
@@ -178,16 +325,62 @@ function el(tag, attrs, text) {
|
|
|
178
325
|
return e;
|
|
179
326
|
}
|
|
180
327
|
|
|
181
|
-
function clip(s, n) { return s.length > n ? s.slice(0, n - 1) + "
|
|
328
|
+
function clip(s, n) { s = String(s); return s.length > n ? s.slice(0, n - 1) + "…" : s; }
|
|
329
|
+
|
|
330
|
+
function ports(p) {
|
|
331
|
+
return { in: { x: p.x + NODE_W / 2, y: p.y }, out: { x: p.x + NODE_W / 2, y: p.y + NODE_H } };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Right-angle path with rounded corners, like React Flow's smoothstep edge.
|
|
335
|
+
function stepPath(a, b) {
|
|
336
|
+
const pts = [a];
|
|
337
|
+
if (b.y - a.y >= 40) { const m = (a.y + b.y) / 2; pts.push({ x: a.x, y: m }, { x: b.x, y: m }); }
|
|
338
|
+
else { const mx = (a.x + b.x) / 2; pts.push({ x: a.x, y: a.y + 20 }, { x: mx, y: a.y + 20 }, { x: mx, y: b.y - 20 }, { x: b.x, y: b.y - 20 }); }
|
|
339
|
+
pts.push(b);
|
|
340
|
+
let d = "M" + pts[0].x + "," + pts[0].y;
|
|
341
|
+
for (let i = 1; i < pts.length - 1; i++) {
|
|
342
|
+
const p = pts[i], prev = pts[i - 1], next = pts[i + 1];
|
|
343
|
+
const r = Math.min(6, Math.hypot(p.x - prev.x, p.y - prev.y) / 2, Math.hypot(next.x - p.x, next.y - p.y) / 2);
|
|
344
|
+
const ux = Math.sign(p.x - prev.x), uy = Math.sign(p.y - prev.y), vx = Math.sign(next.x - p.x), vy = Math.sign(next.y - p.y);
|
|
345
|
+
d += " L" + (p.x - ux * r) + "," + (p.y - uy * r) + " Q" + p.x + "," + p.y + " " + (p.x + vx * r) + "," + (p.y + vy * r);
|
|
346
|
+
}
|
|
347
|
+
d += " L" + b.x + "," + b.y;
|
|
348
|
+
const mid = pts[Math.floor(pts.length / 2)], mid2 = pts[Math.floor(pts.length / 2) - 1];
|
|
349
|
+
return { d, label: { x: (mid.x + mid2.x) / 2, y: (mid.y + mid2.y) / 2 } };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function drawEdges(layer) {
|
|
353
|
+
layer.replaceChildren();
|
|
354
|
+
const pos = {};
|
|
355
|
+
for (const n of state.wf.draft.nodes) pos[n.id] = n.position;
|
|
356
|
+
for (const e of state.wf.draft.edges) {
|
|
357
|
+
const a = pos[e.from], b = pos[e.to];
|
|
358
|
+
if (!a || !b) continue;
|
|
359
|
+
const s = stepPath(ports(a).out, ports(b).in);
|
|
360
|
+
layer.append(el("path", { class: "edge", d: s.d, "marker-end": "url(#arrow)" }));
|
|
361
|
+
if (e.handle && e.handle !== "default") {
|
|
362
|
+
const text = clip(e.handle, 18), w = text.length * 6.4 + 14;
|
|
363
|
+
const chip = el("g", { class: "chip", transform: "translate(" + (s.label.x - w / 2) + "," + (s.label.y - 9) + ")" });
|
|
364
|
+
chip.append(el("rect", { width: w, height: 18, rx: 5 }), el("text", { x: 7, y: 12.5 }, text));
|
|
365
|
+
layer.append(chip);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function errorsFor(id) { return state.issues.filter((i) => i.node === id); }
|
|
182
371
|
|
|
183
372
|
function render() {
|
|
373
|
+
if (!state.wf) return;
|
|
374
|
+
// Redrawing replaces the node under the pointer and kills the drag, so wait for the drop.
|
|
375
|
+
if (state.dragging) { state.redraw = true; return; }
|
|
184
376
|
const wf = state.wf, draft = wf.draft, svg = $("canvas");
|
|
185
377
|
$("title").textContent = wf.name || "Workflow " + wf.id;
|
|
186
378
|
$("state").hidden = false;
|
|
187
|
-
$("state").textContent = (wf.status || "draft") + "
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
379
|
+
$("state").textContent = (wf.status || "draft") + " · " + draft.nodes.length + " nodes";
|
|
380
|
+
$("issues").hidden = !state.issues.length;
|
|
381
|
+
$("issues").textContent = state.issues.length + (state.issues.length === 1 ? " problem" : " problems");
|
|
382
|
+
draft.nodes.forEach((n, i) => { if (!n.position) n.position = { x: i * 260, y: 0 }; });
|
|
383
|
+
const xs = draft.nodes.map((n) => n.position.x), ys = draft.nodes.map((n) => n.position.y);
|
|
191
384
|
const minX = Math.min(...xs, 0) - PAD, minY = Math.min(...ys, 0) - PAD;
|
|
192
385
|
const w = Math.max(...xs, 0) + NODE_W + PAD - minX, h = Math.max(...ys, 0) + NODE_H + PAD - minY;
|
|
193
386
|
const avail = $("stage").clientWidth || 600;
|
|
@@ -196,35 +389,40 @@ function render() {
|
|
|
196
389
|
svg.setAttribute("width", Math.round(w * scale));
|
|
197
390
|
svg.setAttribute("height", Math.round(h * scale));
|
|
198
391
|
svg.replaceChildren();
|
|
199
|
-
|
|
200
|
-
const edges = el("g", {});
|
|
201
|
-
for (const e of draft.edges) {
|
|
202
|
-
const a = pos[e.from], b = pos[e.to];
|
|
203
|
-
if (!a || !b) continue;
|
|
204
|
-
const x1 = a.x + NODE_W, y1 = a.y + NODE_H / 2, x2 = b.x, y2 = b.y + NODE_H / 2, dx = Math.max(40, (x2 - x1) / 2);
|
|
205
|
-
edges.append(el("path", { class: "edge", d: "M" + x1 + "," + y1 + " C" + (x1 + dx) + "," + y1 + " " + (x2 - dx) + "," + y2 + " " + x2 + "," + y2, "marker-end": "url(#arrow)" }));
|
|
206
|
-
if (e.handle && e.handle !== "default") {
|
|
207
|
-
edges.append(el("text", { class: "handle-label", x: x2 - 8, y: y2 - 8, "text-anchor": "end" }, e.handle));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
392
|
const defs = el("defs", {});
|
|
211
|
-
const marker = el("marker", { id: "arrow", viewBox: "0 0 10 10", refX: "
|
|
393
|
+
const marker = el("marker", { id: "arrow", viewBox: "0 0 10 10", refX: "8", refY: "5", markerWidth: "6", markerHeight: "6", orient: "auto-start-reverse" });
|
|
212
394
|
marker.append(el("path", { d: "M0,0 L10,5 L0,10 z", fill: "var(--edge)" }));
|
|
213
395
|
defs.append(marker);
|
|
396
|
+
const edges = el("g", {});
|
|
214
397
|
svg.append(defs, edges);
|
|
398
|
+
drawEdges(edges);
|
|
215
399
|
|
|
216
400
|
for (const n of draft.nodes) {
|
|
217
|
-
const
|
|
218
|
-
const
|
|
401
|
+
const bad = errorsFor(n.id).length > 0;
|
|
402
|
+
const cls = "node" + (state.selected === n.id ? " selected" : "") + (bad ? " invalid" : "");
|
|
403
|
+
const g = el("g", { class: cls, transform: "translate(" + n.position.x + "," + n.position.y + ")", tabindex: "0", role: "button", "aria-label": (n.label || n.id) + ", " + n.type + (bad ? ", has problems" : "") });
|
|
219
404
|
g.append(el("rect", { class: "card", width: NODE_W, height: NODE_H, rx: 8 }));
|
|
220
|
-
g.append(el("rect", {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
g.
|
|
405
|
+
g.append(el("rect", { class: "icon-box", x: 10, y: 10, width: 24, height: 24, rx: 6 }));
|
|
406
|
+
const icon = el("g", { class: "icon", transform: "translate(15,15) scale(0.5833)" });
|
|
407
|
+
icon.innerHTML = ICONS[iconFor(n.type)];
|
|
408
|
+
g.append(icon);
|
|
409
|
+
g.append(el("text", { class: "label", x: 42, y: 26.5 }, clip(n.label || n.id, 23)));
|
|
410
|
+
g.append(el("text", { class: "sub", x: 12, y: NODE_H - 12 }, clip(subtitle(n), 31)));
|
|
411
|
+
const pt = ports({ x: 0, y: 0 });
|
|
412
|
+
if (!n.type.endsWith("trigger") && !n.type.endsWith("_inbound")) g.append(el("circle", { class: "handle", cx: pt.in.x, cy: pt.in.y, r: 4 }));
|
|
413
|
+
g.append(el("circle", { class: "handle", cx: pt.out.x, cy: pt.out.y, r: 4 }));
|
|
414
|
+
g.addEventListener("pointerdown", (ev) => startDrag(ev, n, g, edges));
|
|
224
415
|
g.addEventListener("keydown", (ev) => { if (ev.key === "Enter" || ev.key === " ") { ev.preventDefault(); select(n.id); } });
|
|
225
416
|
svg.append(g);
|
|
226
417
|
}
|
|
227
|
-
|
|
418
|
+
showPanel();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function placeholder() {
|
|
422
|
+
const svg = $("canvas");
|
|
423
|
+
svg.setAttribute("viewBox", "0 0 600 240"); svg.setAttribute("width", 600); svg.setAttribute("height", 240);
|
|
424
|
+
svg.replaceChildren();
|
|
425
|
+
[[40, 90], [320, 30], [320, 150]].forEach(([x, y]) => svg.append(el("rect", { class: "skel", x, y, width: 220, height: 62, rx: 8 })));
|
|
228
426
|
}
|
|
229
427
|
|
|
230
428
|
function toSvg(ev) {
|
|
@@ -233,67 +431,137 @@ function toSvg(ev) {
|
|
|
233
431
|
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
234
432
|
}
|
|
235
433
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
434
|
+
// The drag is tracked on the whole document, not the node: a release outside the chat's
|
|
435
|
+
// frame never reaches the frame, so leaving the frame (or a move with no button held) drops the node there.
|
|
436
|
+
function startDrag(ev, node, g, edges) {
|
|
437
|
+
// One drag at a time, primary pointer only: a second finger must not start a drag nobody saves.
|
|
438
|
+
if (state.busy || state.dragging || ev.button !== 0 || !ev.isPrimary) return;
|
|
439
|
+
const start = toSvg(ev), origin = { x: node.position.x, y: node.position.y };
|
|
239
440
|
let moved = false;
|
|
240
|
-
|
|
441
|
+
state.dragging = true;
|
|
241
442
|
const move = (e) => {
|
|
443
|
+
if (e.buttons === 0) return up();
|
|
242
444
|
const cur = toSvg(e), dx = cur.x - start.x, dy = cur.y - start.y;
|
|
243
445
|
if (!moved && Math.hypot(dx, dy) < 4) return;
|
|
244
446
|
moved = true; g.classList.add("dragging");
|
|
245
|
-
|
|
246
|
-
g.setAttribute("transform", "translate(" +
|
|
447
|
+
node.position = { x: Math.round(origin.x + dx), y: Math.round(origin.y + dy) };
|
|
448
|
+
g.setAttribute("transform", "translate(" + node.position.x + "," + node.position.y + ")");
|
|
449
|
+
drawEdges(edges);
|
|
247
450
|
};
|
|
248
451
|
const up = () => {
|
|
249
|
-
|
|
250
|
-
|
|
452
|
+
document.removeEventListener("pointermove", move);
|
|
453
|
+
document.removeEventListener("pointerup", up);
|
|
454
|
+
document.documentElement.removeEventListener("pointerleave", up);
|
|
455
|
+
window.removeEventListener("blur", up);
|
|
251
456
|
g.classList.remove("dragging");
|
|
457
|
+
if (!state.dragging) return;
|
|
458
|
+
state.dragging = false;
|
|
459
|
+
if (state.redraw) { state.redraw = false; render(); }
|
|
252
460
|
if (!moved) { select(node.id); return; }
|
|
253
|
-
|
|
461
|
+
if (node.position.x === origin.x && node.position.y === origin.y) return;
|
|
462
|
+
save([{ op: "move_node", id: node.id, position: node.position }], "moved node " + quoted(node.id), () => { node.position = origin; });
|
|
254
463
|
};
|
|
255
|
-
|
|
256
|
-
|
|
464
|
+
document.addEventListener("pointermove", move);
|
|
465
|
+
document.addEventListener("pointerup", up);
|
|
466
|
+
document.documentElement.addEventListener("pointerleave", up);
|
|
467
|
+
window.addEventListener("blur", up);
|
|
257
468
|
}
|
|
258
469
|
|
|
259
|
-
|
|
260
|
-
|
|
470
|
+
// Every edit sends the draft revision, so a stale edit is refused instead of overwriting Claude's.
|
|
471
|
+
async function save(ops, what, rollback, button) {
|
|
472
|
+
if (!state.wf) return false;
|
|
473
|
+
if (state.busy) { if (rollback) rollback(); render(); notice("Still loading the workflow. Try again in a moment."); return false; }
|
|
474
|
+
state.busy = true;
|
|
475
|
+
if (button) { button.disabled = true; button.dataset.text = button.textContent; button.textContent = "Saving…"; }
|
|
476
|
+
let ok = false;
|
|
261
477
|
try {
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
notify("ui/update-model-context", { content: [{ type: "text", text: "The user moved node \\"" + node.id + "\\" on workflow " + state.id + " in the canvas. Call getWorkflow for the new revision before your next edit." }] });
|
|
478
|
+
const r = readWorkflow(await callTool("editWorkflow", editArgs(state.id, state.wf.draft.revision, ops)) || {});
|
|
479
|
+
if (r.error) throw new Error(errorText(r.error));
|
|
480
|
+
ok = true;
|
|
481
|
+
notify("ui/update-model-context", { content: [{ type: "text", text: "In the workflow canvas the user " + what + " on workflow " + state.id + ". Call getWorkflow for the new revision before your next edit." }] });
|
|
267
482
|
} catch (e) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
483
|
+
if (rollback) rollback();
|
|
484
|
+
notice("Not saved: " + e.message);
|
|
485
|
+
} finally {
|
|
486
|
+
state.busy = false;
|
|
487
|
+
if (button) { button.disabled = false; button.textContent = button.dataset.text; }
|
|
271
488
|
}
|
|
272
|
-
|
|
489
|
+
const failure = ok ? "" : $("notice").textContent;
|
|
273
490
|
await refresh();
|
|
491
|
+
if (!ok) notice(failure);
|
|
492
|
+
return ok;
|
|
274
493
|
}
|
|
275
494
|
|
|
276
495
|
function select(id) {
|
|
277
496
|
state.selected = id;
|
|
497
|
+
state.dirty = false;
|
|
278
498
|
render();
|
|
279
499
|
const n = state.wf.draft.nodes.find((x) => x.id === id);
|
|
280
|
-
|
|
500
|
+
if (!n) return;
|
|
501
|
+
notify("ui/update-model-context", { content: [{ type: "text", text: "In the workflow canvas the user selected node " + quoted(id) + " (type " + quoted(n.type) + ") on workflow " + state.id + "." }] });
|
|
281
502
|
}
|
|
282
503
|
|
|
283
|
-
function
|
|
284
|
-
|
|
285
|
-
$("
|
|
286
|
-
|
|
504
|
+
function showPanel() {
|
|
505
|
+
const n = state.selected && state.wf.draft.nodes.find((x) => x.id === state.selected);
|
|
506
|
+
$("panel").hidden = !n;
|
|
507
|
+
if (!n) return;
|
|
508
|
+
if (state.dirty && $("panel").dataset.node === n.id) return;
|
|
509
|
+
$("panel").dataset.node = n.id;
|
|
510
|
+
state.dirty = false;
|
|
511
|
+
// What the form was loaded with: the base for working out what the user changed.
|
|
512
|
+
state.form = { id: n.id, label: n.label || "", config: JSON.parse(JSON.stringify(n.config || {})) };
|
|
513
|
+
$("n-label").value = n.label || "";
|
|
287
514
|
$("n-type").textContent = n.type;
|
|
288
515
|
$("n-id").textContent = "id " + n.id;
|
|
289
|
-
$("n-config").
|
|
516
|
+
$("n-config").value = n.config ? JSON.stringify(n.config, null, 2) : "{}";
|
|
517
|
+
const errs = errorsFor(n.id);
|
|
518
|
+
$("n-errors").hidden = !errs.length;
|
|
519
|
+
$("n-errors").textContent = errs.map((e) => e.message).join(" ");
|
|
520
|
+
$("delete").textContent = "Delete node";
|
|
521
|
+
document.documentElement.style.setProperty("--panel-h", $("panel").offsetHeight + "px");
|
|
290
522
|
}
|
|
291
523
|
|
|
524
|
+
// Typed but unsaved settings survive the refresh that follows a move or another save.
|
|
525
|
+
for (const id of ["n-label", "n-config"]) $(id).addEventListener("input", () => { state.dirty = true; });
|
|
526
|
+
|
|
527
|
+
// Sends only what the user changed since the form loaded. If Claude changed the same field in the
|
|
528
|
+
// meantime the save is refused, so neither edit silently overwrites the other.
|
|
529
|
+
$("save").addEventListener("click", () => {
|
|
530
|
+
const n = state.wf && state.wf.draft.nodes.find((x) => x.id === state.selected);
|
|
531
|
+
const base = state.form;
|
|
532
|
+
if (!n || !base || base.id !== n.id) return;
|
|
533
|
+
let config;
|
|
534
|
+
try { config = JSON.parse($("n-config").value || "{}"); }
|
|
535
|
+
catch { notice("The settings are not valid JSON. Fix them and save again."); return; }
|
|
536
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) { notice('The settings must be a JSON object, like {"key": "value"}.'); return; }
|
|
537
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
538
|
+
const now = n.config || {}, op = { op: "update_node", id: n.id }, changed = Object.create(null), clash = [];
|
|
539
|
+
for (const k of Object.keys(config)) if (k !== "__proto__" && !same(config[k], base.config[k])) changed[k] = config[k];
|
|
540
|
+
for (const k of Object.keys(base.config)) if (!(k in config)) changed[k] = null;
|
|
541
|
+
for (const k of Object.keys(changed)) if (!same(now[k], base.config[k])) clash.push(k);
|
|
542
|
+
const label = $("n-label").value.trim();
|
|
543
|
+
if (label && label !== base.label) {
|
|
544
|
+
if ((n.label || "") !== base.label) clash.push("name");
|
|
545
|
+
op.label = label;
|
|
546
|
+
}
|
|
547
|
+
if (clash.length) { notice("Claude changed " + clash.join(", ") + " on this node while you were editing. Select the node again to load its version, then redo your change."); return; }
|
|
548
|
+
if (Object.keys(changed).length) op.config = changed;
|
|
549
|
+
if (!op.label && !op.config) { notice("Nothing changed.", "info"); return; }
|
|
550
|
+
save([op], "edited node " + quoted(n.id), null, $("save")).then((ok) => { if (ok) { state.dirty = false; showPanel(); } });
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
$("delete").addEventListener("click", () => {
|
|
554
|
+
const btn = $("delete"), id = state.selected;
|
|
555
|
+
if (!id) return;
|
|
556
|
+
if (btn.textContent !== "Click again to delete") { btn.textContent = "Click again to delete"; return; }
|
|
557
|
+
save([{ op: "delete_node", id }], "deleted node " + quoted(id), null, btn).then((ok) => { if (ok) { state.selected = null; render(); } });
|
|
558
|
+
});
|
|
559
|
+
|
|
292
560
|
$("refresh").addEventListener("click", refresh);
|
|
293
561
|
$("full").addEventListener("click", async () => {
|
|
294
562
|
const mode = document.documentElement.dataset.mode === "fullscreen" ? "inline" : "fullscreen";
|
|
295
563
|
try { const r = await request("ui/request-display-mode", { mode }); applyContext({ displayMode: r && r.mode }); render(); }
|
|
296
|
-
catch (e) {
|
|
564
|
+
catch (e) { notice("Full screen is not available here."); }
|
|
297
565
|
});
|
|
298
566
|
$("open").addEventListener("click", () => {
|
|
299
567
|
if (state.id != null) request("ui/open-link", { url: "https://omnidim.io/workflow/" + state.id }).catch(() => {});
|
|
@@ -301,20 +569,24 @@ $("open").addEventListener("click", () => {
|
|
|
301
569
|
$("ask").addEventListener("click", () => {
|
|
302
570
|
const n = state.wf && state.wf.draft.nodes.find((x) => x.id === state.selected);
|
|
303
571
|
if (!n) return;
|
|
304
|
-
request("ui/message", { role: "user", content: [{ type: "text", text: "In workflow " + state.id + ", explain the
|
|
572
|
+
request("ui/message", { role: "user", content: [{ type: "text", text: "In workflow " + state.id + ", explain the node with id " + quoted(n.id) + " (type " + quoted(n.type) + ", named " + quoted(n.label || n.id) + ") and check its settings for problems." }] }).catch(() => notice("Could not send the message to the chat."));
|
|
305
573
|
});
|
|
306
574
|
|
|
307
575
|
new ResizeObserver(() => notify("ui/notifications/size-changed", { width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight })).observe(document.body);
|
|
308
576
|
|
|
577
|
+
placeholder();
|
|
309
578
|
request("ui/initialize", {
|
|
310
579
|
protocolVersion: "2026-01-26",
|
|
311
|
-
appInfo: { name: "omnidim-workflow-canvas", version: "0.
|
|
580
|
+
appInfo: { name: "omnidim-workflow-canvas", version: "0.2.0" },
|
|
312
581
|
appCapabilities: { availableDisplayModes: ["inline", "fullscreen"] },
|
|
313
582
|
}).then((r) => {
|
|
314
583
|
applyContext(r && r.hostContext);
|
|
315
584
|
notify("ui/notifications/initialized", {});
|
|
316
|
-
}).catch((
|
|
585
|
+
}).catch(() => notice("This chat app could not open the canvas."));
|
|
317
586
|
</script>
|
|
318
587
|
</body>
|
|
319
588
|
</html>
|
|
320
589
|
`;
|
|
590
|
+
|
|
591
|
+
// Chat apps cache a view by its address, so a changed page needs a new address or users keep the old one.
|
|
592
|
+
export const WORKFLOW_CANVAS_URI = `${LEGACY_CANVAS_URI}/${createHash("sha256").update(WORKFLOW_CANVAS_HTML).digest("hex").slice(0, 12)}`;
|