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/server.js
CHANGED
|
@@ -1,150 +1,164 @@
|
|
|
1
|
-
import { discoverFrameworkAgents, syncFrameworkAgent } from "../framework/agent.js";
|
|
2
|
-
import { memoryActions } from "./memory-actions.js";
|
|
3
|
-
import { createServer } from "node:http";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
import { readCatalog, readLayout, runSelection, saveLayout } from "./project.js";
|
|
6
|
-
import { readMode } from "./session.js";
|
|
7
|
-
import { syncSkill, syncTeam, syncWorkflow } from "./workflow-sync.js";
|
|
8
|
-
import { pullAgentEdits } from "./pull-agent.js";
|
|
9
|
-
import { pushStudioAgent } from "./push.js";
|
|
10
|
-
import { pullStudio } from "./sync.js";
|
|
11
|
-
|
|
12
|
-
export async function startStudio(root, { port = 0, run = runSelection, pull = pullStudio, appCatalog } = {}) {
|
|
13
|
-
const assets = new Map();
|
|
14
|
-
for (const [route, name, mime] of [
|
|
15
|
-
["/memory-panel.js", "memory-panel.js", "text/javascript"],
|
|
16
|
-
["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
|
|
17
|
-
["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
|
|
18
|
-
]) assets.set(route, [await readFile(new URL("./" + name, import.meta.url)), mime]);
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
["/api/framework-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
["/api/
|
|
29
|
-
["/api/
|
|
30
|
-
["/api/
|
|
31
|
-
["/api/
|
|
32
|
-
["/api/
|
|
33
|
-
["/api/
|
|
34
|
-
["/api/
|
|
35
|
-
["/api/
|
|
36
|
-
["/api/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
const
|
|
84
|
-
if (req.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
const result = await
|
|
143
|
-
output.write(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
1
|
+
import { discoverFrameworkAgents, syncFrameworkAgent } from "../framework/agent.js";
|
|
2
|
+
import { memoryActions } from "./memory-actions.js";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { describeRun, readCatalog, readLayout, runSelection, saveLayout, studioModels, validateRunBindings } from "./project.js";
|
|
6
|
+
import { readMode } from "./session.js";
|
|
7
|
+
import { openStudioWorkflow, saveStudioWorkflow, syncSkill, syncTeam, syncWorkflow } from "./workflow-sync.js";
|
|
8
|
+
import { pullAgentEdits } from "./pull-agent.js";
|
|
9
|
+
import { pushStudioAgent } from "./push.js";
|
|
10
|
+
import { pullStudio } from "./sync.js";
|
|
11
|
+
|
|
12
|
+
export async function startStudio(root, { port = 0, run = runSelection, pull = pullStudio, appCatalog, preview = false } = {}) {
|
|
13
|
+
const assets = new Map();
|
|
14
|
+
for (const [route, name, mime] of [
|
|
15
|
+
["/memory-panel.js", "memory-panel.js", "text/javascript"],
|
|
16
|
+
["/agent-ui.js", "agent-ui.js", "text/javascript"], ["/agent-ui.css", "agent-ui.css", "text/css"],
|
|
17
|
+
["/", "index.html", "text/html"], ["/studio.js", "browser.js", "text/javascript"], ["/workflow-editor.js", "workflow-editor.js", "text/javascript"], ["/studio.css", "studio.css", "text/css"],
|
|
18
|
+
]) assets.set(route, [await readFile(new URL("./" + name, import.meta.url)), mime]);
|
|
19
|
+
|
|
20
|
+
const readOnly = preview || Boolean(appCatalog);
|
|
21
|
+
const updates = new Map([
|
|
22
|
+
...(appCatalog ? [] : memoryActions(root)),
|
|
23
|
+
["/api/framework-preview", ({ id }) => syncFrameworkAgent(root, id)],
|
|
24
|
+
["/api/framework-sync", ({ id, fingerprint }) => {
|
|
25
|
+
if (typeof fingerprint !== "string") throw new Error("Preview the registration before syncing.");
|
|
26
|
+
return syncFrameworkAgent(root, id, fingerprint);
|
|
27
|
+
}],
|
|
28
|
+
["/api/save", ({ layout, revision }) => saveLayout(root, layout, revision)],
|
|
29
|
+
["/api/pull", () => pull(root)],
|
|
30
|
+
["/api/push", ({ id }) => pushStudioAgent(root, id)],
|
|
31
|
+
["/api/pull-agent", ({ id }) => pullAgentEdits(root, id)],
|
|
32
|
+
["/api/open-workflow", ({ id }) => openStudioWorkflow(root, id)],
|
|
33
|
+
["/api/save-workflow", async body => saveStudioWorkflow(root, body, await readCatalog(root))],
|
|
34
|
+
["/api/push-workflow", ({ id }) => syncWorkflow(root, id, "push")],
|
|
35
|
+
["/api/pull-workflow", ({ id }) => syncWorkflow(root, id, "pull")],
|
|
36
|
+
["/api/push-team", ({ id }) => syncTeam(root, id, "push")],
|
|
37
|
+
["/api/pull-team", ({ id }) => syncTeam(root, id, "pull")],
|
|
38
|
+
["/api/push-skill", ({ id }) => syncSkill(root, id, "push")],
|
|
39
|
+
["/api/pull-skill", ({ id }) => syncSkill(root, id, "pull")],
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
async function savedActionTargets(body) {
|
|
43
|
+
const { layout, revision } = await readLayout(root);
|
|
44
|
+
if (preview && body.revision !== revision) return null;
|
|
45
|
+
const button = layout.find(node => ["button", "agent-card"].includes(node.kind) && node.id === body.buttonId);
|
|
46
|
+
if (!button) throw new Error("Choose a run button from the app.");
|
|
47
|
+
validateRunBindings(layout, button);
|
|
48
|
+
return button.targets;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let running = false;
|
|
52
|
+
let writing = false;
|
|
53
|
+
const server = createServer(async (req, res) => {
|
|
54
|
+
const send = (status, data, type = "application/json") => {
|
|
55
|
+
res.writeHead(status, {
|
|
56
|
+
"Content-Type": type + "; charset=utf-8", "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff",
|
|
57
|
+
"Content-Security-Policy": "default-src 'none'; script-src 'self'; style-src 'self'; connect-src 'self'; frame-ancestors 'none'",
|
|
58
|
+
});
|
|
59
|
+
res.end(type === "application/json" ? JSON.stringify(data) : data);
|
|
60
|
+
};
|
|
61
|
+
const host = "127.0.0.1:" + server.address().port;
|
|
62
|
+
if (req.headers.host !== host) return send(403, { error: "Use the Studio loopback URL." });
|
|
63
|
+
if (req.method === "GET" && assets.has(req.url)) {
|
|
64
|
+
const [data, mime] = assets.get(req.url);
|
|
65
|
+
return send(200, data, mime);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (req.method === "GET" && req.url === "/api/project") {
|
|
69
|
+
const catalog = appCatalog ?? await readCatalog(root);
|
|
70
|
+
return send(200, {
|
|
71
|
+
...await readLayout(root),
|
|
72
|
+
exported: Boolean(appCatalog),
|
|
73
|
+
preview,
|
|
74
|
+
mode: appCatalog ? undefined : await readMode(root),
|
|
75
|
+
agents: [...catalog.agents.values()].map(({ id, name, source, framework }) => ({ id, name, source, framework })),
|
|
76
|
+
frameworkCandidates: appCatalog ? [] : await discoverFrameworkAgents(root).catch(() => []),
|
|
77
|
+
workflows: catalog.workflows.map(({ id, name, runnable, source }) => ({ id, name, runnable, source })),
|
|
78
|
+
skills: (catalog.skills ?? []).map(({ id, name, source }) => ({ id, name, source })),
|
|
79
|
+
teams: catalog.teams.map(({ id, name, source }) => ({ id, name, source })),
|
|
80
|
+
models: studioModels(),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const runRequest = req.url === "/api/run" || req.url === "/api/run-plan";
|
|
84
|
+
if (req.method !== "POST" || (!runRequest && (readOnly || !updates.has(req.url)))) {
|
|
85
|
+
return send(404, { error: "Not found." });
|
|
86
|
+
}
|
|
87
|
+
if (req.headers.origin !== "http://" + host) return send(403, { error: "Use the Studio page to submit requests." });
|
|
88
|
+
if (req.headers["content-type"]?.split(";")[0] !== "application/json") return send(415, { error: "Use application/json." });
|
|
89
|
+
const chunks = [];
|
|
90
|
+
let size = 0;
|
|
91
|
+
for await (const chunk of req) {
|
|
92
|
+
size += chunk.length;
|
|
93
|
+
if (size > 65_536) return send(413, { error: "Studio request is too large." });
|
|
94
|
+
chunks.push(chunk);
|
|
95
|
+
}
|
|
96
|
+
const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
97
|
+
if (runRequest && readOnly) {
|
|
98
|
+
body.targets = await savedActionTargets(body);
|
|
99
|
+
if (!body.targets) return send(409, { error: "The saved layout changed. Reload the preview before running." });
|
|
100
|
+
}
|
|
101
|
+
if (req.url === "/api/run-plan") {
|
|
102
|
+
return send(200, await describeRun(root, body.targets, appCatalog));
|
|
103
|
+
}
|
|
104
|
+
if (req.url === "/api/run") {
|
|
105
|
+
if (running) return send(409, { error: "A Studio run is already in progress." });
|
|
106
|
+
running = true;
|
|
107
|
+
try {
|
|
108
|
+
return send(200, await run(root, body, appCatalog));
|
|
109
|
+
} finally { running = false; }
|
|
110
|
+
}
|
|
111
|
+
if (writing) return send(409, { error: "Studio is already saving or pulling files." });
|
|
112
|
+
writing = true;
|
|
113
|
+
try {
|
|
114
|
+
return send(200, await updates.get(req.url)(body));
|
|
115
|
+
} finally { writing = false; }
|
|
116
|
+
} catch (error) {
|
|
117
|
+
const message = error.code ? "Studio could not read or write the project." : error.message;
|
|
118
|
+
return send(400, { error: message, ...(error.progress ? { progress: error.progress } : {}) });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
server.requestTimeout = 10_000;
|
|
123
|
+
await new Promise((resolve, reject) => {
|
|
124
|
+
server.once("error", reject);
|
|
125
|
+
server.listen(port, "127.0.0.1", resolve);
|
|
126
|
+
});
|
|
127
|
+
return { server, url: "http://127.0.0.1:" + server.address().port + "/" };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export async function runStudio(args, output = process.stdout) {
|
|
131
|
+
if (args[0] === "--help") {
|
|
132
|
+
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");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (args.length === 1 && args[0] === "pull") {
|
|
136
|
+
const { added, preserved } = await pullStudio(process.cwd());
|
|
137
|
+
output.write("Cloud pull: " + added + " added, " + preserved + " existing preserved.\n");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (args.length === 2 && args[0] === "push") {
|
|
141
|
+
const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
|
|
142
|
+
const result = await pushStudioAgent(process.cwd(), id);
|
|
143
|
+
output.write((result.created ? "Created " : "Synced ") + result.name + " in AgentLyra Cloud.\n");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (args.length === 2 && args[0] === "pull-agent") {
|
|
147
|
+
const id = args[1].startsWith("local:") ? args[1] : "local:" + args[1];
|
|
148
|
+
const result = await pullAgentEdits(process.cwd(), id);
|
|
149
|
+
output.write(result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (args.length === 2 && ["push-workflow", "pull-workflow", "push-team", "pull-team", "push-skill", "pull-skill"].includes(args[0])) {
|
|
153
|
+
const [action, resource] = args[0].split("-");
|
|
154
|
+
const push = action === "push";
|
|
155
|
+
const sync = { team: syncTeam, workflow: syncWorkflow, skill: syncSkill }[resource];
|
|
156
|
+
const result = await sync(process.cwd(), args[1], action);
|
|
157
|
+
output.write(push ? "Saved " + result.name + " in Cloud.\n"
|
|
158
|
+
: result.updated ? "Updated " + result.name + " from Cloud.\n" : "No Cloud edits to pull.\n");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (args.length) throw new Error("See agent-lyra studio --help.");
|
|
162
|
+
const { url } = await startStudio(process.cwd());
|
|
163
|
+
output.write("AgentLyra Studio: " + url + "\n");
|
|
164
|
+
}
|
package/src/studio/session.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { createInterface } from "node:readline/promises";
|
|
6
|
-
import { Writable } from "node:stream";
|
|
7
|
-
|
|
8
|
-
const validKey = key => typeof key === "string" && /^lyra_sdk_[a-f0-9]{64}$/.test(key);
|
|
9
|
-
const account = () => join(homedir(), ".agent-lyra");
|
|
10
|
-
const workspace = root => join(root, ".lyra");
|
|
11
|
-
|
|
12
|
-
async function readJson(path) {
|
|
13
|
-
try {
|
|
14
|
-
if (!(await lstat(path)).isFile()) throw new Error("Lyra settings must be a regular file.");
|
|
15
|
-
return JSON.parse((await readFile(path, "utf8")).replace(/^\uFEFF/, ""));
|
|
16
|
-
} catch (error) {
|
|
17
|
-
if (error.code === "ENOENT") return {};
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function saveJson(directory, name, data) {
|
|
23
|
-
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
24
|
-
if (!(await lstat(directory)).isDirectory()) throw new Error("Lyra settings must use a regular directory.");
|
|
25
|
-
const target = join(directory, name);
|
|
26
|
-
const temporary = target + "." + randomUUID() + ".tmp";
|
|
27
|
-
await writeFile(temporary, JSON.stringify(data, null, 2) + "\n", { flag: "wx", mode: 0o600 });
|
|
28
|
-
try {
|
|
29
|
-
await rename(temporary, target);
|
|
30
|
-
} finally {
|
|
31
|
-
await unlink(temporary).catch(() => {});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function readMode(root) {
|
|
36
|
-
const { mode } = await readJson(join(workspace(root), "session.json"));
|
|
37
|
-
return ["gated", "standalone"].includes(mode) ? mode : "automatic";
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function readSdkKey(root, { home = account() } = {}) {
|
|
41
|
-
const env = process.env.LYRA_API_KEY;
|
|
42
|
-
if (validKey(env)) return env;
|
|
43
|
-
const saved = (await readJson(join(home, "credentials.json"))).LYRA_API_KEY;
|
|
44
|
-
if (validKey(saved)) return saved;
|
|
45
|
-
const workspaceKey = (await readJson(join(workspace(root), "credentials.json"))).LYRA_API_KEY;
|
|
46
|
-
return validKey(workspaceKey) ? workspaceKey : undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function promptKey() {
|
|
50
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
51
|
-
throw new Error("Run this command in your IDE terminal to enter an AgentLyra API key, or supply LYRA_API_KEY in the environment.");
|
|
52
|
-
}
|
|
53
|
-
const silent = new Writable({ write(_chunk, _encoding, done) { done(); } });
|
|
54
|
-
const prompt = createInterface({ input: process.stdin, output: silent, terminal: true, historySize: 0 });
|
|
55
|
-
const cancel = new AbortController();
|
|
56
|
-
prompt.once("SIGINT", () => cancel.abort());
|
|
57
|
-
process.stdout.write("Paste your AgentLyra API key and press Enter (input hidden): ");
|
|
58
|
-
try {
|
|
59
|
-
return (await prompt.question("", { signal: cancel.signal })).trim();
|
|
60
|
-
} finally {
|
|
61
|
-
prompt.close();
|
|
62
|
-
process.stdout.write("\n");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function switchMode(root, mode, args, { output = process.stdout, prompt = promptKey, home = account() } = {}) {
|
|
67
|
-
const replace = mode === "gated" && args.length === 1 && args[0] === "--replace-key";
|
|
68
|
-
if (args.length && !replace) throw new Error("Usage: agent-lyra work-locally | agent-lyra connect-cloud [--replace-key]");
|
|
69
|
-
if (mode === "gated" && (replace || !(await readSdkKey(root, { home })))) {
|
|
70
|
-
output.write("Generate an AgentLyra API key at https://console.agentlyra.in/mcp-servers\n");
|
|
71
|
-
const key = await prompt();
|
|
72
|
-
if (!validKey(key)) throw new Error("Enter an AgentLyra API key beginning with lyra_sdk_.");
|
|
73
|
-
await saveJson(home, "credentials.json", { LYRA_API_KEY: key });
|
|
74
|
-
}
|
|
75
|
-
await saveJson(workspace(root), "session.json", { mode });
|
|
76
|
-
output.write(mode === "gated"
|
|
77
|
-
? "Connected to Cloud. Open Studio and choose Pull from Cloud.\n"
|
|
78
|
-
: "Working locally. Studio Cloud actions are paused.\n");
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function requireCloudMode(mode) {
|
|
82
|
-
if (mode === "standalone") throw new Error("You’re working locally. Run connect-cloud in your project terminal to use Cloud resources.");
|
|
83
|
-
}
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { Writable } from "node:stream";
|
|
7
|
+
|
|
8
|
+
const validKey = key => typeof key === "string" && /^lyra_sdk_[a-f0-9]{64}$/.test(key);
|
|
9
|
+
const account = () => join(homedir(), ".agent-lyra");
|
|
10
|
+
const workspace = root => join(root, ".lyra");
|
|
11
|
+
|
|
12
|
+
async function readJson(path) {
|
|
13
|
+
try {
|
|
14
|
+
if (!(await lstat(path)).isFile()) throw new Error("Lyra settings must be a regular file.");
|
|
15
|
+
return JSON.parse((await readFile(path, "utf8")).replace(/^\uFEFF/, ""));
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error.code === "ENOENT") return {};
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function saveJson(directory, name, data) {
|
|
23
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
24
|
+
if (!(await lstat(directory)).isDirectory()) throw new Error("Lyra settings must use a regular directory.");
|
|
25
|
+
const target = join(directory, name);
|
|
26
|
+
const temporary = target + "." + randomUUID() + ".tmp";
|
|
27
|
+
await writeFile(temporary, JSON.stringify(data, null, 2) + "\n", { flag: "wx", mode: 0o600 });
|
|
28
|
+
try {
|
|
29
|
+
await rename(temporary, target);
|
|
30
|
+
} finally {
|
|
31
|
+
await unlink(temporary).catch(() => {});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function readMode(root) {
|
|
36
|
+
const { mode } = await readJson(join(workspace(root), "session.json"));
|
|
37
|
+
return ["gated", "standalone"].includes(mode) ? mode : "automatic";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function readSdkKey(root, { home = account() } = {}) {
|
|
41
|
+
const env = process.env.LYRA_API_KEY;
|
|
42
|
+
if (validKey(env)) return env;
|
|
43
|
+
const saved = (await readJson(join(home, "credentials.json"))).LYRA_API_KEY;
|
|
44
|
+
if (validKey(saved)) return saved;
|
|
45
|
+
const workspaceKey = (await readJson(join(workspace(root), "credentials.json"))).LYRA_API_KEY;
|
|
46
|
+
return validKey(workspaceKey) ? workspaceKey : undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function promptKey() {
|
|
50
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
51
|
+
throw new Error("Run this command in your IDE terminal to enter an AgentLyra API key, or supply LYRA_API_KEY in the environment.");
|
|
52
|
+
}
|
|
53
|
+
const silent = new Writable({ write(_chunk, _encoding, done) { done(); } });
|
|
54
|
+
const prompt = createInterface({ input: process.stdin, output: silent, terminal: true, historySize: 0 });
|
|
55
|
+
const cancel = new AbortController();
|
|
56
|
+
prompt.once("SIGINT", () => cancel.abort());
|
|
57
|
+
process.stdout.write("Paste your AgentLyra API key and press Enter (input hidden): ");
|
|
58
|
+
try {
|
|
59
|
+
return (await prompt.question("", { signal: cancel.signal })).trim();
|
|
60
|
+
} finally {
|
|
61
|
+
prompt.close();
|
|
62
|
+
process.stdout.write("\n");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function switchMode(root, mode, args, { output = process.stdout, prompt = promptKey, home = account() } = {}) {
|
|
67
|
+
const replace = mode === "gated" && args.length === 1 && args[0] === "--replace-key";
|
|
68
|
+
if (args.length && !replace) throw new Error("Usage: agent-lyra work-locally | agent-lyra connect-cloud [--replace-key]");
|
|
69
|
+
if (mode === "gated" && (replace || !(await readSdkKey(root, { home })))) {
|
|
70
|
+
output.write("Generate an AgentLyra API key at https://console.agentlyra.in/mcp-servers\n");
|
|
71
|
+
const key = await prompt();
|
|
72
|
+
if (!validKey(key)) throw new Error("Enter an AgentLyra API key beginning with lyra_sdk_.");
|
|
73
|
+
await saveJson(home, "credentials.json", { LYRA_API_KEY: key });
|
|
74
|
+
}
|
|
75
|
+
await saveJson(workspace(root), "session.json", { mode });
|
|
76
|
+
output.write(mode === "gated"
|
|
77
|
+
? "Connected to Cloud. Open Studio and choose Pull from Cloud.\n"
|
|
78
|
+
: "Working locally. Studio Cloud actions are paused.\n");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function requireCloudMode(mode) {
|
|
82
|
+
if (mode === "standalone") throw new Error("You’re working locally. Run connect-cloud in your project terminal to use Cloud resources.");
|
|
83
|
+
}
|