@volter/teams 0.1.71 → 0.1.73
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.
- package/browser-channel.d.ts +9 -1
- package/browser-channel.mjs +36 -5
- package/package.json +1 -1
package/browser-channel.d.ts
CHANGED
|
@@ -46,11 +46,19 @@ export type BrowserTurnAnswer =
|
|
|
46
46
|
| { code: 0; turn_id?: string; door?: 'runtime' | 'pane' | 'waiting'; text?: string }
|
|
47
47
|
| { code: number; text?: string };
|
|
48
48
|
|
|
49
|
+
/** The accepted stream ended without a valid receipt; delivery may have occurred. */
|
|
50
|
+
export declare class TurnDeliveryUnconfirmedError extends Error {
|
|
51
|
+
constructor(message: string);
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
/**
|
|
50
55
|
* One line typed into the channel's session as its user's own turn; rejects when the machine refuses the stream.
|
|
51
56
|
* `turnKey`: one per typed line, reused on retry, so the machine types the line once.
|
|
57
|
+
* Receipt waits time out after thirty seconds. Cancellation stops waiting; it
|
|
58
|
+
* does not undo delivery. After acceptance, a lost, invalid or cancelled receipt
|
|
59
|
+
* rejects with TurnDeliveryUnconfirmedError. Reuse the same key when retrying it.
|
|
52
60
|
*/
|
|
53
|
-
export function sendBrowserTurn(channel: BrowserChannel, text: string, options?: { turnKey?: string }): Promise<BrowserTurnAnswer>;
|
|
61
|
+
export function sendBrowserTurn(channel: BrowserChannel, text: string, options?: { turnKey?: string; signal?: AbortSignal }): Promise<BrowserTurnAnswer>;
|
|
54
62
|
|
|
55
63
|
export interface MailHistoryEntry {
|
|
56
64
|
id: string; from: string; fromName: string; to: string; text: string; at: number;
|
package/browser-channel.mjs
CHANGED
|
@@ -167,19 +167,50 @@ export function openBrowserSession({ origin, teamId, sessionId, token }, { WebSo
|
|
|
167
167
|
return connectBrowserChannel(socket, channel, `could not reach session ${sessionId} through ${origin}`, 'the server closed the session channel');
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/** A turn was accepted by its stream, but its delivery receipt was not obtained. */
|
|
171
|
+
export class TurnDeliveryUnconfirmedError extends Error {
|
|
172
|
+
constructor(message) { super(message); this.name = 'TurnDeliveryUnconfirmedError'; }
|
|
173
|
+
}
|
|
174
|
+
|
|
170
175
|
/**
|
|
171
176
|
* One line typed into the channel's session as its user's own turn. Resolves with the machine's answer:
|
|
172
177
|
* `{ code: 0, turn_id, door: 'runtime' | 'pane' | 'waiting' }` (waiting: filed, typed when the session's composer
|
|
173
178
|
* is free), or `{ code, text }` when it was not delivered; rejects when the machine refuses the stream.
|
|
174
179
|
* `turnKey`: one key per line the person typed, reused when they retry it, so a line the machine took after its
|
|
175
180
|
* first send was given up on is not typed twice (a machine of door vocabulary 3 or later keeps each key once).
|
|
181
|
+
* Receipt waits are bounded to thirty seconds and 256 KB. `signal` cancels the
|
|
182
|
+
* wait; neither cancellation nor timeout undoes a turn already accepted.
|
|
176
183
|
*/
|
|
177
|
-
export async function sendBrowserTurn(channel, text, { turnKey } = {}) {
|
|
184
|
+
export async function sendBrowserTurn(channel, text, { turnKey, signal } = {}) {
|
|
185
|
+
signal?.throwIfAborted();
|
|
178
186
|
const stream = await channel.open('mail', { request: { op: 'turn', text, ...(turnKey ? { turn_key: String(turnKey) } : {}) } });
|
|
179
|
-
return new Promise((resolve) => {
|
|
180
|
-
let answer = '';
|
|
181
|
-
stream.
|
|
182
|
-
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
let answer = '', settled = false;
|
|
189
|
+
const cleanup = () => { clearTimeout(timer); stream.off('data', data); stream.off('close', closed); signal?.removeEventListener('abort', cancelled); };
|
|
190
|
+
const fail = error => {
|
|
191
|
+
if (settled) return;
|
|
192
|
+
settled = true; cleanup(); reject(error);
|
|
193
|
+
// close emits synchronously. A failed wait must not parse an incomplete
|
|
194
|
+
// receipt as success, or imply that a typed turn was rolled back.
|
|
195
|
+
stream.close(error.message);
|
|
196
|
+
};
|
|
197
|
+
const cancelled = () => fail(new TurnDeliveryUnconfirmedError('Turn delivery wait cancelled'));
|
|
198
|
+
const timer = setTimeout(() => fail(new TurnDeliveryUnconfirmedError('Turn delivery acknowledgement timed out')), 30_000);
|
|
199
|
+
const data = chunk => { answer += chunk; if (answer.length > 256_000) fail(new TurnDeliveryUnconfirmedError('Turn delivery receipt too large')); };
|
|
200
|
+
const closed = reason => {
|
|
201
|
+
if (settled) return;
|
|
202
|
+
settled = true; cleanup();
|
|
203
|
+
// Only an actual machine answer establishes delivery or refusal. A socket
|
|
204
|
+
// closing, an incomplete JSON frame or an empty receipt cannot prove either.
|
|
205
|
+
try {
|
|
206
|
+
const receipt = JSON.parse(answer);
|
|
207
|
+
if (!receipt || !Number.isInteger(receipt.code)) throw new Error('Invalid receipt');
|
|
208
|
+
resolve(receipt);
|
|
209
|
+
} catch { reject(new TurnDeliveryUnconfirmedError(reason || 'No complete delivery receipt from the machine')); }
|
|
210
|
+
};
|
|
211
|
+
stream.on('data', data);
|
|
212
|
+
if (!settled) stream.on('close', closed);
|
|
213
|
+
if (!settled && signal) { signal.addEventListener('abort', cancelled, { once: true }); if (signal.aborted) cancelled(); }
|
|
183
214
|
});
|
|
184
215
|
}
|
|
185
216
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/teams",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.73",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
|
|
6
6
|
"license": "MIT",
|