ftown-bridge 0.19.18 → 0.19.19

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.
@@ -103,10 +103,10 @@ export function registerFtownOpencodePlugin(client, options = {}) {
103
103
  });
104
104
  }
105
105
 
106
- async function drainMail() {
106
+ async function listInbox(peek) {
107
107
  if (!ftownSessionId) return [];
108
108
  const response = await request(
109
- `/api/sessions/${encodeURIComponent(ftownSessionId)}/inbox?wait=0`,
109
+ `/api/sessions/${encodeURIComponent(ftownSessionId)}/inbox?wait=0${peek ? '&peek=1' : ''}`,
110
110
  { method: 'GET' },
111
111
  );
112
112
  if (!response) return [];
@@ -118,13 +118,18 @@ export function registerFtownOpencodePlugin(client, options = {}) {
118
118
  }
119
119
  }
120
120
 
121
+ /**
122
+ * Peek first, and only mark delivered AFTER the prompt was accepted. If
123
+ * submission fails, mail stays queued for the next boundary instead of
124
+ * being silently lost between a marking drain and a failed injection.
125
+ */
121
126
  async function deliverMail() {
122
- const messages = await drainMail();
123
- if (messages.length === 0 || !currentSessionId) return;
127
+ if (!currentSessionId) return;
128
+ const messages = await listInbox(true);
129
+ if (messages.length === 0) return;
124
130
  const formatted = messages.map(formatMail).join('\n');
125
- // Submitting a prompt starts a new turn; when it finishes, the next
126
- // idle boundary fires and any mail that arrived meanwhile is delivered
127
- // then.
131
+ // Submitting a prompt starts a new turn; when it finishes, the next idle
132
+ // boundary fires and any mail that arrived meanwhile is delivered then.
128
133
  await client.session.prompt({
129
134
  path: { id: currentSessionId },
130
135
  body: {
@@ -138,6 +143,8 @@ export function registerFtownOpencodePlugin(client, options = {}) {
138
143
  ],
139
144
  },
140
145
  });
146
+ // Accepted — only now let the bridge mark the peeked messages delivered.
147
+ await listInbox(false);
141
148
  }
142
149
 
143
150
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ftown-bridge",
3
- "version": "0.19.18",
3
+ "version": "0.19.19",
4
4
  "description": "CLI bridge for ftown — generic PTY-over-Centrifugo relay",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",