orchajs 0.26.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler/build-project.js +22 -10
- package/dist/integrations/runtime-build.js +17 -6
- package/dist/orcha.d.ts +3 -2
- package/dist/orcha.js +22 -14
- package/dist/runtime/compiler-hook.js +15 -6
- package/dist/runtime/context.js +10 -3
- package/dist-cjs/compiler/build-project.js +22 -10
- package/dist-cjs/integrations/runtime-build.js +17 -6
- package/dist-cjs/orcha.js +26 -18
- package/dist-cjs/runtime/compiler-hook.js +15 -6
- package/dist-cjs/runtime/context.js +10 -3
- package/package.json +1 -1
|
@@ -74,10 +74,11 @@ export async function buildProject(options = {}) {
|
|
|
74
74
|
compiledBundle.actionRuntime === "sandbox") {
|
|
75
75
|
throw new Error(`The ${target} target supports precompiled native actions only. Set actions.runtime to "native".`);
|
|
76
76
|
}
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
77
|
+
const compilerDirectory = esmCompilerDirectory();
|
|
78
|
+
const runtimeFactoryPath = resolve(compilerDirectory, "../runtime/create-orcha.js").replaceAll("\\", "/");
|
|
79
|
+
const runtimePlatformPath = resolve(compilerDirectory, `../runtime/platform-${target}.js`).replaceAll("\\", "/");
|
|
80
|
+
const runtimeEntryPath = resolve(compilerDirectory, "../runtime-entry.js").replaceAll("\\", "/");
|
|
81
|
+
const providerDispatcherPath = resolve(compilerDirectory, "../providers/dispatcher.js").replaceAll("\\", "/");
|
|
81
82
|
const sandboxRuntimeSource = compiledBundle.actionRuntime === "sandbox"
|
|
82
83
|
? createSandboxRuntimeSource()
|
|
83
84
|
: "";
|
|
@@ -172,6 +173,17 @@ export async function buildProject(options = {}) {
|
|
|
172
173
|
});
|
|
173
174
|
}
|
|
174
175
|
}
|
|
176
|
+
function esmCompilerDirectory() {
|
|
177
|
+
const currentDirectory = dirname(fileURLToPath(import.meta.url));
|
|
178
|
+
const normalized = currentDirectory.replaceAll("\\", "/");
|
|
179
|
+
if (normalized.endsWith("/dist-cjs/compiler")) {
|
|
180
|
+
const esmCandidate = resolve(currentDirectory, "../../dist/compiler");
|
|
181
|
+
if (existsSync(esmCandidate)) {
|
|
182
|
+
return esmCandidate;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return currentDirectory;
|
|
186
|
+
}
|
|
175
187
|
function bundleFileName(target) {
|
|
176
188
|
return target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
177
189
|
}
|
|
@@ -185,7 +197,7 @@ function runtimePlatformExport(target) {
|
|
|
185
197
|
return "nodeRuntimePlatform";
|
|
186
198
|
}
|
|
187
199
|
function createSandboxRuntimeSource() {
|
|
188
|
-
const runtimeDirectory =
|
|
200
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
189
201
|
const executePath = resolve(runtimeDirectory, "../runtime/actions/execute.js").replaceAll("\\", "/");
|
|
190
202
|
const sandboxPath = resolve(runtimeDirectory, "../runtime/actions/sandbox.js").replaceAll("\\", "/");
|
|
191
203
|
return [
|
|
@@ -196,7 +208,7 @@ function createSandboxRuntimeSource() {
|
|
|
196
208
|
].join("\n");
|
|
197
209
|
}
|
|
198
210
|
function createPlatformActionRuntimeSource(target) {
|
|
199
|
-
const runtimeDirectory =
|
|
211
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
200
212
|
const executePath = resolve(runtimeDirectory, "../runtime/actions/execute.js").replaceAll("\\", "/");
|
|
201
213
|
const nativePath = resolve(runtimeDirectory, target === "node"
|
|
202
214
|
? "../runtime/actions/native.js"
|
|
@@ -209,7 +221,7 @@ function createPlatformActionRuntimeSource(target) {
|
|
|
209
221
|
].join("\n");
|
|
210
222
|
}
|
|
211
223
|
function createMcpRuntimeSource(target) {
|
|
212
|
-
const runtimeDirectory =
|
|
224
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
213
225
|
const clientPath = resolve(runtimeDirectory, "../runtime/mcp/client.js").replaceAll("\\", "/");
|
|
214
226
|
const implementationPath = resolve(runtimeDirectory, target === "node"
|
|
215
227
|
? "../runtime/mcp/node-client.js"
|
|
@@ -226,7 +238,7 @@ function createOptionalFeatureRuntimeSource(options) {
|
|
|
226
238
|
if (!options.inference && !options.cloudStorage) {
|
|
227
239
|
return "";
|
|
228
240
|
}
|
|
229
|
-
const sourceRoot =
|
|
241
|
+
const sourceRoot = esmCompilerDirectory();
|
|
230
242
|
const hooksPath = resolve(sourceRoot, "../runtime/optional-features.js").replaceAll("\\", "/");
|
|
231
243
|
const imports = [];
|
|
232
244
|
const registrations = [];
|
|
@@ -243,7 +255,7 @@ function createOptionalFeatureRuntimeSource(options) {
|
|
|
243
255
|
return [...imports, ...registrations, ""].join("\n");
|
|
244
256
|
}
|
|
245
257
|
function createNodeStorageExports() {
|
|
246
|
-
const sourceRoot =
|
|
258
|
+
const sourceRoot = esmCompilerDirectory();
|
|
247
259
|
const jsonlPath = resolve(sourceRoot, "../storage/node-jsonl.js").replaceAll("\\", "/");
|
|
248
260
|
const sqlitePath = resolve(sourceRoot, "../storage/node-sqlite.js").replaceAll("\\", "/");
|
|
249
261
|
return [
|
|
@@ -259,7 +271,7 @@ function allCompiledAgents(agents) {
|
|
|
259
271
|
]);
|
|
260
272
|
}
|
|
261
273
|
function createProviderRuntimeSource(providerNames, target) {
|
|
262
|
-
const providersDirectory = resolve(
|
|
274
|
+
const providersDirectory = resolve(esmCompilerDirectory(), "../providers");
|
|
263
275
|
const imports = [];
|
|
264
276
|
const entries = [];
|
|
265
277
|
for (const [index, name] of providerNames.entries()) {
|
|
@@ -2,26 +2,37 @@ import { resolve } from "node:path";
|
|
|
2
2
|
import { watch } from "chokidar";
|
|
3
3
|
import { buildProject } from "../compiler/build-project.js";
|
|
4
4
|
import { loadProjectEnvironment } from "../env.js";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const RUNTIME_BUILD_STATE_KEY = Symbol.for("orchajs.runtimeBuildState");
|
|
6
|
+
function getRuntimeBuildState() {
|
|
7
|
+
const globalRecord = globalThis;
|
|
8
|
+
if (!globalRecord[RUNTIME_BUILD_STATE_KEY]) {
|
|
9
|
+
globalRecord[RUNTIME_BUILD_STATE_KEY] = {
|
|
10
|
+
buildQueue: Promise.resolve(),
|
|
11
|
+
watchedTargets: new Set(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return globalRecord[RUNTIME_BUILD_STATE_KEY];
|
|
15
|
+
}
|
|
7
16
|
export function generatedBundlePath(projectRoot, target) {
|
|
8
17
|
const fileName = target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
9
18
|
return resolve(projectRoot, ".orcha/dist", fileName);
|
|
10
19
|
}
|
|
11
20
|
export function queueRuntimeBuild(projectRoot, target) {
|
|
12
|
-
const
|
|
21
|
+
const state = getRuntimeBuildState();
|
|
22
|
+
const build = state.buildQueue.then(async () => {
|
|
13
23
|
loadProjectEnvironment(projectRoot);
|
|
14
24
|
await buildProject({ projectRoot, target });
|
|
15
25
|
});
|
|
16
|
-
buildQueue = build.catch(() => undefined);
|
|
26
|
+
state.buildQueue = build.catch(() => undefined);
|
|
17
27
|
return build;
|
|
18
28
|
}
|
|
19
29
|
export function watchRuntimeTargets(projectRoot, targets) {
|
|
30
|
+
const state = getRuntimeBuildState();
|
|
20
31
|
const key = `${projectRoot}:${targets.join(",")}`;
|
|
21
|
-
if (watchedTargets.has(key)) {
|
|
32
|
+
if (state.watchedTargets.has(key)) {
|
|
22
33
|
return;
|
|
23
34
|
}
|
|
24
|
-
watchedTargets.add(key);
|
|
35
|
+
state.watchedTargets.add(key);
|
|
25
36
|
let timer;
|
|
26
37
|
watch(resolve(projectRoot, "orcha"), { ignoreInitial: true }).on("all", () => {
|
|
27
38
|
clearTimeout(timer);
|
package/dist/orcha.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { type Orcha, type OrchaClient } from "./runtime/create-orcha.js";
|
|
2
|
+
export type { Orcha, OrchaClient };
|
|
3
|
+
export declare const orcha: OrchaClient;
|
package/dist/orcha.js
CHANGED
|
@@ -5,7 +5,7 @@ import { generateProviderResponse } from "./providers/index.js";
|
|
|
5
5
|
import { setNativeRuntimeLoader, setSandboxRuntimeLoader, } from "./runtime/actions/execute.js";
|
|
6
6
|
import { executeNativeAction } from "./runtime/actions/native.js";
|
|
7
7
|
import { getRegistryCompiler } from "./runtime/compiler-hook.js";
|
|
8
|
-
import { createOrcha } from "./runtime/create-orcha.js";
|
|
8
|
+
import { createOrcha, } from "./runtime/create-orcha.js";
|
|
9
9
|
import { setMcpClientFactory } from "./runtime/mcp/client.js";
|
|
10
10
|
import { setCloudSessionStoreFactory, setInferenceGeneratorFactory, } from "./runtime/optional-features.js";
|
|
11
11
|
import { nodeRuntimePlatform } from "./runtime/platform-node.js";
|
|
@@ -22,20 +22,28 @@ setMcpClientFactory(async (server, credentials) => {
|
|
|
22
22
|
});
|
|
23
23
|
setInferenceGeneratorFactory(createAmarsiaInferenceGenerator);
|
|
24
24
|
setCloudSessionStoreFactory((options) => new CloudSessionStore(options));
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const NODE_ORCHA_SINGLETON_KEY = Symbol.for("orchajs.nodeOrchaSingleton");
|
|
26
|
+
function getSharedNodeOrcha() {
|
|
27
|
+
const globalRecord = globalThis;
|
|
28
|
+
if (!globalRecord[NODE_ORCHA_SINGLETON_KEY]) {
|
|
29
|
+
globalRecord[NODE_ORCHA_SINGLETON_KEY] = createOrcha((configuration) => {
|
|
30
|
+
const projectRoot = resolve(configuration.root ??
|
|
31
|
+
process.env.ORCHA_PROJECT_ROOT ??
|
|
32
|
+
process.cwd());
|
|
33
|
+
const compiler = getRegistryCompiler();
|
|
34
|
+
if (process.env.ORCHA_COMPILING === "1" && compiler) {
|
|
35
|
+
return compiler(configuration, projectRoot);
|
|
36
|
+
}
|
|
37
|
+
if (isPrecompiledRuntime() ||
|
|
38
|
+
existsSync(compiledManifestPath(projectRoot))) {
|
|
39
|
+
return loadCompiledManifest(projectRoot, configuration);
|
|
40
|
+
}
|
|
41
|
+
throw new Error('Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.');
|
|
42
|
+
}, generateProviderResponse, nodeRuntimePlatform);
|
|
32
43
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
throw new Error('Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.');
|
|
38
|
-
}, generateProviderResponse, nodeRuntimePlatform);
|
|
44
|
+
return globalRecord[NODE_ORCHA_SINGLETON_KEY];
|
|
45
|
+
}
|
|
46
|
+
export const orcha = getSharedNodeOrcha();
|
|
39
47
|
function isPrecompiledRuntime() {
|
|
40
48
|
return (process.env.ORCHA_USE_BUILD === "1" ||
|
|
41
49
|
process.env.NODE_ENV === "production" ||
|
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const COMPILER_HOOK_STATE_KEY = Symbol.for("orchajs.compilerHookState");
|
|
2
|
+
function getCompilerHookState() {
|
|
3
|
+
const globalRecord = globalThis;
|
|
4
|
+
if (!globalRecord[COMPILER_HOOK_STATE_KEY]) {
|
|
5
|
+
globalRecord[COMPILER_HOOK_STATE_KEY] = {
|
|
6
|
+
registryCompiler: undefined,
|
|
7
|
+
registryCompilationActive: false,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return globalRecord[COMPILER_HOOK_STATE_KEY];
|
|
11
|
+
}
|
|
3
12
|
/** @internal Installed by Node development tooling, never by runtime bundles. */
|
|
4
13
|
export function setRegistryCompiler(compiler) {
|
|
5
|
-
registryCompiler = compiler;
|
|
14
|
+
getCompilerHookState().registryCompiler = compiler;
|
|
6
15
|
}
|
|
7
16
|
export function getRegistryCompiler() {
|
|
8
|
-
return registryCompiler;
|
|
17
|
+
return getCompilerHookState().registryCompiler;
|
|
9
18
|
}
|
|
10
19
|
/** @internal Prevents registry evaluation from starting runtime resources. */
|
|
11
20
|
export function setRegistryCompilationActive(active) {
|
|
12
|
-
registryCompilationActive = active;
|
|
21
|
+
getCompilerHookState().registryCompilationActive = active;
|
|
13
22
|
}
|
|
14
23
|
/** @internal True only while development tooling evaluates a registry. */
|
|
15
24
|
export function isRegistryCompilationActive() {
|
|
16
|
-
return registryCompilationActive;
|
|
25
|
+
return getCompilerHookState().registryCompilationActive;
|
|
17
26
|
}
|
package/dist/runtime/context.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
const
|
|
1
|
+
const RUNTIME_CONTEXTS_KEY = Symbol.for("orchajs.runtimeContexts");
|
|
2
|
+
function getContextsMap() {
|
|
3
|
+
const globalRecord = globalThis;
|
|
4
|
+
if (!globalRecord[RUNTIME_CONTEXTS_KEY]) {
|
|
5
|
+
globalRecord[RUNTIME_CONTEXTS_KEY] = new WeakMap();
|
|
6
|
+
}
|
|
7
|
+
return globalRecord[RUNTIME_CONTEXTS_KEY];
|
|
8
|
+
}
|
|
2
9
|
export function setOrchaRuntimeContext(client, context) {
|
|
3
|
-
|
|
10
|
+
getContextsMap().set(client, context);
|
|
4
11
|
}
|
|
5
12
|
export function getOrchaRuntimeContext(client) {
|
|
6
|
-
const context =
|
|
13
|
+
const context = getContextsMap().get(client);
|
|
7
14
|
if (!context) {
|
|
8
15
|
throw new Error("runTests() requires an initialized Orcha client.");
|
|
9
16
|
}
|
|
@@ -114,20 +114,21 @@ async function buildProject(options = {}) {
|
|
|
114
114
|
`The ${target} target supports precompiled native actions only. Set actions.runtime to "native".`
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
|
+
const compilerDirectory = esmCompilerDirectory();
|
|
117
118
|
const runtimeFactoryPath = (0, import_path.resolve)(
|
|
118
|
-
|
|
119
|
+
compilerDirectory,
|
|
119
120
|
"../runtime/create-orcha.js"
|
|
120
121
|
).replaceAll("\\", "/");
|
|
121
122
|
const runtimePlatformPath = (0, import_path.resolve)(
|
|
122
|
-
|
|
123
|
+
compilerDirectory,
|
|
123
124
|
`../runtime/platform-${target}.js`
|
|
124
125
|
).replaceAll("\\", "/");
|
|
125
126
|
const runtimeEntryPath = (0, import_path.resolve)(
|
|
126
|
-
|
|
127
|
+
compilerDirectory,
|
|
127
128
|
"../runtime-entry.js"
|
|
128
129
|
).replaceAll("\\", "/");
|
|
129
130
|
const providerDispatcherPath = (0, import_path.resolve)(
|
|
130
|
-
|
|
131
|
+
compilerDirectory,
|
|
131
132
|
"../providers/dispatcher.js"
|
|
132
133
|
).replaceAll("\\", "/");
|
|
133
134
|
const sandboxRuntimeSource = compiledBundle.actionRuntime === "sandbox" ? createSandboxRuntimeSource() : "";
|
|
@@ -224,6 +225,17 @@ async function buildProject(options = {}) {
|
|
|
224
225
|
});
|
|
225
226
|
}
|
|
226
227
|
}
|
|
228
|
+
function esmCompilerDirectory() {
|
|
229
|
+
const currentDirectory = (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl));
|
|
230
|
+
const normalized = currentDirectory.replaceAll("\\", "/");
|
|
231
|
+
if (normalized.endsWith("/dist-cjs/compiler")) {
|
|
232
|
+
const esmCandidate = (0, import_path.resolve)(currentDirectory, "../../dist/compiler");
|
|
233
|
+
if ((0, import_fs.existsSync)(esmCandidate)) {
|
|
234
|
+
return esmCandidate;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return currentDirectory;
|
|
238
|
+
}
|
|
227
239
|
function bundleFileName(target) {
|
|
228
240
|
return target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
229
241
|
}
|
|
@@ -237,7 +249,7 @@ function runtimePlatformExport(target) {
|
|
|
237
249
|
return "nodeRuntimePlatform";
|
|
238
250
|
}
|
|
239
251
|
function createSandboxRuntimeSource() {
|
|
240
|
-
const runtimeDirectory = (
|
|
252
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
241
253
|
const executePath = (0, import_path.resolve)(
|
|
242
254
|
runtimeDirectory,
|
|
243
255
|
"../runtime/actions/execute.js"
|
|
@@ -254,7 +266,7 @@ function createSandboxRuntimeSource() {
|
|
|
254
266
|
].join("\n");
|
|
255
267
|
}
|
|
256
268
|
function createPlatformActionRuntimeSource(target) {
|
|
257
|
-
const runtimeDirectory = (
|
|
269
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
258
270
|
const executePath = (0, import_path.resolve)(
|
|
259
271
|
runtimeDirectory,
|
|
260
272
|
"../runtime/actions/execute.js"
|
|
@@ -271,7 +283,7 @@ function createPlatformActionRuntimeSource(target) {
|
|
|
271
283
|
].join("\n");
|
|
272
284
|
}
|
|
273
285
|
function createMcpRuntimeSource(target) {
|
|
274
|
-
const runtimeDirectory = (
|
|
286
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
275
287
|
const clientPath = (0, import_path.resolve)(
|
|
276
288
|
runtimeDirectory,
|
|
277
289
|
"../runtime/mcp/client.js"
|
|
@@ -292,7 +304,7 @@ function createOptionalFeatureRuntimeSource(options) {
|
|
|
292
304
|
if (!options.inference && !options.cloudStorage) {
|
|
293
305
|
return "";
|
|
294
306
|
}
|
|
295
|
-
const sourceRoot = (
|
|
307
|
+
const sourceRoot = esmCompilerDirectory();
|
|
296
308
|
const hooksPath = (0, import_path.resolve)(
|
|
297
309
|
sourceRoot,
|
|
298
310
|
"../runtime/optional-features.js"
|
|
@@ -328,7 +340,7 @@ function createOptionalFeatureRuntimeSource(options) {
|
|
|
328
340
|
return [...imports, ...registrations, ""].join("\n");
|
|
329
341
|
}
|
|
330
342
|
function createNodeStorageExports() {
|
|
331
|
-
const sourceRoot = (
|
|
343
|
+
const sourceRoot = esmCompilerDirectory();
|
|
332
344
|
const jsonlPath = (0, import_path.resolve)(
|
|
333
345
|
sourceRoot,
|
|
334
346
|
"../storage/node-jsonl.js"
|
|
@@ -351,7 +363,7 @@ function allCompiledAgents(agents) {
|
|
|
351
363
|
}
|
|
352
364
|
function createProviderRuntimeSource(providerNames, target) {
|
|
353
365
|
const providersDirectory = (0, import_path.resolve)(
|
|
354
|
-
(
|
|
366
|
+
esmCompilerDirectory(),
|
|
355
367
|
"../providers"
|
|
356
368
|
);
|
|
357
369
|
const imports = [];
|
|
@@ -28,26 +28,37 @@ var import_path = require("path");
|
|
|
28
28
|
var import_chokidar = require("chokidar");
|
|
29
29
|
var import_build_project = require("../compiler/build-project.js");
|
|
30
30
|
var import_env = require("../env.js");
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const RUNTIME_BUILD_STATE_KEY = Symbol.for("orchajs.runtimeBuildState");
|
|
32
|
+
function getRuntimeBuildState() {
|
|
33
|
+
const globalRecord = globalThis;
|
|
34
|
+
if (!globalRecord[RUNTIME_BUILD_STATE_KEY]) {
|
|
35
|
+
globalRecord[RUNTIME_BUILD_STATE_KEY] = {
|
|
36
|
+
buildQueue: Promise.resolve(),
|
|
37
|
+
watchedTargets: /* @__PURE__ */ new Set()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return globalRecord[RUNTIME_BUILD_STATE_KEY];
|
|
41
|
+
}
|
|
33
42
|
function generatedBundlePath(projectRoot, target) {
|
|
34
43
|
const fileName = target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
35
44
|
return (0, import_path.resolve)(projectRoot, ".orcha/dist", fileName);
|
|
36
45
|
}
|
|
37
46
|
function queueRuntimeBuild(projectRoot, target) {
|
|
38
|
-
const
|
|
47
|
+
const state = getRuntimeBuildState();
|
|
48
|
+
const build = state.buildQueue.then(async () => {
|
|
39
49
|
(0, import_env.loadProjectEnvironment)(projectRoot);
|
|
40
50
|
await (0, import_build_project.buildProject)({ projectRoot, target });
|
|
41
51
|
});
|
|
42
|
-
buildQueue = build.catch(() => void 0);
|
|
52
|
+
state.buildQueue = build.catch(() => void 0);
|
|
43
53
|
return build;
|
|
44
54
|
}
|
|
45
55
|
function watchRuntimeTargets(projectRoot, targets) {
|
|
56
|
+
const state = getRuntimeBuildState();
|
|
46
57
|
const key = `${projectRoot}:${targets.join(",")}`;
|
|
47
|
-
if (watchedTargets.has(key)) {
|
|
58
|
+
if (state.watchedTargets.has(key)) {
|
|
48
59
|
return;
|
|
49
60
|
}
|
|
50
|
-
watchedTargets.add(key);
|
|
61
|
+
state.watchedTargets.add(key);
|
|
51
62
|
let timer;
|
|
52
63
|
(0, import_chokidar.watch)((0, import_path.resolve)(projectRoot, "orcha"), { ignoreInitial: true }).on(
|
|
53
64
|
"all",
|
package/dist-cjs/orcha.js
CHANGED
|
@@ -46,25 +46,33 @@ var import_cloud = require("./storage/cloud.js");
|
|
|
46
46
|
});
|
|
47
47
|
(0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
|
|
48
48
|
(0, import_optional_features.setCloudSessionStoreFactory)((options) => new import_cloud.CloudSessionStore(options));
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
const NODE_ORCHA_SINGLETON_KEY = Symbol.for("orchajs.nodeOrchaSingleton");
|
|
50
|
+
function getSharedNodeOrcha() {
|
|
51
|
+
const globalRecord = globalThis;
|
|
52
|
+
if (!globalRecord[NODE_ORCHA_SINGLETON_KEY]) {
|
|
53
|
+
globalRecord[NODE_ORCHA_SINGLETON_KEY] = (0, import_create_orcha.createOrcha)(
|
|
54
|
+
(configuration) => {
|
|
55
|
+
const projectRoot = (0, import_path.resolve)(
|
|
56
|
+
configuration.root ?? process.env.ORCHA_PROJECT_ROOT ?? process.cwd()
|
|
57
|
+
);
|
|
58
|
+
const compiler = (0, import_compiler_hook.getRegistryCompiler)();
|
|
59
|
+
if (process.env.ORCHA_COMPILING === "1" && compiler) {
|
|
60
|
+
return compiler(configuration, projectRoot);
|
|
61
|
+
}
|
|
62
|
+
if (isPrecompiledRuntime() || (0, import_fs.existsSync)(compiledManifestPath(projectRoot))) {
|
|
63
|
+
return loadCompiledManifest(projectRoot, configuration);
|
|
64
|
+
}
|
|
65
|
+
throw new Error(
|
|
66
|
+
'Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.'
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
import_providers.generateProviderResponse,
|
|
70
|
+
import_platform_node.nodeRuntimePlatform
|
|
53
71
|
);
|
|
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
|
-
);
|
|
72
|
+
}
|
|
73
|
+
return globalRecord[NODE_ORCHA_SINGLETON_KEY];
|
|
74
|
+
}
|
|
75
|
+
const orcha = getSharedNodeOrcha();
|
|
68
76
|
function isPrecompiledRuntime() {
|
|
69
77
|
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
78
|
}
|
|
@@ -25,19 +25,28 @@ __export(compiler_hook_exports, {
|
|
|
25
25
|
setRegistryCompiler: () => setRegistryCompiler
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(compiler_hook_exports);
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const COMPILER_HOOK_STATE_KEY = Symbol.for("orchajs.compilerHookState");
|
|
29
|
+
function getCompilerHookState() {
|
|
30
|
+
const globalRecord = globalThis;
|
|
31
|
+
if (!globalRecord[COMPILER_HOOK_STATE_KEY]) {
|
|
32
|
+
globalRecord[COMPILER_HOOK_STATE_KEY] = {
|
|
33
|
+
registryCompiler: void 0,
|
|
34
|
+
registryCompilationActive: false
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return globalRecord[COMPILER_HOOK_STATE_KEY];
|
|
38
|
+
}
|
|
30
39
|
function setRegistryCompiler(compiler) {
|
|
31
|
-
registryCompiler = compiler;
|
|
40
|
+
getCompilerHookState().registryCompiler = compiler;
|
|
32
41
|
}
|
|
33
42
|
function getRegistryCompiler() {
|
|
34
|
-
return registryCompiler;
|
|
43
|
+
return getCompilerHookState().registryCompiler;
|
|
35
44
|
}
|
|
36
45
|
function setRegistryCompilationActive(active) {
|
|
37
|
-
registryCompilationActive = active;
|
|
46
|
+
getCompilerHookState().registryCompilationActive = active;
|
|
38
47
|
}
|
|
39
48
|
function isRegistryCompilationActive() {
|
|
40
|
-
return registryCompilationActive;
|
|
49
|
+
return getCompilerHookState().registryCompilationActive;
|
|
41
50
|
}
|
|
42
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
52
|
0 && (module.exports = {
|
|
@@ -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."
|