agent-lyra 0.6.0 → 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.
Files changed (38) hide show
  1. package/README.md +395 -173
  2. package/bin/agent-lyra.js +16 -3
  3. package/package.json +60 -56
  4. package/src/app-builder/export.js +109 -109
  5. package/src/app-builder/init.js +52 -52
  6. package/src/app-builder/preview.js +22 -22
  7. package/src/app-builder/saved-app.js +70 -70
  8. package/src/app-builder/saved-preview-browser.js +33 -33
  9. package/src/app-builder/saved-preview.html +24 -24
  10. package/src/app-builder/saved-preview.js +61 -61
  11. package/src/app-builder/validate.js +64 -64
  12. package/src/memory/cli.js +49 -0
  13. package/src/memory/contract.json +28 -0
  14. package/src/memory/index.d.ts +49 -0
  15. package/src/memory/index.js +259 -0
  16. package/src/memory/lifecycle.js +29 -0
  17. package/src/memory/proposals.js +84 -0
  18. package/src/memory/skills-cli.js +26 -0
  19. package/src/memory/sync.js +85 -0
  20. package/src/memory/validation.js +25 -0
  21. package/src/runtime/local-cli.js +2 -1
  22. package/src/studio/agent-ui.css +43 -43
  23. package/src/studio/agent-ui.js +32 -32
  24. package/src/studio/browser.js +331 -289
  25. package/src/studio/export.js +80 -79
  26. package/src/studio/index.html +37 -16
  27. package/src/studio/memory-actions.js +37 -0
  28. package/src/studio/memory-panel.js +200 -0
  29. package/src/studio/project.js +197 -190
  30. package/src/studio/pull-agent.js +72 -0
  31. package/src/studio/push.js +54 -0
  32. package/src/studio/python-agent.js +47 -47
  33. package/src/studio/python-agent.py +25 -25
  34. package/src/studio/server.js +143 -102
  35. package/src/studio/session.js +83 -0
  36. package/src/studio/studio.css +10 -7
  37. package/src/studio/sync.js +42 -39
  38. package/src/studio/workflow-sync.js +157 -0
package/package.json CHANGED
@@ -1,56 +1,60 @@
1
- {
2
- "name": "agent-lyra",
3
- "version": "0.6.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
- "./standalone": {
26
- "types": "./src/standalone/index.d.ts",
27
- "default": "./src/standalone/index.js"
28
- },
29
- "./gated": {
30
- "types": "./src/gated/index.d.ts",
31
- "default": "./src/gated/index.js"
32
- }
33
- },
34
- "files": [
35
- "bin",
36
- "src",
37
- "README.md",
38
- "LICENSE"
39
- ],
40
- "sideEffects": false,
41
- "scripts": {
42
- "test": "node --test"
43
- },
44
- "keywords": [
45
- "lyra",
46
- "orchestration",
47
- "rag",
48
- "agents",
49
- "sdk"
50
- ],
51
- "author": "",
52
- "license": "MIT",
53
- "publishConfig": {
54
- "access": "public"
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,109 +1,109 @@
1
- import { mkdir, readFile, writeFile } from "node:fs/promises";
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";
5
- import { readSupportManifest } from "./support-manifest.js";
6
-
7
- const assets = {
8
- "runtime/app-builder/support-template/support-preview.mjs": "./support-template/support-preview.mjs",
9
- "runtime/app-builder/support-template/support-preview.html": "./support-template/support-preview.html",
10
- "runtime/app-builder/support-template/support-preview.js": "./support-template/support-preview.js",
11
- "runtime/app-builder/support-template/support-workflow.mjs": "./support-template/support-workflow.mjs",
12
- "runtime/app-builder/gateway.js": "./gateway.js",
13
- "runtime/app-builder/validate.js": "./validate.js",
14
- "runtime/app-builder/saved-app.js": "./saved-app.js",
15
- "runtime/app-builder/value-schema.js": "./value-schema.js",
16
- "runtime/app-builder/native-adapter.js": "./native-adapter.js",
17
- "runtime/runtime/run-agent.js": "../runtime/run-agent.js",
18
- LICENSE: "../../LICENSE",
19
- };
20
-
21
- export async function runAppExport(args, output = process.stdout) {
22
- if (args.length === 1 && args[0] === "--help") {
23
- output.write("Usage: agent-lyra app export <manifest.json> <new-directory>\n");
24
- return;
25
- }
26
- if (args.length !== 2 || args.some((arg) => arg.startsWith("-"))) {
27
- throw new Error("Provide a manifest and new output directory. See agent-lyra app export --help.");
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
- }
41
- const manifest = await readSupportManifest(args[0]);
42
- const directory = resolve(args[1]);
43
- const files = await Promise.all(Object.entries(assets).map(async ([name, sourcePath]) =>
44
- [name, await readFile(new URL(sourcePath, import.meta.url))]));
45
- const manifestReader = 'const manifest = JSON.parse(await readFile(new URL("./example-manifest.json", import.meta.url), "utf8"));\n';
46
- files.push(["example-manifest.json", JSON.stringify(manifest, null, 2) + "\n"]);
47
- files.push(["support-preview.mjs",
48
- 'import { readFile } from "node:fs/promises";\n' +
49
- 'import { startSupportPreview } from "./runtime/app-builder/support-template/support-preview.mjs";\n' +
50
- manifestReader + "await startSupportPreview(manifest);\n"]);
51
- files.push(["support-example.mjs",
52
- 'import { readFile } from "node:fs/promises";\n' +
53
- 'import { createSupportWorkflow } from "./runtime/app-builder/support-template/support-workflow.mjs";\n' +
54
- manifestReader +
55
- 'console.log(JSON.stringify(await createSupportWorkflow(manifest)(process.argv[2] ?? "Invoice question"), null, 2));\n']);
56
- files.push(["package.json", JSON.stringify({
57
- name: manifest.application.id, version: "1.0.0", private: true, type: "module",
58
- engines: { node: ">=22.13.0" },
59
- scripts: { start: "node support-preview.mjs", demo: "node support-example.mjs" },
60
- }, null, 2) + "\n"]);
61
- files.push(["README.md", "# Support app\n\nRun `npm start` and open http://127.0.0.1:4173/. Run `npm run demo` for the terminal workflow.\n\nThe bundled classifier and provider are deterministic. The app binds to loopback and does not persist or send tickets.\n"]);
62
- try {
63
- await mkdir(directory);
64
- } catch (error) {
65
- if (error.code === "EEXIST") throw new Error("Choose a new directory. Existing files were preserved.");
66
- throw error;
67
- }
68
- for (const [name, contents] of files) {
69
- const target = join(directory, name);
70
- await mkdir(dirname(target), { recursive: true });
71
- await writeFile(target, contents, { flag: "wx" });
72
- }
73
- output.write(`Exported ${manifest.application.id} to ${directory}\n`);
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
- }
1
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
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";
5
+ import { readSupportManifest } from "./support-manifest.js";
6
+
7
+ const assets = {
8
+ "runtime/app-builder/support-template/support-preview.mjs": "./support-template/support-preview.mjs",
9
+ "runtime/app-builder/support-template/support-preview.html": "./support-template/support-preview.html",
10
+ "runtime/app-builder/support-template/support-preview.js": "./support-template/support-preview.js",
11
+ "runtime/app-builder/support-template/support-workflow.mjs": "./support-template/support-workflow.mjs",
12
+ "runtime/app-builder/gateway.js": "./gateway.js",
13
+ "runtime/app-builder/validate.js": "./validate.js",
14
+ "runtime/app-builder/saved-app.js": "./saved-app.js",
15
+ "runtime/app-builder/value-schema.js": "./value-schema.js",
16
+ "runtime/app-builder/native-adapter.js": "./native-adapter.js",
17
+ "runtime/runtime/run-agent.js": "../runtime/run-agent.js",
18
+ LICENSE: "../../LICENSE",
19
+ };
20
+
21
+ export async function runAppExport(args, output = process.stdout) {
22
+ if (args.length === 1 && args[0] === "--help") {
23
+ output.write("Usage: agent-lyra app export <manifest.json> <new-directory>\n");
24
+ return;
25
+ }
26
+ if (args.length !== 2 || args.some((arg) => arg.startsWith("-"))) {
27
+ throw new Error("Provide a manifest and new output directory. See agent-lyra app export --help.");
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
+ }
41
+ const manifest = await readSupportManifest(args[0]);
42
+ const directory = resolve(args[1]);
43
+ const files = await Promise.all(Object.entries(assets).map(async ([name, sourcePath]) =>
44
+ [name, await readFile(new URL(sourcePath, import.meta.url))]));
45
+ const manifestReader = 'const manifest = JSON.parse(await readFile(new URL("./example-manifest.json", import.meta.url), "utf8"));\n';
46
+ files.push(["example-manifest.json", JSON.stringify(manifest, null, 2) + "\n"]);
47
+ files.push(["support-preview.mjs",
48
+ 'import { readFile } from "node:fs/promises";\n' +
49
+ 'import { startSupportPreview } from "./runtime/app-builder/support-template/support-preview.mjs";\n' +
50
+ manifestReader + "await startSupportPreview(manifest);\n"]);
51
+ files.push(["support-example.mjs",
52
+ 'import { readFile } from "node:fs/promises";\n' +
53
+ 'import { createSupportWorkflow } from "./runtime/app-builder/support-template/support-workflow.mjs";\n' +
54
+ manifestReader +
55
+ 'console.log(JSON.stringify(await createSupportWorkflow(manifest)(process.argv[2] ?? "Invoice question"), null, 2));\n']);
56
+ files.push(["package.json", JSON.stringify({
57
+ name: manifest.application.id, version: "1.0.0", private: true, type: "module",
58
+ engines: { node: ">=22.13.0" },
59
+ scripts: { start: "node support-preview.mjs", demo: "node support-example.mjs" },
60
+ }, null, 2) + "\n"]);
61
+ files.push(["README.md", "# Support app\n\nRun `npm start` and open http://127.0.0.1:4173/. Run `npm run demo` for the terminal workflow.\n\nThe bundled classifier and provider are deterministic. The app binds to loopback and does not persist or send tickets.\n"]);
62
+ try {
63
+ await mkdir(directory);
64
+ } catch (error) {
65
+ if (error.code === "EEXIST") throw new Error("Choose a new directory. Existing files were preserved.");
66
+ throw error;
67
+ }
68
+ for (const [name, contents] of files) {
69
+ const target = join(directory, name);
70
+ await mkdir(dirname(target), { recursive: true });
71
+ await writeFile(target, contents, { flag: "wx" });
72
+ }
73
+ output.write(`Exported ${manifest.application.id} to ${directory}\n`);
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
+ }
@@ -1,52 +1,52 @@
1
- import { access, mkdir, writeFile } from "node:fs/promises";
2
- import { dirname, resolve } from "node:path";
3
- import { createInterface } from "node:readline/promises";
4
- import { createSavedAgentClient, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
5
-
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
- } = {}) {
13
- if (args.length === 1 && args[0] === "--help") {
14
- output.write("Usage: agent-lyra app init [manifest.json]\nSelect two saved agents. Requires LYRA_API_KEY. Default: manifest.json\n");
15
- return;
16
- }
17
- if (args.length > 1 || args[0]?.startsWith("-")) {
18
- throw new Error("Provide at most one manifest path. See agent-lyra app init --help.");
19
- }
20
- const target = resolve(args[0] ?? "manifest.json");
21
- try {
22
- await access(target);
23
- throw new Error("Manifest already exists at " + target + ". Choose a new path.");
24
- } catch (error) {
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();
51
- }
52
- }
1
+ import { access, mkdir, writeFile } from "node:fs/promises";
2
+ import { dirname, resolve } from "node:path";
3
+ import { createInterface } from "node:readline/promises";
4
+ import { createSavedAgentClient, SAVED_VERSION, validateSavedApp } from "./saved-app.js";
5
+
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
+ } = {}) {
13
+ if (args.length === 1 && args[0] === "--help") {
14
+ output.write("Usage: agent-lyra app init [manifest.json]\nSelect two saved agents. Requires LYRA_API_KEY. Default: manifest.json\n");
15
+ return;
16
+ }
17
+ if (args.length > 1 || args[0]?.startsWith("-")) {
18
+ throw new Error("Provide at most one manifest path. See agent-lyra app init --help.");
19
+ }
20
+ const target = resolve(args[0] ?? "manifest.json");
21
+ try {
22
+ await access(target);
23
+ throw new Error("Manifest already exists at " + target + ". Choose a new path.");
24
+ } catch (error) {
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();
51
+ }
52
+ }
@@ -1,22 +1,22 @@
1
- import { readAppManifest, SAVED_VERSION } from "./saved-app.js";
2
- import { startSavedPreview } from "./saved-preview.js";
3
- import { readSupportManifest } from "./support-manifest.js";
4
- import { startSupportPreview } from "./support-template/support-preview.mjs";
5
-
6
- export async function runAppPreview(args, output = process.stdout) {
7
- if (args.length === 1 && args[0] === "--help") {
8
- output.write("Usage: agent-lyra app preview <manifest.json>\nSet LYRA_PREVIEW_PORT to override the loopback port.\n");
9
- return;
10
- }
11
- if (args.length !== 1 || args[0].startsWith("-")) {
12
- throw new Error("Provide a manifest path. See agent-lyra app preview --help.");
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
- }
20
- const manifest = await readSupportManifest(args[0]);
21
- await startSupportPreview(manifest);
22
- }
1
+ import { readAppManifest, SAVED_VERSION } from "./saved-app.js";
2
+ import { startSavedPreview } from "./saved-preview.js";
3
+ import { readSupportManifest } from "./support-manifest.js";
4
+ import { startSupportPreview } from "./support-template/support-preview.mjs";
5
+
6
+ export async function runAppPreview(args, output = process.stdout) {
7
+ if (args.length === 1 && args[0] === "--help") {
8
+ output.write("Usage: agent-lyra app preview <manifest.json>\nSet LYRA_PREVIEW_PORT to override the loopback port.\n");
9
+ return;
10
+ }
11
+ if (args.length !== 1 || args[0].startsWith("-")) {
12
+ throw new Error("Provide a manifest path. See agent-lyra app preview --help.");
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
+ }
20
+ const manifest = await readSupportManifest(args[0]);
21
+ await startSupportPreview(manifest);
22
+ }
@@ -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
+ }