opencode-mailbox 0.0.7 → 0.0.8

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 (2) hide show
  1. package/dist/index.js +30 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -12683,6 +12683,20 @@ var dbFile = null;
12683
12683
  var db = null;
12684
12684
  var activeWatches = new Map;
12685
12685
  var watchesBySession = new Map;
12686
+ function resetDatabaseConnection() {
12687
+ if (db) {
12688
+ try {
12689
+ db.close();
12690
+ } catch {}
12691
+ db = null;
12692
+ }
12693
+ }
12694
+ function isDatabaseFileError(error45) {
12695
+ if (!(error45 instanceof Error))
12696
+ return false;
12697
+ const message = error45.message.toLowerCase();
12698
+ return message.includes("database disk image is malformed") || message.includes("no such table") || message.includes("unable to open database file") || message.includes("database is locked") || message.includes("disk i/o error") || message.includes("no more rows available") || message.includes("unable to close") || message.includes("bad parameter or other api misuse");
12699
+ }
12686
12700
  async function getDbFile(client) {
12687
12701
  if (!dbFile) {
12688
12702
  const result = await client.path.get();
@@ -12765,6 +12779,11 @@ function startMailWatch(client, recipient, sessionId, instructions) {
12765
12779
  await injectMailMessage(client, sessionId, recipient, message, instructions);
12766
12780
  }
12767
12781
  } catch (error45) {
12782
+ if (isDatabaseFileError(error45)) {
12783
+ console.error(`[Mailbox] Database file error for ${recipient}, resetting connection...`);
12784
+ resetDatabaseConnection();
12785
+ return;
12786
+ }
12768
12787
  console.error(`[Mailbox] Error watching mail for ${recipient}:`, error45);
12769
12788
  }
12770
12789
  }, 5000);
@@ -12839,7 +12858,17 @@ var mailboxPlugin = async (ctx) => {
12839
12858
  const to = args.to.toLowerCase();
12840
12859
  const from = args.from.toLowerCase();
12841
12860
  const timestamp = Date.now();
12842
- await addMessage(client, to, from, args.message, timestamp);
12861
+ try {
12862
+ await addMessage(client, to, from, args.message, timestamp);
12863
+ } catch (error45) {
12864
+ if (isDatabaseFileError(error45)) {
12865
+ console.error(`[Mailbox] Database file error while sending mail, resetting connection...`);
12866
+ resetDatabaseConnection();
12867
+ await addMessage(client, to, from, args.message, timestamp);
12868
+ } else {
12869
+ throw error45;
12870
+ }
12871
+ }
12843
12872
  return `Mail sent to "${args.to}" from "${args.from}" at ${new Date(timestamp).toISOString()}`;
12844
12873
  }
12845
12874
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-mailbox",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "A simple mailbox system for sending and receiving messages between sessions",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",