sigelo-contact 0.1.20 → 0.1.21

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/carrier.mjs CHANGED
@@ -39,8 +39,9 @@
39
39
  // each contact with its four words (fingerprint),
40
40
  // pair id, chain, ours (an operator attestation of mine marks it), tier, seen_upto
41
41
  // (their newest seen receipt: my messages sealed at or before it were shown; null: none) and
42
- // seen_peer (a receipt came: they read receipts), busy (their busy mark is on) and
43
- // busy_peer (they take busy marks), tier
42
+ // seen_peer (a receipt came: they read receipts), busy (their busy mark is on), busy_n
43
+ // (agents running by it, 0 when off), busy_peer (they take busy marks), host_peer (they
44
+ // take a hosted agent's settings), tier
44
45
  // (store.mjs: own, friend, quiet) and tier_by, prekeys: its
45
46
  // bundle is here (false: messages wait for it), waiting: why they wait, or null;
46
47
  // failed: pairing_failed events (code_expired: an answer that outlived its code) until inbox
@@ -77,7 +78,7 @@
77
78
  // contact's link record (store.mjs setLink)
78
79
  // await c.seen(to, upto) a seen receipt (SEEN_LABEL, the header's "Seen receipts") to contact to: every message of
79
80
  // theirs sealed at or before upto (their iat, unix seconds; 0: none yet) was shown → as send
80
- // await c.busy(to, on, { local }) a busy mark (BUSY_LABEL, the header's "Busy marks") to contact to: on (a turn runs)
81
+ // await c.busy(to, on, { local, n }) a busy mark (BUSY_LABEL, the header's "Busy marks") to contact to: on (a turn runs)
81
82
  // or off → as send, or { status: 'skipped' } for a contact that never said it takes them
82
83
  // await c.read(items, { local }) read marks: a seen receipt to each sender of these inbox items, once per message
83
84
  // (own contacts always, others as the app does) → [{ to, upto, status | error }]
@@ -90,8 +91,9 @@
90
91
  // c.takeTransfers(), c.deliver(item) transfer-node.mjs's: the sigelo-transfer/0 messages received (never in inbox(),
91
92
  // the log or onEvent: a `transfer` event without content says one came), taken;
92
93
  // a file a transfer saved whole, as an inbox item (kept as #onFile keeps one)
93
- // c.takeCalls() call.mjs's: the sigelo-call/0 messages received (never in inbox(), the log or
94
- // onEvent: a `call` event without content says one came), taken
94
+ // c.takeCalls() call.mjs's: the sigelo-call/0 messages this process received (never in inbox(),
95
+ // the log, onEvent, nor the state file: held in memory until taken; a `call`
96
+ // event without content says one came), taken
95
97
  // c.freshEpochs({ only, retire }) every session (or only's) afresh, as after a rotation (a snapshot's
96
98
  // state imported where the seat moved, devices.md §4.3) → the DIDs
97
99
  // c.answeredBy(nonce) the original DID that paired through this agent's code `nonce`, or null
@@ -110,6 +112,9 @@
110
112
  // down with no try already waiting; nothing else. now (a push wake): at once
111
113
  // c.setPush(reg | null), c.pushStatus() the phone's UnifiedPush endpoint and keys registered at this agent's own relay
112
114
  // (sigelo-push/0 on $sigelo/push, relay/push.mjs) at every login; null removes it
115
+ // await c.turnServer() → { urls, username, credential, exp } | null: a TURN credential from this agent's own
116
+ // relay (sigelo-turn/0 on $sigelo/turn, relay/turn.mjs), where GET /challenge says it
117
+ // gives them and the session is up; kept until 10 minutes before exp; null otherwise
113
118
  // started: 'user' | 'confirmed' (start, invite, accept, tryNow) a search the human started: past
114
119
  // POW_SEARCHES a day it is never refused, it asks (pow_confirm),
115
120
  // and 'confirmed' goes on; without it (automatic retries) the cap holds
@@ -251,10 +256,12 @@
251
256
  // what to send and when is the app's (apps/contact/page.mjs: one first receipt to a contact not
252
257
  // known to read them, further ones only once one came back). A contact on an earlier version takes
253
258
  // the first as a message with that label, and never sends one: its messages stay at one tick.
254
- // Once paired, each side also sends one {seen: 0, name}: its display name (the "Names" below).
255
- // Every receipt (the name's too) carries busy: true: this side takes busy marks (below).
259
+ // Once paired, each side also sends one {seen: 0, name, kind?}: its display name and kind (the "Names" below).
260
+ // Every receipt (the name's too) carries busy: true: this side takes busy marks (below), and host: true: it takes a
261
+ // hosted agent's settings (sigelo-host-caps/0, apps/contact/page.mjs "Agent settings"); kept as host_peer (contacts()).
256
262
  // - Busy marks (label BUSY_LABEL, inside the envelope; 2026-11-19): {busy: true|false}, a hosted agent's "I am
257
- // working on it" (sigelo-agent-host.ts): on at a turn's start and every 20 s while it runs, off before its reply.
263
+ // working on it" (sigelo-agent-host.ts): on at a turn's start and every 20 s while it runs, off before its reply;
264
+ // n (optional, an integer 2..99): that many agents run (the session and its subagents), kept as busy_n (absent: 1).
258
265
  // Taken here, never an inbox message, never logged, never an event `message`: the contact's busy_until (now +
259
266
  // BUSY_TTL_S, 0 for off; any message or file of theirs ends it too), contacts() busy, an event `busy`. Sent
260
267
  // only through busy() (BUSY_SEND), with expires now + BUSY_TTL_S (a stale one goes unsent), and only to a
@@ -384,9 +391,10 @@ const DEVICES_MAX = 16;
384
391
  // engine, never logged (an offer carries addresses, an onion message a client key); sent only with TRANSFER_SEND.
385
392
  export const TRANSFER_LABEL = 'sigelo-transfer/0', TRANSFER_SEND = Symbol('sigelo-transfer send');
386
393
  const TRANSFERS_MAX = 256;
387
- // Calls (call.mjs, sigelo-call/0; design/calls.md §2): the signalling of a voice call. The same: kept apart in st.calls
388
- // (at most CALLS_MAX) for the page's Line (page.mjs) or watch's answer, never logged (an offer carries addresses); sent
389
- // only with CALL_SEND.
394
+ // Calls (call.mjs, sigelo-call/0; design/calls.md §2): the signalling of a voice call. Kept apart in memory (at most
395
+ // CALLS_MAX) for the page's Line (page.mjs) or watch's answer, in the process that received them; never logged and never
396
+ // in the state file (an SDP carries addresses and a DTLS fingerprint; a ring lives 60 s, a restart cannot wait for
397
+ // another process anyway). Sent only with CALL_SEND.
390
398
  export const CALL_LABEL = 'sigelo-call/0', CALL_SEND = Symbol('sigelo-call send');
391
399
  const CALLS_MAX = 64;
392
400
  // Seen receipts (the header's): sent only with SEEN_SEND, never an inbox message.
@@ -394,6 +402,8 @@ export const SEEN_LABEL = 'sigelo-seen/0', SEEN_SEND = Symbol('sigelo-seen send'
394
402
  // UnifiedPush (design/push.md, relay/push.mjs): the phone's endpoint and keys, registered with this agent's own
395
403
  // relay over its session (setPush), where GET /challenge says the relay takes them.
396
404
  export const PUSH_TOPIC = '$sigelo/push', PUSH_V = 'sigelo-push/0';
405
+ // TURN (relay/turn.mjs): a credential for coturn on this agent's own relay host, asked over the session.
406
+ export const TURN_TOPIC = '$sigelo/turn', TURN_V = 'sigelo-turn/0', TURN_WAIT_MS = 5000, TURN_KEEP_S = 600;
397
407
  // Busy marks (the header's): sent only with BUSY_SEND, never an inbox message; one is good for BUSY_TTL_S seconds.
398
408
  export const BUSY_LABEL = 'sigelo-busy/0', BUSY_SEND = Symbol('sigelo-busy send'), BUSY_TTL_S = 45;
399
409
  // Names (0.1.17: "the system allocated some random text" for a new contact). Once paired, each side tells the other its
@@ -402,7 +412,13 @@ export const BUSY_LABEL = 'sigelo-busy/0', BUSY_SEND = Symbol('sigelo-busy send'
402
412
  // contact's name was made up here (name_from "auto": an unnamed invite or accept, a public code's) or came from them
403
413
  // before; a name the human gave or changed is never replaced. The name: at most THEIR_NAME_MAX characters, trimmed, no
404
414
  // control or bidi characters, else ignored; one another contact holds gets " (2)", " (3)"….
415
+ // Kinds (2026-11-26): the same receipt carries kind "agent" or "desk" (a support desk) when this side says it is one
416
+ // (selfKind: sigelo-agent says agent by default, --kind desk; a person's app says nothing). The receiver keeps it as the
417
+ // contact's kind_peer (contacts()); the page shows it, and the human's own choice wins (page.mjs "Kinds"). An earlier
418
+ // version ignores the member, as it ignores busy and host; the pairing card (invite.mjs) refuses an unknown field, so
419
+ // the kind does not go there. A claim only: it can make a contact less (no call), never more than a person.
405
420
  export const THEIR_NAME_MAX = 40;
421
+ export const KINDS = Object.freeze(['person', 'agent', 'desk']);
406
422
  // Replies (0.1.17: "reply to messages"): a message that answers one names it in its label, re/<h>/<s|r>, h the first 16
407
423
  // hex of SHA-256 over the quoted text, s when the sender quotes its own message, r the recipient's. The envelope's body is
408
424
  // exact (envelope.mjs BODY): no member can be added, and a label is free text an older client shows as a tag. Each side
@@ -666,6 +682,8 @@ function loadState(files, path, self) {
666
682
  if (s.v !== V || s.self !== self) fail('state', `${path} is not the ${V} state of ${self}`);
667
683
  // Written by an earlier version of this file, which kept neither.
668
684
  s.events ??= []; s.failing ??= {}; s.answered ??= {};
685
+ // Call signalling an earlier version kept here (with its SDP): gone at the next save.
686
+ delete s.calls;
669
687
  return s;
670
688
  }
671
689
 
@@ -933,6 +951,16 @@ export function groupTierOf(n) {
933
951
  if ((n?.tier !== 'free' && n?.tier !== 'pro') || g === null || typeof g !== 'object' || !whole(g.max, 0, GROUPS_TOLD_MAX) || !whole(g.members, 2, GROUP_MEMBERS_MAX)) return null;
934
952
  return { tier: n.tier, groups: { max: g.max, members: g.members } };
935
953
  }
954
+ // The relay's TURN credential ({code: "turn", turn}, relay/turn.mjs): {v, urls (1 to 4 turn: URIs), username, credential, exp},
955
+ // each checked, else ignored. → {urls, username, credential, exp} | null.
956
+ const TURN_URL = /^turns?:[A-Za-z0-9.-]{1,253}(:\d{1,5})?(\?transport=(udp|tcp))?$/;
957
+ export function turnOf(t) {
958
+ if (t === null || typeof t !== 'object' || Array.isArray(t) || Object.keys(t).sort().join() !== 'credential,exp,urls,username,v' || t.v !== TURN_V) return null;
959
+ if (!Array.isArray(t.urls) || t.urls.length < 1 || t.urls.length > 4 || !t.urls.every((u) => typeof u === 'string' && TURN_URL.test(u))) return null;
960
+ if (typeof t.username !== 'string' || !/^[\x21-\x7e]{1,128}$/.test(t.username) || typeof t.credential !== 'string' || !/^[A-Za-z0-9+/=]{1,128}$/.test(t.credential)) return null;
961
+ if (!Number.isSafeInteger(t.exp) || t.exp <= 0) return null;
962
+ return { urls: [...t.urls], username: t.username, credential: t.credential, exp: t.exp };
963
+ }
936
964
  const quotaWhy = (r, name) => (r.code !== 'quota_storage' ? null
937
965
  : r.side === 'reader' ? `${name}'s side is over its storage quota (its queue is full, or its operator's Pro lapsed): nothing is wrong with your relay or your allowance; send again once ${name}'s agent has collected its messages (${relaySays(r.detail)})`
938
966
  : r.side === 'sender' ? `your network has used its share of this relay's free storage: send again once messages are collected or expire (${relaySays(r.detail)})` : null);
@@ -1101,12 +1129,13 @@ export class Carrier {
1101
1129
  #claimed = new Set(); #refusedTopics = new Map(); #handshakes = new Map(); #soon = new Set();
1102
1130
  #renewing = false;
1103
1131
  #started = false; #tick = null; #timers = new Map(); #attempts = new Map(); #connecting = new Set(); #powFails = new Map(); #powWaits = new Set(); #ask = false; #spare = new Map();
1104
- #push = undefined; #pushState = { state: 'none' }; // setPush: undefined = never set (nothing sent), null = off
1105
- #mineMemo = null; #clocks = new Map(); #selfName = () => null;
1132
+ #push = undefined; #pushState = { state: 'none' }; #turn = null; // #turn: the last TURN credential (turnServer) // setPush: undefined = never set (nothing sent), null = off
1133
+ #mineMemo = null; #clocks = new Map(); #selfName = () => null; #selfKind = () => null;
1134
+ #calls = []; // the sigelo-call/0 messages received, until takeCalls (memory only: the header's "Calls")
1106
1135
 
1107
1136
  constructor({ identity, store, state, relay = DEFAULT_RELAY, endpoints = {}, retentionDays, clock = () => Math.floor(Date.now() / 1000),
1108
1137
  onEvent, keep, backoff = BACKOFF, tick = TICK, files, log, transport = 'auto', shortRelay = DEFAULT_RELAY, registry = REGISTRY_URL, registryPin = RELEASE_DID, relays, registryFile,
1109
- platform = nodePlatform, selfName = null, enrolHash = null }) {
1138
+ platform = nodePlatform, selfName = null, selfKind = null, enrolHash = null }) {
1110
1139
  // enrolHash: the enrolment code this (temporary) identity holds, as its park hash: its first login asks
1111
1140
  // GET /challenge?…&enrol=<hash>, and a relay states the base proof of work for it (relay/park.mjs enrolGrace).
1112
1141
  if (enrolHash !== null && !(typeof enrolHash === 'string' && /^[0-9a-f]{64}$/.test(enrolHash))) throw new TypeError('enrolHash: 64 hex (short.mjs codeHash), or null');
@@ -1114,6 +1143,9 @@ export class Carrier {
1114
1143
  // This side's display name, told to each new contact once paired (the header's "Names"): a string or a function → one, or null.
1115
1144
  if (selfName !== null && typeof selfName !== 'string' && typeof selfName !== 'function') throw new TypeError('selfName: a string, a function → a string or null, or null');
1116
1145
  this.#selfName = typeof selfName === 'function' ? selfName : () => selfName;
1146
+ // This side's kind, told with the name (the header's "Kinds"): "agent", "desk", or null (a person: nothing said).
1147
+ if (selfKind !== null && !KINDS.includes(selfKind) && typeof selfKind !== 'function') throw new TypeError('selfKind: agent, desk, person, a function → one, or null');
1148
+ this.#selfKind = typeof selfKind === 'function' ? selfKind : () => selfKind;
1117
1149
  if (!TRANSPORTS.includes(transport)) throw new TypeError(`transport: ${TRANSPORTS.join(', ')}`);
1118
1150
  // The platform (design/apps.md §4.2, platform-node.mjs): files, lock, network, proof of work.
1119
1151
  if (typeof platform?.files?.read !== 'function' || typeof platform.transact !== 'function' || typeof platform.fetch !== 'function' || typeof platform.mqtt !== 'function'
@@ -1312,10 +1344,12 @@ export class Carrier {
1312
1344
  // An event kept for the next inbox() as well: a CLI or MCP agent has no onEvent.
1313
1345
  // This side's name to a contact just paired (the header's "Names"), in its outbox: it goes with the next round.
1314
1346
  #tellName(st, did) {
1315
- let n = null;
1347
+ let n = null, k = null;
1316
1348
  try { n = theirName(this.#selfName()); } catch {}
1317
- if (n === null) return;
1318
- this.#entry(st, did).outbox.push({ id: randomId(), label: SEEN_LABEL, content: { seen: 0, name: n, busy: true } });
1349
+ try { k = this.#selfKind(); } catch {}
1350
+ if (k !== 'agent' && k !== 'desk') k = null;
1351
+ if (n === null && k === null) return;
1352
+ this.#entry(st, did).outbox.push({ id: randomId(), label: SEEN_LABEL, content: { seen: 0, ...(n !== null && { name: n }), ...(k !== null && { kind: k }), busy: true, host: true } });
1319
1353
  }
1320
1354
 
1321
1355
  #note(st, now, ev) {
@@ -1422,6 +1456,9 @@ export class Carrier {
1422
1456
  : route.type === 'answer' ? this.#onAnswer(ctx, t, bytes) : route.type === 'public' ? this.#onPublic(ctx, route.nonce, t, bytes) : this.#onReply(ctx, t, bytes)));
1423
1457
  for (const e of events) this.#emit(e);
1424
1458
  if (route.type === 'answer') this.#renewSoon();
1459
+ // A frame from a contact: it read the pairing's reply and holds its mailbox now, so what waits for it after a
1460
+ // no_reader (a name or kind receipt queued at the pairing, operator hints) goes this round, not the next tick's.
1461
+ if (route.type === 'peer') link.absent.delete(route.did);
1425
1462
  } catch (e) {
1426
1463
  if (route?.type === 'answer') this.#renewSoon();
1427
1464
  if (e instanceof MsgError && !INTERNAL.has(e.check)) this.#drop(e.check, e.message, route);
@@ -1489,6 +1526,8 @@ export class Carrier {
1489
1526
  try { n = parseBytes(bytes); } catch { return; }
1490
1527
  if (n === null || typeof n !== 'object' || typeof n.code !== 'string') return;
1491
1528
  // The relay's group tier for this login (relay/allowance.mjs "tier"): kept per relay in the state, refuses nothing.
1529
+ // The answer to $sigelo/turn (turnServer): kept on the link for the publish that asked.
1530
+ if (n.code === 'turn') { link.turnGot = turnOf(n.turn); return; }
1492
1531
  if (n.code === 'tier') {
1493
1532
  const g = groupTierOf(n);
1494
1533
  if (g) { try { this.#locked(({ st }) => { (st.group_tier ??= {})[link.relay] = g; }); } catch {} this.#emit({ type: 'group_tier', relay: link.relay, ...g }); }
@@ -1588,7 +1627,8 @@ export class Carrier {
1588
1627
  events.push({ type: 'transfer', from: c.did, name: c.name });
1589
1628
  } else if (r.body.label === CALL_LABEL) {
1590
1629
  // A call's signalling (call.mjs): kept for the page's Line, never for inbox() nor onEvent's readers.
1591
- const l = (st.calls ??= []);
1630
+ // In memory (the header's "Calls"): a delivery whose transaction then fails comes again, and the Line drops the repeat.
1631
+ const l = this.#calls;
1592
1632
  l.push({ from: c.did, name: c.name, current_did: r.body.from, label: r.body.label, content: r.body.content, iat: r.body.iat, received: now });
1593
1633
  if (l.length > CALLS_MAX) { st.dropped.calls_full = (st.dropped.calls_full ?? 0) + l.length - CALLS_MAX; l.splice(0, l.length - CALLS_MAX); }
1594
1634
  events.push({ type: 'call', from: c.did, name: c.name });
@@ -1597,6 +1637,10 @@ export class Carrier {
1597
1637
  const n = r.body.content?.seen, nm = theirName(r.body.content?.name);
1598
1638
  // busy: true: they take busy marks (the header's "Busy marks").
1599
1639
  if (r.body.content?.busy === true) this.#entry(st, c.did).busy_peer = true;
1640
+ if (r.body.content?.host === true) this.#entry(st, c.did).host_peer = true;
1641
+ // Its kind (the header's "Kinds"): agent or desk kept; person, or anything else, says nothing.
1642
+ const said = r.body.content?.kind;
1643
+ if (said === 'agent' || said === 'desk') this.#entry(st, c.did).kind_peer = said;
1600
1644
  if (nm !== null) {
1601
1645
  const all = store.load().s.contacts, rec = all[c.did];
1602
1646
  if (rec && (rec.name_from === 'auto' || rec.name_from === 'them') && rec.name !== nm) {
@@ -1607,8 +1651,8 @@ export class Carrier {
1607
1651
  events.push({ type: 'named', did: c.did, name: to });
1608
1652
  } else if (rec && rec.name_from === 'auto') { rec.name_from = 'them'; store.save(); }
1609
1653
  }
1610
- // A name's receipt (seen 0) says nothing of what was shown.
1611
- if (nm !== null && n === 0) { /* the name only */ } else if (!Number.isSafeInteger(n) || n < 0) { st.dropped.seen = (st.dropped.seen ?? 0) + 1; events.push({ type: 'dropped', check: 'seen', detail: 'a seen receipt without its time' }); } else {
1654
+ // A name's (or a kind's) receipt (seen 0) says nothing of what was shown.
1655
+ if ((nm !== null || said === 'agent' || said === 'desk') && n === 0) { /* the name only */ } else if (!Number.isSafeInteger(n) || n < 0) { st.dropped.seen = (st.dropped.seen ?? 0) + 1; events.push({ type: 'dropped', check: 'seen', detail: 'a seen receipt without its time' }); } else {
1612
1656
  const e = this.#entry(st, c.did);
1613
1657
  e.seen_peer = true;
1614
1658
  e.seen_upto = Math.max(e.seen_upto ?? 0, n);
@@ -1616,9 +1660,10 @@ export class Carrier {
1616
1660
  }
1617
1661
  } else if (r.body.label === BUSY_LABEL) {
1618
1662
  // A busy mark (the header's): good for BUSY_TTL_S, never an inbox message nor logged.
1619
- const e = this.#entry(st, c.did), on = r.body.content?.busy === true;
1663
+ const e = this.#entry(st, c.did), on = r.body.content?.busy === true, n = r.body.content?.n;
1620
1664
  e.busy_until = on ? now + BUSY_TTL_S : 0;
1621
- events.push({ type: 'busy', from: c.did, name: c.name, on });
1665
+ e.busy_n = on && Number.isSafeInteger(n) && n > 1 ? Math.min(n, 99) : 1;
1666
+ events.push({ type: 'busy', from: c.did, name: c.name, on, n: e.busy_n });
1622
1667
  } else if (r.body.label === DEVICE_LABEL) {
1623
1668
  // A device message (device.mjs): kept for the `device` verbs, never for inbox() nor onEvent's readers.
1624
1669
  const l = (st.devices ??= []);
@@ -2520,6 +2565,34 @@ export class Carrier {
2520
2565
  /** → { state: 'none' (never set) | 'pending' | 'registered' | 'off' | 'refused' | 'unsupported', relay?, at?, code?, detail? }. */
2521
2566
  pushStatus() { return { ...this.#pushState }; }
2522
2567
 
2568
+ /**
2569
+ * A TURN server for a call or a transfer starting now (relay/turn.mjs): { urls, username, credential, exp } from this agent's
2570
+ * own relay, asked over its session (one publish, in the queue of the session's work: one request in flight), kept until
2571
+ * TURN_KEEP_S before exp. null where the relay gives none, the session is down, or no answer within TURN_WAIT_MS: the
2572
+ * caller goes on with STUN alone.
2573
+ */
2574
+ async turnServer() {
2575
+ const t = this.#turn;
2576
+ if (t && t.exp - TURN_KEEP_S > this.clock()) return { ...t };
2577
+ const link = this.#links.get(this.relay);
2578
+ if (!link?.up || !link.turn) return null;
2579
+ const asked = new Promise((resolve) => {
2580
+ this.#later(async () => {
2581
+ if (!link.up) return resolve(null);
2582
+ link.turnGot = null;
2583
+ let r = null;
2584
+ try { r = await this.#publish(link, TURN_TOPIC, new Uint8Array(0)); } catch { return resolve(null); }
2585
+ const got = link.turnGot;
2586
+ link.turnGot = null;
2587
+ if (r) this.#emit({ type: 'notice', relay: link.relay, code: r.code, detail: r.detail });
2588
+ resolve(r ? null : got);
2589
+ });
2590
+ });
2591
+ const got = await Promise.race([asked, sleep(TURN_WAIT_MS).then(() => null)]);
2592
+ if (got) this.#turn = got;
2593
+ return got ? { ...got } : null;
2594
+ }
2595
+
2523
2596
  // Presence at one relay (the header's "Presence"): each contact's marker toward this agent read
2524
2597
  // (QoS 0: a marker is never queued); this agent's published toward those who may see it, once
2525
2598
  // per connection, by a started carrier only (its CONNECT set the will); cleared toward any other.
@@ -2676,7 +2749,7 @@ export class Carrier {
2676
2749
  }
2677
2750
  const password = canonicalize({ v: LOGIN_V, nonce: ch.nonce, sig, bundle: loginBundle(me.bundle, relay), ...(pow !== undefined && { pow }) });
2678
2751
  // until: this login's nonce is good till about then (#dial keeps it for a retry after "rate").
2679
- return { username: me.current_did, clientId: clientIdOf(me.did), password, pow, until: issued + POW_MS, push: r.body?.push === PUSH_V };
2752
+ return { username: me.current_did, clientId: clientIdOf(me.did), password, pow, until: issued + POW_MS, push: r.body?.push === PUSH_V, turn: r.body?.turn === TURN_V };
2680
2753
  }
2681
2754
 
2682
2755
  // How long this agent's own relay keeps a message on the free tier (relay.json, plan §11), when
@@ -2757,7 +2830,7 @@ export class Carrier {
2757
2830
  if (!link.client.connected) throw link.cut ?? new MsgError('connect', 'the relay closed the connection');
2758
2831
  // Deliveries are counted from here (quiet), not from before the login: a proof-of-work search
2759
2832
  // of seconds would read as a drained queue, and give up stale claims before what they hold came.
2760
- link.since = Date.now(); link.onlineAt = this.clock(); link.push = creds.push === true;
2833
+ link.since = Date.now(); link.onlineAt = this.clock(); link.push = creds.push === true; link.turn = creds.turn === true;
2761
2834
  if (creds.pow !== undefined) this.#locked(({ st }) => { (st.relays[relay] ??= { proven: false, claims: {} }).proven = true; });
2762
2835
  link.client.on('error', () => {}); // a close follows
2763
2836
  link.client.on('close', () => this.#closed(link));
@@ -3441,6 +3514,8 @@ export class Carrier {
3441
3514
  rename(who, name) { return this.#locked(({ store }) => store.rename(who, name)); }
3442
3515
  /** This side's display name as it is told to new contacts (the header's "Names"), or null. */
3443
3516
  selfName() { try { return theirName(this.#selfName()); } catch { return null; } }
3517
+ /** This side's kind as it is told to new contacts (the header's "Kinds"): "agent", "desk", or null. */
3518
+ selfKind() { try { const k = this.#selfKind(); return k === 'agent' || k === 'desk' ? k : null; } catch { return null; } }
3444
3519
 
3445
3520
  contacts() {
3446
3521
  return this.#read(({ now, store, st }) => {
@@ -3454,7 +3529,8 @@ export class Carrier {
3454
3529
  // Presence (the header's): what this contact sees of mine, and theirs as read now (null: not known).
3455
3530
  presence: store.presenceOf(c, now), online: st.presence?.[c.did]?.online ?? null, online_since: st.presence?.[c.did]?.since ?? null, last_seen: st.presence?.[c.did]?.last_seen ?? null,
3456
3531
  seen_upto: e?.seen_upto ?? null, seen_peer: e?.seen_peer === true,
3457
- busy: (e?.busy_until ?? 0) > now, busy_peer: e?.busy_peer === true, via: c.via ?? null, name_from: c.name_from ?? null };
3532
+ busy: (e?.busy_until ?? 0) > now, busy_n: (e?.busy_until ?? 0) > now ? (e?.busy_n ?? 1) : 0, busy_peer: e?.busy_peer === true, host_peer: e?.host_peer === true, via: c.via ?? null, name_from: c.name_from ?? null,
3533
+ kind_peer: e?.kind_peer ?? null };
3458
3534
  }),
3459
3535
  invites: Object.values(s.invites).filter((p) => p.exp > now).map((p) => ({ name: p.name, exp: p.exp, relay: p.relay,
3460
3536
  ...(typeof p.short === 'string' && { short: p.short, short_exp: p.short_exp }), ...(p.renew && { renew: p.renew }) })),
@@ -3487,15 +3563,15 @@ export class Carrier {
3487
3563
  // A seen receipt (the header's "Seen receipts"): every message of to's sealed at or before upto was shown.
3488
3564
  async seen(to, upto, { local = false } = {}) {
3489
3565
  if (!Number.isSafeInteger(upto) || upto < 0) fail('body', 'upto: unix seconds, 0 for none yet');
3490
- return this.send(to, { seen: upto, busy: true }, { label: SEEN_LABEL, local, internal: SEEN_SEND });
3566
+ return this.send(to, { seen: upto, busy: true, host: true }, { label: SEEN_LABEL, local, internal: SEEN_SEND });
3491
3567
  }
3492
3568
 
3493
3569
  // A busy mark (the header's "Busy marks"): on, a turn runs for to; off, it ended. Only to a contact that
3494
- // said it takes them (busy_peer), else { status: 'skipped' }; unsent past BUSY_TTL_S.
3495
- async busy(to, on, { local = false } = {}) {
3570
+ // said it takes them (busy_peer), else { status: 'skipped' }; unsent past BUSY_TTL_S. n: agents running (sent when > 1).
3571
+ async busy(to, on, { local = false, n = 1 } = {}) {
3496
3572
  const peer = this.#read(({ store, st }) => st.peers[this.#resolve(store, to).did]?.busy_peer === true);
3497
3573
  if (!peer) return { status: 'skipped', to, detail: 'this contact never said it takes busy marks' };
3498
- return this.send(to, { busy: on === true }, { label: BUSY_LABEL, local, internal: BUSY_SEND, expires: this.clock() + BUSY_TTL_S });
3574
+ return this.send(to, { busy: on === true, ...(on === true && Number.isSafeInteger(n) && n > 1 && { n: Math.min(n, 99) }) }, { label: BUSY_LABEL, local, internal: BUSY_SEND, expires: this.clock() + BUSY_TTL_S });
3499
3575
  }
3500
3576
 
3501
3577
  // Read marks (the header's "Seen receipts", 0.1.19): an agent's reader took these items (inbox, the MCP, a hook,
@@ -3768,7 +3844,7 @@ export class Carrier {
3768
3844
  takeGroups() { return this.#locked(({ st }) => { const l = st.groups ?? []; st.groups = []; return l; }); }
3769
3845
  takeDevices() { return this.#locked(({ st }) => { const l = st.devices ?? []; st.devices = []; return l; }); }
3770
3846
  // pick(message) → take it (default all); the rest stay for a later take (an engine's).
3771
- takeCalls(pick = () => true) { return this.#locked(({ st }) => { const l = st.calls ?? [], took = l.filter((m) => pick(m)); st.calls = l.filter((m) => !took.includes(m)); return took; }); }
3847
+ takeCalls(pick = () => true) { const took = this.#calls.filter((m) => pick(m)); this.#calls = this.#calls.filter((m) => !took.includes(m)); return took; }
3772
3848
  takeTransfers(pick = () => true) { return this.#locked(({ st }) => { const l = st.transfers ?? [], took = l.filter((m) => pick(m)); st.transfers = l.filter((m) => !took.includes(m)); return took; }); }
3773
3849
  // A file a transfer saved whole (transfer-node.mjs): an inbox item as #onFile makes one, kept for
3774
3850
  // inbox() (keep) and handed to onEvent. item: { type: 'file', from, contact, name, size, sha256, path, … }.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sigelo-contact",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "private": false,
5
5
  "description": "Agent contacts for sigelo identities: invite codes, a contact store, end-to-end encrypted envelopes with hybrid post-quantum key agreement, and an MQTT carrier. Client code (MIT); the relay server is csigelo/sigelo-relay (AGPL-3.0).",
6
6
  "keywords": [
@@ -171,6 +171,6 @@
171
171
  "@noble/post-quantum": "^0.7.1",
172
172
  "hash-wasm": "4.12.0",
173
173
  "mqtt": "^5.16.0",
174
- "sigelo": "^0.1.20"
174
+ "sigelo": "^0.1.21"
175
175
  }
176
176
  }