orchajs 0.20.3 → 0.22.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 (107) hide show
  1. package/README.md +103 -0
  2. package/dist/amarsia/analytics.d.ts +21 -0
  3. package/dist/amarsia/analytics.js +457 -0
  4. package/dist/amarsia/endpoint.d.ts +1 -0
  5. package/dist/amarsia/endpoint.js +8 -0
  6. package/dist/amarsia/sync.js +1 -4
  7. package/dist/bin.d.ts +2 -0
  8. package/dist/bin.js +13 -0
  9. package/dist/browser.d.ts +2 -0
  10. package/dist/browser.js +12 -0
  11. package/dist/cli.js +35 -9
  12. package/dist/compiler/build-project.d.ts +1 -0
  13. package/dist/compiler/build-project.js +75 -8
  14. package/dist/compiler/compile.d.ts +1 -1
  15. package/dist/compiler/compile.js +11 -9
  16. package/dist/errors.d.ts +5 -0
  17. package/dist/errors.js +102 -0
  18. package/dist/file-content.js +42 -6
  19. package/dist/index.d.ts +1 -5
  20. package/dist/index.js +1 -2
  21. package/dist/integrations/esbuild.js +5 -2
  22. package/dist/integrations/expo.d.ts +1 -0
  23. package/dist/integrations/expo.js +1 -0
  24. package/dist/integrations/metro.d.ts +15 -0
  25. package/dist/integrations/metro.js +25 -0
  26. package/dist/integrations/next.d.ts +23 -0
  27. package/dist/integrations/next.js +53 -0
  28. package/dist/integrations/runtime-build.d.ts +4 -0
  29. package/dist/integrations/runtime-build.js +32 -0
  30. package/dist/integrations/vite.d.ts +23 -0
  31. package/dist/integrations/vite.js +32 -0
  32. package/dist/integrations/webpack.d.ts +24 -0
  33. package/dist/integrations/webpack.js +21 -0
  34. package/dist/orcha.js +17 -8
  35. package/dist/playground/server.js +57 -7
  36. package/dist/project-loader.js +3 -0
  37. package/dist/providers/browser.d.ts +2 -0
  38. package/dist/providers/browser.js +20 -0
  39. package/dist/react-native.d.ts +2 -0
  40. package/dist/react-native.js +12 -0
  41. package/dist/runtime/actions/browser-native.d.ts +3 -0
  42. package/dist/runtime/actions/browser-native.js +28 -0
  43. package/dist/runtime/actions/execute.d.ts +7 -0
  44. package/dist/runtime/actions/execute.js +9 -2
  45. package/dist/runtime/agent.d.ts +1 -0
  46. package/dist/runtime/agent.js +38 -10
  47. package/dist/runtime/compiler-hook.d.ts +5 -0
  48. package/dist/runtime/compiler-hook.js +8 -0
  49. package/dist/runtime/create-orcha.d.ts +6 -1
  50. package/dist/runtime/create-orcha.js +35 -21
  51. package/dist/runtime/platform-browser.d.ts +2 -0
  52. package/dist/runtime/platform-browser.js +15 -0
  53. package/dist/runtime/platform-node.d.ts +2 -0
  54. package/dist/runtime/platform-node.js +31 -0
  55. package/dist/runtime/platform-react-native.d.ts +2 -0
  56. package/dist/runtime/platform-react-native.js +15 -0
  57. package/dist/runtime/platform.d.ts +15 -0
  58. package/dist/runtime/platform.js +1 -0
  59. package/dist/runtime/random-id.d.ts +1 -0
  60. package/dist/runtime/random-id.js +26 -0
  61. package/dist/runtime-entry.d.ts +5 -0
  62. package/dist/runtime-entry.js +2 -0
  63. package/dist/storage/browser-indexeddb.d.ts +7 -16
  64. package/dist/storage/browser-indexeddb.js +102 -19
  65. package/dist/storage/react-native-jsonl.d.ts +7 -16
  66. package/dist/storage/react-native-jsonl.js +65 -19
  67. package/dist/types.d.ts +54 -1
  68. package/dist-cjs/amarsia/analytics.js +447 -0
  69. package/dist-cjs/amarsia/endpoint.js +32 -0
  70. package/dist-cjs/amarsia/sync.js +2 -5
  71. package/dist-cjs/browser.js +48 -0
  72. package/dist-cjs/compiler/build-project.js +97 -8
  73. package/dist-cjs/compiler/compile.js +17 -9
  74. package/dist-cjs/errors.js +92 -2
  75. package/dist-cjs/file-content.js +42 -7
  76. package/dist-cjs/index.js +4 -9
  77. package/dist-cjs/integrations/esbuild.js +6 -2
  78. package/dist-cjs/integrations/expo.js +29 -0
  79. package/dist-cjs/integrations/metro.js +51 -0
  80. package/dist-cjs/integrations/next.js +75 -0
  81. package/dist-cjs/integrations/runtime-build.js +70 -0
  82. package/dist-cjs/integrations/vite.js +57 -0
  83. package/dist-cjs/integrations/webpack.js +51 -0
  84. package/dist-cjs/orcha.js +17 -12
  85. package/dist-cjs/playground/server.js +62 -9
  86. package/dist-cjs/project-loader.js +10 -0
  87. package/dist-cjs/providers/browser.js +61 -0
  88. package/dist-cjs/react-native.js +48 -0
  89. package/dist-cjs/runtime/actions/browser-native.js +68 -0
  90. package/dist-cjs/runtime/actions/execute.js +12 -2
  91. package/dist-cjs/runtime/agent.js +37 -14
  92. package/dist-cjs/runtime/compiler-hook.js +37 -0
  93. package/dist-cjs/runtime/create-orcha.js +34 -23
  94. package/dist-cjs/runtime/platform-browser.js +48 -0
  95. package/dist-cjs/runtime/platform-node.js +59 -0
  96. package/dist-cjs/runtime/platform-react-native.js +45 -0
  97. package/dist-cjs/runtime/platform.js +17 -0
  98. package/dist-cjs/runtime/random-id.js +55 -0
  99. package/dist-cjs/runtime-entry.js +34 -0
  100. package/dist-cjs/storage/browser-indexeddb.js +102 -5
  101. package/dist-cjs/storage/react-native-jsonl.js +73 -5
  102. package/dist-cjs/types/react-native-async-storage.d.js +2 -0
  103. package/package.json +69 -9
  104. package/dist/playground/public/app.css +0 -1
  105. package/dist/playground/public/app.js +0 -31
  106. package/dist/playground/public/index.html +0 -15
  107. package/dist/playground/public/orcha-logo.svg +0 -4
@@ -20,11 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var execute_exports = {};
21
21
  __export(execute_exports, {
22
22
  executeLocalAction: () => executeLocalAction,
23
+ setNativeRuntimeLoader: () => setNativeRuntimeLoader,
23
24
  setSandboxRuntimeLoader: () => setSandboxRuntimeLoader
24
25
  });
25
26
  module.exports = __toCommonJS(execute_exports);
26
27
  var import_context = require("./context.js");
27
- var import_native = require("./native.js");
28
+ let loadConfiguredNativeRuntime = async () => {
29
+ throw new Error(
30
+ "The native action runtime was not included in this Orcha build."
31
+ );
32
+ };
28
33
  let loadConfiguredSandboxRuntime = async () => {
29
34
  throw new Error(
30
35
  "The QuickJS sandbox runtime was not included in this Orcha build."
@@ -33,10 +38,14 @@ let loadConfiguredSandboxRuntime = async () => {
33
38
  function setSandboxRuntimeLoader(loader) {
34
39
  loadConfiguredSandboxRuntime = loader;
35
40
  }
41
+ function setNativeRuntimeLoader(loader) {
42
+ loadConfiguredNativeRuntime = loader;
43
+ }
36
44
  async function executeLocalAction(options) {
37
45
  const context = (0, import_context.createLocalActionContext)(options);
38
46
  if (options.configuration.runtime === "native") {
39
- return (0, import_native.executeNativeAction)(options.action, options.parameters, context);
47
+ const { executeNativeAction } = await loadConfiguredNativeRuntime();
48
+ return executeNativeAction(options.action, options.parameters, context);
40
49
  }
41
50
  if (process.env.ORCHA_INCLUDE_SANDBOX !== "0") {
42
51
  const { executeSandboxedAction } = await loadSandboxRuntime();
@@ -69,5 +78,6 @@ async function loadSandboxRuntime() {
69
78
  // Annotate the CommonJS export names for ESM import in node:
70
79
  0 && (module.exports = {
71
80
  executeLocalAction,
81
+ setNativeRuntimeLoader,
72
82
  setSandboxRuntimeLoader
73
83
  });
@@ -22,13 +22,13 @@ __export(agent_exports, {
22
22
  RuntimeAgent: () => RuntimeAgent
23
23
  });
24
24
  module.exports = __toCommonJS(agent_exports);
25
- var import_crypto = require("crypto");
26
25
  var import_errors = require("../errors.js");
27
26
  var import_file_content = require("../file-content.js");
28
27
  var import_session_events = require("./session-events.js");
29
28
  var import_structured_output = require("./structured-output.js");
30
29
  var import_execute = require("./actions/execute.js");
31
30
  var import_execution = require("./execution.js");
31
+ var import_random_id = require("./random-id.js");
32
32
  const LOAD_SKILL_TOOL_NAME = "load_skill";
33
33
  const RUN_AGENT_TOOL_NAME = "run_agent";
34
34
  const RESUME_AGENT_TOOL_NAME = "resume_agent";
@@ -51,6 +51,7 @@ class RuntimeAgent {
51
51
  #agentKey;
52
52
  #sessionIdPrefix;
53
53
  #projectRoot;
54
+ #randomUUID;
54
55
  #evaluationTasks = /* @__PURE__ */ new Map();
55
56
  #sessionIdleWaiters = /* @__PURE__ */ new Map();
56
57
  constructor(options) {
@@ -64,7 +65,8 @@ class RuntimeAgent {
64
65
  this.#delegatedOnly = options.delegatedOnly ?? false;
65
66
  this.#agentKey = options.manifest.key ?? options.manifest.name;
66
67
  this.#sessionIdPrefix = options.sessionIdPrefix ?? "ses_";
67
- this.#projectRoot = options.projectRoot ?? process.cwd();
68
+ this.#projectRoot = options.projectRoot ?? ".";
69
+ this.#randomUUID = options.randomUUID ?? import_random_id.portableRandomUUID;
68
70
  }
69
71
  get agent() {
70
72
  return this.#agentKey;
@@ -91,7 +93,7 @@ class RuntimeAgent {
91
93
  return this.#run(input);
92
94
  }
93
95
  createDelegatedSessionId() {
94
- return createSessionId(this.#sessionIdPrefix);
96
+ return createSessionId(this.#sessionIdPrefix, this.#randomUUID);
95
97
  }
96
98
  runAsChild(sessionId, input, lineage) {
97
99
  const normalized = typeof input === "string" ? { content: input } : input;
@@ -106,7 +108,7 @@ class RuntimeAgent {
106
108
  }
107
109
  #run(input, lineage, requestedSessionId) {
108
110
  const normalized = typeof input === "string" ? { content: input } : input;
109
- const sessionId = requestedSessionId ?? createSessionId(this.#sessionIdPrefix);
111
+ const sessionId = requestedSessionId ?? createSessionId(this.#sessionIdPrefix, this.#randomUUID);
110
112
  if (typeof normalized === "object" && normalized !== null && "sessionId" in normalized) {
111
113
  return this.#createExecution(
112
114
  sessionId,
@@ -812,10 +814,9 @@ class RuntimeAgent {
812
814
  }
813
815
  providerTools.push(...this.#subagentToolDefinitions());
814
816
  try {
815
- response = await this.#generateProviderResponse(
816
- this.#manifest.provider,
817
- provider,
818
- {
817
+ const signal = this.#sessionControls.get(sessionId)?.controller.signal;
818
+ response = await withProviderConnectionRetry(
819
+ () => this.#generateProviderResponse(this.#manifest.provider, provider, {
819
820
  model: this.#manifest.model,
820
821
  region: this.#manifest.region,
821
822
  maxTokens: this.#manifest.maxTokens,
@@ -833,8 +834,9 @@ class RuntimeAgent {
833
834
  streamedOutput = output;
834
835
  publishOutput?.(output);
835
836
  },
836
- signal: this.#sessionControls.get(sessionId)?.controller.signal
837
- }
837
+ signal
838
+ }),
839
+ signal
838
840
  );
839
841
  } catch (error) {
840
842
  if (this.#sessionControls.get(sessionId)?.pauseRequested) {
@@ -875,10 +877,19 @@ class RuntimeAgent {
875
877
  if (error instanceof import_errors.OrchaError) {
876
878
  throw error;
877
879
  }
880
+ const providerError = (0, import_errors.describeProviderError)(error);
878
881
  throw new import_errors.OrchaError(
879
882
  "provider_error",
880
- error instanceof Error ? error.message : String(error),
881
- { retryable: true, cause: error }
883
+ providerError.message,
884
+ {
885
+ retryable: true,
886
+ cause: error,
887
+ details: {
888
+ provider: this.#manifest.provider,
889
+ model: this.#manifest.model,
890
+ ...providerError.details
891
+ }
892
+ }
882
893
  );
883
894
  }
884
895
  const modelDurationMs = Math.round(performance.now() - modelStartedAt);
@@ -2126,9 +2137,9 @@ function normalizeMetadata(metadata) {
2126
2137
  }
2127
2138
  return normalized;
2128
2139
  }
2129
- function createSessionId(prefix) {
2140
+ function createSessionId(prefix, randomUUID) {
2130
2141
  const utcTimestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "").replace("T", "_");
2131
- return `${prefix}${utcTimestamp}_${(0, import_crypto.randomUUID)()}`;
2142
+ return `${prefix}${utcTimestamp}_${randomUUID()}`;
2132
2143
  }
2133
2144
  function normalizeVariables(variables) {
2134
2145
  if (variables === void 0) {
@@ -2822,6 +2833,18 @@ function findLast(events, predicate) {
2822
2833
  }
2823
2834
  return void 0;
2824
2835
  }
2836
+ async function withProviderConnectionRetry(operation, signal) {
2837
+ try {
2838
+ return await operation();
2839
+ } catch (error) {
2840
+ if (signal?.aborted || !(0, import_errors.isRetryableProviderConnectionError)(error)) {
2841
+ throw error;
2842
+ }
2843
+ await new Promise((resolve) => setTimeout(resolve, 250));
2844
+ if (signal?.aborted) throw error;
2845
+ return operation();
2846
+ }
2847
+ }
2825
2848
  function failure(sessionId, code, message, options = {}) {
2826
2849
  const retryable = options.retryable ?? (code === "session_busy" || code === "provider_error" || code === "storage_error");
2827
2850
  return {
@@ -0,0 +1,37 @@
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 compiler_hook_exports = {};
21
+ __export(compiler_hook_exports, {
22
+ getRegistryCompiler: () => getRegistryCompiler,
23
+ setRegistryCompiler: () => setRegistryCompiler
24
+ });
25
+ module.exports = __toCommonJS(compiler_hook_exports);
26
+ let registryCompiler;
27
+ function setRegistryCompiler(compiler) {
28
+ registryCompiler = compiler;
29
+ }
30
+ function getRegistryCompiler() {
31
+ return registryCompiler;
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ getRegistryCompiler,
36
+ setRegistryCompiler
37
+ });
@@ -22,35 +22,36 @@ __export(create_orcha_exports, {
22
22
  createOrcha: () => createOrcha
23
23
  });
24
24
  module.exports = __toCommonJS(create_orcha_exports);
25
- var import_path = require("path");
26
25
  var import_agent = require("./agent.js");
27
- var import_create_store = require("../storage/create-store.js");
28
- var import_sync = require("../amarsia/sync.js");
26
+ var import_analytics = require("../amarsia/analytics.js");
29
27
  var import_context = require("./context.js");
30
28
  class OrchaRuntimeCore {
31
29
  #agents = /* @__PURE__ */ new Map();
32
30
  #bundle;
33
31
  #client;
32
+ #telemetry;
34
33
  #activeSessions = /* @__PURE__ */ new Set();
35
34
  #sessionControls = /* @__PURE__ */ new Map();
36
35
  #resolveBundle;
37
36
  #generateProviderResponse;
38
- constructor(resolveBundle, generateProviderResponse) {
37
+ #platform;
38
+ constructor(resolveBundle, generateProviderResponse, platform) {
39
39
  this.#resolveBundle = resolveBundle;
40
40
  this.#generateProviderResponse = generateProviderResponse;
41
+ this.#platform = platform;
41
42
  }
42
43
  attachClient(client) {
43
44
  this.#client = client;
44
45
  }
45
46
  init(configuration) {
46
- const projectRoot = (0, import_path.resolve)(
47
- configuration.root ?? process.env.ORCHA_PROJECT_ROOT ?? process.cwd()
48
- );
49
- const bundle = this.#resolveBundle(configuration);
50
- if (configuration.amarsia?.key) {
51
- (0, import_sync.syncAmarsiaProject)({
52
- key: configuration.amarsia.key,
53
- endpoint: configuration.amarsia.endpoint,
47
+ if (this.#telemetry) {
48
+ void this.#telemetry.close();
49
+ }
50
+ const projectRoot = this.#platform.projectRoot(configuration);
51
+ const bundle = configuration.bundle ?? this.#resolveBundle(configuration);
52
+ if (configuration.amarsia?.key && this.#platform.syncProject) {
53
+ this.#platform.syncProject({
54
+ configuration,
54
55
  bundle,
55
56
  projectRoot
56
57
  });
@@ -73,13 +74,17 @@ class OrchaRuntimeCore {
73
74
  `Production bundle expects local action runtime "${bundle.actionRuntime}".`
74
75
  );
75
76
  }
76
- const storageDirectory = configuration.storage?.directory ?? ".orcha/sessions";
77
- const createStore = (manifest) => (0, import_create_store.createSessionStore)({
78
- strategy: configuration.storage?.strategy,
79
- directory: storageDirectory,
77
+ const createStore = (manifest) => this.#platform.createSessionStore({
78
+ configuration,
80
79
  projectRoot,
81
- agentName: manifest.key ?? manifest.name
80
+ manifest
82
81
  });
82
+ const telemetry = configuration.amarsia?.key ? new import_analytics.AmarsiaTelemetryClient(configuration.amarsia) : void 0;
83
+ this.#telemetry = telemetry;
84
+ const createRuntimeStore = (manifest) => {
85
+ const store = createStore(manifest);
86
+ return telemetry ? (0, import_analytics.withAmarsiaTelemetry)({ store, manifest, client: telemetry }) : store;
87
+ };
83
88
  const agents = /* @__PURE__ */ new Map();
84
89
  for (const [name, manifest] of Object.entries(bundle.agents)) {
85
90
  const subagents = Object.fromEntries(
@@ -89,12 +94,13 @@ class OrchaRuntimeCore {
89
94
  new import_agent.RuntimeAgent({
90
95
  manifest: subagentManifest,
91
96
  configuration: runtimeConfiguration,
92
- store: createStore(subagentManifest),
97
+ store: createRuntimeStore(subagentManifest),
93
98
  activeSessions: this.#activeSessions,
94
99
  sessionControls: this.#sessionControls,
95
100
  generateProviderResponse: this.#generateProviderResponse,
96
101
  delegatedOnly: true,
97
- projectRoot
102
+ projectRoot,
103
+ randomUUID: this.#platform.randomUUID
98
104
  })
99
105
  ]
100
106
  )
@@ -104,12 +110,13 @@ class OrchaRuntimeCore {
104
110
  new import_agent.RuntimeAgent({
105
111
  manifest,
106
112
  configuration: runtimeConfiguration,
107
- store: createStore(manifest),
113
+ store: createRuntimeStore(manifest),
108
114
  activeSessions: this.#activeSessions,
109
115
  sessionControls: this.#sessionControls,
110
116
  generateProviderResponse: this.#generateProviderResponse,
111
117
  subagents,
112
- projectRoot
118
+ projectRoot,
119
+ randomUUID: this.#platform.randomUUID
113
120
  })
114
121
  );
115
122
  }
@@ -127,6 +134,9 @@ class OrchaRuntimeCore {
127
134
  isInitialized() {
128
135
  return this.#bundle !== void 0;
129
136
  }
137
+ async flushTelemetry(options) {
138
+ await this.#telemetry?.drain(options);
139
+ }
130
140
  getCompiledBundle() {
131
141
  if (!this.#bundle) {
132
142
  throw new Error("Orcha has not been initialized.");
@@ -137,10 +147,11 @@ class OrchaRuntimeCore {
137
147
  return this.#agents.get(name);
138
148
  }
139
149
  }
140
- function createOrcha(resolveBundle, generateProviderResponse) {
150
+ function createOrcha(resolveBundle, generateProviderResponse, platform) {
141
151
  const core = new OrchaRuntimeCore(
142
152
  resolveBundle,
143
- generateProviderResponse
153
+ generateProviderResponse,
154
+ platform
144
155
  );
145
156
  const client = new Proxy(core, {
146
157
  get(target, property) {
@@ -0,0 +1,48 @@
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 platform_browser_exports = {};
21
+ __export(platform_browser_exports, {
22
+ browserRuntimePlatform: () => browserRuntimePlatform
23
+ });
24
+ module.exports = __toCommonJS(platform_browser_exports);
25
+ var import_browser_indexeddb = require("../storage/browser-indexeddb.js");
26
+ var import_random_id = require("./random-id.js");
27
+ const browserRuntimePlatform = {
28
+ randomUUID: import_random_id.portableRandomUUID,
29
+ projectRoot(configuration) {
30
+ return configuration.root ?? "/";
31
+ },
32
+ createSessionStore({ configuration, manifest }) {
33
+ const strategy = configuration.storage?.strategy ?? "indexeddb";
34
+ if (strategy !== "indexeddb") {
35
+ throw new Error(
36
+ `Browser runtimes require storage strategy "indexeddb", received "${strategy}".`
37
+ );
38
+ }
39
+ return new import_browser_indexeddb.BrowserIndexedDbSessionStore(
40
+ manifest.key ?? manifest.name,
41
+ configuration.storage?.directory ?? "orchajs"
42
+ );
43
+ }
44
+ };
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ browserRuntimePlatform
48
+ });
@@ -0,0 +1,59 @@
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 platform_node_exports = {};
21
+ __export(platform_node_exports, {
22
+ nodeRuntimePlatform: () => nodeRuntimePlatform
23
+ });
24
+ module.exports = __toCommonJS(platform_node_exports);
25
+ var import_crypto = require("crypto");
26
+ var import_path = require("path");
27
+ var import_sync = require("../amarsia/sync.js");
28
+ var import_create_store = require("../storage/create-store.js");
29
+ const nodeRuntimePlatform = {
30
+ randomUUID: import_crypto.randomUUID,
31
+ projectRoot(configuration) {
32
+ return (0, import_path.resolve)(
33
+ configuration.root ?? process.env.ORCHA_PROJECT_ROOT ?? process.cwd()
34
+ );
35
+ },
36
+ createSessionStore({ configuration, projectRoot, manifest }) {
37
+ return (0, import_create_store.createSessionStore)({
38
+ strategy: configuration.storage?.strategy,
39
+ directory: configuration.storage?.directory,
40
+ projectRoot,
41
+ agentName: manifest.key ?? manifest.name
42
+ });
43
+ },
44
+ syncProject({ configuration, bundle, projectRoot }) {
45
+ if (!configuration.amarsia?.key) {
46
+ return;
47
+ }
48
+ (0, import_sync.syncAmarsiaProject)({
49
+ key: configuration.amarsia.key,
50
+ endpoint: configuration.amarsia.endpoint,
51
+ bundle,
52
+ projectRoot
53
+ });
54
+ }
55
+ };
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ nodeRuntimePlatform
59
+ });
@@ -0,0 +1,45 @@
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 platform_react_native_exports = {};
21
+ __export(platform_react_native_exports, {
22
+ reactNativeRuntimePlatform: () => reactNativeRuntimePlatform
23
+ });
24
+ module.exports = __toCommonJS(platform_react_native_exports);
25
+ var import_react_native_jsonl = require("../storage/react-native-jsonl.js");
26
+ var import_random_id = require("./random-id.js");
27
+ const reactNativeRuntimePlatform = {
28
+ randomUUID: import_random_id.portableRandomUUID,
29
+ projectRoot(configuration) {
30
+ return configuration.root ?? "/";
31
+ },
32
+ createSessionStore({ configuration, manifest }) {
33
+ const strategy = configuration.storage?.strategy ?? "react-native";
34
+ if (strategy !== "react-native") {
35
+ throw new Error(
36
+ `React Native requires storage strategy "react-native", received "${strategy}".`
37
+ );
38
+ }
39
+ return new import_react_native_jsonl.ReactNativeJsonlSessionStore(manifest.key ?? manifest.name);
40
+ }
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ reactNativeRuntimePlatform
45
+ });
@@ -0,0 +1,17 @@
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 __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var platform_exports = {};
17
+ module.exports = __toCommonJS(platform_exports);
@@ -0,0 +1,55 @@
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 random_id_exports = {};
21
+ __export(random_id_exports, {
22
+ portableRandomUUID: () => portableRandomUUID
23
+ });
24
+ module.exports = __toCommonJS(random_id_exports);
25
+ let fallbackSequence = 0;
26
+ function portableRandomUUID() {
27
+ const crypto = globalThis.crypto;
28
+ if (typeof crypto?.randomUUID === "function") {
29
+ return crypto.randomUUID();
30
+ }
31
+ if (typeof crypto?.getRandomValues === "function") {
32
+ return formatUuid(crypto.getRandomValues(new Uint8Array(16)));
33
+ }
34
+ fallbackSequence = fallbackSequence + 1 >>> 0;
35
+ const bytes = new Uint8Array(16);
36
+ let state = Date.now() ^ fallbackSequence ^ Math.floor(Math.random() * 4294967296);
37
+ for (let index = 0; index < bytes.length; index += 1) {
38
+ state = Math.imul(state, 1664525) + 1013904223 >>> 0;
39
+ bytes[index] = state >>> 24;
40
+ }
41
+ return formatUuid(bytes);
42
+ }
43
+ function formatUuid(bytes) {
44
+ bytes[6] = bytes[6] & 15 | 64;
45
+ bytes[8] = bytes[8] & 63 | 128;
46
+ const value = Array.from(
47
+ bytes,
48
+ (byte) => byte.toString(16).padStart(2, "0")
49
+ ).join("");
50
+ return `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
51
+ }
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ portableRandomUUID
55
+ });
@@ -0,0 +1,34 @@
1
+ "use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var runtime_entry_exports = {};
21
+ __export(runtime_entry_exports, {
22
+ OrchaError: () => import_errors.OrchaError,
23
+ exportSessionJsonl: () => import_migrate.exportSessionJsonl,
24
+ migrateSessionStore: () => import_migrate.migrateSessionStore
25
+ });
26
+ module.exports = __toCommonJS(runtime_entry_exports);
27
+ var import_errors = require("./errors.js");
28
+ var import_migrate = require("./storage/migrate.js");
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ OrchaError,
32
+ exportSessionJsonl,
33
+ migrateSessionStore
34
+ });