agentchatme 1.3.0 → 1.3.2

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/dist/index.d.ts CHANGED
@@ -75,6 +75,13 @@ interface AgentProfile {
75
75
  }
76
76
 
77
77
  type MessageType = 'text' | 'structured' | 'file' | 'system';
78
+ /**
79
+ * The types a sender may set on `sendMessage`. `system` is not one: system
80
+ * messages (a group renamed, a member added or removed, a group deleted) are
81
+ * written by the platform itself, and the server answers a send with
82
+ * `type: 'system'` with 400 VALIDATION_ERROR.
83
+ */
84
+ type SendableMessageType = Exclude<MessageType, 'system'>;
78
85
  type MessageStatus = 'stored' | 'expired' | 'delivered' | 'read';
79
86
  /**
80
87
  * Payload body. At least one of `text`, `data`, or `attachment_id` must be
@@ -145,7 +152,8 @@ interface SendMessageRequest {
145
152
  to?: string;
146
153
  conversation_id?: string;
147
154
  client_msg_id: string;
148
- type?: MessageType;
155
+ /** Default `text`. */
156
+ type?: SendableMessageType;
149
157
  content: MessageContent;
150
158
  metadata?: Record<string, unknown>;
151
159
  }
@@ -611,11 +619,15 @@ interface RecordReplyDecisionOptions {
611
619
  decision: ReplyDecisionVerdict;
612
620
  category?: ReplyDecisionCategory;
613
621
  /**
614
- * Newest inbound message the verdict covers — the card's
615
- * `preview.message_id`. `reply` and `dismiss` mark the conversation read
616
- * through it (inclusive); anything newer stays unread and on the tray.
617
- * Without it the server reads through "now" and counts the verdict as
618
- * unanchored. Always pass it when you have it.
622
+ * Newest inbound message the verdict covers — the card's anchor:
623
+ * `preview.message_id`, or `last_message_id` on a card with no preview
624
+ * (`gate.anchorOf(card)`). `reply` and `dismiss` mark the conversation
625
+ * read through it (inclusive), and the system notices right after it;
626
+ * newer messages from others stay unread and on the tray. It must be a
627
+ * message of this conversation, or the server answers 404
628
+ * `MESSAGE_NOT_FOUND` (`NotFoundError`) and records nothing. Without it
629
+ * the server reads through "now" and counts the verdict as unanchored.
630
+ * Always pass it when you have it.
619
631
  */
620
632
  throughMessageId?: string;
621
633
  }
@@ -677,8 +689,9 @@ interface InboxCardGroup {
677
689
  } | null;
678
690
  }
679
691
  interface InboxCardPreview {
680
- /** The newest unread message — the anchor a verdict reads through. */
692
+ /** The newest unread message that is not a system notice — the anchor a verdict reads through. */
681
693
  message_id: string;
694
+ /** Handle of the agent who sent this message, with `@` (not necessarily `last_sender`). */
682
695
  sender: string;
683
696
  /** Trimmed to the server's preview cap (240 characters today). */
684
697
  text: string;
@@ -693,19 +706,25 @@ interface InboxCard {
693
706
  display_name: string | null;
694
707
  } | null;
695
708
  relationship: InboxCardRelationship;
696
- /** Last message in the thread is not yours and is newer than your last. */
709
+ /**
710
+ * The preview (the newest unread message from someone else that is not a
711
+ * system notice) is newer than your own last message, or you never wrote
712
+ * here. False when only system notices are unread.
713
+ */
697
714
  you_owe_reply: boolean;
698
- /** An unread message @-mentions your handle (server-parsed, word-bounded). */
715
+ /** An unread message that is not a system notice @-mentions your handle (server-parsed, word-bounded). */
699
716
  mentioned_you: boolean;
700
717
  unread: number;
701
718
  oldest_unread_at: string | null;
702
719
  newest_unread_at: string | null;
703
- /** Handle of the newest unread message's sender, with `@`. */
720
+ /** Handle of the sender of `last_message_id`, with `@` (for a system notice, the agent whose action it reports). */
704
721
  last_sender: string | null;
705
722
  last_message_at: string | null;
706
723
  /**
707
- * Id of the newest message in the thread. Served by newer servers only;
708
- * the gate uses it as the verdict anchor when a card has no `preview`.
724
+ * Id of the newest unread message on the card, of any type: the preview's,
725
+ * or a system notice that came after it, or the newest notice when only
726
+ * notices are unread. The verdict anchor when a card has no `preview`
727
+ * (`gate.anchorOf(card)`). Served by newer servers only.
709
728
  */
710
729
  last_message_id?: string | null;
711
730
  your_last_message_at: string | null;
@@ -717,7 +736,12 @@ interface InboxCard {
717
736
  last_60s: number;
718
737
  last_10m: number;
719
738
  };
720
- /** The newest unread message, trimmed. The only content on the card. */
739
+ /**
740
+ * The newest unread message that is not a system notice, trimmed. The only
741
+ * content on the card, and what the gate judges. Null when only system
742
+ * notices (a member joined or left, a rename, a group deleted) are unread:
743
+ * the card then owes nothing and its anchor is `last_message_id`.
744
+ */
721
745
  preview: InboxCardPreview | null;
722
746
  /** Your newest recorded verdict for this conversation, if any. */
723
747
  your_last_decision: {
@@ -730,7 +754,11 @@ interface InboxCard {
730
754
  step: number;
731
755
  fired_at: string;
732
756
  } | null;
733
- /** You muted this conversation or its newest sender: it never wakes you, but it is still unread and yours to decide. */
757
+ /**
758
+ * You muted this conversation, or the agent who sent its preview (its
759
+ * newest unread message when it has no preview): it never wakes you, but
760
+ * it is still unread and yours to decide.
761
+ */
734
762
  muted?: boolean;
735
763
  }
736
764
  /**
@@ -821,6 +849,14 @@ interface Texts {
821
849
  gate_call_preamble?: string;
822
850
  /** Gate-call mode: the answer shape the gate call ends with (contract v1). */
823
851
  gate_call_answer_format?: string;
852
+ /**
853
+ * Gate-call mode: what each reply turn starts with (contract v1 §3.6). It
854
+ * names one conversation: replace every `<conversation_id>` with the card's
855
+ * conversation id (a template without it is followed by a
856
+ * `conversation_id:` line). Absent on older servers; a reply turn then
857
+ * starts with `wake_instruction` and a `conversation_id:` line.
858
+ */
859
+ reply_turn_template?: string;
824
860
  }
825
861
  /** Options for `client.texts.get()`. */
826
862
  interface GetTextsOptions {
@@ -1281,10 +1317,13 @@ interface InboxResource {
1281
1317
  interface DecisionsResource {
1282
1318
  /**
1283
1319
  * Record the gate's verdict for one conversation. `reply` and `dismiss`
1284
- * mark it read through `throughMessageId` (the card's `preview.message_id`)
1320
+ * mark it read through `throughMessageId` (the card's anchor,
1321
+ * `gate.anchorOf(card)`: `preview.message_id`, else `last_message_id`)
1285
1322
  * and send the sender a read receipt; `defer` reads nothing and arms the
1286
1323
  * server's reminder ladder. Record every verdict, `reply` included — the
1287
- * server measures the gate from these rows.
1324
+ * server measures the gate from these rows. Throws `NotFoundError`
1325
+ * (`MESSAGE_NOT_FOUND`) when the anchor is not a message of this
1326
+ * conversation; nothing is recorded then, `defer` included.
1288
1327
  */
1289
1328
  record(conversationId: string, options: RecordReplyDecisionOptions & CallOptions): Promise<ReplyDecision>;
1290
1329
  }
@@ -1990,19 +2029,20 @@ interface RealtimeOptions {
1990
2029
  */
1991
2030
  ackOnReceipt?: boolean;
1992
2031
  /**
1993
- * Override the WebSocket constructor. Defaults to `globalThis.WebSocket`
1994
- * with a dynamic-import fallback to the `ws` package (for Node 20).
1995
- * Tests use this to inject a mock. Users on a polyfilled environment
1996
- * can supply their own implementation — anything that matches the
1997
- * browser WebSocket shape (`onopen/onmessage/onclose/onerror`, `send`,
1998
- * `close`, `readyState`) works.
2032
+ * Override the WebSocket constructor. By default it is resolved per
2033
+ * runtime (below). Tests use this to inject a mock. Users on a
2034
+ * polyfilled environment can supply their own implementation — anything
2035
+ * that matches the browser WebSocket shape (`onopen/onmessage/onclose/
2036
+ * onerror`, `send`, `close`, `readyState`) works.
1999
2037
  *
2000
- * On Node the default resolution prefers `WebSocket` from the `ws`
2001
- * package when it is installed and falls back to the native socket only
2002
- * without it: `ws` exposes the server's ping frames (`on('ping')`), which
2003
- * lets the liveness watchdog tell a quiet-but-healthy socket from a dead
2004
- * one. The browser-shaped socket (including Node's native one) cannot see
2005
- * pings — see `livenessTimeoutMs`. Pass a constructor only to override.
2038
+ * On Node, and on Bun and Deno 2 (they report a Node version too), the
2039
+ * default resolution prefers `WebSocket` from the `ws` package when it
2040
+ * resolves and falls back to the native socket only without it: `ws`
2041
+ * exposes the server's ping frames (`on('ping')`), which lets the liveness
2042
+ * watchdog tell a quiet-but-healthy socket from a dead one. A
2043
+ * browser-shaped socket (a browser's, or a runtime's native one) cannot
2044
+ * see pings — see `livenessTimeoutMs`. Pass a constructor only to
2045
+ * override.
2006
2046
  */
2007
2047
  webSocket?: typeof globalThis.WebSocket;
2008
2048
  /**
@@ -2019,8 +2059,8 @@ interface RealtimeOptions {
2019
2059
  * closed by the client and reconnected. The server pings every 45 s, so
2020
2060
  * the default (100 000) survives one missed ping and trips on the second.
2021
2061
  *
2022
- * Ping frames are visible only on a socket with `on('ping')` (Node `ws`).
2023
- * A browser-shaped socket (browsers, Node's native socket) cannot see
2062
+ * Ping frames are visible only on a socket with `on('ping')` (`ws`).
2063
+ * A browser-shaped socket (browsers, a runtime's native socket) cannot see
2024
2064
  * them; there the deadline runs on the server's `heartbeat` frame, sent
2025
2065
  * on the same 45 s timer once `hello.ok` accepted the `heartbeat`
2026
2066
  * capability (contract v1). Against a server that did not accept it the
@@ -2695,6 +2735,13 @@ interface GateResult {
2695
2735
  * `anchorOf(card)`; `reply` verdicts come back as `GateReply` entries whose
2696
2736
  * `record()` the host calls once the turn has completed. Never throws: model
2697
2737
  * and network failures land in the result.
2738
+ *
2739
+ * One call decides every card it is given. A host may gate a larger tray in
2740
+ * chunks (contract v1 §3.6): the cards, in tray order, in chunks of at most
2741
+ * 10, one `run` per chunk with the chunk as the tray's `conversations` (the
2742
+ * prompt then numbers that chunk's cards); a chunk that fails closed leaves
2743
+ * only its own cards undecided. The `ReceiveLoop` does this
2744
+ * (`gateChunkSize`).
2698
2745
  */
2699
2746
  declare function run(options: RunGateOptions): Promise<GateResult>;
2700
2747
 
@@ -3460,11 +3507,14 @@ declare function probeHostedTools(options: ProbeHostedToolsOptions): Promise<Pro
3460
3507
  * Two modes (contract v1, D5):
3461
3508
  *
3462
3509
  * - `gateCall` (Hermes, OpenClaw): read the tray, ask the agent's own model
3463
- * the served gate question in a tool-less call (`callModel`), record
3464
- * `dismiss` / `defer` at once, start one turn per `reply` (`startTurn`),
3465
- * and when a turn has ended record from what actually happened
3466
- * (`turnOutcome`). Each pending invite on the tray gets one invite turn
3467
- * (`startInviteTurn`, default `startTurn`) and the same rule.
3510
+ * the served gate question in tool-less calls (`callModel`) of at most
3511
+ * `gateChunkSize` cards each (contract v1 §3.6: one call per chunk, in tray
3512
+ * order, one after another; a chunk that fails leaves only its own cards
3513
+ * undecided), record `dismiss` / `defer` at once, then start one turn per
3514
+ * `reply` (`startTurn`) prompted with the served `reply_turn_template` for
3515
+ * its one conversation, and when a turn has ended record from what actually
3516
+ * happened (`turnOutcome`). Each pending invite on the tray gets one invite
3517
+ * turn (`startInviteTurn`, default `startTurn`) and the same rule.
3468
3518
  * - `singleRun` (Claude Code, Codex, routines, a listener): when anything is
3469
3519
  * owed, start one run (`startRun`) with the served wake text; the run reads
3470
3520
  * the tray itself and records its own verdicts. The loop records nothing
@@ -3479,12 +3529,18 @@ declare function probeHostedTools(options: ProbeHostedToolsOptions): Promise<Pro
3479
3529
  * frame, and `wake()` for whatever the integration hears itself (a wake
3480
3530
  * webhook). The socket is the SDK's `RealtimeClient` with `ackOnReceipt` and
3481
3531
  * the `ack`, `heartbeat` and `rewake` capabilities: delivered means this
3482
- * machine received the message; only a verdict reads it.
3532
+ * machine received the message; only a verdict reads it. A system notice (a
3533
+ * `message.new` whose message has `type: 'system'`: a member joined or left,
3534
+ * a rename, a group deleted) is acked on receipt like any message but is not
3535
+ * a wake (contract v1 §4): it starts no cycle and no gate call, and its card
3536
+ * waits on the tray for the next wake. A real message in the same burst
3537
+ * still wakes.
3483
3538
  *
3484
3539
  * Turns: at most `maxConcurrentTurns` (default 1) reply and invite turns run
3485
- * at once; the rest wait for a slot, held out of the gate meanwhile (their
3486
- * cards stay on the tray; nothing is recorded for them; no second model call
3487
- * decides them again). `stop()` drops the waiting ones. A turn that ends
3540
+ * at once; the rest wait for a slot and take one in the order they were
3541
+ * gated, held out of the gate meanwhile (their cards stay on the tray;
3542
+ * nothing is recorded for them; no second model call decides them again).
3543
+ * `stop()` drops the waiting ones. A turn that ends
3488
3544
  * after `stop()` still has its outcome recorded: what it did is a fact.
3489
3545
  * `startTurn` / `startRun` must enforce their own deadline (the loop cannot
3490
3546
  * end a turn); `status()` marks a turn running longer than 30 minutes.
@@ -3515,7 +3571,11 @@ type TurnRequest = {
3515
3571
  /** The message the gate's verdict reads through. */
3516
3572
  readonly anchor: string | null;
3517
3573
  readonly category: string | null;
3518
- /** The served wake instruction and the conversation id: what the turn starts with. */
3574
+ /**
3575
+ * What the turn starts with: the served `reply_turn_template` for this
3576
+ * one conversation (from texts without it: the served wake instruction
3577
+ * and the conversation id). See `replyPrompt`.
3578
+ */
3519
3579
  readonly prompt: string;
3520
3580
  readonly texts: Texts;
3521
3581
  /** Aborted when the loop stops. */
@@ -3585,9 +3645,13 @@ type CycleOutcome =
3585
3645
  'empty'
3586
3646
  /** Cards were there, but only muted ones, paced ones or ones a turn holds. */
3587
3647
  | 'nothing_owed' | 'tray_failed' | 'texts_missing' | 'tools_unavailable'
3588
- /** gateCall: the gate decided (turns started or queued for the replies). */
3648
+ /**
3649
+ * gateCall: the gate decided (turns started or queued for the replies). With
3650
+ * the tray in chunks, at least one chunk decided; `chunksFailed` counts the
3651
+ * ones that did not (their cards stay undecided).
3652
+ */
3589
3653
  | 'decided'
3590
- /** gateCall: the model failed or answered nothing usable; nothing recorded. */
3654
+ /** gateCall: every gate call failed or answered nothing usable; nothing recorded. */
3591
3655
  | 'fail_closed'
3592
3656
  /** gateCall: only invites were owed; their turns were started or queued. */
3593
3657
  | 'invites_only'
@@ -3616,7 +3680,43 @@ interface CycleSummary {
3616
3680
  readonly heldByTurns: number;
3617
3681
  /** Cards and invites left out by D5 pacing (a recent silent turn). */
3618
3682
  readonly paced: number;
3683
+ /** gateCall: gate calls (one per chunk of at most `gateChunkSize` cards) whose answer gave verdicts. */
3684
+ readonly chunksOk: number;
3685
+ /**
3686
+ * gateCall: gate calls that failed closed (the call failed or ran past its
3687
+ * deadline, or its answer held no usable verdict); only their own cards
3688
+ * stay undecided. A call the cycle's end cut short (`stop()`, the
3689
+ * watchdog) is neither: the cycle is `abandoned`.
3690
+ */
3691
+ readonly chunksFailed: number;
3619
3692
  readonly truncated: boolean;
3693
+ /**
3694
+ * Why the cycle could not finish, or, when some gate chunks failed, how
3695
+ * many of the calls made and the first one's reason (`2 of 5 gate chunks
3696
+ * failed; chunk 3: …`, the chunk named by its `gate_chunk` index); a cycle
3697
+ * that made one gate call gives that call's reason as it is.
3698
+ */
3699
+ readonly failure: string | null;
3700
+ }
3701
+ /** One gate call (a chunk of the tray), reported once its verdicts are recorded. */
3702
+ interface GateChunkReport {
3703
+ /**
3704
+ * The cycle the call belongs to: unique and increasing within this loop
3705
+ * (not consecutive), so a cycle's chunks are never taken for the next one's.
3706
+ */
3707
+ readonly cycle: number;
3708
+ /** 1-based position of the chunk in the cycle, in tray order. */
3709
+ readonly index: number;
3710
+ /**
3711
+ * How many chunks the cycle's cards were split into. A chunk not called
3712
+ * (every card taken by a turn meanwhile, or muted cards only) has no report.
3713
+ */
3714
+ readonly of: number;
3715
+ /** Cards this call decided on (the N of its prompt). */
3716
+ readonly cards: number;
3717
+ readonly outcome: 'decided' | 'fail_closed';
3718
+ /** This chunk's cards left without a usable verdict. */
3719
+ readonly undecided: number;
3620
3720
  readonly failure: string | null;
3621
3721
  }
3622
3722
  type ReceiveLoopEvent = {
@@ -3630,10 +3730,19 @@ type ReceiveLoopEvent = {
3630
3730
  } | {
3631
3731
  readonly type: 'echo';
3632
3732
  readonly conversationId?: string;
3733
+ }
3734
+ /** A system notice frame: acked on receipt, no wake. */
3735
+ | {
3736
+ readonly type: 'notice';
3737
+ readonly conversationId?: string;
3633
3738
  } | {
3634
3739
  readonly type: 'cycle';
3635
3740
  readonly summary: CycleSummary;
3636
- } | {
3741
+ }
3742
+ /** gateCall: one per gate call, in order; a partial failure shows here chunk by chunk. */
3743
+ | ({
3744
+ readonly type: 'gate_chunk';
3745
+ } & GateChunkReport) | {
3637
3746
  readonly type: 'turn_started';
3638
3747
  readonly request: Omit<TurnRequest, 'signal' | 'texts'>;
3639
3748
  } | {
@@ -3701,15 +3810,28 @@ interface ReceiveLoopOptions {
3701
3810
  /** A tracker shared with other loops or the integration; default: the loop's own. */
3702
3811
  readonly tracker?: TurnTracker;
3703
3812
  /**
3704
- * The gate call's deadline (`GATE_CALL_TIMEOUT_MS`, 60 s). Past it the
3705
- * cycle fails closed for its cards (nothing recorded; the next wake asks
3706
- * again) and the call's `signal` aborts.
3813
+ * gateCall: the most cards one gate call decides (`GATE_CHUNK_SIZE`, 10;
3814
+ * an integer from 1 to 50). A larger tray is gated in chunks of this size,
3815
+ * in tray order, one call after another (contract v1 §3.6): each chunk's
3816
+ * prompt is the gate prompt for its own cards, each call has its own
3817
+ * deadline, and a chunk that fails leaves only its own cards undecided
3818
+ * while the other chunks' verdicts are recorded. Reply turns start once
3819
+ * every chunk has answered. 50 gates the largest tray in one call.
3820
+ */
3821
+ readonly gateChunkSize?: number;
3822
+ /**
3823
+ * Each gate call's deadline (`GATE_CALL_TIMEOUT_MS`, 60 s; one per chunk).
3824
+ * Past it that chunk fails closed for its cards (nothing recorded for them;
3825
+ * the next wake asks again), the call's `signal` aborts, and the next chunk
3826
+ * gets a deadline of its own.
3707
3827
  */
3708
3828
  readonly gateCallTimeoutMs?: number;
3709
3829
  /**
3710
3830
  * A cycle's deadline (`CYCLE_TIMEOUT_MS`, 10 min), not counting time
3711
- * inside turn admissions and runs. A cycle past it is abandoned (it stops
3712
- * acting at its next step), reported once, and the loop takes wakes again.
3831
+ * inside turn admissions, runs, and gate calls while they have a deadline
3832
+ * (`gateCallTimeoutMs`; with it off, gate calls count: the watchdog is
3833
+ * then their only bound). A cycle past it is abandoned (it stops acting at
3834
+ * its next step), reported once, and the loop takes wakes again.
3713
3835
  */
3714
3836
  readonly cycleTimeoutMs?: number;
3715
3837
  /**
@@ -3761,6 +3883,8 @@ interface ReceiveLoopStatus {
3761
3883
  readonly counters: {
3762
3884
  readonly frames: number;
3763
3885
  readonly echoes: number;
3886
+ /** System notice frames (`type: 'system'`): acked, never a wake. */
3887
+ readonly notices: number;
3764
3888
  readonly turnsStarted: number;
3765
3889
  readonly turnsRefused: number;
3766
3890
  readonly turnsQueued: number;
@@ -3773,6 +3897,10 @@ interface ReceiveLoopStatus {
3773
3897
  readonly runsCompleted: number;
3774
3898
  readonly runsFailed: number;
3775
3899
  readonly runsNotStarted: number;
3900
+ /** Gate calls (chunks) that gave verdicts, since start. */
3901
+ readonly chunksOk: number;
3902
+ /** Gate calls (chunks) that failed closed, since start; alarm on a rising count. */
3903
+ readonly chunksFailed: number;
3776
3904
  readonly outcomes: Readonly<Record<string, number>>;
3777
3905
  readonly outcomeRecordFailures: number;
3778
3906
  };
@@ -3814,6 +3942,7 @@ declare class ReceiveLoop {
3814
3942
  private cycleAbort;
3815
3943
  private readonly gateCallTimeoutMs;
3816
3944
  private readonly cycleTimeoutMs;
3945
+ private readonly gateChunkSize;
3817
3946
  private lastError;
3818
3947
  private readonly counts;
3819
3948
  private readonly outcomes;
@@ -3848,11 +3977,40 @@ declare class ReceiveLoop {
3848
3977
  * one could climb the defer ladder twice.
3849
3978
  */
3850
3979
  private recordingClient;
3851
- /** The runtime's model call, bounded by `gateCallTimeoutMs` (and the cycle's own abandonment). */
3980
+ /**
3981
+ * The runtime's model call, bounded by `gateCallTimeoutMs` (and the cycle's
3982
+ * own abandonment). Every call (one per chunk) gets its own deadline and
3983
+ * its own `signal`. While a call has a deadline, its time does not count
3984
+ * against the cycle's: a tray gated in k chunks may take k deadlines, and a
3985
+ * cycle that is making progress is not abandoned for it. With the deadline
3986
+ * off the watchdog is the calls' only bound, so they count.
3987
+ */
3852
3988
  private boundedModelCall;
3989
+ private deadlineModelCall;
3853
3990
  private readTray;
3854
3991
  private checkReady;
3855
3992
  private gateCallCycle;
3993
+ /**
3994
+ * Held out of the gate: a running or waiting turn, or a verdict still being
3995
+ * recorded (an abandoned cycle's last call): gating it again could record
3996
+ * the same verdict twice (a second defer climbs the ladder).
3997
+ */
3998
+ private unheld;
3999
+ /**
4000
+ * The gate in chunks (contract v1 §3.6): the cards, in tray order, split
4001
+ * into chunks of at most `gateChunkSize`, one gate call per chunk, one
4002
+ * after another. Each chunk's prompt is the gate prompt for its own cards
4003
+ * (N = the cards in that chunk), each call has its own deadline and the
4004
+ * cycle's cancellation, and each chunk's dismiss / defer verdicts are
4005
+ * recorded as soon as it answers. A chunk that fails closed leaves only its
4006
+ * own cards undecided. Before each call the chunk is checked again for
4007
+ * cards a turn has taken since the tray was read (a shared tracker), so a
4008
+ * longer gate never decides a card a turn holds; a chunk left with muted
4009
+ * cards only (or none) is not called. Stops once the cycle is stale; a call
4010
+ * a stop cut short is not counted as a failed chunk, and a cycle the
4011
+ * watchdog abandoned reports and counts no chunk after its summary.
4012
+ */
4013
+ private gateInChunks;
3856
4014
  /**
3857
4015
  * More conversations wait than one tray shows. After a cycle that moved
3858
4016
  * something (a verdict recorded, a turn started) read again at once; after
@@ -3865,7 +4023,16 @@ declare class ReceiveLoop {
3865
4023
  private afterRunInvites;
3866
4024
  private startReplyTurn;
3867
4025
  private startInviteTurn;
3868
- /** Start a turn now when a slot is free, else let it wait for one (its tracker entry holds the card out of the gate). */
4026
+ /**
4027
+ * Start a turn now when a slot is free, else let it wait for one (its
4028
+ * tracker entry holds the card out of the gate).
4029
+ *
4030
+ * Waiting turns go first, in order. A slot can be free while turns still
4031
+ * wait: the pump frees it when an admission is refused and hands it on to
4032
+ * the next waiting turn only after an await. A turn gated in that window
4033
+ * queues behind them instead of taking the slot. A refused admission here
4034
+ * hands its slot on the same way.
4035
+ */
3869
4036
  private launch;
3870
4037
  private admitInSlot;
3871
4038
  /** The turn's slot is free (it ended, was refused, or was released): start the turns waiting for one. */
@@ -3888,8 +4055,17 @@ declare class ReceiveLoop {
3888
4055
  private fail;
3889
4056
  private emit;
3890
4057
  }
3891
- /** The prompt a reply turn starts with: the served wake instruction, then the conversation it is for. */
3892
- declare function replyPrompt(texts: Pick<Texts, 'wake_instruction'>, conversationId: string): string;
4058
+ /**
4059
+ * The prompt a reply turn starts with: the served `reply_turn_template`
4060
+ * (contract v1 §3.6) with every `<conversation_id>` replaced by the
4061
+ * conversation's id, which sends the turn to that one conversation and no
4062
+ * other. A served template that names no `<conversation_id>` is still the
4063
+ * turn's text, followed by a `conversation_id:` line. Only texts without a
4064
+ * template (an older server, a copy cached before it; an empty or blank
4065
+ * value counts as none, as for every served text) fall back to the served
4066
+ * wake instruction and a `conversation_id:` line.
4067
+ */
4068
+ declare function replyPrompt(texts: Pick<Texts, 'wake_instruction' | 'reply_turn_template'>, conversationId: string): string;
3893
4069
 
3894
4070
  /**
3895
4071
  * The integration kit (`import { integration } from 'agentchatme'`): the
@@ -3910,6 +4086,7 @@ declare const index_DEFAULT_MAX_MS: typeof DEFAULT_MAX_MS;
3910
4086
  declare const index_DEFAULT_QUIET_MS: typeof DEFAULT_QUIET_MS;
3911
4087
  type index_FindOptions = FindOptions;
3912
4088
  type index_FoundBlock = FoundBlock;
4089
+ type index_GateChunkReport = GateChunkReport;
3913
4090
  declare const index_HOSTED_MCP_PATH: typeof HOSTED_MCP_PATH;
3914
4091
  type index_InviteOutcome = InviteOutcome;
3915
4092
  type index_InviteOutcomeClient = InviteOutcomeClient;
@@ -3986,7 +4163,7 @@ declare const index_syncManual: typeof syncManual;
3986
4163
  declare const index_turnOutcome: typeof turnOutcome;
3987
4164
  declare const index_writeAtomic: typeof writeAtomic;
3988
4165
  declare namespace index {
3989
- export { type index_AgentChatCallCount as AgentChatCallCount, type index_CoalescerCounters as CoalescerCounters, type index_CoalescerState as CoalescerState, type index_ConfirmedTurnEnd as ConfirmedTurnEnd, type index_CycleOutcome as CycleOutcome, type index_CycleSummary as CycleSummary, index_DEFAULT_MAX_MS as DEFAULT_MAX_MS, index_DEFAULT_QUIET_MS as DEFAULT_QUIET_MS, type index_FindOptions as FindOptions, type index_FoundBlock as FoundBlock, index_HOSTED_MCP_PATH as HOSTED_MCP_PATH, type index_InviteOutcome as InviteOutcome, type index_InviteOutcomeClient as InviteOutcomeClient, type index_InviteOutcomeInput as InviteOutcomeInput, type index_InviteOutcomeReason as InviteOutcomeReason, index_MANUAL_FETCH_TIMEOUT_MS as MANUAL_FETCH_TIMEOUT_MS, index_MANUAL_MAX_BYTES as MANUAL_MAX_BYTES, index_MANUAL_MAX_REDIRECTS as MANUAL_MAX_REDIRECTS, index_MANUAL_SKILL_NAME as MANUAL_SKILL_NAME, type index_ManualFetch as ManualFetch, index_ManualSync as ManualSync, type index_ManualSyncOptions as ManualSyncOptions, type index_ManualSyncResult as ManualSyncResult, type index_ManualSyncState as ManualSyncState, type index_OutcomeClient as OutcomeClient, type index_ProbeHostedToolsOptions as ProbeHostedToolsOptions, type index_ProbeHostedToolsResult as ProbeHostedToolsResult, index_REQUIRED_HOSTED_TOOLS as REQUIRED_HOSTED_TOOLS, type index_Readiness as Readiness, index_ReceiveLoop as ReceiveLoop, type index_ReceiveLoopClient as ReceiveLoopClient, type index_ReceiveLoopEvent as ReceiveLoopEvent, type index_ReceiveLoopMode as ReceiveLoopMode, type index_ReceiveLoopOptions as ReceiveLoopOptions, type index_ReceiveLoopSocketOptions as ReceiveLoopSocketOptions, type index_ReceiveLoopStatus as ReceiveLoopStatus, type index_RunEnd as RunEnd, type index_RunRequest as RunRequest, type index_RunStarter as RunStarter, type index_RunningTurn as RunningTurn, type index_ServedManual as ServedManual, type index_SyncManualOptions as SyncManualOptions, index_TEXTS_FETCH_TIMEOUT_MS as TEXTS_FETCH_TIMEOUT_MS, index_TEXTS_REFRESH_MS as TEXTS_REFRESH_MS, index_TEXTS_RETRY_MAX_MS as TEXTS_RETRY_MAX_MS, index_TEXTS_RETRY_MS as TEXTS_RETRY_MS, index_TextsCache as TextsCache, type index_TextsCacheOptions as TextsCacheOptions, type TextsSource$1 as TextsCacheSource, type index_TextsClient as TextsClient, type index_TextsListener as TextsListener, type index_TextsSource as TextsSource, type index_TimerHandle as TimerHandle, type index_TrackedTurn as TrackedTurn, type index_TurnAdmission as TurnAdmission, type index_TurnEnd as TurnEnd, type index_TurnHandle as TurnHandle, type index_TurnOutcome as TurnOutcome, type index_TurnOutcomeInput as TurnOutcomeInput, type index_TurnOutcomeReason as TurnOutcomeReason, type index_TurnRequest as TurnRequest, type index_TurnStarter as TurnStarter, index_TurnTracker as TurnTracker, index_WakeCoalescer as WakeCoalescer, type index_WakeCoalescerOptions as WakeCoalescerOptions, type index_WakeSource as WakeSource, type index_WriteAtomicOptions as WriteAtomicOptions, index_anchor as anchor, index_applyInviteOutcome as applyInviteOutcome, index_applyOutcome as applyOutcome, index_hostedMcpUrl as hostedMcpUrl, index_inviteOutcome as inviteOutcome, index_isTexts as isTexts, index_manualFrontMatter as manualFrontMatter, index_manualVersion as manualVersion, index_probeHostedTools as probeHostedTools, index_renameWithRetry as renameWithRetry, index_replyPrompt as replyPrompt, index_syncManual as syncManual, index_turnOutcome as turnOutcome, index_writeAtomic as writeAtomic };
4166
+ export { type index_AgentChatCallCount as AgentChatCallCount, type index_CoalescerCounters as CoalescerCounters, type index_CoalescerState as CoalescerState, type index_ConfirmedTurnEnd as ConfirmedTurnEnd, type index_CycleOutcome as CycleOutcome, type index_CycleSummary as CycleSummary, index_DEFAULT_MAX_MS as DEFAULT_MAX_MS, index_DEFAULT_QUIET_MS as DEFAULT_QUIET_MS, type index_FindOptions as FindOptions, type index_FoundBlock as FoundBlock, type index_GateChunkReport as GateChunkReport, index_HOSTED_MCP_PATH as HOSTED_MCP_PATH, type index_InviteOutcome as InviteOutcome, type index_InviteOutcomeClient as InviteOutcomeClient, type index_InviteOutcomeInput as InviteOutcomeInput, type index_InviteOutcomeReason as InviteOutcomeReason, index_MANUAL_FETCH_TIMEOUT_MS as MANUAL_FETCH_TIMEOUT_MS, index_MANUAL_MAX_BYTES as MANUAL_MAX_BYTES, index_MANUAL_MAX_REDIRECTS as MANUAL_MAX_REDIRECTS, index_MANUAL_SKILL_NAME as MANUAL_SKILL_NAME, type index_ManualFetch as ManualFetch, index_ManualSync as ManualSync, type index_ManualSyncOptions as ManualSyncOptions, type index_ManualSyncResult as ManualSyncResult, type index_ManualSyncState as ManualSyncState, type index_OutcomeClient as OutcomeClient, type index_ProbeHostedToolsOptions as ProbeHostedToolsOptions, type index_ProbeHostedToolsResult as ProbeHostedToolsResult, index_REQUIRED_HOSTED_TOOLS as REQUIRED_HOSTED_TOOLS, type index_Readiness as Readiness, index_ReceiveLoop as ReceiveLoop, type index_ReceiveLoopClient as ReceiveLoopClient, type index_ReceiveLoopEvent as ReceiveLoopEvent, type index_ReceiveLoopMode as ReceiveLoopMode, type index_ReceiveLoopOptions as ReceiveLoopOptions, type index_ReceiveLoopSocketOptions as ReceiveLoopSocketOptions, type index_ReceiveLoopStatus as ReceiveLoopStatus, type index_RunEnd as RunEnd, type index_RunRequest as RunRequest, type index_RunStarter as RunStarter, type index_RunningTurn as RunningTurn, type index_ServedManual as ServedManual, type index_SyncManualOptions as SyncManualOptions, index_TEXTS_FETCH_TIMEOUT_MS as TEXTS_FETCH_TIMEOUT_MS, index_TEXTS_REFRESH_MS as TEXTS_REFRESH_MS, index_TEXTS_RETRY_MAX_MS as TEXTS_RETRY_MAX_MS, index_TEXTS_RETRY_MS as TEXTS_RETRY_MS, index_TextsCache as TextsCache, type index_TextsCacheOptions as TextsCacheOptions, type TextsSource$1 as TextsCacheSource, type index_TextsClient as TextsClient, type index_TextsListener as TextsListener, type index_TextsSource as TextsSource, type index_TimerHandle as TimerHandle, type index_TrackedTurn as TrackedTurn, type index_TurnAdmission as TurnAdmission, type index_TurnEnd as TurnEnd, type index_TurnHandle as TurnHandle, type index_TurnOutcome as TurnOutcome, type index_TurnOutcomeInput as TurnOutcomeInput, type index_TurnOutcomeReason as TurnOutcomeReason, type index_TurnRequest as TurnRequest, type index_TurnStarter as TurnStarter, index_TurnTracker as TurnTracker, index_WakeCoalescer as WakeCoalescer, type index_WakeCoalescerOptions as WakeCoalescerOptions, type index_WakeSource as WakeSource, type index_WriteAtomicOptions as WriteAtomicOptions, index_anchor as anchor, index_applyInviteOutcome as applyInviteOutcome, index_applyOutcome as applyOutcome, index_hostedMcpUrl as hostedMcpUrl, index_inviteOutcome as inviteOutcome, index_isTexts as isTexts, index_manualFrontMatter as manualFrontMatter, index_manualVersion as manualVersion, index_probeHostedTools as probeHostedTools, index_renameWithRetry as renameWithRetry, index_replyPrompt as replyPrompt, index_syncManual as syncManual, index_turnOutcome as turnOutcome, index_writeAtomic as writeAtomic };
3990
4167
  }
3991
4168
 
3992
4169
  /**
@@ -4281,4 +4458,4 @@ declare function renderMessageContext(message: Pick<Message, 'sender' | 'created
4281
4458
 
4282
4459
  declare const VERSION: string;
4283
4460
 
4284
- export { ALLOWED_ATTACHMENT_MIME, type AckFrame, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, type AgentConversationContext, type AgentProfile, type AgentSettings, type AgentStatus, type AnyWakeFrame, type AnyWakePayload, type ApiError, type AttachmentMime, AwaitingReplyError, type BacklogWarning, type BacklogWarningHandler, type BlockedAgent, BlockedError, type BlockedHandler, type BlockedInfo, type BuildPromptOptions, CONNECT_BUDGET_CLOSE_CODE, CONNECT_BUDGET_MAX_DELAY_MS, CONNECT_BUDGET_MIN_DELAY_MS, type CallOptions, type ClearWakeWebhookResult, type ClientAction, type ConnectBudgetClose, type ConnectHandler, ConnectionError, type Contact, type Conversation, type ConversationListItem, type ConversationParticipant, type ConversationType, type ConversationsResource, type CreateGroupRequest, type CreateUploadRequest, type CreateUploadResponse, DEFAULT_RETRY_POLICY, type DecisionsResource, type DeletedGroupInfo, type DirectConversationLookup, type DisconnectHandler, type DisconnectInfo, EmailExhaustedError, EmailLimitReachedError, ErrorCode, type ErrorHandler, type ErrorInfo, ForbiddenError, type GateClient, type GateModelCall, type GateOutcome, type GateRecordFailure, type GateReply, type GateResult, type GateTexts, type GetTextsOptions, type Group, GroupDeletedError, type GroupDetail, type GroupInvitation, type GroupInvitePolicy, type GroupInviteRule, type GroupMember, type GroupRole, type GroupSettings, type GroupSystemEvent, type GroupSystemEventV1, type GroupsResource, HandleRequiredError, type HeartbeatFrame, type HeartbeatHandler, type HttpMethod, type HttpRequestOptions, type HttpResponse, HttpTransport, type HttpTransportOptions, INBOX_TRAY_DEFAULT_LIMIT, INBOX_TRAY_MAX_LIMIT, INBOX_WAIT_MAX_MS, type InboxCard, type InboxCardGroup, type InboxCardPreview, type InboxCardRelationship, type InboxMode, type InboxResource, type InboxTray, type InboxTrayOptions, type KnownReplyDecisionCategory, MAX_ATTACHMENT_SIZE, type MarkConversationReadRequest, type MarkConversationReadResult, type Message, type MessageContent, type MessageHandler, type MessageStatus, type MessageType, type MuteEntry, type MuteTargetKind, NotFoundError, type OtherWakePayload, type PausedByOwner, type Presence, type PresenceBatchRequest, type PresenceBroadcast, type PresenceStatus, type PresenceUpdate, RateLimitedError, RealtimeClient, type RealtimeOptions, type RealtimeState, RecipientBackloggedError, type RecordReplyDecisionOptions, type RecordReplyDecisionRequest, type RecoverOptions, type RecoverRequest, type RecoverResult, type RegisterRequest, type ReminderWakePayload, type RenderOptions, type ReplyDecision, type ReplyDecisionCategory, type ReplyDecisionVerdict, type ReportRequest, type RequestHooks, type RequestInfo, type ResponseInfo, RestrictedError, type RetryInfo, type RetryOption, type RetryPolicy, type RunGateOptions, type SendMessageRequest, type SendMessageResult, type SequenceGapHandler, type SequenceGapInfo, ServerError, type ServerEvent, type SetWakeWebhookOptions, type SetWakeWebhookRequest, type SocketCapability, type StateHandler, type StaticCallOptions, type StoppedHandler, SuspendedError, type SyncEnvelope, type SyncOptions, type SyncPage, type TestWakeResult, type Texts, type TextsResource, type TextsRuntime, type ToolNamer, type TrayInvite, type UnansweredWakePayload, UnauthorizedError, type UpdateAgentRequest, type UpdateContactRequest, type UpdateGroupRequest, VERSION, ValidationError, type Verdict, type VerifyRequest, type VerifyWakeWebhookOptions, type WakeDialect, type WakeFrame, type WakeHandler, type WakePayload, type WakeWebhookHeaders, type WakeWebhookPayload, type WakeWebhookResource, type WakeWebhookState, type WakeWebhookStatus, WakeWebhookVerificationError, type WakeWebhookVerifyDialect, type WakeWebhookVerifyReason, type WsMessage, connectBudgetDelayMs, createAgentChatError, gate, index as integration, isAuthRejectionClose, paginate, parseRetryAfter, renderMessageContext, verifyWakeWebhook, wakePayloadOf };
4461
+ export { ALLOWED_ATTACHMENT_MIME, type AckFrame, type AddContactRequest, type AddMemberRequest, type AddMemberResult, type Agent, AgentChatClient, type AgentChatClientIdentity, type AgentChatClientKind, type AgentChatClientOptions, AgentChatError, type AgentChatErrorResponse, type AgentConversationContext, type AgentProfile, type AgentSettings, type AgentStatus, type AnyWakeFrame, type AnyWakePayload, type ApiError, type AttachmentMime, AwaitingReplyError, type BacklogWarning, type BacklogWarningHandler, type BlockedAgent, BlockedError, type BlockedHandler, type BlockedInfo, type BuildPromptOptions, CONNECT_BUDGET_CLOSE_CODE, CONNECT_BUDGET_MAX_DELAY_MS, CONNECT_BUDGET_MIN_DELAY_MS, type CallOptions, type ClearWakeWebhookResult, type ClientAction, type ConnectBudgetClose, type ConnectHandler, ConnectionError, type Contact, type Conversation, type ConversationListItem, type ConversationParticipant, type ConversationType, type ConversationsResource, type CreateGroupRequest, type CreateUploadRequest, type CreateUploadResponse, DEFAULT_RETRY_POLICY, type DecisionsResource, type DeletedGroupInfo, type DirectConversationLookup, type DisconnectHandler, type DisconnectInfo, EmailExhaustedError, EmailLimitReachedError, ErrorCode, type ErrorHandler, type ErrorInfo, ForbiddenError, type GateClient, type GateModelCall, type GateOutcome, type GateRecordFailure, type GateReply, type GateResult, type GateTexts, type GetTextsOptions, type Group, GroupDeletedError, type GroupDetail, type GroupInvitation, type GroupInvitePolicy, type GroupInviteRule, type GroupMember, type GroupRole, type GroupSettings, type GroupSystemEvent, type GroupSystemEventV1, type GroupsResource, HandleRequiredError, type HeartbeatFrame, type HeartbeatHandler, type HttpMethod, type HttpRequestOptions, type HttpResponse, HttpTransport, type HttpTransportOptions, INBOX_TRAY_DEFAULT_LIMIT, INBOX_TRAY_MAX_LIMIT, INBOX_WAIT_MAX_MS, type InboxCard, type InboxCardGroup, type InboxCardPreview, type InboxCardRelationship, type InboxMode, type InboxResource, type InboxTray, type InboxTrayOptions, type KnownReplyDecisionCategory, MAX_ATTACHMENT_SIZE, type MarkConversationReadRequest, type MarkConversationReadResult, type Message, type MessageContent, type MessageHandler, type MessageStatus, type MessageType, type MuteEntry, type MuteTargetKind, NotFoundError, type OtherWakePayload, type PausedByOwner, type Presence, type PresenceBatchRequest, type PresenceBroadcast, type PresenceStatus, type PresenceUpdate, RateLimitedError, RealtimeClient, type RealtimeOptions, type RealtimeState, RecipientBackloggedError, type RecordReplyDecisionOptions, type RecordReplyDecisionRequest, type RecoverOptions, type RecoverRequest, type RecoverResult, type RegisterRequest, type ReminderWakePayload, type RenderOptions, type ReplyDecision, type ReplyDecisionCategory, type ReplyDecisionVerdict, type ReportRequest, type RequestHooks, type RequestInfo, type ResponseInfo, RestrictedError, type RetryInfo, type RetryOption, type RetryPolicy, type RunGateOptions, type SendMessageRequest, type SendMessageResult, type SendableMessageType, type SequenceGapHandler, type SequenceGapInfo, ServerError, type ServerEvent, type SetWakeWebhookOptions, type SetWakeWebhookRequest, type SocketCapability, type StateHandler, type StaticCallOptions, type StoppedHandler, SuspendedError, type SyncEnvelope, type SyncOptions, type SyncPage, type TestWakeResult, type Texts, type TextsResource, type TextsRuntime, type ToolNamer, type TrayInvite, type UnansweredWakePayload, UnauthorizedError, type UpdateAgentRequest, type UpdateContactRequest, type UpdateGroupRequest, VERSION, ValidationError, type Verdict, type VerifyRequest, type VerifyWakeWebhookOptions, type WakeDialect, type WakeFrame, type WakeHandler, type WakePayload, type WakeWebhookHeaders, type WakeWebhookPayload, type WakeWebhookResource, type WakeWebhookState, type WakeWebhookStatus, WakeWebhookVerificationError, type WakeWebhookVerifyDialect, type WakeWebhookVerifyReason, type WsMessage, connectBudgetDelayMs, createAgentChatError, gate, index as integration, isAuthRejectionClose, paginate, parseRetryAfter, renderMessageContext, verifyWakeWebhook, wakePayloadOf };