orchajs 0.20.1 → 0.20.2

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
@@ -808,13 +808,29 @@ module.exports = {
808
808
  };
809
809
  ```
810
810
 
811
- Running `orcha build` separately is not enough: it creates
812
- `.orcha/dist/bundle.js`, but does not rewrite imports in already-built
813
- handlers.
811
+ For an unbundled production application built with plain `tsc` or
812
+ `serverless-plugin-typescript`, run:
814
813
 
815
- Production CI should package the same way as deployment and verify that:
814
+ ```bash
815
+ npx orcha build
816
+ ```
817
+
818
+ Package `.orcha/dist/manifest.json` with the application. AWS Lambda is
819
+ detected automatically; other unbundled environments should set
820
+ `NODE_ENV=production` or `ORCHA_USE_BUILD=1`. The normal `orchajs` import and
821
+ `orcha.init()` call then load the compiled manifest synchronously, so the
822
+ `orcha/` agent source folders do not need to be deployed.
823
+
824
+ This compatibility path still deploys the regular `orchajs` runtime and its
825
+ dependencies. Use the esbuild integration above when deployment size matters;
826
+ it replaces the package import with `.orcha/dist/bundle.js` and removes
827
+ compiler-only code.
828
+
829
+ Bundled production CI should package the same way as deployment and verify
830
+ that:
816
831
 
817
- - the build generated `.orcha/dist/bundle.js`;
832
+ - the build generated `.orcha/dist/bundle.js` and
833
+ `.orcha/dist/manifest.json`;
818
834
  - bundled handlers contain no unresolved bare `orchajs` import or require;
819
835
  - the deployment archive does not contain `node_modules/orchajs`.
820
836
 
@@ -15,6 +15,7 @@ export async function buildProject(options = {}) {
15
15
  const registryBundlePath = resolve(temporaryDirectory, "registry.mjs");
16
16
  const productionEntryPath = resolve(temporaryDirectory, "production-entry.mjs");
17
17
  const outputPath = resolve(projectRoot, ".orcha/dist/bundle.js");
18
+ const manifestPath = resolve(projectRoot, ".orcha/dist/manifest.json");
18
19
  await mkdir(temporaryDirectory, { recursive: true });
19
20
  await mkdir(dirname(outputPath), { recursive: true });
20
21
  try {
@@ -102,6 +103,7 @@ export async function buildProject(options = {}) {
102
103
  : {}),
103
104
  logLevel: "silent",
104
105
  });
106
+ await writeFile(manifestPath, `${JSON.stringify(compiledBundle)}\n`, "utf8");
105
107
  return outputPath;
106
108
  }
107
109
  finally {
package/dist/orcha.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { existsSync, readFileSync } from "node:fs";
1
2
  import { resolve } from "node:path";
2
3
  import { compileRegistry } from "./compiler/compile.js";
3
4
  import { generateProviderResponse } from "./providers/index.js";
@@ -8,13 +9,50 @@ setSandboxRuntimeLoader(async () => {
8
9
  return import(modulePath);
9
10
  });
10
11
  export const orcha = createOrcha((configuration) => {
11
- if (process.env.NODE_ENV === "production" &&
12
- process.env.ORCHA_COMPILING !== "1") {
13
- throw new Error("ORCHA_PRODUCTION_BUNDLE_MISSING: configure the Orcha integration in your application build.");
14
- }
15
12
  const projectRoot = resolve(configuration.root ??
16
13
  process.env.ORCHA_PROJECT_ROOT ??
17
14
  process.cwd());
15
+ if (process.env.ORCHA_COMPILING !== "1" &&
16
+ isPrecompiledRuntime()) {
17
+ return loadCompiledManifest(projectRoot, configuration);
18
+ }
18
19
  const registryRoot = resolve(projectRoot, "orcha");
19
20
  return compileRegistry(configuration.agents, registryRoot, configuration.actions?.runtime ?? "native");
20
21
  }, generateProviderResponse);
22
+ function isPrecompiledRuntime() {
23
+ return (process.env.ORCHA_USE_BUILD === "1" ||
24
+ process.env.NODE_ENV === "production" ||
25
+ process.env.AWS_LAMBDA_FUNCTION_NAME !== undefined ||
26
+ process.env.AWS_EXECUTION_ENV?.startsWith("AWS_Lambda_") === true);
27
+ }
28
+ function loadCompiledManifest(projectRoot, configuration) {
29
+ const manifestPath = resolve(projectRoot, ".orcha/dist/manifest.json");
30
+ if (!existsSync(manifestPath)) {
31
+ 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.`);
32
+ }
33
+ let parsed;
34
+ try {
35
+ parsed = JSON.parse(readFileSync(manifestPath, "utf8"));
36
+ }
37
+ catch (error) {
38
+ throw new Error(`Orcha could not read the compiled manifest at "${manifestPath}". Run "npx orcha build" again.`, { cause: error });
39
+ }
40
+ if (typeof parsed !== "object" ||
41
+ parsed === null ||
42
+ !("schemaVersion" in parsed) ||
43
+ parsed.schemaVersion !== 1 ||
44
+ !("agents" in parsed) ||
45
+ typeof parsed.agents !== "object" ||
46
+ parsed.agents === null ||
47
+ Array.isArray(parsed.agents)) {
48
+ throw new Error(`Orcha compiled manifest "${manifestPath}" is invalid. Run "npx orcha build" again.`);
49
+ }
50
+ const bundle = parsed;
51
+ const registeredAgents = Object.keys(configuration.agents).sort();
52
+ const compiledAgents = Object.keys(bundle.agents).sort();
53
+ if (registeredAgents.length !== compiledAgents.length ||
54
+ registeredAgents.some((name, index) => name !== compiledAgents[index])) {
55
+ throw new Error(`Orcha compiled manifest does not match the registered agents. Run "npx orcha build" again. Expected [${registeredAgents.join(", ")}], found [${compiledAgents.join(", ")}].`);
56
+ }
57
+ return bundle;
58
+ }
@@ -42,6 +42,10 @@ async function buildProject(options = {}) {
42
42
  "production-entry.mjs"
43
43
  );
44
44
  const outputPath = (0, import_path.resolve)(projectRoot, ".orcha/dist/bundle.js");
45
+ const manifestPath = (0, import_path.resolve)(
46
+ projectRoot,
47
+ ".orcha/dist/manifest.json"
48
+ );
45
49
  await (0, import_promises.mkdir)(temporaryDirectory, { recursive: true });
46
50
  await (0, import_promises.mkdir)((0, import_path.dirname)(outputPath), { recursive: true });
47
51
  try {
@@ -134,6 +138,12 @@ async function buildProject(options = {}) {
134
138
  } : {},
135
139
  logLevel: "silent"
136
140
  });
141
+ await (0, import_promises.writeFile)(
142
+ manifestPath,
143
+ `${JSON.stringify(compiledBundle)}
144
+ `,
145
+ "utf8"
146
+ );
137
147
  return outputPath;
138
148
  } finally {
139
149
  await (0, import_promises.rm)(temporaryDirectory, {
package/dist-cjs/orcha.js CHANGED
@@ -22,6 +22,7 @@ __export(orcha_exports, {
22
22
  orcha: () => orcha
23
23
  });
24
24
  module.exports = __toCommonJS(orcha_exports);
25
+ var import_fs = require("fs");
25
26
  var import_path = require("path");
26
27
  var import_compile = require("./compiler/compile.js");
27
28
  var import_providers = require("./providers/index.js");
@@ -33,14 +34,12 @@ var import_create_orcha = require("./runtime/create-orcha.js");
33
34
  });
34
35
  const orcha = (0, import_create_orcha.createOrcha)(
35
36
  (configuration) => {
36
- if (process.env.NODE_ENV === "production" && process.env.ORCHA_COMPILING !== "1") {
37
- throw new Error(
38
- "ORCHA_PRODUCTION_BUNDLE_MISSING: configure the Orcha integration in your application build."
39
- );
40
- }
41
37
  const projectRoot = (0, import_path.resolve)(
42
38
  configuration.root ?? process.env.ORCHA_PROJECT_ROOT ?? process.cwd()
43
39
  );
40
+ if (process.env.ORCHA_COMPILING !== "1" && isPrecompiledRuntime()) {
41
+ return loadCompiledManifest(projectRoot, configuration);
42
+ }
44
43
  const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
45
44
  return (0, import_compile.compileRegistry)(
46
45
  configuration.agents,
@@ -50,6 +49,45 @@ const orcha = (0, import_create_orcha.createOrcha)(
50
49
  },
51
50
  import_providers.generateProviderResponse
52
51
  );
52
+ function isPrecompiledRuntime() {
53
+ return process.env.ORCHA_USE_BUILD === "1" || process.env.NODE_ENV === "production" || process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0 || process.env.AWS_EXECUTION_ENV?.startsWith("AWS_Lambda_") === true;
54
+ }
55
+ function loadCompiledManifest(projectRoot, configuration) {
56
+ const manifestPath = (0, import_path.resolve)(
57
+ projectRoot,
58
+ ".orcha/dist/manifest.json"
59
+ );
60
+ if (!(0, import_fs.existsSync)(manifestPath)) {
61
+ throw new Error(
62
+ `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.`
63
+ );
64
+ }
65
+ let parsed;
66
+ try {
67
+ parsed = JSON.parse((0, import_fs.readFileSync)(manifestPath, "utf8"));
68
+ } catch (error) {
69
+ throw new Error(
70
+ `Orcha could not read the compiled manifest at "${manifestPath}". Run "npx orcha build" again.`,
71
+ { cause: error }
72
+ );
73
+ }
74
+ 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)) {
75
+ throw new Error(
76
+ `Orcha compiled manifest "${manifestPath}" is invalid. Run "npx orcha build" again.`
77
+ );
78
+ }
79
+ const bundle = parsed;
80
+ const registeredAgents = Object.keys(configuration.agents).sort();
81
+ const compiledAgents = Object.keys(bundle.agents).sort();
82
+ if (registeredAgents.length !== compiledAgents.length || registeredAgents.some(
83
+ (name, index) => name !== compiledAgents[index]
84
+ )) {
85
+ throw new Error(
86
+ `Orcha compiled manifest does not match the registered agents. Run "npx orcha build" again. Expected [${registeredAgents.join(", ")}], found [${compiledAgents.join(", ")}].`
87
+ );
88
+ }
89
+ return bundle;
90
+ }
53
91
  // Annotate the CommonJS export names for ESM import in node:
54
92
  0 && (module.exports = {
55
93
  orcha
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchajs",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "description": "A filesystem-convention, stateful agent framework for JavaScript.",
5
5
  "license": "MIT",
6
6
  "repository": {