orchajs 0.23.10 → 0.23.12

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/dist/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync } from "node:fs";
3
- import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
4
4
  import { dirname, relative, resolve } from "node:path";
5
5
  import { watch } from "chokidar";
6
- import { AGENTS_MD } from "./cli-agents-template.js";
7
6
  import { buildProject } from "./compiler/build-project.js";
8
7
  import { loadProjectEnvironment } from "./env.js";
8
+ import { initializeProject } from "./initialize-project.js";
9
9
  import { orcha } from "./orcha.js";
10
10
  import { startPlayground } from "./playground/server.js";
11
11
  import { loadProject } from "./project-loader.js";
@@ -43,7 +43,7 @@ switch (command) {
43
43
  case "build": {
44
44
  const parsed = parseArguments(commandArguments, new Set(["--target"]), new Set());
45
45
  if (parsed.positionals.length > 0) {
46
- throw new Error("Usage: orcha build [--target node|browser|react-native]");
46
+ throw new Error("Usage: orchajs build [--target node|browser|react-native]");
47
47
  }
48
48
  const target = parseBuildTarget(parsed.values.get("--target"));
49
49
  loadProjectEnvironment(projectRoot);
@@ -58,61 +58,12 @@ switch (command) {
58
58
  printUsage();
59
59
  break;
60
60
  default:
61
- throw new Error(`Unknown command "${command}". Run "orcha --help".`);
62
- }
63
- async function initializeProject(projectRoot) {
64
- const files = new Map([
65
- [
66
- "orcha/exampleAgent/index.json",
67
- `${JSON.stringify({
68
- name: "Example Agent",
69
- description: "Answer general questions clearly and concisely.",
70
- provider: "anthropic",
71
- model: "claude-sonnet-4-6",
72
- region: "provider_managed",
73
- maxTokens: 10240,
74
- outputType: "text",
75
- }, null, 2)}\n`,
76
- ],
77
- [
78
- "orcha/exampleAgent/instructions.md",
79
- "You are a concise and helpful assistant.\n",
80
- ],
81
- [
82
- "orcha/index.ts",
83
- [
84
- 'import { orcha } from "orchajs";',
85
- "",
86
- "orcha.init({",
87
- " providers: {",
88
- " anthropic: process.env.ANTHROPIC_API_KEY ?? \"\",",
89
- " },",
90
- " agents: {",
91
- " exampleAgent: \"./exampleAgent\",",
92
- " },",
93
- "});",
94
- "",
95
- ].join("\n"),
96
- ],
97
- ["AGENTS.md", AGENTS_MD],
98
- ]);
99
- for (const [relativePath, contents] of files) {
100
- const path = resolve(projectRoot, relativePath);
101
- if (existsSync(path)) {
102
- console.log(`Skipped existing ${relativePath}`);
103
- continue;
104
- }
105
- await mkdir(dirname(path), { recursive: true });
106
- await writeFile(path, contents, "utf8");
107
- console.log(`Created ${relativePath}`);
108
- }
109
- await ensureGitignore(projectRoot);
110
- console.log('\nRun "orcha dev" to validate changes or "orcha run exampleAgent --input \\"Hello\\"" to execute the agent.');
61
+ throw new Error(`Unknown command "${command}". Run "orchajs --help".`);
111
62
  }
112
63
  async function watchProject(projectRoot, targets) {
113
64
  const registryDirectory = resolve(projectRoot, "orcha");
114
65
  if (!existsSync(registryDirectory)) {
115
- throw new Error('Missing "orcha/". Run "orcha init" first.');
66
+ throw new Error('Missing "orcha/". Run "orchajs init" first.');
116
67
  }
117
68
  loadProjectEnvironment(projectRoot);
118
69
  let validating = false;
@@ -166,7 +117,7 @@ async function runAgent(projectRoot, arguments_) {
166
117
  ]));
167
118
  const agentName = parsed.positionals[0];
168
119
  if (!agentName || parsed.positionals.length > 1) {
169
- throw new Error('Usage: orcha run <agent> (--input "…" | --input-file request.json) [--session <id>] [--json]');
120
+ throw new Error('Usage: orchajs run <agent> (--input "…" | --input-file request.json) [--session <id>] [--json]');
170
121
  }
171
122
  await loadProject(projectRoot);
172
123
  const agent = orcha[agentName];
@@ -213,7 +164,7 @@ async function runAgent(projectRoot, arguments_) {
213
164
  async function testAgents(projectRoot, arguments_) {
214
165
  const parsed = parseArguments(arguments_, new Set());
215
166
  if (parsed.positionals.length > 1) {
216
- throw new Error("Usage: orcha test [agent | agent/test] [--json]");
167
+ throw new Error("Usage: orchajs test [agent | agent/test] [--json]");
217
168
  }
218
169
  const selector = parsed.positionals[0];
219
170
  const [agent, test, extra] = selector?.split("/") ?? [];
@@ -256,7 +207,7 @@ async function testAgents(projectRoot, arguments_) {
256
207
  async function runPlayground(projectRoot, arguments_) {
257
208
  const parsed = parseArguments(arguments_, new Set(["--host", "--port"]), new Set(["--no-open"]));
258
209
  if (parsed.positionals.length > 0) {
259
- throw new Error("Usage: orcha playground [--host localhost] [--port 4310] [--no-open]");
210
+ throw new Error("Usage: orchajs playground [--host localhost] [--port 4310] [--no-open]");
260
211
  }
261
212
  const portValue = parsed.values.get("--port");
262
213
  const port = portValue ? Number.parseInt(portValue, 10) : 4310;
@@ -273,7 +224,7 @@ async function runPlayground(projectRoot, arguments_) {
273
224
  async function migrateStorage(projectRoot, arguments_) {
274
225
  const parsed = parseArguments(arguments_, new Set(["--to", "--agent"]), new Set());
275
226
  if (parsed.positionals.length > 0) {
276
- throw new Error("Usage: orcha migrate-storage --to <sqlite | node-jsonl> [--agent <name>]");
227
+ throw new Error("Usage: orchajs migrate-storage --to <sqlite | node-jsonl> [--agent <name>]");
277
228
  }
278
229
  const destinationStrategy = storageStrategy(parsed.values.get("--to"));
279
230
  const sourceStrategy = destinationStrategy === "sqlite" ? "node-jsonl" : "sqlite";
@@ -305,7 +256,7 @@ async function exportSession(projectRoot, arguments_) {
305
256
  const parsed = parseArguments(arguments_, new Set(["--output"]), new Set());
306
257
  const [agentName, sessionId] = parsed.positionals;
307
258
  if (!agentName || !sessionId || parsed.positionals.length !== 2) {
308
- throw new Error("Usage: orcha export-session <agent> <sessionId> [--output <path>]");
259
+ throw new Error("Usage: orchajs export-session <agent> <sessionId> [--output <path>]");
309
260
  }
310
261
  await loadProject(projectRoot);
311
262
  const context = getOrchaRuntimeContext(orcha);
@@ -347,7 +298,7 @@ function allAgentManifests(agents) {
347
298
  function parseDevTargets(arguments_) {
348
299
  const parsed = parseArguments(arguments_, new Set(["--target"]), new Set());
349
300
  if (parsed.positionals.length > 0) {
350
- throw new Error("Usage: orcha dev [--target node|browser|react-native|all]");
301
+ throw new Error("Usage: orchajs dev [--target node|browser|react-native|all]");
351
302
  }
352
303
  const target = parsed.values.get("--target") ?? "node";
353
304
  if (target === "all") {
@@ -604,24 +555,12 @@ async function sessionLogPath(projectRoot, agentName, sessionId) {
604
555
  }
605
556
  function assertNoArguments(arguments_, command) {
606
557
  if (arguments_.length > 0) {
607
- throw new Error(`Usage: orcha ${command}`);
608
- }
609
- }
610
- async function ensureGitignore(projectRoot) {
611
- const path = resolve(projectRoot, ".gitignore");
612
- const entry = ".orcha/";
613
- const current = existsSync(path) ? await readFile(path, "utf8") : "";
614
- const entries = current.split(/\r?\n/).map((line) => line.trim());
615
- if (entries.includes(entry)) {
616
- return;
558
+ throw new Error(`Usage: orchajs ${command}`);
617
559
  }
618
- const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
619
- await appendFile(path, `${prefix}${entry}\n`, "utf8");
620
- console.log("Updated .gitignore");
621
560
  }
622
561
  function printUsage() {
623
562
  console.log([
624
- "Usage: orcha <command>",
563
+ "Usage: orchajs <command>",
625
564
  "",
626
565
  "Commands:",
627
566
  " init Add Orcha to the current project",
@@ -7,6 +7,7 @@ import { orcha } from "../orcha.js";
7
7
  import { setRegistryCompiler } from "../runtime/compiler-hook.js";
8
8
  import { compileRegistry } from "./compile.js";
9
9
  import { builtInProviderCatalog, isBuiltInProvider, } from "../providers/catalog.js";
10
+ import { ensureProviderDependencies } from "../providers/dependencies.js";
10
11
  let registryImportSequence = 0;
11
12
  export async function buildProject(options = {}) {
12
13
  const projectRoot = resolve(options.projectRoot ?? process.cwd());
@@ -14,7 +15,7 @@ export async function buildProject(options = {}) {
14
15
  setRegistryCompiler((configuration, compilerProjectRoot) => compileRegistry(configuration.agents, resolve(compilerProjectRoot, "orcha"), configuration.actions?.runtime ?? "native", target));
15
16
  const registryPath = resolve(projectRoot, "orcha/index.ts");
16
17
  if (!existsSync(registryPath)) {
17
- throw new Error('Missing "orcha/index.ts". Run "orcha init" first.');
18
+ throw new Error('Missing "orcha/index.ts". Run "orchajs init" first.');
18
19
  }
19
20
  const temporaryDirectory = resolve(projectRoot, ".orcha/.build");
20
21
  const registryBundlePath = resolve(temporaryDirectory, "registry.mjs");
@@ -78,6 +79,7 @@ export async function buildProject(options = {}) {
78
79
  ])),
79
80
  ];
80
81
  const providerRuntimeSource = createProviderRuntimeSource(includedProviders, target);
82
+ await ensureProviderDependencies(includedProviders, projectRoot);
81
83
  const needsNodeRequire = compiledBundle.actionRuntime === "sandbox" ||
82
84
  includedProviders.includes("vertexai") ||
83
85
  includedProviders.includes("bedrock");
@@ -0,0 +1 @@
1
+ export declare function initializeProject(projectRoot: string): Promise<void>;
@@ -0,0 +1,65 @@
1
+ import { existsSync } from "node:fs";
2
+ import { appendFile, mkdir, readFile, writeFile, } from "node:fs/promises";
3
+ import { dirname, resolve } from "node:path";
4
+ import { AGENTS_MD } from "./cli-agents-template.js";
5
+ export async function initializeProject(projectRoot) {
6
+ const files = new Map([
7
+ [
8
+ "orcha/exampleAgent/index.json",
9
+ `${JSON.stringify({
10
+ name: "Example Agent",
11
+ description: "Answer general questions clearly and concisely.",
12
+ provider: "anthropic",
13
+ model: "claude-sonnet-4-6",
14
+ region: "provider_managed",
15
+ maxTokens: 10240,
16
+ outputType: "text",
17
+ }, null, 2)}\n`,
18
+ ],
19
+ [
20
+ "orcha/exampleAgent/instructions.md",
21
+ "You are a concise and helpful assistant.\n",
22
+ ],
23
+ [
24
+ "orcha/index.ts",
25
+ [
26
+ 'import { orcha } from "orchajs";',
27
+ "",
28
+ "orcha.init({",
29
+ " providers: {",
30
+ " anthropic: process.env.ANTHROPIC_API_KEY ?? \"\",",
31
+ " },",
32
+ " agents: {",
33
+ " exampleAgent: \"./exampleAgent\",",
34
+ " },",
35
+ "});",
36
+ "",
37
+ ].join("\n"),
38
+ ],
39
+ ["AGENTS.md", AGENTS_MD],
40
+ ]);
41
+ for (const [relativePath, contents] of files) {
42
+ const path = resolve(projectRoot, relativePath);
43
+ if (existsSync(path)) {
44
+ console.log(`Skipped existing ${relativePath}`);
45
+ continue;
46
+ }
47
+ await mkdir(dirname(path), { recursive: true });
48
+ await writeFile(path, contents, "utf8");
49
+ console.log(`Created ${relativePath}`);
50
+ }
51
+ await ensureGitignore(projectRoot);
52
+ console.log('\nRun "orchajs dev" to validate changes or "orchajs run exampleAgent --input \\"Hello\\"" to execute the agent.');
53
+ }
54
+ async function ensureGitignore(projectRoot) {
55
+ const path = resolve(projectRoot, ".gitignore");
56
+ const entry = ".orcha/";
57
+ const current = existsSync(path) ? await readFile(path, "utf8") : "";
58
+ const entries = current.split(/\r?\n/).map((line) => line.trim());
59
+ if (entries.includes(entry)) {
60
+ return;
61
+ }
62
+ const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
63
+ await appendFile(path, `${prefix}${entry}\n`, "utf8");
64
+ console.log("Updated .gitignore");
65
+ }
package/dist/orcha.js CHANGED
@@ -23,7 +23,7 @@ export const orcha = createOrcha((configuration) => {
23
23
  existsSync(compiledManifestPath(projectRoot))) {
24
24
  return loadCompiledManifest(projectRoot, configuration);
25
25
  }
26
- throw new Error('Orcha agents must be compiled before runtime initialization. Run "npx orcha dev" during development or "npx orcha build" before starting the application.');
26
+ throw new Error('Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.');
27
27
  }, generateProviderResponse, nodeRuntimePlatform);
28
28
  function isPrecompiledRuntime() {
29
29
  return (process.env.ORCHA_USE_BUILD === "1" ||
@@ -34,14 +34,14 @@ function isPrecompiledRuntime() {
34
34
  function loadCompiledManifest(projectRoot, configuration) {
35
35
  const manifestPath = compiledManifestPath(projectRoot);
36
36
  if (!existsSync(manifestPath)) {
37
- throw new Error(`ORCHA_PRODUCTION_BUNDLE_MISSING: "${manifestPath}" was not found. Run "npx orcha build" before packaging, include ".orcha/dist" in the deployment, or configure the Orcha build integration.`);
37
+ throw new Error(`ORCHA_PRODUCTION_BUNDLE_MISSING: "${manifestPath}" was not found. Run "npx orchajs build" before packaging, include ".orcha/dist" in the deployment, or configure the Orcha build integration.`);
38
38
  }
39
39
  let parsed;
40
40
  try {
41
41
  parsed = JSON.parse(readFileSync(manifestPath, "utf8"));
42
42
  }
43
43
  catch (error) {
44
- throw new Error(`Orcha could not read the compiled manifest at "${manifestPath}". Run "npx orcha build" again.`, { cause: error });
44
+ throw new Error(`Orcha could not read the compiled manifest at "${manifestPath}". Run "npx orchajs build" again.`, { cause: error });
45
45
  }
46
46
  if (typeof parsed !== "object" ||
47
47
  parsed === null ||
@@ -51,14 +51,14 @@ function loadCompiledManifest(projectRoot, configuration) {
51
51
  typeof parsed.agents !== "object" ||
52
52
  parsed.agents === null ||
53
53
  Array.isArray(parsed.agents)) {
54
- throw new Error(`Orcha compiled manifest "${manifestPath}" is invalid. Run "npx orcha build" again.`);
54
+ throw new Error(`Orcha compiled manifest "${manifestPath}" is invalid. Run "npx orchajs build" again.`);
55
55
  }
56
56
  const bundle = parsed;
57
57
  const registeredAgents = Object.keys(configuration.agents).sort();
58
58
  const compiledAgents = Object.keys(bundle.agents).sort();
59
59
  if (registeredAgents.length !== compiledAgents.length ||
60
60
  registeredAgents.some((name, index) => name !== compiledAgents[index])) {
61
- throw new Error(`Orcha compiled manifest does not match the registered agents. Run "npx orcha build" again. Expected [${registeredAgents.join(", ")}], found [${compiledAgents.join(", ")}].`);
61
+ throw new Error(`Orcha compiled manifest does not match the registered agents. Run "npx orchajs build" again. Expected [${registeredAgents.join(", ")}], found [${compiledAgents.join(", ")}].`);
62
62
  }
63
63
  return bundle;
64
64
  }
@@ -0,0 +1,10 @@
1
+ export type PackageManager = "npm" | "yarn" | "pnpm" | "bun";
2
+ export declare function detectPackageManager(projectRoot?: string): PackageManager;
3
+ export declare function installCommand(packageManager: PackageManager, packages: readonly string[], development: boolean): {
4
+ command: string;
5
+ arguments: string[];
6
+ };
7
+ export declare function runPackageManager(command: string, arguments_: string[], options?: {
8
+ cwd?: string;
9
+ env?: NodeJS.ProcessEnv;
10
+ }): Promise<number>;
@@ -0,0 +1,78 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ export function detectPackageManager(projectRoot = process.cwd()) {
5
+ if (existsSync(resolve(projectRoot, "yarn.lock"))) {
6
+ return "yarn";
7
+ }
8
+ if (existsSync(resolve(projectRoot, "pnpm-lock.yaml"))) {
9
+ return "pnpm";
10
+ }
11
+ if (existsSync(resolve(projectRoot, "bun.lock")) ||
12
+ existsSync(resolve(projectRoot, "bun.lockb"))) {
13
+ return "bun";
14
+ }
15
+ const userAgent = process.env.npm_config_user_agent;
16
+ if (userAgent?.startsWith("yarn/")) {
17
+ return "yarn";
18
+ }
19
+ if (userAgent?.startsWith("pnpm/")) {
20
+ return "pnpm";
21
+ }
22
+ if (userAgent?.startsWith("bun/")) {
23
+ return "bun";
24
+ }
25
+ return "npm";
26
+ }
27
+ export function installCommand(packageManager, packages, development) {
28
+ switch (packageManager) {
29
+ case "yarn":
30
+ return {
31
+ command: executable("yarn"),
32
+ arguments: ["add", ...(development ? ["--dev"] : []), ...packages],
33
+ };
34
+ case "pnpm":
35
+ return {
36
+ command: executable("pnpm"),
37
+ arguments: [
38
+ "add",
39
+ ...(development ? ["--save-dev"] : []),
40
+ ...packages,
41
+ ],
42
+ };
43
+ case "bun":
44
+ return {
45
+ command: executable("bun"),
46
+ arguments: ["add", ...(development ? ["--dev"] : []), ...packages],
47
+ };
48
+ default:
49
+ return {
50
+ command: executable("npm"),
51
+ arguments: [
52
+ "install",
53
+ ...(development ? ["--save-dev"] : []),
54
+ ...packages,
55
+ ],
56
+ };
57
+ }
58
+ }
59
+ export function runPackageManager(command, arguments_, options = {}) {
60
+ return new Promise((resolveProcess, reject) => {
61
+ const child = spawn(command, arguments_, {
62
+ cwd: options.cwd ?? process.cwd(),
63
+ env: options.env ?? process.env,
64
+ stdio: "inherit",
65
+ });
66
+ child.once("error", reject);
67
+ child.once("exit", (code, signal) => {
68
+ if (signal) {
69
+ process.kill(process.pid, signal);
70
+ return;
71
+ }
72
+ resolveProcess(code ?? 1);
73
+ });
74
+ });
75
+ }
76
+ function executable(command) {
77
+ return process.platform === "win32" ? `${command}.cmd` : command;
78
+ }
@@ -6,13 +6,14 @@ import { build as bundleEntry } from "esbuild";
6
6
  import { compileRegistry } from "./compiler/compile.js";
7
7
  import { loadProjectEnvironment } from "./env.js";
8
8
  import { orcha } from "./orcha.js";
9
+ import { ensureCompiledProviderDependencies } from "./providers/dependencies.js";
9
10
  import { setRegistryCompiler } from "./runtime/compiler-hook.js";
10
11
  export async function loadProject(projectRoot) {
11
12
  setRegistryCompiler((configuration, compilerProjectRoot) => compileRegistry(configuration.agents, resolve(compilerProjectRoot, "orcha"), configuration.actions?.runtime ?? "native", "node"));
12
13
  loadProjectEnvironment(projectRoot);
13
14
  const registryPath = resolve(projectRoot, "orcha/index.ts");
14
15
  if (!existsSync(registryPath)) {
15
- throw new Error('Missing "orcha/index.ts". Run "orcha init" first.');
16
+ throw new Error('Missing "orcha/index.ts". Run "orchajs init" first.');
16
17
  }
17
18
  const temporaryDirectory = resolve(projectRoot, ".orcha/.cli");
18
19
  const bundlePath = resolve(temporaryDirectory, `registry-${process.pid}-${Date.now()}.mjs`);
@@ -46,6 +47,7 @@ export async function loadProject(projectRoot) {
46
47
  orcha.getCompiledBundle() === previousBundle) {
47
48
  throw new Error('"orcha/index.ts" must call orcha.init({ providers, agents }).');
48
49
  }
50
+ await ensureCompiledProviderDependencies(orcha.getCompiledBundle(), projectRoot);
49
51
  }
50
52
  finally {
51
53
  await rm(bundlePath, { force: true });
@@ -0,0 +1,3 @@
1
+ import type { CompiledBundle } from "../types.js";
2
+ export declare function ensureCompiledProviderDependencies(bundle: CompiledBundle, projectRoot: string): Promise<void>;
3
+ export declare function ensureProviderDependencies(providerNames: readonly string[], projectRoot: string): Promise<void>;
@@ -0,0 +1,99 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { createRequire } from "node:module";
3
+ import { resolve } from "node:path";
4
+ import { detectPackageManager, installCommand, runPackageManager, } from "../package-manager.js";
5
+ const providerDependencies = {
6
+ bedrock: {
7
+ packageName: "@aws-sdk/client-bedrock-runtime",
8
+ installSpec: "@aws-sdk/client-bedrock-runtime@3.967.0",
9
+ },
10
+ googlegenai: {
11
+ packageName: "@google/genai",
12
+ installSpec: "@google/genai@2.22.0",
13
+ },
14
+ vertexai: {
15
+ packageName: "@google/genai",
16
+ installSpec: "@google/genai@2.22.0",
17
+ },
18
+ };
19
+ const installations = new Map();
20
+ export function ensureCompiledProviderDependencies(bundle, projectRoot) {
21
+ const providers = allCompiledAgents(bundle.agents).flatMap((agent) => [
22
+ agent.provider,
23
+ ...Object.values(agent.evaluations ?? {})
24
+ .filter((evaluation) => evaluation.enabled !== false)
25
+ .map((evaluation) => evaluation.provider),
26
+ ]);
27
+ return ensureProviderDependencies(providers, projectRoot);
28
+ }
29
+ export async function ensureProviderDependencies(providerNames, projectRoot) {
30
+ const declaredPackages = await readDeclaredPackages(projectRoot);
31
+ const dependencies = [
32
+ ...new Map(providerNames.flatMap((providerName) => {
33
+ const dependency = providerDependencies[providerName];
34
+ return dependency
35
+ ? [[dependency.packageName, dependency]]
36
+ : [];
37
+ })).values(),
38
+ ].filter((dependency) => !declaredPackages.has(dependency.packageName) ||
39
+ !isInstalled(dependency.packageName, projectRoot));
40
+ if (dependencies.length === 0) {
41
+ return;
42
+ }
43
+ const key = `${projectRoot}:${dependencies
44
+ .map((dependency) => dependency.packageName)
45
+ .sort()
46
+ .join(",")}`;
47
+ const existing = installations.get(key);
48
+ if (existing) {
49
+ return existing;
50
+ }
51
+ const installation = installProviderDependencies(dependencies, projectRoot).finally(() => installations.delete(key));
52
+ installations.set(key, installation);
53
+ return installation;
54
+ }
55
+ async function readDeclaredPackages(projectRoot) {
56
+ const packageJson = JSON.parse(await readFile(resolve(projectRoot, "package.json"), "utf8"));
57
+ const declared = new Set();
58
+ for (const field of [
59
+ "dependencies",
60
+ "devDependencies",
61
+ "optionalDependencies",
62
+ ]) {
63
+ const dependencies = packageJson[field];
64
+ if (typeof dependencies !== "object" ||
65
+ dependencies === null ||
66
+ Array.isArray(dependencies)) {
67
+ continue;
68
+ }
69
+ for (const packageName of Object.keys(dependencies)) {
70
+ declared.add(packageName);
71
+ }
72
+ }
73
+ return declared;
74
+ }
75
+ function allCompiledAgents(agents) {
76
+ return Object.values(agents).flatMap((agent) => [
77
+ agent,
78
+ ...Object.values(agent.subagents ?? {}),
79
+ ]);
80
+ }
81
+ function isInstalled(packageName, projectRoot) {
82
+ try {
83
+ createRequire(resolve(projectRoot, "package.json")).resolve(packageName);
84
+ return true;
85
+ }
86
+ catch {
87
+ return false;
88
+ }
89
+ }
90
+ async function installProviderDependencies(dependencies, projectRoot) {
91
+ const packageManager = detectPackageManager(projectRoot);
92
+ const packageNames = dependencies.map((dependency) => dependency.packageName);
93
+ const command = installCommand(packageManager, dependencies.map((dependency) => dependency.installSpec), false);
94
+ console.log(`[orcha] Installing required provider ${packageNames.length === 1 ? "dependency" : "dependencies"} with ${packageManager}: ${packageNames.join(", ")}`);
95
+ const exitCode = await runPackageManager(command.command, command.arguments, { cwd: projectRoot });
96
+ if (exitCode !== 0) {
97
+ throw new Error(`Failed to install required provider ${packageNames.length === 1 ? "dependency" : "dependencies"}: ${packageNames.join(", ")}`);
98
+ }
99
+ }
@@ -30,21 +30,21 @@ files under \`.orcha/\`.
30
30
 
31
31
  ## Commands
32
32
 
33
- - \`orcha init\` creates the initial Orcha files without overwriting files.
34
- - \`orcha dev\` validates agent source and watches \`orcha/**\` for changes.
35
- - \`orcha playground\` opens the built-in local UI and hot reloads agent source.
36
- - \`orcha run <agent> --input "\u2026"\` executes one registered agent.
37
- - \`orcha run <agent> --input-file request.json\` accepts structured input.
38
- - \`orcha run <agent> --session <id> --input "\u2026"\` continues a session.
39
- - \`orcha run <agent> --session <id> --tool-results results.json\` submits
33
+ - \`orchajs init\` creates the initial Orcha files without overwriting files.
34
+ - \`orchajs dev\` validates agent source and watches \`orcha/**\` for changes.
35
+ - \`orchajs playground\` opens the built-in local UI and hot reloads agent source.
36
+ - \`orchajs run <agent> --input "\u2026"\` executes one registered agent.
37
+ - \`orchajs run <agent> --input-file request.json\` accepts structured input.
38
+ - \`orchajs run <agent> --session <id> --input "\u2026"\` continues a session.
39
+ - \`orchajs run <agent> --session <id> --tool-results results.json\` submits
40
40
  pending client-action results.
41
- - \`orcha test\` runs every enabled discovered agent test.
42
- - \`orcha test <agent>\` or \`orcha test <agent>/<case>\` narrows the run.
43
- - \`orcha migrate-storage --to sqlite|node-jsonl\` copies all session histories
41
+ - \`orchajs test\` runs every enabled discovered agent test.
42
+ - \`orchajs test <agent>\` or \`orchajs test <agent>/<case>\` narrows the run.
43
+ - \`orchajs migrate-storage --to sqlite|node-jsonl\` copies all session histories
44
44
  between local stores without deleting the source.
45
- - \`orcha export-session <agent> <sessionId> [--output <path>]\` exports one
45
+ - \`orchajs export-session <agent> <sessionId> [--output <path>]\` exports one
46
46
  session from the active store as JSONL.
47
- - \`orcha build\` creates the production Orcha bundle without calling models.
47
+ - \`orchajs build\` creates the production Orcha bundle without calling models.
48
48
  - Add \`--json\` to \`run\` and \`test\` for machine-readable output.
49
49
 
50
50
  \`run\`, \`test\`, and playground executions use real providers and require
@@ -54,7 +54,7 @@ under \`.orcha/sessions/<agentName>/\`; opt-in SQLite stores all agents in
54
54
 
55
55
  ## Production deployment
56
56
 
57
- \`orcha build\` writes \`.orcha/dist/bundle.js\` for bundler integrations and
57
+ \`orchajs build\` writes \`.orcha/dist/bundle.js\` for bundler integrations and
58
58
  \`.orcha/dist/manifest.json\` for unbundled production runtimes. If deployment
59
59
  uses plain \`tsc\`, \`serverless-plugin-typescript\`, or another packager that
60
60
  does not use \`orchajs/esbuild\`, explicitly include \`.orcha/dist/**\` in the
@@ -70,7 +70,7 @@ package:
70
70
  - ".orcha/dist/**"
71
71
  \`\`\`
72
72
 
73
- Do not assume that a successful \`orcha build\` means the generated files were
73
+ Do not assume that a successful \`orchajs build\` means the generated files were
74
74
  copied by a later packaging tool. Inspect the final ZIP or container image and
75
75
  confirm that \`.orcha/dist/manifest.json\` is present.
76
76
 
@@ -593,7 +593,7 @@ Test \`index.json\` fields:
593
593
  - \`expect.actions\` (optional): ordered expected calls. Each may assert
594
594
  \`arguments.equals\` or \`arguments.partial\`.
595
595
 
596
- The test folder name is the selector used by \`orcha test agent/testName\`.
596
+ The test folder name is the selector used by \`orchajs test agent/testName\`.
597
597
 
598
598
  ## Evaluations
599
599
 
@@ -621,7 +621,7 @@ metrics, and thresholds:
621
621
 
622
622
  \`execution.result\` does not wait for judges. Await
623
623
  \`execution.evaluations\` when results must finish before process exit.
624
- Evaluations always finish during \`orcha test\`; judge errors and missed
624
+ Evaluations always finish during \`orchajs test\`; judge errors and missed
625
625
  thresholds fail the test. Lifecycle events are \`evaluation.requested\`,
626
626
  \`evaluation.completed\`, and \`evaluation.failed\`.
627
627
 
@@ -1027,7 +1027,7 @@ number. A conversational \`resume(...content)\` starts a new run number.
1027
1027
  Concrete action arguments and outputs are validated against their schemas
1028
1028
  when the action is used.
1029
1029
 
1030
- \`orcha dev\` repeats validation when files change. \`orcha build\` performs
1030
+ \`orchajs dev\` repeats validation when files change. \`orchajs build\` performs
1031
1031
  offline production compilation. Neither command invokes a provider.
1032
1032
 
1033
1033
  ### Run lifecycle
@@ -1106,7 +1106,7 @@ needed for faithful continuation but are omitted from evaluation transcripts.
1106
1106
  - Mock actions when tests must avoid side effects; document intentional live
1107
1107
  action coverage.
1108
1108
  - Do not commit \`.orcha/\`; it contains generated output and session data.
1109
- - Run \`orcha dev\` after filesystem changes and \`orcha test\` when behavior
1109
+ - Run \`orchajs dev\` after filesystem changes and \`orchajs test\` when behavior
1110
1110
  changes.
1111
1111
  - Do not weaken assertions to match incorrect behavior. Remove an assertion
1112
1112
  only when it is stricter than the documented agent contract.
@@ -31,6 +31,7 @@ var import_orcha = require("../orcha.js");
31
31
  var import_compiler_hook = require("../runtime/compiler-hook.js");
32
32
  var import_compile = require("./compile.js");
33
33
  var import_catalog = require("../providers/catalog.js");
34
+ var import_dependencies = require("../providers/dependencies.js");
34
35
  let registryImportSequence = 0;
35
36
  async function buildProject(options = {}) {
36
37
  const projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
@@ -45,7 +46,7 @@ async function buildProject(options = {}) {
45
46
  );
46
47
  const registryPath = (0, import_path.resolve)(projectRoot, "orcha/index.ts");
47
48
  if (!(0, import_fs.existsSync)(registryPath)) {
48
- throw new Error('Missing "orcha/index.ts". Run "orcha init" first.');
49
+ throw new Error('Missing "orcha/index.ts". Run "orchajs init" first.');
49
50
  }
50
51
  const temporaryDirectory = (0, import_path.resolve)(projectRoot, ".orcha/.build");
51
52
  const registryBundlePath = (0, import_path.resolve)(temporaryDirectory, "registry.mjs");
@@ -128,6 +129,7 @@ async function buildProject(options = {}) {
128
129
  )
129
130
  ];
130
131
  const providerRuntimeSource = createProviderRuntimeSource(includedProviders, target);
132
+ await (0, import_dependencies.ensureProviderDependencies)(includedProviders, projectRoot);
131
133
  const needsNodeRequire = compiledBundle.actionRuntime === "sandbox" || includedProviders.includes("vertexai") || includedProviders.includes("bedrock");
132
134
  await (0, import_promises.writeFile)(
133
135
  productionEntryPath,