agent-lyra 0.11.0 → 0.11.2

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 CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  [Get started](#get-started) · [SDK](#sdk-library) · [Coding setup](#coding-setup) · [Studio](#lyra-studio) · [App Builder](#lyra-app-builder) · [Memory](#project-memory-and-skill-proposals) · [Cloud](#agentlyra-cloud-and-marketplace)
8
8
 
9
- [Website](https://agentlyra.in/) · [Cloud console](https://console.agentlyra.in/) · [GitHub](https://github.com/agentlyra-labs/agent-lyra-sdk) · [npm](https://www.npmjs.com/package/agent-lyra) · [PyPI](https://pypi.org/project/agent-lyra/)
9
+ [Documentation](https://agentlyra.in/docs) · [Website](https://agentlyra.in/) · [Cloud console](https://console.agentlyra.in/) · [GitHub](https://github.com/agentlyra-labs/agent-lyra-sdk) · [npm](https://www.npmjs.com/package/agent-lyra) · [PyPI](https://pypi.org/project/agent-lyra/)
10
10
 
11
11
  ## Choose your starting point
12
12
 
@@ -201,7 +201,7 @@ In Studio's run drawer, select an execution provider for text agents. The **Exec
201
201
  | Codex CLI | Install the authenticated Codex CLI on PATH. Studio requests a read-only sandbox |
202
202
  | Claude Code CLI | Install the authenticated Claude Code CLI on PATH. Studio requests tool-free execution |
203
203
 
204
- On Windows, Studio discovers native CLI executables (`.exe`) on PATH. To run a saved Cloud text agent locally, connect an SDK key with resource sync permission so Studio can fetch the private agent definition. Choosing Lyra Cloud for a local text agent sends its instructions and input to Cloud for execution. Python and registered framework agents use their own runtimes. VS Code discovery uses workspace settings. Studio provider selection uses CLI or API credentials.
204
+ On Windows, Studio discovers native CLI executables (`.exe`) on PATH. To run a saved Cloud text agent locally, connect an SDK key with resource sync permission so Studio can fetch the private agent definition. Choosing Lyra Cloud for a local text agent sends its instructions and input to Cloud for execution. Python and registered framework agents use their own runtimes. VS Code discovery uses workspace settings. Studio provider selection uses CLI or API credentials. If you select the local OpenAI API and no key is configured, choose **Add OpenAI API key** in the run drawer. Studio saves the key in your user profile for reuse in Studio and Lyra CLI runs from the VS Code terminal. A terminal-provided key takes precedence. VS Code extensions and external agent runtimes manage their own credentials.
205
205
 
206
206
  Hosted Studio text runs record their status, model, duration, and step trace ID in Mission Control. The run drawer and terminal show the matching trace and run IDs. Local-only steps remain local. These SDK execution records store execution metadata and omit prompts and replies.
207
207
 
@@ -215,6 +215,8 @@ Use **Test action** in the editor to try a bound action, or `app preview` to run
215
215
 
216
216
  ## Lyra App Builder
217
217
 
218
+ Studio opens at `http://127.0.0.1:4174/`. Set `LYRA_STUDIO_PORT` before launching to use a different port. For Studio or app preview, set the corresponding variable to `0` to pick a free port automatically.
219
+
218
220
  Use `app init --name "My app"` in your project, then open `studio` to build its interface. Add components, drag to reorder, or set component widths in the inspector. Bind agent cards and run buttons to agents or runnable workflows from your project. Save to `manifest.json`, then preview or export the same layout.
219
221
 
220
222
  | Command | Purpose |
@@ -223,7 +225,7 @@ Use `app init --name "My app"` in your project, then open `studio` to build its
223
225
  | `app init --template agent` | Start with a side-by-side input and result and a run button ready to bind |
224
226
  | `app init --saved-agents [manifest.json]` | Create the guided Cloud chat using two saved agents |
225
227
  | `app validate <manifest.json>` | Check the manifest |
226
- | `app preview [manifest.json]` | Run the saved layout in a local browser. Set `LYRA_PREVIEW_PORT` to choose a port |
228
+ | `app preview [manifest.json]` | Run the saved layout at `http://127.0.0.1:4173/`. Set `LYRA_PREVIEW_PORT` to override it |
227
229
  | `app export <manifest.json> <new-directory>` | Export editable source to a new directory |
228
230
 
229
231
  These commands are available in npm and Python. To import an app or preview a public listing, see [Marketplace](#marketplace).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-lyra",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "Two-layer Lyra SDK with standalone local primitives and gated hosted agents.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -7,29 +7,32 @@ import { startSupportPreview } from "./support-template/support-preview.mjs";
7
7
 
8
8
  export async function runAppPreview(args, output = process.stdout) {
9
9
  if (args.length === 1 && args[0] === "--help") {
10
- output.write("Usage: agent-lyra app preview [manifest.json]\nSet LYRA_PREVIEW_PORT to override the loopback port.\n");
10
+ output.write("Usage: agent-lyra app preview [manifest.json]\nApp preview listens on 127.0.0.1:4173. Set LYRA_PREVIEW_PORT to override it, or use 0 to pick a free port.\n");
11
11
  return;
12
12
  }
13
13
  if (args.length > 1 || args[0]?.startsWith("-")) {
14
14
  throw new Error("Provide at most one manifest path. See agent-lyra app preview --help.");
15
15
  }
16
+ const port = Number(process.env.LYRA_PREVIEW_PORT?.trim() || 4173);
17
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
18
+ throw new Error("LYRA_PREVIEW_PORT must be an integer from 0 to 65535.");
19
+ }
16
20
  const app = await readAppManifest(args[0] ?? "manifest.json");
17
21
  if (Array.isArray(app?.studio?.layout)) {
18
22
  const path = resolve(args[0] ?? "manifest.json");
19
23
  if (basename(path) !== "manifest.json") throw new Error("Use the project manifest.json for a Studio app preview.");
20
- const port = Number(process.env.LYRA_PREVIEW_PORT ?? 0);
21
24
  const { url } = await startStudio(dirname(path), { preview: true, port }).catch(error => {
22
- if (error.code === "EADDRINUSE") throw new Error("Preview port is busy. Set LYRA_PREVIEW_PORT=0 to pick a free port.");
25
+ if (error.code === "EADDRINUSE") throw new Error("Preview port " + port + " is busy. Close the other server, choose another LYRA_PREVIEW_PORT, or set it to 0 to pick a free port.");
23
26
  throw error;
24
27
  });
25
28
  output.write("App preview: " + url + "\n");
26
29
  return;
27
30
  }
28
31
  if (app?.version === SAVED_VERSION) {
29
- const { url } = await startSavedPreview(app);
32
+ const { url } = await startSavedPreview(app, { port });
30
33
  output.write("App preview: " + url + "\n");
31
34
  return;
32
35
  }
33
36
  const manifest = await readSupportManifest(args[0] ?? "manifest.json");
34
- await startSupportPreview(manifest);
37
+ await startSupportPreview(manifest, { port });
35
38
  }
package/src/init.js CHANGED
@@ -43,7 +43,7 @@ function parseArgs(argv = process.argv.slice(2)) {
43
43
  }
44
44
 
45
45
  function printUsage() {
46
- output.write(`Usage:\n agent-lyra init\n lyra init\n\nOptions:\n --mode standalone|gated\n --domains coding,finance\n --stack mern,playwright\n --detect\n --api-key <key>\n --api-base-url <url>\n --dir <target-directory>\n --force\n`);
46
+ output.write(`Documentation: https://agentlyra.in/docs\n\nUsage:\n agent-lyra init\n lyra init\n\nOptions:\n --mode standalone|gated\n --domains coding,finance\n --stack mern,playwright\n --detect\n --api-key <key>\n --api-base-url <url>\n --dir <target-directory>\n --force\n`);
47
47
  }
48
48
 
49
49
  function printWelcomeBanner() {
@@ -1,4 +1,5 @@
1
- import { mkdir, writeFile } from "node:fs/promises";
1
+ import { homedir } from "node:os";
2
+ import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
2
3
  import { join } from "node:path";
3
4
  import { parseArgs } from "node:util";
4
5
  import { withProjectMemory } from "../memory/lifecycle.js";
@@ -126,8 +127,9 @@ export async function runLocalCli(argv, {
126
127
  options: { model: { type: "string" }, prompt: { type: "string" } },
127
128
  });
128
129
  if (!values.model?.trim() || !values.prompt?.trim()) throw new Error("--model and --prompt are required.");
129
- if (!env.OPENAI_API_KEY?.trim()) throw new Error("Set OPENAI_API_KEY in your terminal environment.");
130
- const provider = createOpenAIProvider(env.OPENAI_API_KEY.trim(), fetchRequest);
130
+ const key = env === process.env ? await readOpenAIKey() : env.OPENAI_API_KEY?.trim();
131
+ if (!key) throw new Error("Add an OpenAI API key in Studio or set OPENAI_API_KEY in your terminal.");
132
+ const provider = createOpenAIProvider(key, fetchRequest);
131
133
  const stages = teamCommand
132
134
  ? [
133
135
  { agentId: "draft-writer", system: "Write a first draft that addresses the user's request." },
@@ -159,3 +161,17 @@ export async function runLocalCli(argv, {
159
161
  }
160
162
  return true;
161
163
  }
164
+
165
+ export async function readOpenAIKey() {
166
+ if (process.env.OPENAI_API_KEY?.trim()) return process.env.OPENAI_API_KEY.trim();
167
+ const directory = join(homedir(), ".agent-lyra");
168
+ const path = join(directory, "providers.json");
169
+ try {
170
+ if (!(await lstat(directory)).isDirectory() || !(await lstat(path)).isFile()) return undefined;
171
+ const { OPENAI_API_KEY: key } = JSON.parse(await readFile(path, "utf8"));
172
+ return typeof key === "string" ? key.trim() : undefined;
173
+ } catch (error) {
174
+ if (error.code === "ENOENT") return undefined;
175
+ throw new Error("Studio could not read the saved OpenAI credential.");
176
+ }
177
+ }
@@ -18,6 +18,10 @@ function dom(tag, props, ...children) {
18
18
 
19
19
  const agentSources = { local: "Local agent", cloud: "Cloud agent", python: "Python agent", framework: "Registered framework agent" };
20
20
  const names = { heading:"Heading", text:"Text", input:"Text input", textarea:"Text area", button:"Run button", "agent-card":"Agent card", output:"Output" };
21
+ const componentMarks = {
22
+ heading: "H", text: "≡", input: "▏", textarea: "▤",
23
+ button: "▶", "agent-card": "◇", output: "↳",
24
+ };
21
25
  let project = { layout: [], agents: [], workflows: [], teams: [], skills: [] };
22
26
  let selected, pending;
23
27
  let libraryView = "palette";
@@ -79,7 +83,9 @@ function move(node, offset) {
79
83
  function renderCanvas() {
80
84
  const canvas = $("#canvas");
81
85
  canvas.replaceChildren();
82
- if (!project.layout.length) canvas.append(element("p", "Your canvas is empty."));
86
+ if (!project.layout.length) canvas.append(dom("div", { className: "canvas-empty" },
87
+ element("strong", "Start with a component"),
88
+ element("p", "Drag a component here or click one in the library.")));
83
89
  for (const node of project.layout) {
84
90
  const card = element("div");
85
91
  card.dataset.nodeId = node.id;
@@ -193,7 +199,7 @@ function renderInspector() {
193
199
  node.outputId = id; dirty = true;
194
200
  });
195
201
  if (node.kind === "agent-card") {
196
- addSelect(box, "Agent", [["", "Choose an agent"], ...project.agents.map(agent => [agent.id, agent.name])], node.targets[0], id => {
202
+ addSelect(box, "Agent", [["", "Choose an agent"], ...project.agents.filter(agent => !agent.linkedLocalId || agent.id === node.targets[0]).map(agent => [agent.id, agent.name])], node.targets[0], id => {
197
203
  if (node.label === names["agent-card"] || node.label === labelFor(node.targets[0])) {
198
204
  node.label = id ? labelFor(id) : names["agent-card"];
199
205
  }
@@ -210,7 +216,7 @@ function renderInspector() {
210
216
  box.append(row);
211
217
  });
212
218
  const options = [
213
- ...project.agents.map(agent => [agent.id, agent.name]),
219
+ ...project.agents.filter(agent => !agent.linkedLocalId).map(agent => [agent.id, agent.name]),
214
220
  ...project.workflows.filter(item => item.runnable).map(item => ["workflow:" + item.id, item.name + " (workflow)"]),
215
221
  ];
216
222
  addSelect(box, "Add next step", [["", "Choose agent or workflow"], ...options], "", id => {
@@ -231,9 +237,18 @@ function renderCatalog() {
231
237
  const id = libraryView;
232
238
  const section = $("#" + id);
233
239
  const query = search.value.trim().toLowerCase();
234
- const rows = project[id].filter(row => [row.name, row.source, row.framework, agentSources[row.source]]
240
+ const rows = project[id].filter(row => !row.linkedLocalId && [row.name, row.source, row.framework, agentSources[row.source]]
235
241
  .some(value => value?.toLowerCase().includes(query)));
242
+ const expanded = new Set([...section.querySelectorAll(".agent-options[open]")].map(item => item.dataset.agent));
236
243
  section.replaceChildren();
244
+ if (id === "agents" && !project.cloudConnected) {
245
+ const callout = dom("div", { className: "cloud-callout" },
246
+ element("p", "Connect to AgentLyra Cloud to pull, push, and sync agents."),
247
+ button("Connect to Cloud", openCloudSetup));
248
+ section.append(callout);
249
+ }
250
+ if (id === "skills" && rows.length) section.append(element("p",
251
+ "Open a skill to read its instructions. Skills are reference material here and cannot be run from the canvas."));
237
252
  if (!rows.length) section.append(element("p", query ? "No matching items." : "None in this project."));
238
253
  if (id === "agents" && project.frameworkCandidates?.length) {
239
254
  section.append(element("p", "LangGraph candidates: " + project.frameworkCandidates.map(item => item.name).join(", ") +
@@ -241,17 +256,18 @@ function renderCatalog() {
241
256
  }
242
257
  for (const row of rows) {
243
258
  if (id === "agents") {
244
- const push = row.source === "local" && project.mode !== "standalone"
245
- ? button("Push to Cloud", async () => {
259
+ const push = row.source === "local" && project.cloudConnected && row.syncStatus !== "synced"
260
+ ? button(row.syncStatus ? "Push local edits" : "Push to Cloud", async () => {
246
261
  if (!window.confirm("Send the name and instructions for " + row.name + " to your private AgentLyra Cloud workspace?")) return;
247
262
  push.disabled = true;
248
263
  try {
249
264
  const result = await api("push", { id: row.id });
250
- announce((result.created ? "Created " : "Synced ") + row.name + " in AgentLyra Cloud.");
265
+ await load({ catalogOnly: true });
266
+ announce((result.unchanged ? "Already synced " : result.created ? "Created " : "Synced ") + row.name + " in AgentLyra Cloud.");
251
267
  } catch (error) { announce(error.message); }
252
268
  finally { push.disabled = false; }
253
269
  }) : undefined;
254
- const pull = push && button("Pull agent edits", async () => {
270
+ const pull = row.syncStatus && project.cloudConnected && button("Pull agent edits", async () => {
255
271
  pull.disabled = true;
256
272
  try {
257
273
  const result = await api("pull-agent", { id: row.id });
@@ -260,7 +276,7 @@ function renderCatalog() {
260
276
  } catch (error) { announce(error.message); }
261
277
  finally { pull.disabled = false; }
262
278
  });
263
- const sync = row.source === "framework" && project.mode !== "standalone" && button("Sync registration", async () => {
279
+ const sync = row.source === "framework" && project.cloudConnected && button("Sync registration", async () => {
264
280
  try {
265
281
  const id = row.id.slice("framework:".length);
266
282
  const preview = await api("framework-preview", { id });
@@ -269,13 +285,26 @@ function renderCatalog() {
269
285
  announce("Registration synced. Open Cloud → Agents to view it.");
270
286
  } catch (error) { announce(error.message); }
271
287
  });
272
- const entry = element("details");
273
- entry.className = "library-entry";
274
- const summary = element("summary");
275
288
  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);
289
+ const name = dom("strong", { title: row.name }, row.name);
290
+ const metadata = dom("div", { className: "agent-meta" },
291
+ element("span", source), row.syncStatus && dom("span", { className: "pill" },
292
+ row.syncStatus === "synced" ? "Synced to Cloud" : "Local edits"));
293
+ const run = button("", () => openRun([row.id]));
294
+ run.className = "agent-icon agent-run";
295
+ run.title = "Run " + row.name;
296
+ run.setAttribute("aria-label", run.title);
297
+ run.append(dom("span", { className: "play-icon" }));
298
+ const entry = dom("article", { className: "library-entry" },
299
+ dom("div", { className: "agent-row" }, dom("div", { className: "agent-label" }, name, metadata), run));
300
+ if (push || pull || sync) {
301
+ const control = dom("summary", { className: "agent-icon", title: "Cloud actions",
302
+ "aria-label": "Cloud actions for " + row.name }, "⋯");
303
+ const options = dom("details", { className: "agent-options", open: expanded.has(row.id) },
304
+ control, dom("div", { className: "actions" }, push, pull, sync));
305
+ options.dataset.agent = row.id;
306
+ entry.append(options);
307
+ }
279
308
  section.append(entry);
280
309
  continue;
281
310
  }
@@ -288,7 +317,7 @@ function renderCatalog() {
288
317
  : element("span", "Run this workflow in Lyra Cloud."));
289
318
  }
290
319
  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") {
320
+ if (syncType && row.source !== "cloud" && project.cloudConnected) {
292
321
  for (const [action, label] of [["push", "Push to Cloud"], ["pull", "Pull " + syncType + " edits"]]) {
293
322
  const control = button(label, async () => {
294
323
  if (action === "push" && !window.confirm("Send this " + syncType + " definition to your private Cloud workspace?")) return;
@@ -304,7 +333,23 @@ function renderCatalog() {
304
333
  card.append(control);
305
334
  }
306
335
  }
307
- if (id === "skills") card.append(element("span", row.source === "cloud" ? "Cloud skill" : row.source === "markdown" ? "Local Markdown skill" : "Local text skill"));
336
+ if (id === "skills") {
337
+ card.append(element("span", row.source === "cloud" ? "Cloud skill" : row.source === "markdown" ? "Local Markdown skill" : "Local text skill"));
338
+ const details = element("details");
339
+ const body = dom("div", { className: "skill-instructions", "aria-label": "Skill instructions" });
340
+ details.append(element("summary", "View instructions"), body);
341
+ details.ontoggle = async () => {
342
+ if (!details.open) return;
343
+ body.textContent = "Loading instructions…";
344
+ try {
345
+ const skill = await api("open-skill", { id: row.id });
346
+ body.replaceChildren();
347
+ if (skill.description) body.append(element("p", skill.description));
348
+ body.append(element("pre", skill.instructions || "This skill has no saved instructions."));
349
+ } catch (error) { body.textContent = error.message; }
350
+ };
351
+ card.append(details);
352
+ }
308
353
  if (id === "teams") card.append(element("span", row.source === "cloud" ? "Cloud team" : "Local team"));
309
354
  section.append(card);
310
355
  }
@@ -343,6 +388,10 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
343
388
  const picker = $("#model");
344
389
  const modelLabel = $('label[for="model"]');
345
390
  picker.hidden = modelLabel.hidden = true;
391
+ $("#openai-setup").hidden = true;
392
+ $("#openai-setup").open = false;
393
+ $("#openai-key").value = "";
394
+ $("#openai-status").textContent = "";
346
395
  $("#run").disabled = true;
347
396
  $("#run").textContent = project.preview || project.exported ? "Run" : "Test action";
348
397
  $("#drawer").showModal();
@@ -373,12 +422,26 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
373
422
  picker.replaceChildren(...setup.models.map(model => new Option(model, model)));
374
423
  if (setup.models.includes(previousModel)) picker.value = previousModel;
375
424
  picker.hidden = modelLabel.hidden = !setup.needsModel;
425
+ $("#openai-setup").hidden = !setup.needsOpenAIKey || project.preview || project.exported;
376
426
  action.inputKind = setup.inputKind;
377
427
  if (setup.inputKind === "json") $("#run-input-label").textContent = "JSON input";
378
428
  action.ready = setup.issues.length === 0;
379
429
  $("#run-status").textContent = setup.issues.join(" ");
380
430
  $("#run").disabled = !action.ready;
381
431
  };
432
+ $("#save-openai").onclick = async () => {
433
+ const button = $("#save-openai");
434
+ const key = $("#openai-key");
435
+ button.disabled = true;
436
+ try {
437
+ await api("openai-key", { key: key.value });
438
+ key.value = "";
439
+ await refreshPlan(providerPicker.value);
440
+ if (pending === action && action.ready) $("#run-status").textContent = "OpenAI configured. Ready to run.";
441
+ } catch (error) {
442
+ if (pending === action) $("#openai-status").textContent = error.message;
443
+ } finally { button.disabled = false; }
444
+ };
382
445
  providerPicker.onchange = async () => {
383
446
  action.ready = false;
384
447
  $("#run").disabled = true;
@@ -463,12 +526,15 @@ drawer.onclick = event => {
463
526
  async function load({ catalogOnly = false } = {}) {
464
527
  const next = await api("project");
465
528
  if (catalogOnly) {
466
- for (const key of ["agents", "workflows", "teams", "skills", "mode", "frameworkCandidates"]) project[key] = next[key];
529
+ for (const key of ["agents", "workflows", "teams", "skills", "mode", "frameworkCandidates", "cloudConnected", "hasCloudKey"]) project[key] = next[key];
467
530
  } else {
468
531
  project = next;
469
532
  dirty = false;
470
533
  }
471
- $("#project-name").textContent = project.name + (project.mode === "gated" ? " · Cloud connected" : project.mode === "standalone" ? " · Working locally" : "");
534
+ $("#project-name").textContent = project.name;
535
+ $("#cloud-state").textContent = project.cloudConnected ? "Cloud connected" : "Working locally";
536
+ $("#pull").hidden = !project.cloudConnected;
537
+ $("#connect-cloud").hidden = project.cloudConnected;
472
538
  $("#open-memory").hidden = Boolean(project.exported || project.preview);
473
539
  if (project.exported || project.preview) {
474
540
  document.body.classList.add("exported");
@@ -484,6 +550,11 @@ async function load({ catalogOnly = false } = {}) {
484
550
 
485
551
  for (const [kind, title] of Object.entries(names)) {
486
552
  const item = button(title, () => add(kind));
553
+ item.className = "component-tile";
554
+ const mark = element("span", componentMarks[kind]);
555
+ mark.className = "component-mark";
556
+ mark.setAttribute("aria-hidden", "true");
557
+ item.replaceChildren(mark, element("span", title));
487
558
  item.draggable = true;
488
559
  item.ondragstart = event => event.dataTransfer.setData("text/lyra-component", kind);
489
560
  $("#palette").append(item);
@@ -538,6 +609,30 @@ $("#canvas").ondrop = event => {
538
609
  change();
539
610
  };
540
611
  $("#refresh").onclick = () => load({ catalogOnly: dirty }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
612
+ function openCloudSetup() {
613
+ $("#cloud-key").value = "";
614
+ $("#cloud-key").required = !project.hasCloudKey;
615
+ $("#cloud-key-help").replaceChildren(
616
+ project.hasCloudKey ? "Leave this blank to use your saved AgentLyra key. " : "Create a key with resource sync permission. ",
617
+ dom("a", { href: "https://console.agentlyra.in/mcp-servers", target: "_blank", rel: "noopener noreferrer" }, "Open API Keys"));
618
+ $("#cloud-error").textContent = "";
619
+ $("#cloud-setup").showModal();
620
+ }
621
+ $("#connect-cloud").onclick = openCloudSetup;
622
+ $("#close-cloud").onclick = () => $("#cloud-setup").close();
623
+ $("#cloud-setup").addEventListener("close", () => { $("#cloud-key").value = ""; });
624
+ $("#cloud-form").onsubmit = async event => {
625
+ event.preventDefault();
626
+ const control = event.submitter;
627
+ control.disabled = true;
628
+ try {
629
+ await api("connect-cloud", { key: $("#cloud-key").value.trim() });
630
+ $("#cloud-setup").close();
631
+ await load({ catalogOnly: true });
632
+ announce("Cloud mode enabled. You can now pull agents or sync edits.");
633
+ } catch (error) { $("#cloud-error").textContent = error.message; }
634
+ finally { control.disabled = false; }
635
+ };
541
636
  $("#pull").onclick = async () => {
542
637
  $("#pull").disabled = true;
543
638
  try {
@@ -5,7 +5,7 @@ import { readCatalog, resolveSequence, validateLayout, validateRunBindings } fro
5
5
 
6
6
  const runtime = [
7
7
  "resource-files.js",
8
- "studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/project.js", "studio/sync.js", "studio/index.html",
8
+ "studio/server.js", "studio/memory-actions.js", "studio/memory-panel.js", "studio/project.js", "studio/sync.js", "studio/index.html", "studio/lyra-icon.png",
9
9
  "studio/browser.js", "studio/workflow-editor.js", "studio/cli-providers.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
10
10
  "memory/index.js", "memory/local-store.js", "memory/cloud-sync-actions.js", "memory/validation.js", "memory/proposals.js", "memory/sync.js", "memory/lifecycle.js", "memory/contract.json",
11
11
  "framework/agent.js", "framework/run.py", "framework/mda.js",
@@ -5,12 +5,23 @@
5
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
6
  </head>
7
7
  <body>
8
- <header><strong>AgentLyra Studio</strong><span id="project-name"></span>
8
+ <header class="studio-header">
9
+ <div class="studio-brand"><img class="studio-mark" src="/lyra-icon.png" width="34" height="34" alt=""><div><strong>AgentLyra Studio</strong><span id="project-name"></span></div></div>
9
10
  <nav id="studio-views" aria-label="Studio views">
10
11
  <button id="show-layout" type="button" aria-pressed="true">Layout</button>
11
12
  <button id="show-workflow" type="button" aria-pressed="false">Workflow</button>
12
- </nav><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>
13
+ </nav><div class="toolbar"><span id="cloud-state" class="pill"></span><button id="open-memory" type="button" hidden>Memory</button> <button id="refresh">Reload agents</button> <button id="connect-cloud" type="button" hidden>Connect to Cloud</button> <button id="pull" type="button" hidden>Pull from Cloud</button> <button class="primary" id="save">Save layout</button></div></header>
13
14
  <p role="status" id="status"></p>
15
+ <dialog id="cloud-setup" aria-labelledby="cloud-title">
16
+ <header><h2 id="cloud-title">Connect to AgentLyra Cloud</h2><button id="close-cloud" type="button">Close</button></header>
17
+ <p>Connect your private workspace to pull agents, send local edits, and sync linked resources.</p>
18
+ <form id="cloud-form">
19
+ <label for="cloud-key">AgentLyra SDK key</label>
20
+ <input id="cloud-key" type="password" maxlength="80" autocomplete="off" spellcheck="false">
21
+ <p id="cloud-key-help"></p>
22
+ <button type="submit" class="primary">Connect workspace</button>
23
+ <p id="cloud-error" role="status"></p>
24
+ </form></dialog>
14
25
  <main>
15
26
  <aside id="library" aria-labelledby="library-title">
16
27
  <h2 id="library-title">Project library</h2>
@@ -70,5 +81,10 @@
70
81
  <details><summary>Skill proposals</summary><section id="memory-proposals" aria-label="Skill proposals"></section></details>
71
82
  </dialog>
72
83
  <button id="resume-run" type="button" class="primary" hidden>Resume run</button>
73
- <dialog id="drawer" aria-labelledby="run-title"><form id="runner"><div id="run-header"></div><button id="minimize-run" type="button">Minimize</button><section id="run-plan" aria-label="Execution steps" hidden></section><label for="execution-provider" hidden>Local execution provider</label><select id="execution-provider" hidden></select><label for="model" hidden>Local OpenAI model</label><select id="model" hidden></select><label id="run-input-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>
84
+ <dialog id="drawer" aria-labelledby="run-title"><form id="runner"><div id="run-header"></div><button id="minimize-run" type="button">Minimize</button><section id="run-plan" aria-label="Execution steps" hidden></section><label for="execution-provider" hidden>Local execution provider</label><select id="execution-provider" hidden></select><label for="model" hidden>Local OpenAI model</label><select id="model" hidden></select><details id="openai-setup" hidden><summary>Add OpenAI API key</summary>
85
+ <p>Save the key on this computer for Studio and Lyra SDK commands run from your VS Code terminal.</p>
86
+ <label for="openai-key">OpenAI API key</label>
87
+ <input id="openai-key" type="password" maxlength="503" autocomplete="off" spellcheck="false">
88
+ <button id="save-openai" type="button">Save key</button><p id="openai-status" role="status"></p>
89
+ </details><label id="run-input-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>
74
90
  </body></html>
Binary file
@@ -5,8 +5,8 @@ import { join, dirname, basename } from "node:path";
5
5
  import { resourceFiles } from "../resource-files.js";
6
6
  import { frameworkDescriptor, runFrameworkAgent } from "../framework/agent.js";
7
7
  import { createSavedAgentClient } from "../app-builder/saved-app.js";
8
- import { createOpenAIProvider, openStore } from "../runtime/local-cli.js";
9
- import { readMode, readSdkKey, requireCloudMode } from "./session.js";
8
+ import { createOpenAIProvider, openStore, readOpenAIKey } from "../runtime/local-cli.js";
9
+ import { agentRevision, readAgentLink, readMode, readSdkKey, requireCloudMode } from "./session.js";
10
10
  import { pythonDescriptor, runPythonAgent } from "./python-agent.js";
11
11
  import { withProjectMemory } from "../memory/lifecycle.js";
12
12
  import { runAgent } from "../runtime/run-agent.js";
@@ -52,7 +52,7 @@ export function readLocalAgent(source) {
52
52
  return { id: "local:" + id, name, source: "local", prompt };
53
53
  }
54
54
 
55
- export async function readCatalog(root) {
55
+ export async function readCatalog(root, { includeSkillInstructions = false } = {}) {
56
56
  const directory = join(root, ".lyra", "agents");
57
57
  const agents = new Map();
58
58
  for (const name of await resourceFiles(directory, ".md")) {
@@ -92,6 +92,18 @@ export async function readCatalog(root) {
92
92
  const id = "python:" + item.id;
93
93
  if (!agents.has(id)) agents.set(id, { id, name: item.name, source: "python", ...descriptor });
94
94
  }
95
+ for (const agent of [...agents.values()]) {
96
+ if (agent.source !== "local") continue;
97
+ const link = await readAgentLink(root, agent.id).catch(error => {
98
+ if (error instanceof SyntaxError) return undefined;
99
+ throw error;
100
+ });
101
+ if (!link) continue;
102
+ const id = "cloud:" + link.cloudId;
103
+ agent.syncStatus = agentRevision(agent.name, agent.prompt) === link.revision ? "synced" : "edited";
104
+ // Keep legacy Cloud bindings runnable while offering one card for this linked agent.
105
+ agents.set(id, { id, name: agents.get(id)?.name ?? agent.name, source: "cloud", linkedLocalId: agent.id });
106
+ }
95
107
  const skills = await records("skills");
96
108
  const skillRoot = join(root, ".lyra", "skills");
97
109
  for (const relative of await resourceFiles(skillRoot, "SKILL.md")) {
@@ -107,7 +119,12 @@ export async function readCatalog(root) {
107
119
  const source = await readFile(metadata, "utf8");
108
120
  const front = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(source);
109
121
  const name = front && markdownValue(front[1], "name");
110
- if (name) skills.push({ id: "markdown:" + folder.name, name, source: "markdown" });
122
+ if (name) skills.push({
123
+ id: "markdown:" + folder.name,
124
+ name,
125
+ source: "markdown",
126
+ ...(includeSkillInstructions ? { body: source.slice(front[0].length).trim() } : {}),
127
+ });
111
128
  }
112
129
  return { agents, workflows: await records("workflows"), teams: await records("teams"), skills };
113
130
  }
@@ -216,9 +233,11 @@ export async function describeRun(root, targets, appCatalog, provider) {
216
233
  provider ??= needsModel ? (hasCloud && cloudAvailable ? "cloud" : "openai") : undefined;
217
234
  const models = needsModel && provider === 'openai' ? studioModels() : [];
218
235
  const issues = [];
219
- if (needsModel && provider === 'openai' && !process.env.OPENAI_API_KEY?.trim()) {
220
- issues.push("Set OPENAI_API_KEY in the terminal that starts Studio, then restart Studio.");
221
- }
236
+ const needsOpenAIKey = needsModel && provider === "openai" &&
237
+ !(appCatalog ? process.env.OPENAI_API_KEY?.trim() : await readOpenAIKey());
238
+ if (needsOpenAIKey) issues.push(appCatalog
239
+ ? "Configure an OpenAI API key on the app server."
240
+ : "Add an OpenAI API key to run with the OpenAI API, or choose another provider.");
222
241
  if (needsModel && provider === 'openai' && !models.length) issues.push("Set LYRA_STUDIO_MODELS to a comma-separated list of OpenAI model IDs.");
223
242
  if (hasCloud || provider === "cloud") {
224
243
  try {
@@ -231,7 +250,7 @@ export async function describeRun(root, targets, appCatalog, provider) {
231
250
  name: agent.name, framework: agent.framework, ...runtimeLabels[agent.source],
232
251
  }));
233
252
  if (needsModel && !providers.includes(provider)) issues.push('Selected provider is unavailable.');
234
- return { steps: steps.map((step, i) => ['local', 'cloud'].includes(agents[i].source) ? { ...step, location: provider === 'cloud' ? 'Lyra Cloud' : 'Local project', provider } : step), providers, provider, models, needsModel: needsModel && provider === 'openai', issues, inputKind: agents[0].source === "framework" ? agents[0].input : "text" };
253
+ return { steps: steps.map((step, i) => ['local', 'cloud'].includes(agents[i].source) ? { ...step, location: provider === 'cloud' ? 'Lyra Cloud' : 'Local project', provider } : step), providers, provider, models, needsModel: needsModel && provider === 'openai', issues, needsOpenAIKey, inputKind: agents[0].source === "framework" ? agents[0].input : "text" };
235
254
  }
236
255
 
237
256
  export async function runSelection(root, { targets, input, model, provider }, catalog) {
@@ -247,8 +266,11 @@ export async function runSelection(root, { targets, input, model, provider }, ca
247
266
  const cli = exported ? [] : await availableCliProviders();
248
267
  provider ??= hasCloud ? "cloud" : "openai";
249
268
  if (local && !['openai', 'cloud', ...cli].includes(provider)) throw new Error('Selected provider is unavailable.');
250
- if (local && provider === 'openai' && (!process.env.OPENAI_API_KEY?.trim() || !modelId.test(model ?? ""))) {
251
- throw new Error("Set OPENAI_API_KEY and select an OpenAI model for local agents.");
269
+ const openAIKey = local && provider === "openai"
270
+ ? exported ? process.env.OPENAI_API_KEY?.trim() : await readOpenAIKey()
271
+ : undefined;
272
+ if (local && provider === "openai" && (!openAIKey || !modelId.test(model ?? ""))) {
273
+ throw new Error("Configure an OpenAI API key and choose a model for this run.");
252
274
  }
253
275
  let cloud = null;
254
276
  if (hasCloud || provider === "cloud") {
@@ -307,7 +329,7 @@ export async function runSelection(root, { targets, input, model, provider }, ca
307
329
  const definition = agent.source === "cloud" ? await cloud.definition(agent.id.slice(6)) : agent;
308
330
  const request = { model, messages: [{ role: "system", content: definition.prompt }, { role: "user", content: text }] };
309
331
  const event = await runAgent({
310
- agentId: agent.id, store, traceId: status.traceId, provider: createOpenAIProvider(process.env.OPENAI_API_KEY, fetch),
332
+ agentId: agent.id, store, traceId: status.traceId, provider: createOpenAIProvider(openAIKey, fetch),
311
333
  request: exported ? request : await withProjectMemory(root, request),
312
334
  });
313
335
  status.runId = event.run_id;
@@ -1,11 +1,10 @@
1
- import { createHash, randomUUID } from "node:crypto";
1
+ import { randomUUID } from "node:crypto";
2
2
  import { lstat, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { resourceFiles } from "../resource-files.js";
5
5
  import { readLocalAgent } from "./project.js";
6
- import { readMode, readSdkKey, requireCloudMode } from "./session.js";
6
+ import { agentRevision as hash, readMode, readSdkKey, requireCloudMode } from "./session.js";
7
7
 
8
- const hash = (name, systemPrompt) => createHash("sha256").update(JSON.stringify({ name, systemPrompt })).digest("hex");
9
8
  const digest = /^[a-f0-9]{64}$/;
10
9
 
11
10
  export async function pullAgentEdits(root, id, { request = fetch, key } = {}) {
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
2
2
  import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
3
  import { join, resolve } from "node:path";
4
4
  import { readCatalog } from "./project.js";
5
- import { readMode, readSdkKey, requireCloudMode } from "./session.js";
5
+ import { agentRevision, readMode, readSdkKey, requireCloudMode } from "./session.js";
6
6
 
7
7
  export async function pushStudioAgent(root, id, { key, request = fetch } = {}) {
8
8
  requireCloudMode(await readMode(root));
@@ -29,6 +29,9 @@ export async function pushStudioAgent(root, id, { key, request = fetch } = {}) {
29
29
  } catch (error) {
30
30
  if (error.code !== "ENOENT") throw error;
31
31
  }
32
+ if (link && agentRevision(agent.name, agent.prompt) === link.revision) {
33
+ return { name: agent.name, created: false, unchanged: true };
34
+ }
32
35
  const linkId = link?.linkId ?? createHash("sha256").update(resolve(root) + "\0" + id).digest("hex");
33
36
  const response = await request("https://api.agentlyra.in/api/sdk/v1/studio/agents/" + linkId, {
34
37
  method: "PUT", headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
@@ -3,7 +3,7 @@ import { memoryActions } from "./memory-actions.js";
3
3
  import { createServer } from "node:http";
4
4
  import { readFile } from "node:fs/promises";
5
5
  import { describeRun, readCatalog, readLayout, runSelection, saveLayout, studioModels, validateRunBindings } from "./project.js";
6
- import { readMode } from "./session.js";
6
+ import { readMode, readSdkKey, saveOpenAIKey, switchMode } from "./session.js";
7
7
  import { openStudioWorkflow, saveStudioWorkflow, syncSkill, syncTeam, syncWorkflow } from "./workflow-sync.js";
8
8
  import { pullAgentEdits } from "./pull-agent.js";
9
9
  import { pushStudioAgent } from "./push.js";
@@ -12,6 +12,7 @@ import { pullStudio } from "./sync.js";
12
12
  export async function startStudio(root, { port = 0, run = runSelection, pull = pullStudio, appCatalog, preview = false } = {}) {
13
13
  const assets = new Map();
14
14
  for (const [route, name, mime] of [
15
+ ["/lyra-icon.png", "lyra-icon.png", "image/png"],
15
16
  ["/memory-panel.js", "memory-panel.js", "text/javascript"],
16
17
  ["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
17
18
  ["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/workflow-editor.js", "workflow-editor.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
@@ -25,6 +26,26 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
25
26
  if (typeof fingerprint !== "string") throw new Error("Preview the registration before syncing.");
26
27
  return syncFrameworkAgent(root, id, fingerprint);
27
28
  }],
29
+ ["/api/openai-key", async ({ key }) => {
30
+ await saveOpenAIKey(key);
31
+ return { configured: true };
32
+ }],
33
+ ["/api/connect-cloud", async ({ key }) => {
34
+ await switchMode(root, "gated", key ? ["--replace-key"] : [], {
35
+ output: { write() {} }, prompt: async () => key,
36
+ });
37
+ return { connected: true };
38
+ }],
39
+ ["/api/open-skill", async ({ id }) => {
40
+ if (typeof id !== "string") throw new Error("Choose a skill from the library.");
41
+ const { skills } = await readCatalog(root, { includeSkillInstructions: true });
42
+ const skill = skills.find(item => item.id === id);
43
+ if (!skill) throw new Error("This skill is no longer in the project. Reload the library.");
44
+ return {
45
+ description: typeof skill.description === "string" ? skill.description.slice(0, 1024) : "",
46
+ instructions: typeof skill.body === "string" ? skill.body.slice(0, 64_000) : "",
47
+ };
48
+ }],
28
49
  ["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
29
50
  ["/api/pull", () => pull(root)],
30
51
  ["/api/push", ({ id }) => pushStudioAgent(root, id)],
@@ -53,8 +74,8 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
53
74
  const server = createServer(async (req, res) => {
54
75
  const send = (status, data, type = "application/json") => {
55
76
  res.writeHead(status, {
56
- "Content-Type": type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
57
- "Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; frame-ancestors 'none'",
77
+ "Content-Type": type.startsWith("image/") ? type : type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
78
+ "Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self'; connect-src 'self'; frame-ancestors 'none'",
58
79
  });
59
80
  res.end(type === "application/json" ? JSON.stringify(data) : data);
60
81
  };
@@ -67,12 +88,17 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
67
88
  try {
68
89
  if (req.method === "GET" && req.url === "/api/project") {
69
90
  const catalog = appCatalog ?? await readCatalog(root);
91
+ const mode = appCatalog ? undefined : await readMode(root);
92
+ const hasCloudKey = !appCatalog && Boolean(await readSdkKey(root));
70
93
  return send(200, {
71
94
  ...await readLayout(root),
72
95
  exported: Boolean(appCatalog),
73
96
  preview,
74
- mode: appCatalog ? undefined : await readMode(root),
75
- agents: [...catalog.agents.values()].map(({ id, name, source, framework }) => ({ id, name, source, framework })),
97
+ mode,
98
+ hasCloudKey,
99
+ cloudConnected: mode !== "standalone" && hasCloudKey,
100
+ agents: [...catalog.agents.values()].map(({ id, name, source, framework, syncStatus, linkedLocalId }) =>
101
+ ({ id, name, source, framework, syncStatus, linkedLocalId })),
76
102
  frameworkCandidates: appCatalog ? [] : await discoverFrameworkAgents(root).catch(() => []),
77
103
  workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
78
104
  skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
@@ -129,7 +155,7 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
129
155
 
130
156
  export async function runStudio(args, output = process.stdout) {
131
157
  if (args[0] === "--help") {
132
- output.write("Usage: agent-lyra studio | agent-lyra studio pull | agent-lyra studio push <local-agent-id> | agent-lyra studio pull-agent <local-agent-id> | agent-lyra studio push-workflow <workflow-id> | agent-lyra studio pull-workflow <workflow-id> | agent-lyra studio push-team <team-id> | agent-lyra studio pull-team <team-id> | agent-lyra studio push-skill <skill-id> | agent-lyra studio pull-skill <skill-id>\n");
158
+ output.write("Usage: agent-lyra studio | agent-lyra studio pull | agent-lyra studio push <local-agent-id> | agent-lyra studio pull-agent <local-agent-id> | agent-lyra studio push-workflow <workflow-id> | agent-lyra studio pull-workflow <workflow-id> | agent-lyra studio push-team <team-id> | agent-lyra studio pull-team <team-id> | agent-lyra studio push-skill <skill-id> | agent-lyra studio pull-skill <skill-id>\nStudio listens on 127.0.0.1:4174. Set LYRA_STUDIO_PORT to override it, or use 0 to pick a free port.\n");
133
159
  return;
134
160
  }
135
161
  if (args.length === 1 && args[0] === "pull") {
@@ -140,7 +166,7 @@ export async function runStudio(args, output = process.stdout) {
140
166
  if (args.length === 2 && args[0] === "push") {
141
167
  const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
142
168
  const result = await pushStudioAgent(process.cwd(), id);
143
- output.write((result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
169
+ output.write((result.unchanged ? "Already synced " : result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
144
170
  return;
145
171
  }
146
172
  if (args.length === 2 && args[0] === "pull-agent") {
@@ -159,6 +185,15 @@ export async function runStudio(args, output = process.stdout) {
159
185
  return;
160
186
  }
161
187
  if (args.length) throw new Error("See agent-lyra studio --help.");
162
- const { url } = await startStudio(process.cwd());
188
+ const port = Number(process.env.LYRA_STUDIO_PORT?.trim() || 4174);
189
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
190
+ throw new Error("LYRA_STUDIO_PORT must be an integer from 0 to 65535.");
191
+ }
192
+ const { url } = await startStudio(process.cwd(), { port }).catch(error => {
193
+ if (error.code === "EADDRINUSE") {
194
+ throw new Error("Studio port " + port + " is busy. Close the other server, choose another LYRA_STUDIO_PORT, or set it to 0 to pick a free port.");
195
+ }
196
+ throw error;
197
+ });
163
198
  output.write("AgentLyra Studio: " + url + "\n");
164
199
  }
@@ -1,4 +1,4 @@
1
- import { randomUUID } from "node:crypto";
1
+ import { createHash, randomUUID } from "node:crypto";
2
2
  import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { join } from "node:path";
@@ -46,6 +46,30 @@ export async function readSdkKey(root, { home = account() } = {}) {
46
46
  return validKey(workspaceKey) ? workspaceKey : undefined;
47
47
  }
48
48
 
49
+ export const agentRevision = (name, systemPrompt) =>
50
+ createHash("sha256").update(JSON.stringify({ name: name.trim(), systemPrompt: systemPrompt.trim() })).digest("hex");
51
+
52
+ export async function readAgentLink(root, id) {
53
+ if (!/^local:[a-zA-Z0-9][a-zA-Z0-9_-]{0,95}$/.test(id)) return undefined;
54
+ const directory = join(workspace(root), "agent-links");
55
+ if (!(await lstat(directory).catch(error => {
56
+ if (error.code === "ENOENT") return null;
57
+ throw error;
58
+ }))?.isDirectory()) return undefined;
59
+ const link = await readJson(join(directory, id.slice(6) + ".json"));
60
+ return /^[a-f0-9]{64}$/.test(link.linkId ?? "") &&
61
+ /^[a-f0-9]{64}$/.test(link.revision ?? "") &&
62
+ /^[a-f0-9]{24}$/i.test(link.cloudId ?? "") ? link : undefined;
63
+ }
64
+
65
+ export async function saveOpenAIKey(value) {
66
+ const key = typeof value === "string" ? value.trim() : "";
67
+ if (!/^sk-[a-zA-Z0-9_-]{16,500}$/.test(key)) {
68
+ throw new Error("Paste an OpenAI API key beginning with sk-.");
69
+ }
70
+ await saveJson(account(), "providers.json", { OPENAI_API_KEY: key });
71
+ }
72
+
49
73
  async function promptKey() {
50
74
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
51
75
  throw new Error("Run this command in your IDE terminal to enter an AgentLyra API key, or supply LYRA_API_KEY in the environment.");
@@ -24,15 +24,27 @@ main:has(#inspector-panel:not([hidden])) {
24
24
  #library-tabs {
25
25
  display: flex;
26
26
  flex-wrap: wrap;
27
- gap: .35rem;
28
- margin-bottom: .75rem;
27
+ gap: .15rem .7rem;
28
+ margin: 0 0 .85rem;
29
+ padding: 0 0 .25rem;
30
+ border-bottom: 1px solid var(--studio-line);
29
31
  }
30
32
  #library-tabs button {
33
+ min-height: 34px;
34
+ padding: .28rem .08rem;
35
+ border: 0;
36
+ border-bottom: 2px solid transparent;
37
+ border-radius: 0;
38
+ background: transparent;
39
+ color: var(--studio-muted);
31
40
  font-size: .8rem;
32
41
  }
42
+ #library-tabs button:hover,
33
43
  #library-tabs button[aria-pressed="true"] {
34
- background: #e6f0e9;
35
- border-color: #478367;
44
+ color: var(--studio-green);
45
+ }
46
+ #library-tabs button[aria-pressed="true"] {
47
+ border-bottom-color: var(--studio-green);
36
48
  }
37
49
  #library-search-label {
38
50
  font-size: .8rem;
@@ -46,26 +58,6 @@ main:has(#inspector-panel:not([hidden])) {
46
58
  #library-content #palette {
47
59
  margin: 0;
48
60
  }
49
- .library-entry {
50
- border-bottom: 1px solid #d9e4dd;
51
- }
52
- .library-entry summary {
53
- cursor: pointer;
54
- padding: .55rem .25rem;
55
- overflow-wrap: anywhere;
56
- }
57
- .library-entry summary span {
58
- display: block;
59
- padding-left: 1.15rem;
60
- color: #47675a;
61
- font-size: .8rem;
62
- }
63
- .library-entry .actions {
64
- padding: 0 .25rem .6rem;
65
- }
66
- .library-entry .actions button {
67
- font-size: .8rem;
68
- }
69
61
  .inspector-heading {
70
62
  display: flex;
71
63
  justify-content: space-between;
@@ -255,3 +247,214 @@ main:has(#inspector-panel:not([hidden])) {
255
247
  margin: 1rem 0;
256
248
  padding-left: .85rem;
257
249
  }
250
+
251
+
252
+ /* AgentLyra workspace */
253
+ :root {
254
+ --studio-ink: #192b24;
255
+ --studio-muted: #52675e;
256
+ --studio-line: #dce6df;
257
+ --studio-green: #214e3d;
258
+ --studio-tint: #eaf3ed;
259
+ }
260
+ body {
261
+ background: #f4f7f5;
262
+ color: var(--studio-ink);
263
+ font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
264
+ }
265
+ .studio-header {
266
+ position: sticky;
267
+ top: 0;
268
+ z-index: 2;
269
+ min-height: 68px;
270
+ padding: .65rem clamp(.9rem, 2.5vw, 2rem);
271
+ border-color: var(--studio-line);
272
+ }
273
+ .studio-brand, .toolbar { display: flex; align-items: center; gap: .5rem; }
274
+ .toolbar { flex-wrap: wrap; }
275
+ .studio-mark {
276
+ display: grid;
277
+ place-items: center;
278
+ width: 34px;
279
+ height: 34px;
280
+ margin-right: .2rem;
281
+ border-radius: 9px;
282
+ background: var(--studio-green);
283
+ color: white;
284
+ font-size: 19px;
285
+ font-weight: 650;
286
+ }
287
+ #project-name { display: block; color: var(--studio-muted); font-size: .78rem; overflow-wrap: anywhere; }
288
+ #studio-views { padding: .22rem; background: #f0f4f1; border: 1px solid var(--studio-line); border-radius: 9px; }
289
+ #studio-views button { border-color: transparent; background: transparent; }
290
+ #studio-views button[aria-pressed="true"] { background: white; border-color: var(--studio-line); box-shadow: 0 1px 3px #192b2411; }
291
+ h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -.025em; }
292
+ h2 { font-weight: 650; }
293
+ button {
294
+ min-height: 34px;
295
+ border-color: #cbdacf;
296
+ border-radius: 7px;
297
+ font-weight: 600;
298
+ }
299
+ button:disabled { cursor: not-allowed; }
300
+ .primary { background: var(--studio-green); border-color: var(--studio-green); }
301
+ :is(button, a, input, textarea, select, summary):focus-visible { outline: 2px solid #286b51; outline-offset: 2px; }
302
+ label { font-size: .85rem; font-weight: 600; }
303
+ input, textarea, select { border-color: #cbdacf; border-radius: 7px; padding: .52rem .65rem; }
304
+ select { padding-right: 1.4rem; }
305
+ main { padding-inline: clamp(.9rem, 2.5vw, 2rem); }
306
+ main > aside, main > section { border-color: var(--studio-line); border-radius: 12px; padding: 1.1rem; box-shadow: 0 2px 5px #192b2408; }
307
+ #library { top: 5.15rem; }
308
+ #library-content { padding-right: .25rem; }
309
+ #status { color: var(--studio-muted); font-size: .83rem; padding-inline: clamp(.9rem, 2.5vw, 2rem); }
310
+ #status:empty { min-height: .65rem; }
311
+ #canvas {
312
+ min-height: 22rem;
313
+ border-color: #adbfaf;
314
+ background-color: #f9fcfa;
315
+ background-image: radial-gradient(#dce6df 1px, transparent 1px);
316
+ background-size: 16px 16px;
317
+ padding: .9rem;
318
+ }
319
+ .library-entry {
320
+ display: grid;
321
+ grid-template-columns: minmax(0, 1fr) auto;
322
+ align-items: start;
323
+ border-bottom: 1px solid var(--studio-line);
324
+ }
325
+ .agent-row {
326
+ display: flex;
327
+ align-items: center;
328
+ justify-content: space-between;
329
+ gap: .25rem;
330
+ min-width: 0;
331
+ padding: .38rem 0 .38rem .25rem;
332
+ }
333
+ .library-entry:hover { background: #f8faf8; }
334
+ .agent-label { min-width: 0; }
335
+ .agent-label > strong {
336
+ display: block;
337
+ overflow: hidden;
338
+ text-overflow: ellipsis;
339
+ white-space: nowrap;
340
+ font-size: .82rem;
341
+ }
342
+ .agent-meta {
343
+ display: flex;
344
+ align-items: center;
345
+ flex-wrap: wrap;
346
+ gap: .15rem .35rem;
347
+ color: var(--studio-muted);
348
+ font-size: .72rem;
349
+ }
350
+ .agent-icon {
351
+ display: grid;
352
+ place-items: center;
353
+ width: 32px;
354
+ min-height: 32px;
355
+ padding: 0;
356
+ border: 0;
357
+ border-radius: 6px;
358
+ background: transparent;
359
+ color: var(--studio-green);
360
+ cursor: pointer;
361
+ }
362
+ .agent-icon:hover, .agent-options[open] > summary { background: var(--studio-tint); }
363
+ .agent-run { flex: 0 0 auto; background: #edf4ef; }
364
+ .play-icon {
365
+ width: 0;
366
+ height: 0;
367
+ margin-left: 2px;
368
+ border-block: 5px solid transparent;
369
+ border-left: 8px solid currentColor;
370
+ }
371
+ .agent-options { display: contents; }
372
+ .agent-options[open]::details-content { display: contents; }
373
+ .agent-options > summary { list-style: none; margin: .38rem 0; font-size: 1.1rem; }
374
+ .agent-options > summary::-webkit-details-marker { display: none; }
375
+ .agent-options .actions { grid-column: 1 / -1; padding: 0 .25rem .45rem; }
376
+ .agent-options .actions button { font-size: .76rem; }
377
+ .pill, .library-entry .agent-meta .pill {
378
+ display: inline-block;
379
+ padding: .1rem .45rem;
380
+ border: 1px solid #d4e5da;
381
+ border-radius: 99px;
382
+ background: var(--studio-tint);
383
+ color: var(--studio-green);
384
+ font-size: .73rem;
385
+ font-weight: 650;
386
+ }
387
+ .cloud-callout, #openai-setup {
388
+ padding: .7rem;
389
+ margin-bottom: .65rem;
390
+ border: 1px solid var(--studio-line);
391
+ border-radius: 8px;
392
+ background: #f4f8f5;
393
+ }
394
+ #openai-setup summary { cursor: pointer; font-weight: 650; }
395
+ #openai-setup p, #cloud-key-help { color: var(--studio-muted); }
396
+ #run-result:empty, #openai-status:empty, #cloud-error:empty { display: none; }
397
+ #drawer, #cloud-setup { padding: 1.25rem; box-shadow: -12px 0 44px #192b2422; }
398
+ #drawer::backdrop, #cloud-setup::backdrop { background: #132d246b; }
399
+ #cloud-setup a { color: var(--studio-green); font-weight: 600; }
400
+ @media (max-width: 950px) {
401
+ .studio-header { position: static; flex-wrap: wrap; }
402
+ #library { top: 1rem; }
403
+ }
404
+
405
+ .canvas-empty {
406
+ place-self: center;
407
+ align-self: start;
408
+ max-width: 26rem;
409
+ margin: 6rem 0 2rem;
410
+ padding: .8rem 1.15rem;
411
+ border: 1px solid var(--studio-line);
412
+ border-radius: 9px;
413
+ background: white;
414
+ text-align: center;
415
+ }
416
+ .canvas-empty p { margin: .2rem 0 0; color: var(--studio-muted); }
417
+ .exported #canvas { background-image: none; min-height: 0; }
418
+ .exported .canvas-empty { display: none; }
419
+
420
+ /* Component tiles in the project library */
421
+ #library-content #palette {
422
+ padding: .2rem .15rem .45rem;
423
+ gap: .5rem;
424
+ }
425
+ .component-tile {
426
+ display: grid;
427
+ justify-items: start;
428
+ align-content: start;
429
+ gap: .42rem;
430
+ min-width: 0;
431
+ min-height: 66px;
432
+ padding: .45rem .55rem;
433
+ border-color: var(--studio-line);
434
+ border-radius: 8px;
435
+ background: #f8faf8;
436
+ color: var(--studio-ink);
437
+ cursor: grab;
438
+ font-size: .8rem;
439
+ text-align: left;
440
+ }
441
+ .component-tile:hover {
442
+ border-color: #86ac97;
443
+ background: var(--studio-tint);
444
+ }
445
+ .component-tile:active { cursor: grabbing; }
446
+ .component-mark {
447
+ display: grid;
448
+ place-items: center;
449
+ width: 23px;
450
+ height: 23px;
451
+ border-radius: 5px;
452
+ background: #e3eee7;
453
+ color: var(--studio-green);
454
+ font: 650 .87rem/1 system-ui, sans-serif;
455
+ }
456
+
457
+
458
+ #skills > p { color: var(--studio-muted); font-size: .8rem; }
459
+ #skills summary { margin-top: .45rem; color: var(--studio-green); cursor: pointer; font-weight: 600; }
460
+ .skill-instructions pre { max-height: 16rem; overflow: auto; font-size: .77rem; }
@@ -1,3 +1,4 @@
1
+ import { readCatalog } from "./project.js";
1
2
  import { lstat, mkdir, writeFile } from "node:fs/promises";
2
3
  import { readMode, readSdkKey, requireCloudMode } from "./session.js";
3
4
  import { join } from "node:path";
@@ -16,6 +17,8 @@ export async function pullStudio(root, { key, request = fetch } = {}) {
16
17
  await mkdir(base, { recursive: true });
17
18
  if (!(await lstat(base)).isDirectory()) throw new Error(".lyra must be a regular directory.");
18
19
 
20
+ const linked = new Set([...((await readCatalog(root)).agents.values())]
21
+ .filter(agent => agent.linkedLocalId).map(agent => agent.id));
19
22
  for (const [kind, rows] of Object.entries({ agents: catalog.agents, workflows: catalog.workflows, teams: catalog.teams, skills: catalog.skills ?? [] })) {
20
23
  if (!Array.isArray(rows) || rows.length > 100) throw new Error("Unexpected Cloud catalog response.");
21
24
  const folder = join(base, kind);
@@ -25,6 +28,10 @@ export async function pullStudio(root, { key, request = fetch } = {}) {
25
28
  if (typeof row?.id !== "string" || !/^[a-f0-9]{24}$/i.test(row.id) || typeof row.name !== "string") {
26
29
  throw new Error("Unexpected Cloud catalog entry.");
27
30
  }
31
+ if (kind === "agents" && linked.has("cloud:" + row.id)) {
32
+ count.preserved++;
33
+ continue;
34
+ }
28
35
  const name = "cloud-" + row.id + (kind === "agents" ? ".md" : ".json");
29
36
  const content = kind === "agents"
30
37
  ? "---\nid: " + row.id + "\nname: " + JSON.stringify(row.name) + "\nmode: cloud\n---\n"
@@ -104,7 +104,9 @@ export function mountWorkflowEditor({ api, project, reloadCatalog, run, switchVi
104
104
  config.append(element("h2", "Configure step " + (selected + 1)));
105
105
  const agent = document.createElement("select");
106
106
  agent.add(new Option("Choose an agent", ""));
107
- for (const candidate of project().agents) agent.add(new Option(candidate.name, candidate.id));
107
+ for (const candidate of project().agents) {
108
+ if (!candidate.linkedLocalId || candidate.id === step.agentId) agent.add(new Option(candidate.name, candidate.id));
109
+ }
108
110
  if (step.agentId && !agentName(step.agentId)) agent.add(new Option("Unavailable agent · " + step.agentId, step.agentId));
109
111
  agent.value = step.agentId ?? "";
110
112
  agent.onchange = () => { step.agentId = agent.value; markChanged(); drawGraph(); };