agent-lyra 0.6.1 → 0.6.3

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 (108) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +435 -395
  3. package/bin/agent-lyra.js +49 -44
  4. package/bin/lyra-oss-preview.js +16 -0
  5. package/package.json +60 -60
  6. package/src/app-builder/export.js +109 -109
  7. package/src/app-builder/gateway.js +62 -62
  8. package/src/app-builder/init.js +52 -52
  9. package/src/app-builder/manifest-contract.js +46 -0
  10. package/src/app-builder/native-adapter.js +29 -29
  11. package/src/app-builder/preview.js +22 -22
  12. package/src/app-builder/publish.js +14 -14
  13. package/src/app-builder/saved-app.js +70 -70
  14. package/src/app-builder/saved-preview-browser.js +33 -33
  15. package/src/app-builder/saved-preview.html +24 -24
  16. package/src/app-builder/saved-preview.js +61 -61
  17. package/src/app-builder/support-manifest.js +50 -50
  18. package/src/app-builder/support-template/manifest.json +55 -55
  19. package/src/app-builder/support-template/support-preview.html +56 -56
  20. package/src/app-builder/support-template/support-preview.js +37 -37
  21. package/src/app-builder/support-template/support-preview.mjs +67 -67
  22. package/src/app-builder/support-template/support-workflow.mjs +36 -36
  23. package/src/app-builder/use.js +37 -37
  24. package/src/app-builder/validate.js +21 -64
  25. package/src/app-builder/value-schema.js +37 -37
  26. package/src/catalog.js +147 -147
  27. package/src/coding/catalog.js +56 -0
  28. package/src/coding/cloud-catalog.js +64 -0
  29. package/src/coding/detect-stack.mjs +110 -0
  30. package/src/coding/export.js +130 -0
  31. package/src/coding/setup.js +175 -0
  32. package/src/coding/skills/lyra-android/SKILL.md +37 -0
  33. package/src/coding/skills/lyra-angular/SKILL.md +37 -0
  34. package/src/coding/skills/lyra-cucumber/SKILL.md +37 -0
  35. package/src/coding/skills/lyra-dbt/SKILL.md +37 -0
  36. package/src/coding/skills/lyra-django/SKILL.md +37 -0
  37. package/src/coding/skills/lyra-docker/SKILL.md +37 -0
  38. package/src/coding/skills/lyra-dotnet/SKILL.md +37 -0
  39. package/src/coding/skills/lyra-express/SKILL.md +37 -0
  40. package/src/coding/skills/lyra-fastapi/SKILL.md +37 -0
  41. package/src/coding/skills/lyra-flutter/SKILL.md +37 -0
  42. package/src/coding/skills/lyra-github-actions/SKILL.md +37 -0
  43. package/src/coding/skills/lyra-gitlab-ci/SKILL.md +37 -0
  44. package/src/coding/skills/lyra-go/SKILL.md +37 -0
  45. package/src/coding/skills/lyra-ios/SKILL.md +37 -0
  46. package/src/coding/skills/lyra-kubernetes/SKILL.md +37 -0
  47. package/src/coding/skills/lyra-mongodb/SKILL.md +37 -0
  48. package/src/coding/skills/lyra-mysql/SKILL.md +37 -0
  49. package/src/coding/skills/lyra-nextjs/SKILL.md +37 -0
  50. package/src/coding/skills/lyra-node/SKILL.md +37 -0
  51. package/src/coding/skills/lyra-playwright/SKILL.md +37 -0
  52. package/src/coding/skills/lyra-postgresql/SKILL.md +37 -0
  53. package/src/coding/skills/lyra-python/SKILL.md +37 -0
  54. package/src/coding/skills/lyra-react/SKILL.md +37 -0
  55. package/src/coding/skills/lyra-react-native/SKILL.md +37 -0
  56. package/src/coding/skills/lyra-redis/SKILL.md +37 -0
  57. package/src/coding/skills/lyra-rust/SKILL.md +37 -0
  58. package/src/coding/skills/lyra-spark/SKILL.md +37 -0
  59. package/src/coding/skills/lyra-spring-boot/SKILL.md +37 -0
  60. package/src/coding/skills/lyra-svelte/SKILL.md +37 -0
  61. package/src/coding/skills/lyra-terraform/SKILL.md +37 -0
  62. package/src/coding/skills/lyra-typescript/SKILL.md +37 -0
  63. package/src/coding/skills/lyra-vue/SKILL.md +37 -0
  64. package/src/gated/hostedAgents.js +56 -56
  65. package/src/gated/index.d.ts +25 -25
  66. package/src/gated/index.js +5 -5
  67. package/src/index.d.ts +2 -2
  68. package/src/index.js +2 -2
  69. package/src/init.js +965 -937
  70. package/src/memory/cli.js +21 -49
  71. package/src/memory/contract.json +28 -28
  72. package/src/memory/index.d.ts +49 -49
  73. package/src/memory/index.js +259 -259
  74. package/src/memory/lifecycle.js +29 -29
  75. package/src/memory/local-cli.js +34 -0
  76. package/src/memory/proposals.js +84 -84
  77. package/src/memory/skills-cli.js +26 -26
  78. package/src/memory/sync.js +89 -85
  79. package/src/memory/validation.js +25 -25
  80. package/src/onboardingAgents.js +532 -532
  81. package/src/promptTemplates.js +178 -178
  82. package/src/runtime/contracts.d.ts +47 -47
  83. package/src/runtime/local-cli.js +160 -160
  84. package/src/runtime/mcp-stdio.js +111 -111
  85. package/src/runtime/orchestration.js +59 -59
  86. package/src/runtime/run-agent.js +43 -43
  87. package/src/standalone/index.d.ts +45 -45
  88. package/src/standalone/index.js +13 -13
  89. package/src/standalone/init.js +12 -0
  90. package/src/standalone/orchestration.js +6 -6
  91. package/src/standalone/rag.js +113 -113
  92. package/src/studio/agent-ui.css +43 -43
  93. package/src/studio/agent-ui.js +32 -32
  94. package/src/studio/browser.js +331 -331
  95. package/src/studio/export.js +80 -80
  96. package/src/studio/index.html +37 -37
  97. package/src/studio/memory-actions.js +37 -37
  98. package/src/studio/memory-panel.js +200 -200
  99. package/src/studio/project.js +216 -197
  100. package/src/studio/pull-agent.js +72 -72
  101. package/src/studio/push.js +54 -54
  102. package/src/studio/python-agent.js +47 -47
  103. package/src/studio/python-agent.py +25 -25
  104. package/src/studio/server.js +143 -143
  105. package/src/studio/session.js +83 -83
  106. package/src/studio/studio.css +10 -10
  107. package/src/studio/sync.js +42 -42
  108. package/src/studio/workflow-sync.js +157 -157
@@ -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
+ }
@@ -0,0 +1,46 @@
1
+ import { assertValueSchema } from "./value-schema.js";
2
+
3
+ const modes = new Set(["in-process", "local-process", "remote"]);
4
+ const identifier = /^[a-z][a-z0-9-]*$/;
5
+ const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
6
+ const isIdentifier = (value) => typeof value === "string" && identifier.test(value);
7
+
8
+ export function validateAppManifest(manifest) {
9
+ if (!isRecord(manifest) || manifest.version !== "1.0") {
10
+ throw new Error('Application manifest requires version "1.0".');
11
+ }
12
+ const { application, capabilities, actions } = manifest;
13
+ if (!isRecord(application) || !isIdentifier(application.id) ||
14
+ typeof application.name !== "string" || !application.name.trim()) {
15
+ throw new Error("Application requires a valid id and a name.");
16
+ }
17
+ if (!Array.isArray(capabilities) || !Array.isArray(actions)) {
18
+ throw new Error("Capabilities and actions must be arrays.");
19
+ }
20
+
21
+ const capabilityIds = new Set();
22
+ for (const capability of capabilities) {
23
+ if (!isRecord(capability) || !isIdentifier(capability.id) || !isIdentifier(capability.adapterId) ||
24
+ !modes.has(capability.executionMode)) {
25
+ throw new Error("Each capability requires an id, adapterId, and supported executionMode.");
26
+ }
27
+ if (capabilityIds.has(capability.id)) throw new Error(`Duplicate capability: ${capability.id}.`);
28
+ for (const key of ["inputSchema", "outputSchema"]) {
29
+ if (Object.hasOwn(capability, key)) assertValueSchema(capability[key], `${capability.id} ${key}`);
30
+ }
31
+ capabilityIds.add(capability.id);
32
+ }
33
+ const actionIds = new Set();
34
+ for (const action of actions) {
35
+ if (!isRecord(action) || !isIdentifier(action.id) || !isIdentifier(action.capabilityId)) {
36
+ throw new Error("Each action requires an id and capabilityId.");
37
+ }
38
+ if (actionIds.has(action.id)) throw new Error(`Duplicate action: ${action.id}.`);
39
+ if (!capabilityIds.has(action.capabilityId)) {
40
+ throw new Error(`Action ${action.id} refers to unknown capability ${action.capabilityId}.`);
41
+ }
42
+ actionIds.add(action.id);
43
+ }
44
+ return { id: application.id, capabilityCount: capabilityIds.size, actionCount: actionIds.size };
45
+ }
46
+
@@ -1,29 +1,29 @@
1
- import { runAgent } from "../runtime/run-agent.js";
2
- import { capabilityContractVersion } from "./gateway.js";
3
-
4
- export function createNativeAdapter({ agents, provider, store }) {
5
- const configured = new Map(agents);
6
- return {
7
- id: "native",
8
- contractVersion: capabilityContractVersion,
9
- async invoke({ capabilityId, input }) {
10
- const agent = configured.get(capabilityId);
11
- if (!agent || typeof input !== "string" || !input.trim()) return { status: "failed" };
12
- const event = await runAgent({
13
- agentId: capabilityId,
14
- request: {
15
- model: agent.model,
16
- messages: [
17
- ...(agent.system ? [{ role: "system", content: agent.system }] : []),
18
- { role: "user", content: input },
19
- ],
20
- },
21
- provider,
22
- store,
23
- });
24
- if (event.type === "run.failed") return { status: "failed", nativeExecutionId: event.run_id };
25
- const { text, usage } = event.data.result;
26
- return { status: "completed", nativeExecutionId: event.run_id, output: text, ...(usage && { usage }) };
27
- },
28
- };
29
- }
1
+ import { runAgent } from "../runtime/run-agent.js";
2
+ import { capabilityContractVersion } from "./gateway.js";
3
+
4
+ export function createNativeAdapter({ agents, provider, store }) {
5
+ const configured = new Map(agents);
6
+ return {
7
+ id: "native",
8
+ contractVersion: capabilityContractVersion,
9
+ async invoke({ capabilityId, input }) {
10
+ const agent = configured.get(capabilityId);
11
+ if (!agent || typeof input !== "string" || !input.trim()) return { status: "failed" };
12
+ const event = await runAgent({
13
+ agentId: capabilityId,
14
+ request: {
15
+ model: agent.model,
16
+ messages: [
17
+ ...(agent.system ? [{ role: "system", content: agent.system }] : []),
18
+ { role: "user", content: input },
19
+ ],
20
+ },
21
+ provider,
22
+ store,
23
+ });
24
+ if (event.type === "run.failed") return { status: "failed", nativeExecutionId: event.run_id };
25
+ const { text, usage } = event.data.result;
26
+ return { status: "completed", nativeExecutionId: event.run_id, output: text, ...(usage && { usage }) };
27
+ },
28
+ };
29
+ }
@@ -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,14 +1,14 @@
1
- import { readSupportManifest } from "./support-manifest.js";
2
-
3
- export async function runAppPublish(args, output = process.stdout) {
4
- if (args.length === 1 && args[0] === "--help") {
5
- output.write("Usage: agent-lyra app publish <manifest.json> --dry-run\n");
6
- return;
7
- }
8
- if (args.length !== 2 || args[0].startsWith("-") || args[1] !== "--dry-run") {
9
- throw new Error("Only offline listing previews are supported. Pass <manifest.json> --dry-run.");
10
- }
11
- const manifest = await readSupportManifest(args[0]);
12
- const listing = { listingSchemaVersion: "1.0", manifest };
13
- output.write(`${JSON.stringify(listing, null, 2)}\n`);
14
- }
1
+ import { readSupportManifest } from "./support-manifest.js";
2
+
3
+ export async function runAppPublish(args, output = process.stdout) {
4
+ if (args.length === 1 && args[0] === "--help") {
5
+ output.write("Usage: agent-lyra app publish <manifest.json> --dry-run\n");
6
+ return;
7
+ }
8
+ if (args.length !== 2 || args[0].startsWith("-") || args[1] !== "--dry-run") {
9
+ throw new Error("Only offline listing previews are supported. Pass <manifest.json> --dry-run.");
10
+ }
11
+ const manifest = await readSupportManifest(args[0]);
12
+ const listing = { listingSchemaVersion: "1.0", manifest };
13
+ output.write(`${JSON.stringify(listing, null, 2)}\n`);
14
+ }
@@ -1,70 +1,70 @@
1
- import { readFile } from "node:fs/promises";
2
-
3
- export const SAVED_VERSION = "2.0";
4
- const idPattern = /^[a-f0-9]{24}$/i;
5
- const appIdPattern = /^[a-z][a-z0-9-]{0,79}$/;
6
-
7
- export function validateSavedApp(manifest) {
8
- if (manifest?.version !== SAVED_VERSION || !appIdPattern.test(manifest.application?.id ?? "") ||
9
- typeof manifest.application.name !== "string" || !manifest.application.name.trim() ||
10
- manifest.application.name.length > 120) {
11
- throw new Error('Version "2.0" requires an application ID and name.');
12
- }
13
- const { steps } = manifest.workflow ?? {};
14
- if (!Array.isArray(steps) || steps.length !== 2 ||
15
- !steps.every(step => typeof step?.agentId === "string" && idPattern.test(step.agentId)) ||
16
- steps[0].agentId.toLowerCase() === steps[1].agentId.toLowerCase()) {
17
- throw new Error("A workflow requires two distinct saved Lyra agent IDs.");
18
- }
19
- return manifest;
20
- }
21
-
22
- export async function readAppManifest(path) {
23
- const source = await readFile(path, "utf8");
24
- try {
25
- return JSON.parse(source.replace(/^\uFEFF/, ""));
26
- } catch {
27
- throw new Error("Application manifest is not valid JSON.");
28
- }
29
- }
30
-
31
- export function createSavedAgentClient({ key = process.env.LYRA_API_KEY, fetchRequest = fetch } = {}) {
32
- if (!/^lyra_sdk_[a-f0-9]{64}$/.test(key ?? "")) {
33
- throw new Error("Set LYRA_API_KEY to a dedicated SDK key from AgentLyra Console.");
34
- }
35
-
36
- async function request(path, prompt) {
37
- const response = await fetchRequest("https://api.agentlyra.in/api/sdk/v1/saved-agents" + path, {
38
- method: prompt === undefined ? "GET" : "POST",
39
- headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
40
- body: prompt === undefined ? undefined : JSON.stringify({ prompt }),
41
- redirect: "error",
42
- signal: AbortSignal.timeout(65_000),
43
- });
44
- if (!response.ok) {
45
- if (response.status === 401) throw new Error("The SDK key is invalid or revoked.");
46
- if (response.status === 403) throw new Error("Add your OpenAI key in AgentLyra Console → Models.");
47
- if (response.status === 404) throw new Error("A selected agent is unavailable to this SDK key.");
48
- throw new Error("AgentLyra Cloud request failed (HTTP " + response.status + ").");
49
- }
50
- return response.json();
51
- }
52
-
53
- return {
54
- list: async () => (await request("")).agents,
55
- invoke: async (id, prompt) => (await request("/" + encodeURIComponent(id) + "/invoke", prompt)).output,
56
- };
57
- }
58
-
59
- export async function runSavedApp(manifest, input, client = createSavedAgentClient()) {
60
- const [first, second] = validateSavedApp(manifest).workflow.steps;
61
- if (typeof input !== "string" || !input.trim() || input.length > 4000) {
62
- throw new Error("Enter between 1 and 4,000 characters.");
63
- }
64
- const firstOutput = await client.invoke(first.agentId, input.trim());
65
- const output = await client.invoke(second.agentId, JSON.stringify({
66
- input: input.trim(),
67
- previousAgentOutput: firstOutput,
68
- }).slice(0, 12_000));
69
- return { firstOutput, output };
70
- }
1
+ import { readFile } from "node:fs/promises";
2
+
3
+ export const SAVED_VERSION = "2.0";
4
+ const idPattern = /^[a-f0-9]{24}$/i;
5
+ const appIdPattern = /^[a-z][a-z0-9-]{0,79}$/;
6
+
7
+ export function validateSavedApp(manifest) {
8
+ if (manifest?.version !== SAVED_VERSION || !appIdPattern.test(manifest.application?.id ?? "") ||
9
+ typeof manifest.application.name !== "string" || !manifest.application.name.trim() ||
10
+ manifest.application.name.length > 120) {
11
+ throw new Error('Version "2.0" requires an application ID and name.');
12
+ }
13
+ const { steps } = manifest.workflow ?? {};
14
+ if (!Array.isArray(steps) || steps.length !== 2 ||
15
+ !steps.every(step => typeof step?.agentId === "string" && idPattern.test(step.agentId)) ||
16
+ steps[0].agentId.toLowerCase() === steps[1].agentId.toLowerCase()) {
17
+ throw new Error("A workflow requires two distinct saved Lyra agent IDs.");
18
+ }
19
+ return manifest;
20
+ }
21
+
22
+ export async function readAppManifest(path) {
23
+ const source = await readFile(path, "utf8");
24
+ try {
25
+ return JSON.parse(source.replace(/^\uFEFF/, ""));
26
+ } catch {
27
+ throw new Error("Application manifest is not valid JSON.");
28
+ }
29
+ }
30
+
31
+ export function createSavedAgentClient({ key = process.env.LYRA_API_KEY, fetchRequest = fetch } = {}) {
32
+ if (!/^lyra_sdk_[a-f0-9]{64}$/.test(key ?? "")) {
33
+ throw new Error("Set LYRA_API_KEY to a dedicated SDK key from AgentLyra Console.");
34
+ }
35
+
36
+ async function request(path, prompt) {
37
+ const response = await fetchRequest("https://api.agentlyra.in/api/sdk/v1/saved-agents" + path, {
38
+ method: prompt === undefined ? "GET" : "POST",
39
+ headers: { Authorization: "Bearer " + key, "Content-Type": "application/json" },
40
+ body: prompt === undefined ? undefined : JSON.stringify({ prompt }),
41
+ redirect: "error",
42
+ signal: AbortSignal.timeout(65_000),
43
+ });
44
+ if (!response.ok) {
45
+ if (response.status === 401) throw new Error("The SDK key is invalid or revoked.");
46
+ if (response.status === 403) throw new Error("Add your OpenAI key in AgentLyra Console → Models.");
47
+ if (response.status === 404) throw new Error("A selected agent is unavailable to this SDK key.");
48
+ throw new Error("AgentLyra Cloud request failed (HTTP " + response.status + ").");
49
+ }
50
+ return response.json();
51
+ }
52
+
53
+ return {
54
+ list: async () => (await request("")).agents,
55
+ invoke: async (id, prompt) => (await request("/" + encodeURIComponent(id) + "/invoke", prompt)).output,
56
+ };
57
+ }
58
+
59
+ export async function runSavedApp(manifest, input, client = createSavedAgentClient()) {
60
+ const [first, second] = validateSavedApp(manifest).workflow.steps;
61
+ if (typeof input !== "string" || !input.trim() || input.length > 4000) {
62
+ throw new Error("Enter between 1 and 4,000 characters.");
63
+ }
64
+ const firstOutput = await client.invoke(first.agentId, input.trim());
65
+ const output = await client.invoke(second.agentId, JSON.stringify({
66
+ input: input.trim(),
67
+ previousAgentOutput: firstOutput,
68
+ }).slice(0, 12_000));
69
+ return { firstOutput, output };
70
+ }
@@ -1,33 +1,33 @@
1
- const form = document.querySelector("form");
2
- const button = form.querySelector("button");
3
- const status = document.querySelector("#status");
4
- const result = document.querySelector("#result");
5
-
6
- fetch("/api/app").then(response => response.json()).then(({ name }) => {
7
- document.title = name;
8
- document.querySelector("h1").textContent = name;
9
- }).catch(() => { status.textContent = "Could not load application details."; });
10
-
11
- form.addEventListener("submit", async event => {
12
- event.preventDefault();
13
- button.disabled = true;
14
- result.hidden = true;
15
- status.textContent = "Running both agents…";
16
- try {
17
- const response = await fetch("/api/run", {
18
- method: "POST",
19
- headers: { "Content-Type": "application/json" },
20
- body: JSON.stringify({ input: document.querySelector("#input").value }),
21
- });
22
- const data = await response.json();
23
- if (!response.ok) throw new Error(data.error);
24
- document.querySelector("#output").textContent = data.output;
25
- document.querySelector("#first").textContent = data.firstOutput;
26
- result.hidden = false;
27
- status.textContent = "Workflow completed.";
28
- } catch (error) {
29
- status.textContent = error.message;
30
- } finally {
31
- button.disabled = false;
32
- }
33
- });
1
+ const form = document.querySelector("form");
2
+ const button = form.querySelector("button");
3
+ const status = document.querySelector("#status");
4
+ const result = document.querySelector("#result");
5
+
6
+ fetch("/api/app").then(response => response.json()).then(({ name }) => {
7
+ document.title = name;
8
+ document.querySelector("h1").textContent = name;
9
+ }).catch(() => { status.textContent = "Could not load application details."; });
10
+
11
+ form.addEventListener("submit", async event => {
12
+ event.preventDefault();
13
+ button.disabled = true;
14
+ result.hidden = true;
15
+ status.textContent = "Running both agents…";
16
+ try {
17
+ const response = await fetch("/api/run", {
18
+ method: "POST",
19
+ headers: { "Content-Type": "application/json" },
20
+ body: JSON.stringify({ input: document.querySelector("#input").value }),
21
+ });
22
+ const data = await response.json();
23
+ if (!response.ok) throw new Error(data.error);
24
+ document.querySelector("#output").textContent = data.output;
25
+ document.querySelector("#first").textContent = data.firstOutput;
26
+ result.hidden = false;
27
+ status.textContent = "Workflow completed.";
28
+ } catch (error) {
29
+ status.textContent = error.message;
30
+ } finally {
31
+ button.disabled = false;
32
+ }
33
+ });
@@ -1,24 +1,24 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Lyra application</title>
7
- <style>
8
- body { background:#f6f9f7;color:#152c23;font:1rem/1.6 system-ui,sans-serif;margin:0 }
9
- main { max-width:50rem;margin:4rem auto;padding:0 1.25rem }
10
- label,textarea,button { display:block;font:inherit }
11
- textarea { box-sizing:border-box;width:100%;min-height:8rem;margin:.45rem 0 1rem;padding:.75rem;border:1px solid #8ea99c;border-radius:.5rem }
12
- button { background:#174b38;color:white;border:0;border-radius:.5rem;padding:.6rem 1rem;cursor:pointer }
13
- button:disabled { opacity:.65;cursor:wait }
14
- pre { white-space:pre-wrap;overflow-wrap:anywhere;background:white;padding:1rem;border:1px solid #cfddd5;border-radius:.5rem;font:inherit }
15
- </style>
16
- <script src="/preview.js" defer></script>
17
- </head>
18
- <body><main>
19
- <h1>Lyra application</h1>
20
- <form><label for="input">Workflow input</label><textarea id="input" required maxlength="4000"></textarea><button>Run workflow</button></form>
21
- <p role="status" id="status"></p>
22
- <section hidden id="result"><h2>Final result</h2><pre id="output"></pre><details><summary>First agent output</summary><pre id="first"></pre></details></section>
23
- </main></body>
24
- </html>
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Lyra application</title>
7
+ <style>
8
+ body { background:#f6f9f7;color:#152c23;font:1rem/1.6 system-ui,sans-serif;margin:0 }
9
+ main { max-width:50rem;margin:4rem auto;padding:0 1.25rem }
10
+ label,textarea,button { display:block;font:inherit }
11
+ textarea { box-sizing:border-box;width:100%;min-height:8rem;margin:.45rem 0 1rem;padding:.75rem;border:1px solid #8ea99c;border-radius:.5rem }
12
+ button { background:#174b38;color:white;border:0;border-radius:.5rem;padding:.6rem 1rem;cursor:pointer }
13
+ button:disabled { opacity:.65;cursor:wait }
14
+ pre { white-space:pre-wrap;overflow-wrap:anywhere;background:white;padding:1rem;border:1px solid #cfddd5;border-radius:.5rem;font:inherit }
15
+ </style>
16
+ <script src="/preview.js" defer></script>
17
+ </head>
18
+ <body><main>
19
+ <h1>Lyra application</h1>
20
+ <form><label for="input">Workflow input</label><textarea id="input" required maxlength="4000"></textarea><button>Run workflow</button></form>
21
+ <p role="status" id="status"></p>
22
+ <section hidden id="result"><h2>Final result</h2><pre id="output"></pre><details><summary>First agent output</summary><pre id="first"></pre></details></section>
23
+ </main></body>
24
+ </html>