@yielded/agent-storage-memory 0.1.0-beta.172 → 0.1.0-beta.174

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.
@@ -33,19 +33,19 @@ const isBatchBoundary = (thread, sequence) => {
33
33
  return record !== void 0 && thread.batches.get(record.batchId)?.result.lastSequence === sequence;
34
34
  };
35
35
  const storedBytes = (thread, sequence) => thread.chunks.get(Math.floor((sequence - 1) / RECORD_CHUNK_SIZE))?.bytes[(sequence - 1) % RECORD_CHUNK_SIZE];
36
- const storedPage = (thread, after, limit) => {
36
+ const storedPage = Effect.fnUntraced(function* (thread, after, limit) {
37
37
  const page = [];
38
38
  let bytes = 0;
39
39
  for (let sequence = after + 1; sequence <= Math.min(thread.tailSequence, after + limit); sequence++) {
40
40
  const record = storedRecord(thread, sequence);
41
- if (record === void 0) throw new Error("Incomplete canonical chunk table");
41
+ if (record === void 0) return yield* storeError("read", "Incomplete canonical chunk table");
42
42
  const size = storedBytes(thread, sequence) ?? 0;
43
43
  if (bytes + size > 33554432) break;
44
44
  bytes += size;
45
45
  page.push(record);
46
46
  }
47
47
  return page;
48
- };
48
+ });
49
49
  const retainRecords = (thread, records) => {
50
50
  for (const entry of records) {
51
51
  const chunkId = Math.floor((entry.sequence - 1) / RECORD_CHUNK_SIZE);
@@ -747,7 +747,7 @@ const makeThreadStore = Effect.gen(function* () {
747
747
  const index = yield* readyIndex(request.threadId, thread.tailSequence).pipe(Effect.mapError((cause) => storeError("countPeerMessages", cause.message)));
748
748
  return Math.min(index.foreign.peer + (deliveryTransfer?.peerCount(request.threadId, request.nowMillis, request.limit) ?? 0), request.limit);
749
749
  });
750
- const readSnapshot = (threadId, afterSequence, limit) => Ref.get(state).pipe(Effect.flatMap((current) => findThread(current, threadId)), Effect.map((thread) => {
750
+ const readSnapshot = (threadId, afterSequence, limit) => Ref.get(state).pipe(Effect.flatMap((current) => findThread(current, threadId)), Effect.flatMap((thread) => {
751
751
  return storedPage(thread, afterSequence ?? ZERO_CANONICAL_SEQUENCE, limit);
752
752
  }));
753
753
  const selectedStream = (sources, after, through, maximum) => Stream.paginate({
@@ -783,7 +783,7 @@ const makeThreadStore = Effect.gen(function* () {
783
783
  after: request.afterSequence ?? ZERO_CANONICAL_SEQUENCE,
784
784
  count: 0
785
785
  }, (cursor) => Effect.gen(function* () {
786
- const page = storedPage(thread, cursor.after, Math.min(READ_PAGE_SIZE, request.limit - cursor.count));
786
+ const page = yield* storedPage(thread, cursor.after, Math.min(READ_PAGE_SIZE, request.limit - cursor.count));
787
787
  const next = {
788
788
  after: page.at(-1)?.sequence ?? cursor.after,
789
789
  count: cursor.count + page.length
@@ -1048,7 +1048,7 @@ const makeThreadStore = Effect.gen(function* () {
1048
1048
  const verificationReader = makeExportReader(false);
1049
1049
  const exportThread = (request) => exportThreadPage(request).pipe(Effect.provideService(ThreadExporterReader, exportReader));
1050
1050
  const verificationPage = (request) => exportThreadPage(request).pipe(Effect.provideService(ThreadExporterReader, verificationReader));
1051
- const exactRunRecords = (thread, runId) => Effect.gen(function* () {
1051
+ const exactRunRecords = Effect.fnUntraced(function* (thread, runId) {
1052
1052
  const records = [];
1053
1053
  let bytes = 0;
1054
1054
  const facts = thread.runRecords.get(runId) ?? [];
@@ -1480,20 +1480,20 @@ const makeThreadStore = Effect.gen(function* () {
1480
1480
  initializeWork: (threadId) => {
1481
1481
  if (!MutableRef.get(state.ref).threads.has(threadId) && !MutableRef.get(workState.ref).has(threadId)) publishWork(threadId, emptyWorkIndex());
1482
1482
  },
1483
- registerWorkOwner: (kind, owner) => withMutation(Effect.sync(() => {
1484
- if (workOwners.has(kind)) throw new Error(`MemoryThreadStore already has a ${kind} work owner`);
1483
+ registerWorkOwner: (kind, owner) => withMutation(Effect.gen(function* () {
1484
+ if (workOwners.has(kind)) return yield* Effect.die(storeError("initialize", `MemoryThreadStore already has a ${kind} work owner`));
1485
1485
  workOwners.set(kind, owner);
1486
1486
  })),
1487
- registerDeliveryLookup: (lookup) => withMutation(Effect.sync(() => {
1488
- if (deliveryLookup !== void 0) throw new Error("MemoryThreadStore already has a delivery lookup");
1487
+ registerDeliveryLookup: (lookup) => withMutation(Effect.gen(function* () {
1488
+ if (deliveryLookup !== void 0) return yield* Effect.die(storeError("initialize", "MemoryThreadStore already has a delivery lookup"));
1489
1489
  deliveryLookup = lookup;
1490
1490
  })),
1491
- registerLedgerTransfer: (transfer) => withMutation(Effect.sync(() => {
1492
- if (ledgerTransfer !== void 0) throw new Error("MemoryThreadStore already has a paired SubmissionLedger");
1491
+ registerLedgerTransfer: (transfer) => withMutation(Effect.gen(function* () {
1492
+ if (ledgerTransfer !== void 0) return yield* Effect.die(storeError("initialize", "MemoryThreadStore already has a paired SubmissionLedger"));
1493
1493
  ledgerTransfer = transfer;
1494
1494
  })),
1495
- registerDeliveryTransfer: (transfer) => withMutation(Effect.sync(() => {
1496
- if (deliveryTransfer !== void 0) throw new Error("MemoryThreadStore already has a paired delivery store");
1495
+ registerDeliveryTransfer: (transfer) => withMutation(Effect.gen(function* () {
1496
+ if (deliveryTransfer !== void 0) return yield* Effect.die(storeError("initialize", "MemoryThreadStore already has a paired delivery store"));
1497
1497
  deliveryTransfer = transfer;
1498
1498
  })),
1499
1499
  prepareAppend,