agent-lyra 0.3.2 → 0.6.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/README.md +394 -119
- package/bin/agent-lyra.js +16 -0
- package/package.json +60 -56
- package/src/app-builder/export.js +50 -0
- package/src/app-builder/init.js +40 -11
- package/src/app-builder/preview.js +8 -0
- package/src/app-builder/saved-app.js +70 -0
- package/src/app-builder/saved-preview-browser.js +33 -0
- package/src/app-builder/saved-preview.html +24 -0
- package/src/app-builder/saved-preview.js +61 -0
- package/src/app-builder/validate.js +6 -7
- package/src/memory/cli.js +49 -0
- package/src/memory/contract.json +28 -0
- package/src/memory/index.d.ts +49 -0
- package/src/memory/index.js +259 -0
- package/src/memory/lifecycle.js +29 -0
- package/src/memory/proposals.js +84 -0
- package/src/memory/skills-cli.js +26 -0
- package/src/memory/sync.js +85 -0
- package/src/memory/validation.js +25 -0
- package/src/runtime/local-cli.js +4 -3
- package/src/studio/agent-ui.css +43 -0
- package/src/studio/agent-ui.js +32 -0
- package/src/studio/browser.js +331 -0
- package/src/studio/export.js +80 -0
- package/src/studio/index.html +37 -0
- package/src/studio/memory-actions.js +37 -0
- package/src/studio/memory-panel.js +200 -0
- package/src/studio/project.js +197 -0
- package/src/studio/pull-agent.js +72 -0
- package/src/studio/push.js +54 -0
- package/src/studio/python-agent.js +47 -0
- package/src/studio/python-agent.py +25 -0
- package/src/studio/server.js +143 -0
- package/src/studio/session.js +83 -0
- package/src/studio/studio.css +10 -0
- package/src/studio/sync.js +42 -0
- package/src/studio/workflow-sync.js +157 -0
|
@@ -0,0 +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));
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { pythonSource } from "./python-agent.js";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { readCatalog, resolveSequence, validateLayout } from "./project.js";
|
|
5
|
+
|
|
6
|
+
const runtime = [
|
|
7
|
+
"studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/project.js", "studio/sync.js", "studio/index.html",
|
|
8
|
+
"studio/browser.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
|
|
9
|
+
"memory/index.js", "memory/validation.js", "memory/proposals.js", "memory/sync.js", "memory/lifecycle.js", "memory/contract.json",
|
|
10
|
+
"runtime/local-cli.js", "runtime/run-agent.js", "studio/session.js", "studio/push.js", "studio/workflow-sync.js", "studio/pull-agent.js", "studio/python-agent.js", "studio/python-agent.py",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export async function exportStudioApp(app, root, directory) {
|
|
14
|
+
const layout = validateLayout(app.studio.layout);
|
|
15
|
+
if (!layout.length) throw new Error("Add components to the Studio canvas and save before exporting.");
|
|
16
|
+
const catalog = await readCatalog(root);
|
|
17
|
+
const agents = new Map();
|
|
18
|
+
const workflows = new Map();
|
|
19
|
+
const buttons = layout.filter(node => ["button", "agent-card"].includes(node.kind));
|
|
20
|
+
for (const button of buttons) {
|
|
21
|
+
if ((button.sourceId && !layout.some(node => node.id === button.sourceId && ["input", "textarea"].includes(node.kind))) ||
|
|
22
|
+
(button.outputId && !layout.some(node => node.id === button.outputId && node.kind === "output"))) {
|
|
23
|
+
throw new Error("Fix the input or output binding for " + button.label + " in Studio.");
|
|
24
|
+
}
|
|
25
|
+
let sequence;
|
|
26
|
+
try {
|
|
27
|
+
sequence = resolveSequence(catalog, button.targets);
|
|
28
|
+
if (button.kind === "agent-card" && !catalog.agents.has(button.targets[0])) {
|
|
29
|
+
throw new Error("Choose one agent for this card.");
|
|
30
|
+
}
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw new Error("Fix the run targets for " + button.label + ": " + error.message);
|
|
33
|
+
}
|
|
34
|
+
for (const { agentId } of sequence) agents.set(agentId, catalog.agents.get(agentId));
|
|
35
|
+
for (const target of button.targets.filter(id => id.startsWith("workflow:"))) {
|
|
36
|
+
const workflow = catalog.workflows.find(item => "workflow:" + item.id === target);
|
|
37
|
+
workflows.set(workflow.id, {
|
|
38
|
+
id: workflow.id, name: workflow.name, runnable: true,
|
|
39
|
+
steps: workflow.steps.map(({ agentId, task, input, output }) => ({ agentId, task, input, output })),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const name = typeof app.application?.name === "string" ? app.application.name : "Lyra app";
|
|
44
|
+
const files = await Promise.all(runtime.map(async file => [
|
|
45
|
+
"runtime/" + file, await readFile(new URL("../" + file, import.meta.url)),
|
|
46
|
+
]));
|
|
47
|
+
const pythonAgents = [...agents.values()].filter(agent => agent.source === "python");
|
|
48
|
+
const pythonFiles = new Map();
|
|
49
|
+
for (const agent of pythonAgents) {
|
|
50
|
+
if (pythonFiles.has(agent.file)) continue;
|
|
51
|
+
const path = await pythonSource(root, agent, false);
|
|
52
|
+
pythonFiles.set(agent.file, await readFile(path));
|
|
53
|
+
}
|
|
54
|
+
for (const [filename, source] of pythonFiles) files.push(["python-agents/" + filename, source]);
|
|
55
|
+
const pythonNotes = pythonAgents.length
|
|
56
|
+
? "\nInstall the Python SDK and any agent dependencies in your Python environment. Set LYRA_PYTHON to its interpreter if needed. The python-agents folder contains the source of the bound agents.\n"
|
|
57
|
+
: "";
|
|
58
|
+
files.push(
|
|
59
|
+
["LICENSE", await readFile(new URL("../../LICENSE", import.meta.url))],
|
|
60
|
+
["package.json", { name: "lyra-app", version: "1.0.0", private: true, type: "module", engines: { node: ">=22.13.0" }, scripts: { start: "node server.js" } }],
|
|
61
|
+
["manifest.json", { version: "3.0", application: { id: "lyra-app", name }, studio: { layout } }],
|
|
62
|
+
["catalog.json", { agents: [...agents.values()], workflows: [...workflows.values()] }],
|
|
63
|
+
[".gitignore", ".lyra/\n.env\n"],
|
|
64
|
+
["README.md", "# Run the exported Lyra app\n\nUse Node.js 22.13 or newer. Run `npm start` and open the loopback URL printed in the terminal.\n\nLocal agents require `OPENAI_API_KEY`. Cloud agents require `LYRA_API_KEY`, plus an OpenAI key configured in Cloud Models. Set credentials in the environment. The export includes system prompts for referenced local agents. The server is intended for local use.\n" + pythonNotes],
|
|
65
|
+
["server.js", 'import { readFile } from "node:fs/promises";\nimport { fileURLToPath } from "node:url";\nimport { startStudio } from "./runtime/studio/server.js";\n\nconst snapshot = JSON.parse(await readFile(new URL("./catalog.json", import.meta.url), "utf8"));\nconst catalog = { agents: new Map(snapshot.agents.map(agent => [agent.id, agent])), workflows: snapshot.workflows, teams: [] };\nconst { url } = await startStudio(fileURLToPath(new URL(".", import.meta.url)), { appCatalog: catalog });\nconsole.log("Lyra app: " + url);\n'],
|
|
66
|
+
);
|
|
67
|
+
try {
|
|
68
|
+
await mkdir(directory);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
if (error.code === "EEXIST") throw new Error("Choose a new directory. Existing files were preserved.");
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
for (const [file, contents] of files) {
|
|
74
|
+
const path = join(directory, file);
|
|
75
|
+
await mkdir(dirname(path), { recursive: true });
|
|
76
|
+
await writeFile(path, typeof contents === "string" || Buffer.isBuffer(contents)
|
|
77
|
+
? contents
|
|
78
|
+
: JSON.stringify(contents, null, 2) + "\n", { flag: "wx" });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
|
+
<title>AgentLyra Studio</title><link rel="stylesheet" href="/studio.css"><link rel="stylesheet" href="/agent-ui.css"><script src="/studio.js" type="module"></script>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<header><strong>AgentLyra Studio</strong><span id="project-name"></span><div><button id="open-memory" type="button" hidden>Memory</button> <button id="refresh">Reload agents</button> <button id="pull">Pull from Cloud</button> <button class="primary" id="save">Save layout</button></div></header>
|
|
9
|
+
<p role="status" id="status"></p>
|
|
10
|
+
<main>
|
|
11
|
+
<aside><h2>Components</h2><div id="palette"></div><h2>Agents</h2><div id="agents"></div><h2>Workflows</h2><div id="workflows"></div><h2>Teams</h2><div id="teams"></div><h2>Skills</h2><div id="skills"></div></aside>
|
|
12
|
+
<section><h1>App canvas</h1><p>Drop a component here or select it from the palette. Use the inspector to bind an Agent card or Run button to your inputs and outputs.</p><div id="canvas"></div></section>
|
|
13
|
+
<aside><h2>Inspector</h2><div id="inspector"></div></aside>
|
|
14
|
+
</main>
|
|
15
|
+
<dialog id="memory-panel" aria-labelledby="memory-title">
|
|
16
|
+
<header><h2 id="memory-title">Memory</h2><button id="close-memory" type="button">Close</button></header>
|
|
17
|
+
<p>Project memories stay local until you choose to upload a verified record.</p>
|
|
18
|
+
<p id="memory-status" role="status"></p>
|
|
19
|
+
<p id="memory-summary"></p>
|
|
20
|
+
<form id="memory-search"><label for="memory-query">Search project memories</label><input id="memory-query" maxlength="240"><button type="submit">Search</button></form>
|
|
21
|
+
<details><summary>Record a candidate</summary><form id="memory-create">
|
|
22
|
+
<label>Type<select name="type"><option>corrective</option><option>episodic</option><option>semantic</option><option>procedural</option></select></label>
|
|
23
|
+
<label>Title<input name="title" maxlength="160" required></label>
|
|
24
|
+
<label>Learning<textarea name="learning" maxlength="4000" required></textarea></label>
|
|
25
|
+
<label>Evidence IDs, separated by commas<input name="evidence" maxlength="2048"></label>
|
|
26
|
+
<button type="submit">Record candidate</button>
|
|
27
|
+
</form></details>
|
|
28
|
+
<details><summary>Pull a Cloud memory</summary><form id="memory-pull">
|
|
29
|
+
<label>Cloud memory ID<input name="id" maxlength="36" required></label>
|
|
30
|
+
<button type="submit">Pull from Cloud</button>
|
|
31
|
+
</form></details>
|
|
32
|
+
<div id="memory-list" aria-label="Project memories"></div>
|
|
33
|
+
<section id="memory-detail" aria-label="Selected memory"></section>
|
|
34
|
+
<details><summary>Skill proposals</summary><section id="memory-proposals" aria-label="Skill proposals"></section></details>
|
|
35
|
+
</dialog>
|
|
36
|
+
<dialog id="drawer" aria-labelledby="run-title"><form id="runner"><div id="run-header"></div><label for="model">Local model</label><select id="model"></select><label for="prompt">Input</label><textarea id="prompt" maxlength="4000" rows="6" required></textarea><button class="primary" id="run">Run</button><p role="status" id="run-status"></p><pre id="run-result"></pre></form></dialog>
|
|
37
|
+
</body></html>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { openMemoryStore } from "../memory/index.js";
|
|
2
|
+
import { syncMemory } from "../memory/sync.js";
|
|
3
|
+
|
|
4
|
+
export function memoryActions(root) {
|
|
5
|
+
return new Map([
|
|
6
|
+
["/api/memory/list", ({ query = "" }) => useStore(root, store => ({
|
|
7
|
+
records: query.trim() ? store.search(query, 50) : store.list(50), stats: store.stats(),
|
|
8
|
+
}))],
|
|
9
|
+
["/api/memory/record", body => useStore(root, store => store.record({
|
|
10
|
+
...body, evidence: typeof body.evidence === "string" ? body.evidence.split(",").map(value => value.trim()).filter(Boolean) : body.evidence,
|
|
11
|
+
}))],
|
|
12
|
+
["/api/memory/archive", ({ id }) => useStore(root, store => {
|
|
13
|
+
const record = store.archive(id);
|
|
14
|
+
if (!record) throw new Error("Memory record was not found.");
|
|
15
|
+
return record;
|
|
16
|
+
})],
|
|
17
|
+
["/api/memory/preview", ({ id }) => syncMemory(root, "preview", id)],
|
|
18
|
+
["/api/memory/push", ({ id, fingerprint }) => {
|
|
19
|
+
if (typeof fingerprint !== "string" || !/^[a-f0-9]{64}$/.test(fingerprint)) throw new Error("Preview the outbound memory before uploading.");
|
|
20
|
+
return syncMemory(root, "push", id, { confirmed: true, expectedPreview: fingerprint });
|
|
21
|
+
}],
|
|
22
|
+
["/api/memory/pull", ({ id }) => syncMemory(root, "pull", id)],
|
|
23
|
+
["/api/memory/compare", ({ id }) => syncMemory(root, "compare", id)],
|
|
24
|
+
["/api/memory/resolve", ({ id, choice, fingerprint }) =>
|
|
25
|
+
syncMemory(root, "resolve", id, { choice, expectedConflict: fingerprint })],
|
|
26
|
+
["/api/memory/verify", ({ id, evidence }) => useStore(root, store => store.verify(id, evidence))],
|
|
27
|
+
["/api/memory/proposals", () => useStore(root, store => store.proposals())],
|
|
28
|
+
["/api/memory/proposal-decision", ({ id, decision, evidence }) =>
|
|
29
|
+
useStore(root, store => store.decideProposal(id, decision, evidence))],
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function useStore(root, action) {
|
|
34
|
+
const store = await openMemoryStore(root);
|
|
35
|
+
try { return await action(store); }
|
|
36
|
+
finally { store.close(); }
|
|
37
|
+
}
|