agent-lyra 0.3.2 → 0.6.1
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 +394 -119
- package/bin/agent-lyra.js +16 -0
- package/package.json +60 -56
- package/src/app-builder/export.js +50 -0
- package/src/app-builder/init.js +40 -11
- package/src/app-builder/preview.js +8 -0
- package/src/app-builder/saved-app.js +70 -0
- package/src/app-builder/saved-preview-browser.js +33 -0
- package/src/app-builder/saved-preview.html +24 -0
- package/src/app-builder/saved-preview.js +61 -0
- package/src/app-builder/validate.js +6 -7
- package/src/memory/cli.js +49 -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/proposals.js +84 -0
- package/src/memory/skills-cli.js +26 -0
- package/src/memory/sync.js +85 -0
- package/src/memory/validation.js +25 -0
- package/src/runtime/local-cli.js +4 -3
- package/src/studio/agent-ui.css +43 -0
- package/src/studio/agent-ui.js +32 -0
- package/src/studio/browser.js +331 -0
- package/src/studio/export.js +80 -0
- package/src/studio/index.html +37 -0
- package/src/studio/memory-actions.js +37 -0
- package/src/studio/memory-panel.js +200 -0
- package/src/studio/project.js +197 -0
- package/src/studio/pull-agent.js +72 -0
- package/src/studio/push.js +54 -0
- package/src/studio/python-agent.js +47 -0
- package/src/studio/python-agent.py +25 -0
- package/src/studio/server.js +143 -0
- package/src/studio/session.js +83 -0
- package/src/studio/studio.css +10 -0
- package/src/studio/sync.js +42 -0
- package/src/studio/workflow-sync.js +157 -0
package/package.json
CHANGED
|
@@ -1,56 +1,60 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "agent-lyra",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Two-layer Lyra SDK with standalone local primitives and gated hosted agents.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./src/index.js",
|
|
7
|
-
"types": "./src/index.d.ts",
|
|
8
|
-
"engines": {
|
|
9
|
-
"node": ">=22.13.0"
|
|
10
|
-
},
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+https://gitlab.com/vibified/agent-lyra.git",
|
|
14
|
-
"directory": "packages/lyra"
|
|
15
|
-
},
|
|
16
|
-
"homepage": "https://agentlyra.in",
|
|
17
|
-
"bin": {
|
|
18
|
-
"agent-lyra": "./bin/agent-lyra.js"
|
|
19
|
-
},
|
|
20
|
-
"exports": {
|
|
21
|
-
".": {
|
|
22
|
-
"types": "./src/index.d.ts",
|
|
23
|
-
"default": "./src/index.js"
|
|
24
|
-
},
|
|
25
|
-
"./
|
|
26
|
-
"types": "./src/
|
|
27
|
-
"default": "./src/
|
|
28
|
-
},
|
|
29
|
-
"./
|
|
30
|
-
"types": "./src/
|
|
31
|
-
"default": "./src/
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "agent-lyra",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "Two-layer Lyra SDK with standalone local primitives and gated hosted agents.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22.13.0"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://gitlab.com/vibified/agent-lyra.git",
|
|
14
|
+
"directory": "packages/lyra"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://agentlyra.in",
|
|
17
|
+
"bin": {
|
|
18
|
+
"agent-lyra": "./bin/agent-lyra.js"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
23
|
+
"default": "./src/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./memory": {
|
|
26
|
+
"types": "./src/memory/index.d.ts",
|
|
27
|
+
"default": "./src/memory/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./standalone": {
|
|
30
|
+
"types": "./src/standalone/index.d.ts",
|
|
31
|
+
"default": "./src/standalone/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./gated": {
|
|
34
|
+
"types": "./src/gated/index.d.ts",
|
|
35
|
+
"default": "./src/gated/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"bin",
|
|
40
|
+
"src",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"scripts": {
|
|
46
|
+
"test": "node --test"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"lyra",
|
|
50
|
+
"orchestration",
|
|
51
|
+
"rag",
|
|
52
|
+
"agents",
|
|
53
|
+
"sdk"
|
|
54
|
+
],
|
|
55
|
+
"author": "",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { readAppManifest, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
|
|
4
|
+
import { exportStudioApp } from "../studio/export.js";
|
|
3
5
|
import { readSupportManifest } from "./support-manifest.js";
|
|
4
6
|
|
|
5
7
|
const assets = {
|
|
@@ -9,6 +11,7 @@ const assets = {
|
|
|
9
11
|
"runtime/app-builder/support-template/support-workflow.mjs": "./support-template/support-workflow.mjs",
|
|
10
12
|
"runtime/app-builder/gateway.js": "./gateway.js",
|
|
11
13
|
"runtime/app-builder/validate.js": "./validate.js",
|
|
14
|
+
"runtime/app-builder/saved-app.js": "./saved-app.js",
|
|
12
15
|
"runtime/app-builder/value-schema.js": "./value-schema.js",
|
|
13
16
|
"runtime/app-builder/native-adapter.js": "./native-adapter.js",
|
|
14
17
|
"runtime/runtime/run-agent.js": "../runtime/run-agent.js",
|
|
@@ -23,6 +26,18 @@ export async function runAppExport(args, output = process.stdout) {
|
|
|
23
26
|
if (args.length !== 2 || args.some((arg) => arg.startsWith("-"))) {
|
|
24
27
|
throw new Error("Provide a manifest and new output directory. See agent-lyra app export --help.");
|
|
25
28
|
}
|
|
29
|
+
const app = await readAppManifest(args[0]);
|
|
30
|
+
if (Array.isArray(app?.studio?.layout)) {
|
|
31
|
+
const directory = resolve(args[1]);
|
|
32
|
+
await exportStudioApp(app, dirname(resolve(args[0])), directory);
|
|
33
|
+
output.write("Exported Studio app to " + directory + "\n");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (app?.version === SAVED_VERSION) {
|
|
37
|
+
await exportSavedApp(validateSavedApp(app), resolve(args[1]));
|
|
38
|
+
output.write("Exported " + app.application.id + " to " + resolve(args[1]) + "\n");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
26
41
|
const manifest = await readSupportManifest(args[0]);
|
|
27
42
|
const directory = resolve(args[1]);
|
|
28
43
|
const files = await Promise.all(Object.entries(assets).map(async ([name, sourcePath]) =>
|
|
@@ -57,3 +72,38 @@ export async function runAppExport(args, output = process.stdout) {
|
|
|
57
72
|
}
|
|
58
73
|
output.write(`Exported ${manifest.application.id} to ${directory}\n`);
|
|
59
74
|
}
|
|
75
|
+
|
|
76
|
+
async function exportSavedApp(manifest, directory) {
|
|
77
|
+
const runtime = ["saved-app.js", "saved-preview.js", "saved-preview-browser.js", "saved-preview.html"];
|
|
78
|
+
const files = await Promise.all(runtime.map(async name => [
|
|
79
|
+
name, await readFile(new URL("./" + name, import.meta.url)),
|
|
80
|
+
]));
|
|
81
|
+
const project = {
|
|
82
|
+
name: manifest.application.id, version: "1.0.0", private: true, type: "module",
|
|
83
|
+
engines: { node: ">=22.13.0" }, scripts: { start: "node server.js" },
|
|
84
|
+
};
|
|
85
|
+
const safeManifest = {
|
|
86
|
+
version: SAVED_VERSION,
|
|
87
|
+
application: { id: manifest.application.id, name: manifest.application.name },
|
|
88
|
+
workflow: { steps: manifest.workflow.steps.map(({ agentId }) => ({ agentId })) },
|
|
89
|
+
};
|
|
90
|
+
files.push(["package.json", JSON.stringify(project, null, 2) + "\n"]);
|
|
91
|
+
files.push(["manifest.json", JSON.stringify(safeManifest, null, 2) + "\n"]);
|
|
92
|
+
files.push(["server.js",
|
|
93
|
+
'import { readAppManifest } from "./saved-app.js";\n' +
|
|
94
|
+
'import { startSavedPreview } from "./saved-preview.js";\n' +
|
|
95
|
+
'const { url } = await startSavedPreview(await readAppManifest(new URL("./manifest.json", import.meta.url)));\n' +
|
|
96
|
+
'console.log("App preview: " + url);\n']);
|
|
97
|
+
files.push(["README.md", "# Run this Lyra app\n\nSet LYRA_API_KEY to your AgentLyra SDK key, then run npm start. Open the loopback URL. Your selected agents run in AgentLyra Cloud. Set LYRA_PREVIEW_PORT=0 to pick a free port. The local server does not provide authentication for public hosting.\n"]);
|
|
98
|
+
files.push(["LICENSE", await readFile(new URL("../../LICENSE", import.meta.url))]);
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
await mkdir(directory);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error.code === "EEXIST") throw new Error("Choose a new directory. Existing files were preserved.");
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
for (const [name, contents] of files) {
|
|
107
|
+
await writeFile(join(directory, name), contents, { flag: "wx" });
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/app-builder/init.js
CHANGED
|
@@ -1,23 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { access, mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { createInterface } from "node:readline/promises";
|
|
4
|
+
import { createSavedAgentClient, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
|
|
3
5
|
|
|
4
|
-
export async function runAppInit(args, output = process.stdout
|
|
6
|
+
export async function runAppInit(args, output = process.stdout, {
|
|
7
|
+
openTerminal = () => createInterface({ input: process.stdin, output }),
|
|
8
|
+
listAgents = async () => {
|
|
9
|
+
if (!process.stdin.isTTY) throw new Error("Run app init from an interactive terminal to choose your agents.");
|
|
10
|
+
return createSavedAgentClient().list();
|
|
11
|
+
},
|
|
12
|
+
} = {}) {
|
|
5
13
|
if (args.length === 1 && args[0] === "--help") {
|
|
6
|
-
output.write("Usage: agent-lyra app init [manifest.json]\
|
|
14
|
+
output.write("Usage: agent-lyra app init [manifest.json]\nSelect two saved agents. Requires LYRA_API_KEY. Default: manifest.json\n");
|
|
7
15
|
return;
|
|
8
16
|
}
|
|
9
17
|
if (args.length > 1 || args[0]?.startsWith("-")) {
|
|
10
18
|
throw new Error("Provide at most one manifest path. See agent-lyra app init --help.");
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
const target = resolve(args[0] ?? ".lyra/app/manifest.json");
|
|
14
|
-
const template = await readFile(new URL("./support-template/manifest.json", import.meta.url));
|
|
15
|
-
await mkdir(dirname(target), { recursive: true });
|
|
20
|
+
const target = resolve(args[0] ?? "manifest.json");
|
|
16
21
|
try {
|
|
17
|
-
await
|
|
22
|
+
await access(target);
|
|
23
|
+
throw new Error("Manifest already exists at " + target + ". Choose a new path.");
|
|
18
24
|
} catch (error) {
|
|
19
|
-
if (error.code
|
|
20
|
-
|
|
25
|
+
if (error.code !== "ENOENT") throw error;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const agents = await listAgents();
|
|
29
|
+
if (agents.length < 2) throw new Error("Create at least two enabled agents in AgentLyra Console first.");
|
|
30
|
+
for (const [index, agent] of agents.entries()) {
|
|
31
|
+
const name = String(agent.name).replace(/[\x00-\x1f\x7f]/g, " ");
|
|
32
|
+
output.write((index + 1) + ". " + name + "\n");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const terminal = openTerminal();
|
|
36
|
+
try {
|
|
37
|
+
const name = (await terminal.question("Application name: ")).trim();
|
|
38
|
+
const first = agents[Number(await terminal.question("First agent number: ")) - 1];
|
|
39
|
+
const second = agents[Number(await terminal.question("Second agent number: ")) - 1];
|
|
40
|
+
const id = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
41
|
+
const manifest = validateSavedApp({
|
|
42
|
+
version: SAVED_VERSION,
|
|
43
|
+
application: { id: id && /^[a-z]/.test(id) ? id.slice(0, 80) : "lyra-app", name },
|
|
44
|
+
workflow: { steps: [{ agentId: first?.id }, { agentId: second?.id }] },
|
|
45
|
+
});
|
|
46
|
+
await mkdir(dirname(target), { recursive: true });
|
|
47
|
+
await writeFile(target, JSON.stringify(manifest, null, 2) + "\n", { flag: "wx" });
|
|
48
|
+
output.write("Created " + target + "\n");
|
|
49
|
+
} finally {
|
|
50
|
+
terminal.close();
|
|
21
51
|
}
|
|
22
|
-
output.write(`Created ${target}\n`);
|
|
23
52
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { readAppManifest, SAVED_VERSION } from "./saved-app.js";
|
|
2
|
+
import { startSavedPreview } from "./saved-preview.js";
|
|
1
3
|
import { readSupportManifest } from "./support-manifest.js";
|
|
2
4
|
import { startSupportPreview } from "./support-template/support-preview.mjs";
|
|
3
5
|
|
|
@@ -9,6 +11,12 @@ export async function runAppPreview(args, output = process.stdout) {
|
|
|
9
11
|
if (args.length !== 1 || args[0].startsWith("-")) {
|
|
10
12
|
throw new Error("Provide a manifest path. See agent-lyra app preview --help.");
|
|
11
13
|
}
|
|
14
|
+
const app = await readAppManifest(args[0]);
|
|
15
|
+
if (app?.version === SAVED_VERSION) {
|
|
16
|
+
const { url } = await startSavedPreview(app);
|
|
17
|
+
output.write("App preview: " + url + "\n");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
12
20
|
const manifest = await readSupportManifest(args[0]);
|
|
13
21
|
await startSupportPreview(manifest);
|
|
14
22
|
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +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
|
+
});
|
|
@@ -0,0 +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>
|
|
@@ -0,0 +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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readAppManifest, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
|
|
2
2
|
import { assertValueSchema } from "./value-schema.js";
|
|
3
3
|
|
|
4
4
|
const modes = new Set(["in-process", "local-process", "remote"]);
|
|
@@ -53,12 +53,11 @@ export async function runAppValidation(args, output = process.stdout) {
|
|
|
53
53
|
if (args.length !== 1 || args[0].startsWith("-")) {
|
|
54
54
|
throw new Error("Provide a manifest path. See agent-lyra app validate --help.");
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
throw new Error("Application manifest is not valid JSON.");
|
|
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;
|
|
62
61
|
}
|
|
63
62
|
const { id, capabilityCount, actionCount } = validateAppManifest(manifest);
|
|
64
63
|
output.write(`Valid app ${id} (${capabilityCount} capabilities, ${actionCount} actions).\n`);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { syncMemory } from "./sync.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { openMemoryStore } from "./index.js";
|
|
4
|
+
|
|
5
|
+
export async function runMemory(args, output = process.stdout) {
|
|
6
|
+
const [action, value, flag] = args;
|
|
7
|
+
if (action === "cloud") return runCloudMemory(args.slice(1), output);
|
|
8
|
+
if (!action || action === "--help") {
|
|
9
|
+
output.write("Usage: agent-lyra memory init | record <json-file> | list | search <query> | inspect <id> | verify <id> <evidence.json> | archive <id> | consolidate <context> | stats | forget <id> --yes | cloud --help\n");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const bare = ["init", "list", "stats"].includes(action) && args.length === 1;
|
|
13
|
+
const withValue = ["record", "search", "inspect", "archive", "consolidate"].includes(action) && args.length === 2 && value;
|
|
14
|
+
if (!bare && !withValue && !(action === "verify" && args.length === 3 && value && flag) && !(action === "forget" && args.length === 3 && flag === "--yes" && value)) {
|
|
15
|
+
throw new Error("See agent-lyra memory --help. Forget requires --yes.");
|
|
16
|
+
}
|
|
17
|
+
const store = await openMemoryStore();
|
|
18
|
+
try {
|
|
19
|
+
let result;
|
|
20
|
+
switch (action) {
|
|
21
|
+
case "init": result = { database: store.file, ...store.stats() }; break;
|
|
22
|
+
case "record": result = store.record(JSON.parse((await readFile(value, "utf8")).replace(/^\uFEFF/, ""))); break;
|
|
23
|
+
case "list": result = store.list(); break;
|
|
24
|
+
case "search": result = store.search(value); break;
|
|
25
|
+
case "inspect": result = store.get(value); break;
|
|
26
|
+
case "verify": result = store.verify(value, JSON.parse((await readFile(flag, "utf8")).replace(/^\uFEFF/, ""))); break;
|
|
27
|
+
case "consolidate": result = store.consolidate(value); break;
|
|
28
|
+
case "archive": result = store.archive(value); break;
|
|
29
|
+
case "stats": result = store.stats(); break;
|
|
30
|
+
case "forget": result = store.forget(value) ? { deleted: value } : null; break;
|
|
31
|
+
}
|
|
32
|
+
if (result === null) throw new Error("Memory record was not found.");
|
|
33
|
+
output.write(JSON.stringify(result, null, 2) + "\n");
|
|
34
|
+
} finally { store.close(); }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function runCloudMemory(args, output) {
|
|
38
|
+
const [action, id, flag] = args;
|
|
39
|
+
if (!action || action === "--help") {
|
|
40
|
+
output.write("Usage: agent-lyra memory cloud list [cursor] | preview <id> | push <id> --yes | pull <id>\n");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const valid = (action === "list" && args.length <= 2) ||
|
|
44
|
+
(["preview", "pull"].includes(action) && args.length === 2) ||
|
|
45
|
+
(action === "push" && args.length === 3 && flag === "--yes");
|
|
46
|
+
if (!valid) throw new Error("See agent-lyra memory cloud --help.");
|
|
47
|
+
const result = await syncMemory(process.cwd(), action, id, { confirmed: flag === "--yes" });
|
|
48
|
+
output.write(JSON.stringify(result, null, 2) + "\n");
|
|
49
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 4,
|
|
3
|
+
"applicationId": 1279873601,
|
|
4
|
+
"types": [
|
|
5
|
+
"episodic",
|
|
6
|
+
"semantic",
|
|
7
|
+
"procedural",
|
|
8
|
+
"corrective"
|
|
9
|
+
],
|
|
10
|
+
"statuses": [
|
|
11
|
+
"candidate",
|
|
12
|
+
"verified",
|
|
13
|
+
"archived"
|
|
14
|
+
],
|
|
15
|
+
"limits": {
|
|
16
|
+
"records": 5000,
|
|
17
|
+
"results": 100,
|
|
18
|
+
"title": 160,
|
|
19
|
+
"learning": 4000,
|
|
20
|
+
"evidence": 16,
|
|
21
|
+
"id": 128
|
|
22
|
+
},
|
|
23
|
+
"adapters": {"coding":{"types":["corrective"],"prefix":"test:","check":"test","error":"Verification requires a linked passing coding test, a compatibility context, and explicit review."},"practice":{"types":["corrective","procedural"],"prefix":"exercise:","check":"exercise","error":"Verification requires a linked passing practice exercise, a compatibility context, and explicit review."}},
|
|
24
|
+
"migration4": "CREATE TABLE memory_cloud_links (id TEXT PRIMARY KEY, cloud_revision INTEGER NOT NULL, local_revision INTEGER NOT NULL, cloud_account TEXT NOT NULL);",
|
|
25
|
+
"migration3": "CREATE TABLE skill_proposals (id TEXT PRIMARY KEY, context TEXT NOT NULL, title TEXT NOT NULL, markdown TEXT NOT NULL, sources TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending','approved','rejected','withdrawn')), created_at TEXT NOT NULL, decided_at TEXT, receipt TEXT);",
|
|
26
|
+
"migration2": "ALTER TABLE memories ADD COLUMN verification TEXT; CREATE INDEX memories_verified ON memories(status, updated_at);",
|
|
27
|
+
"migration": "CREATE TABLE memories (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n title TEXT NOT NULL,\n learning TEXT NOT NULL,\n evidence TEXT NOT NULL,\n scope TEXT NOT NULL DEFAULT 'project' CHECK (scope = 'project'),\n status TEXT NOT NULL DEFAULT 'candidate',\n revision INTEGER NOT NULL DEFAULT 1,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL\n);\nCREATE TABLE memory_tombstones (id TEXT PRIMARY KEY, revision INTEGER NOT NULL, deleted_at TEXT NOT NULL);\nCREATE TABLE memory_index_state (id INTEGER PRIMARY KEY CHECK (id = 1), revision INTEGER NOT NULL, indexed_revision INTEGER NOT NULL);\nINSERT INTO memory_index_state VALUES (1, 0, -1);\nCREATE INDEX memories_status_updated ON memories (status, updated_at DESC);"
|
|
28
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type MemoryType = "episodic" | "semantic" | "procedural" | "corrective";
|
|
2
|
+
export type MemoryStatus = "candidate" | "verified" | "archived";
|
|
3
|
+
export interface MemoryInput { type: MemoryType; title: string; learning: string; evidence?: string[] }
|
|
4
|
+
export type MemoryAdapter = "coding" | "practice";
|
|
5
|
+
export type VerificationReceipt = { evidenceId: string; context: string } & (
|
|
6
|
+
{ adapter: "coding"; test: string } | { adapter: "practice"; exercise: string }
|
|
7
|
+
);
|
|
8
|
+
export interface MemoryRecord extends MemoryInput {
|
|
9
|
+
id: string;
|
|
10
|
+
evidence: string[];
|
|
11
|
+
scope: "project";
|
|
12
|
+
status: MemoryStatus;
|
|
13
|
+
revision: number;
|
|
14
|
+
createdAt: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
verification?: VerificationReceipt;
|
|
17
|
+
}
|
|
18
|
+
export interface SkillProposalSource { id: string; revision: number; evidenceId: string }
|
|
19
|
+
export interface SkillProposalReceipt { evidenceId: string; context: string; result: "passed"; reviewed: true }
|
|
20
|
+
export interface SkillProposal {
|
|
21
|
+
id: string;
|
|
22
|
+
context: string;
|
|
23
|
+
title: string;
|
|
24
|
+
markdown: string;
|
|
25
|
+
sources: SkillProposalSource[];
|
|
26
|
+
status: "pending" | "approved" | "rejected" | "withdrawn";
|
|
27
|
+
createdAt: string;
|
|
28
|
+
decidedAt: string | null;
|
|
29
|
+
receipt: SkillProposalReceipt | null;
|
|
30
|
+
}
|
|
31
|
+
export interface MemoryStore {
|
|
32
|
+
readonly file: string;
|
|
33
|
+
consolidate(context: string): Array<{ title: string; learning: string; sources: SkillProposalSource[] }>;
|
|
34
|
+
propose(context: string, memoryId: string): SkillProposal;
|
|
35
|
+
proposal(id: string): SkillProposal | null;
|
|
36
|
+
proposals(): SkillProposal[];
|
|
37
|
+
decideProposal(id: string, decision: "approved" | "rejected" | "withdrawn", evidence?: SkillProposalReceipt): SkillProposal;
|
|
38
|
+
close(): void;
|
|
39
|
+
get(id: string): MemoryRecord | null;
|
|
40
|
+
list(limit?: number): MemoryRecord[];
|
|
41
|
+
record(value: MemoryInput): MemoryRecord;
|
|
42
|
+
search(query: string, limit?: number): MemoryRecord[];
|
|
43
|
+
stats(): { schemaVersion: number; search: "fts5" | "keyword" } & Record<MemoryStatus, number>;
|
|
44
|
+
verify(id: string, evidence: VerificationReceipt & { result: "passed"; reviewed: true }): MemoryRecord;
|
|
45
|
+
retrieve(query: string, context: string, adapter?: MemoryAdapter): MemoryRecord[];
|
|
46
|
+
archive(id: string): MemoryRecord | null;
|
|
47
|
+
forget(id: string): boolean;
|
|
48
|
+
}
|
|
49
|
+
export function openMemoryStore(root?: string, options?: { forceKeyword?: boolean }): Promise<MemoryStore>;
|