agent-lyra 0.10.0 → 0.11.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.
- package/README.md +21 -2
- 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 +4 -1
- package/src/standalone/init.js +2 -0
- package/src/studio/browser.js +24 -4
- package/src/studio/cli-providers.js +40 -0
- package/src/studio/export.js +1 -1
- package/src/studio/index.html +1 -1
- package/src/studio/project.js +39 -14
- package/src/studio/server.js +1 -1
- package/src/vscode/workspace.js +158 -0
package/README.md
CHANGED
|
@@ -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.
|
|
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
|
|
|
@@ -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/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
|
@@ -336,6 +336,10 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
336
336
|
const plan = $("#run-plan");
|
|
337
337
|
plan.hidden = true;
|
|
338
338
|
plan.replaceChildren();
|
|
339
|
+
const providerPicker = $("#execution-provider");
|
|
340
|
+
const providerLabel = $('label[for="execution-provider"]');
|
|
341
|
+
providerPicker.hidden = providerLabel.hidden = true;
|
|
342
|
+
providerPicker.disabled = false;
|
|
339
343
|
const picker = $("#model");
|
|
340
344
|
const modelLabel = $('label[for="model"]');
|
|
341
345
|
picker.hidden = modelLabel.hidden = true;
|
|
@@ -348,8 +352,11 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
348
352
|
(component.outputId && !project.layout.some(node => node.id === component.outputId && node.kind === "output")))) {
|
|
349
353
|
throw new Error("Fix the input or output binding in the inspector.");
|
|
350
354
|
}
|
|
351
|
-
|
|
352
|
-
|
|
355
|
+
let planRequest = 0;
|
|
356
|
+
const refreshPlan = async provider => {
|
|
357
|
+
const request = ++planRequest;
|
|
358
|
+
const setup = await api("run-plan", { targets: action.targets, buttonId, revision: action.revision, provider });
|
|
359
|
+
if (pending !== action || request !== planRequest) return;
|
|
353
360
|
const list = element("ol");
|
|
354
361
|
for (const step of setup.steps) {
|
|
355
362
|
const row = element("li");
|
|
@@ -359,6 +366,9 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
359
366
|
}
|
|
360
367
|
plan.replaceChildren(element("h2", "Execution steps"), list);
|
|
361
368
|
plan.hidden = false;
|
|
369
|
+
providerPicker.replaceChildren(...(setup.providers || []).map(id => new Option(id === "openai" ? "Local OpenAI API" : id === "cloud" ? "Lyra Cloud" : id + " CLI", id)));
|
|
370
|
+
providerPicker.value = setup.provider || "";
|
|
371
|
+
providerPicker.hidden = providerLabel.hidden = !setup.providers?.length;
|
|
362
372
|
const previousModel = picker.value;
|
|
363
373
|
picker.replaceChildren(...setup.models.map(model => new Option(model, model)));
|
|
364
374
|
if (setup.models.includes(previousModel)) picker.value = previousModel;
|
|
@@ -368,6 +378,16 @@ async function openRun(targets, input = "", outputId = "", buttonId) {
|
|
|
368
378
|
action.ready = setup.issues.length === 0;
|
|
369
379
|
$("#run-status").textContent = setup.issues.join(" ");
|
|
370
380
|
$("#run").disabled = !action.ready;
|
|
381
|
+
};
|
|
382
|
+
providerPicker.onchange = async () => {
|
|
383
|
+
action.ready = false;
|
|
384
|
+
$("#run").disabled = true;
|
|
385
|
+
providerPicker.disabled = true;
|
|
386
|
+
try { await refreshPlan(providerPicker.value); }
|
|
387
|
+
catch (error) { if (pending === action) $("#run-status").textContent = error.message; }
|
|
388
|
+
finally { if (pending === action) providerPicker.disabled = false; }
|
|
389
|
+
};
|
|
390
|
+
await refreshPlan();
|
|
371
391
|
} catch (error) {
|
|
372
392
|
if (pending === action) $("#run-status").textContent = error.message;
|
|
373
393
|
}
|
|
@@ -378,7 +398,7 @@ function showRunResults({ answers, traceId, steps }) {
|
|
|
378
398
|
if (steps) {
|
|
379
399
|
for (const step of steps) {
|
|
380
400
|
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,
|
|
401
|
+
lines.push([heading, "Step trace " + step.traceId, step.runId && "Runtime run " + step.runId, step.provider && "Provider " + step.provider, step.model && "Model " + step.model,
|
|
382
402
|
answers[step.index - 1]?.output].filter(Boolean).join("\n"));
|
|
383
403
|
}
|
|
384
404
|
} else {
|
|
@@ -405,7 +425,7 @@ $("#runner").onsubmit = async event => {
|
|
|
405
425
|
$("#run-status").textContent = "Running…";
|
|
406
426
|
$("#run-result").textContent = "";
|
|
407
427
|
try {
|
|
408
|
-
const result = await api("run", { targets: pending.targets, buttonId: pending.buttonId, revision: pending.revision, input: prompt.value, model: $("#model").value });
|
|
428
|
+
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
429
|
showRunResults(result);
|
|
410
430
|
if (pending.outputId) outputs.set(pending.outputId, result.answers.at(-1).output);
|
|
411
431
|
renderCanvas();
|
|
@@ -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
|
@@ -6,7 +6,7 @@ import { readCatalog, resolveSequence, validateLayout, validateRunBindings } fro
|
|
|
6
6
|
const runtime = [
|
|
7
7
|
"resource-files.js",
|
|
8
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",
|
|
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
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
<details><summary>Skill proposals</summary><section id="memory-proposals" aria-label="Skill proposals"></section></details>
|
|
71
71
|
</dialog>
|
|
72
72
|
<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="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>
|
|
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>
|
|
74
74
|
</body></html>
|
package/src/studio/project.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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";
|
|
@@ -203,17 +204,23 @@ async function cloudKey(root, exported) {
|
|
|
203
204
|
return exported ? process.env.LYRA_API_KEY : readSdkKey(root);
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
export async function describeRun(root, targets, appCatalog) {
|
|
207
|
+
export async function describeRun(root, targets, appCatalog, provider) {
|
|
207
208
|
const catalog = appCatalog ?? await readCatalog(root);
|
|
208
209
|
const agents = resolveSequence(catalog, targets).map(step => catalog.agents.get(step.agentId));
|
|
209
|
-
const needsModel = agents.some(agent => agent.source
|
|
210
|
-
const
|
|
210
|
+
const needsModel = agents.some(agent => ["local", "cloud"].includes(agent.source));
|
|
211
|
+
const cli = appCatalog ? [] : await availableCliProviders();
|
|
212
|
+
const hasCloud = agents.some(agent => agent.source === 'cloud');
|
|
213
|
+
let cloudAvailable = false;
|
|
214
|
+
try { createSavedAgentClient({ key: await cloudKey(root, Boolean(appCatalog)) ?? '' }); cloudAvailable = true; } catch {}
|
|
215
|
+
const providers = needsModel ? [...cli, 'openai', ...(cloudAvailable || hasCloud ? ['cloud'] : [])] : [];
|
|
216
|
+
provider ??= needsModel ? (hasCloud && cloudAvailable ? "cloud" : "openai") : undefined;
|
|
217
|
+
const models = needsModel && provider === 'openai' ? studioModels() : [];
|
|
211
218
|
const issues = [];
|
|
212
|
-
if (needsModel && !process.env.OPENAI_API_KEY?.trim()) {
|
|
219
|
+
if (needsModel && provider === 'openai' && !process.env.OPENAI_API_KEY?.trim()) {
|
|
213
220
|
issues.push("Set OPENAI_API_KEY in the terminal that starts Studio, then restart Studio.");
|
|
214
221
|
}
|
|
215
|
-
if (needsModel && !models.length) issues.push("Set LYRA_STUDIO_MODELS to a comma-separated list of OpenAI model IDs.");
|
|
216
|
-
if (
|
|
222
|
+
if (needsModel && provider === 'openai' && !models.length) issues.push("Set LYRA_STUDIO_MODELS to a comma-separated list of OpenAI model IDs.");
|
|
223
|
+
if (hasCloud || provider === "cloud") {
|
|
217
224
|
try {
|
|
218
225
|
createSavedAgentClient({ key: await cloudKey(root, Boolean(appCatalog)) ?? "" });
|
|
219
226
|
} catch (error) {
|
|
@@ -223,10 +230,11 @@ export async function describeRun(root, targets, appCatalog) {
|
|
|
223
230
|
const steps = agents.map(agent => ({
|
|
224
231
|
name: agent.name, framework: agent.framework, ...runtimeLabels[agent.source],
|
|
225
232
|
}));
|
|
226
|
-
|
|
233
|
+
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" };
|
|
227
235
|
}
|
|
228
236
|
|
|
229
|
-
export async function runSelection(root, { targets, input, model }, catalog) {
|
|
237
|
+
export async function runSelection(root, { targets, input, model, provider }, catalog) {
|
|
230
238
|
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
231
239
|
throw new Error("Enter up to 4,000 characters.");
|
|
232
240
|
}
|
|
@@ -234,12 +242,16 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
234
242
|
catalog ??= await readCatalog(root);
|
|
235
243
|
const sequence = resolveSequence(catalog, targets);
|
|
236
244
|
const agents = sequence.map(step => catalog.agents.get(step.agentId));
|
|
237
|
-
const local = agents.some(agent => agent.source
|
|
238
|
-
|
|
245
|
+
const local = agents.some(agent => ["local", "cloud"].includes(agent.source));
|
|
246
|
+
const hasCloud = agents.some(agent => agent.source === "cloud");
|
|
247
|
+
const cli = exported ? [] : await availableCliProviders();
|
|
248
|
+
provider ??= hasCloud ? "cloud" : "openai";
|
|
249
|
+
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 ?? ""))) {
|
|
239
251
|
throw new Error("Set OPENAI_API_KEY and select an OpenAI model for local agents.");
|
|
240
252
|
}
|
|
241
253
|
let cloud = null;
|
|
242
|
-
if (
|
|
254
|
+
if (hasCloud || provider === "cloud") {
|
|
243
255
|
cloud = createSavedAgentClient({ key: await cloudKey(root, exported) ?? "" });
|
|
244
256
|
}
|
|
245
257
|
const store = local || agents.some(agent => agent.source === "framework") ? await openStore(root) : null;
|
|
@@ -254,12 +266,17 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
254
266
|
const text = [step.task, input.trim(), previous && "Previous result: " + previous].filter(Boolean).join("\n\n").slice(0, 12_000);
|
|
255
267
|
const status = { index: steps.length + 1, agent: agent.name, source: agent.source, traceId: randomUUID() };
|
|
256
268
|
steps.push(status);
|
|
269
|
+
console.info('[Lyra Studio]', JSON.stringify({ event: 'step.started', traceId: status.traceId, agent: agent.name, source: agent.source }));
|
|
257
270
|
const started = Date.now();
|
|
258
271
|
let output;
|
|
259
272
|
let run;
|
|
260
273
|
try {
|
|
261
|
-
if (agent.source === "cloud") {
|
|
262
|
-
|
|
274
|
+
if (["local", "cloud"].includes(agent.source) && provider === "cloud") {
|
|
275
|
+
const result = agent.source === "cloud" ? await cloud.invokeWithTrace(agent.id.slice("cloud:".length), text, status.traceId) : await cloud.invokeLocal(agent, text, status.traceId);
|
|
276
|
+
output = result.output;
|
|
277
|
+
status.runId = result.runId;
|
|
278
|
+
status.provider = result.provider || "openai";
|
|
279
|
+
status.model = result.model || null;
|
|
263
280
|
} else if (agent.source === "python") {
|
|
264
281
|
output = await runPythonAgent(root, agent, text, exported);
|
|
265
282
|
} else if (agent.source === "framework") {
|
|
@@ -280,8 +297,15 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
280
297
|
|
|
281
298
|
output = event.data.result.text;
|
|
282
299
|
run = { runId: event.run_id, traceId, framework: agent.framework };
|
|
300
|
+
} else if (provider !== 'openai') {
|
|
301
|
+
status.provider = provider;
|
|
302
|
+
const definition = agent.source === 'cloud' ? await cloud.definition(agent.id.slice(6)) : agent;
|
|
303
|
+
output = await completeCli(provider, root, definition.prompt + '\n\nUser input:\n' + text);
|
|
283
304
|
} else {
|
|
284
|
-
|
|
305
|
+
status.provider = 'openai';
|
|
306
|
+
status.model = model;
|
|
307
|
+
const definition = agent.source === "cloud" ? await cloud.definition(agent.id.slice(6)) : agent;
|
|
308
|
+
const request = { model, messages: [{ role: "system", content: definition.prompt }, { role: "user", content: text }] };
|
|
285
309
|
const event = await runAgent({
|
|
286
310
|
agentId: agent.id, store, traceId: status.traceId, provider: createOpenAIProvider(process.env.OPENAI_API_KEY, fetch),
|
|
287
311
|
request: exported ? request : await withProjectMemory(root, request),
|
|
@@ -297,6 +321,7 @@ export async function runSelection(root, { targets, input, model }, catalog) {
|
|
|
297
321
|
throw Object.assign(new Error(message, { cause: error }), { progress: { traceId, steps, answers } });
|
|
298
322
|
} finally {
|
|
299
323
|
status.durationMs = Date.now() - started;
|
|
324
|
+
console.info('[Lyra Studio]', JSON.stringify({ event: 'step.' + status.state, ...status }));
|
|
300
325
|
}
|
|
301
326
|
if (step.output) named.set(step.output, output);
|
|
302
327
|
answers.push({ agent: agent.name, output, ...(run ? { run } : {}) });
|
package/src/studio/server.js
CHANGED
|
@@ -99,7 +99,7 @@ export async function startStudio(root, { port = 0, run = runSelection, pull = p
|
|
|
99
99
|
if (!body.targets) return send(409, { error: "The saved layout changed. Reload the preview before running." });
|
|
100
100
|
}
|
|
101
101
|
if (req.url === "/api/run-plan") {
|
|
102
|
-
return send(200, await describeRun(root, body.targets, appCatalog));
|
|
102
|
+
return send(200, await describeRun(root, body.targets, appCatalog, body.provider));
|
|
103
103
|
}
|
|
104
104
|
if (req.url === "/api/run") {
|
|
105
105
|
if (running) return send(409, { error: "A Studio run is already in progress." });
|
|
@@ -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
|
+
}
|