agent-lyra 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +435 -173
- package/bin/agent-lyra.js +21 -3
- package/bin/lyra-oss-preview.js +14 -0
- package/package.json +60 -56
- package/src/app-builder/export.js +109 -109
- package/src/app-builder/init.js +52 -52
- package/src/app-builder/manifest-contract.js +46 -0
- package/src/app-builder/preview.js +22 -22
- 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/validate.js +21 -64
- package/src/coding/catalog.js +56 -0
- package/src/coding/cloud-catalog.js +44 -0
- package/src/coding/detect-stack.mjs +110 -0
- package/src/coding/export.js +130 -0
- package/src/coding/setup.js +174 -0
- package/src/init.js +32 -4
- package/src/memory/cli.js +21 -0
- package/src/memory/contract.json +28 -0
- package/src/memory/index.d.ts +49 -0
- package/src/memory/index.js +259 -0
- package/src/memory/lifecycle.js +29 -0
- package/src/memory/local-cli.js +34 -0
- package/src/memory/proposals.js +84 -0
- package/src/memory/skills-cli.js +26 -0
- package/src/memory/sync.js +89 -0
- package/src/memory/validation.js +25 -0
- package/src/runtime/local-cli.js +2 -1
- package/src/studio/agent-ui.css +43 -43
- package/src/studio/agent-ui.js +32 -32
- package/src/studio/browser.js +331 -289
- package/src/studio/export.js +80 -79
- package/src/studio/index.html +37 -16
- package/src/studio/memory-actions.js +37 -0
- package/src/studio/memory-panel.js +200 -0
- package/src/studio/project.js +216 -190
- package/src/studio/pull-agent.js +72 -0
- package/src/studio/push.js +54 -0
- package/src/studio/python-agent.js +47 -47
- package/src/studio/python-agent.py +25 -25
- package/src/studio/server.js +143 -102
- package/src/studio/session.js +83 -0
- package/src/studio/studio.css +10 -7
- package/src/studio/sync.js +42 -39
- package/src/studio/workflow-sync.js +157 -0
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
|
|
3
|
-
export const SAVED_VERSION = "2.0";
|
|
4
|
-
const idPattern = /^[a-f0-9]{24}$/i;
|
|
5
|
-
const appIdPattern = /^[a-z][a-z0-9-]{0,79}$/;
|
|
6
|
-
|
|
7
|
-
export function validateSavedApp(manifest) {
|
|
8
|
-
if (manifest?.version !== SAVED_VERSION || !appIdPattern.test(manifest.application?.id ?? "") ||
|
|
9
|
-
typeof manifest.application.name !== "string" || !manifest.application.name.trim() ||
|
|
10
|
-
manifest.application.name.length > 120) {
|
|
11
|
-
throw new Error('Version "2.0" requires an application ID and name.');
|
|
12
|
-
}
|
|
13
|
-
const { steps } = manifest.workflow ?? {};
|
|
14
|
-
if (!Array.isArray(steps) || steps.length !== 2 ||
|
|
15
|
-
!steps.every(step => typeof step?.agentId === "string" && idPattern.test(step.agentId)) ||
|
|
16
|
-
steps[0].agentId.toLowerCase() === steps[1].agentId.toLowerCase()) {
|
|
17
|
-
throw new Error("A workflow requires two distinct saved Lyra agent IDs.");
|
|
18
|
-
}
|
|
19
|
-
return manifest;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export async function readAppManifest(path) {
|
|
23
|
-
const source = await readFile(path, "utf8");
|
|
24
|
-
try {
|
|
25
|
-
return JSON.parse(source.replace(/^\uFEFF/, ""));
|
|
26
|
-
} catch {
|
|
27
|
-
throw new Error("Application manifest is not valid JSON.");
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function createSavedAgentClient({ key = process.env.LYRA_API_KEY, fetchRequest = fetch } = {}) {
|
|
32
|
-
if (!/^lyra_sdk_[a-f0-9]{64}$/.test(key ?? "")) {
|
|
33
|
-
throw new Error("Set LYRA_API_KEY to a dedicated SDK key from AgentLyra Console.");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function request(path, prompt) {
|
|
37
|
-
const response = await fetchRequest("https://api.agentlyra.in/api/sdk/v1/saved-agents" + path, {
|
|
38
|
-
method: prompt === undefined ? "GET" : "POST",
|
|
39
|
-
headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
|
|
40
|
-
body: prompt === undefined ? undefined : JSON.stringify({ prompt }),
|
|
41
|
-
redirect: "error",
|
|
42
|
-
signal: AbortSignal.timeout(65_000),
|
|
43
|
-
});
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
if (response.status === 401) throw new Error("The SDK key is invalid or revoked.");
|
|
46
|
-
if (response.status === 403) throw new Error("Add your OpenAI key in AgentLyra Console → Models.");
|
|
47
|
-
if (response.status === 404) throw new Error("A selected agent is unavailable to this SDK key.");
|
|
48
|
-
throw new Error("AgentLyra Cloud request failed (HTTP " + response.status + ").");
|
|
49
|
-
}
|
|
50
|
-
return response.json();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
list: async () => (await request("")).agents,
|
|
55
|
-
invoke: async (id, prompt) => (await request("/" + encodeURIComponent(id) + "/invoke", prompt)).output,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function runSavedApp(manifest, input, client = createSavedAgentClient()) {
|
|
60
|
-
const [first, second] = validateSavedApp(manifest).workflow.steps;
|
|
61
|
-
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
62
|
-
throw new Error("Enter between 1 and 4,000 characters.");
|
|
63
|
-
}
|
|
64
|
-
const firstOutput = await client.invoke(first.agentId, input.trim());
|
|
65
|
-
const output = await client.invoke(second.agentId, JSON.stringify({
|
|
66
|
-
input: input.trim(),
|
|
67
|
-
previousAgentOutput: firstOutput,
|
|
68
|
-
}).slice(0, 12_000));
|
|
69
|
-
return { firstOutput, output };
|
|
70
|
-
}
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
export const SAVED_VERSION = "2.0";
|
|
4
|
+
const idPattern = /^[a-f0-9]{24}$/i;
|
|
5
|
+
const appIdPattern = /^[a-z][a-z0-9-]{0,79}$/;
|
|
6
|
+
|
|
7
|
+
export function validateSavedApp(manifest) {
|
|
8
|
+
if (manifest?.version !== SAVED_VERSION || !appIdPattern.test(manifest.application?.id ?? "") ||
|
|
9
|
+
typeof manifest.application.name !== "string" || !manifest.application.name.trim() ||
|
|
10
|
+
manifest.application.name.length > 120) {
|
|
11
|
+
throw new Error('Version "2.0" requires an application ID and name.');
|
|
12
|
+
}
|
|
13
|
+
const { steps } = manifest.workflow ?? {};
|
|
14
|
+
if (!Array.isArray(steps) || steps.length !== 2 ||
|
|
15
|
+
!steps.every(step => typeof step?.agentId === "string" && idPattern.test(step.agentId)) ||
|
|
16
|
+
steps[0].agentId.toLowerCase() === steps[1].agentId.toLowerCase()) {
|
|
17
|
+
throw new Error("A workflow requires two distinct saved Lyra agent IDs.");
|
|
18
|
+
}
|
|
19
|
+
return manifest;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function readAppManifest(path) {
|
|
23
|
+
const source = await readFile(path, "utf8");
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(source.replace(/^\uFEFF/, ""));
|
|
26
|
+
} catch {
|
|
27
|
+
throw new Error("Application manifest is not valid JSON.");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createSavedAgentClient({ key = process.env.LYRA_API_KEY, fetchRequest = fetch } = {}) {
|
|
32
|
+
if (!/^lyra_sdk_[a-f0-9]{64}$/.test(key ?? "")) {
|
|
33
|
+
throw new Error("Set LYRA_API_KEY to a dedicated SDK key from AgentLyra Console.");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function request(path, prompt) {
|
|
37
|
+
const response = await fetchRequest("https://api.agentlyra.in/api/sdk/v1/saved-agents" + path, {
|
|
38
|
+
method: prompt === undefined ? "GET" : "POST",
|
|
39
|
+
headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
|
|
40
|
+
body: prompt === undefined ? undefined : JSON.stringify({ prompt }),
|
|
41
|
+
redirect: "error",
|
|
42
|
+
signal: AbortSignal.timeout(65_000),
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
if (response.status === 401) throw new Error("The SDK key is invalid or revoked.");
|
|
46
|
+
if (response.status === 403) throw new Error("Add your OpenAI key in AgentLyra Console → Models.");
|
|
47
|
+
if (response.status === 404) throw new Error("A selected agent is unavailable to this SDK key.");
|
|
48
|
+
throw new Error("AgentLyra Cloud request failed (HTTP " + response.status + ").");
|
|
49
|
+
}
|
|
50
|
+
return response.json();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
list: async () => (await request("")).agents,
|
|
55
|
+
invoke: async (id, prompt) => (await request("/" + encodeURIComponent(id) + "/invoke", prompt)).output,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function runSavedApp(manifest, input, client = createSavedAgentClient()) {
|
|
60
|
+
const [first, second] = validateSavedApp(manifest).workflow.steps;
|
|
61
|
+
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
62
|
+
throw new Error("Enter between 1 and 4,000 characters.");
|
|
63
|
+
}
|
|
64
|
+
const firstOutput = await client.invoke(first.agentId, input.trim());
|
|
65
|
+
const output = await client.invoke(second.agentId, JSON.stringify({
|
|
66
|
+
input: input.trim(),
|
|
67
|
+
previousAgentOutput: firstOutput,
|
|
68
|
+
}).slice(0, 12_000));
|
|
69
|
+
return { firstOutput, output };
|
|
70
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const form = document.querySelector("form");
|
|
2
|
-
const button = form.querySelector("button");
|
|
3
|
-
const status = document.querySelector("#status");
|
|
4
|
-
const result = document.querySelector("#result");
|
|
5
|
-
|
|
6
|
-
fetch("/api/app").then(response => response.json()).then(({ name }) => {
|
|
7
|
-
document.title = name;
|
|
8
|
-
document.querySelector("h1").textContent = name;
|
|
9
|
-
}).catch(() => { status.textContent = "Could not load application details."; });
|
|
10
|
-
|
|
11
|
-
form.addEventListener("submit", async event => {
|
|
12
|
-
event.preventDefault();
|
|
13
|
-
button.disabled = true;
|
|
14
|
-
result.hidden = true;
|
|
15
|
-
status.textContent = "Running both agents…";
|
|
16
|
-
try {
|
|
17
|
-
const response = await fetch("/api/run", {
|
|
18
|
-
method: "POST",
|
|
19
|
-
headers: { "Content-Type": "application/json" },
|
|
20
|
-
body: JSON.stringify({ input: document.querySelector("#input").value }),
|
|
21
|
-
});
|
|
22
|
-
const data = await response.json();
|
|
23
|
-
if (!response.ok) throw new Error(data.error);
|
|
24
|
-
document.querySelector("#output").textContent = data.output;
|
|
25
|
-
document.querySelector("#first").textContent = data.firstOutput;
|
|
26
|
-
result.hidden = false;
|
|
27
|
-
status.textContent = "Workflow completed.";
|
|
28
|
-
} catch (error) {
|
|
29
|
-
status.textContent = error.message;
|
|
30
|
-
} finally {
|
|
31
|
-
button.disabled = false;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
1
|
+
const form = document.querySelector("form");
|
|
2
|
+
const button = form.querySelector("button");
|
|
3
|
+
const status = document.querySelector("#status");
|
|
4
|
+
const result = document.querySelector("#result");
|
|
5
|
+
|
|
6
|
+
fetch("/api/app").then(response => response.json()).then(({ name }) => {
|
|
7
|
+
document.title = name;
|
|
8
|
+
document.querySelector("h1").textContent = name;
|
|
9
|
+
}).catch(() => { status.textContent = "Could not load application details."; });
|
|
10
|
+
|
|
11
|
+
form.addEventListener("submit", async event => {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
button.disabled = true;
|
|
14
|
+
result.hidden = true;
|
|
15
|
+
status.textContent = "Running both agents…";
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch("/api/run", {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: { "Content-Type": "application/json" },
|
|
20
|
+
body: JSON.stringify({ input: document.querySelector("#input").value }),
|
|
21
|
+
});
|
|
22
|
+
const data = await response.json();
|
|
23
|
+
if (!response.ok) throw new Error(data.error);
|
|
24
|
+
document.querySelector("#output").textContent = data.output;
|
|
25
|
+
document.querySelector("#first").textContent = data.firstOutput;
|
|
26
|
+
result.hidden = false;
|
|
27
|
+
status.textContent = "Workflow completed.";
|
|
28
|
+
} catch (error) {
|
|
29
|
+
status.textContent = error.message;
|
|
30
|
+
} finally {
|
|
31
|
+
button.disabled = false;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>Lyra application</title>
|
|
7
|
-
<style>
|
|
8
|
-
body { background:#f6f9f7;color:#152c23;font:1rem/1.6 system-ui,sans-serif;margin:0 }
|
|
9
|
-
main { max-width:50rem;margin:4rem auto;padding:0 1.25rem }
|
|
10
|
-
label,textarea,button { display:block;font:inherit }
|
|
11
|
-
textarea { box-sizing:border-box;width:100%;min-height:8rem;margin:.45rem 0 1rem;padding:.75rem;border:1px solid #8ea99c;border-radius:.5rem }
|
|
12
|
-
button { background:#174b38;color:white;border:0;border-radius:.5rem;padding:.6rem 1rem;cursor:pointer }
|
|
13
|
-
button:disabled { opacity:.65;cursor:wait }
|
|
14
|
-
pre { white-space:pre-wrap;overflow-wrap:anywhere;background:white;padding:1rem;border:1px solid #cfddd5;border-radius:.5rem;font:inherit }
|
|
15
|
-
</style>
|
|
16
|
-
<script src="/preview.js" defer></script>
|
|
17
|
-
</head>
|
|
18
|
-
<body><main>
|
|
19
|
-
<h1>Lyra application</h1>
|
|
20
|
-
<form><label for="input">Workflow input</label><textarea id="input" required maxlength="4000"></textarea><button>Run workflow</button></form>
|
|
21
|
-
<p role="status" id="status"></p>
|
|
22
|
-
<section hidden id="result"><h2>Final result</h2><pre id="output"></pre><details><summary>First agent output</summary><pre id="first"></pre></details></section>
|
|
23
|
-
</main></body>
|
|
24
|
-
</html>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Lyra application</title>
|
|
7
|
+
<style>
|
|
8
|
+
body { background:#f6f9f7;color:#152c23;font:1rem/1.6 system-ui,sans-serif;margin:0 }
|
|
9
|
+
main { max-width:50rem;margin:4rem auto;padding:0 1.25rem }
|
|
10
|
+
label,textarea,button { display:block;font:inherit }
|
|
11
|
+
textarea { box-sizing:border-box;width:100%;min-height:8rem;margin:.45rem 0 1rem;padding:.75rem;border:1px solid #8ea99c;border-radius:.5rem }
|
|
12
|
+
button { background:#174b38;color:white;border:0;border-radius:.5rem;padding:.6rem 1rem;cursor:pointer }
|
|
13
|
+
button:disabled { opacity:.65;cursor:wait }
|
|
14
|
+
pre { white-space:pre-wrap;overflow-wrap:anywhere;background:white;padding:1rem;border:1px solid #cfddd5;border-radius:.5rem;font:inherit }
|
|
15
|
+
</style>
|
|
16
|
+
<script src="/preview.js" defer></script>
|
|
17
|
+
</head>
|
|
18
|
+
<body><main>
|
|
19
|
+
<h1>Lyra application</h1>
|
|
20
|
+
<form><label for="input">Workflow input</label><textarea id="input" required maxlength="4000"></textarea><button>Run workflow</button></form>
|
|
21
|
+
<p role="status" id="status"></p>
|
|
22
|
+
<section hidden id="result"><h2>Final result</h2><pre id="output"></pre><details><summary>First agent output</summary><pre id="first"></pre></details></section>
|
|
23
|
+
</main></body>
|
|
24
|
+
</html>
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { createServer } from "node:http";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { createSavedAgentClient, runSavedApp, validateSavedApp } from "./saved-app.js";
|
|
4
|
-
|
|
5
|
-
export async function startSavedPreview(manifest, { port = Number(process.env.LYRA_PREVIEW_PORT ?? 4173), client } = {}) {
|
|
6
|
-
validateSavedApp(manifest);
|
|
7
|
-
client ??= createSavedAgentClient();
|
|
8
|
-
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error("Invalid preview port.");
|
|
9
|
-
const [html, script] = await Promise.all(["saved-preview.html", "saved-preview-browser.js"].map(
|
|
10
|
-
name => readFile(new URL("./" + name, import.meta.url)),
|
|
11
|
-
));
|
|
12
|
-
const server = createServer(async (req, res) => {
|
|
13
|
-
const send = (status, body, type = "application/json; charset=utf-8") => {
|
|
14
|
-
res.writeHead(status, {
|
|
15
|
-
"Content-Type": type, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
16
|
-
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'",
|
|
17
|
-
});
|
|
18
|
-
res.end(type.startsWith("application/json") ? JSON.stringify(body) : body);
|
|
19
|
-
};
|
|
20
|
-
const authority = "127.0.0.1:" + server.address().port;
|
|
21
|
-
if (req.headers.host !== authority) return send(403, { error: "Use the loopback address." });
|
|
22
|
-
if (req.method === "GET" && req.url === "/") return send(200, html, "text/html; charset=utf-8");
|
|
23
|
-
if (req.method === "GET" && req.url === "/preview.js") return send(200, script, "text/javascript; charset=utf-8");
|
|
24
|
-
if (req.method === "GET" && req.url === "/api/app") return send(200, { name: manifest.application.name });
|
|
25
|
-
if (req.method !== "POST" || req.url !== "/api/run") return send(404, { error: "Not found." });
|
|
26
|
-
if (req.headers.origin !== "http://" + authority) return send(403, { error: "Use the application page to run agents." });
|
|
27
|
-
if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
|
|
28
|
-
|
|
29
|
-
const chunks = [];
|
|
30
|
-
let size = 0;
|
|
31
|
-
let input;
|
|
32
|
-
try {
|
|
33
|
-
for await (const chunk of req) {
|
|
34
|
-
size += chunk.length;
|
|
35
|
-
if (size > 24_576) return send(413, { error: "Input is too large." });
|
|
36
|
-
chunks.push(chunk);
|
|
37
|
-
}
|
|
38
|
-
input = JSON.parse(Buffer.concat(chunks).toString("utf8"))?.input;
|
|
39
|
-
} catch {
|
|
40
|
-
return send(400, { error: "Invalid request." });
|
|
41
|
-
}
|
|
42
|
-
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
43
|
-
return send(400, { error: "Enter between 1 and 4,000 characters." });
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
send(200, await runSavedApp(manifest, input, client));
|
|
47
|
-
} catch (error) {
|
|
48
|
-
send(502, { error: error.message });
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
server.requestTimeout = 10_000;
|
|
53
|
-
await new Promise((resolve, reject) => {
|
|
54
|
-
server.once("error", reject);
|
|
55
|
-
server.listen(port, "127.0.0.1", resolve);
|
|
56
|
-
}).catch(error => {
|
|
57
|
-
if (error.code === "EADDRINUSE") throw new Error("Preview port is busy. Set LYRA_PREVIEW_PORT=0 to pick a free port.");
|
|
58
|
-
throw error;
|
|
59
|
-
});
|
|
60
|
-
return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
|
|
61
|
-
}
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { createSavedAgentClient, runSavedApp, validateSavedApp } from "./saved-app.js";
|
|
4
|
+
|
|
5
|
+
export async function startSavedPreview(manifest, { port = Number(process.env.LYRA_PREVIEW_PORT ?? 4173), client } = {}) {
|
|
6
|
+
validateSavedApp(manifest);
|
|
7
|
+
client ??= createSavedAgentClient();
|
|
8
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error("Invalid preview port.");
|
|
9
|
+
const [html, script] = await Promise.all(["saved-preview.html", "saved-preview-browser.js"].map(
|
|
10
|
+
name => readFile(new URL("./" + name, import.meta.url)),
|
|
11
|
+
));
|
|
12
|
+
const server = createServer(async (req, res) => {
|
|
13
|
+
const send = (status, body, type = "application/json; charset=utf-8") => {
|
|
14
|
+
res.writeHead(status, {
|
|
15
|
+
"Content-Type": type, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
16
|
+
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'unsafe-inline'; connect-src 'self'; frame-ancestors 'none'",
|
|
17
|
+
});
|
|
18
|
+
res.end(type.startsWith("application/json") ? JSON.stringify(body) : body);
|
|
19
|
+
};
|
|
20
|
+
const authority = "127.0.0.1:" + server.address().port;
|
|
21
|
+
if (req.headers.host !== authority) return send(403, { error: "Use the loopback address." });
|
|
22
|
+
if (req.method === "GET" && req.url === "/") return send(200, html, "text/html; charset=utf-8");
|
|
23
|
+
if (req.method === "GET" && req.url === "/preview.js") return send(200, script, "text/javascript; charset=utf-8");
|
|
24
|
+
if (req.method === "GET" && req.url === "/api/app") return send(200, { name: manifest.application.name });
|
|
25
|
+
if (req.method !== "POST" || req.url !== "/api/run") return send(404, { error: "Not found." });
|
|
26
|
+
if (req.headers.origin !== "http://" + authority) return send(403, { error: "Use the application page to run agents." });
|
|
27
|
+
if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
|
|
28
|
+
|
|
29
|
+
const chunks = [];
|
|
30
|
+
let size = 0;
|
|
31
|
+
let input;
|
|
32
|
+
try {
|
|
33
|
+
for await (const chunk of req) {
|
|
34
|
+
size += chunk.length;
|
|
35
|
+
if (size > 24_576) return send(413, { error: "Input is too large." });
|
|
36
|
+
chunks.push(chunk);
|
|
37
|
+
}
|
|
38
|
+
input = JSON.parse(Buffer.concat(chunks).toString("utf8"))?.input;
|
|
39
|
+
} catch {
|
|
40
|
+
return send(400, { error: "Invalid request." });
|
|
41
|
+
}
|
|
42
|
+
if (typeof input !== "string" || !input.trim() || input.length > 4000) {
|
|
43
|
+
return send(400, { error: "Enter between 1 and 4,000 characters." });
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
send(200, await runSavedApp(manifest, input, client));
|
|
47
|
+
} catch (error) {
|
|
48
|
+
send(502, { error: error.message });
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
server.requestTimeout = 10_000;
|
|
53
|
+
await new Promise((resolve, reject) => {
|
|
54
|
+
server.once("error", reject);
|
|
55
|
+
server.listen(port, "127.0.0.1", resolve);
|
|
56
|
+
}).catch(error => {
|
|
57
|
+
if (error.code === "EADDRINUSE") throw new Error("Preview port is busy. Set LYRA_PREVIEW_PORT=0 to pick a free port.");
|
|
58
|
+
throw error;
|
|
59
|
+
});
|
|
60
|
+
return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
|
|
61
|
+
}
|
|
@@ -1,64 +1,21 @@
|
|
|
1
|
-
import { readAppManifest, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
throw new Error(
|
|
12
|
-
}
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const capabilityIds = new Set();
|
|
23
|
-
for (const capability of capabilities) {
|
|
24
|
-
if (!isRecord(capability) || !isIdentifier(capability.id) || !isIdentifier(capability.adapterId) ||
|
|
25
|
-
!modes.has(capability.executionMode)) {
|
|
26
|
-
throw new Error("Each capability requires an id, adapterId, and supported executionMode.");
|
|
27
|
-
}
|
|
28
|
-
if (capabilityIds.has(capability.id)) throw new Error(`Duplicate capability: ${capability.id}.`);
|
|
29
|
-
for (const key of ["inputSchema", "outputSchema"]) {
|
|
30
|
-
if (Object.hasOwn(capability, key)) assertValueSchema(capability[key], `${capability.id} ${key}`);
|
|
31
|
-
}
|
|
32
|
-
capabilityIds.add(capability.id);
|
|
33
|
-
}
|
|
34
|
-
const actionIds = new Set();
|
|
35
|
-
for (const action of actions) {
|
|
36
|
-
if (!isRecord(action) || !isIdentifier(action.id) || !isIdentifier(action.capabilityId)) {
|
|
37
|
-
throw new Error("Each action requires an id and capabilityId.");
|
|
38
|
-
}
|
|
39
|
-
if (actionIds.has(action.id)) throw new Error(`Duplicate action: ${action.id}.`);
|
|
40
|
-
if (!capabilityIds.has(action.capabilityId)) {
|
|
41
|
-
throw new Error(`Action ${action.id} refers to unknown capability ${action.capabilityId}.`);
|
|
42
|
-
}
|
|
43
|
-
actionIds.add(action.id);
|
|
44
|
-
}
|
|
45
|
-
return { id: application.id, capabilityCount: capabilityIds.size, actionCount: actionIds.size };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function runAppValidation(args, output = process.stdout) {
|
|
49
|
-
if (args.length === 1 && args[0] === "--help") {
|
|
50
|
-
output.write("Usage: agent-lyra app validate <manifest.json>\n");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (args.length !== 1 || args[0].startsWith("-")) {
|
|
54
|
-
throw new Error("Provide a manifest path. See agent-lyra app validate --help.");
|
|
55
|
-
}
|
|
56
|
-
const manifest = await readAppManifest(args[0]);
|
|
57
|
-
if (manifest?.version === SAVED_VERSION) {
|
|
58
|
-
validateSavedApp(manifest);
|
|
59
|
-
output.write("Valid app " + manifest.application.id + " (2 saved agents).\n");
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const { id, capabilityCount, actionCount } = validateAppManifest(manifest);
|
|
63
|
-
output.write(`Valid app ${id} (${capabilityCount} capabilities, ${actionCount} actions).\n`);
|
|
64
|
-
}
|
|
1
|
+
import { readAppManifest, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
|
|
2
|
+
import { validateAppManifest } from "./manifest-contract.js";
|
|
3
|
+
export { validateAppManifest } from "./manifest-contract.js";
|
|
4
|
+
|
|
5
|
+
export async function runAppValidation(args, output = process.stdout) {
|
|
6
|
+
if (args.length === 1 && args[0] === "--help") {
|
|
7
|
+
output.write("Usage: agent-lyra app validate <manifest.json>\n");
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (args.length !== 1 || args[0].startsWith("-")) {
|
|
11
|
+
throw new Error("Provide a manifest path. See agent-lyra app validate --help.");
|
|
12
|
+
}
|
|
13
|
+
const manifest = await readAppManifest(args[0]);
|
|
14
|
+
if (manifest?.version === SAVED_VERSION) {
|
|
15
|
+
validateSavedApp(manifest);
|
|
16
|
+
output.write("Valid app " + manifest.application.id + " (2 saved agents).\n");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const { id, capabilityCount, actionCount } = validateAppManifest(manifest);
|
|
20
|
+
output.write(`Valid app ${id} (${capabilityCount} capabilities, ${actionCount} actions).\n`);
|
|
21
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const catalogVersion = 2;
|
|
2
|
+
|
|
3
|
+
// Each technology contributes an actionable skill. Roles are reused across packs.
|
|
4
|
+
export const areas = {
|
|
5
|
+
frontend: "Frontend developer",
|
|
6
|
+
backend: "Backend developer",
|
|
7
|
+
database: "Database developer",
|
|
8
|
+
devops: "DevOps engineer",
|
|
9
|
+
qa: "QA automation engineer",
|
|
10
|
+
mobile: "Mobile developer",
|
|
11
|
+
data: "Data engineer",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const technologies = {
|
|
15
|
+
react: ["frontend", "React", "Component behavior", "Check loading, error, and success states. Test the visible behavior with accessible queries and keep state close to the components that own it."],
|
|
16
|
+
nextjs: ["frontend", "Next.js", "Rendering and routing", "Identify the router and rendering boundary first. Keep server-only data on the server and test navigation, loading, and error states."],
|
|
17
|
+
typescript: ["frontend", "TypeScript", "Type-safe changes", "Read tsconfig for the project. Narrow unknown input at boundaries, preserve public types, and run the repository type check."],
|
|
18
|
+
node: ["backend", "Node.js", "Runtime compatibility", "Check the supported Node versions and module format. Handle async errors, close resources, and run the applicable package scripts."],
|
|
19
|
+
express: ["backend", "Express", "Request validation", "Validate request data at the route boundary, reuse existing middleware, and test status codes for missing, invalid, and valid input."],
|
|
20
|
+
python: ["backend", "Python", "Package and test changes", "Read pyproject.toml and supported Python versions. Use existing project tooling and test behavior through its public entry points."],
|
|
21
|
+
fastapi: ["backend", "FastAPI", "API contracts", "Use request and response models consistent with the project. Test validation, dependency overrides, and error responses with the app test client."],
|
|
22
|
+
mongodb: ["database", "MongoDB", "Document modeling", "Model against actual query patterns. Review indexes, existing document shapes, and migration compatibility with synthetic data."],
|
|
23
|
+
postgresql: ["database", "PostgreSQL", "Schema migrations", "Review data volume and lock implications. Test forward migrations against realistic fixtures and document application compatibility."],
|
|
24
|
+
docker: ["devops", "Docker", "Container builds", "Check build context and ignore rules. Keep secrets outside image layers and verify the start command and health endpoint locally."],
|
|
25
|
+
"github-actions": ["devops", "GitHub Actions", "CI workflows", "Review job triggers, permissions, and test artifacts. Reuse repository scripts and keep credentials in repository or environment secrets."],
|
|
26
|
+
"gitlab-ci": ["devops", "GitLab CI", "CI pipelines", "Review job rules, needs, and artifacts. Reuse project test commands and validate changes on a test branch."],
|
|
27
|
+
playwright: ["qa", "Playwright", "Browser automation", "Use role-based locators and web-first assertions. Isolate test data with fixtures, retain traces on failures, and diagnose flaky tests without adding fixed sleeps."],
|
|
28
|
+
vue: ["frontend", "Vue", "Reactive UI", "Check the Vue version and routing conventions. Test emitted events, user-visible states, and composable cleanup."],
|
|
29
|
+
angular: ["frontend", "Angular", "Component and service integration", "Follow the project's standalone or module pattern. Verify DI boundaries, form validation, and loading and error states."],
|
|
30
|
+
svelte: ["frontend", "Svelte", "Component state", "Use the project's Svelte version and reactive primitives. Cover interaction, SSR boundaries where relevant, and state reset."],
|
|
31
|
+
django: ["backend", "Django", "Model and view changes", "Review model validation, permissions, and migration dependencies. Exercise the relevant views through the test client."],
|
|
32
|
+
"spring-boot": ["backend", "Spring Boot", "Service and controller changes", "Follow existing configuration and dependency injection conventions. Test validation and error mapping using the project's test slices."],
|
|
33
|
+
dotnet: ["backend", ".NET", "Application and API changes", "Check target frameworks and hosting conventions. Test middleware, dependency injection, and public endpoint behavior."],
|
|
34
|
+
go: ["backend", "Go", "Service changes", "Use the module version and existing package boundaries. Propagate context and errors, and use table-driven tests for edge cases."],
|
|
35
|
+
rust: ["backend", "Rust", "Crate changes", "Check workspace features and the minimum supported Rust version. Preserve API error contracts and test meaningful feature combinations."],
|
|
36
|
+
mysql: ["database", "MySQL", "Schema and query changes", "Check server version and SQL mode. Validate migration locks, indexes, and query plans against synthetic data."],
|
|
37
|
+
redis: ["database", "Redis", "Cache behavior", "Define key scope and expiration. Cover cache misses, stale values, and recovery when Redis is unavailable."],
|
|
38
|
+
kubernetes: ["devops", "Kubernetes", "Deployment configuration", "Validate manifests against supported versions. Review probes, resource requests, and rollout behavior in a test namespace."],
|
|
39
|
+
terraform: ["devops", "Terraform", "Infrastructure review", "Inspect configuration and state boundaries. Review a plan in the intended environment before any apply."],
|
|
40
|
+
"react-native": ["mobile", "React Native", "Cross-platform screens", "Verify behavior on both supported platforms. Check accessibility, permission handling, and loading or offline states."],
|
|
41
|
+
flutter: ["mobile", "Flutter", "Widgets and navigation", "Follow project state and navigation conventions. Cover key behavior with widget tests and verify platform integrations separately."],
|
|
42
|
+
android: ["mobile", "Android", "Platform behavior", "Check lifecycle and target SDK constraints. Use local and instrumented tests as appropriate for storage, permissions, and navigation."],
|
|
43
|
+
ios: ["mobile", "iOS", "Platform behavior", "Check supported OS versions and project structure. Verify main-thread UI behavior, accessibility, and permission states."],
|
|
44
|
+
dbt: ["data", "dbt", "Data model tests", "Trace model dependencies, review incremental behavior, and test uniqueness, nullability, and source freshness with suitable data."],
|
|
45
|
+
spark: ["data", "Apache Spark", "Pipeline changes", "Review schema evolution, joins, partitioning, and null semantics. Test with a small deterministic dataset before larger workloads."],
|
|
46
|
+
cucumber: ["qa", "Cucumber", "Acceptance scenarios", "Write Gherkin scenarios around observable behavior. Reuse parameterized steps, keep state scoped to each scenario, and review undefined or ambiguous steps."],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const presets = {
|
|
50
|
+
mern: ["mongodb", "express", "react", "node"],
|
|
51
|
+
"python-fastapi": ["python", "fastapi"],
|
|
52
|
+
"playwright-cucumber": ["playwright", "cucumber"],
|
|
53
|
+
"spring-postgres": ["spring-boot", "postgresql"],
|
|
54
|
+
"react-native-mobile": ["react-native", "typescript"],
|
|
55
|
+
"spark-dbt": ["spark", "dbt"],
|
|
56
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { areas, catalogVersion, presets, technologies } from "./catalog.js";
|
|
2
|
+
|
|
3
|
+
export const bundledCatalog = { version: catalogVersion, technologies, presets };
|
|
4
|
+
|
|
5
|
+
export async function fetchCodingCatalog(version, fetchRequest = fetch) {
|
|
6
|
+
if (!/^[1-9][0-9]{0,5}$/.test(version)) throw new Error("Use a numeric Cloud catalog version.");
|
|
7
|
+
const response = await fetchRequest("https://api.agentlyra.in/api/coding-catalog/" + version, {
|
|
8
|
+
redirect: "error", signal: AbortSignal.timeout(5000),
|
|
9
|
+
});
|
|
10
|
+
if (!response.ok) throw new Error("Cloud coding catalog version " + version + " is unavailable. Omit --catalog-version to use bundled packs.");
|
|
11
|
+
const reader = response.body.getReader();
|
|
12
|
+
const chunks = [];
|
|
13
|
+
let total = 0;
|
|
14
|
+
while (true) {
|
|
15
|
+
const { done, value } = await reader.read();
|
|
16
|
+
if (done) break;
|
|
17
|
+
total += value.byteLength;
|
|
18
|
+
if (total > 262_144) {
|
|
19
|
+
await reader.cancel();
|
|
20
|
+
throw new Error("Cloud coding catalog exceeds the size limit.");
|
|
21
|
+
}
|
|
22
|
+
chunks.push(Buffer.from(value));
|
|
23
|
+
}
|
|
24
|
+
return validateCodingCatalog(JSON.parse(Buffer.concat(chunks).toString("utf8")), Number(version));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function validateCodingCatalog(catalog, version = catalog?.version) {
|
|
28
|
+
if (!Number.isSafeInteger(version) || version < 1 || version > 999_999) throw new Error("Invalid Cloud catalog version.");
|
|
29
|
+
const slug = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
30
|
+
const plain = object => object !== null && typeof object === "object" && !Array.isArray(object);
|
|
31
|
+
const validText = (value, max) => typeof value === "string" && value.trim() && value.length <= max &&
|
|
32
|
+
!/[\u0000-\u001f\u007f]/.test(value);
|
|
33
|
+
if (catalog?.version !== version || !plain(catalog.technologies) || !plain(catalog.presets)) throw new Error("Invalid Cloud catalog.");
|
|
34
|
+
const items = Object.entries(catalog.technologies);
|
|
35
|
+
const bundles = Object.entries(catalog.presets);
|
|
36
|
+
if (!items.length || items.length > 150 || bundles.length > 100 ||
|
|
37
|
+
items.some(([id, pack]) => !slug.test(id) || !Array.isArray(pack) || pack.length !== 4 ||
|
|
38
|
+
!Object.hasOwn(areas, pack[0]) || !validText(pack[1], 80) || !validText(pack[2], 120) || !validText(pack[3], 2000)) ||
|
|
39
|
+
bundles.some(([id, ids]) => !slug.test(id) || !Array.isArray(ids) || !ids.length || ids.length > 30 ||
|
|
40
|
+
ids.some(item => typeof item !== "string" || !Object.hasOwn(catalog.technologies, item)))) {
|
|
41
|
+
throw new Error("Invalid Cloud catalog.");
|
|
42
|
+
}
|
|
43
|
+
return { version: catalog.version, technologies: catalog.technologies, presets: catalog.presets };
|
|
44
|
+
}
|