agent-lyra 0.6.2 → 0.6.4
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/LICENSE +21 -21
- package/README.md +235 -435
- package/bin/agent-lyra.js +49 -49
- package/bin/lyra-oss-preview.js +16 -14
- package/package.json +60 -60
- package/src/app-builder/export.js +109 -109
- package/src/app-builder/gateway.js +62 -62
- package/src/app-builder/init.js +52 -52
- package/src/app-builder/manifest-contract.js +46 -46
- package/src/app-builder/native-adapter.js +29 -29
- package/src/app-builder/preview.js +22 -22
- package/src/app-builder/publish.js +14 -14
- package/src/app-builder/saved-app.js +70 -70
- package/src/app-builder/saved-preview-browser.js +33 -33
- package/src/app-builder/saved-preview.html +24 -24
- package/src/app-builder/saved-preview.js +61 -61
- package/src/app-builder/support-manifest.js +50 -50
- package/src/app-builder/support-template/manifest.json +55 -55
- package/src/app-builder/support-template/support-preview.html +56 -56
- package/src/app-builder/support-template/support-preview.js +37 -37
- package/src/app-builder/support-template/support-preview.mjs +67 -67
- package/src/app-builder/support-template/support-workflow.mjs +36 -36
- package/src/app-builder/use.js +37 -37
- package/src/app-builder/validate.js +21 -21
- package/src/app-builder/value-schema.js +37 -37
- package/src/catalog.js +147 -147
- package/src/coding/catalog.js +56 -56
- package/src/coding/cloud-catalog.js +64 -44
- package/src/coding/detect-stack.mjs +110 -110
- package/src/coding/export.js +130 -130
- package/src/coding/setup.js +175 -174
- package/src/coding/skills/lyra-android/SKILL.md +37 -0
- package/src/coding/skills/lyra-angular/SKILL.md +37 -0
- package/src/coding/skills/lyra-cucumber/SKILL.md +37 -0
- package/src/coding/skills/lyra-dbt/SKILL.md +37 -0
- package/src/coding/skills/lyra-django/SKILL.md +37 -0
- package/src/coding/skills/lyra-docker/SKILL.md +37 -0
- package/src/coding/skills/lyra-dotnet/SKILL.md +37 -0
- package/src/coding/skills/lyra-express/SKILL.md +37 -0
- package/src/coding/skills/lyra-fastapi/SKILL.md +37 -0
- package/src/coding/skills/lyra-flutter/SKILL.md +37 -0
- package/src/coding/skills/lyra-github-actions/SKILL.md +37 -0
- package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -0
- package/src/coding/skills/lyra-go/SKILL.md +37 -0
- package/src/coding/skills/lyra-ios/SKILL.md +37 -0
- package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -0
- package/src/coding/skills/lyra-mongodb/SKILL.md +37 -0
- package/src/coding/skills/lyra-mysql/SKILL.md +37 -0
- package/src/coding/skills/lyra-nextjs/SKILL.md +37 -0
- package/src/coding/skills/lyra-node/SKILL.md +37 -0
- package/src/coding/skills/lyra-playwright/SKILL.md +37 -0
- package/src/coding/skills/lyra-postgresql/SKILL.md +37 -0
- package/src/coding/skills/lyra-python/SKILL.md +37 -0
- package/src/coding/skills/lyra-react/SKILL.md +37 -0
- package/src/coding/skills/lyra-react-native/SKILL.md +37 -0
- package/src/coding/skills/lyra-redis/SKILL.md +37 -0
- package/src/coding/skills/lyra-rust/SKILL.md +37 -0
- package/src/coding/skills/lyra-spark/SKILL.md +37 -0
- package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -0
- package/src/coding/skills/lyra-svelte/SKILL.md +37 -0
- package/src/coding/skills/lyra-terraform/SKILL.md +37 -0
- package/src/coding/skills/lyra-typescript/SKILL.md +37 -0
- package/src/coding/skills/lyra-vue/SKILL.md +37 -0
- package/src/gated/hostedAgents.js +56 -56
- package/src/gated/index.d.ts +25 -25
- package/src/gated/index.js +5 -5
- package/src/index.d.ts +2 -2
- package/src/index.js +2 -2
- package/src/init.js +965 -965
- package/src/memory/cli.js +21 -21
- package/src/memory/contract.json +28 -28
- package/src/memory/index.d.ts +49 -49
- package/src/memory/index.js +259 -259
- package/src/memory/lifecycle.js +29 -29
- package/src/memory/local-cli.js +34 -34
- package/src/memory/proposals.js +84 -84
- package/src/memory/skills-cli.js +26 -26
- package/src/memory/sync.js +89 -89
- package/src/memory/validation.js +25 -25
- package/src/onboardingAgents.js +532 -532
- package/src/promptTemplates.js +178 -178
- package/src/runtime/contracts.d.ts +47 -47
- package/src/runtime/local-cli.js +160 -160
- package/src/runtime/mcp-stdio.js +111 -111
- package/src/runtime/orchestration.js +59 -59
- package/src/runtime/run-agent.js +43 -43
- package/src/standalone/index.d.ts +45 -45
- package/src/standalone/index.js +13 -13
- package/src/standalone/init.js +12 -0
- package/src/standalone/orchestration.js +6 -6
- package/src/standalone/rag.js +113 -113
- package/src/studio/agent-ui.css +43 -43
- package/src/studio/agent-ui.js +32 -32
- package/src/studio/browser.js +331 -331
- package/src/studio/export.js +80 -80
- package/src/studio/index.html +37 -37
- package/src/studio/memory-actions.js +37 -37
- package/src/studio/memory-panel.js +200 -200
- package/src/studio/project.js +216 -216
- package/src/studio/pull-agent.js +72 -72
- package/src/studio/push.js +54 -54
- package/src/studio/python-agent.js +47 -47
- package/src/studio/python-agent.py +25 -25
- package/src/studio/server.js +143 -143
- package/src/studio/session.js +83 -83
- package/src/studio/studio.css +10 -10
- package/src/studio/sync.js +42 -42
- package/src/studio/workflow-sync.js +157 -157
package/src/studio/push.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
-
import { join, resolve } from "node:path";
|
|
4
|
-
import { readCatalog } from "./project.js";
|
|
5
|
-
import { readMode, readSdkKey, requireCloudMode } from "./session.js";
|
|
6
|
-
|
|
7
|
-
export async function pushStudioAgent(root, id, { key, request = fetch } = {}) {
|
|
8
|
-
requireCloudMode(await readMode(root));
|
|
9
|
-
const base = join(root, ".lyra");
|
|
10
|
-
for (const directory of [base, join(base, "agents")]) {
|
|
11
|
-
if (!(await lstat(directory).catch(() => null))?.isDirectory()) throw new Error("Use a regular .lyra/agents folder.");
|
|
12
|
-
}
|
|
13
|
-
const agent = (await readCatalog(root)).agents.get(id);
|
|
14
|
-
if (agent?.source !== "local") throw new Error("Choose a local Markdown text agent to push.");
|
|
15
|
-
key ??= await readSdkKey(root);
|
|
16
|
-
if (!key) throw new Error("Use Connect to Cloud with a Cloud sync key before pushing.");
|
|
17
|
-
|
|
18
|
-
const links = join(base, "agent-links");
|
|
19
|
-
await mkdir(links, { recursive: true });
|
|
20
|
-
if (!(await lstat(links)).isDirectory()) throw new Error("Agent links must use a regular directory.");
|
|
21
|
-
const metadata = join(links, agent.id.slice("local:".length) + ".json");
|
|
22
|
-
let link;
|
|
23
|
-
try {
|
|
24
|
-
if (!(await lstat(metadata)).isFile()) throw new Error("An agent link must be a regular file.");
|
|
25
|
-
link = JSON.parse(await readFile(metadata, "utf8"));
|
|
26
|
-
if (!/^[a-f0-9]{64}$/.test(link?.linkId ?? "") || !/^[a-f0-9]{64}$/.test(link?.revision ?? "")) {
|
|
27
|
-
throw new Error("This agent has invalid Cloud link metadata.");
|
|
28
|
-
}
|
|
29
|
-
} catch (error) {
|
|
30
|
-
if (error.code !== "ENOENT") throw error;
|
|
31
|
-
}
|
|
32
|
-
const linkId = link?.linkId ?? createHash("sha256").update(resolve(root) + "\0" + id).digest("hex");
|
|
33
|
-
const response = await request("https://api.agentlyra.in/api/sdk/v1/studio/agents/" + linkId, {
|
|
34
|
-
method: "PUT", headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
|
|
35
|
-
body: JSON.stringify({ name: agent.name, prompt: agent.prompt, revision: link?.revision }),
|
|
36
|
-
redirect: "error", signal: AbortSignal.timeout(20_000),
|
|
37
|
-
});
|
|
38
|
-
const result = await response.json();
|
|
39
|
-
if (!response.ok) {
|
|
40
|
-
if (response.status === 401) throw new Error("The Cloud key was rejected. Run connect-cloud --replace-key.");
|
|
41
|
-
throw new Error(result.error || "Cloud push failed (HTTP " + response.status + ").");
|
|
42
|
-
}
|
|
43
|
-
if (!/^[a-f0-9]{24}$/i.test(result.id ?? "") || !/^[a-f0-9]{64}$/.test(result.revision ?? "")) {
|
|
44
|
-
throw new Error("Unexpected Cloud agent response.");
|
|
45
|
-
}
|
|
46
|
-
const temporary = metadata + "." + process.pid + ".tmp";
|
|
47
|
-
await writeFile(temporary, JSON.stringify({ linkId, cloudId: result.id, revision: result.revision }) + "\n", { flag: "wx", mode: 0o600 });
|
|
48
|
-
try {
|
|
49
|
-
await rename(temporary, metadata);
|
|
50
|
-
} finally {
|
|
51
|
-
await unlink(temporary).catch(() => {});
|
|
52
|
-
}
|
|
53
|
-
return { name: agent.name, created: response.status === 201 };
|
|
54
|
-
}
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { readCatalog } from "./project.js";
|
|
5
|
+
import { readMode, readSdkKey, requireCloudMode } from "./session.js";
|
|
6
|
+
|
|
7
|
+
export async function pushStudioAgent(root, id, { key, request = fetch } = {}) {
|
|
8
|
+
requireCloudMode(await readMode(root));
|
|
9
|
+
const base = join(root, ".lyra");
|
|
10
|
+
for (const directory of [base, join(base, "agents")]) {
|
|
11
|
+
if (!(await lstat(directory).catch(() => null))?.isDirectory()) throw new Error("Use a regular .lyra/agents folder.");
|
|
12
|
+
}
|
|
13
|
+
const agent = (await readCatalog(root)).agents.get(id);
|
|
14
|
+
if (agent?.source !== "local") throw new Error("Choose a local Markdown text agent to push.");
|
|
15
|
+
key ??= await readSdkKey(root);
|
|
16
|
+
if (!key) throw new Error("Use Connect to Cloud with a Cloud sync key before pushing.");
|
|
17
|
+
|
|
18
|
+
const links = join(base, "agent-links");
|
|
19
|
+
await mkdir(links, { recursive: true });
|
|
20
|
+
if (!(await lstat(links)).isDirectory()) throw new Error("Agent links must use a regular directory.");
|
|
21
|
+
const metadata = join(links, agent.id.slice("local:".length) + ".json");
|
|
22
|
+
let link;
|
|
23
|
+
try {
|
|
24
|
+
if (!(await lstat(metadata)).isFile()) throw new Error("An agent link must be a regular file.");
|
|
25
|
+
link = JSON.parse(await readFile(metadata, "utf8"));
|
|
26
|
+
if (!/^[a-f0-9]{64}$/.test(link?.linkId ?? "") || !/^[a-f0-9]{64}$/.test(link?.revision ?? "")) {
|
|
27
|
+
throw new Error("This agent has invalid Cloud link metadata.");
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error.code !== "ENOENT") throw error;
|
|
31
|
+
}
|
|
32
|
+
const linkId = link?.linkId ?? createHash("sha256").update(resolve(root) + "\0" + id).digest("hex");
|
|
33
|
+
const response = await request("https://api.agentlyra.in/api/sdk/v1/studio/agents/" + linkId, {
|
|
34
|
+
method: "PUT", headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
|
|
35
|
+
body: JSON.stringify({ name: agent.name, prompt: agent.prompt, revision: link?.revision }),
|
|
36
|
+
redirect: "error", signal: AbortSignal.timeout(20_000),
|
|
37
|
+
});
|
|
38
|
+
const result = await response.json();
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
if (response.status === 401) throw new Error("The Cloud key was rejected. Run connect-cloud --replace-key.");
|
|
41
|
+
throw new Error(result.error || "Cloud push failed (HTTP " + response.status + ").");
|
|
42
|
+
}
|
|
43
|
+
if (!/^[a-f0-9]{24}$/i.test(result.id ?? "") || !/^[a-f0-9]{64}$/.test(result.revision ?? "")) {
|
|
44
|
+
throw new Error("Unexpected Cloud agent response.");
|
|
45
|
+
}
|
|
46
|
+
const temporary = metadata + "." + process.pid + ".tmp";
|
|
47
|
+
await writeFile(temporary, JSON.stringify({ linkId, cloudId: result.id, revision: result.revision }) + "\n", { flag: "wx", mode: 0o600 });
|
|
48
|
+
try {
|
|
49
|
+
await rename(temporary, metadata);
|
|
50
|
+
} finally {
|
|
51
|
+
await unlink(temporary).catch(() => {});
|
|
52
|
+
}
|
|
53
|
+
return { name: agent.name, created: response.status === 201 };
|
|
54
|
+
}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { lstat } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
const filename = /^[A-Za-z0-9_][A-Za-z0-9_-]{0,95}\.py$/;
|
|
6
|
-
const skillId = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,95}$/;
|
|
7
|
-
|
|
8
|
-
export function pythonDescriptor(item) {
|
|
9
|
-
if (item?.runtime !== "python" || !filename.test(item.file ?? "") || !skillId.test(item.skill ?? "")) return null;
|
|
10
|
-
return { file: item.file, skill: item.skill };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function pythonSource(root, agent, exported) {
|
|
14
|
-
if (!pythonDescriptor({ ...agent, runtime: "python" })) throw new Error("Invalid Python agent descriptor.");
|
|
15
|
-
let directory = root;
|
|
16
|
-
for (const part of exported ? ["python-agents"] : [".lyra", "agents"]) {
|
|
17
|
-
directory = join(directory, part);
|
|
18
|
-
if (!(await lstat(directory)).isDirectory()) throw new Error("Python agent folders must be regular directories.");
|
|
19
|
-
}
|
|
20
|
-
const source = join(directory, agent.file);
|
|
21
|
-
if (!(await lstat(source)).isFile()) throw new Error("Python agent source must be a regular file.");
|
|
22
|
-
return source;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function runPythonAgent(root, agent, input, exported) {
|
|
26
|
-
const file = await pythonSource(root, agent, exported);
|
|
27
|
-
const python = process.env.LYRA_PYTHON || (process.platform === "win32" ? "py.exe" : "python3");
|
|
28
|
-
const runner = new URL("./python-agent.py", import.meta.url);
|
|
29
|
-
const { fileURLToPath } = await import("node:url");
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
const child = execFile(python, [fileURLToPath(runner), file, agent.skill], {
|
|
32
|
-
cwd: root, timeout: 60_000, maxBuffer: 1024 * 1024, windowsHide: true,
|
|
33
|
-
}, (error, stdout) => {
|
|
34
|
-
if (error?.code === "ENOENT") return reject(new Error("Install Python 3.9+ and agent-lyra, or set LYRA_PYTHON to your virtual environment's interpreter."));
|
|
35
|
-
if (error) return reject(new Error("Python agent " + agent.name + " failed. Check its dependencies and skill registration."));
|
|
36
|
-
try {
|
|
37
|
-
const result = JSON.parse(stdout);
|
|
38
|
-
if (typeof result.output !== "string") throw new Error();
|
|
39
|
-
resolve(result.output);
|
|
40
|
-
} catch {
|
|
41
|
-
reject(new Error("Python agent " + agent.name + " returned an invalid response."));
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
child.stdin.on("error", () => {});
|
|
45
|
-
child.stdin.end(JSON.stringify({ input }));
|
|
46
|
-
});
|
|
47
|
-
}
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { lstat } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const filename = /^[A-Za-z0-9_][A-Za-z0-9_-]{0,95}\.py$/;
|
|
6
|
+
const skillId = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,95}$/;
|
|
7
|
+
|
|
8
|
+
export function pythonDescriptor(item) {
|
|
9
|
+
if (item?.runtime !== "python" || !filename.test(item.file ?? "") || !skillId.test(item.skill ?? "")) return null;
|
|
10
|
+
return { file: item.file, skill: item.skill };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function pythonSource(root, agent, exported) {
|
|
14
|
+
if (!pythonDescriptor({ ...agent, runtime: "python" })) throw new Error("Invalid Python agent descriptor.");
|
|
15
|
+
let directory = root;
|
|
16
|
+
for (const part of exported ? ["python-agents"] : [".lyra", "agents"]) {
|
|
17
|
+
directory = join(directory, part);
|
|
18
|
+
if (!(await lstat(directory)).isDirectory()) throw new Error("Python agent folders must be regular directories.");
|
|
19
|
+
}
|
|
20
|
+
const source = join(directory, agent.file);
|
|
21
|
+
if (!(await lstat(source)).isFile()) throw new Error("Python agent source must be a regular file.");
|
|
22
|
+
return source;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function runPythonAgent(root, agent, input, exported) {
|
|
26
|
+
const file = await pythonSource(root, agent, exported);
|
|
27
|
+
const python = process.env.LYRA_PYTHON || (process.platform === "win32" ? "py.exe" : "python3");
|
|
28
|
+
const runner = new URL("./python-agent.py", import.meta.url);
|
|
29
|
+
const { fileURLToPath } = await import("node:url");
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
const child = execFile(python, [fileURLToPath(runner), file, agent.skill], {
|
|
32
|
+
cwd: root, timeout: 60_000, maxBuffer: 1024 * 1024, windowsHide: true,
|
|
33
|
+
}, (error, stdout) => {
|
|
34
|
+
if (error?.code === "ENOENT") return reject(new Error("Install Python 3.9+ and agent-lyra, or set LYRA_PYTHON to your virtual environment's interpreter."));
|
|
35
|
+
if (error) return reject(new Error("Python agent " + agent.name + " failed. Check its dependencies and skill registration."));
|
|
36
|
+
try {
|
|
37
|
+
const result = JSON.parse(stdout);
|
|
38
|
+
if (typeof result.output !== "string") throw new Error();
|
|
39
|
+
resolve(result.output);
|
|
40
|
+
} catch {
|
|
41
|
+
reject(new Error("Python agent " + agent.name + " returned an invalid response."));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
child.stdin.on("error", () => {});
|
|
45
|
+
child.stdin.end(JSON.stringify({ input }));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"""Run a registered Lyra skill from a trusted project agent file."""
|
|
2
|
-
import asyncio
|
|
3
|
-
import json
|
|
4
|
-
import runpy
|
|
5
|
-
import sys
|
|
6
|
-
from contextlib import redirect_stdout
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def main():
|
|
10
|
-
source, skill = sys.argv[1:]
|
|
11
|
-
payload = json.load(sys.stdin)
|
|
12
|
-
with redirect_stdout(sys.stderr):
|
|
13
|
-
from lyra.standalone import Agent
|
|
14
|
-
|
|
15
|
-
agent = runpy.run_path(source).get("agent")
|
|
16
|
-
if not isinstance(agent, Agent):
|
|
17
|
-
raise TypeError("Export a lyra.standalone.Agent named 'agent'.")
|
|
18
|
-
output = asyncio.run(agent.run(skill, payload["input"]))
|
|
19
|
-
if not isinstance(output, str):
|
|
20
|
-
output = json.dumps(output, allow_nan=False)
|
|
21
|
-
print(json.dumps({"output": output}))
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if __name__ == "__main__":
|
|
25
|
-
main()
|
|
1
|
+
"""Run a registered Lyra skill from a trusted project agent file."""
|
|
2
|
+
import asyncio
|
|
3
|
+
import json
|
|
4
|
+
import runpy
|
|
5
|
+
import sys
|
|
6
|
+
from contextlib import redirect_stdout
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
source, skill = sys.argv[1:]
|
|
11
|
+
payload = json.load(sys.stdin)
|
|
12
|
+
with redirect_stdout(sys.stderr):
|
|
13
|
+
from lyra.standalone import Agent
|
|
14
|
+
|
|
15
|
+
agent = runpy.run_path(source).get("agent")
|
|
16
|
+
if not isinstance(agent, Agent):
|
|
17
|
+
raise TypeError("Export a lyra.standalone.Agent named 'agent'.")
|
|
18
|
+
output = asyncio.run(agent.run(skill, payload["input"]))
|
|
19
|
+
if not isinstance(output, str):
|
|
20
|
+
output = json.dumps(output, allow_nan=False)
|
|
21
|
+
print(json.dumps({"output": output}))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
main()
|
package/src/studio/server.js
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
import { memoryActions } from "./memory-actions.js";
|
|
2
|
-
import { createServer } from "node:http";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
|
-
import { readCatalog, readLayout, runSelection, saveLayout } from "./project.js";
|
|
5
|
-
import { readMode } from "./session.js";
|
|
6
|
-
import { syncSkill, syncTeam, syncWorkflow } from "./workflow-sync.js";
|
|
7
|
-
import { pullAgentEdits } from "./pull-agent.js";
|
|
8
|
-
import { pushStudioAgent } from "./push.js";
|
|
9
|
-
import { pullStudio } from "./sync.js";
|
|
10
|
-
|
|
11
|
-
export async function startStudio(root, { port = 0, run = runSelection, pull = pullStudio, appCatalog } = {}) {
|
|
12
|
-
const assets = new Map();
|
|
13
|
-
for (const [route, name, mime] of [
|
|
14
|
-
["/memory-panel.js", "memory-panel.js", "text/javascript"],
|
|
15
|
-
["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
|
|
16
|
-
["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
|
|
17
|
-
]) assets.set(route, [await readFile(new URL("./" + name, import.meta.url)), mime]);
|
|
18
|
-
|
|
19
|
-
const updates = new Map([
|
|
20
|
-
...(appCatalog ? [] : memoryActions(root)),
|
|
21
|
-
["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
|
|
22
|
-
["/api/pull", () => pull(root)],
|
|
23
|
-
["/api/push", ({ id }) => pushStudioAgent(root, id)],
|
|
24
|
-
["/api/pull-agent", ({ id }) => pullAgentEdits(root, id)],
|
|
25
|
-
["/api/push-workflow", ({ id }) => syncWorkflow(root, id, "push")],
|
|
26
|
-
["/api/pull-workflow", ({ id }) => syncWorkflow(root, id, "pull")],
|
|
27
|
-
["/api/push-team", ({ id }) => syncTeam(root, id, "push")],
|
|
28
|
-
["/api/pull-team", ({ id }) => syncTeam(root, id, "pull")],
|
|
29
|
-
["/api/push-skill", ({ id }) => syncSkill(root, id, "push")],
|
|
30
|
-
["/api/pull-skill", ({ id }) => syncSkill(root, id, "pull")],
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
let running = false;
|
|
34
|
-
let writing = false;
|
|
35
|
-
const server = createServer(async (req, res) => {
|
|
36
|
-
const send = (status, data, type = "application/json") => {
|
|
37
|
-
res.writeHead(status, {
|
|
38
|
-
"Content-Type": type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
39
|
-
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; frame-ancestors 'none'",
|
|
40
|
-
});
|
|
41
|
-
res.end(type === "application/json" ? JSON.stringify(data) : data);
|
|
42
|
-
};
|
|
43
|
-
const host = "127.0.0.1:" + server.address().port;
|
|
44
|
-
if (req.headers.host !== host) return send(403, { error: "Use the Studio loopback URL." });
|
|
45
|
-
if (req.method === "GET" && assets.has(req.url)) {
|
|
46
|
-
const [data, mime] = assets.get(req.url);
|
|
47
|
-
return send(200, data, mime);
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
if (req.method === "GET" && req.url === "/api/project") {
|
|
51
|
-
const catalog = appCatalog ?? await readCatalog(root);
|
|
52
|
-
return send(200, {
|
|
53
|
-
...await readLayout(root),
|
|
54
|
-
exported: Boolean(appCatalog),
|
|
55
|
-
mode: appCatalog ? undefined : await readMode(root),
|
|
56
|
-
agents: [...catalog.agents.values()].map(({ id, name, source }) => ({ id, name, source })),
|
|
57
|
-
workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
|
|
58
|
-
skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
|
|
59
|
-
teams: catalog.teams.map(({ id, name, source }) => ({ id, name, source })),
|
|
60
|
-
models: (process.env.LYRA_STUDIO_MODELS || "gpt-4o-mini").split(",").map(value => value.trim()).filter(Boolean),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (req.method !== "POST" || (req.url !== "/api/run" && !updates.has(req.url))) {
|
|
64
|
-
return send(404, { error: "Not found." });
|
|
65
|
-
}
|
|
66
|
-
if (appCatalog && req.url !== "/api/run") return send(404, { error: "Not found." });
|
|
67
|
-
if (req.headers.origin !== "http://" + host) return send(403, { error: "Use the Studio page to submit requests." });
|
|
68
|
-
if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
|
|
69
|
-
const chunks = [];
|
|
70
|
-
let size = 0;
|
|
71
|
-
for await (const chunk of req) {
|
|
72
|
-
size += chunk.length;
|
|
73
|
-
if (size > 65_536) return send(413, { error: "Studio request is too large." });
|
|
74
|
-
chunks.push(chunk);
|
|
75
|
-
}
|
|
76
|
-
const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
77
|
-
if (req.url === "/api/run") {
|
|
78
|
-
if (running) return send(409, { error: "A Studio run is already in progress." });
|
|
79
|
-
running = true;
|
|
80
|
-
try {
|
|
81
|
-
if (appCatalog) {
|
|
82
|
-
const { layout } = await readLayout(root);
|
|
83
|
-
const button = layout.find(node => ["button", "agent-card"].includes(node.kind) && node.id === body.buttonId);
|
|
84
|
-
if (!button) return send(400, { error: "Choose a run button from the app." });
|
|
85
|
-
body.targets = button.targets;
|
|
86
|
-
}
|
|
87
|
-
return send(200, await run(root, body, appCatalog));
|
|
88
|
-
} finally { running = false; }
|
|
89
|
-
}
|
|
90
|
-
if (writing) return send(409, { error: "Studio is already saving or pulling files." });
|
|
91
|
-
writing = true;
|
|
92
|
-
try {
|
|
93
|
-
return send(200, await updates.get(req.url)(body));
|
|
94
|
-
} finally { writing = false; }
|
|
95
|
-
} catch (error) {
|
|
96
|
-
const message = error.code ? "Studio could not read or write the project." : error.message;
|
|
97
|
-
return send(400, { error: message });
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
server.requestTimeout = 10_000;
|
|
102
|
-
await new Promise((resolve, reject) => {
|
|
103
|
-
server.once("error", reject);
|
|
104
|
-
server.listen(port, "127.0.0.1", resolve);
|
|
105
|
-
});
|
|
106
|
-
return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function runStudio(args, output = process.stdout) {
|
|
110
|
-
if (args[0] === "--help") {
|
|
111
|
-
output.write("Usage: agent-lyra studio | agent-lyra studio pull | agent-lyra studio push <local-agent-id> | agent-lyra studio pull-agent <local-agent-id> | agent-lyra studio push-workflow <workflow-id> | agent-lyra studio pull-workflow <workflow-id> | agent-lyra studio push-team <team-id> | agent-lyra studio pull-team <team-id> | agent-lyra studio push-skill <skill-id> | agent-lyra studio pull-skill <skill-id>\n");
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (args.length === 1 && args[0] === "pull") {
|
|
115
|
-
const { added, preserved } = await pullStudio(process.cwd());
|
|
116
|
-
output.write("Cloud pull: " + added + " added, " + preserved + " existing preserved.\n");
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (args.length === 2 && args[0] === "push") {
|
|
120
|
-
const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
|
|
121
|
-
const result = await pushStudioAgent(process.cwd(), id);
|
|
122
|
-
output.write((result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (args.length === 2 && args[0] === "pull-agent") {
|
|
126
|
-
const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
|
|
127
|
-
const result = await pullAgentEdits(process.cwd(), id);
|
|
128
|
-
output.write(result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (args.length === 2 && ["push-workflow", "pull-workflow", "push-team", "pull-team", "push-skill", "pull-skill"].includes(args[0])) {
|
|
132
|
-
const [action, resource] = args[0].split("-");
|
|
133
|
-
const push = action === "push";
|
|
134
|
-
const sync = { team: syncTeam, workflow: syncWorkflow, skill: syncSkill }[resource];
|
|
135
|
-
const result = await sync(process.cwd(), args[1], action);
|
|
136
|
-
output.write(push ? "Saved " + result.name + " in Cloud.\n"
|
|
137
|
-
: result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (args.length) throw new Error("See agent-lyra studio --help.");
|
|
141
|
-
const { url } = await startStudio(process.cwd());
|
|
142
|
-
output.write("AgentLyra Studio: " + url + "\n");
|
|
143
|
-
}
|
|
1
|
+
import { memoryActions } from "./memory-actions.js";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { readCatalog, readLayout, runSelection, saveLayout } from "./project.js";
|
|
5
|
+
import { readMode } from "./session.js";
|
|
6
|
+
import { syncSkill, syncTeam, syncWorkflow } from "./workflow-sync.js";
|
|
7
|
+
import { pullAgentEdits } from "./pull-agent.js";
|
|
8
|
+
import { pushStudioAgent } from "./push.js";
|
|
9
|
+
import { pullStudio } from "./sync.js";
|
|
10
|
+
|
|
11
|
+
export async function startStudio(root, { port = 0, run = runSelection, pull = pullStudio, appCatalog } = {}) {
|
|
12
|
+
const assets = new Map();
|
|
13
|
+
for (const [route, name, mime] of [
|
|
14
|
+
["/memory-panel.js", "memory-panel.js", "text/javascript"],
|
|
15
|
+
["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
|
|
16
|
+
["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
|
|
17
|
+
]) assets.set(route, [await readFile(new URL("./" + name, import.meta.url)), mime]);
|
|
18
|
+
|
|
19
|
+
const updates = new Map([
|
|
20
|
+
...(appCatalog ? [] : memoryActions(root)),
|
|
21
|
+
["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
|
|
22
|
+
["/api/pull", () => pull(root)],
|
|
23
|
+
["/api/push", ({ id }) => pushStudioAgent(root, id)],
|
|
24
|
+
["/api/pull-agent", ({ id }) => pullAgentEdits(root, id)],
|
|
25
|
+
["/api/push-workflow", ({ id }) => syncWorkflow(root, id, "push")],
|
|
26
|
+
["/api/pull-workflow", ({ id }) => syncWorkflow(root, id, "pull")],
|
|
27
|
+
["/api/push-team", ({ id }) => syncTeam(root, id, "push")],
|
|
28
|
+
["/api/pull-team", ({ id }) => syncTeam(root, id, "pull")],
|
|
29
|
+
["/api/push-skill", ({ id }) => syncSkill(root, id, "push")],
|
|
30
|
+
["/api/pull-skill", ({ id }) => syncSkill(root, id, "pull")],
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
let running = false;
|
|
34
|
+
let writing = false;
|
|
35
|
+
const server = createServer(async (req, res) => {
|
|
36
|
+
const send = (status, data, type = "application/json") => {
|
|
37
|
+
res.writeHead(status, {
|
|
38
|
+
"Content-Type": type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
39
|
+
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; frame-ancestors 'none'",
|
|
40
|
+
});
|
|
41
|
+
res.end(type === "application/json" ? JSON.stringify(data) : data);
|
|
42
|
+
};
|
|
43
|
+
const host = "127.0.0.1:" + server.address().port;
|
|
44
|
+
if (req.headers.host !== host) return send(403, { error: "Use the Studio loopback URL." });
|
|
45
|
+
if (req.method === "GET" && assets.has(req.url)) {
|
|
46
|
+
const [data, mime] = assets.get(req.url);
|
|
47
|
+
return send(200, data, mime);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
if (req.method === "GET" && req.url === "/api/project") {
|
|
51
|
+
const catalog = appCatalog ?? await readCatalog(root);
|
|
52
|
+
return send(200, {
|
|
53
|
+
...await readLayout(root),
|
|
54
|
+
exported: Boolean(appCatalog),
|
|
55
|
+
mode: appCatalog ? undefined : await readMode(root),
|
|
56
|
+
agents: [...catalog.agents.values()].map(({ id, name, source }) => ({ id, name, source })),
|
|
57
|
+
workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
|
|
58
|
+
skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
|
|
59
|
+
teams: catalog.teams.map(({ id, name, source }) => ({ id, name, source })),
|
|
60
|
+
models: (process.env.LYRA_STUDIO_MODELS || "gpt-4o-mini").split(",").map(value => value.trim()).filter(Boolean),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (req.method !== "POST" || (req.url !== "/api/run" && !updates.has(req.url))) {
|
|
64
|
+
return send(404, { error: "Not found." });
|
|
65
|
+
}
|
|
66
|
+
if (appCatalog && req.url !== "/api/run") return send(404, { error: "Not found." });
|
|
67
|
+
if (req.headers.origin !== "http://" + host) return send(403, { error: "Use the Studio page to submit requests." });
|
|
68
|
+
if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
|
|
69
|
+
const chunks = [];
|
|
70
|
+
let size = 0;
|
|
71
|
+
for await (const chunk of req) {
|
|
72
|
+
size += chunk.length;
|
|
73
|
+
if (size > 65_536) return send(413, { error: "Studio request is too large." });
|
|
74
|
+
chunks.push(chunk);
|
|
75
|
+
}
|
|
76
|
+
const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
77
|
+
if (req.url === "/api/run") {
|
|
78
|
+
if (running) return send(409, { error: "A Studio run is already in progress." });
|
|
79
|
+
running = true;
|
|
80
|
+
try {
|
|
81
|
+
if (appCatalog) {
|
|
82
|
+
const { layout } = await readLayout(root);
|
|
83
|
+
const button = layout.find(node => ["button", "agent-card"].includes(node.kind) && node.id === body.buttonId);
|
|
84
|
+
if (!button) return send(400, { error: "Choose a run button from the app." });
|
|
85
|
+
body.targets = button.targets;
|
|
86
|
+
}
|
|
87
|
+
return send(200, await run(root, body, appCatalog));
|
|
88
|
+
} finally { running = false; }
|
|
89
|
+
}
|
|
90
|
+
if (writing) return send(409, { error: "Studio is already saving or pulling files." });
|
|
91
|
+
writing = true;
|
|
92
|
+
try {
|
|
93
|
+
return send(200, await updates.get(req.url)(body));
|
|
94
|
+
} finally { writing = false; }
|
|
95
|
+
} catch (error) {
|
|
96
|
+
const message = error.code ? "Studio could not read or write the project." : error.message;
|
|
97
|
+
return send(400, { error: message });
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
server.requestTimeout = 10_000;
|
|
102
|
+
await new Promise((resolve, reject) => {
|
|
103
|
+
server.once("error", reject);
|
|
104
|
+
server.listen(port, "127.0.0.1", resolve);
|
|
105
|
+
});
|
|
106
|
+
return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function runStudio(args, output = process.stdout) {
|
|
110
|
+
if (args[0] === "--help") {
|
|
111
|
+
output.write("Usage: agent-lyra studio | agent-lyra studio pull | agent-lyra studio push <local-agent-id> | agent-lyra studio pull-agent <local-agent-id> | agent-lyra studio push-workflow <workflow-id> | agent-lyra studio pull-workflow <workflow-id> | agent-lyra studio push-team <team-id> | agent-lyra studio pull-team <team-id> | agent-lyra studio push-skill <skill-id> | agent-lyra studio pull-skill <skill-id>\n");
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (args.length === 1 && args[0] === "pull") {
|
|
115
|
+
const { added, preserved } = await pullStudio(process.cwd());
|
|
116
|
+
output.write("Cloud pull: " + added + " added, " + preserved + " existing preserved.\n");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (args.length === 2 && args[0] === "push") {
|
|
120
|
+
const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
|
|
121
|
+
const result = await pushStudioAgent(process.cwd(), id);
|
|
122
|
+
output.write((result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (args.length === 2 && args[0] === "pull-agent") {
|
|
126
|
+
const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
|
|
127
|
+
const result = await pullAgentEdits(process.cwd(), id);
|
|
128
|
+
output.write(result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (args.length === 2 && ["push-workflow", "pull-workflow", "push-team", "pull-team", "push-skill", "pull-skill"].includes(args[0])) {
|
|
132
|
+
const [action, resource] = args[0].split("-");
|
|
133
|
+
const push = action === "push";
|
|
134
|
+
const sync = { team: syncTeam, workflow: syncWorkflow, skill: syncSkill }[resource];
|
|
135
|
+
const result = await sync(process.cwd(), args[1], action);
|
|
136
|
+
output.write(push ? "Saved " + result.name + " in Cloud.\n"
|
|
137
|
+
: result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (args.length) throw new Error("See agent-lyra studio --help.");
|
|
141
|
+
const { url } = await startStudio(process.cwd());
|
|
142
|
+
output.write("AgentLyra Studio: " + url + "\n");
|
|
143
|
+
}
|