agent-lyra 0.10.0 → 0.11.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 +22 -3
- package/package.json +1 -1
- package/src/app-builder/saved-app.js +5 -2
- package/src/coding/setup.js +1 -1
- package/src/init.js +5 -2
- package/src/runtime/local-cli.js +19 -3
- package/src/standalone/init.js +2 -0
- package/src/studio/browser.js +96 -17
- package/src/studio/cli-providers.js +40 -0
- package/src/studio/export.js +2 -2
- package/src/studio/index.html +19 -3
- package/src/studio/lyra-icon.png +0 -0
- package/src/studio/project.js +62 -20
- package/src/studio/pull-agent.js +2 -3
- package/src/studio/push.js +4 -1
- package/src/studio/server.js +23 -7
- package/src/studio/session.js +25 -1
- package/src/studio/studio.css +117 -0
- package/src/studio/sync.js +7 -0
- package/src/studio/workflow-editor.js +3 -1
- package/src/vscode/workspace.js +158 -0
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
|
|
|
@@ -64,6 +64,10 @@ Values in angle brackets are placeholders. Use `--help` to check arguments for t
|
|
|
64
64
|
|
|
65
65
|
The registry wizard supports `--mode`, `--domains`, `--stack`, `--detect`, `--dir`, `--force`, `--api-key`, and `--api-base-url`. For account credentials, prefer the hidden prompt in `connect-cloud`.
|
|
66
66
|
|
|
67
|
+
### VS Code agent discovery
|
|
68
|
+
|
|
69
|
+
`agent-lyra init` registers `.lyra/agents` in the workspace's `.vscode/settings.json` under `chat.agentFilesLocations`, preserving unrelated settings. Newly generated registry SDK agents use `.agent.md` filenames. Reload VS Code after initialization. Existing agent files are not automatically migrated. Discovery does not guarantee a new entry in VS Code's agent creation location picker.
|
|
70
|
+
|
|
67
71
|
## SDK library
|
|
68
72
|
|
|
69
73
|
Use the SDK directly in your own code to compose workflows, run agents, and work with retrieval. Choose the runtime and provider that fit your app.
|
|
@@ -186,9 +190,24 @@ npx agent-lyra studio
|
|
|
186
190
|
|
|
187
191
|
Run `python -m lyra studio` from a Python project. Start from the project root so Studio can find your `.lyra` agents, workflows, and skills. See [Cloud sync](#agentlyra-cloud-and-marketplace) for importing or pushing selected resources.
|
|
188
192
|
|
|
189
|
-
|
|
193
|
+
### Provider switching and run records
|
|
194
|
+
|
|
195
|
+
In Studio's run drawer, select an execution provider for text agents. The **Execution steps** list shows where each step runs.
|
|
196
|
+
|
|
197
|
+
| Provider | Requirements |
|
|
198
|
+
| --- | --- |
|
|
199
|
+
| Local OpenAI API | Set `OPENAI_API_KEY` in the Studio terminal and select a model |
|
|
200
|
+
| Lyra Cloud | Connect an SDK key and configure your own OpenAI key in Cloud Models |
|
|
201
|
+
| Codex CLI | Install the authenticated Codex CLI on PATH. Studio requests a read-only sandbox |
|
|
202
|
+
| Claude Code CLI | Install the authenticated Claude Code CLI on PATH. Studio requests tool-free execution |
|
|
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. 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
|
+
|
|
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
|
+
|
|
208
|
+
The GitHub source edition includes the approved local SDK subset and VS Code discovery helper. Install the npm or PyPI distribution for the full Studio experience.
|
|
190
209
|
|
|
191
|
-
In **Workflow**, create a sequence of agents between **Trigger** and **Output**. Give each step a task and optionally name its output so a later step can read it. Save to
|
|
210
|
+
In **Workflow**, create a sequence of agents between **Trigger** and **Output**. Give each step a task and optionally name its output so a later step can read it. Save to `.lyra/workflows`, test the sequence, then use **Layout** to bind a run button to the saved workflow. The run drawer shows each step's result, status, duration, and Studio trace ID. Cloud-only workflows open for inspection and run in the Cloud console. Use **Duplicate locally** to customize a pulled workflow that can run in Studio.
|
|
192
211
|
|
|
193
212
|
To sync a workflow through the existing Cloud commands, use two to eight steps with enabled Cloud text agents or local text agents already linked to Cloud.
|
|
194
213
|
|
package/package.json
CHANGED
|
@@ -33,11 +33,11 @@ export function createSavedAgentClient({ key = process.env.LYRA_API_KEY, fetchRe
|
|
|
33
33
|
throw new Error("Set LYRA_API_KEY to a dedicated SDK key from AgentLyra Console.");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
async function request(path, prompt) {
|
|
36
|
+
async function request(path, prompt, traceId, extra = {}) {
|
|
37
37
|
const response = await fetchRequest("https://api.agentlyra.in/api/sdk/v1/saved-agents" + path, {
|
|
38
38
|
method: prompt === undefined ? "GET" : "POST",
|
|
39
39
|
headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
|
|
40
|
-
body: prompt === undefined ? undefined : JSON.stringify({ prompt }),
|
|
40
|
+
body: prompt === undefined ? undefined : JSON.stringify({ prompt, ...(traceId ? { traceId } : {}), ...extra }),
|
|
41
41
|
redirect: "error",
|
|
42
42
|
signal: AbortSignal.timeout(65_000),
|
|
43
43
|
});
|
|
@@ -51,7 +51,10 @@ export function createSavedAgentClient({ key = process.env.LYRA_API_KEY, fetchRe
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
return {
|
|
54
|
+
definition: async id => request('/' + encodeURIComponent(id) + '/definition'),
|
|
55
|
+
invokeLocal: async (agent, prompt, traceId) => request('/local/invoke', prompt, traceId, { systemPrompt: agent.prompt, agentName: agent.name }),
|
|
54
56
|
list: async () => (await request("")).agents,
|
|
57
|
+
invokeWithTrace: async (id, prompt, traceId) => request("/" + encodeURIComponent(id) + "/invoke", prompt, traceId),
|
|
55
58
|
invoke: async (id, prompt) => (await request("/" + encodeURIComponent(id) + "/invoke", prompt)).output,
|
|
56
59
|
};
|
|
57
60
|
}
|
package/src/coding/setup.js
CHANGED
|
@@ -49,7 +49,7 @@ function plan(selection, scope, { version, technologies, presets, skills }) {
|
|
|
49
49
|
? label.slice(0, 74) + "-" + createHash("sha256").update(label).digest("hex").slice(0, 8)
|
|
50
50
|
: label) + suffix;
|
|
51
51
|
const agentName = name + " (" + packs.map(pack => technologies[pack][1]).join(", ") + ")";
|
|
52
|
-
files.set("agents/coding/" + id + ".md", [
|
|
52
|
+
files.set("agents/coding/" + id + ".agent.md", [
|
|
53
53
|
"---", "id: " + id, "name: " + JSON.stringify(scope === "." ? agentName : agentName + " — " + scope), "mode: standalone", "domain: coding", "---",
|
|
54
54
|
"", "## System Prompt", "",
|
|
55
55
|
"You are the project's " + name.toLowerCase() + ". Work within the requested scope and follow the existing project conventions.",
|
package/src/init.js
CHANGED
|
@@ -7,6 +7,7 @@ import { stdin as input, stdout as output } from "node:process";
|
|
|
7
7
|
import { GATED_DOMAINS, STANDALONE_DOMAINS, getDomainCatalog } from "./catalog.js";
|
|
8
8
|
|
|
9
9
|
import { prepareCodingStack, recommendCodingStacks, selectCodingStack } from "./coding/setup.js";
|
|
10
|
+
import { ensureVSCodeAgentDiscovery } from "./vscode/workspace.js";
|
|
10
11
|
|
|
11
12
|
const DEFAULT_API_BASE_URL = "https://www.agentlyra.in";
|
|
12
13
|
|
|
@@ -42,7 +43,7 @@ function parseArgs(argv = process.argv.slice(2)) {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
function printUsage() {
|
|
45
|
-
output.write(`
|
|
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`);
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
function printWelcomeBanner() {
|
|
@@ -577,6 +578,7 @@ function buildAgentMarkdown(spec) {
|
|
|
577
578
|
id: spec.id,
|
|
578
579
|
slug: spec.slug,
|
|
579
580
|
name: spec.name,
|
|
581
|
+
description: spec.description || "AgentLyra project agent",
|
|
580
582
|
domain: spec.domain,
|
|
581
583
|
category: spec.category,
|
|
582
584
|
mode: spec.mode,
|
|
@@ -705,7 +707,7 @@ async function writeTopLevelManifest(rootDir, mode, selectedDomains) {
|
|
|
705
707
|
await fs.mkdir(domainDir, { recursive: true });
|
|
706
708
|
for (const agent of domain.agents || []) {
|
|
707
709
|
const spec = buildAgentSpec(domain, mode, agent);
|
|
708
|
-
const fileName = `${spec.slug}.md`;
|
|
710
|
+
const fileName = `${spec.slug}.agent.md`;
|
|
709
711
|
await fs.writeFile(path.join(domainDir, fileName), buildAgentMarkdown(spec), "utf8");
|
|
710
712
|
}
|
|
711
713
|
}
|
|
@@ -933,6 +935,7 @@ export async function runInitWizard(options = {}) {
|
|
|
933
935
|
await ensureEmptyOrApproved(rl, lyraDir, Boolean(options.force));
|
|
934
936
|
await writeScaffold({ targetDir, mode, selectedDomains, apiKey });
|
|
935
937
|
if (applyCoding) await applyCoding();
|
|
938
|
+
await ensureVSCodeAgentDiscovery(targetDir);
|
|
936
939
|
|
|
937
940
|
output.write(`Created ${lyraDir} for ${mode} mode with ${selectedDomains.length} domain(s).\n`);
|
|
938
941
|
} finally {
|
package/src/runtime/local-cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
130
|
-
|
|
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
|
+
}
|
package/src/standalone/init.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { resolve, join } from 'node:path';
|
|
3
3
|
import { parseArgs } from 'node:util';
|
|
4
|
+
import { ensureVSCodeAgentDiscovery } from '../vscode/workspace.js';
|
|
4
5
|
export async function initStandalone(args) {
|
|
5
6
|
if(args.includes('--help')) { console.log('Usage: agent-lyra init [--mode standalone] [--dir <directory>]'); return; }
|
|
6
7
|
const {values}=parseArgs({args,options:{mode:{type:'string'},dir:{type:'string'}}});
|
|
@@ -8,5 +9,6 @@ export async function initStandalone(args) {
|
|
|
8
9
|
const root=resolve(values.dir||process.cwd(),'.lyra');
|
|
9
10
|
for(const folder of ['agents','skills','workflows','teams']) await mkdir(join(root,folder),{recursive:true});
|
|
10
11
|
await writeFile(join(root,'config.json'),JSON.stringify({version:1,mode:'standalone',domains:[]},null,2)+'\n',{flag:'wx'}).catch(e=>{if(e.code!=='EEXIST')throw e;});
|
|
12
|
+
await ensureVSCodeAgentDiscovery(resolve(values.dir||process.cwd()));
|
|
11
13
|
console.log('Initialized '+root+' (existing files preserved).');
|
|
12
14
|
}
|
package/src/studio/browser.js
CHANGED
|
@@ -79,7 +79,9 @@ function move(node, offset) {
|
|
|
79
79
|
function renderCanvas() {
|
|
80
80
|
const canvas = $("#canvas");
|
|
81
81
|
canvas.replaceChildren();
|
|
82
|
-
if (!project.layout.length) canvas.append(
|
|
82
|
+
if (!project.layout.length) canvas.append(dom("div", { className: "canvas-empty" },
|
|
83
|
+
element("strong", "Start with a component"),
|
|
84
|
+
element("p", "Drag a component here or click one in the library.")));
|
|
83
85
|
for (const node of project.layout) {
|
|
84
86
|
const card = element("div");
|
|
85
87
|
card.dataset.nodeId = node.id;
|
|
@@ -193,7 +195,7 @@ function renderInspector() {
|
|
|
193
195
|
node.outputId = id; dirty = true;
|
|
194
196
|
});
|
|
195
197
|
if (node.kind === "agent-card") {
|
|
196
|
-
addSelect(box, "Agent", [["", "Choose an agent"], ...project.agents.map(agent => [agent.id, agent.name])], node.targets[0], id => {
|
|
198
|
+
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
199
|
if (node.label === names["agent-card"] || node.label === labelFor(node.targets[0])) {
|
|
198
200
|
node.label = id ? labelFor(id) : names["agent-card"];
|
|
199
201
|
}
|
|
@@ -210,7 +212,7 @@ function renderInspector() {
|
|
|
210
212
|
box.append(row);
|
|
211
213
|
});
|
|
212
214
|
const options = [
|
|
213
|
-
...project.agents.map(agent => [agent.id, agent.name]),
|
|
215
|
+
...project.agents.filter(agent => !agent.linkedLocalId).map(agent => [agent.id, agent.name]),
|
|
214
216
|
...project.workflows.filter(item => item.runnable).map(item => ["workflow:" + item.id, item.name + " (workflow)"]),
|
|
215
217
|
];
|
|
216
218
|
addSelect(box, "Add next step", [["", "Choose agent or workflow"], ...options], "", id => {
|
|
@@ -231,9 +233,16 @@ function renderCatalog() {
|
|
|
231
233
|
const id = libraryView;
|
|
232
234
|
const section = $("#" + id);
|
|
233
235
|
const query = search.value.trim().toLowerCase();
|
|
234
|
-
const rows = project[id].filter(row => [row.name, row.source, row.framework, agentSources[row.source]]
|
|
236
|
+
const rows = project[id].filter(row => !row.linkedLocalId && [row.name, row.source, row.framework, agentSources[row.source]]
|
|
235
237
|
.some(value => value?.toLowerCase().includes(query)));
|
|
238
|
+
const expanded = new Set([...section.querySelectorAll("details[open]")].map(item => item.dataset.agent));
|
|
236
239
|
section.replaceChildren();
|
|
240
|
+
if (id === "agents" && !project.cloudConnected) {
|
|
241
|
+
const callout = dom("div", { className: "cloud-callout" },
|
|
242
|
+
element("p", "Connect to AgentLyra Cloud to pull, push, and sync agents."),
|
|
243
|
+
button("Connect to Cloud", openCloudSetup));
|
|
244
|
+
section.append(callout);
|
|
245
|
+
}
|
|
237
246
|
if (!rows.length) section.append(element("p", query ? "No matching items." : "None in this project."));
|
|
238
247
|
if (id === "agents" && project.frameworkCandidates?.length) {
|
|
239
248
|
section.append(element("p", "LangGraph candidates: " + project.frameworkCandidates.map(item => item.name).join(", ") +
|
|
@@ -241,17 +250,18 @@ function renderCatalog() {
|
|
|
241
250
|
}
|
|
242
251
|
for (const row of rows) {
|
|
243
252
|
if (id === "agents") {
|
|
244
|
-
const push = row.source === "local" && project.
|
|
245
|
-
? button("Push to Cloud", async () => {
|
|
253
|
+
const push = row.source === "local" && project.cloudConnected && row.syncStatus !== "synced"
|
|
254
|
+
? button(row.syncStatus ? "Push local edits" : "Push to Cloud", async () => {
|
|
246
255
|
if (!window.confirm("Send the name and instructions for " + row.name + " to your private AgentLyra Cloud workspace?")) return;
|
|
247
256
|
push.disabled = true;
|
|
248
257
|
try {
|
|
249
258
|
const result = await api("push", { id: row.id });
|
|
250
|
-
|
|
259
|
+
await load({ catalogOnly: true });
|
|
260
|
+
announce((result.unchanged ? "Already synced " : result.created ? "Created " : "Synced ") + row.name + " in AgentLyra Cloud.");
|
|
251
261
|
} catch (error) { announce(error.message); }
|
|
252
262
|
finally { push.disabled = false; }
|
|
253
263
|
}) : undefined;
|
|
254
|
-
const pull =
|
|
264
|
+
const pull = row.syncStatus && project.cloudConnected && button("Pull agent edits", async () => {
|
|
255
265
|
pull.disabled = true;
|
|
256
266
|
try {
|
|
257
267
|
const result = await api("pull-agent", { id: row.id });
|
|
@@ -260,7 +270,7 @@ function renderCatalog() {
|
|
|
260
270
|
} catch (error) { announce(error.message); }
|
|
261
271
|
finally { pull.disabled = false; }
|
|
262
272
|
});
|
|
263
|
-
const sync = row.source === "framework" && project.
|
|
273
|
+
const sync = row.source === "framework" && project.cloudConnected && button("Sync registration", async () => {
|
|
264
274
|
try {
|
|
265
275
|
const id = row.id.slice("framework:".length);
|
|
266
276
|
const preview = await api("framework-preview", { id });
|
|
@@ -271,9 +281,13 @@ function renderCatalog() {
|
|
|
271
281
|
});
|
|
272
282
|
const entry = element("details");
|
|
273
283
|
entry.className = "library-entry";
|
|
284
|
+
entry.dataset.agent = row.id;
|
|
285
|
+
entry.open = expanded.has(row.id);
|
|
274
286
|
const summary = element("summary");
|
|
275
287
|
const source = row.framework ? row.framework + " · Local" : agentSources[row.source];
|
|
276
|
-
summary.append(element("strong", row.name),
|
|
288
|
+
summary.append(element("strong", row.name), dom("span", { className: "agent-meta" },
|
|
289
|
+
element("span", source), row.syncStatus && dom("span", { className: "pill" },
|
|
290
|
+
row.syncStatus === "synced" ? "Synced to Cloud" : "Local edits")));
|
|
277
291
|
const actions = dom("div", { className: "actions" }, button("Run now", () => openRun([row.id])), push, pull, sync);
|
|
278
292
|
entry.append(summary, actions);
|
|
279
293
|
section.append(entry);
|
|
@@ -288,7 +302,7 @@ function renderCatalog() {
|
|
|
288
302
|
: element("span", "Run this workflow in Lyra Cloud."));
|
|
289
303
|
}
|
|
290
304
|
const syncType = id === "skills" && row.source !== "markdown" ? "skill" : id === "teams" ? "team" : id === "workflows" && row.runnable ? "workflow" : undefined;
|
|
291
|
-
if (syncType && row.source !== "cloud" && project.
|
|
305
|
+
if (syncType && row.source !== "cloud" && project.cloudConnected) {
|
|
292
306
|
for (const [action, label] of [["push", "Push to Cloud"], ["pull", "Pull " + syncType + " edits"]]) {
|
|
293
307
|
const control = button(label, async () => {
|
|
294
308
|
if (action === "push" && !window.confirm("Send this " + syncType + " definition to your private Cloud workspace?")) return;
|
|
@@ -336,9 +350,17 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
336
350
|
const plan = $("#run-plan");
|
|
337
351
|
plan.hidden = true;
|
|
338
352
|
plan.replaceChildren();
|
|
353
|
+
const providerPicker = $("#execution-provider");
|
|
354
|
+
const providerLabel = $('label[for="execution-provider"]');
|
|
355
|
+
providerPicker.hidden = providerLabel.hidden = true;
|
|
356
|
+
providerPicker.disabled = false;
|
|
339
357
|
const picker = $("#model");
|
|
340
358
|
const modelLabel = $('label[for="model"]');
|
|
341
359
|
picker.hidden = modelLabel.hidden = true;
|
|
360
|
+
$("#openai-setup").hidden = true;
|
|
361
|
+
$("#openai-setup").open = false;
|
|
362
|
+
$("#openai-key").value = "";
|
|
363
|
+
$("#openai-status").textContent = "";
|
|
342
364
|
$("#run").disabled = true;
|
|
343
365
|
$("#run").textContent = project.preview || project.exported ? "Run" : "Test action";
|
|
344
366
|
$("#drawer").showModal();
|
|
@@ -348,8 +370,11 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
348
370
|
(component.outputId && !project.layout.some(node => node.id === component.outputId && node.kind === "output")))) {
|
|
349
371
|
throw new Error("Fix the input or output binding in the inspector.");
|
|
350
372
|
}
|
|
351
|
-
|
|
352
|
-
|
|
373
|
+
let planRequest = 0;
|
|
374
|
+
const refreshPlan = async provider => {
|
|
375
|
+
const request = ++planRequest;
|
|
376
|
+
const setup = await api("run-plan", { targets: action.targets, buttonId, revision: action.revision, provider });
|
|
377
|
+
if (pending !== action || request !== planRequest) return;
|
|
353
378
|
const list = element("ol");
|
|
354
379
|
for (const step of setup.steps) {
|
|
355
380
|
const row = element("li");
|
|
@@ -359,15 +384,42 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
359
384
|
}
|
|
360
385
|
plan.replaceChildren(element("h2", "Execution steps"), list);
|
|
361
386
|
plan.hidden = false;
|
|
387
|
+
providerPicker.replaceChildren(...(setup.providers || []).map(id => new Option(id === "openai" ? "Local OpenAI API" : id === "cloud" ? "Lyra Cloud" : id + " CLI", id)));
|
|
388
|
+
providerPicker.value = setup.provider || "";
|
|
389
|
+
providerPicker.hidden = providerLabel.hidden = !setup.providers?.length;
|
|
362
390
|
const previousModel = picker.value;
|
|
363
391
|
picker.replaceChildren(...setup.models.map(model => new Option(model, model)));
|
|
364
392
|
if (setup.models.includes(previousModel)) picker.value = previousModel;
|
|
365
393
|
picker.hidden = modelLabel.hidden = !setup.needsModel;
|
|
394
|
+
$("#openai-setup").hidden = !setup.needsOpenAIKey || project.preview || project.exported;
|
|
366
395
|
action.inputKind = setup.inputKind;
|
|
367
396
|
if (setup.inputKind === "json") $("#run-input-label").textContent = "JSON input";
|
|
368
397
|
action.ready = setup.issues.length === 0;
|
|
369
398
|
$("#run-status").textContent = setup.issues.join(" ");
|
|
370
399
|
$("#run").disabled = !action.ready;
|
|
400
|
+
};
|
|
401
|
+
$("#save-openai").onclick = async () => {
|
|
402
|
+
const button = $("#save-openai");
|
|
403
|
+
const key = $("#openai-key");
|
|
404
|
+
button.disabled = true;
|
|
405
|
+
try {
|
|
406
|
+
await api("openai-key", { key: key.value });
|
|
407
|
+
key.value = "";
|
|
408
|
+
await refreshPlan(providerPicker.value);
|
|
409
|
+
if (pending === action && action.ready) $("#run-status").textContent = "OpenAI configured. Ready to run.";
|
|
410
|
+
} catch (error) {
|
|
411
|
+
if (pending === action) $("#openai-status").textContent = error.message;
|
|
412
|
+
} finally { button.disabled = false; }
|
|
413
|
+
};
|
|
414
|
+
providerPicker.onchange = async () => {
|
|
415
|
+
action.ready = false;
|
|
416
|
+
$("#run").disabled = true;
|
|
417
|
+
providerPicker.disabled = true;
|
|
418
|
+
try { await refreshPlan(providerPicker.value); }
|
|
419
|
+
catch (error) { if (pending === action) $("#run-status").textContent = error.message; }
|
|
420
|
+
finally { if (pending === action) providerPicker.disabled = false; }
|
|
421
|
+
};
|
|
422
|
+
await refreshPlan();
|
|
371
423
|
} catch (error) {
|
|
372
424
|
if (pending === action) $("#run-status").textContent = error.message;
|
|
373
425
|
}
|
|
@@ -378,7 +430,7 @@ function showRunResults({ answers, traceId, steps }) {
|
|
|
378
430
|
if (steps) {
|
|
379
431
|
for (const step of steps) {
|
|
380
432
|
const heading = step.index + ". " + step.agent + " · " + step.state + " · " + step.durationMs + " ms";
|
|
381
|
-
lines.push([heading, "Step trace " + step.traceId, step.runId && "Runtime run " + step.runId,
|
|
433
|
+
lines.push([heading, "Step trace " + step.traceId, step.runId && "Runtime run " + step.runId, step.provider && "Provider " + step.provider, step.model && "Model " + step.model,
|
|
382
434
|
answers[step.index - 1]?.output].filter(Boolean).join("\n"));
|
|
383
435
|
}
|
|
384
436
|
} else {
|
|
@@ -405,7 +457,7 @@ $("#runner").onsubmit = async event => {
|
|
|
405
457
|
$("#run-status").textContent = "Running…";
|
|
406
458
|
$("#run-result").textContent = "";
|
|
407
459
|
try {
|
|
408
|
-
const result = await api("run", { targets: pending.targets, buttonId: pending.buttonId, revision: pending.revision, input: prompt.value, model: $("#model").value });
|
|
460
|
+
const result = await api("run", { targets: pending.targets, buttonId: pending.buttonId, revision: pending.revision, input: prompt.value, model: $("#model").value, provider: $("#execution-provider").value });
|
|
409
461
|
showRunResults(result);
|
|
410
462
|
if (pending.outputId) outputs.set(pending.outputId, result.answers.at(-1).output);
|
|
411
463
|
renderCanvas();
|
|
@@ -443,12 +495,15 @@ drawer.onclick = event => {
|
|
|
443
495
|
async function load({ catalogOnly = false } = {}) {
|
|
444
496
|
const next = await api("project");
|
|
445
497
|
if (catalogOnly) {
|
|
446
|
-
for (const key of ["agents", "workflows", "teams", "skills", "mode", "frameworkCandidates"]) project[key] = next[key];
|
|
498
|
+
for (const key of ["agents", "workflows", "teams", "skills", "mode", "frameworkCandidates", "cloudConnected", "hasCloudKey"]) project[key] = next[key];
|
|
447
499
|
} else {
|
|
448
500
|
project = next;
|
|
449
501
|
dirty = false;
|
|
450
502
|
}
|
|
451
|
-
$("#project-name").textContent = project.name
|
|
503
|
+
$("#project-name").textContent = project.name;
|
|
504
|
+
$("#cloud-state").textContent = project.cloudConnected ? "Cloud connected" : "Working locally";
|
|
505
|
+
$("#pull").hidden = !project.cloudConnected;
|
|
506
|
+
$("#connect-cloud").hidden = project.cloudConnected;
|
|
452
507
|
$("#open-memory").hidden = Boolean(project.exported || project.preview);
|
|
453
508
|
if (project.exported || project.preview) {
|
|
454
509
|
document.body.classList.add("exported");
|
|
@@ -518,6 +573,30 @@ $("#canvas").ondrop = event => {
|
|
|
518
573
|
change();
|
|
519
574
|
};
|
|
520
575
|
$("#refresh").onclick = () => load({ catalogOnly: dirty }).then(() => announce("Project refreshed.")).catch(error => announce(error.message));
|
|
576
|
+
function openCloudSetup() {
|
|
577
|
+
$("#cloud-key").value = "";
|
|
578
|
+
$("#cloud-key").required = !project.hasCloudKey;
|
|
579
|
+
$("#cloud-key-help").replaceChildren(
|
|
580
|
+
project.hasCloudKey ? "Leave this blank to use your saved AgentLyra key. " : "Create a key with resource sync permission. ",
|
|
581
|
+
dom("a", { href: "https://console.agentlyra.in/mcp-servers", target: "_blank", rel: "noopener noreferrer" }, "Open API Keys"));
|
|
582
|
+
$("#cloud-error").textContent = "";
|
|
583
|
+
$("#cloud-setup").showModal();
|
|
584
|
+
}
|
|
585
|
+
$("#connect-cloud").onclick = openCloudSetup;
|
|
586
|
+
$("#close-cloud").onclick = () => $("#cloud-setup").close();
|
|
587
|
+
$("#cloud-setup").addEventListener("close", () => { $("#cloud-key").value = ""; });
|
|
588
|
+
$("#cloud-form").onsubmit = async event => {
|
|
589
|
+
event.preventDefault();
|
|
590
|
+
const control = event.submitter;
|
|
591
|
+
control.disabled = true;
|
|
592
|
+
try {
|
|
593
|
+
await api("connect-cloud", { key: $("#cloud-key").value.trim() });
|
|
594
|
+
$("#cloud-setup").close();
|
|
595
|
+
await load({ catalogOnly: true });
|
|
596
|
+
announce("Cloud mode enabled. You can now pull agents or sync edits.");
|
|
597
|
+
} catch (error) { $("#cloud-error").textContent = error.message; }
|
|
598
|
+
finally { control.disabled = false; }
|
|
599
|
+
};
|
|
521
600
|
$("#pull").onclick = async () => {
|
|
522
601
|
$("#pull").disabled = true;
|
|
523
602
|
try {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { access, stat } from "node:fs/promises";
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import { delimiter, isAbsolute, join } from "node:path";
|
|
5
|
+
const commands = { codex: ["codex", ["exec", "--sandbox", "read-only", "--skip-git-repo-check", "-"]], claude: ["claude", ["-p", "--tools", "", "--permission-mode", "plan"]] };
|
|
6
|
+
async function resolveExecutable(command) {
|
|
7
|
+
const filename = process.platform === "win32" ? command + ".exe" : command;
|
|
8
|
+
for (const entry of (process.env.PATH || "").split(delimiter)) {
|
|
9
|
+
const directory = entry.replace(/^"|"$/g, "");
|
|
10
|
+
if (!isAbsolute(directory)) continue;
|
|
11
|
+
const executable = join(directory, filename);
|
|
12
|
+
try {
|
|
13
|
+
if (!(await stat(executable)).isFile()) continue;
|
|
14
|
+
await access(executable, constants.X_OK);
|
|
15
|
+
return executable;
|
|
16
|
+
} catch {}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function availableCliProviders() {
|
|
21
|
+
const candidates = await Promise.all(Object.entries(commands).map(async ([id, [command]]) =>
|
|
22
|
+
(await resolveExecutable(command)) ? id : null));
|
|
23
|
+
return candidates.filter(Boolean);
|
|
24
|
+
}
|
|
25
|
+
export async function completeCli(provider, root, prompt) {
|
|
26
|
+
if (!Object.hasOwn(commands, provider)) throw new Error("Unsupported CLI provider.");
|
|
27
|
+
const [command, args] = commands[provider];
|
|
28
|
+
const executable = await resolveExecutable(command);
|
|
29
|
+
if (!executable) throw new Error("Install the native " + provider + " executable and add it to PATH.");
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const child = spawn(executable, args, { cwd: root, shell: false, stdio: ["pipe", "pipe", "pipe"], timeout: 120000 });
|
|
32
|
+
let output = "";
|
|
33
|
+
child.on("error", () => reject(new Error("Unable to launch " + provider + " CLI.")));
|
|
34
|
+
child.stdin.on("error", () => reject(new Error("CLI input failed.")));
|
|
35
|
+
child.stderr.resume();
|
|
36
|
+
child.stdout.on("data", chunk => { output += chunk.toString(); if (output.length > 1000000) { child.kill(); reject(new Error("CLI output limit exceeded.")); } });
|
|
37
|
+
child.on("close", code => code === 0 && output.trim() ? resolve(output.trim()) : reject(new Error(provider + " CLI failed. Check authentication and configuration.")));
|
|
38
|
+
child.stdin.end(prompt);
|
|
39
|
+
});
|
|
40
|
+
}
|
package/src/studio/export.js
CHANGED
|
@@ -5,8 +5,8 @@ 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",
|
|
9
|
-
"studio/browser.js", "studio/workflow-editor.js", "studio/studio.css", "studio/agent-ui.js", "studio/agent-ui.css", "app-builder/saved-app.js",
|
|
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
|
+
"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",
|
|
12
12
|
"intelligence/lifecycle.js", "intelligence/graphsnip-provider.js",
|
package/src/studio/index.html
CHANGED
|
@@ -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
|
|
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="
|
|
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
|
package/src/studio/project.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { availableCliProviders, completeCli } from "./cli-providers.js";
|
|
1
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
3
|
import { lstat, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
|
|
3
4
|
import { join, dirname, basename } from "node:path";
|
|
4
5
|
import { resourceFiles } from "../resource-files.js";
|
|
5
6
|
import { frameworkDescriptor, runFrameworkAgent } from "../framework/agent.js";
|
|
6
7
|
import { createSavedAgentClient } from "../app-builder/saved-app.js";
|
|
7
|
-
import { createOpenAIProvider, openStore } from "../runtime/local-cli.js";
|
|
8
|
-
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";
|
|
9
10
|
import { pythonDescriptor, runPythonAgent } from "./python-agent.js";
|
|
10
11
|
import { withProjectMemory } from "../memory/lifecycle.js";
|
|
11
12
|
import { runAgent } from "../runtime/run-agent.js";
|
|
@@ -91,6 +92,18 @@ export async function readCatalog(root) {
|
|
|
91
92
|
const id = "python:" + item.id;
|
|
92
93
|
if (!agents.has(id)) agents.set(id, { id, name: item.name, source: "python", ...descriptor });
|
|
93
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
|
+
}
|
|
94
107
|
const skills = await records("skills");
|
|
95
108
|
const skillRoot = join(root, ".lyra", "skills");
|
|
96
109
|
for (const relative of await resourceFiles(skillRoot, "SKILL.md")) {
|
|
@@ -203,17 +216,25 @@ async function cloudKey(root, exported) {
|
|
|
203
216
|
return exported ? process.env.LYRA_API_KEY : readSdkKey(root);
|
|
204
217
|
}
|
|
205
218
|
|
|
206
|
-
export async function describeRun(root, targets, appCatalog) {
|
|
219
|
+
export async function describeRun(root, targets, appCatalog, provider) {
|
|
207
220
|
const catalog = appCatalog ?? await readCatalog(root);
|
|
208
221
|
const agents = resolveSequence(catalog, targets).map(step => catalog.agents.get(step.agentId));
|
|
209
|
-
const needsModel = agents.some(agent => agent.source
|
|
210
|
-
const
|
|
222
|
+
const needsModel = agents.some(agent => ["local", "cloud"].includes(agent.source));
|
|
223
|
+
const cli = appCatalog ? [] : await availableCliProviders();
|
|
224
|
+
const hasCloud = agents.some(agent => agent.source === 'cloud');
|
|
225
|
+
let cloudAvailable = false;
|
|
226
|
+
try { createSavedAgentClient({ key: await cloudKey(root, Boolean(appCatalog)) ?? '' }); cloudAvailable = true; } catch {}
|
|
227
|
+
const providers = needsModel ? [...cli, 'openai', ...(cloudAvailable || hasCloud ? ['cloud'] : [])] : [];
|
|
228
|
+
provider ??= needsModel ? (hasCloud && cloudAvailable ? "cloud" : "openai") : undefined;
|
|
229
|
+
const models = needsModel && provider === 'openai' ? studioModels() : [];
|
|
211
230
|
const issues = [];
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
231
|
+
const needsOpenAIKey = needsModel && provider === "openai" &&
|
|
232
|
+
!(appCatalog ? process.env.OPENAI_API_KEY?.trim() : await readOpenAIKey());
|
|
233
|
+
if (needsOpenAIKey) issues.push(appCatalog
|
|
234
|
+
? "Configure an OpenAI API key on the app server."
|
|
235
|
+
: "Add an OpenAI API key to run with the OpenAI API, or choose another provider.");
|
|
236
|
+
if (needsModel && provider === 'openai' && !models.length) issues.push("Set LYRA_STUDIO_MODELS to a comma-separated list of OpenAI model IDs.");
|
|
237
|
+
if (hasCloud || provider === "cloud") {
|
|
217
238
|
try {
|
|
218
239
|
createSavedAgentClient({ key: await cloudKey(root, Boolean(appCatalog)) ?? "" });
|
|
219
240
|
} catch (error) {
|
|
@@ -223,10 +244,11 @@ export async function describeRun(root, targets, appCatalog) {
|
|
|
223
244
|
const steps = agents.map(agent => ({
|
|
224
245
|
name: agent.name, framework: agent.framework, ...runtimeLabels[agent.source],
|
|
225
246
|
}));
|
|
226
|
-
|
|
247
|
+
if (needsModel && !providers.includes(provider)) issues.push('Selected provider is unavailable.');
|
|
248
|
+
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" };
|
|
227
249
|
}
|
|
228
250
|
|
|
229
|
-
export async function runSelection(root, { targets, input, model }, catalog) {
|
|
251
|
+
export async function runSelection(root, { targets, input, model, provider }, catalog) {
|
|
230
252
|
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
231
253
|
throw new Error("Enter up to 4,000 characters.");
|
|
232
254
|
}
|
|
@@ -234,12 +256,19 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
234
256
|
catalog ??= await readCatalog(root);
|
|
235
257
|
const sequence = resolveSequence(catalog, targets);
|
|
236
258
|
const agents = sequence.map(step => catalog.agents.get(step.agentId));
|
|
237
|
-
const local = agents.some(agent => agent.source
|
|
238
|
-
|
|
239
|
-
|
|
259
|
+
const local = agents.some(agent => ["local", "cloud"].includes(agent.source));
|
|
260
|
+
const hasCloud = agents.some(agent => agent.source === "cloud");
|
|
261
|
+
const cli = exported ? [] : await availableCliProviders();
|
|
262
|
+
provider ??= hasCloud ? "cloud" : "openai";
|
|
263
|
+
if (local && !['openai', 'cloud', ...cli].includes(provider)) throw new Error('Selected provider is unavailable.');
|
|
264
|
+
const openAIKey = local && provider === "openai"
|
|
265
|
+
? exported ? process.env.OPENAI_API_KEY?.trim() : await readOpenAIKey()
|
|
266
|
+
: undefined;
|
|
267
|
+
if (local && provider === "openai" && (!openAIKey || !modelId.test(model ?? ""))) {
|
|
268
|
+
throw new Error("Configure an OpenAI API key and choose a model for this run.");
|
|
240
269
|
}
|
|
241
270
|
let cloud = null;
|
|
242
|
-
if (
|
|
271
|
+
if (hasCloud || provider === "cloud") {
|
|
243
272
|
cloud = createSavedAgentClient({ key: await cloudKey(root, exported) ?? "" });
|
|
244
273
|
}
|
|
245
274
|
const store = local || agents.some(agent => agent.source === "framework") ? await openStore(root) : null;
|
|
@@ -254,12 +283,17 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
254
283
|
const text = [step.task, input.trim(), previous && "Previous result: " + previous].filter(Boolean).join("\n\n").slice(0, 12_000);
|
|
255
284
|
const status = { index: steps.length + 1, agent: agent.name, source: agent.source, traceId: randomUUID() };
|
|
256
285
|
steps.push(status);
|
|
286
|
+
console.info('[Lyra Studio]', JSON.stringify({ event: 'step.started', traceId: status.traceId, agent: agent.name, source: agent.source }));
|
|
257
287
|
const started = Date.now();
|
|
258
288
|
let output;
|
|
259
289
|
let run;
|
|
260
290
|
try {
|
|
261
|
-
if (agent.source === "cloud") {
|
|
262
|
-
|
|
291
|
+
if (["local", "cloud"].includes(agent.source) && provider === "cloud") {
|
|
292
|
+
const result = agent.source === "cloud" ? await cloud.invokeWithTrace(agent.id.slice("cloud:".length), text, status.traceId) : await cloud.invokeLocal(agent, text, status.traceId);
|
|
293
|
+
output = result.output;
|
|
294
|
+
status.runId = result.runId;
|
|
295
|
+
status.provider = result.provider || "openai";
|
|
296
|
+
status.model = result.model || null;
|
|
263
297
|
} else if (agent.source === "python") {
|
|
264
298
|
output = await runPythonAgent(root, agent, text, exported);
|
|
265
299
|
} else if (agent.source === "framework") {
|
|
@@ -280,10 +314,17 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
280
314
|
|
|
281
315
|
output = event.data.result.text;
|
|
282
316
|
run = { runId: event.run_id, traceId, framework: agent.framework };
|
|
317
|
+
} else if (provider !== 'openai') {
|
|
318
|
+
status.provider = provider;
|
|
319
|
+
const definition = agent.source === 'cloud' ? await cloud.definition(agent.id.slice(6)) : agent;
|
|
320
|
+
output = await completeCli(provider, root, definition.prompt + '\n\nUser input:\n' + text);
|
|
283
321
|
} else {
|
|
284
|
-
|
|
322
|
+
status.provider = 'openai';
|
|
323
|
+
status.model = model;
|
|
324
|
+
const definition = agent.source === "cloud" ? await cloud.definition(agent.id.slice(6)) : agent;
|
|
325
|
+
const request = { model, messages: [{ role: "system", content: definition.prompt }, { role: "user", content: text }] };
|
|
285
326
|
const event = await runAgent({
|
|
286
|
-
agentId: agent.id, store, traceId: status.traceId, provider: createOpenAIProvider(
|
|
327
|
+
agentId: agent.id, store, traceId: status.traceId, provider: createOpenAIProvider(openAIKey, fetch),
|
|
287
328
|
request: exported ? request : await withProjectMemory(root, request),
|
|
288
329
|
});
|
|
289
330
|
status.runId = event.run_id;
|
|
@@ -297,6 +338,7 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
297
338
|
throw Object.assign(new Error(message, { cause: error }), { progress: { traceId, steps, answers } });
|
|
298
339
|
} finally {
|
|
299
340
|
status.durationMs = Date.now() - started;
|
|
341
|
+
console.info('[Lyra Studio]', JSON.stringify({ event: 'step.' + status.state, ...status }));
|
|
300
342
|
}
|
|
301
343
|
if (step.output) named.set(step.output, output);
|
|
302
344
|
answers.push({ agent: agent.name, output, ...(run ? { run } : {}) });
|
package/src/studio/pull-agent.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
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 } = {}) {
|
package/src/studio/push.js
CHANGED
|
@@ -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" },
|
package/src/studio/server.js
CHANGED
|
@@ -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,16 @@ 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
|
+
}],
|
|
28
39
|
["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
|
|
29
40
|
["/api/pull", () => pull(root)],
|
|
30
41
|
["/api/push", ({ id }) => pushStudioAgent(root, id)],
|
|
@@ -53,8 +64,8 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
|
|
|
53
64
|
const server = createServer(async (req, res) => {
|
|
54
65
|
const send = (status, data, type = "application/json") => {
|
|
55
66
|
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'",
|
|
67
|
+
"Content-Type": type.startsWith("image/") ? type : type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
68
|
+
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self'; connect-src 'self'; frame-ancestors 'none'",
|
|
58
69
|
});
|
|
59
70
|
res.end(type === "application/json" ? JSON.stringify(data) : data);
|
|
60
71
|
};
|
|
@@ -67,12 +78,17 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
|
|
|
67
78
|
try {
|
|
68
79
|
if (req.method === "GET" && req.url === "/api/project") {
|
|
69
80
|
const catalog = appCatalog ?? await readCatalog(root);
|
|
81
|
+
const mode = appCatalog ? undefined : await readMode(root);
|
|
82
|
+
const hasCloudKey = !appCatalog && Boolean(await readSdkKey(root));
|
|
70
83
|
return send(200, {
|
|
71
84
|
...await readLayout(root),
|
|
72
85
|
exported: Boolean(appCatalog),
|
|
73
86
|
preview,
|
|
74
|
-
mode
|
|
75
|
-
|
|
87
|
+
mode,
|
|
88
|
+
hasCloudKey,
|
|
89
|
+
cloudConnected: mode !== "standalone" && hasCloudKey,
|
|
90
|
+
agents: [...catalog.agents.values()].map(({ id, name, source, framework, syncStatus, linkedLocalId }) =>
|
|
91
|
+
({ id, name, source, framework, syncStatus, linkedLocalId })),
|
|
76
92
|
frameworkCandidates: appCatalog ? [] : await discoverFrameworkAgents(root).catch(() => []),
|
|
77
93
|
workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
|
|
78
94
|
skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
|
|
@@ -99,7 +115,7 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
|
|
|
99
115
|
if (!body.targets) return send(409, { error: "The saved layout changed. Reload the preview before running." });
|
|
100
116
|
}
|
|
101
117
|
if (req.url === "/api/run-plan") {
|
|
102
|
-
return send(200, await describeRun(root, body.targets, appCatalog));
|
|
118
|
+
return send(200, await describeRun(root, body.targets, appCatalog, body.provider));
|
|
103
119
|
}
|
|
104
120
|
if (req.url === "/api/run") {
|
|
105
121
|
if (running) return send(409, { error: "A Studio run is already in progress." });
|
|
@@ -140,7 +156,7 @@ export async function runStudio(args, output = process.stdout) {
|
|
|
140
156
|
if (args.length === 2 && args[0] === "push") {
|
|
141
157
|
const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
|
|
142
158
|
const result = await pushStudioAgent(process.cwd(), id);
|
|
143
|
-
output.write((result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
|
|
159
|
+
output.write((result.unchanged ? "Already synced " : result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
|
|
144
160
|
return;
|
|
145
161
|
}
|
|
146
162
|
if (args.length === 2 && args[0] === "pull-agent") {
|
package/src/studio/session.js
CHANGED
|
@@ -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.");
|
package/src/studio/studio.css
CHANGED
|
@@ -255,3 +255,120 @@ main:has(#inspector-panel:not([hidden])) {
|
|
|
255
255
|
margin: 1rem 0;
|
|
256
256
|
padding-left: .85rem;
|
|
257
257
|
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
/* AgentLyra workspace */
|
|
261
|
+
:root {
|
|
262
|
+
--studio-ink: #192b24;
|
|
263
|
+
--studio-muted: #52675e;
|
|
264
|
+
--studio-line: #dce6df;
|
|
265
|
+
--studio-green: #214e3d;
|
|
266
|
+
--studio-tint: #eaf3ed;
|
|
267
|
+
}
|
|
268
|
+
body {
|
|
269
|
+
background: #f4f7f5;
|
|
270
|
+
color: var(--studio-ink);
|
|
271
|
+
font: 14px/1.5 "Segoe UI", system-ui, sans-serif;
|
|
272
|
+
}
|
|
273
|
+
.studio-header {
|
|
274
|
+
position: sticky;
|
|
275
|
+
top: 0;
|
|
276
|
+
z-index: 2;
|
|
277
|
+
min-height: 68px;
|
|
278
|
+
padding: .65rem clamp(.9rem, 2.5vw, 2rem);
|
|
279
|
+
border-color: var(--studio-line);
|
|
280
|
+
}
|
|
281
|
+
.studio-brand, .toolbar { display: flex; align-items: center; gap: .5rem; }
|
|
282
|
+
.toolbar { flex-wrap: wrap; }
|
|
283
|
+
.studio-mark {
|
|
284
|
+
display: grid;
|
|
285
|
+
place-items: center;
|
|
286
|
+
width: 34px;
|
|
287
|
+
height: 34px;
|
|
288
|
+
margin-right: .2rem;
|
|
289
|
+
border-radius: 9px;
|
|
290
|
+
background: var(--studio-green);
|
|
291
|
+
color: white;
|
|
292
|
+
font-size: 19px;
|
|
293
|
+
font-weight: 650;
|
|
294
|
+
}
|
|
295
|
+
#project-name { display: block; color: var(--studio-muted); font-size: .78rem; overflow-wrap: anywhere; }
|
|
296
|
+
#studio-views { padding: .22rem; background: #f0f4f1; border: 1px solid var(--studio-line); border-radius: 9px; }
|
|
297
|
+
#studio-views button { border-color: transparent; background: transparent; }
|
|
298
|
+
#studio-views button[aria-pressed="true"] { background: white; border-color: var(--studio-line); box-shadow: 0 1px 3px #192b2411; }
|
|
299
|
+
h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -.025em; }
|
|
300
|
+
h2 { font-weight: 650; }
|
|
301
|
+
button {
|
|
302
|
+
min-height: 34px;
|
|
303
|
+
border-color: #cbdacf;
|
|
304
|
+
border-radius: 7px;
|
|
305
|
+
font-weight: 600;
|
|
306
|
+
}
|
|
307
|
+
button:disabled { cursor: not-allowed; }
|
|
308
|
+
.primary { background: var(--studio-green); border-color: var(--studio-green); }
|
|
309
|
+
:is(button, a, input, textarea, select, summary):focus-visible { outline: 2px solid #286b51; outline-offset: 2px; }
|
|
310
|
+
label { font-size: .85rem; font-weight: 600; }
|
|
311
|
+
input, textarea, select { border-color: #cbdacf; border-radius: 7px; padding: .52rem .65rem; }
|
|
312
|
+
select { padding-right: 1.4rem; }
|
|
313
|
+
main { padding-inline: clamp(.9rem, 2.5vw, 2rem); }
|
|
314
|
+
main > aside, main > section { border-color: var(--studio-line); border-radius: 12px; padding: 1.1rem; box-shadow: 0 2px 5px #192b2408; }
|
|
315
|
+
#library { top: 5.15rem; }
|
|
316
|
+
#library-content { padding-right: .25rem; }
|
|
317
|
+
#library-tabs button[aria-pressed="true"] { background: var(--studio-tint); border-color: #86ac97; }
|
|
318
|
+
#status { color: var(--studio-muted); font-size: .83rem; padding-inline: clamp(.9rem, 2.5vw, 2rem); }
|
|
319
|
+
#status:empty { min-height: .65rem; }
|
|
320
|
+
#canvas {
|
|
321
|
+
min-height: 22rem;
|
|
322
|
+
border-color: #adbfaf;
|
|
323
|
+
background-color: #f9fcfa;
|
|
324
|
+
background-image: radial-gradient(#dce6df 1px, transparent 1px);
|
|
325
|
+
background-size: 16px 16px;
|
|
326
|
+
padding: .9rem;
|
|
327
|
+
}
|
|
328
|
+
.library-entry { margin-bottom: .35rem; padding: .1rem .2rem; border: 1px solid var(--studio-line); border-radius: 7px; }
|
|
329
|
+
.library-entry[open] { border-color: #a1bbaa; }
|
|
330
|
+
.library-entry summary:hover { color: #286b51; }
|
|
331
|
+
.library-entry .agent-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .4rem; }
|
|
332
|
+
.library-entry .agent-meta span { padding-left: 0; }
|
|
333
|
+
.pill, .library-entry .agent-meta .pill {
|
|
334
|
+
display: inline-block;
|
|
335
|
+
padding: .1rem .45rem;
|
|
336
|
+
border: 1px solid #d4e5da;
|
|
337
|
+
border-radius: 99px;
|
|
338
|
+
background: var(--studio-tint);
|
|
339
|
+
color: var(--studio-green);
|
|
340
|
+
font-size: .73rem;
|
|
341
|
+
font-weight: 650;
|
|
342
|
+
}
|
|
343
|
+
.cloud-callout, #openai-setup {
|
|
344
|
+
padding: .7rem;
|
|
345
|
+
margin-bottom: .65rem;
|
|
346
|
+
border: 1px solid var(--studio-line);
|
|
347
|
+
border-radius: 8px;
|
|
348
|
+
background: #f4f8f5;
|
|
349
|
+
}
|
|
350
|
+
#openai-setup summary { cursor: pointer; font-weight: 650; }
|
|
351
|
+
#openai-setup p, #cloud-key-help { color: var(--studio-muted); }
|
|
352
|
+
#run-result:empty, #openai-status:empty, #cloud-error:empty { display: none; }
|
|
353
|
+
#drawer, #cloud-setup { padding: 1.25rem; box-shadow: -12px 0 44px #192b2422; }
|
|
354
|
+
#drawer::backdrop, #cloud-setup::backdrop { background: #132d246b; }
|
|
355
|
+
#cloud-setup a { color: var(--studio-green); font-weight: 600; }
|
|
356
|
+
@media (max-width: 950px) {
|
|
357
|
+
.studio-header { position: static; flex-wrap: wrap; }
|
|
358
|
+
#library { top: 1rem; }
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.canvas-empty {
|
|
362
|
+
place-self: center;
|
|
363
|
+
align-self: start;
|
|
364
|
+
max-width: 26rem;
|
|
365
|
+
margin: 6rem 0 2rem;
|
|
366
|
+
padding: .8rem 1.15rem;
|
|
367
|
+
border: 1px solid var(--studio-line);
|
|
368
|
+
border-radius: 9px;
|
|
369
|
+
background: white;
|
|
370
|
+
text-align: center;
|
|
371
|
+
}
|
|
372
|
+
.canvas-empty p { margin: .2rem 0 0; color: var(--studio-muted); }
|
|
373
|
+
.exported #canvas { background-image: none; min-height: 0; }
|
|
374
|
+
.exported .canvas-empty { display: none; }
|
package/src/studio/sync.js
CHANGED
|
@@ -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)
|
|
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(); };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
const SETTING = "chat.agentFilesLocations";
|
|
5
|
+
const AGENTS = ".lyra/agents";
|
|
6
|
+
|
|
7
|
+
function tokenize(source) {
|
|
8
|
+
const masked = source.split("");
|
|
9
|
+
const tokens = [];
|
|
10
|
+
for (let i = 0; i < source.length;) {
|
|
11
|
+
const ch = source[i];
|
|
12
|
+
if (/\s/.test(ch)) { i += 1; continue; }
|
|
13
|
+
if (ch === "/" && source[i + 1] === "/") {
|
|
14
|
+
let j = i + 2;
|
|
15
|
+
while (j < source.length && source[j] !== "\n") j += 1;
|
|
16
|
+
for (let k = i; k < j; k += 1) masked[k] = " ";
|
|
17
|
+
i = j;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (ch === "/" && source[i + 1] === "*") {
|
|
21
|
+
const end = source.indexOf("*/", i + 2);
|
|
22
|
+
if (end < 0) throw new Error("Unterminated comment in VS Code settings.json.");
|
|
23
|
+
const j = end + 2;
|
|
24
|
+
for (let k = i; k < j; k += 1) if (masked[k] !== "\n" && masked[k] !== "\r") masked[k] = " ";
|
|
25
|
+
i = j;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (ch === '"') {
|
|
29
|
+
const start = i++;
|
|
30
|
+
while (i < source.length) {
|
|
31
|
+
if (source[i] === "\\") { i += 2; continue; }
|
|
32
|
+
if (source[i++] === '"') break;
|
|
33
|
+
}
|
|
34
|
+
tokens.push({ kind: "string", value: JSON.parse(source.slice(start, i)), start, end: i });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if ("{}[]:,".includes(ch)) {
|
|
38
|
+
tokens.push({ kind: ch, start: i, end: i + 1 });
|
|
39
|
+
i += 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const start = i++;
|
|
43
|
+
while (i < source.length && !/[\s{}\[\]:,\/]/.test(source[i])) i += 1;
|
|
44
|
+
tokens.push({ kind: "literal", start, end: i });
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < tokens.length - 1; i += 1) {
|
|
47
|
+
if (tokens[i].kind === "," && ["}", "]"].includes(tokens[i + 1].kind)) {
|
|
48
|
+
masked[tokens[i].start] = " ";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { tokens, value: JSON.parse(masked.join("")) };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function valueEnd(tokens, index) {
|
|
55
|
+
const opening = tokens[index]?.kind;
|
|
56
|
+
if (!["{", "["].includes(opening)) return index + 1;
|
|
57
|
+
const stack = [];
|
|
58
|
+
for (let i = index; i < tokens.length; i += 1) {
|
|
59
|
+
const kind = tokens[i].kind;
|
|
60
|
+
if (kind === "{" || kind === "[") stack.push(kind);
|
|
61
|
+
if (kind === "}" || kind === "]") {
|
|
62
|
+
const expected = kind === "}" ? "{" : "[";
|
|
63
|
+
if (stack.pop() !== expected) throw new Error("Invalid VS Code settings.json structure.");
|
|
64
|
+
if (!stack.length) return i + 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw new Error("Unclosed JSON container in VS Code settings.json.");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function objectAt(tokens, opening) {
|
|
71
|
+
if (tokens[opening]?.kind !== "{") throw new Error("Expected object in VS Code settings.json.");
|
|
72
|
+
const properties = [];
|
|
73
|
+
let i = opening + 1;
|
|
74
|
+
while (i < tokens.length && tokens[i].kind !== "}") {
|
|
75
|
+
const key = tokens[i];
|
|
76
|
+
if (key.kind !== "string" || tokens[i + 1]?.kind !== ":") {
|
|
77
|
+
throw new Error("Invalid VS Code settings.json property.");
|
|
78
|
+
}
|
|
79
|
+
const valueStart = i + 2;
|
|
80
|
+
const endIndex = valueEnd(tokens, valueStart);
|
|
81
|
+
properties.push({ key: key.value, valueStart, endIndex });
|
|
82
|
+
i = endIndex;
|
|
83
|
+
if (tokens[i]?.kind === ",") i += 1;
|
|
84
|
+
else if (tokens[i]?.kind !== "}") throw new Error("Invalid VS Code settings.json separator.");
|
|
85
|
+
}
|
|
86
|
+
if (tokens[i]?.kind !== "}") throw new Error("Unclosed VS Code settings.json object.");
|
|
87
|
+
return { properties, closeIndex: i, opening };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function insertProperty(source, tokens, object, name, value) {
|
|
91
|
+
const close = tokens[object.closeIndex].start;
|
|
92
|
+
const open = tokens[object.opening].start;
|
|
93
|
+
const lineStart = source.lastIndexOf("\n", open - 1) + 1;
|
|
94
|
+
const indent = (/^\s*/.exec(source.slice(lineStart, open)) || [""])[0];
|
|
95
|
+
const first = object.properties[0];
|
|
96
|
+
const childIndent = first
|
|
97
|
+
? (/^\s*/.exec(source.slice(source.lastIndexOf("\n", tokens[first.valueStart].start - 1) + 1)) || [indent + " "])[0]
|
|
98
|
+
: indent + " ";
|
|
99
|
+
const row = "\n" + childIndent + JSON.stringify(name) + ": " + value + "\n" + indent;
|
|
100
|
+
let updated = source.slice(0, close) + row + source.slice(close);
|
|
101
|
+
const last = object.properties.at(-1);
|
|
102
|
+
if (last && tokens[object.closeIndex - 1]?.kind !== ",") {
|
|
103
|
+
const end = tokens[last.endIndex - 1].end;
|
|
104
|
+
updated = updated.slice(0, end) + "," + updated.slice(end);
|
|
105
|
+
}
|
|
106
|
+
return updated;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Register Lyra agent discovery in the current VS Code workspace.
|
|
111
|
+
* Preserve existing JSONC comments, other settings, and unrelated providers.
|
|
112
|
+
*/
|
|
113
|
+
export async function ensureVSCodeAgentDiscovery(root) {
|
|
114
|
+
const directory = join(root, ".vscode");
|
|
115
|
+
const file = join(directory, "settings.json");
|
|
116
|
+
await mkdir(directory, { recursive: true });
|
|
117
|
+
const stat = await lstat(file).catch(error => {
|
|
118
|
+
if (error.code === "ENOENT") return null;
|
|
119
|
+
throw error;
|
|
120
|
+
});
|
|
121
|
+
if (stat && !stat.isFile()) throw new Error("Expected regular VS Code settings file: " + file);
|
|
122
|
+
if (!stat) {
|
|
123
|
+
await writeFile(file, JSON.stringify({ [SETTING]: { [AGENTS]: true } }, null, 2) + "\n", { flag: "wx" });
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const original = await readFile(file, "utf8");
|
|
128
|
+
const source = original.trim() ? original : "{}";
|
|
129
|
+
const { tokens, value } = tokenize(source);
|
|
130
|
+
if (!value || Array.isArray(value) || typeof value !== "object") {
|
|
131
|
+
throw new Error("VS Code settings.json must contain an object.");
|
|
132
|
+
}
|
|
133
|
+
if (value[SETTING]?.[AGENTS] === true) return false;
|
|
134
|
+
|
|
135
|
+
const rootObject = objectAt(tokens, 0);
|
|
136
|
+
const entry = rootObject.properties.find(property => property.key === SETTING);
|
|
137
|
+
let updated;
|
|
138
|
+
if (!entry) {
|
|
139
|
+
updated = insertProperty(source, tokens, rootObject, SETTING, JSON.stringify({ [AGENTS]: true }));
|
|
140
|
+
} else {
|
|
141
|
+
if (!value[SETTING] || Array.isArray(value[SETTING]) || typeof value[SETTING] !== "object") {
|
|
142
|
+
throw new Error(SETTING + " must be an object in VS Code settings.json.");
|
|
143
|
+
}
|
|
144
|
+
const nested = objectAt(tokens, entry.valueStart);
|
|
145
|
+
const agentEntry = nested.properties.find(property => property.key === AGENTS);
|
|
146
|
+
if (agentEntry) {
|
|
147
|
+
const start = tokens[agentEntry.valueStart].start;
|
|
148
|
+
const end = tokens[agentEntry.endIndex - 1].end;
|
|
149
|
+
updated = source.slice(0, start) + "true" + source.slice(end);
|
|
150
|
+
} else {
|
|
151
|
+
updated = insertProperty(source, tokens, nested, AGENTS, "true");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Validate the generated JSONC before replacing the workspace configuration.
|
|
155
|
+
tokenize(updated);
|
|
156
|
+
await writeFile(file, updated, "utf8");
|
|
157
|
+
return true;
|
|
158
|
+
}
|