orchajs 0.20.0 → 0.20.1

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.
@@ -52,6 +52,9 @@ export async function buildProject(options = {}) {
52
52
  const compiledBundle = orcha.getCompiledBundle();
53
53
  const runtimeFactoryPath = resolve(dirname(fileURLToPath(import.meta.url)), "../runtime/create-orcha.js").replaceAll("\\", "/");
54
54
  const providerDispatcherPath = resolve(dirname(fileURLToPath(import.meta.url)), "../providers/dispatcher.js").replaceAll("\\", "/");
55
+ const sandboxRuntimeSource = compiledBundle.actionRuntime === "sandbox"
56
+ ? createSandboxRuntimeSource()
57
+ : "";
55
58
  const includedProviders = [
56
59
  ...new Set(allCompiledAgents(compiledBundle.agents).flatMap((agent) => [
57
60
  agent.provider,
@@ -68,6 +71,7 @@ export async function buildProject(options = {}) {
68
71
  `import { createOrcha } from ${JSON.stringify(runtimeFactoryPath)};`,
69
72
  `import { createProviderResponseGenerator } from ${JSON.stringify(providerDispatcherPath)};`,
70
73
  providerRuntimeSource,
74
+ sandboxRuntimeSource,
71
75
  `const compiledBundle = ${JSON.stringify(compiledBundle)};`,
72
76
  "const generateProviderResponse = createProviderResponseGenerator(includedProviders);",
73
77
  "export const orcha = createOrcha(() => compiledBundle, generateProviderResponse);",
@@ -107,6 +111,17 @@ export async function buildProject(options = {}) {
107
111
  });
108
112
  }
109
113
  }
114
+ function createSandboxRuntimeSource() {
115
+ const runtimeDirectory = dirname(fileURLToPath(import.meta.url));
116
+ const executePath = resolve(runtimeDirectory, "../runtime/actions/execute.js").replaceAll("\\", "/");
117
+ const sandboxPath = resolve(runtimeDirectory, "../runtime/actions/sandbox.js").replaceAll("\\", "/");
118
+ return [
119
+ `import { setSandboxRuntimeLoader } from ${JSON.stringify(executePath)};`,
120
+ `import { executeSandboxedAction } from ${JSON.stringify(sandboxPath)};`,
121
+ "setSandboxRuntimeLoader(async () => ({ executeSandboxedAction }));",
122
+ "",
123
+ ].join("\n");
124
+ }
110
125
  function allCompiledAgents(agents) {
111
126
  return Object.values(agents).flatMap((agent) => [
112
127
  agent,
package/dist/orcha.js CHANGED
@@ -1,7 +1,12 @@
1
1
  import { resolve } from "node:path";
2
2
  import { compileRegistry } from "./compiler/compile.js";
3
3
  import { generateProviderResponse } from "./providers/index.js";
4
+ import { setSandboxRuntimeLoader } from "./runtime/actions/execute.js";
4
5
  import { createOrcha } from "./runtime/create-orcha.js";
6
+ setSandboxRuntimeLoader(async () => {
7
+ const modulePath = "./runtime/actions/sandbox.js";
8
+ return import(modulePath);
9
+ });
5
10
  export const orcha = createOrcha((configuration) => {
6
11
  if (process.env.NODE_ENV === "production" &&
7
12
  process.env.ORCHA_COMPILING !== "1") {
@@ -1,4 +1,8 @@
1
1
  import type { CompiledActionManifest, LocalActionRuntimeConfiguration, SessionMetadata } from "../../types.js";
2
+ type SandboxRuntime = typeof import("./sandbox.js");
3
+ type SandboxRuntimeLoader = () => Promise<SandboxRuntime>;
4
+ /** @internal Supplies the statically bundled sandbox in production builds. */
5
+ export declare function setSandboxRuntimeLoader(loader: SandboxRuntimeLoader): void;
2
6
  export declare function executeLocalAction(options: {
3
7
  action: CompiledActionManifest;
4
8
  parameters: Record<string, unknown>;
@@ -7,3 +11,4 @@ export declare function executeLocalAction(options: {
7
11
  metadata: SessionMetadata;
8
12
  idempotencyKey: string;
9
13
  }): Promise<unknown>;
14
+ export {};
@@ -1,5 +1,12 @@
1
1
  import { createLocalActionContext } from "./context.js";
2
2
  import { executeNativeAction } from "./native.js";
3
+ let loadConfiguredSandboxRuntime = async () => {
4
+ throw new Error("The QuickJS sandbox runtime was not included in this Orcha build.");
5
+ };
6
+ /** @internal Supplies the statically bundled sandbox in production builds. */
7
+ export function setSandboxRuntimeLoader(loader) {
8
+ loadConfiguredSandboxRuntime = loader;
9
+ }
3
10
  export async function executeLocalAction(options) {
4
11
  const context = createLocalActionContext(options);
5
12
  if (options.configuration.runtime === "native") {
@@ -13,7 +20,7 @@ export async function executeLocalAction(options) {
13
20
  }
14
21
  async function loadSandboxRuntime() {
15
22
  try {
16
- return await import("./sandbox.js");
23
+ return await loadConfiguredSandboxRuntime();
17
24
  }
18
25
  catch (error) {
19
26
  if (error instanceof Error &&
@@ -82,6 +82,7 @@ async function buildProject(options = {}) {
82
82
  (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
83
83
  "../providers/dispatcher.js"
84
84
  ).replaceAll("\\", "/");
85
+ const sandboxRuntimeSource = compiledBundle.actionRuntime === "sandbox" ? createSandboxRuntimeSource() : "";
85
86
  const includedProviders = [
86
87
  ...new Set(
87
88
  allCompiledAgents(compiledBundle.agents).flatMap(
@@ -100,6 +101,7 @@ async function buildProject(options = {}) {
100
101
  `import { createOrcha } from ${JSON.stringify(runtimeFactoryPath)};`,
101
102
  `import { createProviderResponseGenerator } from ${JSON.stringify(providerDispatcherPath)};`,
102
103
  providerRuntimeSource,
104
+ sandboxRuntimeSource,
103
105
  `const compiledBundle = ${JSON.stringify(compiledBundle)};`,
104
106
  "const generateProviderResponse = createProviderResponseGenerator(includedProviders);",
105
107
  "export const orcha = createOrcha(() => compiledBundle, generateProviderResponse);",
@@ -140,6 +142,23 @@ async function buildProject(options = {}) {
140
142
  });
141
143
  }
142
144
  }
145
+ function createSandboxRuntimeSource() {
146
+ const runtimeDirectory = (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl));
147
+ const executePath = (0, import_path.resolve)(
148
+ runtimeDirectory,
149
+ "../runtime/actions/execute.js"
150
+ ).replaceAll("\\", "/");
151
+ const sandboxPath = (0, import_path.resolve)(
152
+ runtimeDirectory,
153
+ "../runtime/actions/sandbox.js"
154
+ ).replaceAll("\\", "/");
155
+ return [
156
+ `import { setSandboxRuntimeLoader } from ${JSON.stringify(executePath)};`,
157
+ `import { executeSandboxedAction } from ${JSON.stringify(sandboxPath)};`,
158
+ "setSandboxRuntimeLoader(async () => ({ executeSandboxedAction }));",
159
+ ""
160
+ ].join("\n");
161
+ }
143
162
  function allCompiledAgents(agents) {
144
163
  return Object.values(agents).flatMap((agent) => [
145
164
  agent,
package/dist-cjs/orcha.js CHANGED
@@ -25,7 +25,12 @@ module.exports = __toCommonJS(orcha_exports);
25
25
  var import_path = require("path");
26
26
  var import_compile = require("./compiler/compile.js");
27
27
  var import_providers = require("./providers/index.js");
28
+ var import_execute = require("./runtime/actions/execute.js");
28
29
  var import_create_orcha = require("./runtime/create-orcha.js");
30
+ (0, import_execute.setSandboxRuntimeLoader)(async () => {
31
+ const modulePath = "./runtime/actions/sandbox.js";
32
+ return import(modulePath);
33
+ });
29
34
  const orcha = (0, import_create_orcha.createOrcha)(
30
35
  (configuration) => {
31
36
  if (process.env.NODE_ENV === "production" && process.env.ORCHA_COMPILING !== "1") {
@@ -1,10 +1,8 @@
1
1
  "use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
2
2
  "use strict";
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
7
  var __export = (target, all) => {
10
8
  for (var name in all)
@@ -18,22 +16,23 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
  var execute_exports = {};
31
21
  __export(execute_exports, {
32
- executeLocalAction: () => executeLocalAction
22
+ executeLocalAction: () => executeLocalAction,
23
+ setSandboxRuntimeLoader: () => setSandboxRuntimeLoader
33
24
  });
34
25
  module.exports = __toCommonJS(execute_exports);
35
26
  var import_context = require("./context.js");
36
27
  var import_native = require("./native.js");
28
+ let loadConfiguredSandboxRuntime = async () => {
29
+ throw new Error(
30
+ "The QuickJS sandbox runtime was not included in this Orcha build."
31
+ );
32
+ };
33
+ function setSandboxRuntimeLoader(loader) {
34
+ loadConfiguredSandboxRuntime = loader;
35
+ }
37
36
  async function executeLocalAction(options) {
38
37
  const context = (0, import_context.createLocalActionContext)(options);
39
38
  if (options.configuration.runtime === "native") {
@@ -54,7 +53,7 @@ async function executeLocalAction(options) {
54
53
  }
55
54
  async function loadSandboxRuntime() {
56
55
  try {
57
- return await import("./sandbox.js");
56
+ return await loadConfiguredSandboxRuntime();
58
57
  } catch (error) {
59
58
  if (error instanceof Error && (error.message.includes("quickjs-emscripten-core") || error.message.includes(
60
59
  "@jitl/quickjs-singlefile-cjs-release-sync"
@@ -69,5 +68,6 @@ async function loadSandboxRuntime() {
69
68
  }
70
69
  // Annotate the CommonJS export names for ESM import in node:
71
70
  0 && (module.exports = {
72
- executeLocalAction
71
+ executeLocalAction,
72
+ setSandboxRuntimeLoader
73
73
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchajs",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "description": "A filesystem-convention, stateful agent framework for JavaScript.",
5
5
  "license": "MIT",
6
6
  "repository": {