orchajs 0.26.0 → 0.27.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.
- package/dist/browser.d.ts +2 -1
- package/dist/browser.js +17 -3
- package/dist/cli.js +58 -9
- package/dist/compiler/build-project.js +49 -12
- package/dist/compiler/compile.js +12 -1
- package/dist/initialize-project.js +48 -0
- package/dist/integrations/metro.d.ts +1 -0
- package/dist/integrations/metro.js +1 -1
- package/dist/integrations/next.d.ts +1 -0
- package/dist/integrations/next.js +1 -1
- package/dist/integrations/runtime-build.js +40 -9
- package/dist/orcha.d.ts +3 -2
- package/dist/orcha.js +76 -18
- package/dist/project-loader.js +4 -5
- package/dist/react-native.d.ts +2 -1
- package/dist/react-native.js +17 -3
- package/dist/runtime/compiled-manifest.d.ts +6 -0
- package/dist/runtime/compiled-manifest.js +5 -0
- package/dist/runtime/compiler-hook.d.ts +4 -0
- package/dist/runtime/compiler-hook.js +24 -6
- package/dist/runtime/context.js +10 -3
- package/dist/storage/react-native-jsonl.js +66 -19
- package/dist-cjs/browser.js +22 -8
- package/dist-cjs/compiler/build-project.js +53 -10
- package/dist-cjs/compiler/compile.js +15 -2
- package/dist-cjs/initialize-project.js +45 -0
- package/dist-cjs/integrations/metro.js +1 -1
- package/dist-cjs/integrations/next.js +1 -1
- package/dist-cjs/integrations/runtime-build.js +44 -19
- package/dist-cjs/orcha.js +109 -19
- package/dist-cjs/project-loader.js +4 -2
- package/dist-cjs/react-native.js +24 -8
- package/dist-cjs/runtime/compiled-manifest.js +29 -0
- package/dist-cjs/runtime/compiler-hook.js +26 -6
- package/dist-cjs/runtime/context.js +10 -3
- package/dist-cjs/storage/react-native-jsonl.js +64 -29
- package/package.json +1 -1
|
@@ -24,43 +24,68 @@ __export(runtime_build_exports, {
|
|
|
24
24
|
watchRuntimeTargets: () => watchRuntimeTargets
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(runtime_build_exports);
|
|
27
|
+
var import_fs = require("fs");
|
|
28
|
+
var import_module = require("module");
|
|
27
29
|
var import_path = require("path");
|
|
28
|
-
var import_chokidar = require("chokidar");
|
|
29
30
|
var import_build_project = require("../compiler/build-project.js");
|
|
30
31
|
var import_env = require("../env.js");
|
|
31
|
-
|
|
32
|
-
const
|
|
32
|
+
const require2 = (0, import_module.createRequire)(__orchaImportMetaUrl);
|
|
33
|
+
const RUNTIME_BUILD_STATE_KEY = Symbol.for("orchajs.runtimeBuildState");
|
|
34
|
+
function getRuntimeBuildState() {
|
|
35
|
+
const globalRecord = globalThis;
|
|
36
|
+
if (!globalRecord[RUNTIME_BUILD_STATE_KEY]) {
|
|
37
|
+
globalRecord[RUNTIME_BUILD_STATE_KEY] = {
|
|
38
|
+
buildQueue: Promise.resolve(),
|
|
39
|
+
watchedTargets: /* @__PURE__ */ new Set()
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return globalRecord[RUNTIME_BUILD_STATE_KEY];
|
|
43
|
+
}
|
|
33
44
|
function generatedBundlePath(projectRoot, target) {
|
|
34
45
|
const fileName = target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
35
46
|
return (0, import_path.resolve)(projectRoot, ".orcha/dist", fileName);
|
|
36
47
|
}
|
|
37
48
|
function queueRuntimeBuild(projectRoot, target) {
|
|
38
|
-
const
|
|
49
|
+
const state = getRuntimeBuildState();
|
|
50
|
+
const build = state.buildQueue.then(async () => {
|
|
39
51
|
(0, import_env.loadProjectEnvironment)(projectRoot);
|
|
40
52
|
await (0, import_build_project.buildProject)({ projectRoot, target });
|
|
41
53
|
});
|
|
42
|
-
buildQueue = build.catch(() => void 0);
|
|
54
|
+
state.buildQueue = build.catch(() => void 0);
|
|
43
55
|
return build;
|
|
44
56
|
}
|
|
45
57
|
function watchRuntimeTargets(projectRoot, targets) {
|
|
58
|
+
const state = getRuntimeBuildState();
|
|
46
59
|
const key = `${projectRoot}:${targets.join(",")}`;
|
|
47
|
-
if (watchedTargets.has(key)) {
|
|
60
|
+
if (state.watchedTargets.has(key)) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let watchFn;
|
|
64
|
+
try {
|
|
65
|
+
const chokidarModule = require2("chokidar");
|
|
66
|
+
watchFn = chokidarModule.watch;
|
|
67
|
+
} catch {
|
|
48
68
|
return;
|
|
49
69
|
}
|
|
50
|
-
watchedTargets.add(key);
|
|
70
|
+
state.watchedTargets.add(key);
|
|
51
71
|
let timer;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
const watcher = watchFn((0, import_path.resolve)(projectRoot, "orcha"), {
|
|
73
|
+
ignoreInitial: true,
|
|
74
|
+
persistent: false
|
|
75
|
+
});
|
|
76
|
+
watcher.on("all", () => {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
timer = setTimeout(() => {
|
|
79
|
+
if (!(0, import_fs.existsSync)((0, import_path.resolve)(projectRoot, "orcha/index.ts"))) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
void targets.reduce(
|
|
83
|
+
(pending, target) => pending.then(() => queueRuntimeBuild(projectRoot, target)),
|
|
84
|
+
Promise.resolve()
|
|
85
|
+
).catch(() => void 0);
|
|
86
|
+
}, 75);
|
|
87
|
+
timer.unref?.();
|
|
88
|
+
});
|
|
64
89
|
}
|
|
65
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
91
|
0 && (module.exports = {
|
package/dist-cjs/orcha.js
CHANGED
|
@@ -24,7 +24,9 @@ __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_url = require("url");
|
|
27
28
|
var import_inference = require("./amarsia/inference.js");
|
|
29
|
+
var import_compile = require("./compiler/compile.js");
|
|
28
30
|
var import_providers = require("./providers/index.js");
|
|
29
31
|
var import_execute = require("./runtime/actions/execute.js");
|
|
30
32
|
var import_native = require("./runtime/actions/native.js");
|
|
@@ -46,33 +48,110 @@ var import_cloud = require("./storage/cloud.js");
|
|
|
46
48
|
});
|
|
47
49
|
(0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
|
|
48
50
|
(0, import_optional_features.setCloudSessionStoreFactory)((options) => new import_cloud.CloudSessionStore(options));
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const NODE_ORCHA_SINGLETON_KEY = Symbol.for("orchajs.runtime");
|
|
52
|
+
function getSharedNodeOrcha() {
|
|
53
|
+
const globalRecord = globalThis;
|
|
54
|
+
if (!globalRecord[NODE_ORCHA_SINGLETON_KEY]) {
|
|
55
|
+
globalRecord[NODE_ORCHA_SINGLETON_KEY] = (0, import_create_orcha.createOrcha)(
|
|
56
|
+
(configuration) => {
|
|
57
|
+
const projectRoot = (0, import_path.resolve)(
|
|
58
|
+
configuration.root ?? process.env.ORCHA_PROJECT_ROOT ?? process.cwd()
|
|
59
|
+
);
|
|
60
|
+
const compiler = (0, import_compiler_hook.getRegistryCompiler)();
|
|
61
|
+
if (process.env.ORCHA_COMPILING === "1" && compiler) {
|
|
62
|
+
return compiler(configuration, projectRoot);
|
|
63
|
+
}
|
|
64
|
+
const precompiled = isPrecompiledRuntime();
|
|
65
|
+
const manifestFile = compiledManifestPath(projectRoot);
|
|
66
|
+
if (precompiled || (0, import_fs.existsSync)(manifestFile)) {
|
|
67
|
+
return loadCompiledManifest(projectRoot, configuration);
|
|
68
|
+
}
|
|
69
|
+
const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
|
|
70
|
+
if ((0, import_fs.existsSync)(registryRoot)) {
|
|
71
|
+
const compiled = (0, import_compile.compileRegistry)(
|
|
72
|
+
configuration.agents,
|
|
73
|
+
registryRoot,
|
|
74
|
+
configuration.actions?.runtime ?? "native",
|
|
75
|
+
"node"
|
|
76
|
+
);
|
|
77
|
+
persistDevManifest(projectRoot, manifestFile, compiled);
|
|
78
|
+
return compiled;
|
|
79
|
+
}
|
|
80
|
+
throw new Error(
|
|
81
|
+
'Orcha agents could not be found in "orcha/" and no precompiled manifest exists at ".orcha/dist/manifest.json". Run "npx orchajs init" or "npx orchajs build".'
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
import_providers.generateProviderResponse,
|
|
85
|
+
import_platform_node.nodeRuntimePlatform
|
|
53
86
|
);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (isPrecompiledRuntime() || (0, import_fs.existsSync)(compiledManifestPath(projectRoot))) {
|
|
59
|
-
return loadCompiledManifest(projectRoot, configuration);
|
|
60
|
-
}
|
|
61
|
-
throw new Error(
|
|
62
|
-
'Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.'
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
import_providers.generateProviderResponse,
|
|
66
|
-
import_platform_node.nodeRuntimePlatform
|
|
67
|
-
);
|
|
87
|
+
}
|
|
88
|
+
return globalRecord[NODE_ORCHA_SINGLETON_KEY];
|
|
89
|
+
}
|
|
90
|
+
const orcha = getSharedNodeOrcha();
|
|
68
91
|
function isPrecompiledRuntime() {
|
|
69
92
|
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;
|
|
70
93
|
}
|
|
94
|
+
function persistDevManifest(projectRoot, manifestPath, bundle) {
|
|
95
|
+
(0, import_compiler_hook.setGlobalCompiledManifest)(bundle);
|
|
96
|
+
try {
|
|
97
|
+
(0, import_fs.mkdirSync)((0, import_path.dirname)(manifestPath), { recursive: true });
|
|
98
|
+
(0, import_fs.writeFileSync)(manifestPath, `${JSON.stringify(bundle)}
|
|
99
|
+
`, "utf8");
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const ownPackageRoot = (0, import_path.resolve)(
|
|
104
|
+
(0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
|
|
105
|
+
".."
|
|
106
|
+
);
|
|
107
|
+
const consumerPackageRoot = (0, import_path.resolve)(projectRoot, "node_modules/orchajs");
|
|
108
|
+
if ((0, import_fs.existsSync)(consumerPackageRoot) && (0, import_fs.realpathSync)(consumerPackageRoot) !== (0, import_fs.realpathSync)(ownPackageRoot)) {
|
|
109
|
+
const serialized = JSON.stringify(bundle);
|
|
110
|
+
const esmTarget = (0, import_path.resolve)(
|
|
111
|
+
consumerPackageRoot,
|
|
112
|
+
"dist/runtime/compiled-manifest.js"
|
|
113
|
+
);
|
|
114
|
+
const cjsTarget = (0, import_path.resolve)(
|
|
115
|
+
consumerPackageRoot,
|
|
116
|
+
"dist-cjs/runtime/compiled-manifest.js"
|
|
117
|
+
);
|
|
118
|
+
if ((0, import_fs.existsSync)((0, import_path.dirname)(esmTarget))) {
|
|
119
|
+
(0, import_fs.writeFileSync)(
|
|
120
|
+
esmTarget,
|
|
121
|
+
`export const compiledManifest = ${serialized};
|
|
122
|
+
`,
|
|
123
|
+
"utf8"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
if ((0, import_fs.existsSync)((0, import_path.dirname)(cjsTarget))) {
|
|
127
|
+
(0, import_fs.writeFileSync)(
|
|
128
|
+
cjsTarget,
|
|
129
|
+
`"use strict";
|
|
130
|
+
exports.compiledManifest = ${serialized};
|
|
131
|
+
`,
|
|
132
|
+
"utf8"
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
}
|
|
71
139
|
function loadCompiledManifest(projectRoot, configuration) {
|
|
72
140
|
const manifestPath = compiledManifestPath(projectRoot);
|
|
73
141
|
if (!(0, import_fs.existsSync)(manifestPath)) {
|
|
142
|
+
const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
|
|
143
|
+
if ((0, import_fs.existsSync)(registryRoot)) {
|
|
144
|
+
const compiled = (0, import_compile.compileRegistry)(
|
|
145
|
+
configuration.agents,
|
|
146
|
+
registryRoot,
|
|
147
|
+
configuration.actions?.runtime ?? "native",
|
|
148
|
+
"node"
|
|
149
|
+
);
|
|
150
|
+
persistDevManifest(projectRoot, manifestPath, compiled);
|
|
151
|
+
return compiled;
|
|
152
|
+
}
|
|
74
153
|
throw new Error(
|
|
75
|
-
`ORCHA_PRODUCTION_BUNDLE_MISSING: "${manifestPath}" was not found. Run "npx orchajs build" before packaging, include ".orcha/dist" in the deployment, or
|
|
154
|
+
`ORCHA_PRODUCTION_BUNDLE_MISSING: "${manifestPath}" was not found. Run "npx orchajs build" before packaging, include ".orcha/dist" in the deployment, or keep the "orcha/" directory available at runtime.`
|
|
76
155
|
);
|
|
77
156
|
}
|
|
78
157
|
let parsed;
|
|
@@ -95,6 +174,17 @@ function loadCompiledManifest(projectRoot, configuration) {
|
|
|
95
174
|
if (registeredAgents.length !== compiledAgents.length || registeredAgents.some(
|
|
96
175
|
(name, index) => name !== compiledAgents[index]
|
|
97
176
|
)) {
|
|
177
|
+
const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
|
|
178
|
+
if (!isPrecompiledRuntime() && (0, import_fs.existsSync)(registryRoot)) {
|
|
179
|
+
const recompiled = (0, import_compile.compileRegistry)(
|
|
180
|
+
configuration.agents,
|
|
181
|
+
registryRoot,
|
|
182
|
+
configuration.actions?.runtime ?? "native",
|
|
183
|
+
"node"
|
|
184
|
+
);
|
|
185
|
+
persistDevManifest(projectRoot, manifestPath, recompiled);
|
|
186
|
+
return recompiled;
|
|
187
|
+
}
|
|
98
188
|
throw new Error(
|
|
99
189
|
`Orcha compiled manifest does not match the registered agents. Run "npx orchajs build" again. Expected [${registeredAgents.join(", ")}], found [${compiledAgents.join(", ")}].`
|
|
100
190
|
);
|
|
@@ -53,7 +53,9 @@ async function loadProject(projectRoot) {
|
|
|
53
53
|
);
|
|
54
54
|
await (0, import_promises.mkdir)(temporaryDirectory, { recursive: true });
|
|
55
55
|
try {
|
|
56
|
-
|
|
56
|
+
if (import_orcha.orcha.isInitialized()) {
|
|
57
|
+
await import_orcha.orcha.close();
|
|
58
|
+
}
|
|
57
59
|
await (0, import_esbuild.build)({
|
|
58
60
|
entryPoints: [registryPath],
|
|
59
61
|
outfile: bundlePath,
|
|
@@ -74,7 +76,7 @@ async function loadProject(projectRoot) {
|
|
|
74
76
|
restoreEnvironment("ORCHA_PROJECT_ROOT", previousRoot);
|
|
75
77
|
restoreEnvironment("ORCHA_COMPILING", previousCompiling);
|
|
76
78
|
}
|
|
77
|
-
if (!import_orcha.orcha.isInitialized()
|
|
79
|
+
if (!import_orcha.orcha.isInitialized()) {
|
|
78
80
|
throw new Error(
|
|
79
81
|
'"orcha/index.ts" must call orcha.init({ agents, ... }).'
|
|
80
82
|
);
|
package/dist-cjs/react-native.js
CHANGED
|
@@ -26,6 +26,8 @@ module.exports = __toCommonJS(react_native_exports);
|
|
|
26
26
|
var import_inference = require("./amarsia/inference.js");
|
|
27
27
|
var import_browser = require("./providers/browser.js");
|
|
28
28
|
var import_execute = require("./runtime/actions/execute.js");
|
|
29
|
+
var import_compiled_manifest = require("./runtime/compiled-manifest.js");
|
|
30
|
+
var import_compiler_hook = require("./runtime/compiler-hook.js");
|
|
29
31
|
var import_create_orcha = require("./runtime/create-orcha.js");
|
|
30
32
|
var import_optional_features = require("./runtime/optional-features.js");
|
|
31
33
|
var import_platform_react_native = require("./runtime/platform-react-native.js");
|
|
@@ -37,15 +39,29 @@ __reExport(react_native_exports, require("./runtime-entry.js"), module.exports);
|
|
|
37
39
|
});
|
|
38
40
|
(0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
|
|
39
41
|
(0, import_optional_features.setCloudSessionStoreFactory)((options) => new import_cloud.CloudSessionStore(options));
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
throw new Error(
|
|
43
|
-
"The React Native runtime requires a precompiled Orcha bundle. Configure the Orcha Metro integration."
|
|
44
|
-
);
|
|
45
|
-
},
|
|
46
|
-
import_browser.generateBrowserProviderResponse,
|
|
47
|
-
import_platform_react_native.reactNativeRuntimePlatform
|
|
42
|
+
const REACT_NATIVE_ORCHA_SINGLETON_KEY = Symbol.for(
|
|
43
|
+
"orchajs.reactNativeRuntime"
|
|
48
44
|
);
|
|
45
|
+
function getSharedReactNativeOrcha() {
|
|
46
|
+
const globalRecord = globalThis;
|
|
47
|
+
if (!globalRecord[REACT_NATIVE_ORCHA_SINGLETON_KEY]) {
|
|
48
|
+
globalRecord[REACT_NATIVE_ORCHA_SINGLETON_KEY] = (0, import_create_orcha.createOrcha)(
|
|
49
|
+
() => {
|
|
50
|
+
const manifest = (0, import_compiler_hook.getGlobalCompiledManifest)() ?? import_compiled_manifest.compiledManifest;
|
|
51
|
+
if (manifest) {
|
|
52
|
+
return manifest;
|
|
53
|
+
}
|
|
54
|
+
throw new Error(
|
|
55
|
+
'The React Native runtime requires a compiled Orcha manifest. Run "npx orchajs dev" or "npx orchajs build".'
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
import_browser.generateBrowserProviderResponse,
|
|
59
|
+
import_platform_react_native.reactNativeRuntimePlatform
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return globalRecord[REACT_NATIVE_ORCHA_SINGLETON_KEY];
|
|
63
|
+
}
|
|
64
|
+
const orcha = getSharedReactNativeOrcha();
|
|
49
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
66
|
0 && (module.exports = {
|
|
51
67
|
orcha,
|
|
@@ -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 compiled_manifest_exports = {};
|
|
21
|
+
__export(compiled_manifest_exports, {
|
|
22
|
+
compiledManifest: () => compiledManifest
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(compiled_manifest_exports);
|
|
25
|
+
const compiledManifest = void 0;
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
compiledManifest
|
|
29
|
+
});
|
|
@@ -19,30 +19,50 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var compiler_hook_exports = {};
|
|
21
21
|
__export(compiler_hook_exports, {
|
|
22
|
+
getGlobalCompiledManifest: () => getGlobalCompiledManifest,
|
|
22
23
|
getRegistryCompiler: () => getRegistryCompiler,
|
|
23
24
|
isRegistryCompilationActive: () => isRegistryCompilationActive,
|
|
25
|
+
setGlobalCompiledManifest: () => setGlobalCompiledManifest,
|
|
24
26
|
setRegistryCompilationActive: () => setRegistryCompilationActive,
|
|
25
27
|
setRegistryCompiler: () => setRegistryCompiler
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(compiler_hook_exports);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const COMPILER_HOOK_STATE_KEY = Symbol.for("orchajs.compilerHookState");
|
|
31
|
+
function getCompilerHookState() {
|
|
32
|
+
const globalRecord = globalThis;
|
|
33
|
+
if (!globalRecord[COMPILER_HOOK_STATE_KEY]) {
|
|
34
|
+
globalRecord[COMPILER_HOOK_STATE_KEY] = {
|
|
35
|
+
registryCompiler: void 0,
|
|
36
|
+
registryCompilationActive: false,
|
|
37
|
+
compiledManifest: void 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return globalRecord[COMPILER_HOOK_STATE_KEY];
|
|
41
|
+
}
|
|
30
42
|
function setRegistryCompiler(compiler) {
|
|
31
|
-
registryCompiler = compiler;
|
|
43
|
+
getCompilerHookState().registryCompiler = compiler;
|
|
32
44
|
}
|
|
33
45
|
function getRegistryCompiler() {
|
|
34
|
-
return registryCompiler;
|
|
46
|
+
return getCompilerHookState().registryCompiler;
|
|
35
47
|
}
|
|
36
48
|
function setRegistryCompilationActive(active) {
|
|
37
|
-
registryCompilationActive = active;
|
|
49
|
+
getCompilerHookState().registryCompilationActive = active;
|
|
38
50
|
}
|
|
39
51
|
function isRegistryCompilationActive() {
|
|
40
|
-
return registryCompilationActive;
|
|
52
|
+
return getCompilerHookState().registryCompilationActive;
|
|
53
|
+
}
|
|
54
|
+
function setGlobalCompiledManifest(bundle) {
|
|
55
|
+
getCompilerHookState().compiledManifest = bundle;
|
|
56
|
+
}
|
|
57
|
+
function getGlobalCompiledManifest() {
|
|
58
|
+
return getCompilerHookState().compiledManifest;
|
|
41
59
|
}
|
|
42
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
61
|
0 && (module.exports = {
|
|
62
|
+
getGlobalCompiledManifest,
|
|
44
63
|
getRegistryCompiler,
|
|
45
64
|
isRegistryCompilationActive,
|
|
65
|
+
setGlobalCompiledManifest,
|
|
46
66
|
setRegistryCompilationActive,
|
|
47
67
|
setRegistryCompiler
|
|
48
68
|
});
|
|
@@ -23,12 +23,19 @@ __export(context_exports, {
|
|
|
23
23
|
setOrchaRuntimeContext: () => setOrchaRuntimeContext
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(context_exports);
|
|
26
|
-
const
|
|
26
|
+
const RUNTIME_CONTEXTS_KEY = Symbol.for("orchajs.runtimeContexts");
|
|
27
|
+
function getContextsMap() {
|
|
28
|
+
const globalRecord = globalThis;
|
|
29
|
+
if (!globalRecord[RUNTIME_CONTEXTS_KEY]) {
|
|
30
|
+
globalRecord[RUNTIME_CONTEXTS_KEY] = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
}
|
|
32
|
+
return globalRecord[RUNTIME_CONTEXTS_KEY];
|
|
33
|
+
}
|
|
27
34
|
function setOrchaRuntimeContext(client, context) {
|
|
28
|
-
|
|
35
|
+
getContextsMap().set(client, context);
|
|
29
36
|
}
|
|
30
37
|
function getOrchaRuntimeContext(client) {
|
|
31
|
-
const context =
|
|
38
|
+
const context = getContextsMap().get(client);
|
|
32
39
|
if (!context) {
|
|
33
40
|
throw new Error(
|
|
34
41
|
"runTests() requires an initialized Orcha client."
|
|
@@ -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,21 +16,48 @@ 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 react_native_jsonl_exports = {};
|
|
31
21
|
__export(react_native_jsonl_exports, {
|
|
32
22
|
ReactNativeJsonlSessionStore: () => ReactNativeJsonlSessionStore
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(react_native_jsonl_exports);
|
|
35
|
-
|
|
25
|
+
const fallbackMemoryMap = /* @__PURE__ */ new Map();
|
|
26
|
+
const fallbackMemoryStorage = {
|
|
27
|
+
async getItem(key) {
|
|
28
|
+
return fallbackMemoryMap.get(key) ?? null;
|
|
29
|
+
},
|
|
30
|
+
async setItem(key, value) {
|
|
31
|
+
fallbackMemoryMap.set(key, value);
|
|
32
|
+
},
|
|
33
|
+
async removeItem(key) {
|
|
34
|
+
fallbackMemoryMap.delete(key);
|
|
35
|
+
},
|
|
36
|
+
async getAllKeys() {
|
|
37
|
+
return [...fallbackMemoryMap.keys()];
|
|
38
|
+
},
|
|
39
|
+
async multiSet(keyValuePairs) {
|
|
40
|
+
for (const [key, value] of keyValuePairs) {
|
|
41
|
+
fallbackMemoryMap.set(key, value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
let resolvedAsyncStoragePromise;
|
|
46
|
+
function getAsyncStorage() {
|
|
47
|
+
if (!resolvedAsyncStoragePromise) {
|
|
48
|
+
const moduleSpecifier = "@react-native-async-storage/async-storage";
|
|
49
|
+
resolvedAsyncStoragePromise = import(moduleSpecifier).then((loaded) => {
|
|
50
|
+
if (loaded?.default && typeof loaded.default.getItem === "function") {
|
|
51
|
+
return loaded.default;
|
|
52
|
+
}
|
|
53
|
+
if (typeof loaded?.getItem === "function") {
|
|
54
|
+
return loaded;
|
|
55
|
+
}
|
|
56
|
+
return fallbackMemoryStorage;
|
|
57
|
+
}).catch(() => fallbackMemoryStorage);
|
|
58
|
+
}
|
|
59
|
+
return resolvedAsyncStoragePromise;
|
|
60
|
+
}
|
|
36
61
|
const writes = /* @__PURE__ */ new Map();
|
|
37
62
|
const tailIndexes = /* @__PURE__ */ new Map();
|
|
38
63
|
const TAIL_CHUNK_SIZE = 100;
|
|
@@ -45,7 +70,8 @@ class ReactNativeJsonlSessionStore {
|
|
|
45
70
|
this.#namespace = namespace;
|
|
46
71
|
}
|
|
47
72
|
async read(sessionId) {
|
|
48
|
-
const
|
|
73
|
+
const storage = await getAsyncStorage();
|
|
74
|
+
const contents = await storage.getItem(this.#key(sessionId));
|
|
49
75
|
if (!contents) {
|
|
50
76
|
return [];
|
|
51
77
|
}
|
|
@@ -55,6 +81,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
55
81
|
if (!Number.isInteger(afterSequence) || afterSequence < 0 || !Number.isInteger(limit) || limit <= 0) {
|
|
56
82
|
throw new Error("Invalid session event tail range.");
|
|
57
83
|
}
|
|
84
|
+
const storage = await getAsyncStorage();
|
|
58
85
|
await writes.get(this.#key(sessionId))?.catch(() => void 0);
|
|
59
86
|
const index = await this.#ensureTailIndex(sessionId);
|
|
60
87
|
const relevant = index.chunks.filter(
|
|
@@ -62,7 +89,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
62
89
|
);
|
|
63
90
|
const events = [];
|
|
64
91
|
for (const chunk of relevant) {
|
|
65
|
-
const contents = await
|
|
92
|
+
const contents = await storage.getItem(chunk.key);
|
|
66
93
|
if (contents === null) {
|
|
67
94
|
tailIndexes.delete(this.#tailIndexKey(sessionId));
|
|
68
95
|
return this.#readTailFromCanonical(
|
|
@@ -86,11 +113,12 @@ class ReactNativeJsonlSessionStore {
|
|
|
86
113
|
const key = this.#key(sessionId);
|
|
87
114
|
const previous = writes.get(key) ?? Promise.resolve();
|
|
88
115
|
const write = previous.then(async () => {
|
|
116
|
+
const storage = await getAsyncStorage();
|
|
89
117
|
const index = await this.#ensureTailIndex(sessionId);
|
|
90
|
-
await
|
|
91
|
-
const existing = await
|
|
118
|
+
await storage.setItem(this.#tailPendingKey(sessionId), "1");
|
|
119
|
+
const existing = await storage.getItem(key);
|
|
92
120
|
const appended = events.map((event) => JSON.stringify(event)).join("\n");
|
|
93
|
-
await
|
|
121
|
+
await storage.setItem(
|
|
94
122
|
key,
|
|
95
123
|
`${existing ? `${existing.replace(/\n*$/, "")}
|
|
96
124
|
` : ""}${appended}
|
|
@@ -98,7 +126,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
98
126
|
);
|
|
99
127
|
try {
|
|
100
128
|
await this.#appendTailIndex(sessionId, index, events);
|
|
101
|
-
await
|
|
129
|
+
await storage.removeItem(this.#tailPendingKey(sessionId));
|
|
102
130
|
} catch {
|
|
103
131
|
tailIndexes.delete(this.#tailIndexKey(sessionId));
|
|
104
132
|
}
|
|
@@ -115,12 +143,14 @@ class ReactNativeJsonlSessionStore {
|
|
|
115
143
|
this.#allListeners.forEach((listener) => listener(sessionId, events));
|
|
116
144
|
}
|
|
117
145
|
async listSessionIds() {
|
|
146
|
+
const storage = await getAsyncStorage();
|
|
118
147
|
const prefix = `@orchajs:${this.#namespace}:`;
|
|
119
|
-
return (await
|
|
148
|
+
return (await storage.getAllKeys()).filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length)).sort();
|
|
120
149
|
}
|
|
121
150
|
async getCloudAcknowledgement(sessionId) {
|
|
151
|
+
const storage = await getAsyncStorage();
|
|
122
152
|
const value = Number(
|
|
123
|
-
await
|
|
153
|
+
await storage.getItem(this.#acknowledgementKey(sessionId))
|
|
124
154
|
);
|
|
125
155
|
return Number.isInteger(value) && value >= 0 ? value : 0;
|
|
126
156
|
}
|
|
@@ -131,9 +161,10 @@ class ReactNativeJsonlSessionStore {
|
|
|
131
161
|
const key = this.#acknowledgementKey(sessionId);
|
|
132
162
|
const previous = writes.get(key) ?? Promise.resolve();
|
|
133
163
|
const write = previous.then(async () => {
|
|
134
|
-
const
|
|
164
|
+
const storage = await getAsyncStorage();
|
|
165
|
+
const current = Number(await storage.getItem(key));
|
|
135
166
|
if (!Number.isInteger(current) || current < sequence) {
|
|
136
|
-
await
|
|
167
|
+
await storage.setItem(key, String(sequence));
|
|
137
168
|
}
|
|
138
169
|
});
|
|
139
170
|
writes.set(key, write);
|
|
@@ -178,14 +209,15 @@ class ReactNativeJsonlSessionStore {
|
|
|
178
209
|
return `@orchajs-tail-chunk:${this.#namespace}:${sessionId}:${Date.now()}:${tailChunkGeneration}`;
|
|
179
210
|
}
|
|
180
211
|
async #ensureTailIndex(sessionId) {
|
|
212
|
+
const storage = await getAsyncStorage();
|
|
181
213
|
const indexKey = this.#tailIndexKey(sessionId);
|
|
182
|
-
const pending = await
|
|
214
|
+
const pending = await storage.getItem(
|
|
183
215
|
this.#tailPendingKey(sessionId)
|
|
184
216
|
);
|
|
185
217
|
if (!pending) {
|
|
186
218
|
const cached = tailIndexes.get(indexKey);
|
|
187
219
|
if (cached) return cached;
|
|
188
|
-
const stored = await
|
|
220
|
+
const stored = await storage.getItem(indexKey);
|
|
189
221
|
if (stored) {
|
|
190
222
|
try {
|
|
191
223
|
const parsed = parseTailIndex(stored);
|
|
@@ -198,6 +230,7 @@ class ReactNativeJsonlSessionStore {
|
|
|
198
230
|
return this.#rebuildTailIndex(sessionId);
|
|
199
231
|
}
|
|
200
232
|
async #rebuildTailIndex(sessionId) {
|
|
233
|
+
const storage = await getAsyncStorage();
|
|
201
234
|
const events = await this.read(sessionId);
|
|
202
235
|
const chunks = [];
|
|
203
236
|
const writes2 = [];
|
|
@@ -213,19 +246,20 @@ class ReactNativeJsonlSessionStore {
|
|
|
213
246
|
chunks
|
|
214
247
|
};
|
|
215
248
|
writes2.push([this.#tailIndexKey(sessionId), JSON.stringify(index)]);
|
|
216
|
-
if (writes2.length > 0) await
|
|
217
|
-
await
|
|
249
|
+
if (writes2.length > 0) await storage.multiSet(writes2);
|
|
250
|
+
await storage.removeItem(this.#tailPendingKey(sessionId));
|
|
218
251
|
tailIndexes.set(this.#tailIndexKey(sessionId), index);
|
|
219
252
|
return index;
|
|
220
253
|
}
|
|
221
254
|
async #appendTailIndex(sessionId, current, events) {
|
|
255
|
+
const storage = await getAsyncStorage();
|
|
222
256
|
const chunks = [...current.chunks];
|
|
223
257
|
const replacements = [];
|
|
224
258
|
const obsolete = [];
|
|
225
259
|
let remaining = [...events];
|
|
226
260
|
const last = chunks.at(-1);
|
|
227
261
|
if (last && last.count < TAIL_CHUNK_SIZE) {
|
|
228
|
-
const stored = await
|
|
262
|
+
const stored = await storage.getItem(last.key);
|
|
229
263
|
if (stored === null) throw new Error("Missing tail index chunk.");
|
|
230
264
|
const retained = parseEvents(stored).slice(0, last.count);
|
|
231
265
|
const added = remaining.splice(
|
|
@@ -253,18 +287,19 @@ class ReactNativeJsonlSessionStore {
|
|
|
253
287
|
this.#tailIndexKey(sessionId),
|
|
254
288
|
JSON.stringify(index)
|
|
255
289
|
]);
|
|
256
|
-
await
|
|
290
|
+
await storage.multiSet(replacements);
|
|
257
291
|
tailIndexes.set(this.#tailIndexKey(sessionId), index);
|
|
258
292
|
await Promise.all(
|
|
259
|
-
obsolete.map((key) =>
|
|
293
|
+
obsolete.map((key) => storage.removeItem(key))
|
|
260
294
|
);
|
|
261
295
|
}
|
|
262
296
|
async #readTailFromCanonical(sessionId, afterSequence, limit) {
|
|
297
|
+
const storage = await getAsyncStorage();
|
|
263
298
|
const index = await this.#rebuildTailIndex(sessionId);
|
|
264
299
|
const events = [];
|
|
265
300
|
for (const chunk of index.chunks) {
|
|
266
301
|
if (chunk.lastSequence <= afterSequence) continue;
|
|
267
|
-
const contents = await
|
|
302
|
+
const contents = await storage.getItem(chunk.key);
|
|
268
303
|
if (!contents) continue;
|
|
269
304
|
for (const event of parseEvents(contents).slice(0, chunk.count)) {
|
|
270
305
|
if (event.sequence > afterSequence) events.push(event);
|