agent-lyra 0.3.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,160 +1,173 @@
1
- # agent-lyra
1
+ # AgentLyra SDK
2
2
 
3
- ## Local-first release
3
+ Build apps from your saved Lyra agents, run agents with your own OpenAI key, and inspect saved runs from your IDE. The Node.js package includes a command-line tool and typed JavaScript APIs for composing workflows.
4
4
 
5
- The supported release path is local. It includes the Node CLI, SQLite run history, the draft-review team, and read-only IDE MCP. OpenAI-backed runs use your own key. The legacy gated client expects a compatible hosted `/agents/<vertical>/invoke` endpoint. The bundled hosted default has not been verified against AgentLyra production, so hosted invocation is outside this release’s supported scope.
5
+ [AgentLyra homepage](https://agentlyra.in/) · [CLI reference](https://agentlyra.in/#sdk-commands) · [Cloud console](https://console.agentlyra.in/)
6
6
 
7
- ## CLI reference
7
+ ## Choose an SDK mode
8
8
 
9
- Use Node.js 22.13 or newer. Run these commands from your project after installing `agent-lyra`. Angle brackets mark required arguments. Square brackets mark optional arguments.
9
+ | Mode | Where work runs | What you need |
10
+ | --- | --- | --- |
11
+ | **Standalone** | In your own Node.js process. Use `agent-lyra/standalone` for local workflows and retrieval, or run your own local workflows. | No AgentLyra account or key. Model-backed CLI runs use your own OpenAI key. |
12
+ | **Gated** | On a compatible hosted backend. `agent-lyra/gated` calls the backend's `/agents/<vertical>/invoke` endpoint. | A Lyra API key for that backend and its base URL. For AgentLyra Cloud, use a dedicated SDK key and the base URL https://api.agentlyra.in/api/sdk/v1. Cloud SDK calls also require an OpenAI key in Models settings. |
10
13
 
11
- ### Project setup
14
+ The App Builder below uses a dedicated SDK key to run saved agents in AgentLyra Cloud. Standalone workflows remain available through the SDK and CLI.
12
15
 
13
- | Command | What it does |
14
- | --- | --- |
15
- | `npx agent-lyra init [options]` | Scaffold a `.lyra` workspace and starter agents. Options include `--mode`, `--domains`, `--api-key`, `--api-base-url`, `--dir`, and `--force`. |
16
- | `npx agent-lyra --help` | Show the init command and its options. The help alias does the same. Add `--help` to a specific command for its syntax. |
16
+ ## Install
17
17
 
18
- ### App Builder
18
+ Requires **Node.js 22.13 or newer**. From your project directory:
19
19
 
20
- | Command | What it does |
21
- | --- | --- |
22
- | `npx agent-lyra app init [manifest.json]` | Create the Support IQ starter. Defaults to `.lyra/app/manifest.json`. |
23
- | `npx agent-lyra app validate <manifest.json>` | Check the app manifest before previewing or exporting. |
24
- | `npx agent-lyra app preview <manifest.json>` | Run the starter preview on loopback. Set `LYRA_PREVIEW_PORT` to change its port. |
25
- | `npx agent-lyra app export <manifest.json> <new-directory>` | Export the supported starter into a new directory. |
26
- | `npx agent-lyra app publish <manifest.json> --dry-run` | Print the proposed Marketplace payload for review. Submit the listing in the cloud. |
27
- | `npx agent-lyra app use <listing-id> [new-manifest.json]` | Import a published app and save its manifest. Requires `LYRA_SESSION_TOKEN`. |
20
+ ```bash
21
+ npm install agent-lyra
22
+ ```
28
23
 
29
- ### Agent runs and IDE integration
24
+ Use `pnpm add agent-lyra` if your project uses pnpm. Run the CLI with `npx agent-lyra` after installation.
30
25
 
31
- | Command | What it does |
32
- | --- | --- |
33
- | `npx agent-lyra agent run --model <model> --prompt <text>` | Run a local agent with an OpenAI model. Requires `OPENAI_API_KEY`. |
34
- | `npx agent-lyra team run draft-review --model <model> --prompt <text>` | Run the built-in writer and reviewer team. Requires `OPENAI_API_KEY`. |
35
- | `npx agent-lyra run status <run-id>` | Read the latest event for a run from local SQLite history. |
36
- | `npx agent-lyra mcp serve --dir <absolute-project-directory>` | Expose saved runs to an IDE over read-only stdio MCP. |
26
+ ## Build an app from your Lyra agents
37
27
 
38
- ## Build a support app
28
+ Create two enabled text agents in AgentLyra Console. In [API key settings](https://console.agentlyra.in/settings/lyra-api-key), choose **Generate SDK key** and set it as `LYRA_API_KEY` in your terminal environment. Add your own OpenAI key in Console → Models. Keep both keys out of source control.
39
29
 
40
30
  ```bash
41
31
  npx agent-lyra app init
42
- npx agent-lyra app validate .lyra/app/manifest.json
43
- npx agent-lyra app preview .lyra/app/manifest.json
44
- npx agent-lyra app export .lyra/app/manifest.json ./my-support-app
32
+ npx agent-lyra app validate manifest.json
33
+ npx agent-lyra app preview manifest.json
45
34
  ```
46
35
 
47
- Run each command separately. Stop the preview before exporting from the same terminal. The starter supports the local Support IQ template without cloud authentication. Use `app publish <manifest.json> --dry-run` to review a listing payload offline. `app use <listing-id>` imports a published app using an existing cloud session supplied through `LYRA_SESSION_TOKEN`. The cloud Marketplace also lets signed-in users save a private copy and download its manifest.
48
-
49
- ## Run a local agent
36
+ Choose the agents in the order they should run. The CLI creates one `manifest.json` in your project. Open the URL printed by the preview and enter some text. The first agent runs on that input, then the second receives the input and first result. The browser shows both outputs. This version runs each saved agent's instructions as text-only; connected tools and skills are outside this workflow.
50
37
 
51
- With Node.js 22.13 or newer, set `OPENAI_API_KEY` in your terminal environment, then run these commands from your project:
38
+ Stop the preview or open a new terminal, then export into a new folder:
52
39
 
53
40
  ```bash
54
- npx agent-lyra agent run --model YOUR_MODEL --prompt "Summarize this idea"
55
- npx agent-lyra run status YOUR_RUN_ID
41
+ npx agent-lyra app export manifest.json ./my-app
42
+ cd my-app
43
+ npm start
56
44
  ```
57
45
 
58
- The first command sends your prompt to OpenAI using your key and prints a run ID. The second reads the most recent event from `.lyra/state/runs.sqlite`, including the generated output on success. Keep that directory local if the output is sensitive. The run requires no Lyra account. The existing `init` wizard remains available for scaffolding.
46
+ The export contains editable HTML, a Node.js server, the runtime, and the app manifest. Keep `LYRA_API_KEY` in the server environment. The exported server binds to loopback and the two agents continue to run in Cloud.
47
+
48
+ ## Choose the workflow you need
49
+
50
+ | I want to… | Start here |
51
+ | --- | --- |
52
+ | Set up a repo with starter agent definitions | `npx agent-lyra init` |
53
+ | Build and export an app from your own saved agents | [Build an app from your Lyra agents](#build-an-app-from-your-lyra-agents) |
54
+ | Run a model-backed agent from my terminal | [Run an agent](#run-an-agent) |
55
+ | Inspect saved runs inside my IDE | [Connect your IDE](#connect-your-ide) |
56
+ | Share or import an app | [Use the Marketplace](#use-the-marketplace) |
57
+
58
+ ### Run an agent
59
59
 
60
- To run the built-in writing team with the same setup:
60
+ Set `OPENAI_API_KEY` in your environment. Replace `YOUR_MODEL` with an OpenAI model available to your key.
61
61
 
62
62
  ```bash
63
- npx agent-lyra team run draft-review --model YOUR_MODEL --prompt "Draft a project update"
63
+ npx agent-lyra agent run --model YOUR_MODEL --prompt "Draft a project update"
64
+ npx agent-lyra run status YOUR_RUN_ID
64
65
  ```
65
66
 
66
- The writer produces a draft, then the reviewer receives the prompt and draft and returns revised text. Each step prints a run ID you can inspect with `agent-lyra run status`. The team makes two model calls when both steps succeed.
67
+ Copy the run ID printed by the first command into the second. The CLI saves run events locally in `.lyra/state/runs.sqlite`. To run a writer followed by a reviewer, use `team run draft-review` with the same model and prompt flags.
67
68
 
68
- ## Inspect saved runs from an IDE
69
+ ### Connect your IDE
69
70
 
70
- Configure a stdio MCP server in your IDE with the installed `agent-lyra` executable (use its absolute path if needed) and these arguments:
71
+ Configure a stdio MCP server with the installed `agent-lyra` executable, using its absolute path if your IDE requires one. Set the arguments to:
71
72
 
72
73
  ```json
73
74
  ["mcp", "serve", "--dir", "ABSOLUTE_PROJECT_PATH"]
74
75
  ```
75
76
 
76
- Two-layer Lyra SDK package:
77
+ The MCP server reads saved runs from that project.
77
78
 
78
- - Standalone layer: local orchestration primitives and RAG utilities with no API key.
79
- - Gated layer: compatibility client for deployments that provide the hosted invocation endpoint.
79
+ ### Use the Marketplace
80
80
 
81
- ## Install
81
+ Generate a shareable listing preview with `npx agent-lyra app publish .lyra/app/manifest.json --dry-run`. Review it before submitting the listing in the cloud. Browse apps publicly, then sign in to import an editable private copy. CLI imports require an existing Lyra session supplied through `LYRA_SESSION_TOKEN`. [Marketplace Apps](https://agentlyra.in/marketplace/apps)
82
+
83
+ ## Local Studio
82
84
 
83
85
  ```bash
84
- npm install agent-lyra
85
- # or
86
- pnpm add agent-lyra
86
+ npx agent-lyra studio
87
87
  ```
88
88
 
89
- Installation has zero side effects:
89
+ Open the printed loopback URL. Drag a heading, text, input, text area, run button, or output onto the canvas. You can also add components by clicking them. Select a run button in the inspector, bind an input and output, and add agents or compatible workflows in the order they should run. **Save layout** writes the layout into your root `manifest.json`.
90
90
 
91
- - no files/folders created
92
- - no network calls by package code
93
- - no postinstall hooks
91
+ Studio reads standalone Markdown agents from `.lyra/agents/`. Each needs an `id`, a `name`, and a `## System Prompt` section. To run a local agent, set `OPENAI_API_KEY` and choose a model in the Run now drawer. Override the model list with a comma-separated `LYRA_STUDIO_MODELS` environment variable if needed.
94
92
 
95
- Initialization is explicit and happens only when the user runs the CLI.
93
+ Set `LYRA_API_KEY` to an AgentLyra SDK key, then select **Pull from Cloud** or run `npx agent-lyra studio pull`. The pull saves Cloud agent references, workflows, and team metadata into `.lyra/agents/`, `.lyra/workflows/`, and `.lyra/teams/`. Existing files are preserved. Studio can run compatible sequential text workflows. Other workflows and teams appear as reference cards. Cloud agents use the OpenAI key configured in Cloud Models.
96
94
 
97
- ## Init A Repo
95
+ Add an **Agent card** to let users run one agent directly from the app. Choose the agent in the Inspector and optionally bind an input and an output. Use a **Run button** for a sequence of agents or workflows.
98
96
 
99
- ```bash
100
- npx agent-lyra init
97
+ Save the canvas in Studio and export it with `npx agent-lyra app export manifest.json ./my-app`. Open the new folder and run `npm start` to launch the app locally. The export keeps the component layout and Run button bindings. It includes the prompts of referenced local agents and the IDs of referenced Cloud agents. Supply your API keys through environment variables when starting the app.
98
+
99
+
100
+ ### Run a Python skill from the canvas
101
+
102
+ Install the Python SDK in your environment. Create `.lyra/agents/draft.py`:
103
+
104
+ ```python
105
+ from lyra.standalone import Agent, Skill
106
+
107
+ def draft(text):
108
+ return f"Draft: {text}"
109
+
110
+ agent = Agent("draft", [Skill("draft-note", draft)])
101
111
  ```
102
112
 
103
- Or after install:
113
+ Register the skill in `.lyra/agents/draft.json`:
104
114
 
105
- ```bash
106
- agent-lyra init
115
+ ```json
116
+ {"id":"draft","name":"Draft a note","runtime":"python","file":"draft.py","skill":"draft-note"}
107
117
  ```
108
118
 
109
- Flow:
119
+ Restart Studio or click **Reload agents**. Select **Draft a note** on an Agent card, or add it to a Run button's execution order. Studio passes the input as a string, along with any previous step result. Skills may return strings or JSON-serializable values. The Python CLI uses its own interpreter. If you launch Studio from npm or start an exported app, set `LYRA_PYTHON` to your virtual environment's Python executable when needed.
110
120
 
111
- - optional login step with Lyra API key to sync your web-created agents
112
- - choose pack type: `Professional` or `Everyday`
113
- - choose `standalone` or `gated` (or set with `--mode`)
114
- - standalone: select onboarding domains with `Space`, confirm with `Enter`
115
- - for repository-aware engineering personas, select `engineering-bootstrap`
116
- - gated: select hosted verticals, then enter the Lyra API key from the Lyra login UI
117
- - logged-out gated selections are marked as `needs login` in generated metadata
118
- - the command creates a `.lyra/` folder in the current repo only after confirmation
121
+ Export includes the Python files bound to the canvas. Install the Python SDK and any dependencies in the environment running the export. If an agent imports other project files, add those files to the exported project and make them importable in that environment. Run Python agents from projects whose source you trust.
119
122
 
120
- Generated files:
123
+ ## CLI reference
121
124
 
122
- - `.lyra/config.json`
123
- - `.lyra/manifest.json` (root manifest with `source` + `comparisonStatus`)
124
- - `.lyra/README.md`
125
- - `.lyra/domains/<domain>/domain.json` (domain manifest)
126
- - `.lyra/domains/<domain>/agents/*.md`
127
- - `.lyra/agents/*.md` (flattened top-level agent specs)
128
- - `.lyra/credentials.json` only for gated mode
129
- - `.lyra/.gitignore` to ignore the local credentials file
125
+ Prefix each command with `npx agent-lyra`. Angle brackets indicate required arguments. Square brackets indicate optional arguments.
130
126
 
131
- Agent Markdown files are generated from the canonical onboarding catalog and include rich fields:
127
+ ### Project setup
132
128
 
133
- - identity: `id`, `slug`, `name`, `domain`, `category`, `mode`
134
- - execution: `type`, `runtime` (standalone) or `hosted` (gated)
135
- - behavior: `description`, `systemPrompt`, `skills`, `integrations`
136
- - output policy: `outputs`
129
+ | Command | What it does |
130
+ | --- | --- |
131
+ | `init [options]` | Scaffold a `.lyra` workspace and starter agents. Options include `--mode`, `--domains`, `--api-key`, `--api-base-url`, `--dir`, and `--force`. |
132
+ | `--help` | Show the init command and its options. The help alias does the same. Add `--help` to a specific command for its syntax. |
137
133
 
138
- Engineering bootstrap agents are dynamic and repo-intelligence-ready:
134
+ ### App Builder
139
135
 
140
- - roles generated: `Engineering Dev Lead`, `Engineering QA Lead`, `Engineering Product Manager`, `Engineering Scrum Master`, `Engineering Architect`
141
- - prompts are stack-agnostic and rely on runtime repo scan context
142
- - each agent spec includes a `repoIntelligence` contract that aligns with:
143
- - scan endpoint: `/api/repositories/:id/scan`
144
- - PR endpoint: `/api/repositories/:id/lyra-pr`
136
+ | Command | What it does |
137
+ | --- | --- |
138
+ | `app init [manifest.json]` | Select two saved Lyra agents. Defaults to `manifest.json` in your project. |
139
+ | `app validate <manifest.json>` | Check the app manifest before previewing or exporting. |
140
+ | `app preview <manifest.json>` | Preview the app in your browser on loopback. Set `LYRA_PREVIEW_PORT` to change its port. |
141
+ | `app export <manifest.json> <new-directory>` | Export editable app source into a new directory. |
142
+ | `app publish <manifest.json> --dry-run` | Print the proposed Marketplace payload for review. Submit the listing in the cloud. |
143
+ | `app use <listing-id> [new-manifest.json]` | Import a published app and save its manifest. Requires `LYRA_SESSION_TOKEN`. |
144
+
145
+ ### Agent runs and IDE integration
146
+
147
+ | Command | What it does |
148
+ | --- | --- |
149
+ | `agent run --model <model> --prompt <text>` | Run a local agent with an OpenAI model. Requires `OPENAI_API_KEY`. |
150
+ | `team run draft-review --model <model> --prompt <text>` | Run the built-in writer and reviewer team. Requires `OPENAI_API_KEY`. |
151
+ | `run status <run-id>` | Read the latest event for a run from local SQLite history. |
152
+ | `mcp serve --dir <absolute-project-directory>` | Expose saved runs to an IDE over read-only stdio MCP. |
145
153
 
146
- ## Usage
154
+ ## Use the library from JavaScript
147
155
 
148
156
  ```js
149
- import { standalone, gated } from "agent-lyra";
157
+ import { createLinearWorkflow, runWorkflow } from "agent-lyra/standalone";
150
158
 
151
- const workflow = standalone.createLinearWorkflow(
159
+ const workflow = createLinearWorkflow(
152
160
  async () => "collect",
153
- async (ctx) => `${ctx.step_1}:analyze`,
161
+ async (context) => `${context.step_1}:analyze`,
154
162
  );
155
163
 
156
- const result = await standalone.runWorkflow(workflow);
157
-
158
- const client = gated.createHostedAgentClient({ apiKey: process.env.LYRA_API_KEY });
159
- const output = await client.invoke("sales", { prompt: "Summarize latest pipeline risk." });
164
+ console.log(await runWorkflow(workflow));
160
165
  ```
166
+
167
+ The standalone entry point also includes retrieval utilities. The gated entry point is a compatibility client for deployments that expose the hosted invocation API. Check endpoint compatibility before using it with a cloud deployment.
168
+
169
+ ## Current scope
170
+
171
+ The App Builder supports two saved text agents in sequence. Publishing saved-agent app manifests to Marketplace is outside the current release. OpenAI-backed agent runs use your own provider key. Cloud accounts and AgentLyra API keys are managed in the [AgentLyra console](https://console.agentlyra.in/).
172
+
173
+ MIT licensed.
package/bin/agent-lyra.js CHANGED
@@ -10,8 +10,11 @@ import { runAppPreview } from "../src/app-builder/preview.js";
10
10
  import { runAppPublish } from "../src/app-builder/publish.js";
11
11
  import { runAppUse } from "../src/app-builder/use.js";
12
12
 
13
+ import { runStudio } from "../src/studio/server.js";
14
+
13
15
  async function main() {
14
- const argv = process.argv.slice(2);
16
+ const argv = process.argv.slice(2);
17
+ if (argv[0] === "studio") return runStudio(argv.slice(1));
15
18
  if (argv[0] === "app" && argv[1] === "use") return runAppUse(argv.slice(2));
16
19
  if (argv[0] === "app" && argv[1] === "init") return runAppInit(argv.slice(2));
17
20
  if (argv[0] === "app" && argv[1] === "preview") return runAppPreview(argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-lyra",
3
- "version": "0.3.1",
3
+ "version": "0.6.0",
4
4
  "description": "Two-layer Lyra SDK with standalone local primitives and gated hosted agents.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -1,59 +1,109 @@
1
- import { mkdir, readFile, writeFile } from "node:fs/promises";
2
- import { dirname, join, resolve } from "node:path";
3
- import { readSupportManifest } from "./support-manifest.js";
4
-
5
- const assets = {
6
- "runtime/app-builder/support-template/support-preview.mjs": "./support-template/support-preview.mjs",
7
- "runtime/app-builder/support-template/support-preview.html": "./support-template/support-preview.html",
8
- "runtime/app-builder/support-template/support-preview.js": "./support-template/support-preview.js",
9
- "runtime/app-builder/support-template/support-workflow.mjs": "./support-template/support-workflow.mjs",
10
- "runtime/app-builder/gateway.js": "./gateway.js",
11
- "runtime/app-builder/validate.js": "./validate.js",
12
- "runtime/app-builder/value-schema.js": "./value-schema.js",
13
- "runtime/app-builder/native-adapter.js": "./native-adapter.js",
14
- "runtime/runtime/run-agent.js": "../runtime/run-agent.js",
15
- LICENSE: "../../LICENSE",
16
- };
17
-
18
- export async function runAppExport(args, output = process.stdout) {
19
- if (args.length === 1 && args[0] === "--help") {
20
- output.write("Usage: agent-lyra app export <manifest.json> <new-directory>\n");
21
- return;
22
- }
23
- if (args.length !== 2 || args.some((arg) => arg.startsWith("-"))) {
24
- throw new Error("Provide a manifest and new output directory. See agent-lyra app export --help.");
25
- }
26
- const manifest = await readSupportManifest(args[0]);
27
- const directory = resolve(args[1]);
28
- const files = await Promise.all(Object.entries(assets).map(async ([name, sourcePath]) =>
29
- [name, await readFile(new URL(sourcePath, import.meta.url))]));
30
- const manifestReader = 'const manifest = JSON.parse(await readFile(new URL("./example-manifest.json", import.meta.url), "utf8"));\n';
31
- files.push(["example-manifest.json", JSON.stringify(manifest, null, 2) + "\n"]);
32
- files.push(["support-preview.mjs",
33
- 'import { readFile } from "node:fs/promises";\n' +
34
- 'import { startSupportPreview } from "./runtime/app-builder/support-template/support-preview.mjs";\n' +
35
- manifestReader + "await startSupportPreview(manifest);\n"]);
36
- files.push(["support-example.mjs",
37
- 'import { readFile } from "node:fs/promises";\n' +
38
- 'import { createSupportWorkflow } from "./runtime/app-builder/support-template/support-workflow.mjs";\n' +
39
- manifestReader +
40
- 'console.log(JSON.stringify(await createSupportWorkflow(manifest)(process.argv[2] ?? "Invoice question"), null, 2));\n']);
41
- files.push(["package.json", JSON.stringify({
42
- name: manifest.application.id, version: "1.0.0", private: true, type: "module",
43
- engines: { node: ">=22.13.0" },
44
- scripts: { start: "node support-preview.mjs", demo: "node support-example.mjs" },
45
- }, null, 2) + "\n"]);
46
- 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"]);
47
- try {
48
- await mkdir(directory);
49
- } catch (error) {
50
- if (error.code === "EEXIST") throw new Error("Choose a new directory. Existing files were preserved.");
51
- throw error;
52
- }
53
- for (const [name, contents] of files) {
54
- const target = join(directory, name);
55
- await mkdir(dirname(target), { recursive: true });
56
- await writeFile(target, contents, { flag: "wx" });
57
- }
58
- output.write(`Exported ${manifest.application.id} to ${directory}\n`);
59
- }
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,23 +1,52 @@
1
- import { mkdir, readFile, writeFile } from "node:fs/promises";
2
- import { dirname, resolve } from "node:path";
3
-
4
- export async function runAppInit(args, output = process.stdout) {
5
- if (args.length === 1 && args[0] === "--help") {
6
- output.write("Usage: agent-lyra app init [manifest.json]\nDefault: .lyra/app/manifest.json\n");
7
- return;
8
- }
9
- if (args.length > 1 || args[0]?.startsWith("-")) {
10
- throw new Error("Provide at most one manifest path. See agent-lyra app init --help.");
11
- }
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 });
16
- try {
17
- await writeFile(target, template, { flag: "wx" });
18
- } catch (error) {
19
- if (error.code === "EEXIST") throw new Error(`Manifest already exists at ${target}. It was preserved.`);
20
- throw error;
21
- }
22
- output.write(`Created ${target}\n`);
23
- }
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,14 +1,22 @@
1
- import { readSupportManifest } from "./support-manifest.js";
2
- import { startSupportPreview } from "./support-template/support-preview.mjs";
3
-
4
- export async function runAppPreview(args, output = process.stdout) {
5
- if (args.length === 1 && args[0] === "--help") {
6
- output.write("Usage: agent-lyra app preview <manifest.json>\nSet LYRA_PREVIEW_PORT to override the loopback port.\n");
7
- return;
8
- }
9
- if (args.length !== 1 || args[0].startsWith("-")) {
10
- throw new Error("Provide a manifest path. See agent-lyra app preview --help.");
11
- }
12
- const manifest = await readSupportManifest(args[0]);
13
- await startSupportPreview(manifest);
14
- }
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
+ }