orchajs 0.20.2 → 0.21.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 (99) hide show
  1. package/README.md +129 -0
  2. package/dist/bin.d.ts +2 -0
  3. package/dist/bin.js +13 -0
  4. package/dist/browser.d.ts +2 -0
  5. package/dist/browser.js +12 -0
  6. package/dist/cli-agents-template.d.ts +1 -1
  7. package/dist/cli-agents-template.js +22 -0
  8. package/dist/cli.js +35 -9
  9. package/dist/compiler/build-project.d.ts +1 -0
  10. package/dist/compiler/build-project.js +75 -8
  11. package/dist/compiler/compile.d.ts +1 -1
  12. package/dist/compiler/compile.js +11 -9
  13. package/dist/file-content.js +42 -6
  14. package/dist/index.d.ts +1 -5
  15. package/dist/index.js +1 -2
  16. package/dist/integrations/esbuild.js +5 -2
  17. package/dist/integrations/expo.d.ts +1 -0
  18. package/dist/integrations/expo.js +1 -0
  19. package/dist/integrations/metro.d.ts +15 -0
  20. package/dist/integrations/metro.js +25 -0
  21. package/dist/integrations/next.d.ts +23 -0
  22. package/dist/integrations/next.js +53 -0
  23. package/dist/integrations/runtime-build.d.ts +4 -0
  24. package/dist/integrations/runtime-build.js +32 -0
  25. package/dist/integrations/vite.d.ts +23 -0
  26. package/dist/integrations/vite.js +32 -0
  27. package/dist/integrations/webpack.d.ts +24 -0
  28. package/dist/integrations/webpack.js +21 -0
  29. package/dist/orcha.js +17 -8
  30. package/dist/playground/server.js +57 -7
  31. package/dist/project-loader.js +3 -0
  32. package/dist/providers/browser.d.ts +2 -0
  33. package/dist/providers/browser.js +20 -0
  34. package/dist/react-native.d.ts +2 -0
  35. package/dist/react-native.js +12 -0
  36. package/dist/runtime/actions/browser-native.d.ts +3 -0
  37. package/dist/runtime/actions/browser-native.js +28 -0
  38. package/dist/runtime/actions/execute.d.ts +7 -0
  39. package/dist/runtime/actions/execute.js +9 -2
  40. package/dist/runtime/agent.d.ts +1 -0
  41. package/dist/runtime/agent.js +8 -5
  42. package/dist/runtime/compiler-hook.d.ts +5 -0
  43. package/dist/runtime/compiler-hook.js +8 -0
  44. package/dist/runtime/create-orcha.d.ts +2 -1
  45. package/dist/runtime/create-orcha.js +15 -19
  46. package/dist/runtime/platform-browser.d.ts +2 -0
  47. package/dist/runtime/platform-browser.js +15 -0
  48. package/dist/runtime/platform-node.d.ts +2 -0
  49. package/dist/runtime/platform-node.js +31 -0
  50. package/dist/runtime/platform-react-native.d.ts +2 -0
  51. package/dist/runtime/platform-react-native.js +15 -0
  52. package/dist/runtime/platform.d.ts +15 -0
  53. package/dist/runtime/platform.js +1 -0
  54. package/dist/runtime/random-id.d.ts +1 -0
  55. package/dist/runtime/random-id.js +26 -0
  56. package/dist/runtime-entry.d.ts +5 -0
  57. package/dist/runtime-entry.js +2 -0
  58. package/dist/storage/browser-indexeddb.d.ts +7 -16
  59. package/dist/storage/browser-indexeddb.js +102 -19
  60. package/dist/storage/react-native-jsonl.d.ts +7 -16
  61. package/dist/storage/react-native-jsonl.js +65 -19
  62. package/dist/types.d.ts +3 -1
  63. package/dist-cjs/browser.js +48 -0
  64. package/dist-cjs/cli-agents-template.js +22 -0
  65. package/dist-cjs/compiler/build-project.js +97 -8
  66. package/dist-cjs/compiler/compile.js +17 -9
  67. package/dist-cjs/file-content.js +42 -7
  68. package/dist-cjs/index.js +4 -9
  69. package/dist-cjs/integrations/esbuild.js +6 -2
  70. package/dist-cjs/integrations/expo.js +29 -0
  71. package/dist-cjs/integrations/metro.js +51 -0
  72. package/dist-cjs/integrations/next.js +75 -0
  73. package/dist-cjs/integrations/runtime-build.js +70 -0
  74. package/dist-cjs/integrations/vite.js +57 -0
  75. package/dist-cjs/integrations/webpack.js +51 -0
  76. package/dist-cjs/orcha.js +17 -12
  77. package/dist-cjs/playground/server.js +62 -9
  78. package/dist-cjs/project-loader.js +10 -0
  79. package/dist-cjs/providers/browser.js +61 -0
  80. package/dist-cjs/react-native.js +48 -0
  81. package/dist-cjs/runtime/actions/browser-native.js +68 -0
  82. package/dist-cjs/runtime/actions/execute.js +12 -2
  83. package/dist-cjs/runtime/agent.js +8 -6
  84. package/dist-cjs/runtime/compiler-hook.js +37 -0
  85. package/dist-cjs/runtime/create-orcha.js +18 -21
  86. package/dist-cjs/runtime/platform-browser.js +48 -0
  87. package/dist-cjs/runtime/platform-node.js +59 -0
  88. package/dist-cjs/runtime/platform-react-native.js +45 -0
  89. package/dist-cjs/runtime/platform.js +17 -0
  90. package/dist-cjs/runtime/random-id.js +55 -0
  91. package/dist-cjs/runtime-entry.js +34 -0
  92. package/dist-cjs/storage/browser-indexeddb.js +102 -5
  93. package/dist-cjs/storage/react-native-jsonl.js +73 -5
  94. package/dist-cjs/types/react-native-async-storage.d.js +2 -0
  95. package/package.json +69 -9
  96. package/dist/playground/public/app.css +0 -1
  97. package/dist/playground/public/app.js +0 -31
  98. package/dist/playground/public/index.html +0 -15
  99. package/dist/playground/public/orcha-logo.svg +0 -4
@@ -24,8 +24,6 @@ __export(file_content_exports, {
24
24
  readLocalFileContent: () => readLocalFileContent
25
25
  });
26
26
  module.exports = __toCommonJS(file_content_exports);
27
- var import_promises = require("fs/promises");
28
- var import_path = require("path");
29
27
  const MIME_TYPES = {
30
28
  ".csv": "text/csv",
31
29
  ".doc": "application/msword",
@@ -47,8 +45,8 @@ const MIME_TYPES = {
47
45
  ".xls": "application/vnd.ms-excel",
48
46
  ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
49
47
  };
50
- function normalizeLocalFile(filePath, mimeType, projectRoot = process.cwd()) {
51
- const absolutePath = (0, import_path.resolve)(projectRoot, filePath);
48
+ function normalizeLocalFile(filePath, mimeType, projectRoot = ".") {
49
+ const absolutePath = resolvePortablePath(projectRoot, filePath);
52
50
  return {
53
51
  type: "file",
54
52
  filePath: absolutePath,
@@ -72,20 +70,22 @@ function normalizeUrlContent(url, mimeType) {
72
70
  };
73
71
  }
74
72
  async function readLocalFileContent(content) {
75
- const bytes = await (0, import_promises.readFile)(content.filePath);
73
+ const fsModule = "fs/promises";
74
+ const { readFile } = await import(fsModule);
75
+ const bytes = await readFile(content.filePath);
76
76
  const base64 = bytes.toString("base64");
77
77
  return {
78
78
  bytes,
79
79
  base64,
80
80
  dataUri: `data:${content.mimeType};base64,${base64}`,
81
- fileName: (0, import_path.basename)(content.filePath)
81
+ fileName: portableBasename(content.filePath)
82
82
  };
83
83
  }
84
84
  function normalizeMimeType(mimeType, source) {
85
85
  if (mimeType?.trim()) {
86
86
  return mimeType.trim().toLowerCase();
87
87
  }
88
- const inferred = MIME_TYPES[(0, import_path.extname)(source).toLowerCase()];
88
+ const inferred = MIME_TYPES[portableExtension(source).toLowerCase()];
89
89
  if (!inferred) {
90
90
  throw new Error(
91
91
  `Could not infer a MIME type for "${source}". Provide mimeType explicitly.`
@@ -93,6 +93,41 @@ function normalizeMimeType(mimeType, source) {
93
93
  }
94
94
  return inferred;
95
95
  }
96
+ function resolvePortablePath(root, filePath) {
97
+ if (/^(?:\/|[a-zA-Z]:[\\/])/.test(filePath)) {
98
+ return normalizePath(filePath);
99
+ }
100
+ return normalizePath(`${root.replace(/[\\/]+$/, "")}/${filePath}`);
101
+ }
102
+ function normalizePath(path) {
103
+ const separator = path.includes("\\") ? "\\" : "/";
104
+ const prefix = path.match(/^(?:[a-zA-Z]:)?[\\/]/)?.[0] ?? "";
105
+ const source = prefix ? path.slice(prefix.length) : path;
106
+ const parts = [];
107
+ for (const part of source.split(/[\\/]+/)) {
108
+ if (!part || part === ".") {
109
+ continue;
110
+ }
111
+ if (part === "..") {
112
+ if (parts.length > 0 && parts.at(-1) !== "..") {
113
+ parts.pop();
114
+ } else if (!prefix) {
115
+ parts.push(part);
116
+ }
117
+ continue;
118
+ }
119
+ parts.push(part);
120
+ }
121
+ return `${prefix}${parts.join(separator)}` || ".";
122
+ }
123
+ function portableBasename(path) {
124
+ return path.split(/[\\/]/).at(-1) ?? path;
125
+ }
126
+ function portableExtension(path) {
127
+ const name = portableBasename(path);
128
+ const index = name.lastIndexOf(".");
129
+ return index > 0 ? name.slice(index) : "";
130
+ }
96
131
  // Annotate the CommonJS export names for ESM import in node:
97
132
  0 && (module.exports = {
98
133
  normalizeLocalFile,
package/dist-cjs/index.js CHANGED
@@ -16,28 +16,23 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
21
  var index_exports = {};
21
22
  __export(index_exports, {
22
23
  NodeJsonlSessionStore: () => import_node_jsonl.NodeJsonlSessionStore,
23
24
  NodeSqliteSessionStore: () => import_node_sqlite.NodeSqliteSessionStore,
24
- OrchaError: () => import_errors.OrchaError,
25
- exportSessionJsonl: () => import_migrate.exportSessionJsonl,
26
- migrateSessionStore: () => import_migrate.migrateSessionStore,
27
25
  orcha: () => import_orcha.orcha
28
26
  });
29
27
  module.exports = __toCommonJS(index_exports);
30
28
  var import_orcha = require("./orcha.js");
31
- var import_errors = require("./errors.js");
29
+ __reExport(index_exports, require("./runtime-entry.js"), module.exports);
32
30
  var import_node_jsonl = require("./storage/node-jsonl.js");
33
31
  var import_node_sqlite = require("./storage/node-sqlite.js");
34
- var import_migrate = require("./storage/migrate.js");
35
32
  // Annotate the CommonJS export names for ESM import in node:
36
33
  0 && (module.exports = {
37
34
  NodeJsonlSessionStore,
38
35
  NodeSqliteSessionStore,
39
- OrchaError,
40
- exportSessionJsonl,
41
- migrateSessionStore,
42
- orcha
36
+ orcha,
37
+ ...require("./runtime-entry.js")
43
38
  });
@@ -26,12 +26,16 @@ var import_path = require("path");
26
26
  var import_build_project = require("../compiler/build-project.js");
27
27
  function orchaPlugin(options = {}) {
28
28
  const projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
29
- const generatedBundle = (0, import_path.resolve)(projectRoot, ".orcha/dist/bundle.js");
30
29
  return {
31
30
  name: "orchajs",
32
31
  setup(builder) {
32
+ const target = builder.initialOptions.platform === "browser" ? "browser" : "node";
33
+ const generatedBundle = (0, import_path.resolve)(
34
+ projectRoot,
35
+ `.orcha/dist/${target === "node" ? "bundle.js" : "bundle.browser.js"}`
36
+ );
33
37
  builder.onStart(async () => {
34
- await (0, import_build_project.buildProject)({ projectRoot });
38
+ await (0, import_build_project.buildProject)({ projectRoot, target });
35
39
  });
36
40
  builder.onResolve({ filter: /^orchajs$/ }, () => ({
37
41
  path: generatedBundle
@@ -0,0 +1,29 @@
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 expo_exports = {};
21
+ __export(expo_exports, {
22
+ withOrchaExpo: () => import_metro.withOrchaMetro
23
+ });
24
+ module.exports = __toCommonJS(expo_exports);
25
+ var import_metro = require("./metro.js");
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ withOrchaExpo
29
+ });
@@ -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 metro_exports = {};
21
+ __export(metro_exports, {
22
+ withOrchaMetro: () => withOrchaMetro
23
+ });
24
+ module.exports = __toCommonJS(metro_exports);
25
+ var import_path = require("path");
26
+ var import_runtime_build = require("./runtime-build.js");
27
+ async function withOrchaMetro(configuration, options = {}) {
28
+ const projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
29
+ await (0, import_runtime_build.queueRuntimeBuild)(projectRoot, "react-native");
30
+ if (process.env.NODE_ENV !== "production") {
31
+ (0, import_runtime_build.watchRuntimeTargets)(projectRoot, ["react-native"]);
32
+ }
33
+ const existingResolver = configuration.resolver?.resolveRequest;
34
+ return {
35
+ ...configuration,
36
+ resolver: {
37
+ ...configuration.resolver,
38
+ resolveRequest(context, moduleName, platform) {
39
+ const requestedModule = moduleName === "orchajs" ? (0, import_runtime_build.generatedBundlePath)(projectRoot, "react-native") : moduleName;
40
+ if (existingResolver) {
41
+ return existingResolver(context, requestedModule, platform);
42
+ }
43
+ return context.resolveRequest(context, requestedModule, platform);
44
+ }
45
+ }
46
+ };
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ withOrchaMetro
51
+ });
@@ -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":