agent-lyra 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +45 -35
  2. package/bin/agent-lyra.js +1 -1
  3. package/package.json +1 -1
  4. package/src/app-builder/init.js +3 -3
  5. package/src/framework/agent.js +19 -8
  6. package/src/framework/mda.js +5 -2
  7. package/src/framework/run.py +83 -11
  8. package/src/index.d.ts +1 -0
  9. package/src/index.js +1 -0
  10. package/src/init.js +1 -1
  11. package/src/intelligence/lifecycle.js +3 -2
  12. package/src/memory/LICENSE +1 -1
  13. package/src/memory/UPSTREAM.json +6 -3
  14. package/src/memory/external-engine.js +35 -0
  15. package/src/memory/index.js +19 -1
  16. package/src/memory/lifecycle.js +2 -1
  17. package/src/runtime/programmatic.d.ts +84 -0
  18. package/src/runtime/programmatic.js +155 -0
  19. package/src/runtime/run-agent.js +10 -2
  20. package/src/studio/browser.js +125 -19
  21. package/src/studio/export.js +7 -4
  22. package/src/studio/graphsnip-workbench.js +77 -0
  23. package/src/studio/history-panel.js +155 -0
  24. package/src/studio/ide-provider.js +65 -0
  25. package/src/studio/index.html +61 -9
  26. package/src/studio/intelligence.js +94 -0
  27. package/src/studio/local-provider.js +43 -0
  28. package/src/studio/memory-actions.js +28 -1
  29. package/src/studio/memory-panel.js +29 -5
  30. package/src/studio/mission-ui.css +52 -0
  31. package/src/studio/mission-ui.js +57 -0
  32. package/src/studio/programmatic-runner.mjs +21 -0
  33. package/src/studio/programmatic.js +58 -0
  34. package/src/studio/project.js +102 -24
  35. package/src/studio/python-agent.py +28 -4
  36. package/src/studio/run-history.js +119 -0
  37. package/src/studio/server.js +77 -8
  38. package/src/studio/session.js +1 -1
  39. package/src/studio/studio.css +76 -0
@@ -1,5 +1,7 @@
1
1
  import { discoverFrameworkAgents, syncFrameworkAgent } from "../framework/agent.js";
2
2
  import { memoryActions } from "./memory-actions.js";
3
+ import { buildKnowledgeGraph, graphTokenLedger, knowledgeGraph } from "./graphsnip-workbench.js";
4
+ import { openRunHistory } from "./run-history.js";
3
5
  import { createServer } from "node:http";
4
6
  import { readFile } from "node:fs/promises";
5
7
  import { describeRun, readCatalog, readLayout, runSelection, saveLayout, studioModels, validateRunBindings } from "./project.js";
@@ -13,6 +15,9 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
13
15
  const assets = new Map();
14
16
  for (const [route, name, mime] of [
15
17
  ["/lyra-icon.png", "lyra-icon.png", "image/png"],
18
+ ["/mission-ui.js", "mission-ui.js", "text/javascript"], ["/mission-ui.css", "mission-ui.css", "text/css"],
19
+ ["/intelligence.js", "intelligence.js", "text/javascript"],
20
+ ["/history-panel.js", "history-panel.js", "text/javascript"],
16
21
  ["/memory-panel.js", "memory-panel.js", "text/javascript"],
17
22
  ["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
18
23
  ["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/workflow-editor.js", "workflow-editor.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
@@ -30,6 +35,11 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
30
35
  await saveOpenAIKey(key);
31
36
  return { configured: true };
32
37
  }],
38
+ ["/api/graphsnip/build", () => buildKnowledgeGraph(root)],
39
+ ["/api/work-locally", async () => {
40
+ await switchMode(root, "standalone", [], { output: { write() {} } });
41
+ return { connected: false };
42
+ }],
33
43
  ["/api/connect-cloud", async ({ key }) => {
34
44
  await switchMode(root, "gated", key ? ["--replace-key"] : [], {
35
45
  output: { write() {} }, prompt: async () => key,
@@ -70,12 +80,14 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
70
80
  }
71
81
 
72
82
  let running = false;
83
+ let activeStream;
73
84
  let writing = false;
74
85
  const server = createServer(async (req, res) => {
75
- const send = (status, data, type = "application/json") => {
86
+ const send = (status, data, type = "application/json", headers = {}) => {
76
87
  res.writeHead(status, {
77
88
  "Content-Type": type.startsWith("image/") ? type : type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
78
89
  "Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self'; connect-src 'self'; frame-ancestors 'none'",
90
+ ...headers,
79
91
  });
80
92
  res.end(type === "application/json" ? JSON.stringify(data) : data);
81
93
  };
@@ -106,8 +118,26 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
106
118
  models: studioModels(),
107
119
  });
108
120
  }
121
+ if (!readOnly && req.method === "GET") {
122
+ if (req.url === "/api/graphsnip/graph") return send(200, await knowledgeGraph(root));
123
+ if (req.url === "/api/graphsnip/tokens") return send(200, await graphTokenLedger(root));
124
+ }
125
+ const historyRoute = /^\/api\/history\/([a-f0-9-]{36})(\/report)?$/i.exec(req.url);
126
+ const historyId = historyRoute?.[1];
127
+ if (!appCatalog && req.method === "GET" && (req.url === "/api/history" || historyId)) {
128
+ const history = await openRunHistory(root);
129
+ try {
130
+ if (!historyId) return send(200, { schemaVersion: 1, runs: history.list() });
131
+ const detail = history.get(historyId);
132
+ if (!detail) return send(404, { error: "Run not found in this project." });
133
+ return send(200, detail, "application/json", historyRoute[2]
134
+ ? { "Content-Disposition": 'attachment; filename="lyra-run-' + historyId + '.json"' }
135
+ : {});
136
+ } finally { history.close(); }
137
+ }
109
138
  const runRequest = req.url === "/api/run" || req.url === "/api/run-plan";
110
- if (req.method !== "POST" || (!runRequest && (readOnly || !updates.has(req.url)))) {
139
+ const cancelRequest = req.url === "/api/cancel-run";
140
+ if (req.method !== "POST" || (!runRequest && !cancelRequest && (readOnly || !updates.has(req.url)))) {
111
141
  return send(404, { error: "Not found." });
112
142
  }
113
143
  if (req.headers.origin !== "http://" + host) return send(403, { error: "Use the Studio page to submit requests." });
@@ -120,6 +150,11 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
120
150
  chunks.push(chunk);
121
151
  }
122
152
  const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
153
+ if (cancelRequest) {
154
+ if (!activeStream || activeStream.id !== body.streamId) return send(404, { error: "The IDE run has already stopped." });
155
+ activeStream.controller.abort(new Error("Run cancelled."));
156
+ return send(200, { cancelled: true });
157
+ }
123
158
  if (runRequest && readOnly) {
124
159
  body.targets = await savedActionTargets(body);
125
160
  if (!body.targets) return send(409, { error: "The saved layout changed. Reload the preview before running." });
@@ -131,8 +166,42 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
131
166
  if (running) return send(409, { error: "A Studio run is already in progress." });
132
167
  running = true;
133
168
  try {
134
- return send(200, await run(root, body, appCatalog));
135
- } finally { running = false; }
169
+ if (typeof body.streamId !== "string" ||
170
+ !/^[a-f0-9-]{36}$/i.test(body.streamId)) {
171
+ return send(200, await run(root, body, appCatalog));
172
+ }
173
+ const controller = new AbortController();
174
+ const cancellable = body.provider === "vscode" ||
175
+ (await describeRun(root, body.targets, appCatalog, body.provider)).frameworkOnly;
176
+ if (cancellable) activeStream = { id: body.streamId, controller };
177
+ res.on("close", () => {
178
+ if (cancellable && !res.writableEnded) controller.abort(new Error("Run cancelled."));
179
+ });
180
+ res.writeHead(200, {
181
+ "Content-Type": "application/x-ndjson; charset=utf-8",
182
+ "Cache-Control": "no-store",
183
+ "X-Content-Type-Options": "nosniff",
184
+ });
185
+ res.flushHeaders();
186
+ const emit = event => {
187
+ if (!res.destroyed) res.write(JSON.stringify(event) + "\n");
188
+ };
189
+ try {
190
+ const result = await run(root, body, appCatalog, {
191
+ signal: cancellable ? controller.signal : undefined,
192
+ onDelta: text => emit({ type: "delta", text }),
193
+ onEvent: event => emit({ type: "event", event }),
194
+ });
195
+ emit({ type: "result", result });
196
+ } catch (error) {
197
+ emit({ type: "error", message: error.code ? "Studio could not read or write the project." : error.message,
198
+ progress: error.progress });
199
+ }
200
+ return res.end();
201
+ } finally {
202
+ activeStream = undefined;
203
+ running = false;
204
+ }
136
205
  }
137
206
  if (writing) return send(409, { error: "Studio is already saving or pulling files." });
138
207
  writing = true;
@@ -153,9 +222,9 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
153
222
  return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
154
223
  }
155
224
 
156
- export async function runStudio(args, output = process.stdout) {
225
+ export async function runStudio(args, output = process.stdout, { legacy = false } = {}) {
157
226
  if (args[0] === "--help") {
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");
227
+ output.write("Usage: agent-lyra workbench | agent-lyra workbench pull | agent-lyra workbench push <local-agent-id> | agent-lyra workbench pull-agent <local-agent-id> | agent-lyra workbench push-workflow <workflow-id> | agent-lyra workbench pull-workflow <workflow-id> | agent-lyra workbench push-team <team-id> | agent-lyra workbench pull-team <team-id> | agent-lyra workbench push-skill <skill-id> | agent-lyra workbench pull-skill <skill-id>\nWorkbench listens on 127.0.0.1:4174. The studio command is a compatibility alias. Set LYRA_STUDIO_PORT to override it, or use 0 to pick a free port.\n");
159
228
  return;
160
229
  }
161
230
  if (args.length === 1 && args[0] === "pull") {
@@ -184,7 +253,7 @@ export async function runStudio(args, output = process.stdout) {
184
253
  : result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
185
254
  return;
186
255
  }
187
- if (args.length) throw new Error("See agent-lyra studio --help.");
256
+ if (args.length) throw new Error("See agent-lyra workbench --help.");
188
257
  const port = Number(process.env.LYRA_STUDIO_PORT?.trim() || 4174);
189
258
  if (!Number.isInteger(port) || port < 0 || port > 65535) {
190
259
  throw new Error("LYRA_STUDIO_PORT must be an integer from 0 to 65535.");
@@ -195,5 +264,5 @@ export async function runStudio(args, output = process.stdout) {
195
264
  }
196
265
  throw error;
197
266
  });
198
- output.write("AgentLyra Studio: " + url + "\n");
267
+ output.write((legacy ? "AgentLyra Studio: " : "AgentLyra Workbench: ") + url + "\n");
199
268
  }
@@ -98,7 +98,7 @@ export async function switchMode(root, mode, args, { output = process.stdout, pr
98
98
  }
99
99
  await saveJson(workspace(root), "session.json", { mode });
100
100
  output.write(mode === "gated"
101
- ? "Connected to Cloud. Open Studio and choose Pull from Cloud.\n"
101
+ ? "Connected to Cloud. Open Workbench and choose Pull from Cloud.\n"
102
102
  : "Working locally. Studio Cloud actions are paused.\n");
103
103
  }
104
104
 
@@ -458,3 +458,79 @@ main > aside, main > section { border-color: var(--studio-line); border-radius:
458
458
  #skills > p { color: var(--studio-muted); font-size: .8rem; }
459
459
  #skills summary { margin-top: .45rem; color: var(--studio-green); cursor: pointer; font-weight: 600; }
460
460
  .skill-instructions pre { max-height: 16rem; overflow: auto; font-size: .77rem; }
461
+
462
+
463
+ #history-panel { grid-column: 1 / -1; }
464
+ .history-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: .65rem; }
465
+ .history-heading p { color: var(--studio-muted); }
466
+ .history-content { max-width: 78rem; }
467
+ .history-content { display: grid; grid-template-columns: minmax(11rem, 1fr) minmax(0, 2fr); gap: 1rem; }
468
+ #history-list { max-height: 72dvh; overflow-y: auto; padding: .2rem; }
469
+ .history-row { display: grid; gap: .1rem; padding: .6rem; margin-bottom: .3rem; border: 1px solid var(--studio-line); border-radius: 8px; color: var(--studio-ink); text-decoration: none; }
470
+ .history-row:hover, .history-row[aria-current="true"] { background: var(--studio-tint); }
471
+ .history-row > span:not(.lyra-mission-status), .history-row code { font-size: .76rem; color: var(--studio-muted); }
472
+ #history-detail { min-width: 0; overflow-wrap: anywhere; }
473
+ #history-detail h3 { margin: .15rem 0; }
474
+ #history-detail > a { display: block; width: fit-content; margin-top: .55rem; color: var(--studio-green); font-weight: 600; }
475
+ @media (max-width: 580px) {
476
+ .history-content { grid-template-columns: 1fr; }
477
+ #history-list { max-height: 28dvh; }
478
+ }
479
+
480
+
481
+ #cloud-settings, #library.registry-view { grid-column: 1 / -1; }
482
+ #cloud-settings p { max-width: 54ch; color: var(--studio-muted); }
483
+ #library.registry-view { position: static; }
484
+ #library.registry-view input { max-width: 25rem; }
485
+ #library.registry-view .agent-label > strong { white-space: normal; overflow-wrap: anywhere; }
486
+ #library.registry-view #library-content { max-width: 60rem; }
487
+ #studio-views { flex-wrap: wrap; }
488
+
489
+
490
+ .studio-header {
491
+ display: grid;
492
+ grid-template-columns: minmax(0, 1fr) auto;
493
+ gap: .55rem 1rem;
494
+ }
495
+ #studio-views {
496
+ grid-column: 1 / -1;
497
+ gap: .45rem 1.2rem;
498
+ padding: .35rem 0 0;
499
+ border: 0;
500
+ border-top: 1px solid var(--studio-line);
501
+ border-radius: 0;
502
+ background: transparent;
503
+ }
504
+ #studio-views > div { display: flex; align-items: center; flex-wrap: wrap; gap: .2rem; }
505
+ #studio-views > div > span { margin-right: .25rem; color: var(--studio-muted); font-size: .72rem; }
506
+ #studio-views button { min-height: 30px; font-size: .8rem; }
507
+ #studio-views button[aria-pressed="true"] { border-color: #c9dfd0; background: var(--studio-tint); box-shadow: none; }
508
+ #library { top: 7.4rem; }
509
+ .history-detail-tabs {
510
+ display: flex;
511
+ flex-wrap: wrap;
512
+ gap: .4rem;
513
+ padding: .45rem 0 0;
514
+ margin-top: .6rem;
515
+ border-top: 1px solid var(--studio-line);
516
+ }
517
+ .history-detail-tabs button { min-height: 32px; border-color: transparent; font-size: .8rem; }
518
+ .history-detail-tabs button[aria-pressed="true"] { border-color: #c9dfd0; background: var(--studio-tint); }
519
+ @media (max-width: 950px) {
520
+ #library { top: 1rem; }
521
+ #studio-views { gap: .3rem .7rem; }
522
+ }
523
+ @media (max-width: 520px) {
524
+ .studio-header { grid-template-columns: minmax(0, 1fr); }
525
+ }
526
+
527
+
528
+ .intelligence-panel { grid-column: 1 / -1; }
529
+ #graph-content select { max-width: 28rem; }
530
+ #graph-content ul { max-height: 28rem; overflow: auto; }
531
+ #token-content { display: flex; flex-wrap: wrap; gap: 1rem; }
532
+ #token-content section { flex: 1 1 14rem; background: #f8faf8; border: 1px solid var(--studio-line); border-radius: 8px; padding: .8rem; }
533
+
534
+
535
+ .learning-suggestions { margin: .7rem 0; padding: .65rem; background: var(--studio-tint); border-radius: 8px; }
536
+ .learning-suggestions button { margin: .3rem .35rem 0 0; }