@volter/teams 0.1.40 → 0.1.42

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.
@@ -46,8 +46,11 @@ 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
- /** One line typed into the channel's session as its user's own turn; rejects when the machine refuses the stream. */
50
- export function sendBrowserTurn(channel: BrowserChannel, text: string): Promise<BrowserTurnAnswer>;
49
+ /**
50
+ * One line typed into the channel's session as its user's own turn; rejects when the machine refuses the stream.
51
+ * `turnKey`: one per typed line, reused on retry, so the machine types the line once.
52
+ */
53
+ export function sendBrowserTurn(channel: BrowserChannel, text: string, options?: { turnKey?: string }): Promise<BrowserTurnAnswer>;
51
54
 
52
55
  /** A pane's terminal stream. Events: `data` (text), `hello`, `notice`, `error-message`, `close`. */
53
56
  export interface BrowserPane extends ChannelEvents {
@@ -155,9 +155,11 @@ export function openBrowserSession({ origin, teamId, sessionId, token }, { WebSo
155
155
  * One line typed into the channel's session as its user's own turn. Resolves with the machine's answer:
156
156
  * `{ code: 0, turn_id, door: 'runtime' | 'pane' | 'waiting' }` (waiting: filed, typed when the session's composer
157
157
  * is free), or `{ code, text }` when it was not delivered; rejects when the machine refuses the stream.
158
+ * `turnKey`: one key per line the person typed, reused when they retry it, so a line the machine took after its
159
+ * first send was given up on is not typed twice (a machine of door vocabulary 3 or later keeps each key once).
158
160
  */
159
- export async function sendBrowserTurn(channel, text) {
160
- const stream = await channel.open('mail', { request: { op: 'turn', text } });
161
+ export async function sendBrowserTurn(channel, text, { turnKey } = {}) {
162
+ const stream = await channel.open('mail', { request: { op: 'turn', text, ...(turnKey ? { turn_key: String(turnKey) } : {}) } });
161
163
  return new Promise((resolve) => {
162
164
  let answer = '';
163
165
  stream.on('data', (chunk) => { answer += chunk; });
package/channel.mjs CHANGED
@@ -265,8 +265,8 @@ export class Channel extends EventEmitter {
265
265
  return this;
266
266
  }
267
267
 
268
- /** Open a named stream; resolves once the peer accepts it, rejects if refused. */
269
- open(name, params = {}) {
268
+ /** Open a named stream; resolves once the peer accepts it, rejects if refused or unanswered within `timeoutMs`. */
269
+ open(name, params = {}, { timeoutMs = HANDSHAKE_TIMEOUT_MS } = {}) {
270
270
  // A closed connection refuses at once rather than waiting out the handshake bound.
271
271
  if (this.closed) return Promise.reject(new Error(`${name} refused: connection closed`));
272
272
  const id = this._nextStream;
@@ -278,8 +278,8 @@ export class Channel extends EventEmitter {
278
278
  const timer = setTimeout(() => {
279
279
  stream.off('opened', onOpened); stream.off('close', onClosed);
280
280
  this._streams.delete(id);
281
- reject(new Error(`${name} did not open within ${HANDSHAKE_TIMEOUT_MS} ms`));
282
- }, HANDSHAKE_TIMEOUT_MS);
281
+ reject(new Error(`${name} did not open within ${timeoutMs} ms`));
282
+ }, timeoutMs);
283
283
  timer.unref?.();
284
284
  const onOpened = () => { clearTimeout(timer); stream.off('close', onClosed); resolve(stream); };
285
285
  const onClosed = (reason) => { clearTimeout(timer); stream.off('opened', onOpened); reject(new Error(`${name} refused: ${reason ?? 'closed'}`)); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
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",