agent-lyra 0.7.0 → 0.10.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.
Files changed (126) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +301 -276
  3. package/bin/agent-lyra.js +51 -51
  4. package/bin/lyra-oss-preview.js +16 -16
  5. package/package.json +60 -60
  6. package/src/app-builder/export.js +109 -109
  7. package/src/app-builder/gateway.js +62 -62
  8. package/src/app-builder/init.js +115 -72
  9. package/src/app-builder/manifest-contract.js +46 -46
  10. package/src/app-builder/native-adapter.js +29 -29
  11. package/src/app-builder/preview.js +35 -31
  12. package/src/app-builder/publish.js +14 -14
  13. package/src/app-builder/saved-app.js +70 -70
  14. package/src/app-builder/saved-preview-browser.js +33 -33
  15. package/src/app-builder/saved-preview.html +24 -24
  16. package/src/app-builder/saved-preview.js +61 -61
  17. package/src/app-builder/support-manifest.js +50 -50
  18. package/src/app-builder/support-template/manifest.json +55 -55
  19. package/src/app-builder/support-template/support-preview.html +56 -56
  20. package/src/app-builder/support-template/support-preview.js +37 -37
  21. package/src/app-builder/support-template/support-preview.mjs +67 -67
  22. package/src/app-builder/support-template/support-workflow.mjs +36 -36
  23. package/src/app-builder/use.js +37 -37
  24. package/src/app-builder/validate.js +31 -21
  25. package/src/app-builder/value-schema.js +37 -37
  26. package/src/catalog.js +147 -147
  27. package/src/coding/catalog.js +56 -56
  28. package/src/coding/cloud-catalog.js +64 -64
  29. package/src/coding/detect-stack.mjs +110 -110
  30. package/src/coding/export.js +133 -133
  31. package/src/coding/setup.js +175 -175
  32. package/src/coding/skills/lyra-android/SKILL.md +37 -37
  33. package/src/coding/skills/lyra-angular/SKILL.md +37 -37
  34. package/src/coding/skills/lyra-cucumber/SKILL.md +37 -37
  35. package/src/coding/skills/lyra-dbt/SKILL.md +37 -37
  36. package/src/coding/skills/lyra-django/SKILL.md +37 -37
  37. package/src/coding/skills/lyra-docker/SKILL.md +37 -37
  38. package/src/coding/skills/lyra-dotnet/SKILL.md +37 -37
  39. package/src/coding/skills/lyra-express/SKILL.md +37 -37
  40. package/src/coding/skills/lyra-fastapi/SKILL.md +37 -37
  41. package/src/coding/skills/lyra-flutter/SKILL.md +37 -37
  42. package/src/coding/skills/lyra-github-actions/SKILL.md +37 -37
  43. package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -37
  44. package/src/coding/skills/lyra-go/SKILL.md +37 -37
  45. package/src/coding/skills/lyra-ios/SKILL.md +37 -37
  46. package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -37
  47. package/src/coding/skills/lyra-mongodb/SKILL.md +37 -37
  48. package/src/coding/skills/lyra-mysql/SKILL.md +37 -37
  49. package/src/coding/skills/lyra-nextjs/SKILL.md +37 -37
  50. package/src/coding/skills/lyra-node/SKILL.md +37 -37
  51. package/src/coding/skills/lyra-playwright/SKILL.md +37 -37
  52. package/src/coding/skills/lyra-postgresql/SKILL.md +37 -37
  53. package/src/coding/skills/lyra-python/SKILL.md +37 -37
  54. package/src/coding/skills/lyra-react/SKILL.md +37 -37
  55. package/src/coding/skills/lyra-react-native/SKILL.md +37 -37
  56. package/src/coding/skills/lyra-redis/SKILL.md +37 -37
  57. package/src/coding/skills/lyra-rust/SKILL.md +37 -37
  58. package/src/coding/skills/lyra-spark/SKILL.md +37 -37
  59. package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -37
  60. package/src/coding/skills/lyra-svelte/SKILL.md +37 -37
  61. package/src/coding/skills/lyra-terraform/SKILL.md +37 -37
  62. package/src/coding/skills/lyra-typescript/SKILL.md +37 -37
  63. package/src/coding/skills/lyra-vue/SKILL.md +37 -37
  64. package/src/framework/agent.js +181 -173
  65. package/src/framework/mda.js +65 -0
  66. package/src/framework/run.py +111 -111
  67. package/src/gated/hostedAgents.js +56 -56
  68. package/src/gated/index.d.ts +25 -25
  69. package/src/gated/index.js +5 -5
  70. package/src/index.d.ts +2 -2
  71. package/src/index.js +2 -2
  72. package/src/init.js +960 -960
  73. package/src/intelligence/graphsnip-provider.d.ts +5 -5
  74. package/src/intelligence/graphsnip-provider.js +57 -57
  75. package/src/intelligence/lifecycle.js +25 -0
  76. package/src/memory/LICENSE +21 -21
  77. package/src/memory/README.md +5 -5
  78. package/src/memory/UPSTREAM.json +24 -14
  79. package/src/memory/bridge-cli.js +16 -16
  80. package/src/memory/bridge.js +18 -18
  81. package/src/memory/cli.js +21 -21
  82. package/src/memory/cloud-sync-actions.js +61 -61
  83. package/src/memory/contract.json +45 -45
  84. package/src/memory/index.d.ts +50 -49
  85. package/src/memory/index.js +7 -7
  86. package/src/memory/lifecycle.js +29 -29
  87. package/src/memory/local-cli.js +34 -34
  88. package/src/memory/local-store.js +209 -209
  89. package/src/memory/package.json +33 -33
  90. package/src/memory/proposals.js +90 -90
  91. package/src/memory/skills-cli.js +26 -26
  92. package/src/memory/standalone.d.ts +50 -50
  93. package/src/memory/standalone.js +1 -1
  94. package/src/memory/sync.js +89 -89
  95. package/src/memory/validation.js +25 -25
  96. package/src/onboardingAgents.js +532 -532
  97. package/src/promptTemplates.js +178 -178
  98. package/src/resource-files.js +18 -18
  99. package/src/runtime/contracts.d.ts +47 -47
  100. package/src/runtime/local-cli.js +161 -160
  101. package/src/runtime/mcp-stdio.js +111 -111
  102. package/src/runtime/orchestration.js +59 -59
  103. package/src/runtime/run-agent.js +54 -53
  104. package/src/standalone/index.d.ts +45 -45
  105. package/src/standalone/index.js +13 -13
  106. package/src/standalone/init.js +12 -12
  107. package/src/standalone/orchestration.js +6 -6
  108. package/src/standalone/rag.js +113 -113
  109. package/src/studio/agent-ui.css +43 -43
  110. package/src/studio/agent-ui.js +32 -32
  111. package/src/studio/browser.js +542 -345
  112. package/src/studio/export.js +83 -85
  113. package/src/studio/index.html +74 -37
  114. package/src/studio/memory-actions.js +37 -37
  115. package/src/studio/memory-panel.js +200 -200
  116. package/src/studio/project.js +308 -240
  117. package/src/studio/pull-agent.js +72 -72
  118. package/src/studio/push.js +54 -54
  119. package/src/studio/python-agent.js +47 -47
  120. package/src/studio/python-agent.py +25 -25
  121. package/src/studio/server.js +164 -150
  122. package/src/studio/session.js +83 -83
  123. package/src/studio/studio.css +257 -10
  124. package/src/studio/sync.js +42 -42
  125. package/src/studio/workflow-editor.js +240 -0
  126. package/src/studio/workflow-sync.js +229 -157
@@ -1,345 +1,542 @@
1
- import { mountMemoryPanel } from "./memory-panel.js";
2
- import { renderAgentCard, renderRunHeader } from "./agent-ui.js";
3
-
4
- const $ = selector => document.querySelector(selector);
5
- const element = (tag, text) => Object.assign(document.createElement(tag), text === undefined ? {} : { textContent: text });
6
- function dom(tag, props, ...children) {
7
- const node = document.createElement(tag);
8
- for (const [key, value] of Object.entries(props)) {
9
- if (value == null) continue;
10
- if (key === "onClick") node.onclick = value;
11
- else if (key === "aria-label") node.setAttribute(key, value);
12
- else node[key] = value;
13
- }
14
- node.append(...children.filter(child => child != null && child !== false && child !== ""));
15
- return node;
16
- }
17
-
18
- const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent", framework: "Registered framework agent" };
19
- const names = { heading:"Heading", text:"Text", input:"Text input", textarea:"Text area", button:"Run button", "agent-card":"Agent card", output:"Output" };
20
- let project = { layout: [], agents: [], workflows: [], teams: [], skills: [], models: [] };
21
- let selected, pending;
22
- let dirty = false;
23
- const values = new Map();
24
- const outputs = new Map();
25
-
26
- function button(text, click) {
27
- const control = element("button", text);
28
- control.type = "button";
29
- control.onclick = click;
30
- return control;
31
- }
32
-
33
- async function api(path, data) {
34
- const response = await fetch("/api/" + path, data === undefined ? {} : {
35
- method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data),
36
- });
37
- const payload = await response.json();
38
- if (!response.ok) throw new Error(payload.error);
39
- return payload;
40
- }
41
-
42
- mountMemoryPanel(api);
43
-
44
- function announce(message) { $("#status").textContent = message; }
45
- function change() { dirty = true; renderCanvas(); renderInspector(); }
46
-
47
- function add(kind) {
48
- if (!Object.hasOwn(names, kind) || project.layout.length >= 60) return;
49
- const node = { id: crypto.randomUUID(), kind, label: names[kind] };
50
- if (["button", "agent-card"].includes(kind)) node.targets = [];
51
- project.layout.push(node);
52
- selected = node.id;
53
- change();
54
- }
55
-
56
- function move(node, offset) {
57
- const index = project.layout.indexOf(node);
58
- const next = index + offset;
59
- if (next < 0 || next >= project.layout.length) return;
60
- [project.layout[index], project.layout[next]] = [project.layout[next], node];
61
- change();
62
- }
63
-
64
- function renderCanvas() {
65
- const canvas = $("#canvas");
66
- canvas.replaceChildren();
67
- if (!project.layout.length) canvas.append(element("p", "Your canvas is empty."));
68
- for (const node of project.layout) {
69
- const card = element("div");
70
- card.className = "node" + (node.id === selected ? " selected" : "");
71
- const select = button("Edit " + names[node.kind], () => { selected = node.id; renderCanvas(); renderInspector(); });
72
- if (!project.exported) card.append(select);
73
- if (node.kind === "heading" || node.kind === "text") card.append(element(node.kind === "heading" ? "h2" : "p", node.label));
74
- if (["input", "textarea"].includes(node.kind)) {
75
- const id = "component-" + node.id;
76
- const label = element("label", node.label);
77
- label.htmlFor = id;
78
- const input = element(node.kind);
79
- input.id = id;
80
- input.maxLength = 4000;
81
- input.value = values.get(node.id) ?? "";
82
- input.oninput = () => values.set(node.id, input.value);
83
- card.append(label, input);
84
- }
85
- if (node.kind === "output") card.append(element("h2", node.label), element("pre", outputs.get(node.id) ?? "Run a workflow to see a result."));
86
- if (node.kind === "agent-card") {
87
- const agent = project.agents.find(item => item.id === node.targets[0]);
88
- card.append(renderAgentCard(dom, {
89
- name: node.label, source: agent ? agentSources[agent.source] : "Choose an agent in the inspector",
90
- onRun: agent ? () => openRun(node.targets, values.get(node.sourceId) ?? "", node.outputId, node.id) : undefined,
91
- }));
92
- }
93
- if (node.kind === "button") {
94
- const trigger = button(node.label, () => {
95
- if (!node.targets.length) return announce("Assign an agent or workflow in the inspector first.");
96
- openRun(node.targets, values.get(node.sourceId) ?? "", node.outputId, node.id);
97
- });
98
- if (!node.targets.length) trigger.title = "Assign a target in the inspector";
99
- trigger.className = "primary";
100
- card.append(trigger);
101
- }
102
- canvas.append(card);
103
- }
104
- }
105
-
106
- function addSelect(parent, label, choices, value, onChange) {
107
- const wrap = element("label", label);
108
- const select = element("select");
109
- for (const [id, title] of choices) select.add(new Option(title, id));
110
- select.value = value ?? "";
111
- select.onchange = () => onChange(select.value);
112
- wrap.append(select);
113
- parent.append(wrap);
114
- return select;
115
- }
116
-
117
- function labelFor(id) {
118
- return project.agents.find(agent => agent.id === id)?.name ??
119
- project.workflows.find(workflow => "workflow:" + workflow.id === id)?.name ?? id;
120
- }
121
-
122
- function renderInspector() {
123
- const box = $("#inspector");
124
- box.replaceChildren();
125
- const node = project.layout.find(item => item.id === selected);
126
- if (!node) { box.append(element("p", "Select a component to configure it.")); return; }
127
-
128
- const label = element("label", "Label");
129
- const field = element("input");
130
- field.value = node.label;
131
- field.maxLength = 160;
132
- field.oninput = () => { node.label = field.value; dirty = true; renderCanvas(); };
133
- label.append(field);
134
- const actions = element("div");
135
- actions.className = "actions";
136
- actions.append(button("Move up", () => move(node, -1)), button("Move down", () => move(node, 1)), button("Remove", () => {
137
- project.layout = project.layout.filter(item => item !== node);
138
- for (const item of project.layout) {
139
- if (item.sourceId === node.id) item.sourceId = "";
140
- if (item.outputId === node.id) item.outputId = "";
141
- }
142
- selected = null;
143
- change();
144
- }));
145
- box.append(label, actions);
146
- if (!["button", "agent-card"].includes(node.kind)) return;
147
-
148
- const fields = project.layout.filter(item => ["input", "textarea"].includes(item.kind));
149
- const results = project.layout.filter(item => item.kind === "output");
150
- addSelect(box, "Input component", [["", "Enter in run drawer"], ...fields.map(item => [item.id, item.label])], node.sourceId, id => {
151
- node.sourceId = id; dirty = true;
152
- });
153
- addSelect(box, "Output component", [["", "Show in run drawer"], ...results.map(item => [item.id, item.label])], node.outputId, id => {
154
- node.outputId = id; dirty = true;
155
- });
156
- if (node.kind === "agent-card") {
157
- addSelect(box, "Agent", [["", "Choose an agent"], ...project.agents.map(agent => [agent.id, agent.name])], node.targets[0], id => {
158
- if (node.label === names["agent-card"] || node.label === labelFor(node.targets[0])) {
159
- node.label = id ? labelFor(id) : names["agent-card"];
160
- }
161
- node.targets = id ? [id] : [];
162
- change();
163
- });
164
- return;
165
- }
166
- box.append(element("h2", "Run order"));
167
- node.targets.forEach((target, index) => {
168
- const row = element("div", labelFor(target));
169
- row.className = "binding";
170
- row.append(button("Remove", () => { node.targets.splice(index, 1); change(); }));
171
- box.append(row);
172
- });
173
- const options = [
174
- ...project.agents.map(agent => [agent.id, agent.name]),
175
- ...project.workflows.filter(item => item.runnable).map(item => ["workflow:" + item.id, item.name + " (workflow)"]),
176
- ];
177
- addSelect(box, "Add next step", [["", "Choose agent or workflow"], ...options], "", id => {
178
- if (id && node.targets.length < 8) { node.targets.push(id); change(); }
179
- });
180
- }
181
-
182
- function renderCatalog() {
183
- for (const [id, rows] of [["agents", project.agents], ["workflows", project.workflows], ["teams", project.teams], ["skills", project.skills]]) {
184
- const section = $("#" + id);
185
- section.replaceChildren();
186
- if (!rows.length) section.append(element("p", "None in this project."));
187
- if (id === "agents" && project.frameworkCandidates?.length) {
188
- section.append(element("p", "LangGraph candidates: " + project.frameworkCandidates.map(item => item.name).join(", ") +
189
- ". Run agent-lyra agent discover, then register the entry you want."));
190
- }
191
- for (const row of rows) {
192
- if (id === "agents") {
193
- const push = row.source === "local" && project.mode !== "standalone"
194
- ? button("Push to Cloud", async () => {
195
- if (!window.confirm("Send the name and instructions for " + row.name + " to your private AgentLyra Cloud workspace?")) return;
196
- push.disabled = true;
197
- try {
198
- const result = await api("push", { id: row.id });
199
- announce((result.created ? "Created " : "Synced ") + row.name + " in AgentLyra Cloud.");
200
- } catch (error) { announce(error.message); }
201
- finally { push.disabled = false; }
202
- }) : undefined;
203
- const pull = push && button("Pull agent edits", async () => {
204
- pull.disabled = true;
205
- try {
206
- const result = await api("pull-agent", { id: row.id });
207
- await load({ catalogOnly: true });
208
- announce(result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
209
- } catch (error) { announce(error.message); }
210
- finally { pull.disabled = false; }
211
- });
212
- const sync = row.source === "framework" && project.mode !== "standalone" && button("Sync registration", async () => {
213
- try {
214
- const id = row.id.slice("framework:".length);
215
- const preview = await api("framework-preview", { id });
216
- if (!window.confirm("Sync only this private registration?\n" + JSON.stringify(preview.payload, null, 2))) return;
217
- await api("framework-sync", { id, fingerprint: preview.fingerprint });
218
- announce("Registration synced. Open Cloud → Agents to view it.");
219
- } catch (error) { announce(error.message); }
220
- });
221
- const actions = push ? dom("div", { className: "actions" }, push, pull) : sync;
222
- section.append(renderAgentCard(dom, { name: row.name, source: row.framework ? row.framework + " · Local" : agentSources[row.source], onRun: () => openRun([row.id]), extraAction: actions }));
223
- continue;
224
- }
225
- const card = element("article");
226
- card.className = "agent-card";
227
- card.append(element("strong", row.name));
228
- if (id === "workflows") card.append(row.runnable
229
- ? button("Run now", () => openRun(["workflow:" + row.id]))
230
- : element("span", "Cloud workflow requires the console"));
231
- const syncType = id === "skills" && row.source !== "markdown" ? "skill" : id === "teams" ? "team" : id === "workflows" && row.runnable ? "workflow" : undefined;
232
- if (syncType && row.source !== "cloud" && project.mode !== "standalone") {
233
- for (const [action, label] of [["push", "Push to Cloud"], ["pull", "Pull " + syncType + " edits"]]) {
234
- const control = button(label, async () => {
235
- if (action === "push" && !window.confirm("Send this " + syncType + " definition to your private Cloud workspace?")) return;
236
- control.disabled = true;
237
- try {
238
- const result = await api(action + "-" + syncType, { id: row.id });
239
- await load({ catalogOnly: true });
240
- announce(action === "push" ? "Saved " + result.name + " in Cloud."
241
- : result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
242
- } catch (error) { announce(error.message); }
243
- finally { control.disabled = false; }
244
- });
245
- card.append(control);
246
- }
247
- }
248
- if (id === "skills") card.append(element("span", row.source === "cloud" ? "Cloud skill" : row.source === "markdown" ? "Local Markdown skill" : "Local text skill"));
249
- if (id === "teams") card.append(element("span", row.source === "cloud" ? "Cloud team" : "Local team"));
250
- section.append(card);
251
- }
252
- }
253
- }
254
-
255
- function openRun(targets, input = "", outputId = "", buttonId) {
256
- pending = { targets, outputId, buttonId };
257
- $("#run-header").replaceChildren(renderRunHeader(dom, {
258
- title: targets.map(labelFor).join(" → "), kind: targets.length > 1 || targets[0].startsWith("workflow:") ? "Workflow" : "Agent",
259
- closeId: "close-run", onClose: () => $("#drawer").close(),
260
- }));
261
- $("#prompt").value = input;
262
- $("#run-result").textContent = "";
263
- $("#run-status").textContent = "";
264
- const picker = $("#model");
265
- picker.replaceChildren(...project.models.map(model => new Option(model, model)));
266
- const needsLocalModel = targets.some(id => id.startsWith("local:"));
267
- picker.hidden = !needsLocalModel;
268
- document.querySelector('label[for="model"]').hidden = !needsLocalModel;
269
- $("#drawer").showModal();
270
- }
271
-
272
- $("#runner").onsubmit = async event => {
273
- event.preventDefault();
274
- $("#run").disabled = true;
275
- $("#close-run").disabled = true;
276
- $("#run-status").textContent = "Running workflow…";
277
- try {
278
- const { answers } = await api("run", { targets: pending.targets, buttonId: pending.buttonId, input: $("#prompt").value, model: $("#model").value });
279
- const text = answers.map(({ agent, output, run }) => agent + "\n" + output +
280
- (run ? "\nRun " + run.runId + " · Trace " + run.traceId : "")).join("\n\n");
281
- $("#run-result").textContent = text;
282
- if (pending.outputId) outputs.set(pending.outputId, answers.at(-1).output);
283
- renderCanvas();
284
- $("#run-status").textContent = "Run completed.";
285
- } catch (error) {
286
- $("#run-status").textContent = error.message;
287
- } finally {
288
- $("#run").disabled = false;
289
- $("#close-run").disabled = false;
290
- }
291
- };
292
- $("#drawer").oncancel = event => { if ($("#run").disabled) event.preventDefault(); };
293
-
294
- async function load({ catalogOnly = false } = {}) {
295
- const next = await api("project");
296
- if (catalogOnly) {
297
- for (const key of ["agents", "workflows", "teams", "skills", "models", "mode", "frameworkCandidates"]) project[key] = next[key];
298
- } else {
299
- project = next;
300
- dirty = false;
301
- }
302
- $("#project-name").textContent = project.name + (project.mode === "gated" ? " · Cloud connected" : project.mode === "standalone" ? " · Working locally" : "");
303
- $("#open-memory").hidden = Boolean(project.exported);
304
- if (project.exported) {
305
- document.body.classList.add("exported");
306
- document.title = project.name;
307
- $("main h1").textContent = project.name;
308
- } else {
309
- renderCatalog();
310
- renderInspector();
311
- }
312
- renderCanvas();
313
- }
314
-
315
- for (const [kind, title] of Object.entries(names)) {
316
- const item = button(title, () => add(kind));
317
- item.draggable = true;
318
- item.ondragstart = event => event.dataTransfer.setData("text/lyra-component", kind);
319
- $("#palette").append(item);
320
- }
321
- $("#canvas").ondragover = event => { if (event.dataTransfer.types.includes("text/lyra-component")) event.preventDefault(); };
322
- $("#canvas").ondrop = event => { event.preventDefault(); add(event.dataTransfer.getData("text/lyra-component")); };
323
- $("#refresh").onclick = () => load({ catalogOnly: dirty }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
324
- $("#pull").onclick = async () => {
325
- $("#pull").disabled = true;
326
- try {
327
- const result = await api("pull", {});
328
- await load({ catalogOnly: true });
329
- announce(result.added + " added. " + result.preserved + " existing files preserved.");
330
- } catch (error) { announce(error.message); }
331
- finally { $("#pull").disabled = false; }
332
- };
333
- $("#save").onclick = async () => {
334
- $("#save").disabled = true;
335
- const snapshot = JSON.stringify(project.layout);
336
- try {
337
- const result = await api("save", { layout: JSON.parse(snapshot), revision: project.revision });
338
- project.revision = result.revision;
339
- dirty = snapshot !== JSON.stringify(project.layout);
340
- announce(dirty ? "Saved. You have newer canvas edits." : "Saved to manifest.json.");
341
- } catch (error) { announce(error.message); }
342
- finally { $("#save").disabled = false; }
343
- };
344
- window.addEventListener("beforeunload", event => { if (dirty) { event.preventDefault(); event.returnValue = ""; } });
345
- load().catch(error => announce(error.message));
1
+ import { mountWorkflowEditor } from "./workflow-editor.js";
2
+ import { mountMemoryPanel } from "./memory-panel.js";
3
+ import { renderAgentCard, renderRunHeader } from "./agent-ui.js";
4
+
5
+ const $ = selector => document.querySelector(selector);
6
+ const element = (tag, text) => Object.assign(document.createElement(tag), text === undefined ? {} : { textContent: text });
7
+ function dom(tag, props, ...children) {
8
+ const node = document.createElement(tag);
9
+ for (const [key, value] of Object.entries(props)) {
10
+ if (value == null) continue;
11
+ if (key === "onClick") node.onclick = value;
12
+ else if (key === "aria-label") node.setAttribute(key, value);
13
+ else node[key] = value;
14
+ }
15
+ node.append(...children.filter(child => child != null && child !== false && child !== ""));
16
+ return node;
17
+ }
18
+
19
+ const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent", framework: "Registered framework agent" };
20
+ const names = { heading:"Heading", text:"Text", input:"Text input", textarea:"Text area", button:"Run button", "agent-card":"Agent card", output:"Output" };
21
+ let project = { layout: [], agents: [], workflows: [], teams: [], skills: [] };
22
+ let selected, pending;
23
+ let libraryView = "palette";
24
+ let dirty = false;
25
+ let runInProgress = false;
26
+ const values = new Map();
27
+ const outputs = new Map();
28
+
29
+ function button(text, click) {
30
+ const control = element("button", text);
31
+ control.type = "button";
32
+ control.onclick = click;
33
+ return control;
34
+ }
35
+
36
+ async function api(path, data) {
37
+ const response = await fetch("/api/" + path, data === undefined ? {} : {
38
+ method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data),
39
+ });
40
+ const payload = await response.json();
41
+ if (!response.ok) throw Object.assign(new Error(payload.error), { progress: payload.progress });
42
+ return payload;
43
+ }
44
+
45
+ mountMemoryPanel(api);
46
+ const workflowEditor = mountWorkflowEditor({
47
+ api, project: () => project, reloadCatalog: () => load({ catalogOnly: true }),
48
+ run: id => openRun(["workflow:" + id]),
49
+ switchView: editing => {
50
+ $("#save").hidden = $("#canvas-panel").hidden = editing;
51
+ $("#library").hidden = editing;
52
+ if (editing) closeInspector();
53
+ $("#workflow-panel").hidden = !editing;
54
+ $("#show-layout").setAttribute("aria-pressed", String(!editing));
55
+ $("#show-workflow").setAttribute("aria-pressed", String(editing));
56
+ },
57
+ });
58
+
59
+ function announce(message) { $("#status").textContent = message; }
60
+ function change() { dirty = true; renderCanvas(); renderInspector(); }
61
+
62
+ function add(kind, index = project.layout.length) {
63
+ if (!Object.hasOwn(names, kind) || project.layout.length >= 60) return;
64
+ const node = { id: crypto.randomUUID(), kind, label: names[kind] };
65
+ if (["button", "agent-card"].includes(kind)) node.targets = [];
66
+ project.layout.splice(index, 0, node);
67
+ selected = node.id;
68
+ change();
69
+ }
70
+
71
+ function move(node, offset) {
72
+ const index = project.layout.indexOf(node);
73
+ const next = index + offset;
74
+ if (next < 0 || next >= project.layout.length) return;
75
+ [project.layout[index], project.layout[next]] = [project.layout[next], node];
76
+ change();
77
+ }
78
+
79
+ function renderCanvas() {
80
+ const canvas = $("#canvas");
81
+ canvas.replaceChildren();
82
+ if (!project.layout.length) canvas.append(element("p", "Your canvas is empty."));
83
+ for (const node of project.layout) {
84
+ const card = element("div");
85
+ card.dataset.nodeId = node.id;
86
+ card.dataset.span = node.span ?? 12;
87
+ card.className = "node" + (node.id === selected ? " selected" : "");
88
+ const select = button("Edit " + names[node.kind], () => { selected = node.id; renderCanvas(); renderInspector(); });
89
+ if (!project.exported && !project.preview) {
90
+ const handle = element("span", "⠿");
91
+ handle.className = "move-handle";
92
+ handle.title = "Drag to move, or use the inspector's move buttons";
93
+ handle.setAttribute("aria-hidden", "true");
94
+ handle.draggable = true;
95
+ handle.ondragstart = event => {
96
+ event.dataTransfer.setData("text/lyra-node", node.id);
97
+ event.dataTransfer.effectAllowed = "move";
98
+ event.dataTransfer.setDragImage(card, 12, 12);
99
+ };
100
+ const tools = element("div");
101
+ tools.className = "component-tools";
102
+ tools.append(handle, select);
103
+ card.append(tools);
104
+ }
105
+ if (node.kind === "heading" || node.kind === "text") card.append(element(node.kind === "heading" ? "h2" : "p", node.label));
106
+ if (["input", "textarea"].includes(node.kind)) {
107
+ const id = "component-" + node.id;
108
+ const label = element("label", node.label);
109
+ label.htmlFor = id;
110
+ const input = element(node.kind);
111
+ input.id = id;
112
+ input.maxLength = 4000;
113
+ input.value = values.get(node.id) ?? "";
114
+ input.oninput = () => values.set(node.id, input.value);
115
+ card.append(label, input);
116
+ }
117
+ if (node.kind === "output") card.append(element("h2", node.label), element("pre", outputs.get(node.id) ?? "Run a workflow to see a result."));
118
+ if (node.kind === "agent-card") {
119
+ const agent = project.agents.find(item => item.id === node.targets[0]);
120
+ card.append(renderAgentCard(dom, {
121
+ name: node.label, source: agent ? agentSources[agent.source] : "Choose an agent in the inspector",
122
+ onRun: agent ? () => openRun(node.targets, values.get(node.sourceId) ?? "", node.outputId, node.id) : undefined,
123
+ }));
124
+ }
125
+ if (node.kind === "button") {
126
+ const trigger = button(node.label, () => {
127
+ if (!node.targets.length) return announce("Assign an agent or workflow in the inspector first.");
128
+ openRun(node.targets, values.get(node.sourceId) ?? "", node.outputId, node.id);
129
+ });
130
+ if (!node.targets.length) trigger.title = "Assign a target in the inspector";
131
+ trigger.className = "primary";
132
+ card.append(trigger);
133
+ }
134
+ canvas.append(card);
135
+ }
136
+ }
137
+
138
+ function addSelect(parent, label, choices, value, onChange) {
139
+ const wrap = element("label", label);
140
+ const select = element("select");
141
+ for (const [id, title] of choices) select.add(new Option(title, id));
142
+ select.value = value ?? "";
143
+ select.onchange = () => onChange(select.value);
144
+ wrap.append(select);
145
+ parent.append(wrap);
146
+ return select;
147
+ }
148
+
149
+ function labelFor(id) {
150
+ return project.agents.find(agent => agent.id === id)?.name ??
151
+ project.workflows.find(workflow => "workflow:" + workflow.id === id)?.name ?? id;
152
+ }
153
+
154
+ function renderInspector() {
155
+ const box = $("#inspector");
156
+ box.replaceChildren();
157
+ const node = project.layout.find(item => item.id === selected);
158
+ $("#inspector-panel").hidden = !node;
159
+ if (!node) return;
160
+
161
+ const label = element("label", "Label");
162
+ const field = element("input");
163
+ field.value = node.label;
164
+ field.maxLength = 160;
165
+ field.oninput = () => { node.label = field.value; dirty = true; renderCanvas(); };
166
+ label.append(field);
167
+ const actions = element("div");
168
+ actions.className = "actions";
169
+ actions.append(button("Move up", () => move(node, -1)), button("Move down", () => move(node, 1)), button("Remove", () => {
170
+ project.layout = project.layout.filter(item => item !== node);
171
+ for (const item of project.layout) {
172
+ if (item.sourceId === node.id) item.sourceId = "";
173
+ if (item.outputId === node.id) item.outputId = "";
174
+ }
175
+ selected = null;
176
+ change();
177
+ }));
178
+ box.append(label);
179
+ addSelect(box, "Width", [[12, "Full"], [9, "Three quarters"], [8, "Two thirds"], [6, "Half"], [4, "One third"], [3, "Quarter"]], node.span ?? 12, width => {
180
+ node.span = Number(width);
181
+ dirty = true;
182
+ renderCanvas();
183
+ });
184
+ box.append(actions);
185
+ if (!["button", "agent-card"].includes(node.kind)) return;
186
+
187
+ const fields = project.layout.filter(item => ["input", "textarea"].includes(item.kind));
188
+ const results = project.layout.filter(item => item.kind === "output");
189
+ addSelect(box, "Input component", [["", "Enter in run drawer"], ...fields.map(item => [item.id, item.label])], node.sourceId, id => {
190
+ node.sourceId = id; dirty = true;
191
+ });
192
+ addSelect(box, "Output component", [["", "Show in run drawer"], ...results.map(item => [item.id, item.label])], node.outputId, id => {
193
+ node.outputId = id; dirty = true;
194
+ });
195
+ if (node.kind === "agent-card") {
196
+ addSelect(box, "Agent", [["", "Choose an agent"], ...project.agents.map(agent => [agent.id, agent.name])], node.targets[0], id => {
197
+ if (node.label === names["agent-card"] || node.label === labelFor(node.targets[0])) {
198
+ node.label = id ? labelFor(id) : names["agent-card"];
199
+ }
200
+ node.targets = id ? [id] : [];
201
+ change();
202
+ });
203
+ return;
204
+ }
205
+ box.append(element("h2", "Run order"));
206
+ node.targets.forEach((target, index) => {
207
+ const row = element("div", labelFor(target));
208
+ row.className = "binding";
209
+ row.append(button("Remove", () => { node.targets.splice(index, 1); change(); }));
210
+ box.append(row);
211
+ });
212
+ const options = [
213
+ ...project.agents.map(agent => [agent.id, agent.name]),
214
+ ...project.workflows.filter(item => item.runnable).map(item => ["workflow:" + item.id, item.name + " (workflow)"]),
215
+ ];
216
+ addSelect(box, "Add next step", [["", "Choose agent or workflow"], ...options], "", id => {
217
+ if (id && node.targets.length < 8) { node.targets.push(id); change(); }
218
+ });
219
+ }
220
+
221
+ function renderCatalog() {
222
+ for (const tab of $("#library-tabs").querySelectorAll("button")) {
223
+ const active = libraryView === tab.dataset.library;
224
+ tab.setAttribute("aria-pressed", String(active));
225
+ $("#" + tab.dataset.library).hidden = !active;
226
+ }
227
+ const search = $("#library-search");
228
+ search.hidden = $("#library-search-label").hidden = libraryView === "palette";
229
+ if (search.hidden) return;
230
+
231
+ const id = libraryView;
232
+ const section = $("#" + id);
233
+ const query = search.value.trim().toLowerCase();
234
+ const rows = project[id].filter(row => [row.name, row.source, row.framework, agentSources[row.source]]
235
+ .some(value => value?.toLowerCase().includes(query)));
236
+ section.replaceChildren();
237
+ if (!rows.length) section.append(element("p", query ? "No matching items." : "None in this project."));
238
+ if (id === "agents" && project.frameworkCandidates?.length) {
239
+ section.append(element("p", "LangGraph candidates: " + project.frameworkCandidates.map(item => item.name).join(", ") +
240
+ ". Run agent-lyra agent discover, then register the entry you want."));
241
+ }
242
+ for (const row of rows) {
243
+ if (id === "agents") {
244
+ const push = row.source === "local" && project.mode !== "standalone"
245
+ ? button("Push to Cloud", async () => {
246
+ if (!window.confirm("Send the name and instructions for " + row.name + " to your private AgentLyra Cloud workspace?")) return;
247
+ push.disabled = true;
248
+ try {
249
+ const result = await api("push", { id: row.id });
250
+ announce((result.created ? "Created " : "Synced ") + row.name + " in AgentLyra Cloud.");
251
+ } catch (error) { announce(error.message); }
252
+ finally { push.disabled = false; }
253
+ }) : undefined;
254
+ const pull = push && button("Pull agent edits", async () => {
255
+ pull.disabled = true;
256
+ try {
257
+ const result = await api("pull-agent", { id: row.id });
258
+ await load({ catalogOnly: true });
259
+ announce(result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
260
+ } catch (error) { announce(error.message); }
261
+ finally { pull.disabled = false; }
262
+ });
263
+ const sync = row.source === "framework" && project.mode !== "standalone" && button("Sync registration", async () => {
264
+ try {
265
+ const id = row.id.slice("framework:".length);
266
+ const preview = await api("framework-preview", { id });
267
+ if (!window.confirm("Sync only this private registration?\n" + JSON.stringify(preview.payload, null, 2))) return;
268
+ await api("framework-sync", { id, fingerprint: preview.fingerprint });
269
+ announce("Registration synced. Open Cloud → Agents to view it.");
270
+ } catch (error) { announce(error.message); }
271
+ });
272
+ const entry = element("details");
273
+ entry.className = "library-entry";
274
+ const summary = element("summary");
275
+ const source = row.framework ? row.framework + " · Local" : agentSources[row.source];
276
+ summary.append(element("strong", row.name), element("span", source));
277
+ const actions = dom("div", { className: "actions" }, button("Run now", () => openRun([row.id])), push, pull, sync);
278
+ entry.append(summary, actions);
279
+ section.append(entry);
280
+ continue;
281
+ }
282
+ const card = element("article");
283
+ card.className = "agent-card";
284
+ card.append(element("strong", row.name));
285
+ if (id === "workflows") {
286
+ card.append(button("Open workflow", () => workflowEditor.open(row.id)));
287
+ card.append(row.runnable ? button("Run now", () => openRun(["workflow:" + row.id]))
288
+ : element("span", "Run this workflow in Lyra Cloud."));
289
+ }
290
+ const syncType = id === "skills" && row.source !== "markdown" ? "skill" : id === "teams" ? "team" : id === "workflows" && row.runnable ? "workflow" : undefined;
291
+ if (syncType && row.source !== "cloud" && project.mode !== "standalone") {
292
+ for (const [action, label] of [["push", "Push to Cloud"], ["pull", "Pull " + syncType + " edits"]]) {
293
+ const control = button(label, async () => {
294
+ if (action === "push" && !window.confirm("Send this " + syncType + " definition to your private Cloud workspace?")) return;
295
+ control.disabled = true;
296
+ try {
297
+ const result = await api(action + "-" + syncType, { id: row.id });
298
+ await load({ catalogOnly: true });
299
+ announce(action === "push" ? "Saved " + result.name + " in Cloud."
300
+ : result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
301
+ } catch (error) { announce(error.message); }
302
+ finally { control.disabled = false; }
303
+ });
304
+ card.append(control);
305
+ }
306
+ }
307
+ if (id === "skills") card.append(element("span", row.source === "cloud" ? "Cloud skill" : row.source === "markdown" ? "Local Markdown skill" : "Local text skill"));
308
+ if (id === "teams") card.append(element("span", row.source === "cloud" ? "Cloud team" : "Local team"));
309
+ section.append(card);
310
+ }
311
+ }
312
+
313
+ function minimizeRun() {
314
+ $("#drawer").close();
315
+ $("#resume-run").hidden = false;
316
+ $("#resume-run").focus();
317
+ }
318
+
319
+ async function openRun(targets, input = "", outputId = "", buttonId) {
320
+ if (runInProgress) {
321
+ $("#resume-run").click();
322
+ return;
323
+ }
324
+ $("#resume-run").hidden = true;
325
+ const action = { targets: [...targets], outputId, buttonId, revision: project.revision };
326
+ pending = action;
327
+ $("#run-header").replaceChildren(renderRunHeader(dom, {
328
+ title: targets.map(labelFor).join(" → "), kind: targets.length > 1 || targets[0].startsWith("workflow:") ? "Workflow" : "Agent",
329
+ closeId: "close-run", onClose: () => $("#drawer").close(),
330
+ }));
331
+ $("#prompt").value = input;
332
+ $("#run-result").textContent = "";
333
+ $("#run-status").textContent = "Checking run setup…";
334
+ $("#run-input-label").textContent = "Input";
335
+ $("#prompt").setCustomValidity("");
336
+ const plan = $("#run-plan");
337
+ plan.hidden = true;
338
+ plan.replaceChildren();
339
+ const picker = $("#model");
340
+ const modelLabel = $('label[for="model"]');
341
+ picker.hidden = modelLabel.hidden = true;
342
+ $("#run").disabled = true;
343
+ $("#run").textContent = project.preview || project.exported ? "Run" : "Test action";
344
+ $("#drawer").showModal();
345
+ try {
346
+ const component = project.layout.find(node => node.id === buttonId);
347
+ if (component && ((component.sourceId && !project.layout.some(node => node.id === component.sourceId && ["input", "textarea"].includes(node.kind))) ||
348
+ (component.outputId && !project.layout.some(node => node.id === component.outputId && node.kind === "output")))) {
349
+ throw new Error("Fix the input or output binding in the inspector.");
350
+ }
351
+ const setup = await api("run-plan", { targets: action.targets, buttonId, revision: action.revision });
352
+ if (pending !== action) return;
353
+ const list = element("ol");
354
+ for (const step of setup.steps) {
355
+ const row = element("li");
356
+ row.append(element("strong", step.name), element("span",
357
+ [step.location, step.framework, step.provider].filter(Boolean).join(" · ")));
358
+ list.append(row);
359
+ }
360
+ plan.replaceChildren(element("h2", "Execution steps"), list);
361
+ plan.hidden = false;
362
+ const previousModel = picker.value;
363
+ picker.replaceChildren(...setup.models.map(model => new Option(model, model)));
364
+ if (setup.models.includes(previousModel)) picker.value = previousModel;
365
+ picker.hidden = modelLabel.hidden = !setup.needsModel;
366
+ action.inputKind = setup.inputKind;
367
+ if (setup.inputKind === "json") $("#run-input-label").textContent = "JSON input";
368
+ action.ready = setup.issues.length === 0;
369
+ $("#run-status").textContent = setup.issues.join(" ");
370
+ $("#run").disabled = !action.ready;
371
+ } catch (error) {
372
+ if (pending === action) $("#run-status").textContent = error.message;
373
+ }
374
+ }
375
+
376
+ function showRunResults({ answers, traceId, steps }) {
377
+ const lines = traceId ? ["Studio run trace " + traceId] : [];
378
+ if (steps) {
379
+ for (const step of steps) {
380
+ const heading = step.index + ". " + step.agent + " · " + step.state + " · " + step.durationMs + " ms";
381
+ lines.push([heading, "Step trace " + step.traceId, step.runId && "Runtime run " + step.runId,
382
+ answers[step.index - 1]?.output].filter(Boolean).join("\n"));
383
+ }
384
+ } else {
385
+ for (const { agent, output } of answers) lines.push(agent + "\n" + output);
386
+ }
387
+ $("#run-result").textContent = lines.join("\n\n");
388
+ }
389
+
390
+ $("#runner").onsubmit = async event => {
391
+ event.preventDefault();
392
+ if (!pending?.ready || runInProgress) return;
393
+ const prompt = $("#prompt");
394
+ if (pending.inputKind === "json") {
395
+ try { JSON.parse(prompt.value); }
396
+ catch {
397
+ prompt.setCustomValidity("Enter valid JSON for the first agent.");
398
+ prompt.reportValidity();
399
+ return;
400
+ }
401
+ }
402
+ runInProgress = true;
403
+ $("#run").disabled = true;
404
+ $("#close-run").disabled = true;
405
+ $("#run-status").textContent = "Running…";
406
+ $("#run-result").textContent = "";
407
+ try {
408
+ const result = await api("run", { targets: pending.targets, buttonId: pending.buttonId, revision: pending.revision, input: prompt.value, model: $("#model").value });
409
+ showRunResults(result);
410
+ if (pending.outputId) outputs.set(pending.outputId, result.answers.at(-1).output);
411
+ renderCanvas();
412
+ $("#run-status").textContent = "Run completed.";
413
+ } catch (error) {
414
+ if (error.progress) showRunResults(error.progress);
415
+ $("#run-status").textContent = error.message;
416
+ } finally {
417
+ runInProgress = false;
418
+ $("#run").disabled = false;
419
+ $("#close-run").disabled = false;
420
+ }
421
+ };
422
+ $("#prompt").oninput = event => event.target.setCustomValidity("");
423
+ const drawer = $("#drawer");
424
+ $("#resume-run").onclick = () => {
425
+ if (!drawer.open) drawer.showModal();
426
+ $("#resume-run").hidden = true;
427
+ };
428
+ $("#minimize-run").onclick = minimizeRun;
429
+ drawer.oncancel = event => {
430
+ event.preventDefault();
431
+ minimizeRun();
432
+ };
433
+ let pressedBackdrop = false;
434
+ drawer.onpointerdown = event => { pressedBackdrop = event.target === drawer; };
435
+ drawer.onclick = event => {
436
+ if (pressedBackdrop && event.target === drawer) {
437
+ const { left, right, top, bottom } = drawer.getBoundingClientRect();
438
+ if (event.clientX < left || event.clientX > right || event.clientY < top || event.clientY > bottom) minimizeRun();
439
+ }
440
+ pressedBackdrop = false;
441
+ };
442
+
443
+ async function load({ catalogOnly = false } = {}) {
444
+ const next = await api("project");
445
+ if (catalogOnly) {
446
+ for (const key of ["agents", "workflows", "teams", "skills", "mode", "frameworkCandidates"]) project[key] = next[key];
447
+ } else {
448
+ project = next;
449
+ dirty = false;
450
+ }
451
+ $("#project-name").textContent = project.name + (project.mode === "gated" ? " · Cloud connected" : project.mode === "standalone" ? " · Working locally" : "");
452
+ $("#open-memory").hidden = Boolean(project.exported || project.preview);
453
+ if (project.exported || project.preview) {
454
+ document.body.classList.add("exported");
455
+ document.title = project.name;
456
+ $("main h1").textContent = project.name;
457
+ } else {
458
+ renderCatalog();
459
+ renderInspector();
460
+ workflowEditor.refresh();
461
+ }
462
+ renderCanvas();
463
+ }
464
+
465
+ for (const [kind, title] of Object.entries(names)) {
466
+ const item = button(title, () => add(kind));
467
+ item.draggable = true;
468
+ item.ondragstart = event => event.dataTransfer.setData("text/lyra-component", kind);
469
+ $("#palette").append(item);
470
+ }
471
+ function closeInspector() {
472
+ selected = null;
473
+ $("#canvas .selected")?.classList.remove("selected");
474
+ renderInspector();
475
+ }
476
+ $("#close-inspector").onclick = closeInspector;
477
+ $("#canvas-panel").onclick = event => {
478
+ if (selected && event.target.isConnected && !event.target.closest(".node")) closeInspector();
479
+ };
480
+ $("#library-search").oninput = renderCatalog;
481
+ $("#library-tabs").onclick = event => {
482
+ const tab = event.target.closest("button[data-library]");
483
+ if (!tab || tab.dataset.library === libraryView) return;
484
+ libraryView = tab.dataset.library;
485
+ $("#library-search").value = "";
486
+ $("#library-content").scrollTop = 0;
487
+ renderCatalog();
488
+ };
489
+ $("#canvas").ondragover = event => {
490
+ if (project.exported || project.preview) return;
491
+ const types = event.dataTransfer.types;
492
+ if (types.includes("text/lyra-component") || types.includes("text/lyra-node")) event.preventDefault();
493
+ };
494
+ $("#canvas").ondrop = event => {
495
+ if (project.exported || project.preview) return;
496
+ event.preventDefault();
497
+ const target = event.target.closest(".node");
498
+ const targetId = target?.dataset.nodeId;
499
+ const targetIndex = project.layout.findIndex(node => node.id === targetId);
500
+ let index = project.layout.length;
501
+ if (targetIndex !== -1) {
502
+ const bounds = target.getBoundingClientRect();
503
+ const spansRow = target.offsetWidth >= $("#canvas").clientWidth - 32;
504
+ const after = spansRow ? event.clientY > bounds.top + bounds.height / 2 :
505
+ event.clientX > bounds.left + bounds.width / 2;
506
+ index = targetIndex + Number(after);
507
+ }
508
+ const sourceId = event.dataTransfer.getData("text/lyra-node");
509
+ if (!sourceId) {
510
+ add(event.dataTransfer.getData("text/lyra-component"), index);
511
+ return;
512
+ }
513
+ const from = project.layout.findIndex(node => node.id === sourceId);
514
+ if (from === -1 || from === index || from + 1 === index) return;
515
+ const [node] = project.layout.splice(from, 1);
516
+ project.layout.splice(index > from ? index - 1 : index, 0, node);
517
+ selected = node.id;
518
+ change();
519
+ };
520
+ $("#refresh").onclick = () => load({ catalogOnly: dirty }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
521
+ $("#pull").onclick = async () => {
522
+ $("#pull").disabled = true;
523
+ try {
524
+ const result = await api("pull", {});
525
+ await load({ catalogOnly: true });
526
+ announce(result.added + " added. " + result.preserved + " existing files preserved.");
527
+ } catch (error) { announce(error.message); }
528
+ finally { $("#pull").disabled = false; }
529
+ };
530
+ $("#save").onclick = async () => {
531
+ $("#save").disabled = true;
532
+ const snapshot = JSON.stringify(project.layout);
533
+ try {
534
+ const result = await api("save", { layout: JSON.parse(snapshot), revision: project.revision });
535
+ project.revision = result.revision;
536
+ dirty = snapshot !== JSON.stringify(project.layout);
537
+ announce(dirty ? "Saved. You have newer canvas edits." : "Saved to manifest.json.");
538
+ } catch (error) { announce(error.message); }
539
+ finally { $("#save").disabled = false; }
540
+ };
541
+ window.addEventListener("beforeunload", event => { if (dirty || workflowEditor.dirty()) { event.preventDefault(); event.returnValue = ""; } });
542
+ load().catch(error => announce(error.message));