orchajs 0.26.1 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ "use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var compiled_manifest_exports = {};
21
+ __export(compiled_manifest_exports, {
22
+ compiledManifest: () => compiledManifest
23
+ });
24
+ module.exports = __toCommonJS(compiled_manifest_exports);
25
+ const compiledManifest = void 0;
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ compiledManifest
29
+ });
@@ -19,8 +19,10 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var compiler_hook_exports = {};
21
21
  __export(compiler_hook_exports, {
22
+ getGlobalCompiledManifest: () => getGlobalCompiledManifest,
22
23
  getRegistryCompiler: () => getRegistryCompiler,
23
24
  isRegistryCompilationActive: () => isRegistryCompilationActive,
25
+ setGlobalCompiledManifest: () => setGlobalCompiledManifest,
24
26
  setRegistryCompilationActive: () => setRegistryCompilationActive,
25
27
  setRegistryCompiler: () => setRegistryCompiler
26
28
  });
@@ -31,7 +33,8 @@ function getCompilerHookState() {
31
33
  if (!globalRecord[COMPILER_HOOK_STATE_KEY]) {
32
34
  globalRecord[COMPILER_HOOK_STATE_KEY] = {
33
35
  registryCompiler: void 0,
34
- registryCompilationActive: false
36
+ registryCompilationActive: false,
37
+ compiledManifest: void 0
35
38
  };
36
39
  }
37
40
  return globalRecord[COMPILER_HOOK_STATE_KEY];
@@ -48,10 +51,18 @@ function setRegistryCompilationActive(active) {
48
51
  function isRegistryCompilationActive() {
49
52
  return getCompilerHookState().registryCompilationActive;
50
53
  }
54
+ function setGlobalCompiledManifest(bundle) {
55
+ getCompilerHookState().compiledManifest = bundle;
56
+ }
57
+ function getGlobalCompiledManifest() {
58
+ return getCompilerHookState().compiledManifest;
59
+ }
51
60
  // Annotate the CommonJS export names for ESM import in node:
52
61
  0 && (module.exports = {
62
+ getGlobalCompiledManifest,
53
63
  getRegistryCompiler,
54
64
  isRegistryCompilationActive,
65
+ setGlobalCompiledManifest,
55
66
  setRegistryCompilationActive,
56
67
  setRegistryCompiler
57
68
  });
@@ -1,10 +1,8 @@
1
1
  "use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
2
2
  "use strict";
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
7
  var __export = (target, all) => {
10
8
  for (var name in all)
@@ -18,21 +16,48 @@ var __copyProps = (to, from, except, desc) => {
18
16
  }
19
17
  return to;
20
18
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
20
  var react_native_jsonl_exports = {};
31
21
  __export(react_native_jsonl_exports, {
32
22
  ReactNativeJsonlSessionStore: () => ReactNativeJsonlSessionStore
33
23
  });
34
24
  module.exports = __toCommonJS(react_native_jsonl_exports);
35
- var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"), 1);
25
+ const fallbackMemoryMap = /* @__PURE__ */ new Map();
26
+ const fallbackMemoryStorage = {
27
+ async getItem(key) {
28
+ return fallbackMemoryMap.get(key) ?? null;
29
+ },
30
+ async setItem(key, value) {
31
+ fallbackMemoryMap.set(key, value);
32
+ },
33
+ async removeItem(key) {
34
+ fallbackMemoryMap.delete(key);
35
+ },
36
+ async getAllKeys() {
37
+ return [...fallbackMemoryMap.keys()];
38
+ },
39
+ async multiSet(keyValuePairs) {
40
+ for (const [key, value] of keyValuePairs) {
41
+ fallbackMemoryMap.set(key, value);
42
+ }
43
+ }
44
+ };
45
+ let resolvedAsyncStoragePromise;
46
+ function getAsyncStorage() {
47
+ if (!resolvedAsyncStoragePromise) {
48
+ const moduleSpecifier = "@react-native-async-storage/async-storage";
49
+ resolvedAsyncStoragePromise = import(moduleSpecifier).then((loaded) => {
50
+ if (loaded?.default && typeof loaded.default.getItem === "function") {
51
+ return loaded.default;
52
+ }
53
+ if (typeof loaded?.getItem === "function") {
54
+ return loaded;
55
+ }
56
+ return fallbackMemoryStorage;
57
+ }).catch(() => fallbackMemoryStorage);
58
+ }
59
+ return resolvedAsyncStoragePromise;
60
+ }
36
61
  const writes = /* @__PURE__ */ new Map();
37
62
  const tailIndexes = /* @__PURE__ */ new Map();
38
63
  const TAIL_CHUNK_SIZE = 100;
@@ -45,7 +70,8 @@ class ReactNativeJsonlSessionStore {
45
70
  this.#namespace = namespace;
46
71
  }
47
72
  async read(sessionId) {
48
- const contents = await import_async_storage.default.getItem(this.#key(sessionId));
73
+ const storage = await getAsyncStorage();
74
+ const contents = await storage.getItem(this.#key(sessionId));
49
75
  if (!contents) {
50
76
  return [];
51
77
  }
@@ -55,6 +81,7 @@ class ReactNativeJsonlSessionStore {
55
81
  if (!Number.isInteger(afterSequence) || afterSequence < 0 || !Number.isInteger(limit) || limit <= 0) {
56
82
  throw new Error("Invalid session event tail range.");
57
83
  }
84
+ const storage = await getAsyncStorage();
58
85
  await writes.get(this.#key(sessionId))?.catch(() => void 0);
59
86
  const index = await this.#ensureTailIndex(sessionId);
60
87
  const relevant = index.chunks.filter(
@@ -62,7 +89,7 @@ class ReactNativeJsonlSessionStore {
62
89
  );
63
90
  const events = [];
64
91
  for (const chunk of relevant) {
65
- const contents = await import_async_storage.default.getItem(chunk.key);
92
+ const contents = await storage.getItem(chunk.key);
66
93
  if (contents === null) {
67
94
  tailIndexes.delete(this.#tailIndexKey(sessionId));
68
95
  return this.#readTailFromCanonical(
@@ -86,11 +113,12 @@ class ReactNativeJsonlSessionStore {
86
113
  const key = this.#key(sessionId);
87
114
  const previous = writes.get(key) ?? Promise.resolve();
88
115
  const write = previous.then(async () => {
116
+ const storage = await getAsyncStorage();
89
117
  const index = await this.#ensureTailIndex(sessionId);
90
- await import_async_storage.default.setItem(this.#tailPendingKey(sessionId), "1");
91
- const existing = await import_async_storage.default.getItem(key);
118
+ await storage.setItem(this.#tailPendingKey(sessionId), "1");
119
+ const existing = await storage.getItem(key);
92
120
  const appended = events.map((event) => JSON.stringify(event)).join("\n");
93
- await import_async_storage.default.setItem(
121
+ await storage.setItem(
94
122
  key,
95
123
  `${existing ? `${existing.replace(/\n*$/, "")}
96
124
  ` : ""}${appended}
@@ -98,7 +126,7 @@ class ReactNativeJsonlSessionStore {
98
126
  );
99
127
  try {
100
128
  await this.#appendTailIndex(sessionId, index, events);
101
- await import_async_storage.default.removeItem(this.#tailPendingKey(sessionId));
129
+ await storage.removeItem(this.#tailPendingKey(sessionId));
102
130
  } catch {
103
131
  tailIndexes.delete(this.#tailIndexKey(sessionId));
104
132
  }
@@ -115,12 +143,14 @@ class ReactNativeJsonlSessionStore {
115
143
  this.#allListeners.forEach((listener) => listener(sessionId, events));
116
144
  }
117
145
  async listSessionIds() {
146
+ const storage = await getAsyncStorage();
118
147
  const prefix = `@orchajs:${this.#namespace}:`;
119
- return (await import_async_storage.default.getAllKeys()).filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length)).sort();
148
+ return (await storage.getAllKeys()).filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length)).sort();
120
149
  }
121
150
  async getCloudAcknowledgement(sessionId) {
151
+ const storage = await getAsyncStorage();
122
152
  const value = Number(
123
- await import_async_storage.default.getItem(this.#acknowledgementKey(sessionId))
153
+ await storage.getItem(this.#acknowledgementKey(sessionId))
124
154
  );
125
155
  return Number.isInteger(value) && value >= 0 ? value : 0;
126
156
  }
@@ -131,9 +161,10 @@ class ReactNativeJsonlSessionStore {
131
161
  const key = this.#acknowledgementKey(sessionId);
132
162
  const previous = writes.get(key) ?? Promise.resolve();
133
163
  const write = previous.then(async () => {
134
- const current = Number(await import_async_storage.default.getItem(key));
164
+ const storage = await getAsyncStorage();
165
+ const current = Number(await storage.getItem(key));
135
166
  if (!Number.isInteger(current) || current < sequence) {
136
- await import_async_storage.default.setItem(key, String(sequence));
167
+ await storage.setItem(key, String(sequence));
137
168
  }
138
169
  });
139
170
  writes.set(key, write);
@@ -178,14 +209,15 @@ class ReactNativeJsonlSessionStore {
178
209
  return `@orchajs-tail-chunk:${this.#namespace}:${sessionId}:${Date.now()}:${tailChunkGeneration}`;
179
210
  }
180
211
  async #ensureTailIndex(sessionId) {
212
+ const storage = await getAsyncStorage();
181
213
  const indexKey = this.#tailIndexKey(sessionId);
182
- const pending = await import_async_storage.default.getItem(
214
+ const pending = await storage.getItem(
183
215
  this.#tailPendingKey(sessionId)
184
216
  );
185
217
  if (!pending) {
186
218
  const cached = tailIndexes.get(indexKey);
187
219
  if (cached) return cached;
188
- const stored = await import_async_storage.default.getItem(indexKey);
220
+ const stored = await storage.getItem(indexKey);
189
221
  if (stored) {
190
222
  try {
191
223
  const parsed = parseTailIndex(stored);
@@ -198,6 +230,7 @@ class ReactNativeJsonlSessionStore {
198
230
  return this.#rebuildTailIndex(sessionId);
199
231
  }
200
232
  async #rebuildTailIndex(sessionId) {
233
+ const storage = await getAsyncStorage();
201
234
  const events = await this.read(sessionId);
202
235
  const chunks = [];
203
236
  const writes2 = [];
@@ -213,19 +246,20 @@ class ReactNativeJsonlSessionStore {
213
246
  chunks
214
247
  };
215
248
  writes2.push([this.#tailIndexKey(sessionId), JSON.stringify(index)]);
216
- if (writes2.length > 0) await import_async_storage.default.multiSet(writes2);
217
- await import_async_storage.default.removeItem(this.#tailPendingKey(sessionId));
249
+ if (writes2.length > 0) await storage.multiSet(writes2);
250
+ await storage.removeItem(this.#tailPendingKey(sessionId));
218
251
  tailIndexes.set(this.#tailIndexKey(sessionId), index);
219
252
  return index;
220
253
  }
221
254
  async #appendTailIndex(sessionId, current, events) {
255
+ const storage = await getAsyncStorage();
222
256
  const chunks = [...current.chunks];
223
257
  const replacements = [];
224
258
  const obsolete = [];
225
259
  let remaining = [...events];
226
260
  const last = chunks.at(-1);
227
261
  if (last && last.count < TAIL_CHUNK_SIZE) {
228
- const stored = await import_async_storage.default.getItem(last.key);
262
+ const stored = await storage.getItem(last.key);
229
263
  if (stored === null) throw new Error("Missing tail index chunk.");
230
264
  const retained = parseEvents(stored).slice(0, last.count);
231
265
  const added = remaining.splice(
@@ -253,18 +287,19 @@ class ReactNativeJsonlSessionStore {
253
287
  this.#tailIndexKey(sessionId),
254
288
  JSON.stringify(index)
255
289
  ]);
256
- await import_async_storage.default.multiSet(replacements);
290
+ await storage.multiSet(replacements);
257
291
  tailIndexes.set(this.#tailIndexKey(sessionId), index);
258
292
  await Promise.all(
259
- obsolete.map((key) => import_async_storage.default.removeItem(key))
293
+ obsolete.map((key) => storage.removeItem(key))
260
294
  );
261
295
  }
262
296
  async #readTailFromCanonical(sessionId, afterSequence, limit) {
297
+ const storage = await getAsyncStorage();
263
298
  const index = await this.#rebuildTailIndex(sessionId);
264
299
  const events = [];
265
300
  for (const chunk of index.chunks) {
266
301
  if (chunk.lastSequence <= afterSequence) continue;
267
- const contents = await import_async_storage.default.getItem(chunk.key);
302
+ const contents = await storage.getItem(chunk.key);
268
303
  if (!contents) continue;
269
304
  for (const event of parseEvents(contents).slice(0, chunk.count)) {
270
305
  if (event.sequence > afterSequence) events.push(event);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orchajs",
3
- "version": "0.26.1",
3
+ "version": "0.27.0",
4
4
  "description": "A filesystem-convention, stateful agent framework for JavaScript.",
5
5
  "license": "MIT",
6
6
  "repository": {