orchajs 0.20.3 → 0.22.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.
Files changed (107) hide show
  1. package/README.md +103 -0
  2. package/dist/amarsia/analytics.d.ts +21 -0
  3. package/dist/amarsia/analytics.js +457 -0
  4. package/dist/amarsia/endpoint.d.ts +1 -0
  5. package/dist/amarsia/endpoint.js +8 -0
  6. package/dist/amarsia/sync.js +1 -4
  7. package/dist/bin.d.ts +2 -0
  8. package/dist/bin.js +13 -0
  9. package/dist/browser.d.ts +2 -0
  10. package/dist/browser.js +12 -0
  11. package/dist/cli.js +35 -9
  12. package/dist/compiler/build-project.d.ts +1 -0
  13. package/dist/compiler/build-project.js +75 -8
  14. package/dist/compiler/compile.d.ts +1 -1
  15. package/dist/compiler/compile.js +11 -9
  16. package/dist/errors.d.ts +5 -0
  17. package/dist/errors.js +102 -0
  18. package/dist/file-content.js +42 -6
  19. package/dist/index.d.ts +1 -5
  20. package/dist/index.js +1 -2
  21. package/dist/integrations/esbuild.js +5 -2
  22. package/dist/integrations/expo.d.ts +1 -0
  23. package/dist/integrations/expo.js +1 -0
  24. package/dist/integrations/metro.d.ts +15 -0
  25. package/dist/integrations/metro.js +25 -0
  26. package/dist/integrations/next.d.ts +23 -0
  27. package/dist/integrations/next.js +53 -0
  28. package/dist/integrations/runtime-build.d.ts +4 -0
  29. package/dist/integrations/runtime-build.js +32 -0
  30. package/dist/integrations/vite.d.ts +23 -0
  31. package/dist/integrations/vite.js +32 -0
  32. package/dist/integrations/webpack.d.ts +24 -0
  33. package/dist/integrations/webpack.js +21 -0
  34. package/dist/orcha.js +17 -8
  35. package/dist/playground/server.js +57 -7
  36. package/dist/project-loader.js +3 -0
  37. package/dist/providers/browser.d.ts +2 -0
  38. package/dist/providers/browser.js +20 -0
  39. package/dist/react-native.d.ts +2 -0
  40. package/dist/react-native.js +12 -0
  41. package/dist/runtime/actions/browser-native.d.ts +3 -0
  42. package/dist/runtime/actions/browser-native.js +28 -0
  43. package/dist/runtime/actions/execute.d.ts +7 -0
  44. package/dist/runtime/actions/execute.js +9 -2
  45. package/dist/runtime/agent.d.ts +1 -0
  46. package/dist/runtime/agent.js +38 -10
  47. package/dist/runtime/compiler-hook.d.ts +5 -0
  48. package/dist/runtime/compiler-hook.js +8 -0
  49. package/dist/runtime/create-orcha.d.ts +6 -1
  50. package/dist/runtime/create-orcha.js +35 -21
  51. package/dist/runtime/platform-browser.d.ts +2 -0
  52. package/dist/runtime/platform-browser.js +15 -0
  53. package/dist/runtime/platform-node.d.ts +2 -0
  54. package/dist/runtime/platform-node.js +31 -0
  55. package/dist/runtime/platform-react-native.d.ts +2 -0
  56. package/dist/runtime/platform-react-native.js +15 -0
  57. package/dist/runtime/platform.d.ts +15 -0
  58. package/dist/runtime/platform.js +1 -0
  59. package/dist/runtime/random-id.d.ts +1 -0
  60. package/dist/runtime/random-id.js +26 -0
  61. package/dist/runtime-entry.d.ts +5 -0
  62. package/dist/runtime-entry.js +2 -0
  63. package/dist/storage/browser-indexeddb.d.ts +7 -16
  64. package/dist/storage/browser-indexeddb.js +102 -19
  65. package/dist/storage/react-native-jsonl.d.ts +7 -16
  66. package/dist/storage/react-native-jsonl.js +65 -19
  67. package/dist/types.d.ts +54 -1
  68. package/dist-cjs/amarsia/analytics.js +447 -0
  69. package/dist-cjs/amarsia/endpoint.js +32 -0
  70. package/dist-cjs/amarsia/sync.js +2 -5
  71. package/dist-cjs/browser.js +48 -0
  72. package/dist-cjs/compiler/build-project.js +97 -8
  73. package/dist-cjs/compiler/compile.js +17 -9
  74. package/dist-cjs/errors.js +92 -2
  75. package/dist-cjs/file-content.js +42 -7
  76. package/dist-cjs/index.js +4 -9
  77. package/dist-cjs/integrations/esbuild.js +6 -2
  78. package/dist-cjs/integrations/expo.js +29 -0
  79. package/dist-cjs/integrations/metro.js +51 -0
  80. package/dist-cjs/integrations/next.js +75 -0
  81. package/dist-cjs/integrations/runtime-build.js +70 -0
  82. package/dist-cjs/integrations/vite.js +57 -0
  83. package/dist-cjs/integrations/webpack.js +51 -0
  84. package/dist-cjs/orcha.js +17 -12
  85. package/dist-cjs/playground/server.js +62 -9
  86. package/dist-cjs/project-loader.js +10 -0
  87. package/dist-cjs/providers/browser.js +61 -0
  88. package/dist-cjs/react-native.js +48 -0
  89. package/dist-cjs/runtime/actions/browser-native.js +68 -0
  90. package/dist-cjs/runtime/actions/execute.js +12 -2
  91. package/dist-cjs/runtime/agent.js +37 -14
  92. package/dist-cjs/runtime/compiler-hook.js +37 -0
  93. package/dist-cjs/runtime/create-orcha.js +34 -23
  94. package/dist-cjs/runtime/platform-browser.js +48 -0
  95. package/dist-cjs/runtime/platform-node.js +59 -0
  96. package/dist-cjs/runtime/platform-react-native.js +45 -0
  97. package/dist-cjs/runtime/platform.js +17 -0
  98. package/dist-cjs/runtime/random-id.js +55 -0
  99. package/dist-cjs/runtime-entry.js +34 -0
  100. package/dist-cjs/storage/browser-indexeddb.js +102 -5
  101. package/dist-cjs/storage/react-native-jsonl.js +73 -5
  102. package/dist-cjs/types/react-native-async-storage.d.js +2 -0
  103. package/package.json +69 -9
  104. package/dist/playground/public/app.css +0 -1
  105. package/dist/playground/public/app.js +0 -31
  106. package/dist/playground/public/index.html +0 -15
  107. package/dist/playground/public/orcha-logo.svg +0 -4
@@ -0,0 +1,75 @@
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 next_exports = {};
21
+ __export(next_exports, {
22
+ withOrcha: () => withOrcha
23
+ });
24
+ module.exports = __toCommonJS(next_exports);
25
+ var import_path = require("path");
26
+ var import_runtime_build = require("./runtime-build.js");
27
+ var import_webpack = require("./webpack.js");
28
+ async function withOrcha(configuration = {}, options = {}) {
29
+ const projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
30
+ await (0, import_runtime_build.queueRuntimeBuild)(projectRoot, "browser");
31
+ await (0, import_runtime_build.queueRuntimeBuild)(projectRoot, "node");
32
+ if (process.env.NODE_ENV !== "production") {
33
+ (0, import_runtime_build.watchRuntimeTargets)(projectRoot, ["browser", "node"]);
34
+ }
35
+ const existingWebpack = configuration.webpack;
36
+ return {
37
+ ...configuration,
38
+ turbopack: {
39
+ ...configuration.turbopack,
40
+ resolveAlias: {
41
+ ...configuration.turbopack?.resolveAlias,
42
+ orchajs: {
43
+ browser: (0, import_runtime_build.generatedBundlePath)(projectRoot, "browser")
44
+ }
45
+ }
46
+ },
47
+ webpack(webpackConfiguration, context) {
48
+ const target = nextTarget(context);
49
+ if (target === "node") {
50
+ return existingWebpack ? existingWebpack(webpackConfiguration, context) : webpackConfiguration;
51
+ }
52
+ const plugin = new import_webpack.OrchaWebpackPlugin({
53
+ projectRoot,
54
+ target
55
+ });
56
+ webpackConfiguration.resolve ??= {};
57
+ webpackConfiguration.resolve.alias = {
58
+ ...webpackConfiguration.resolve.alias,
59
+ orchajs$: plugin.bundlePath
60
+ };
61
+ webpackConfiguration.plugins = [
62
+ ...webpackConfiguration.plugins ?? [],
63
+ plugin
64
+ ];
65
+ return existingWebpack ? existingWebpack(webpackConfiguration, context) : webpackConfiguration;
66
+ }
67
+ };
68
+ }
69
+ function nextTarget(context) {
70
+ return context.isServer && context.nextRuntime !== "edge" ? "node" : "browser";
71
+ }
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ withOrcha
75
+ });
@@ -0,0 +1,70 @@
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 runtime_build_exports = {};
21
+ __export(runtime_build_exports, {
22
+ generatedBundlePath: () => generatedBundlePath,
23
+ queueRuntimeBuild: () => queueRuntimeBuild,
24
+ watchRuntimeTargets: () => watchRuntimeTargets
25
+ });
26
+ module.exports = __toCommonJS(runtime_build_exports);
27
+ var import_path = require("path");
28
+ var import_chokidar = require("chokidar");
29
+ var import_build_project = require("../compiler/build-project.js");
30
+ var import_env = require("../env.js");
31
+ let buildQueue = Promise.resolve();
32
+ const watchedTargets = /* @__PURE__ */ new Set();
33
+ function generatedBundlePath(projectRoot, target) {
34
+ const fileName = target === "node" ? "bundle.js" : `bundle.${target}.js`;
35
+ return (0, import_path.resolve)(projectRoot, ".orcha/dist", fileName);
36
+ }
37
+ function queueRuntimeBuild(projectRoot, target) {
38
+ const build = buildQueue.then(async () => {
39
+ (0, import_env.loadProjectEnvironment)(projectRoot);
40
+ await (0, import_build_project.buildProject)({ projectRoot, target });
41
+ });
42
+ buildQueue = build.catch(() => void 0);
43
+ return build;
44
+ }
45
+ function watchRuntimeTargets(projectRoot, targets) {
46
+ const key = `${projectRoot}:${targets.join(",")}`;
47
+ if (watchedTargets.has(key)) {
48
+ return;
49
+ }
50
+ watchedTargets.add(key);
51
+ let timer;
52
+ (0, import_chokidar.watch)((0, import_path.resolve)(projectRoot, "orcha"), { ignoreInitial: true }).on(
53
+ "all",
54
+ () => {
55
+ clearTimeout(timer);
56
+ timer = setTimeout(() => {
57
+ void targets.reduce(
58
+ (pending, target) => pending.then(() => queueRuntimeBuild(projectRoot, target)),
59
+ Promise.resolve()
60
+ );
61
+ }, 75);
62
+ }
63
+ );
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ generatedBundlePath,
68
+ queueRuntimeBuild,
69
+ watchRuntimeTargets
70
+ });
@@ -0,0 +1,57 @@
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 vite_exports = {};
21
+ __export(vite_exports, {
22
+ orchaVitePlugin: () => orchaVitePlugin
23
+ });
24
+ module.exports = __toCommonJS(vite_exports);
25
+ var import_path = require("path");
26
+ var import_runtime_build = require("./runtime-build.js");
27
+ function orchaVitePlugin(options = {}) {
28
+ let projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
29
+ return {
30
+ name: "orchajs",
31
+ enforce: "pre",
32
+ configResolved(config) {
33
+ projectRoot = (0, import_path.resolve)(options.projectRoot ?? config.root);
34
+ },
35
+ async buildStart() {
36
+ await (0, import_runtime_build.queueRuntimeBuild)(projectRoot, "browser");
37
+ },
38
+ configureServer(server) {
39
+ const registryDirectory = (0, import_path.resolve)(projectRoot, "orcha");
40
+ server.watcher.add(registryDirectory);
41
+ server.watcher.on("all", (_event, path) => {
42
+ if (path === registryDirectory || path.startsWith(`${registryDirectory}${import_path.sep}`)) {
43
+ void (0, import_runtime_build.queueRuntimeBuild)(projectRoot, "browser").then(() => {
44
+ server.ws.send({ type: "full-reload" });
45
+ });
46
+ }
47
+ });
48
+ },
49
+ resolveId(source) {
50
+ return source === "orchajs" ? (0, import_runtime_build.generatedBundlePath)(projectRoot, "browser") : void 0;
51
+ }
52
+ };
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ orchaVitePlugin
57
+ });
@@ -0,0 +1,51 @@
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 webpack_exports = {};
21
+ __export(webpack_exports, {
22
+ OrchaWebpackPlugin: () => OrchaWebpackPlugin
23
+ });
24
+ module.exports = __toCommonJS(webpack_exports);
25
+ var import_path = require("path");
26
+ var import_runtime_build = require("./runtime-build.js");
27
+ class OrchaWebpackPlugin {
28
+ #projectRoot;
29
+ #target;
30
+ constructor(options = {}) {
31
+ this.#projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
32
+ this.#target = options.target ?? "browser";
33
+ }
34
+ get bundlePath() {
35
+ return (0, import_runtime_build.generatedBundlePath)(this.#projectRoot, this.#target);
36
+ }
37
+ apply(compiler) {
38
+ compiler.hooks.beforeCompile.tapPromise("orchajs", async () => {
39
+ await (0, import_runtime_build.queueRuntimeBuild)(this.#projectRoot, this.#target);
40
+ });
41
+ compiler.hooks.afterCompile.tap("orchajs", (compilation) => {
42
+ compilation.contextDependencies.add(
43
+ (0, import_path.resolve)(this.#projectRoot, "orcha")
44
+ );
45
+ });
46
+ }
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ OrchaWebpackPlugin
51
+ });
package/dist-cjs/orcha.js CHANGED
@@ -24,10 +24,13 @@ __export(orcha_exports, {
24
24
  module.exports = __toCommonJS(orcha_exports);
25
25
  var import_fs = require("fs");
26
26
  var import_path = require("path");
27
- var import_compile = require("./compiler/compile.js");
28
27
  var import_providers = require("./providers/index.js");
29
28
  var import_execute = require("./runtime/actions/execute.js");
29
+ var import_native = require("./runtime/actions/native.js");
30
+ var import_compiler_hook = require("./runtime/compiler-hook.js");
30
31
  var import_create_orcha = require("./runtime/create-orcha.js");
32
+ var import_platform_node = require("./runtime/platform-node.js");
33
+ (0, import_execute.setNativeRuntimeLoader)(async () => ({ executeNativeAction: import_native.executeNativeAction }));
31
34
  (0, import_execute.setSandboxRuntimeLoader)(async () => {
32
35
  const modulePath = "./runtime/actions/sandbox.js";
33
36
  return import(modulePath);
@@ -37,26 +40,25 @@ const orcha = (0, import_create_orcha.createOrcha)(
37
40
  const projectRoot = (0, import_path.resolve)(
38
41
  configuration.root ?? process.env.ORCHA_PROJECT_ROOT ?? process.cwd()
39
42
  );
40
- if (process.env.ORCHA_COMPILING !== "1" && isPrecompiledRuntime()) {
43
+ const compiler = (0, import_compiler_hook.getRegistryCompiler)();
44
+ if (process.env.ORCHA_COMPILING === "1" && compiler) {
45
+ return compiler(configuration, projectRoot);
46
+ }
47
+ if (isPrecompiledRuntime() || (0, import_fs.existsSync)(compiledManifestPath(projectRoot))) {
41
48
  return loadCompiledManifest(projectRoot, configuration);
42
49
  }
43
- const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
44
- return (0, import_compile.compileRegistry)(
45
- configuration.agents,
46
- registryRoot,
47
- configuration.actions?.runtime ?? "native"
50
+ throw new Error(
51
+ 'Orcha agents must be compiled before runtime initialization. Run "npx orcha dev" during development or "npx orcha build" before starting the application.'
48
52
  );
49
53
  },
50
- import_providers.generateProviderResponse
54
+ import_providers.generateProviderResponse,
55
+ import_platform_node.nodeRuntimePlatform
51
56
  );
52
57
  function isPrecompiledRuntime() {
53
58
  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
59
  }
55
60
  function loadCompiledManifest(projectRoot, configuration) {
56
- const manifestPath = (0, import_path.resolve)(
57
- projectRoot,
58
- ".orcha/dist/manifest.json"
59
- );
61
+ const manifestPath = compiledManifestPath(projectRoot);
60
62
  if (!(0, import_fs.existsSync)(manifestPath)) {
61
63
  throw new Error(
62
64
  `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.`
@@ -88,6 +90,9 @@ function loadCompiledManifest(projectRoot, configuration) {
88
90
  }
89
91
  return bundle;
90
92
  }
93
+ function compiledManifestPath(projectRoot) {
94
+ return (0, import_path.resolve)(projectRoot, ".orcha/dist/manifest.json");
95
+ }
91
96
  // Annotate the CommonJS export names for ESM import in node:
92
97
  0 && (module.exports = {
93
98
  orcha
@@ -26,10 +26,11 @@ var import_child_process = require("child_process");
26
26
  var import_crypto = require("crypto");
27
27
  var import_fs = require("fs");
28
28
  var import_promises = require("fs/promises");
29
+ var import_module = require("module");
29
30
  var import_path = require("path");
30
- var import_url = require("url");
31
31
  var import_http = require("http");
32
32
  var import_chokidar = require("chokidar");
33
+ var import_esbuild = require("esbuild");
33
34
  var import_orcha = require("../orcha.js");
34
35
  var import_project_loader = require("../project-loader.js");
35
36
  var import_testing = require("../testing.js");
@@ -46,6 +47,7 @@ async function startPlayground(options = {}) {
46
47
  const mutationToken = (0, import_crypto.randomBytes)(32).toString("base64url");
47
48
  const allowedHosts = playgroundHosts(host, port);
48
49
  await (0, import_project_loader.loadProject)(projectRoot);
50
+ const publicRoot = await buildPlaygroundAssets(projectRoot);
49
51
  const projectClients = /* @__PURE__ */ new Set();
50
52
  const server = (0, import_http.createServer)(async (request, response) => {
51
53
  try {
@@ -57,7 +59,8 @@ async function startPlayground(options = {}) {
57
59
  port,
58
60
  projectClients,
59
61
  mutationToken,
60
- allowedHosts
62
+ allowedHosts,
63
+ publicRoot
61
64
  });
62
65
  } catch (error) {
63
66
  sendJson(response, error instanceof HttpError ? error.status : 500, {
@@ -340,7 +343,7 @@ async function routeRequest(context) {
340
343
  return;
341
344
  }
342
345
  if (method === "GET") {
343
- await serveAsset(response, url.pathname);
346
+ await serveAsset(response, url.pathname, context.publicRoot);
344
347
  return;
345
348
  }
346
349
  sendJson(response, 404, { error: "Not found." });
@@ -472,11 +475,7 @@ async function readAllEventPages(read) {
472
475
  }
473
476
  return pages.flat();
474
477
  }
475
- async function serveAsset(response, pathname) {
476
- const publicRoot = (0, import_path.resolve)(
477
- (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
478
- "public"
479
- );
478
+ async function serveAsset(response, pathname, publicRoot) {
480
479
  const requested = pathname === "/" ? "index.html" : pathname.slice(1);
481
480
  const path = (0, import_path.resolve)(publicRoot, requested);
482
481
  const relativePath = (0, import_path.relative)(publicRoot, path);
@@ -484,7 +483,7 @@ async function serveAsset(response, pathname) {
484
483
  const indexPath = (0, import_path.resolve)(publicRoot, "index.html");
485
484
  if (!(0, import_fs.existsSync)(indexPath)) {
486
485
  sendJson(response, 503, {
487
- error: "Playground assets are missing. Rebuild orchajs."
486
+ error: "Playground assets are missing. Restart the Orcha playground."
488
487
  });
489
488
  return;
490
489
  }
@@ -501,6 +500,60 @@ async function serveAsset(response, pathname) {
501
500
  });
502
501
  response.end(await (0, import_promises.readFile)(path));
503
502
  }
503
+ async function buildPlaygroundAssets(projectRoot) {
504
+ const require2 = (0, import_module.createRequire)(__orchaImportMetaUrl);
505
+ let entryPath;
506
+ let logoPath;
507
+ try {
508
+ entryPath = require2.resolve("@orchajs/playground-ui/mount");
509
+ logoPath = require2.resolve("@orchajs/playground-ui/orcha-logo.svg");
510
+ } catch (error) {
511
+ throw new Error(
512
+ 'The playground requires the optional "@orchajs/playground-ui" package. Install it as a development dependency.',
513
+ { cause: error }
514
+ );
515
+ }
516
+ const publicRoot = (0, import_path.resolve)(projectRoot, ".orcha/playground");
517
+ await (0, import_promises.mkdir)(publicRoot, { recursive: true });
518
+ await Promise.all([
519
+ (0, import_esbuild.build)({
520
+ entryPoints: [entryPath],
521
+ outfile: (0, import_path.resolve)(publicRoot, "app.js"),
522
+ bundle: true,
523
+ format: "esm",
524
+ platform: "browser",
525
+ target: ["chrome110", "firefox110", "safari16"],
526
+ minify: true,
527
+ sourcemap: false,
528
+ legalComments: "none",
529
+ define: {
530
+ "process.env.NODE_ENV": JSON.stringify("production")
531
+ }
532
+ }),
533
+ (0, import_promises.copyFile)(logoPath, (0, import_path.resolve)(publicRoot, "orcha-logo.svg")),
534
+ (0, import_promises.writeFile)(
535
+ (0, import_path.resolve)(publicRoot, "index.html"),
536
+ `<!doctype html>
537
+ <html lang="en">
538
+ <head>
539
+ <meta charset="UTF-8" />
540
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
541
+ <meta name="color-scheme" content="light" />
542
+ <link rel="icon" href="/orcha-logo.svg" type="image/svg+xml" />
543
+ <title>Orcha Playground</title>
544
+ <link rel="stylesheet" href="/app.css" />
545
+ </head>
546
+ <body>
547
+ <div id="root"></div>
548
+ <script type="module" src="/app.js"></script>
549
+ </body>
550
+ </html>
551
+ `,
552
+ "utf8"
553
+ )
554
+ ]);
555
+ return publicRoot;
556
+ }
504
557
  function contentType(path) {
505
558
  switch ((0, import_path.extname)(path)) {
506
559
  case ".html":
@@ -27,9 +27,19 @@ var import_promises = require("fs/promises");
27
27
  var import_path = require("path");
28
28
  var import_url = require("url");
29
29
  var import_esbuild = require("esbuild");
30
+ var import_compile = require("./compiler/compile.js");
30
31
  var import_env = require("./env.js");
31
32
  var import_orcha = require("./orcha.js");
33
+ var import_compiler_hook = require("./runtime/compiler-hook.js");
32
34
  async function loadProject(projectRoot) {
35
+ (0, import_compiler_hook.setRegistryCompiler)(
36
+ (configuration, compilerProjectRoot) => (0, import_compile.compileRegistry)(
37
+ configuration.agents,
38
+ (0, import_path.resolve)(compilerProjectRoot, "orcha"),
39
+ configuration.actions?.runtime ?? "native",
40
+ "node"
41
+ )
42
+ );
33
43
  (0, import_env.loadProjectEnvironment)(projectRoot);
34
44
  const registryPath = (0, import_path.resolve)(projectRoot, "orcha/index.ts");
35
45
  if (!(0, import_fs.existsSync)(registryPath)) {
@@ -0,0 +1,61 @@
1
+ "use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
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
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var browser_exports = {};
31
+ __export(browser_exports, {
32
+ generateBrowserProviderResponse: () => generateBrowserProviderResponse
33
+ });
34
+ module.exports = __toCommonJS(browser_exports);
35
+ var import_errors = require("../errors.js");
36
+ const loadedProviders = /* @__PURE__ */ new Map();
37
+ const loaders = {
38
+ anthropic: () => import("./anthropic.js").then((module2) => module2.anthropicProvider),
39
+ deepseek: () => import("./deepseek.js").then((module2) => module2.deepSeekProvider),
40
+ googlegenai: () => import("./google-genai.js").then((module2) => module2.googleGenAIProvider),
41
+ openai: () => import("./openai.js").then((module2) => module2.openAIProvider)
42
+ };
43
+ const generateBrowserProviderResponse = async (name, configuration, request) => {
44
+ const loader = loaders[name];
45
+ if (!loader) {
46
+ throw new import_errors.OrchaError(
47
+ "provider_error",
48
+ `Provider "${name}" is not available in browser or React Native runtimes.`
49
+ );
50
+ }
51
+ let provider = loadedProviders.get(name);
52
+ if (!provider) {
53
+ provider = loader();
54
+ loadedProviders.set(name, provider);
55
+ }
56
+ return (await provider).generate(configuration, request);
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ generateBrowserProviderResponse
61
+ });
@@ -0,0 +1,48 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var react_native_exports = {};
22
+ __export(react_native_exports, {
23
+ orcha: () => orcha
24
+ });
25
+ module.exports = __toCommonJS(react_native_exports);
26
+ var import_browser = require("./providers/browser.js");
27
+ var import_execute = require("./runtime/actions/execute.js");
28
+ var import_create_orcha = require("./runtime/create-orcha.js");
29
+ var import_platform_react_native = require("./runtime/platform-react-native.js");
30
+ __reExport(react_native_exports, require("./runtime-entry.js"), module.exports);
31
+ (0, import_execute.setNativeRuntimeLoader)(async () => {
32
+ const modulePath = "./runtime/actions/browser-native.js";
33
+ return import(modulePath);
34
+ });
35
+ const orcha = (0, import_create_orcha.createOrcha)(
36
+ () => {
37
+ throw new Error(
38
+ "The React Native runtime requires a precompiled Orcha bundle. Configure the Orcha Metro integration."
39
+ );
40
+ },
41
+ import_browser.generateBrowserProviderResponse,
42
+ import_platform_react_native.reactNativeRuntimePlatform
43
+ );
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ orcha,
47
+ ...require("./runtime-entry.js")
48
+ });
@@ -0,0 +1,68 @@
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 browser_native_exports = {};
21
+ __export(browser_native_exports, {
22
+ executeNativeAction: () => executeNativeAction
23
+ });
24
+ module.exports = __toCommonJS(browser_native_exports);
25
+ async function executeNativeAction(action, parameters, context) {
26
+ if (!action.source) {
27
+ throw new Error(`Action "${action.name}" has no compiled source.`);
28
+ }
29
+ if (/\brequire\s*\(/.test(action.source)) {
30
+ throw new Error(
31
+ `Browser action "${action.name}" contains a Node.js require() call. Rebuild it for the browser target.`
32
+ );
33
+ }
34
+ const loadAction = new Function(
35
+ `"use strict";
36
+ ${action.source}
37
+ return __orchaActionModule.default;`
38
+ );
39
+ const executable = loadAction();
40
+ if (typeof executable !== "function") {
41
+ throw new Error(
42
+ `Action "${action.name}" index.js must export a default function.`
43
+ );
44
+ }
45
+ const timeoutMs = action.timeoutMs ?? 1e4;
46
+ let timeout;
47
+ try {
48
+ return await Promise.race([
49
+ Promise.resolve(
50
+ executable(parameters, context)
51
+ ),
52
+ new Promise((_resolve, reject) => {
53
+ timeout = setTimeout(
54
+ () => reject(new Error(`Action timed out after ${timeoutMs}ms.`)),
55
+ timeoutMs
56
+ );
57
+ })
58
+ ]);
59
+ } finally {
60
+ if (timeout) {
61
+ clearTimeout(timeout);
62
+ }
63
+ }
64
+ }
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ executeNativeAction
68
+ });