agent-lyra 0.8.0 → 0.10.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/LICENSE +21 -21
- package/README.md +301 -291
- package/bin/agent-lyra.js +51 -51
- package/bin/lyra-oss-preview.js +16 -16
- 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 +115 -72
- package/src/app-builder/manifest-contract.js +46 -46
- package/src/app-builder/native-adapter.js +29 -29
- package/src/app-builder/preview.js +35 -31
- 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 +31 -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 -64
- package/src/coding/detect-stack.mjs +110 -110
- package/src/coding/export.js +133 -133
- package/src/coding/setup.js +175 -175
- package/src/coding/skills/lyra-android/SKILL.md +37 -37
- package/src/coding/skills/lyra-angular/SKILL.md +37 -37
- package/src/coding/skills/lyra-cucumber/SKILL.md +37 -37
- package/src/coding/skills/lyra-dbt/SKILL.md +37 -37
- package/src/coding/skills/lyra-django/SKILL.md +37 -37
- package/src/coding/skills/lyra-docker/SKILL.md +37 -37
- package/src/coding/skills/lyra-dotnet/SKILL.md +37 -37
- package/src/coding/skills/lyra-express/SKILL.md +37 -37
- package/src/coding/skills/lyra-fastapi/SKILL.md +37 -37
- package/src/coding/skills/lyra-flutter/SKILL.md +37 -37
- package/src/coding/skills/lyra-github-actions/SKILL.md +37 -37
- package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -37
- package/src/coding/skills/lyra-go/SKILL.md +37 -37
- package/src/coding/skills/lyra-ios/SKILL.md +37 -37
- package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -37
- package/src/coding/skills/lyra-mongodb/SKILL.md +37 -37
- package/src/coding/skills/lyra-mysql/SKILL.md +37 -37
- package/src/coding/skills/lyra-nextjs/SKILL.md +37 -37
- package/src/coding/skills/lyra-node/SKILL.md +37 -37
- package/src/coding/skills/lyra-playwright/SKILL.md +37 -37
- package/src/coding/skills/lyra-postgresql/SKILL.md +37 -37
- package/src/coding/skills/lyra-python/SKILL.md +37 -37
- package/src/coding/skills/lyra-react/SKILL.md +37 -37
- package/src/coding/skills/lyra-react-native/SKILL.md +37 -37
- package/src/coding/skills/lyra-redis/SKILL.md +37 -37
- package/src/coding/skills/lyra-rust/SKILL.md +37 -37
- package/src/coding/skills/lyra-spark/SKILL.md +37 -37
- package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -37
- package/src/coding/skills/lyra-svelte/SKILL.md +37 -37
- package/src/coding/skills/lyra-terraform/SKILL.md +37 -37
- package/src/coding/skills/lyra-typescript/SKILL.md +37 -37
- package/src/coding/skills/lyra-vue/SKILL.md +37 -37
- package/src/framework/agent.js +181 -181
- package/src/framework/mda.js +65 -65
- package/src/framework/run.py +111 -111
- 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 +960 -960
- package/src/intelligence/graphsnip-provider.d.ts +5 -5
- package/src/intelligence/graphsnip-provider.js +57 -57
- package/src/intelligence/lifecycle.js +25 -25
- package/src/memory/LICENSE +21 -21
- package/src/memory/README.md +5 -5
- package/src/memory/UPSTREAM.json +24 -24
- package/src/memory/bridge-cli.js +16 -16
- package/src/memory/bridge.js +18 -18
- package/src/memory/cli.js +21 -21
- package/src/memory/cloud-sync-actions.js +61 -61
- package/src/memory/contract.json +45 -45
- package/src/memory/index.d.ts +50 -50
- package/src/memory/index.js +7 -7
- package/src/memory/lifecycle.js +29 -29
- package/src/memory/local-cli.js +34 -34
- package/src/memory/local-store.js +209 -209
- package/src/memory/package.json +33 -33
- package/src/memory/proposals.js +90 -90
- package/src/memory/skills-cli.js +26 -26
- package/src/memory/standalone.d.ts +50 -50
- package/src/memory/standalone.js +1 -1
- 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/resource-files.js +18 -18
- package/src/runtime/contracts.d.ts +47 -47
- package/src/runtime/local-cli.js +161 -161
- package/src/runtime/mcp-stdio.js +111 -111
- package/src/runtime/orchestration.js +59 -59
- package/src/runtime/run-agent.js +54 -54
- package/src/standalone/index.d.ts +45 -45
- package/src/standalone/index.js +13 -13
- package/src/standalone/init.js +12 -12
- 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 +542 -345
- package/src/studio/export.js +83 -86
- package/src/studio/index.html +74 -37
- package/src/studio/memory-actions.js +37 -37
- package/src/studio/memory-panel.js +200 -200
- package/src/studio/project.js +308 -240
- 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 +164 -150
- package/src/studio/session.js +83 -83
- package/src/studio/studio.css +257 -10
- package/src/studio/sync.js +42 -42
- package/src/studio/workflow-editor.js +240 -0
- package/src/studio/workflow-sync.js +229 -157
package/src/studio/pull-agent.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { lstat, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { resourceFiles } from "../resource-files.js";
|
|
5
|
-
import { readLocalAgent } from "./project.js";
|
|
6
|
-
import { readMode, readSdkKey, requireCloudMode } from "./session.js";
|
|
7
|
-
|
|
8
|
-
const hash = (name, systemPrompt) => createHash("sha256").update(JSON.stringify({ name, systemPrompt })).digest("hex");
|
|
9
|
-
const digest = /^[a-f0-9]{64}$/;
|
|
10
|
-
|
|
11
|
-
export async function pullAgentEdits(root, id, { request = fetch, key } = {}) {
|
|
12
|
-
requireCloudMode(await readMode(root));
|
|
13
|
-
if (!/^local:[a-zA-Z0-9][a-zA-Z0-9_-]{0,95}$/.test(id ?? "")) throw new Error("Choose a local Markdown text agent.");
|
|
14
|
-
const base = join(root, ".lyra");
|
|
15
|
-
const links = join(base, "agent-links");
|
|
16
|
-
const folder = join(base, "agents");
|
|
17
|
-
for (const directory of [base, links, folder]) {
|
|
18
|
-
if (!(await lstat(directory).catch(() => null))?.isDirectory()) throw new Error("Push this agent to Cloud once to link it.");
|
|
19
|
-
}
|
|
20
|
-
const metadata = join(links, id.slice(6) + ".json");
|
|
21
|
-
if (!(await lstat(metadata).catch(() => null))?.isFile()) throw new Error("Push this agent to Cloud once to link it.");
|
|
22
|
-
const link = JSON.parse(await readFile(metadata, "utf8"));
|
|
23
|
-
if (!digest.test(link?.linkId ?? "") || !digest.test(link?.revision ?? "")) throw new Error("Invalid Cloud link.");
|
|
24
|
-
|
|
25
|
-
const matches = [];
|
|
26
|
-
for (const name of await resourceFiles(folder, ".md")) {
|
|
27
|
-
const path = join(folder, name);
|
|
28
|
-
const content = await readFile(path, "utf8");
|
|
29
|
-
const parsed = readLocalAgent(content);
|
|
30
|
-
if (parsed?.id === id) matches.push({ path, content, parsed });
|
|
31
|
-
}
|
|
32
|
-
if (matches.length !== 1) throw new Error("Use a unique local agent ID before pulling edits.");
|
|
33
|
-
const [{ path, content, parsed }] = matches;
|
|
34
|
-
|
|
35
|
-
key ??= await readSdkKey(root);
|
|
36
|
-
if (!key) throw new Error("Use Connect to Cloud with a Cloud sync key before pulling edits.");
|
|
37
|
-
const response = await request("https://api.agentlyra.in/api/sdk/v1/studio/agents/" + link.linkId, {
|
|
38
|
-
headers: { Authorization: "Bearer " + key }, redirect: "error", signal: AbortSignal.timeout(20_000),
|
|
39
|
-
});
|
|
40
|
-
const remote = await response.json();
|
|
41
|
-
if (!response.ok) throw new Error(remote.error || "Could not pull agent edits.");
|
|
42
|
-
if (remote.id !== link.cloudId || typeof remote.name !== "string" || typeof remote.prompt !== "string" ||
|
|
43
|
-
!digest.test(remote.revision ?? "")) throw new Error("The Cloud agent link no longer matches.");
|
|
44
|
-
const local = hash(parsed.name.trim(), parsed.prompt.trim());
|
|
45
|
-
if (remote.revision === link.revision || local === remote.revision) {
|
|
46
|
-
if (local !== remote.revision) return { name: parsed.name, updated: false };
|
|
47
|
-
} else {
|
|
48
|
-
if (local !== link.revision) throw new Error("Both copies changed. Review the Cloud agent and reconcile the edits before syncing.");
|
|
49
|
-
const front = /^---\r?\n[\s\S]*?\r?\n---\r?\n/.exec(content)[0];
|
|
50
|
-
const body = content.slice(front.length);
|
|
51
|
-
const next = front.replace(/^name:[^\r\n]*/m, () => "name: " + JSON.stringify(remote.name)) +
|
|
52
|
-
body.replace(/(^|\n)## System Prompt[^\S\r\n]*\r?\n[\s\S]*?(?=\r?\n## [^\n]+|$)/,
|
|
53
|
-
(_whole, prefix) => prefix + "## System Prompt\n" + remote.prompt + "\n");
|
|
54
|
-
const checked = readLocalAgent(next);
|
|
55
|
-
if (!checked || hash(checked.name, checked.prompt) !== remote.revision) {
|
|
56
|
-
throw new Error("The Cloud instructions cannot be represented in this Markdown agent. Copy them manually.");
|
|
57
|
-
}
|
|
58
|
-
if (await readFile(path, "utf8") !== content) throw new Error("The local agent changed during the pull. Try again.");
|
|
59
|
-
await replace(path, next);
|
|
60
|
-
}
|
|
61
|
-
if (link.revision !== remote.revision) {
|
|
62
|
-
await replace(metadata, JSON.stringify({ ...link, revision: remote.revision }) + "\n");
|
|
63
|
-
}
|
|
64
|
-
return { name: remote.name, updated: local !== remote.revision };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function replace(path, content) {
|
|
68
|
-
const temporary = path + "." + randomUUID() + ".tmp";
|
|
69
|
-
await writeFile(temporary, content, { flag: "wx", mode: 0o600 });
|
|
70
|
-
try { await rename(temporary, path); }
|
|
71
|
-
finally { await unlink(temporary).catch(() => {}); }
|
|
72
|
-
}
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { resourceFiles } from "../resource-files.js";
|
|
5
|
+
import { readLocalAgent } from "./project.js";
|
|
6
|
+
import { readMode, readSdkKey, requireCloudMode } from "./session.js";
|
|
7
|
+
|
|
8
|
+
const hash = (name, systemPrompt) => createHash("sha256").update(JSON.stringify({ name, systemPrompt })).digest("hex");
|
|
9
|
+
const digest = /^[a-f0-9]{64}$/;
|
|
10
|
+
|
|
11
|
+
export async function pullAgentEdits(root, id, { request = fetch, key } = {}) {
|
|
12
|
+
requireCloudMode(await readMode(root));
|
|
13
|
+
if (!/^local:[a-zA-Z0-9][a-zA-Z0-9_-]{0,95}$/.test(id ?? "")) throw new Error("Choose a local Markdown text agent.");
|
|
14
|
+
const base = join(root, ".lyra");
|
|
15
|
+
const links = join(base, "agent-links");
|
|
16
|
+
const folder = join(base, "agents");
|
|
17
|
+
for (const directory of [base, links, folder]) {
|
|
18
|
+
if (!(await lstat(directory).catch(() => null))?.isDirectory()) throw new Error("Push this agent to Cloud once to link it.");
|
|
19
|
+
}
|
|
20
|
+
const metadata = join(links, id.slice(6) + ".json");
|
|
21
|
+
if (!(await lstat(metadata).catch(() => null))?.isFile()) throw new Error("Push this agent to Cloud once to link it.");
|
|
22
|
+
const link = JSON.parse(await readFile(metadata, "utf8"));
|
|
23
|
+
if (!digest.test(link?.linkId ?? "") || !digest.test(link?.revision ?? "")) throw new Error("Invalid Cloud link.");
|
|
24
|
+
|
|
25
|
+
const matches = [];
|
|
26
|
+
for (const name of await resourceFiles(folder, ".md")) {
|
|
27
|
+
const path = join(folder, name);
|
|
28
|
+
const content = await readFile(path, "utf8");
|
|
29
|
+
const parsed = readLocalAgent(content);
|
|
30
|
+
if (parsed?.id === id) matches.push({ path, content, parsed });
|
|
31
|
+
}
|
|
32
|
+
if (matches.length !== 1) throw new Error("Use a unique local agent ID before pulling edits.");
|
|
33
|
+
const [{ path, content, parsed }] = matches;
|
|
34
|
+
|
|
35
|
+
key ??= await readSdkKey(root);
|
|
36
|
+
if (!key) throw new Error("Use Connect to Cloud with a Cloud sync key before pulling edits.");
|
|
37
|
+
const response = await request("https://api.agentlyra.in/api/sdk/v1/studio/agents/" + link.linkId, {
|
|
38
|
+
headers: { Authorization: "Bearer " + key }, redirect: "error", signal: AbortSignal.timeout(20_000),
|
|
39
|
+
});
|
|
40
|
+
const remote = await response.json();
|
|
41
|
+
if (!response.ok) throw new Error(remote.error || "Could not pull agent edits.");
|
|
42
|
+
if (remote.id !== link.cloudId || typeof remote.name !== "string" || typeof remote.prompt !== "string" ||
|
|
43
|
+
!digest.test(remote.revision ?? "")) throw new Error("The Cloud agent link no longer matches.");
|
|
44
|
+
const local = hash(parsed.name.trim(), parsed.prompt.trim());
|
|
45
|
+
if (remote.revision === link.revision || local === remote.revision) {
|
|
46
|
+
if (local !== remote.revision) return { name: parsed.name, updated: false };
|
|
47
|
+
} else {
|
|
48
|
+
if (local !== link.revision) throw new Error("Both copies changed. Review the Cloud agent and reconcile the edits before syncing.");
|
|
49
|
+
const front = /^---\r?\n[\s\S]*?\r?\n---\r?\n/.exec(content)[0];
|
|
50
|
+
const body = content.slice(front.length);
|
|
51
|
+
const next = front.replace(/^name:[^\r\n]*/m, () => "name: " + JSON.stringify(remote.name)) +
|
|
52
|
+
body.replace(/(^|\n)## System Prompt[^\S\r\n]*\r?\n[\s\S]*?(?=\r?\n## [^\n]+|$)/,
|
|
53
|
+
(_whole, prefix) => prefix + "## System Prompt\n" + remote.prompt + "\n");
|
|
54
|
+
const checked = readLocalAgent(next);
|
|
55
|
+
if (!checked || hash(checked.name, checked.prompt) !== remote.revision) {
|
|
56
|
+
throw new Error("The Cloud instructions cannot be represented in this Markdown agent. Copy them manually.");
|
|
57
|
+
}
|
|
58
|
+
if (await readFile(path, "utf8") !== content) throw new Error("The local agent changed during the pull. Try again.");
|
|
59
|
+
await replace(path, next);
|
|
60
|
+
}
|
|
61
|
+
if (link.revision !== remote.revision) {
|
|
62
|
+
await replace(metadata, JSON.stringify({ ...link, revision: remote.revision }) + "\n");
|
|
63
|
+
}
|
|
64
|
+
return { name: remote.name, updated: local !== remote.revision };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function replace(path, content) {
|
|
68
|
+
const temporary = path + "." + randomUUID() + ".tmp";
|
|
69
|
+
await writeFile(temporary, content, { flag: "wx", mode: 0o600 });
|
|
70
|
+
try { await rename(temporary, path); }
|
|
71
|
+
finally { await unlink(temporary).catch(() => {}); }
|
|
72
|
+
}
|
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()
|