orchajs 0.27.3 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +31 -0
  2. package/dist/amarsia/analytics.d.ts +37 -3
  3. package/dist/amarsia/analytics.js +57 -5
  4. package/dist/cli-agents-template.d.ts +1 -1
  5. package/dist/cli-agents-template.js +9 -0
  6. package/dist/errors.d.ts +1 -0
  7. package/dist/errors.js +7 -0
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/orcha.js +14 -8
  11. package/dist/providers/index.js +7 -1
  12. package/dist/runtime/agent.js +22 -9
  13. package/dist/runtime/create-orcha.js +15 -5
  14. package/dist/runtime/node-module-loader.d.ts +11 -0
  15. package/dist/runtime/node-module-loader.js +18 -0
  16. package/dist/runtime/structured-output.d.ts +1 -0
  17. package/dist/runtime/structured-output.js +10 -1
  18. package/dist/storage/create-store.js +1 -1
  19. package/dist/storage/node-sqlite-facade.d.ts +20 -0
  20. package/dist/storage/node-sqlite-facade.js +48 -0
  21. package/dist/telemetry/open-telemetry.d.ts +19 -0
  22. package/dist/telemetry/open-telemetry.js +630 -0
  23. package/dist/types.d.ts +13 -0
  24. package/dist-cjs/amarsia/analytics.js +60 -5
  25. package/dist-cjs/cli-agents-template.js +9 -0
  26. package/dist-cjs/errors.js +7 -0
  27. package/dist-cjs/index.js +2 -2
  28. package/dist-cjs/orcha.js +19 -8
  29. package/dist-cjs/providers/index.js +7 -1
  30. package/dist-cjs/runtime/agent.js +16 -9
  31. package/dist-cjs/runtime/create-orcha.js +12 -2
  32. package/dist-cjs/runtime/node-module-loader.js +42 -0
  33. package/dist-cjs/runtime/structured-output.js +12 -1
  34. package/dist-cjs/storage/create-store.js +2 -2
  35. package/dist-cjs/storage/node-sqlite-facade.js +72 -0
  36. package/dist-cjs/telemetry/open-telemetry.js +635 -0
  37. package/package.json +36 -4
@@ -21,7 +21,8 @@ var analytics_exports = {};
21
21
  __export(analytics_exports, {
22
22
  AmarsiaTelemetryClient: () => AmarsiaTelemetryClient,
23
23
  sanitizeErrorMessage: () => sanitizeErrorMessage,
24
- withAmarsiaTelemetry: () => withAmarsiaTelemetry
24
+ withAmarsiaTelemetry: () => withAmarsiaTelemetry,
25
+ withRunTelemetry: () => withRunTelemetry
25
26
  });
26
27
  module.exports = __toCommonJS(analytics_exports);
27
28
  var import_endpoint = require("./endpoint.js");
@@ -250,7 +251,7 @@ class AmarsiaTelemetryClient {
250
251
  }
251
252
  }
252
253
  }
253
- function withAmarsiaTelemetry(options) {
254
+ function withRunTelemetry(options) {
254
255
  const { store, manifest, client } = options;
255
256
  const projections = /* @__PURE__ */ new Map();
256
257
  const pending = /* @__PURE__ */ new Map();
@@ -296,7 +297,15 @@ function withAmarsiaTelemetry(options) {
296
297
  if (projection.isTest || !hasNewEvents) return;
297
298
  for (const run of runs) {
298
299
  const fact = projectRunFact(manifest, sessionId, run, projection);
299
- if (fact) client.enqueue(fact);
300
+ if (fact) {
301
+ client.enqueue(
302
+ fact,
303
+ projectRunTelemetryDetails(
304
+ projection.runs.get(run) ?? [],
305
+ projection.sessionCreated
306
+ )
307
+ );
308
+ }
300
309
  }
301
310
  for (const run of progressRuns) {
302
311
  const fact = projectRunFact(manifest, sessionId, run, projection);
@@ -324,7 +333,15 @@ function withAmarsiaTelemetry(options) {
324
333
  run,
325
334
  projection
326
335
  );
327
- if (fact) client.enqueue(fact);
336
+ if (fact) {
337
+ client.enqueue(
338
+ fact,
339
+ projectRunTelemetryDetails(
340
+ projection.runs.get(run) ?? [],
341
+ projection.sessionCreated
342
+ )
343
+ );
344
+ }
328
345
  }
329
346
  for (const run of progressRuns) {
330
347
  const fact = projectRunFact(
@@ -346,6 +363,7 @@ function withAmarsiaTelemetry(options) {
346
363
  }
347
364
  };
348
365
  }
366
+ const withAmarsiaTelemetry = withRunTelemetry;
349
367
  function createProjection(events) {
350
368
  const projection = {
351
369
  seenSequences: /* @__PURE__ */ new Set(),
@@ -477,6 +495,42 @@ function projectRunFact(manifest, sessionId, run, projection) {
477
495
  ...typeof error?.retryable === "boolean" ? { error_retryable: error.retryable } : {}
478
496
  };
479
497
  }
498
+ function projectRunTelemetryDetails(runEvents, sessionCreated) {
499
+ const lineage = asRecord(sessionCreated?.data.lineage);
500
+ return {
501
+ modelCalls: runEvents.filter(
502
+ (event) => event.type === "message.created" && event.data.role === "assistant"
503
+ ).map((event) => {
504
+ const usage = usageFields(asRecord(event.data.usage) ?? {});
505
+ const duration = numberValue(event.data.durationMs);
506
+ const endedAt = event.timestamp;
507
+ const endedAtMs = new Date(endedAt).getTime();
508
+ return {
509
+ provider: typeof event.data.provider === "string" ? event.data.provider : "unknown",
510
+ model: typeof event.data.model === "string" ? event.data.model : "unknown",
511
+ started_at: new Date(
512
+ Number.isFinite(endedAtMs) ? endedAtMs - duration : endedAtMs
513
+ ).toISOString(),
514
+ ended_at: endedAt,
515
+ duration_ms: duration,
516
+ input_tokens: usage.input_tokens,
517
+ output_tokens: usage.output_tokens,
518
+ reasoning_tokens: usage.reasoning_tokens ?? 0,
519
+ cache_read_tokens: usage.cache_read_tokens,
520
+ cache_write_tokens: usage.cache_write_tokens,
521
+ ...typeof event.data.responseId === "string" ? { response_id: event.data.responseId } : {},
522
+ ...typeof event.data.stopReason === "string" ? { finish_reason: event.data.stopReason } : {}
523
+ };
524
+ }),
525
+ ...lineage ? {
526
+ lineage: {
527
+ ...typeof lineage.parentRunNumber === "number" ? { parentRunNumber: lineage.parentRunNumber } : {},
528
+ ...typeof lineage.rootSessionId === "string" ? { rootSessionId: lineage.rootSessionId } : {},
529
+ ...typeof lineage.rootRunNumber === "number" ? { rootRunNumber: lineage.rootRunNumber } : {}
530
+ }
531
+ } : {}
532
+ };
533
+ }
480
534
  function normalizeUsage(terminalUsage, assistants) {
481
535
  const direct = asRecord(terminalUsage);
482
536
  if (direct) {
@@ -650,5 +704,6 @@ function sanitizeErrorMessage(value) {
650
704
  0 && (module.exports = {
651
705
  AmarsiaTelemetryClient,
652
706
  sanitizeErrorMessage,
653
- withAmarsiaTelemetry
707
+ withAmarsiaTelemetry,
708
+ withRunTelemetry
654
709
  });
@@ -130,6 +130,12 @@ required.
130
130
  - \`amarsia.inference\` (optional): routes all model calls through Amarsia while
131
131
  preserving the provider and model in each manifest. It reuses \`amarsia.key\`;
132
132
  local provider credentials are not required.
133
+ - \`telemetry.otel\` (optional): set to \`true\` to emit spans through the
134
+ application's global OpenTelemetry provider, or pass
135
+ \`{ endpoint, headers? }\` to send OTLP/HTTP JSON directly to a collector.
136
+ Spans follow OpenTelemetry GenAI Semantic Conventions. Telemetry excludes
137
+ prompts, responses, action arguments, and action outputs. Subagents share
138
+ their root agent's trace; \`orcha.close()\` marks active runs interrupted.
133
139
  - \`actions\` (optional): overrides the native local-action runtime or configures
134
140
  its environment and sandbox settings.
135
141
  - \`mcp.credentials\` (optional): runtime-only values used to resolve
@@ -807,6 +813,9 @@ type SessionCreated = SessionEvent<{
807
813
  parentAgent: string;
808
814
  parentSessionId: string;
809
815
  parentCallId: string;
816
+ parentRunNumber?: number;
817
+ rootSessionId?: string;
818
+ rootRunNumber?: number;
810
819
  };
811
820
  }>; // type "session.created", no run
812
821
 
@@ -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", {
@@ -1849,11 +1849,15 @@ class RuntimeAgent {
1849
1849
  call.arguments.input,
1850
1850
  this.#projectRoot
1851
1851
  );
1852
+ const parentLineage = sessionLineage(parentEvents);
1852
1853
  const lineage = {
1853
1854
  origin: "delegated",
1854
1855
  parentAgent: this.#manifest.key,
1855
1856
  parentSessionId,
1856
- parentCallId: call.callId
1857
+ parentCallId: call.callId,
1858
+ parentRunNumber: writer.run,
1859
+ rootSessionId: parentLineage?.rootSessionId ?? parentSessionId,
1860
+ rootRunNumber: parentLineage?.rootRunNumber ?? writer.run
1857
1861
  };
1858
1862
  const childSessionId2 = child2.createDelegatedSessionId();
1859
1863
  const initiated = writer.create("subagent.initiated", {
@@ -2046,7 +2050,7 @@ class RuntimeAgent {
2046
2050
  try {
2047
2051
  return await operation();
2048
2052
  } catch (error) {
2049
- const normalized = error instanceof import_errors.OrchaError ? error : new import_errors.OrchaError(
2053
+ const normalized = (0, import_errors.isOrchaError)(error) ? error : new import_errors.OrchaError(
2050
2054
  "storage_error",
2051
2055
  error instanceof Error ? error.message : String(error),
2052
2056
  { retryable: true, cause: error }
@@ -2072,7 +2076,7 @@ class RuntimeAgent {
2072
2076
  try {
2073
2077
  return await operation();
2074
2078
  } catch (error) {
2075
- if (error instanceof import_errors.OrchaError) {
2079
+ if ((0, import_errors.isOrchaError)(error)) {
2076
2080
  throw error;
2077
2081
  }
2078
2082
  throw new import_errors.OrchaError(
@@ -3260,7 +3264,10 @@ function sessionLineage(events) {
3260
3264
  origin: "delegated",
3261
3265
  parentAgent: value.parentAgent,
3262
3266
  parentSessionId: value.parentSessionId,
3263
- parentCallId: value.parentCallId
3267
+ parentCallId: value.parentCallId,
3268
+ ...typeof value.parentRunNumber === "number" ? { parentRunNumber: value.parentRunNumber } : {},
3269
+ ...typeof value.rootSessionId === "string" ? { rootSessionId: value.rootSessionId } : {},
3270
+ ...typeof value.rootRunNumber === "number" ? { rootRunNumber: value.rootRunNumber } : {}
3264
3271
  };
3265
3272
  }
3266
3273
  function requiredToolString(value, name) {
@@ -27,6 +27,7 @@ var import_analytics = require("../amarsia/analytics.js");
27
27
  var import_compiler_hook = require("./compiler-hook.js");
28
28
  var import_context = require("./context.js");
29
29
  var import_optional_features = require("./optional-features.js");
30
+ var import_open_telemetry = require("../telemetry/open-telemetry.js");
30
31
  class OrchaRuntimeCore {
31
32
  #agents = /* @__PURE__ */ new Map();
32
33
  #bundle;
@@ -108,11 +109,20 @@ class OrchaRuntimeCore {
108
109
  projectRoot,
109
110
  manifest
110
111
  });
111
- const telemetry = configuration.amarsia?.key ? new import_analytics.AmarsiaTelemetryClient(configuration.amarsia) : void 0;
112
+ const telemetryClients = [];
113
+ if (configuration.amarsia?.key) {
114
+ telemetryClients.push(new import_analytics.AmarsiaTelemetryClient(configuration.amarsia));
115
+ }
116
+ if (configuration.telemetry?.otel) {
117
+ telemetryClients.push(
118
+ (0, import_open_telemetry.createOpenTelemetryClient)(configuration.telemetry.otel)
119
+ );
120
+ }
121
+ const telemetry = telemetryClients.length === 0 ? void 0 : telemetryClients.length === 1 ? telemetryClients[0] : new import_open_telemetry.CompositeRunTelemetryClient(telemetryClients);
112
122
  this.#telemetry = telemetry;
113
123
  const createRuntimeStore = (manifest) => {
114
124
  const store = createStore(manifest);
115
- const runtimeStore = telemetry ? (0, import_analytics.withAmarsiaTelemetry)({ store, manifest, client: telemetry }) : store;
125
+ const runtimeStore = telemetry ? (0, import_analytics.withRunTelemetry)({ store, manifest, client: telemetry }) : store;
116
126
  this.#stores.add(runtimeStore);
117
127
  return runtimeStore;
118
128
  };
@@ -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
+ });