orchajs 0.27.3 → 0.27.4

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/errors.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare class OrchaError extends Error {
9
9
  cause?: unknown;
10
10
  });
11
11
  }
12
+ export declare function isOrchaError(value: unknown): value is OrchaError;
12
13
  export declare function createProviderHttpError(response: Response, providerLabel: string): Promise<Error>;
13
14
  export declare function describeProviderError(error: unknown): {
14
15
  message: string;
package/dist/errors.js CHANGED
@@ -1,3 +1,4 @@
1
+ const ORCHA_ERROR_BRAND = Symbol.for("orchajs.OrchaError");
1
2
  export class OrchaError extends Error {
2
3
  code;
3
4
  retryable;
@@ -5,11 +6,17 @@ export class OrchaError extends Error {
5
6
  constructor(code, message, options = {}) {
6
7
  super(message, { cause: options.cause });
7
8
  this.name = "OrchaError";
9
+ Object.defineProperty(this, ORCHA_ERROR_BRAND, { value: true });
8
10
  this.code = code;
9
11
  this.retryable = options.retryable ?? false;
10
12
  this.details = options.details;
11
13
  }
12
14
  }
15
+ export function isOrchaError(value) {
16
+ return (typeof value === "object" &&
17
+ value !== null &&
18
+ value[ORCHA_ERROR_BRAND] === true);
19
+ }
13
20
  const NON_RETRYABLE_STATUS_CODES = new Set([400, 401, 403, 404, 413, 422]);
14
21
  const NON_RETRYABLE_ERROR_NAMES = new Set([
15
22
  "ValidationException",
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { orcha } from "./orcha.js";
2
2
  export * from "./runtime-entry.js";
3
3
  export { NodeJsonlSessionStore } from "./storage/node-jsonl.js";
4
- export { NodeSqliteSessionStore } from "./storage/node-sqlite.js";
4
+ export { NodeSqliteSessionStore } from "./storage/node-sqlite-facade.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { orcha } from "./orcha.js";
2
2
  export * from "./runtime-entry.js";
3
3
  export { NodeJsonlSessionStore } from "./storage/node-jsonl.js";
4
- export { NodeSqliteSessionStore } from "./storage/node-sqlite.js";
4
+ export { NodeSqliteSessionStore } from "./storage/node-sqlite-facade.js";
package/dist/orcha.js CHANGED
@@ -2,24 +2,26 @@ import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync, } fro
2
2
  import { dirname, resolve } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { createAmarsiaInferenceGenerator } from "./amarsia/inference.js";
5
- import { compileRegistry } from "./compiler/compile.js";
6
5
  import { generateProviderResponse } from "./providers/index.js";
7
6
  import { setNativeRuntimeLoader, setSandboxRuntimeLoader, } from "./runtime/actions/execute.js";
8
7
  import { executeNativeAction } from "./runtime/actions/native.js";
9
8
  import { getRegistryCompiler, setGlobalCompiledManifest, } from "./runtime/compiler-hook.js";
10
9
  import { createOrcha, } from "./runtime/create-orcha.js";
11
10
  import { setMcpClientFactory } from "./runtime/mcp/client.js";
11
+ import { importRuntimeModule, requireRuntimeModule, } from "./runtime/node-module-loader.js";
12
12
  import { setCloudSessionStoreFactory, setInferenceGeneratorFactory, } from "./runtime/optional-features.js";
13
13
  import { nodeRuntimePlatform } from "./runtime/platform-node.js";
14
14
  import { CloudSessionStore } from "./storage/cloud.js";
15
15
  setNativeRuntimeLoader(async () => ({ executeNativeAction }));
16
16
  setSandboxRuntimeLoader(async () => {
17
- const modulePath = "./runtime/actions/sandbox.js";
18
- return import(modulePath);
17
+ return importRuntimeModule([
18
+ "orchajs",
19
+ "runtime",
20
+ "sandbox",
21
+ ]);
19
22
  });
20
23
  setMcpClientFactory(async (server, credentials) => {
21
- const modulePath = "./runtime/mcp/node-client.js";
22
- const { createNodeMcpClient } = await import(modulePath);
24
+ const { createNodeMcpClient } = await importRuntimeModule(["orchajs", "runtime", "mcp-node"]);
23
25
  return createNodeMcpClient(server, credentials);
24
26
  });
25
27
  setInferenceGeneratorFactory(createAmarsiaInferenceGenerator);
@@ -43,7 +45,7 @@ function getSharedNodeOrcha() {
43
45
  }
44
46
  const registryRoot = resolve(projectRoot, "orcha");
45
47
  if (existsSync(registryRoot)) {
46
- const compiled = compileRegistry(configuration.agents, registryRoot, configuration.actions?.runtime ?? "native", "node");
48
+ const compiled = compileRegistryAtRuntime(configuration.agents, registryRoot, configuration.actions?.runtime ?? "native", "node");
47
49
  persistDevManifest(projectRoot, manifestFile, compiled);
48
50
  return compiled;
49
51
  }
@@ -93,7 +95,7 @@ function loadCompiledManifest(projectRoot, configuration) {
93
95
  if (!existsSync(manifestPath)) {
94
96
  const registryRoot = resolve(projectRoot, "orcha");
95
97
  if (existsSync(registryRoot)) {
96
- const compiled = compileRegistry(configuration.agents, registryRoot, configuration.actions?.runtime ?? "native", "node");
98
+ const compiled = compileRegistryAtRuntime(configuration.agents, registryRoot, configuration.actions?.runtime ?? "native", "node");
97
99
  persistDevManifest(projectRoot, manifestPath, compiled);
98
100
  return compiled;
99
101
  }
@@ -123,7 +125,7 @@ function loadCompiledManifest(projectRoot, configuration) {
123
125
  registeredAgents.some((name, index) => name !== compiledAgents[index])) {
124
126
  const registryRoot = resolve(projectRoot, "orcha");
125
127
  if (!isPrecompiledRuntime() && existsSync(registryRoot)) {
126
- const recompiled = compileRegistry(configuration.agents, registryRoot, configuration.actions?.runtime ?? "native", "node");
128
+ const recompiled = compileRegistryAtRuntime(configuration.agents, registryRoot, configuration.actions?.runtime ?? "native", "node");
127
129
  persistDevManifest(projectRoot, manifestPath, recompiled);
128
130
  return recompiled;
129
131
  }
@@ -134,3 +136,7 @@ function loadCompiledManifest(projectRoot, configuration) {
134
136
  function compiledManifestPath(projectRoot) {
135
137
  return resolve(projectRoot, ".orcha/dist/manifest.json");
136
138
  }
139
+ function compileRegistryAtRuntime(registrations, registryRoot, actionRuntime, target) {
140
+ const { compileRegistry } = requireRuntimeModule(["orchajs", "compiler"]);
141
+ return compileRegistry(registrations, registryRoot, actionRuntime, target);
142
+ }
@@ -1,4 +1,5 @@
1
1
  import { OrchaError } from "../errors.js";
2
+ import { importRuntimeModule } from "../runtime/node-module-loader.js";
2
3
  import { builtInProviderCatalog, isBuiltInProvider, } from "./catalog.js";
3
4
  export { isBuiltInProvider } from "./catalog.js";
4
5
  const loadedProviders = new Map();
@@ -15,7 +16,12 @@ function loadProvider(name) {
15
16
  throw new OrchaError("provider_error", `Provider "${name}" is not implemented by this version of OrchaJS.`);
16
17
  }
17
18
  const descriptor = builtInProviderCatalog[name];
18
- const loading = import(`./${descriptor.moduleFile}`)
19
+ const moduleName = descriptor.moduleFile.replace(/\.js$/, "");
20
+ const loading = importRuntimeModule([
21
+ "orchajs",
22
+ "providers",
23
+ moduleName,
24
+ ])
19
25
  .then((module) => {
20
26
  const provider = module[descriptor.exportName];
21
27
  if (!isProviderAdapter(provider) || provider.name !== name) {
@@ -1,8 +1,8 @@
1
- import { describeProviderError, isRetryableProviderConnectionError, OrchaError, } from "../errors.js";
1
+ import { describeProviderError, isOrchaError, isRetryableProviderConnectionError, OrchaError, } from "../errors.js";
2
2
  import { sanitizeErrorMessage } from "../amarsia/analytics.js";
3
3
  import { normalizeLocalFile, normalizeUrlContent, } from "../file-content.js";
4
4
  import { messagesFromEvents, normalizePersistedToolResults, SessionEventWriter, } from "./session-events.js";
5
- import { StructuredOutputError, validateStructuredValue, } from "./structured-output.js";
5
+ import { isStructuredOutputError, validateStructuredValue, } from "./structured-output.js";
6
6
  import { executeLocalAction } from "./actions/execute.js";
7
7
  import { createExecution, } from "./execution.js";
8
8
  import { McpClientPool, } from "./mcp/client.js";
@@ -751,7 +751,7 @@ export class RuntimeAgent {
751
751
  output: streamedOutput,
752
752
  };
753
753
  }
754
- if (error instanceof StructuredOutputError && error.response) {
754
+ if (isStructuredOutputError(error) && error.response) {
755
755
  const modelDurationMs = Math.round(performance.now() - modelStartedAt);
756
756
  const usage = aggregateUsage(previousEvents, writer.run, error.response.usage);
757
757
  const assistantEvent = writer.create("message.created", {
@@ -803,7 +803,7 @@ export class RuntimeAgent {
803
803
  details,
804
804
  });
805
805
  }
806
- if (error instanceof OrchaError) {
806
+ if (isOrchaError(error)) {
807
807
  throw error;
808
808
  }
809
809
  const providerError = describeProviderError(error);
@@ -992,9 +992,9 @@ export class RuntimeAgent {
992
992
  }
993
993
  catch (error) {
994
994
  const message = error instanceof Error ? error.message : String(error);
995
- const code = error instanceof OrchaError ? error.code : "execution_failed";
996
- const details = error instanceof OrchaError ? error.details : undefined;
997
- const retryable = error instanceof OrchaError ? error.retryable : false;
995
+ const code = isOrchaError(error) ? error.code : "execution_failed";
996
+ const details = isOrchaError(error) ? error.details : undefined;
997
+ const retryable = isOrchaError(error) ? error.retryable : false;
998
998
  const usage = usageForRun(previousEvents, writer.run);
999
999
  await this.#store.append(sessionId, [
1000
1000
  writer.create("run.failed", {
@@ -1680,7 +1680,7 @@ export class RuntimeAgent {
1680
1680
  return await operation();
1681
1681
  }
1682
1682
  catch (error) {
1683
- const normalized = error instanceof OrchaError
1683
+ const normalized = isOrchaError(error)
1684
1684
  ? error
1685
1685
  : new OrchaError("storage_error", error instanceof Error ? error.message : String(error), { retryable: true, cause: error });
1686
1686
  return failure(sessionId, normalized.code, normalized.message, {
@@ -1702,7 +1702,7 @@ export class RuntimeAgent {
1702
1702
  return await operation();
1703
1703
  }
1704
1704
  catch (error) {
1705
- if (error instanceof OrchaError) {
1705
+ if (isOrchaError(error)) {
1706
1706
  throw error;
1707
1707
  }
1708
1708
  throw new OrchaError("storage_error", error instanceof Error ? error.message : String(error), { retryable: true, cause: error });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Loads a Node-only package subpath without exposing it to consumer bundlers.
3
+ * Callers pass path segments so no optional module specifier is statically
4
+ * discoverable from the default package graph.
5
+ */
6
+ export declare function requireRuntimeModule<T>(specifierSegments: string[]): T;
7
+ /**
8
+ * Loads an ESM package subpath without exposing the optional module specifier
9
+ * to consumer bundlers.
10
+ */
11
+ export declare function importRuntimeModule<T>(specifierSegments: string[]): Promise<T>;
@@ -0,0 +1,18 @@
1
+ import { createRequire } from "node:module";
2
+ const runtimeRequire = createRequire(import.meta.url);
3
+ const runtimeImport = new Function("specifier", "return import(specifier)");
4
+ /**
5
+ * Loads a Node-only package subpath without exposing it to consumer bundlers.
6
+ * Callers pass path segments so no optional module specifier is statically
7
+ * discoverable from the default package graph.
8
+ */
9
+ export function requireRuntimeModule(specifierSegments) {
10
+ return runtimeRequire(specifierSegments.join("/"));
11
+ }
12
+ /**
13
+ * Loads an ESM package subpath without exposing the optional module specifier
14
+ * to consumer bundlers.
15
+ */
16
+ export async function importRuntimeModule(specifierSegments) {
17
+ return await runtimeImport(specifierSegments.join("/"));
18
+ }
@@ -14,6 +14,7 @@ export declare class StructuredOutputError extends Error {
14
14
  cause?: unknown;
15
15
  });
16
16
  }
17
+ export declare function isStructuredOutputError(value: unknown): value is StructuredOutputError;
17
18
  export declare function resolveProviderStructuredOutput(request: ProviderRequest, baseResponse: ProviderResponse, textOutput: string): ProviderResponse;
18
19
  export declare function parseStructuredOutput(text: string, schema: Record<string, unknown>): unknown;
19
20
  export declare function validateStructuredValue(value: unknown, schema: Record<string, unknown>, label?: string): void;
@@ -1,3 +1,4 @@
1
+ const STRUCTURED_OUTPUT_ERROR_BRAND = Symbol.for("orchajs.StructuredOutputError");
1
2
  export class StructuredOutputError extends Error {
2
3
  kind;
3
4
  rawText;
@@ -7,12 +8,20 @@ export class StructuredOutputError extends Error {
7
8
  constructor(message, options) {
8
9
  super(message, { cause: options.cause });
9
10
  this.name = "StructuredOutputError";
11
+ Object.defineProperty(this, STRUCTURED_OUTPUT_ERROR_BRAND, {
12
+ value: true,
13
+ });
10
14
  this.kind = options.kind;
11
15
  this.rawText = options.rawText;
12
16
  this.responsePreview = options.responsePreview;
13
17
  this.schemaErrors = options.schemaErrors;
14
18
  }
15
19
  }
20
+ export function isStructuredOutputError(value) {
21
+ return (typeof value === "object" &&
22
+ value !== null &&
23
+ value[STRUCTURED_OUTPUT_ERROR_BRAND] === true);
24
+ }
16
25
  export function resolveProviderStructuredOutput(request, baseResponse, textOutput) {
17
26
  if (request.outputType !== "json" ||
18
27
  baseResponse.toolCalls.length > 0 ||
@@ -27,7 +36,7 @@ export function resolveProviderStructuredOutput(request, baseResponse, textOutpu
27
36
  };
28
37
  }
29
38
  catch (error) {
30
- if (error instanceof StructuredOutputError) {
39
+ if (isStructuredOutputError(error)) {
31
40
  error.response = baseResponse;
32
41
  }
33
42
  throw error;
@@ -1,5 +1,5 @@
1
1
  import { NodeJsonlSessionStore } from "./node-jsonl.js";
2
- import { NodeSqliteSessionStore } from "./node-sqlite.js";
2
+ import { NodeSqliteSessionStore } from "./node-sqlite-facade.js";
3
3
  export function createSessionStore(options) {
4
4
  const strategy = options.strategy ?? "node-jsonl";
5
5
  const directory = options.directory ?? ".orcha/sessions";
@@ -0,0 +1,20 @@
1
+ import type { SessionEvent, SessionStore } from "../types.js";
2
+ /**
3
+ * Backwards-compatible lazy facade for SQLite storage. The native-backed
4
+ * implementation is resolved only when this class is instantiated.
5
+ */
6
+ export declare class NodeSqliteSessionStore implements SessionStore {
7
+ #private;
8
+ readonly databasePath: string;
9
+ readonly agentName: string;
10
+ constructor(directory?: string, projectRoot?: string, agentName?: string);
11
+ read(sessionId: string): Promise<SessionEvent[]>;
12
+ readAfterSequence(sessionId: string, afterSequence: number, limit: number): Promise<SessionEvent[]>;
13
+ append(sessionId: string, events: SessionEvent[]): Promise<void>;
14
+ listSessionIds(): Promise<string[]>;
15
+ getCloudAcknowledgement(sessionId: string): Promise<number>;
16
+ setCloudAcknowledgement(sessionId: string, sequence: number): Promise<void>;
17
+ subscribe(sessionId: string, listener: (events: SessionEvent[]) => void): () => void;
18
+ subscribeAll(listener: (sessionId: string, events: SessionEvent[]) => void): () => void;
19
+ describeLocation(sessionId: string): Promise<string>;
20
+ }
@@ -0,0 +1,48 @@
1
+ import { requireRuntimeModule } from "../runtime/node-module-loader.js";
2
+ /**
3
+ * Backwards-compatible lazy facade for SQLite storage. The native-backed
4
+ * implementation is resolved only when this class is instantiated.
5
+ */
6
+ export class NodeSqliteSessionStore {
7
+ #store;
8
+ databasePath;
9
+ agentName;
10
+ constructor(directory = ".orcha/sessions", projectRoot = process.cwd(), agentName) {
11
+ const { NodeSqliteSessionStore: SqliteStore } = requireRuntimeModule(["orchajs", "storage", "sqlite"]);
12
+ const store = new SqliteStore(directory, projectRoot, agentName);
13
+ this.#store = store;
14
+ this.databasePath = store.databasePath;
15
+ this.agentName = store.agentName;
16
+ }
17
+ read(sessionId) {
18
+ return this.#store.read(sessionId);
19
+ }
20
+ readAfterSequence(sessionId, afterSequence, limit) {
21
+ return this.#store.readAfterSequence?.(sessionId, afterSequence, limit) ?? Promise.resolve([]);
22
+ }
23
+ append(sessionId, events) {
24
+ return this.#store.append(sessionId, events);
25
+ }
26
+ listSessionIds() {
27
+ return this.#store.listSessionIds();
28
+ }
29
+ getCloudAcknowledgement(sessionId) {
30
+ return this.#store.getCloudAcknowledgement?.(sessionId) ??
31
+ Promise.resolve(0);
32
+ }
33
+ setCloudAcknowledgement(sessionId, sequence) {
34
+ return this.#store.setCloudAcknowledgement?.(sessionId, sequence) ??
35
+ Promise.resolve();
36
+ }
37
+ subscribe(sessionId, listener) {
38
+ return this.#store.subscribe?.(sessionId, listener) ??
39
+ (() => undefined);
40
+ }
41
+ subscribeAll(listener) {
42
+ return this.#store.subscribeAll?.(listener) ?? (() => undefined);
43
+ }
44
+ describeLocation(sessionId) {
45
+ return this.#store.describeLocation?.(sessionId) ??
46
+ Promise.resolve(this.databasePath);
47
+ }
48
+ }
@@ -22,9 +22,11 @@ __export(errors_exports, {
22
22
  OrchaError: () => OrchaError,
23
23
  createProviderHttpError: () => createProviderHttpError,
24
24
  describeProviderError: () => describeProviderError,
25
+ isOrchaError: () => isOrchaError,
25
26
  isRetryableProviderConnectionError: () => isRetryableProviderConnectionError
26
27
  });
27
28
  module.exports = __toCommonJS(errors_exports);
29
+ const ORCHA_ERROR_BRAND = Symbol.for("orchajs.OrchaError");
28
30
  class OrchaError extends Error {
29
31
  code;
30
32
  retryable;
@@ -32,11 +34,15 @@ class OrchaError extends Error {
32
34
  constructor(code, message, options = {}) {
33
35
  super(message, { cause: options.cause });
34
36
  this.name = "OrchaError";
37
+ Object.defineProperty(this, ORCHA_ERROR_BRAND, { value: true });
35
38
  this.code = code;
36
39
  this.retryable = options.retryable ?? false;
37
40
  this.details = options.details;
38
41
  }
39
42
  }
43
+ function isOrchaError(value) {
44
+ return typeof value === "object" && value !== null && value[ORCHA_ERROR_BRAND] === true;
45
+ }
40
46
  const NON_RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([400, 401, 403, 404, 413, 422]);
41
47
  const NON_RETRYABLE_ERROR_NAMES = /* @__PURE__ */ new Set([
42
48
  "ValidationException",
@@ -224,5 +230,6 @@ function stringOrNumberField(value, key) {
224
230
  OrchaError,
225
231
  createProviderHttpError,
226
232
  describeProviderError,
233
+ isOrchaError,
227
234
  isRetryableProviderConnectionError
228
235
  });
package/dist-cjs/index.js CHANGED
@@ -21,14 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  NodeJsonlSessionStore: () => import_node_jsonl.NodeJsonlSessionStore,
24
- NodeSqliteSessionStore: () => import_node_sqlite.NodeSqliteSessionStore,
24
+ NodeSqliteSessionStore: () => import_node_sqlite_facade.NodeSqliteSessionStore,
25
25
  orcha: () => import_orcha.orcha
26
26
  });
27
27
  module.exports = __toCommonJS(index_exports);
28
28
  var import_orcha = require("./orcha.js");
29
29
  __reExport(index_exports, require("./runtime-entry.js"), module.exports);
30
30
  var import_node_jsonl = require("./storage/node-jsonl.js");
31
- var import_node_sqlite = require("./storage/node-sqlite.js");
31
+ var import_node_sqlite_facade = require("./storage/node-sqlite-facade.js");
32
32
  // Annotate the CommonJS export names for ESM import in node:
33
33
  0 && (module.exports = {
34
34
  NodeJsonlSessionStore,
package/dist-cjs/orcha.js CHANGED
@@ -26,24 +26,26 @@ var import_fs = require("fs");
26
26
  var import_path = require("path");
27
27
  var import_url = require("url");
28
28
  var import_inference = require("./amarsia/inference.js");
29
- var import_compile = require("./compiler/compile.js");
30
29
  var import_providers = require("./providers/index.js");
31
30
  var import_execute = require("./runtime/actions/execute.js");
32
31
  var import_native = require("./runtime/actions/native.js");
33
32
  var import_compiler_hook = require("./runtime/compiler-hook.js");
34
33
  var import_create_orcha = require("./runtime/create-orcha.js");
35
34
  var import_client = require("./runtime/mcp/client.js");
35
+ var import_node_module_loader = require("./runtime/node-module-loader.js");
36
36
  var import_optional_features = require("./runtime/optional-features.js");
37
37
  var import_platform_node = require("./runtime/platform-node.js");
38
38
  var import_cloud = require("./storage/cloud.js");
39
39
  (0, import_execute.setNativeRuntimeLoader)(async () => ({ executeNativeAction: import_native.executeNativeAction }));
40
40
  (0, import_execute.setSandboxRuntimeLoader)(async () => {
41
- const modulePath = "./runtime/actions/sandbox.js";
42
- return import(modulePath);
41
+ return (0, import_node_module_loader.importRuntimeModule)([
42
+ "orchajs",
43
+ "runtime",
44
+ "sandbox"
45
+ ]);
43
46
  });
44
47
  (0, import_client.setMcpClientFactory)(async (server, credentials) => {
45
- const modulePath = "./runtime/mcp/node-client.js";
46
- const { createNodeMcpClient } = await import(modulePath);
48
+ const { createNodeMcpClient } = await (0, import_node_module_loader.importRuntimeModule)(["orchajs", "runtime", "mcp-node"]);
47
49
  return createNodeMcpClient(server, credentials);
48
50
  });
49
51
  (0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
@@ -68,7 +70,7 @@ function getSharedNodeOrcha() {
68
70
  }
69
71
  const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
70
72
  if ((0, import_fs.existsSync)(registryRoot)) {
71
- const compiled = (0, import_compile.compileRegistry)(
73
+ const compiled = compileRegistryAtRuntime(
72
74
  configuration.agents,
73
75
  registryRoot,
74
76
  configuration.actions?.runtime ?? "native",
@@ -141,7 +143,7 @@ function loadCompiledManifest(projectRoot, configuration) {
141
143
  if (!(0, import_fs.existsSync)(manifestPath)) {
142
144
  const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
143
145
  if ((0, import_fs.existsSync)(registryRoot)) {
144
- const compiled = (0, import_compile.compileRegistry)(
146
+ const compiled = compileRegistryAtRuntime(
145
147
  configuration.agents,
146
148
  registryRoot,
147
149
  configuration.actions?.runtime ?? "native",
@@ -176,7 +178,7 @@ function loadCompiledManifest(projectRoot, configuration) {
176
178
  )) {
177
179
  const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
178
180
  if (!isPrecompiledRuntime() && (0, import_fs.existsSync)(registryRoot)) {
179
- const recompiled = (0, import_compile.compileRegistry)(
181
+ const recompiled = compileRegistryAtRuntime(
180
182
  configuration.agents,
181
183
  registryRoot,
182
184
  configuration.actions?.runtime ?? "native",
@@ -194,6 +196,15 @@ function loadCompiledManifest(projectRoot, configuration) {
194
196
  function compiledManifestPath(projectRoot) {
195
197
  return (0, import_path.resolve)(projectRoot, ".orcha/dist/manifest.json");
196
198
  }
199
+ function compileRegistryAtRuntime(registrations, registryRoot, actionRuntime, target) {
200
+ const { compileRegistry } = (0, import_node_module_loader.requireRuntimeModule)(["orchajs", "compiler"]);
201
+ return compileRegistry(
202
+ registrations,
203
+ registryRoot,
204
+ actionRuntime,
205
+ target
206
+ );
207
+ }
197
208
  // Annotate the CommonJS export names for ESM import in node:
198
209
  0 && (module.exports = {
199
210
  orcha
@@ -24,6 +24,7 @@ __export(providers_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(providers_exports);
26
26
  var import_errors = require("../errors.js");
27
+ var import_node_module_loader = require("../runtime/node-module-loader.js");
27
28
  var import_catalog = require("./catalog.js");
28
29
  var import_catalog2 = require("./catalog.js");
29
30
  const loadedProviders = /* @__PURE__ */ new Map();
@@ -43,7 +44,12 @@ function loadProvider(name) {
43
44
  );
44
45
  }
45
46
  const descriptor = import_catalog.builtInProviderCatalog[name];
46
- const loading = import(`./${descriptor.moduleFile}`).then((module2) => {
47
+ const moduleName = descriptor.moduleFile.replace(/\.js$/, "");
48
+ const loading = (0, import_node_module_loader.importRuntimeModule)([
49
+ "orchajs",
50
+ "providers",
51
+ moduleName
52
+ ]).then((module2) => {
47
53
  const provider = module2[descriptor.exportName];
48
54
  if (!isProviderAdapter(provider) || provider.name !== name) {
49
55
  throw new Error(
@@ -996,7 +996,7 @@ class RuntimeAgent {
996
996
  output: streamedOutput
997
997
  };
998
998
  }
999
- if (error instanceof import_structured_output.StructuredOutputError && error.response) {
999
+ if ((0, import_structured_output.isStructuredOutputError)(error) && error.response) {
1000
1000
  const modelDurationMs2 = Math.round(
1001
1001
  performance.now() - modelStartedAt
1002
1002
  );
@@ -1049,7 +1049,7 @@ class RuntimeAgent {
1049
1049
  details
1050
1050
  });
1051
1051
  }
1052
- if (error instanceof import_errors.OrchaError) {
1052
+ if ((0, import_errors.isOrchaError)(error)) {
1053
1053
  throw error;
1054
1054
  }
1055
1055
  const providerError = (0, import_errors.describeProviderError)(error);
@@ -1282,9 +1282,9 @@ class RuntimeAgent {
1282
1282
  };
1283
1283
  } catch (error) {
1284
1284
  const message = error instanceof Error ? error.message : String(error);
1285
- const code = error instanceof import_errors.OrchaError ? error.code : "execution_failed";
1286
- const details = error instanceof import_errors.OrchaError ? error.details : void 0;
1287
- const retryable = error instanceof import_errors.OrchaError ? error.retryable : false;
1285
+ const code = (0, import_errors.isOrchaError)(error) ? error.code : "execution_failed";
1286
+ const details = (0, import_errors.isOrchaError)(error) ? error.details : void 0;
1287
+ const retryable = (0, import_errors.isOrchaError)(error) ? error.retryable : false;
1288
1288
  const usage = usageForRun(previousEvents, writer.run);
1289
1289
  await this.#store.append(sessionId, [
1290
1290
  writer.create("run.failed", {
@@ -2046,7 +2046,7 @@ class RuntimeAgent {
2046
2046
  try {
2047
2047
  return await operation();
2048
2048
  } catch (error) {
2049
- const normalized = error instanceof import_errors.OrchaError ? error : new import_errors.OrchaError(
2049
+ const normalized = (0, import_errors.isOrchaError)(error) ? error : new import_errors.OrchaError(
2050
2050
  "storage_error",
2051
2051
  error instanceof Error ? error.message : String(error),
2052
2052
  { retryable: true, cause: error }
@@ -2072,7 +2072,7 @@ class RuntimeAgent {
2072
2072
  try {
2073
2073
  return await operation();
2074
2074
  } catch (error) {
2075
- if (error instanceof import_errors.OrchaError) {
2075
+ if ((0, import_errors.isOrchaError)(error)) {
2076
2076
  throw error;
2077
2077
  }
2078
2078
  throw new import_errors.OrchaError(
@@ -0,0 +1,42 @@
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 node_module_loader_exports = {};
21
+ __export(node_module_loader_exports, {
22
+ importRuntimeModule: () => importRuntimeModule,
23
+ requireRuntimeModule: () => requireRuntimeModule
24
+ });
25
+ module.exports = __toCommonJS(node_module_loader_exports);
26
+ var import_module = require("module");
27
+ const runtimeRequire = (0, import_module.createRequire)(__orchaImportMetaUrl);
28
+ const runtimeImport = new Function(
29
+ "specifier",
30
+ "return import(specifier)"
31
+ );
32
+ function requireRuntimeModule(specifierSegments) {
33
+ return runtimeRequire(specifierSegments.join("/"));
34
+ }
35
+ async function importRuntimeModule(specifierSegments) {
36
+ return await runtimeImport(specifierSegments.join("/"));
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ importRuntimeModule,
41
+ requireRuntimeModule
42
+ });
@@ -20,11 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var structured_output_exports = {};
21
21
  __export(structured_output_exports, {
22
22
  StructuredOutputError: () => StructuredOutputError,
23
+ isStructuredOutputError: () => isStructuredOutputError,
23
24
  parseStructuredOutput: () => parseStructuredOutput,
24
25
  resolveProviderStructuredOutput: () => resolveProviderStructuredOutput,
25
26
  validateStructuredValue: () => validateStructuredValue
26
27
  });
27
28
  module.exports = __toCommonJS(structured_output_exports);
29
+ const STRUCTURED_OUTPUT_ERROR_BRAND = Symbol.for(
30
+ "orchajs.StructuredOutputError"
31
+ );
28
32
  class StructuredOutputError extends Error {
29
33
  kind;
30
34
  rawText;
@@ -34,12 +38,18 @@ class StructuredOutputError extends Error {
34
38
  constructor(message, options) {
35
39
  super(message, { cause: options.cause });
36
40
  this.name = "StructuredOutputError";
41
+ Object.defineProperty(this, STRUCTURED_OUTPUT_ERROR_BRAND, {
42
+ value: true
43
+ });
37
44
  this.kind = options.kind;
38
45
  this.rawText = options.rawText;
39
46
  this.responsePreview = options.responsePreview;
40
47
  this.schemaErrors = options.schemaErrors;
41
48
  }
42
49
  }
50
+ function isStructuredOutputError(value) {
51
+ return typeof value === "object" && value !== null && value[STRUCTURED_OUTPUT_ERROR_BRAND] === true;
52
+ }
43
53
  function resolveProviderStructuredOutput(request, baseResponse, textOutput) {
44
54
  if (request.outputType !== "json" || baseResponse.toolCalls.length > 0 || baseResponse.stopReason === "max_tokens" || baseResponse.stopReason === "content_filter") {
45
55
  return baseResponse;
@@ -53,7 +63,7 @@ function resolveProviderStructuredOutput(request, baseResponse, textOutput) {
53
63
  )
54
64
  };
55
65
  } catch (error) {
56
- if (error instanceof StructuredOutputError) {
66
+ if (isStructuredOutputError(error)) {
57
67
  error.response = baseResponse;
58
68
  }
59
69
  throw error;
@@ -215,6 +225,7 @@ function isObject(value) {
215
225
  // Annotate the CommonJS export names for ESM import in node:
216
226
  0 && (module.exports = {
217
227
  StructuredOutputError,
228
+ isStructuredOutputError,
218
229
  parseStructuredOutput,
219
230
  resolveProviderStructuredOutput,
220
231
  validateStructuredValue
@@ -23,7 +23,7 @@ __export(create_store_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(create_store_exports);
25
25
  var import_node_jsonl = require("./node-jsonl.js");
26
- var import_node_sqlite = require("./node-sqlite.js");
26
+ var import_node_sqlite_facade = require("./node-sqlite-facade.js");
27
27
  function createSessionStore(options) {
28
28
  const strategy = options.strategy ?? "node-jsonl";
29
29
  const directory = options.directory ?? ".orcha/sessions";
@@ -35,7 +35,7 @@ function createSessionStore(options) {
35
35
  );
36
36
  }
37
37
  if (strategy === "sqlite") {
38
- return new import_node_sqlite.NodeSqliteSessionStore(
38
+ return new import_node_sqlite_facade.NodeSqliteSessionStore(
39
39
  directory,
40
40
  options.projectRoot,
41
41
  options.agentName
@@ -0,0 +1,72 @@
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 node_sqlite_facade_exports = {};
21
+ __export(node_sqlite_facade_exports, {
22
+ NodeSqliteSessionStore: () => NodeSqliteSessionStore
23
+ });
24
+ module.exports = __toCommonJS(node_sqlite_facade_exports);
25
+ var import_node_module_loader = require("../runtime/node-module-loader.js");
26
+ class NodeSqliteSessionStore {
27
+ #store;
28
+ databasePath;
29
+ agentName;
30
+ constructor(directory = ".orcha/sessions", projectRoot = process.cwd(), agentName) {
31
+ const { NodeSqliteSessionStore: SqliteStore } = (0, import_node_module_loader.requireRuntimeModule)(["orchajs", "storage", "sqlite"]);
32
+ const store = new SqliteStore(directory, projectRoot, agentName);
33
+ this.#store = store;
34
+ this.databasePath = store.databasePath;
35
+ this.agentName = store.agentName;
36
+ }
37
+ read(sessionId) {
38
+ return this.#store.read(sessionId);
39
+ }
40
+ readAfterSequence(sessionId, afterSequence, limit) {
41
+ return this.#store.readAfterSequence?.(
42
+ sessionId,
43
+ afterSequence,
44
+ limit
45
+ ) ?? Promise.resolve([]);
46
+ }
47
+ append(sessionId, events) {
48
+ return this.#store.append(sessionId, events);
49
+ }
50
+ listSessionIds() {
51
+ return this.#store.listSessionIds();
52
+ }
53
+ getCloudAcknowledgement(sessionId) {
54
+ return this.#store.getCloudAcknowledgement?.(sessionId) ?? Promise.resolve(0);
55
+ }
56
+ setCloudAcknowledgement(sessionId, sequence) {
57
+ return this.#store.setCloudAcknowledgement?.(sessionId, sequence) ?? Promise.resolve();
58
+ }
59
+ subscribe(sessionId, listener) {
60
+ return this.#store.subscribe?.(sessionId, listener) ?? (() => void 0);
61
+ }
62
+ subscribeAll(listener) {
63
+ return this.#store.subscribeAll?.(listener) ?? (() => void 0);
64
+ }
65
+ describeLocation(sessionId) {
66
+ return this.#store.describeLocation?.(sessionId) ?? Promise.resolve(this.databasePath);
67
+ }
68
+ }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ NodeSqliteSessionStore
72
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchajs",
3
- "version": "0.27.3",
3
+ "version": "0.27.4",
4
4
  "description": "A filesystem-convention, stateful agent framework for JavaScript.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,6 +24,7 @@
24
24
  ".": {
25
25
  "types": "./dist/index.d.ts",
26
26
  "react-native": "./dist/react-native.js",
27
+ "edge-light": "./dist/browser.js",
27
28
  "browser": "./dist/browser.js",
28
29
  "import": "./dist/index.js",
29
30
  "require": "./dist-cjs/index.js"
@@ -67,6 +68,31 @@
67
68
  "types": "./dist/integrations/expo.d.ts",
68
69
  "import": "./dist/integrations/expo.js",
69
70
  "require": "./dist-cjs/integrations/expo.js"
71
+ },
72
+ "./compiler": {
73
+ "types": "./dist/compiler/compile.d.ts",
74
+ "import": "./dist/compiler/compile.js",
75
+ "require": "./dist-cjs/compiler/compile.js"
76
+ },
77
+ "./providers/*": {
78
+ "types": "./dist/providers/*.d.ts",
79
+ "import": "./dist/providers/*.js",
80
+ "require": "./dist-cjs/providers/*.js"
81
+ },
82
+ "./runtime/sandbox": {
83
+ "types": "./dist/runtime/actions/sandbox.d.ts",
84
+ "import": "./dist/runtime/actions/sandbox.js",
85
+ "require": "./dist-cjs/runtime/actions/sandbox.js"
86
+ },
87
+ "./runtime/mcp-node": {
88
+ "types": "./dist/runtime/mcp/node-client.d.ts",
89
+ "import": "./dist/runtime/mcp/node-client.js",
90
+ "require": "./dist-cjs/runtime/mcp/node-client.js"
91
+ },
92
+ "./storage/sqlite": {
93
+ "types": "./dist/storage/node-sqlite.d.ts",
94
+ "import": "./dist/storage/node-sqlite.js",
95
+ "require": "./dist-cjs/storage/node-sqlite.js"
70
96
  }
71
97
  },
72
98
  "typesVersions": {
@@ -94,6 +120,9 @@
94
120
  ],
95
121
  "expo": [
96
122
  "dist/integrations/expo.d.ts"
123
+ ],
124
+ "storage/sqlite": [
125
+ "dist/storage/node-sqlite.d.ts"
97
126
  ]
98
127
  }
99
128
  },