orchajs 0.23.11 → 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/README.md +19 -19
- package/dist/bin.js +11 -84
- package/dist/cli-agents-template.d.ts +1 -1
- package/dist/cli-agents-template.js +18 -18
- package/dist/cli.js +11 -11
- package/dist/compiler/build-project.js +3 -1
- package/dist/initialize-project.js +1 -1
- package/dist/orcha.js +5 -5
- package/dist/package-manager.d.ts +10 -0
- package/dist/package-manager.js +78 -0
- package/dist/project-loader.js +3 -1
- package/dist/providers/dependencies.d.ts +3 -0
- package/dist/providers/dependencies.js +99 -0
- package/dist-cjs/cli-agents-template.js +18 -18
- package/dist-cjs/compiler/build-project.js +3 -1
- package/dist-cjs/initialize-project.js +1 -1
- package/dist-cjs/orcha.js +5 -5
- package/dist-cjs/package-manager.js +109 -0
- package/dist-cjs/project-loader.js +6 -1
- package/dist-cjs/providers/dependencies.js +145 -0
- package/package.json +2 -1
|
@@ -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 "
|
|
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");
|
|
@@ -49,7 +49,7 @@ export async function initializeProject(projectRoot) {
|
|
|
49
49
|
console.log(`Created ${relativePath}`);
|
|
50
50
|
}
|
|
51
51
|
await ensureGitignore(projectRoot);
|
|
52
|
-
console.log('\nRun "
|
|
52
|
+
console.log('\nRun "orchajs dev" to validate changes or "orchajs run exampleAgent --input \\"Hello\\"" to execute the agent.');
|
|
53
53
|
}
|
|
54
54
|
async function ensureGitignore(projectRoot) {
|
|
55
55
|
const path = resolve(projectRoot, ".gitignore");
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
+
}
|
package/dist/project-loader.js
CHANGED
|
@@ -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 "
|
|
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
|
-
- \`
|
|
34
|
-
- \`
|
|
35
|
-
- \`
|
|
36
|
-
- \`
|
|
37
|
-
- \`
|
|
38
|
-
- \`
|
|
39
|
-
- \`
|
|
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
|
-
- \`
|
|
42
|
-
- \`
|
|
43
|
-
- \`
|
|
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
|
-
- \`
|
|
45
|
+
- \`orchajs export-session <agent> <sessionId> [--output <path>]\` exports one
|
|
46
46
|
session from the active store as JSONL.
|
|
47
|
-
- \`
|
|
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
|
-
\`
|
|
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 \`
|
|
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 \`
|
|
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 \`
|
|
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
|
-
\`
|
|
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 \`
|
|
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 "
|
|
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,
|
|
@@ -79,7 +79,7 @@ async function initializeProject(projectRoot) {
|
|
|
79
79
|
}
|
|
80
80
|
await ensureGitignore(projectRoot);
|
|
81
81
|
console.log(
|
|
82
|
-
'\nRun "
|
|
82
|
+
'\nRun "orchajs dev" to validate changes or "orchajs run exampleAgent --input \\"Hello\\"" to execute the agent.'
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
async function ensureGitignore(projectRoot) {
|
package/dist-cjs/orcha.js
CHANGED
|
@@ -48,7 +48,7 @@ const orcha = (0, import_create_orcha.createOrcha)(
|
|
|
48
48
|
return loadCompiledManifest(projectRoot, configuration);
|
|
49
49
|
}
|
|
50
50
|
throw new Error(
|
|
51
|
-
'Orcha agents must be compiled before runtime initialization. Run "npx
|
|
51
|
+
'Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.'
|
|
52
52
|
);
|
|
53
53
|
},
|
|
54
54
|
import_providers.generateProviderResponse,
|
|
@@ -61,7 +61,7 @@ function loadCompiledManifest(projectRoot, configuration) {
|
|
|
61
61
|
const manifestPath = compiledManifestPath(projectRoot);
|
|
62
62
|
if (!(0, import_fs.existsSync)(manifestPath)) {
|
|
63
63
|
throw new Error(
|
|
64
|
-
`ORCHA_PRODUCTION_BUNDLE_MISSING: "${manifestPath}" was not found. Run "npx
|
|
64
|
+
`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.`
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
let parsed;
|
|
@@ -69,13 +69,13 @@ function loadCompiledManifest(projectRoot, configuration) {
|
|
|
69
69
|
parsed = JSON.parse((0, import_fs.readFileSync)(manifestPath, "utf8"));
|
|
70
70
|
} catch (error) {
|
|
71
71
|
throw new Error(
|
|
72
|
-
`Orcha could not read the compiled manifest at "${manifestPath}". Run "npx
|
|
72
|
+
`Orcha could not read the compiled manifest at "${manifestPath}". Run "npx orchajs build" again.`,
|
|
73
73
|
{ cause: error }
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
76
|
if (typeof parsed !== "object" || parsed === null || !("schemaVersion" in parsed) || parsed.schemaVersion !== 1 || !("agents" in parsed) || typeof parsed.agents !== "object" || parsed.agents === null || Array.isArray(parsed.agents)) {
|
|
77
77
|
throw new Error(
|
|
78
|
-
`Orcha compiled manifest "${manifestPath}" is invalid. Run "npx
|
|
78
|
+
`Orcha compiled manifest "${manifestPath}" is invalid. Run "npx orchajs build" again.`
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
81
|
const bundle = parsed;
|
|
@@ -85,7 +85,7 @@ function loadCompiledManifest(projectRoot, configuration) {
|
|
|
85
85
|
(name, index) => name !== compiledAgents[index]
|
|
86
86
|
)) {
|
|
87
87
|
throw new Error(
|
|
88
|
-
`Orcha compiled manifest does not match the registered agents. Run "npx
|
|
88
|
+
`Orcha compiled manifest does not match the registered agents. Run "npx orchajs build" again. Expected [${registeredAgents.join(", ")}], found [${compiledAgents.join(", ")}].`
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
91
|
return bundle;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var package_manager_exports = {};
|
|
21
|
+
__export(package_manager_exports, {
|
|
22
|
+
detectPackageManager: () => detectPackageManager,
|
|
23
|
+
installCommand: () => installCommand,
|
|
24
|
+
runPackageManager: () => runPackageManager
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(package_manager_exports);
|
|
27
|
+
var import_child_process = require("child_process");
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
function detectPackageManager(projectRoot = process.cwd()) {
|
|
31
|
+
if ((0, import_fs.existsSync)((0, import_path.resolve)(projectRoot, "yarn.lock"))) {
|
|
32
|
+
return "yarn";
|
|
33
|
+
}
|
|
34
|
+
if ((0, import_fs.existsSync)((0, import_path.resolve)(projectRoot, "pnpm-lock.yaml"))) {
|
|
35
|
+
return "pnpm";
|
|
36
|
+
}
|
|
37
|
+
if ((0, import_fs.existsSync)((0, import_path.resolve)(projectRoot, "bun.lock")) || (0, import_fs.existsSync)((0, import_path.resolve)(projectRoot, "bun.lockb"))) {
|
|
38
|
+
return "bun";
|
|
39
|
+
}
|
|
40
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
41
|
+
if (userAgent?.startsWith("yarn/")) {
|
|
42
|
+
return "yarn";
|
|
43
|
+
}
|
|
44
|
+
if (userAgent?.startsWith("pnpm/")) {
|
|
45
|
+
return "pnpm";
|
|
46
|
+
}
|
|
47
|
+
if (userAgent?.startsWith("bun/")) {
|
|
48
|
+
return "bun";
|
|
49
|
+
}
|
|
50
|
+
return "npm";
|
|
51
|
+
}
|
|
52
|
+
function installCommand(packageManager, packages, development) {
|
|
53
|
+
switch (packageManager) {
|
|
54
|
+
case "yarn":
|
|
55
|
+
return {
|
|
56
|
+
command: executable("yarn"),
|
|
57
|
+
arguments: ["add", ...development ? ["--dev"] : [], ...packages]
|
|
58
|
+
};
|
|
59
|
+
case "pnpm":
|
|
60
|
+
return {
|
|
61
|
+
command: executable("pnpm"),
|
|
62
|
+
arguments: [
|
|
63
|
+
"add",
|
|
64
|
+
...development ? ["--save-dev"] : [],
|
|
65
|
+
...packages
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
case "bun":
|
|
69
|
+
return {
|
|
70
|
+
command: executable("bun"),
|
|
71
|
+
arguments: ["add", ...development ? ["--dev"] : [], ...packages]
|
|
72
|
+
};
|
|
73
|
+
default:
|
|
74
|
+
return {
|
|
75
|
+
command: executable("npm"),
|
|
76
|
+
arguments: [
|
|
77
|
+
"install",
|
|
78
|
+
...development ? ["--save-dev"] : [],
|
|
79
|
+
...packages
|
|
80
|
+
]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function runPackageManager(command, arguments_, options = {}) {
|
|
85
|
+
return new Promise((resolveProcess, reject) => {
|
|
86
|
+
const child = (0, import_child_process.spawn)(command, arguments_, {
|
|
87
|
+
cwd: options.cwd ?? process.cwd(),
|
|
88
|
+
env: options.env ?? process.env,
|
|
89
|
+
stdio: "inherit"
|
|
90
|
+
});
|
|
91
|
+
child.once("error", reject);
|
|
92
|
+
child.once("exit", (code, signal) => {
|
|
93
|
+
if (signal) {
|
|
94
|
+
process.kill(process.pid, signal);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
resolveProcess(code ?? 1);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function executable(command) {
|
|
102
|
+
return process.platform === "win32" ? `${command}.cmd` : command;
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
detectPackageManager,
|
|
107
|
+
installCommand,
|
|
108
|
+
runPackageManager
|
|
109
|
+
});
|
|
@@ -30,6 +30,7 @@ var import_esbuild = require("esbuild");
|
|
|
30
30
|
var import_compile = require("./compiler/compile.js");
|
|
31
31
|
var import_env = require("./env.js");
|
|
32
32
|
var import_orcha = require("./orcha.js");
|
|
33
|
+
var import_dependencies = require("./providers/dependencies.js");
|
|
33
34
|
var import_compiler_hook = require("./runtime/compiler-hook.js");
|
|
34
35
|
async function loadProject(projectRoot) {
|
|
35
36
|
(0, import_compiler_hook.setRegistryCompiler)(
|
|
@@ -43,7 +44,7 @@ async function loadProject(projectRoot) {
|
|
|
43
44
|
(0, import_env.loadProjectEnvironment)(projectRoot);
|
|
44
45
|
const registryPath = (0, import_path.resolve)(projectRoot, "orcha/index.ts");
|
|
45
46
|
if (!(0, import_fs.existsSync)(registryPath)) {
|
|
46
|
-
throw new Error('Missing "orcha/index.ts". Run "
|
|
47
|
+
throw new Error('Missing "orcha/index.ts". Run "orchajs init" first.');
|
|
47
48
|
}
|
|
48
49
|
const temporaryDirectory = (0, import_path.resolve)(projectRoot, ".orcha/.cli");
|
|
49
50
|
const bundlePath = (0, import_path.resolve)(
|
|
@@ -78,6 +79,10 @@ async function loadProject(projectRoot) {
|
|
|
78
79
|
'"orcha/index.ts" must call orcha.init({ providers, agents }).'
|
|
79
80
|
);
|
|
80
81
|
}
|
|
82
|
+
await (0, import_dependencies.ensureCompiledProviderDependencies)(
|
|
83
|
+
import_orcha.orcha.getCompiledBundle(),
|
|
84
|
+
projectRoot
|
|
85
|
+
);
|
|
81
86
|
} finally {
|
|
82
87
|
await (0, import_promises.rm)(bundlePath, { force: true });
|
|
83
88
|
}
|