agent-lyra 0.6.1 → 0.6.3
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/LICENSE +21 -21
- package/README.md +435 -395
- package/bin/agent-lyra.js +49 -44
- package/bin/lyra-oss-preview.js +16 -0
- package/package.json +60 -60
- package/src/app-builder/export.js +109 -109
- package/src/app-builder/gateway.js +62 -62
- package/src/app-builder/init.js +52 -52
- package/src/app-builder/manifest-contract.js +46 -0
- package/src/app-builder/native-adapter.js +29 -29
- package/src/app-builder/preview.js +22 -22
- package/src/app-builder/publish.js +14 -14
- package/src/app-builder/saved-app.js +70 -70
- package/src/app-builder/saved-preview-browser.js +33 -33
- package/src/app-builder/saved-preview.html +24 -24
- package/src/app-builder/saved-preview.js +61 -61
- package/src/app-builder/support-manifest.js +50 -50
- package/src/app-builder/support-template/manifest.json +55 -55
- package/src/app-builder/support-template/support-preview.html +56 -56
- package/src/app-builder/support-template/support-preview.js +37 -37
- package/src/app-builder/support-template/support-preview.mjs +67 -67
- package/src/app-builder/support-template/support-workflow.mjs +36 -36
- package/src/app-builder/use.js +37 -37
- package/src/app-builder/validate.js +21 -64
- package/src/app-builder/value-schema.js +37 -37
- package/src/catalog.js +147 -147
- package/src/coding/catalog.js +56 -0
- package/src/coding/cloud-catalog.js +64 -0
- package/src/coding/detect-stack.mjs +110 -0
- package/src/coding/export.js +130 -0
- package/src/coding/setup.js +175 -0
- package/src/coding/skills/lyra-android/SKILL.md +37 -0
- package/src/coding/skills/lyra-angular/SKILL.md +37 -0
- package/src/coding/skills/lyra-cucumber/SKILL.md +37 -0
- package/src/coding/skills/lyra-dbt/SKILL.md +37 -0
- package/src/coding/skills/lyra-django/SKILL.md +37 -0
- package/src/coding/skills/lyra-docker/SKILL.md +37 -0
- package/src/coding/skills/lyra-dotnet/SKILL.md +37 -0
- package/src/coding/skills/lyra-express/SKILL.md +37 -0
- package/src/coding/skills/lyra-fastapi/SKILL.md +37 -0
- package/src/coding/skills/lyra-flutter/SKILL.md +37 -0
- package/src/coding/skills/lyra-github-actions/SKILL.md +37 -0
- package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -0
- package/src/coding/skills/lyra-go/SKILL.md +37 -0
- package/src/coding/skills/lyra-ios/SKILL.md +37 -0
- package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -0
- package/src/coding/skills/lyra-mongodb/SKILL.md +37 -0
- package/src/coding/skills/lyra-mysql/SKILL.md +37 -0
- package/src/coding/skills/lyra-nextjs/SKILL.md +37 -0
- package/src/coding/skills/lyra-node/SKILL.md +37 -0
- package/src/coding/skills/lyra-playwright/SKILL.md +37 -0
- package/src/coding/skills/lyra-postgresql/SKILL.md +37 -0
- package/src/coding/skills/lyra-python/SKILL.md +37 -0
- package/src/coding/skills/lyra-react/SKILL.md +37 -0
- package/src/coding/skills/lyra-react-native/SKILL.md +37 -0
- package/src/coding/skills/lyra-redis/SKILL.md +37 -0
- package/src/coding/skills/lyra-rust/SKILL.md +37 -0
- package/src/coding/skills/lyra-spark/SKILL.md +37 -0
- package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -0
- package/src/coding/skills/lyra-svelte/SKILL.md +37 -0
- package/src/coding/skills/lyra-terraform/SKILL.md +37 -0
- package/src/coding/skills/lyra-typescript/SKILL.md +37 -0
- package/src/coding/skills/lyra-vue/SKILL.md +37 -0
- package/src/gated/hostedAgents.js +56 -56
- package/src/gated/index.d.ts +25 -25
- package/src/gated/index.js +5 -5
- package/src/index.d.ts +2 -2
- package/src/index.js +2 -2
- package/src/init.js +965 -937
- package/src/memory/cli.js +21 -49
- package/src/memory/contract.json +28 -28
- package/src/memory/index.d.ts +49 -49
- package/src/memory/index.js +259 -259
- package/src/memory/lifecycle.js +29 -29
- package/src/memory/local-cli.js +34 -0
- package/src/memory/proposals.js +84 -84
- package/src/memory/skills-cli.js +26 -26
- package/src/memory/sync.js +89 -85
- package/src/memory/validation.js +25 -25
- package/src/onboardingAgents.js +532 -532
- package/src/promptTemplates.js +178 -178
- package/src/runtime/contracts.d.ts +47 -47
- package/src/runtime/local-cli.js +160 -160
- package/src/runtime/mcp-stdio.js +111 -111
- package/src/runtime/orchestration.js +59 -59
- package/src/runtime/run-agent.js +43 -43
- package/src/standalone/index.d.ts +45 -45
- package/src/standalone/index.js +13 -13
- package/src/standalone/init.js +12 -0
- package/src/standalone/orchestration.js +6 -6
- package/src/standalone/rag.js +113 -113
- package/src/studio/agent-ui.css +43 -43
- package/src/studio/agent-ui.js +32 -32
- package/src/studio/browser.js +331 -331
- package/src/studio/export.js +80 -80
- package/src/studio/index.html +37 -37
- package/src/studio/memory-actions.js +37 -37
- package/src/studio/memory-panel.js +200 -200
- package/src/studio/project.js +216 -197
- package/src/studio/pull-agent.js +72 -72
- package/src/studio/push.js +54 -54
- package/src/studio/python-agent.js +47 -47
- package/src/studio/python-agent.py +25 -25
- package/src/studio/server.js +143 -143
- package/src/studio/session.js +83 -83
- package/src/studio/studio.css +10 -10
- package/src/studio/sync.js +42 -42
- package/src/studio/workflow-sync.js +157 -157
package/src/studio/browser.js
CHANGED
|
@@ -1,331 +1,331 @@
|
|
|
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" };
|
|
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
|
-
for (const row of rows) {
|
|
188
|
-
if (id === "agents") {
|
|
189
|
-
const push = row.source === "local" && project.mode !== "standalone"
|
|
190
|
-
? button("Push to Cloud", async () => {
|
|
191
|
-
if (!window.confirm("Send the name and instructions for " + row.name + " to your private AgentLyra Cloud workspace?")) return;
|
|
192
|
-
push.disabled = true;
|
|
193
|
-
try {
|
|
194
|
-
const result = await api("push", { id: row.id });
|
|
195
|
-
announce((result.created ? "Created " : "Synced ") + row.name + " in AgentLyra Cloud.");
|
|
196
|
-
} catch (error) { announce(error.message); }
|
|
197
|
-
finally { push.disabled = false; }
|
|
198
|
-
}) : undefined;
|
|
199
|
-
const pull = push && button("Pull agent edits", async () => {
|
|
200
|
-
pull.disabled = true;
|
|
201
|
-
try {
|
|
202
|
-
const result = await api("pull-agent", { id: row.id });
|
|
203
|
-
await load({ catalogOnly: true });
|
|
204
|
-
announce(result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
|
|
205
|
-
} catch (error) { announce(error.message); }
|
|
206
|
-
finally { pull.disabled = false; }
|
|
207
|
-
});
|
|
208
|
-
const actions = push ? dom("div", { className: "actions" }, push, pull) : undefined;
|
|
209
|
-
section.append(renderAgentCard(dom, { name: row.name, source: agentSources[row.source], onRun: () => openRun([row.id]), extraAction: actions }));
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
const card = element("article");
|
|
213
|
-
card.className = "agent-card";
|
|
214
|
-
card.append(element("strong", row.name));
|
|
215
|
-
if (id === "workflows") card.append(row.runnable
|
|
216
|
-
? button("Run now", () => openRun(["workflow:" + row.id]))
|
|
217
|
-
: element("span", "Cloud workflow requires the console"));
|
|
218
|
-
const syncType = id === "skills" ? "skill" : id === "teams" ? "team" : id === "workflows" && row.runnable ? "workflow" : undefined;
|
|
219
|
-
if (syncType && row.source !== "cloud" && project.mode !== "standalone") {
|
|
220
|
-
for (const [action, label] of [["push", "Push to Cloud"], ["pull", "Pull " + syncType + " edits"]]) {
|
|
221
|
-
const control = button(label, async () => {
|
|
222
|
-
if (action === "push" && !window.confirm("Send this " + syncType + " definition to your private Cloud workspace?")) return;
|
|
223
|
-
control.disabled = true;
|
|
224
|
-
try {
|
|
225
|
-
const result = await api(action + "-" + syncType, { id: row.id });
|
|
226
|
-
await load({ catalogOnly: true });
|
|
227
|
-
announce(action === "push" ? "Saved " + result.name + " in Cloud."
|
|
228
|
-
: result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
|
|
229
|
-
} catch (error) { announce(error.message); }
|
|
230
|
-
finally { control.disabled = false; }
|
|
231
|
-
});
|
|
232
|
-
card.append(control);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (id === "skills") card.append(element("span", row.source === "cloud" ? "Cloud skill" : "Local text skill"));
|
|
236
|
-
if (id === "teams") card.append(element("span", row.source === "cloud" ? "Cloud team" : "Local team"));
|
|
237
|
-
section.append(card);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function openRun(targets, input = "", outputId = "", buttonId) {
|
|
243
|
-
pending = { targets, outputId, buttonId };
|
|
244
|
-
$("#run-header").replaceChildren(renderRunHeader(dom, {
|
|
245
|
-
title: targets.map(labelFor).join(" → "), kind: targets.length > 1 || targets[0].startsWith("workflow:") ? "Workflow" : "Agent",
|
|
246
|
-
closeId: "close-run", onClose: () => $("#drawer").close(),
|
|
247
|
-
}));
|
|
248
|
-
$("#prompt").value = input;
|
|
249
|
-
$("#run-result").textContent = "";
|
|
250
|
-
$("#run-status").textContent = "";
|
|
251
|
-
const picker = $("#model");
|
|
252
|
-
picker.replaceChildren(...project.models.map(model => new Option(model, model)));
|
|
253
|
-
const needsLocalModel = targets.some(id => id.startsWith("local:"));
|
|
254
|
-
picker.hidden = !needsLocalModel;
|
|
255
|
-
document.querySelector('label[for="model"]').hidden = !needsLocalModel;
|
|
256
|
-
$("#drawer").showModal();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
$("#runner").onsubmit = async event => {
|
|
260
|
-
event.preventDefault();
|
|
261
|
-
$("#run").disabled = true;
|
|
262
|
-
$("#close-run").disabled = true;
|
|
263
|
-
$("#run-status").textContent = "Running workflow…";
|
|
264
|
-
try {
|
|
265
|
-
const { answers } = await api("run", { targets: pending.targets, buttonId: pending.buttonId, input: $("#prompt").value, model: $("#model").value });
|
|
266
|
-
const text = answers.map(({ agent, output }) => agent + "\n" + output).join("\n\n");
|
|
267
|
-
$("#run-result").textContent = text;
|
|
268
|
-
if (pending.outputId) outputs.set(pending.outputId, answers.at(-1).output);
|
|
269
|
-
renderCanvas();
|
|
270
|
-
$("#run-status").textContent = "Run completed.";
|
|
271
|
-
} catch (error) {
|
|
272
|
-
$("#run-status").textContent = error.message;
|
|
273
|
-
} finally {
|
|
274
|
-
$("#run").disabled = false;
|
|
275
|
-
$("#close-run").disabled = false;
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
$("#drawer").oncancel = event => { if ($("#run").disabled) event.preventDefault(); };
|
|
279
|
-
|
|
280
|
-
async function load({ catalogOnly = false } = {}) {
|
|
281
|
-
const next = await api("project");
|
|
282
|
-
if (catalogOnly) {
|
|
283
|
-
for (const key of ["agents", "workflows", "teams", "skills", "models", "mode"]) project[key] = next[key];
|
|
284
|
-
} else {
|
|
285
|
-
project = next;
|
|
286
|
-
dirty = false;
|
|
287
|
-
}
|
|
288
|
-
$("#project-name").textContent = project.name + (project.mode === "gated" ? " · Cloud connected" : project.mode === "standalone" ? " · Working locally" : "");
|
|
289
|
-
$("#open-memory").hidden = Boolean(project.exported);
|
|
290
|
-
if (project.exported) {
|
|
291
|
-
document.body.classList.add("exported");
|
|
292
|
-
document.title = project.name;
|
|
293
|
-
$("main h1").textContent = project.name;
|
|
294
|
-
} else {
|
|
295
|
-
renderCatalog();
|
|
296
|
-
renderInspector();
|
|
297
|
-
}
|
|
298
|
-
renderCanvas();
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
for (const [kind, title] of Object.entries(names)) {
|
|
302
|
-
const item = button(title, () => add(kind));
|
|
303
|
-
item.draggable = true;
|
|
304
|
-
item.ondragstart = event => event.dataTransfer.setData("text/lyra-component", kind);
|
|
305
|
-
$("#palette").append(item);
|
|
306
|
-
}
|
|
307
|
-
$("#canvas").ondragover = event => { if (event.dataTransfer.types.includes("text/lyra-component")) event.preventDefault(); };
|
|
308
|
-
$("#canvas").ondrop = event => { event.preventDefault(); add(event.dataTransfer.getData("text/lyra-component")); };
|
|
309
|
-
$("#refresh").onclick = () => load({ catalogOnly: dirty }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
|
|
310
|
-
$("#pull").onclick = async () => {
|
|
311
|
-
$("#pull").disabled = true;
|
|
312
|
-
try {
|
|
313
|
-
const result = await api("pull", {});
|
|
314
|
-
await load({ catalogOnly: true });
|
|
315
|
-
announce(result.added + " added. " + result.preserved + " existing files preserved.");
|
|
316
|
-
} catch (error) { announce(error.message); }
|
|
317
|
-
finally { $("#pull").disabled = false; }
|
|
318
|
-
};
|
|
319
|
-
$("#save").onclick = async () => {
|
|
320
|
-
$("#save").disabled = true;
|
|
321
|
-
const snapshot = JSON.stringify(project.layout);
|
|
322
|
-
try {
|
|
323
|
-
const result = await api("save", { layout: JSON.parse(snapshot), revision: project.revision });
|
|
324
|
-
project.revision = result.revision;
|
|
325
|
-
dirty = snapshot !== JSON.stringify(project.layout);
|
|
326
|
-
announce(dirty ? "Saved. You have newer canvas edits." : "Saved to manifest.json.");
|
|
327
|
-
} catch (error) { announce(error.message); }
|
|
328
|
-
finally { $("#save").disabled = false; }
|
|
329
|
-
};
|
|
330
|
-
window.addEventListener("beforeunload", event => { if (dirty) { event.preventDefault(); event.returnValue = ""; } });
|
|
331
|
-
load().catch(error => announce(error.message));
|
|
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" };
|
|
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
|
+
for (const row of rows) {
|
|
188
|
+
if (id === "agents") {
|
|
189
|
+
const push = row.source === "local" && project.mode !== "standalone"
|
|
190
|
+
? button("Push to Cloud", async () => {
|
|
191
|
+
if (!window.confirm("Send the name and instructions for " + row.name + " to your private AgentLyra Cloud workspace?")) return;
|
|
192
|
+
push.disabled = true;
|
|
193
|
+
try {
|
|
194
|
+
const result = await api("push", { id: row.id });
|
|
195
|
+
announce((result.created ? "Created " : "Synced ") + row.name + " in AgentLyra Cloud.");
|
|
196
|
+
} catch (error) { announce(error.message); }
|
|
197
|
+
finally { push.disabled = false; }
|
|
198
|
+
}) : undefined;
|
|
199
|
+
const pull = push && button("Pull agent edits", async () => {
|
|
200
|
+
pull.disabled = true;
|
|
201
|
+
try {
|
|
202
|
+
const result = await api("pull-agent", { id: row.id });
|
|
203
|
+
await load({ catalogOnly: true });
|
|
204
|
+
announce(result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
|
|
205
|
+
} catch (error) { announce(error.message); }
|
|
206
|
+
finally { pull.disabled = false; }
|
|
207
|
+
});
|
|
208
|
+
const actions = push ? dom("div", { className: "actions" }, push, pull) : undefined;
|
|
209
|
+
section.append(renderAgentCard(dom, { name: row.name, source: agentSources[row.source], onRun: () => openRun([row.id]), extraAction: actions }));
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const card = element("article");
|
|
213
|
+
card.className = "agent-card";
|
|
214
|
+
card.append(element("strong", row.name));
|
|
215
|
+
if (id === "workflows") card.append(row.runnable
|
|
216
|
+
? button("Run now", () => openRun(["workflow:" + row.id]))
|
|
217
|
+
: element("span", "Cloud workflow requires the console"));
|
|
218
|
+
const syncType = id === "skills" && row.source !== "markdown" ? "skill" : id === "teams" ? "team" : id === "workflows" && row.runnable ? "workflow" : undefined;
|
|
219
|
+
if (syncType && row.source !== "cloud" && project.mode !== "standalone") {
|
|
220
|
+
for (const [action, label] of [["push", "Push to Cloud"], ["pull", "Pull " + syncType + " edits"]]) {
|
|
221
|
+
const control = button(label, async () => {
|
|
222
|
+
if (action === "push" && !window.confirm("Send this " + syncType + " definition to your private Cloud workspace?")) return;
|
|
223
|
+
control.disabled = true;
|
|
224
|
+
try {
|
|
225
|
+
const result = await api(action + "-" + syncType, { id: row.id });
|
|
226
|
+
await load({ catalogOnly: true });
|
|
227
|
+
announce(action === "push" ? "Saved " + result.name + " in Cloud."
|
|
228
|
+
: result.updated ? "Updated " + result.name + " from Cloud." : "No Cloud edits to pull.");
|
|
229
|
+
} catch (error) { announce(error.message); }
|
|
230
|
+
finally { control.disabled = false; }
|
|
231
|
+
});
|
|
232
|
+
card.append(control);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (id === "skills") card.append(element("span", row.source === "cloud" ? "Cloud skill" : row.source === "markdown" ? "Local Markdown skill" : "Local text skill"));
|
|
236
|
+
if (id === "teams") card.append(element("span", row.source === "cloud" ? "Cloud team" : "Local team"));
|
|
237
|
+
section.append(card);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function openRun(targets, input = "", outputId = "", buttonId) {
|
|
243
|
+
pending = { targets, outputId, buttonId };
|
|
244
|
+
$("#run-header").replaceChildren(renderRunHeader(dom, {
|
|
245
|
+
title: targets.map(labelFor).join(" → "), kind: targets.length > 1 || targets[0].startsWith("workflow:") ? "Workflow" : "Agent",
|
|
246
|
+
closeId: "close-run", onClose: () => $("#drawer").close(),
|
|
247
|
+
}));
|
|
248
|
+
$("#prompt").value = input;
|
|
249
|
+
$("#run-result").textContent = "";
|
|
250
|
+
$("#run-status").textContent = "";
|
|
251
|
+
const picker = $("#model");
|
|
252
|
+
picker.replaceChildren(...project.models.map(model => new Option(model, model)));
|
|
253
|
+
const needsLocalModel = targets.some(id => id.startsWith("local:"));
|
|
254
|
+
picker.hidden = !needsLocalModel;
|
|
255
|
+
document.querySelector('label[for="model"]').hidden = !needsLocalModel;
|
|
256
|
+
$("#drawer").showModal();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
$("#runner").onsubmit = async event => {
|
|
260
|
+
event.preventDefault();
|
|
261
|
+
$("#run").disabled = true;
|
|
262
|
+
$("#close-run").disabled = true;
|
|
263
|
+
$("#run-status").textContent = "Running workflow…";
|
|
264
|
+
try {
|
|
265
|
+
const { answers } = await api("run", { targets: pending.targets, buttonId: pending.buttonId, input: $("#prompt").value, model: $("#model").value });
|
|
266
|
+
const text = answers.map(({ agent, output }) => agent + "\n" + output).join("\n\n");
|
|
267
|
+
$("#run-result").textContent = text;
|
|
268
|
+
if (pending.outputId) outputs.set(pending.outputId, answers.at(-1).output);
|
|
269
|
+
renderCanvas();
|
|
270
|
+
$("#run-status").textContent = "Run completed.";
|
|
271
|
+
} catch (error) {
|
|
272
|
+
$("#run-status").textContent = error.message;
|
|
273
|
+
} finally {
|
|
274
|
+
$("#run").disabled = false;
|
|
275
|
+
$("#close-run").disabled = false;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
$("#drawer").oncancel = event => { if ($("#run").disabled) event.preventDefault(); };
|
|
279
|
+
|
|
280
|
+
async function load({ catalogOnly = false } = {}) {
|
|
281
|
+
const next = await api("project");
|
|
282
|
+
if (catalogOnly) {
|
|
283
|
+
for (const key of ["agents", "workflows", "teams", "skills", "models", "mode"]) project[key] = next[key];
|
|
284
|
+
} else {
|
|
285
|
+
project = next;
|
|
286
|
+
dirty = false;
|
|
287
|
+
}
|
|
288
|
+
$("#project-name").textContent = project.name + (project.mode === "gated" ? " · Cloud connected" : project.mode === "standalone" ? " · Working locally" : "");
|
|
289
|
+
$("#open-memory").hidden = Boolean(project.exported);
|
|
290
|
+
if (project.exported) {
|
|
291
|
+
document.body.classList.add("exported");
|
|
292
|
+
document.title = project.name;
|
|
293
|
+
$("main h1").textContent = project.name;
|
|
294
|
+
} else {
|
|
295
|
+
renderCatalog();
|
|
296
|
+
renderInspector();
|
|
297
|
+
}
|
|
298
|
+
renderCanvas();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
for (const [kind, title] of Object.entries(names)) {
|
|
302
|
+
const item = button(title, () => add(kind));
|
|
303
|
+
item.draggable = true;
|
|
304
|
+
item.ondragstart = event => event.dataTransfer.setData("text/lyra-component", kind);
|
|
305
|
+
$("#palette").append(item);
|
|
306
|
+
}
|
|
307
|
+
$("#canvas").ondragover = event => { if (event.dataTransfer.types.includes("text/lyra-component")) event.preventDefault(); };
|
|
308
|
+
$("#canvas").ondrop = event => { event.preventDefault(); add(event.dataTransfer.getData("text/lyra-component")); };
|
|
309
|
+
$("#refresh").onclick = () => load({ catalogOnly: dirty }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
|
|
310
|
+
$("#pull").onclick = async () => {
|
|
311
|
+
$("#pull").disabled = true;
|
|
312
|
+
try {
|
|
313
|
+
const result = await api("pull", {});
|
|
314
|
+
await load({ catalogOnly: true });
|
|
315
|
+
announce(result.added + " added. " + result.preserved + " existing files preserved.");
|
|
316
|
+
} catch (error) { announce(error.message); }
|
|
317
|
+
finally { $("#pull").disabled = false; }
|
|
318
|
+
};
|
|
319
|
+
$("#save").onclick = async () => {
|
|
320
|
+
$("#save").disabled = true;
|
|
321
|
+
const snapshot = JSON.stringify(project.layout);
|
|
322
|
+
try {
|
|
323
|
+
const result = await api("save", { layout: JSON.parse(snapshot), revision: project.revision });
|
|
324
|
+
project.revision = result.revision;
|
|
325
|
+
dirty = snapshot !== JSON.stringify(project.layout);
|
|
326
|
+
announce(dirty ? "Saved. You have newer canvas edits." : "Saved to manifest.json.");
|
|
327
|
+
} catch (error) { announce(error.message); }
|
|
328
|
+
finally { $("#save").disabled = false; }
|
|
329
|
+
};
|
|
330
|
+
window.addEventListener("beforeunload", event => { if (dirty) { event.preventDefault(); event.returnValue = ""; } });
|
|
331
|
+
load().catch(error => announce(error.message));
|