@pmate/chat-sdk 0.12.0-next.48 → 0.12.0-next.49

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.
@@ -424,19 +424,32 @@ export class DurableChatSender {
424
424
  if (!hashes.length)
425
425
  return;
426
426
  await this.ready;
427
- await this.withEpoch("rw", async () => {
428
- const previous = await this.outbox.bulkGet(hashes.map(hash => [this.scope, hash]));
429
- const confirmed = previous.filter((record) => Boolean(record && !record.confirmed)).map(record => ({ ...record, voiceBlob: undefined, voiceData: undefined, status: "sent", confirmed: true }));
430
- if (confirmed.length)
431
- await this.outbox.bulkPut(confirmed);
432
- });
433
427
  let changed = false;
434
- for (const hash of hashes) {
435
- changed = this.values.delete(hash) || changed;
436
- this.releaseUrl(hash);
428
+ try {
429
+ for (let offset = 0; offset < hashes.length; offset += 128) {
430
+ const batch = hashes.slice(offset, offset + 128);
431
+ await this.withEpoch("rw", async () => {
432
+ const previous = await this.outbox.bulkGet(batch.map(hash => [this.scope, hash]));
433
+ const confirmed = previous.filter((record) => Boolean(record && !record.confirmed)).map(record => ({ ...record, voiceBlob: undefined, voiceData: undefined, status: "sent", confirmed: true }));
434
+ if (confirmed.length)
435
+ await this.outbox.bulkPut(confirmed);
436
+ });
437
+ // Retire only committed rows. A later failed transaction leaves the
438
+ // remaining sends retryable, including after a browser restart.
439
+ for (const hash of batch) {
440
+ changed = this.values.delete(hash) || changed;
441
+ this.releaseUrl(hash);
442
+ }
443
+ if (offset + batch.length < hashes.length)
444
+ await new Promise(resolve => setTimeout(resolve, 0));
445
+ }
446
+ }
447
+ finally {
448
+ // One confirmation operation publishes at most once, also on partial
449
+ // failure so consumers see exactly the progress that was committed.
450
+ if (changed)
451
+ this.emit();
437
452
  }
438
- if (changed)
439
- this.emit();
440
453
  }
441
454
  async resume() {
442
455
  await this.ready;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/chat-sdk",
3
- "version": "0.12.0-next.48",
3
+ "version": "0.12.0-next.49",
4
4
  "description": "Cross-platform PMate chat input components, voice input primitives, and ASR helpers",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",