@kangentic/protocol 0.2.0 → 0.3.0

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.
@@ -24,12 +24,13 @@
24
24
  * event before its router dispatches on `kind`.
25
25
  */
26
26
  import type { JsonValue } from '../wire/messages';
27
- import { type ActivityReasonWire, type ActivityStateWire, type SessionEventWire, type SessionUsageWire, type TranscriptEntryWire } from './payloads';
27
+ import { type ActivityReasonWire, type ActivityStateWire, type SessionEventWire, type SessionUsageWire, type TranscriptEventPayload } from './payloads';
28
28
  export interface TranscriptEvent {
29
29
  kind: 'transcript';
30
30
  sessionId: string;
31
31
  taskId: string;
32
- payload: TranscriptEntryWire[];
32
+ /** Incremental (protocol v2): indexed upserts or a reset signal, never the whole transcript. See TranscriptEventPayload. */
33
+ payload: TranscriptEventPayload;
33
34
  }
34
35
  export type ActivityEventPayload = {
35
36
  type: 'activity';
@@ -68,6 +68,40 @@ export type TranscriptEntryWire = {
68
68
  subtype: TranscriptSystemSubtypeWire;
69
69
  text: string;
70
70
  };
71
+ /** One transcript entry at its absolute position in the full transcript at the delta's revision. */
72
+ export interface TranscriptUpsertWire {
73
+ index: number;
74
+ entry: TranscriptEntryWire;
75
+ }
76
+ /**
77
+ * Protocol v2 transcript payload: incremental, never the whole transcript.
78
+ *
79
+ * - 'delta' carries only the entries that changed or appeared since the
80
+ * last delta the desktop sent on this subscription, as absolute-indexed
81
+ * upserts in ascending order. A large delta is split across several
82
+ * events (same revision) so every frame stays well under the transport
83
+ * caps and the first chunk renders without waiting for the rest. The
84
+ * phone applies upserts inside or adjacent to its loaded window and
85
+ * re-requests a window when it detects a gap.
86
+ * - 'reset' tells the phone its local state is unreconstructable from
87
+ * deltas (entries removed or reordered, or a degraded transcript source
88
+ * whose uuids are unstable) - drop local entries and re-request a
89
+ * window via the read-stream 'transcript-window' action.
90
+ *
91
+ * `revision` is the desktop's monotonically increasing whole-transcript
92
+ * version; `totalEntries` is the full transcript length at that revision,
93
+ * which is how the phone knows history extends above its window.
94
+ */
95
+ export type TranscriptEventPayload = {
96
+ mode: 'delta';
97
+ revision: number;
98
+ totalEntries: number;
99
+ upserts: TranscriptUpsertWire[];
100
+ } | {
101
+ mode: 'reset';
102
+ revision: number;
103
+ totalEntries: number;
104
+ };
71
105
  /** Mirrors the desktop's ActivityState. 'permission' means the agent paused for user approval (incl. AskUserQuestion / ExitPlanMode pauses). */
72
106
  export type ActivityStateWire = 'thinking' | 'idle' | 'permission';
73
107
  /** Mirrors the desktop's ActivityReason discriminated union. */
@@ -198,8 +232,10 @@ export interface DiffFileContentWire {
198
232
  modified: string;
199
233
  language: string;
200
234
  }
201
- /** Narrows a transcript event's payload to the entry array the phone renders. Throws on a malformed entry so the caller can drop the push. */
235
+ /** Narrows a transcript entry array (windowed-history pages). Throws on a malformed entry so the caller can drop the payload. */
202
236
  export declare function parseTranscriptEntriesWire(payload: JsonValue): TranscriptEntryWire[];
237
+ /** Narrows a transcript event's delta/reset payload. Throws on a malformed required field so the caller can drop the push. */
238
+ export declare function parseTranscriptEventPayload(payload: JsonValue): TranscriptEventPayload;
203
239
  /** True for a well-formed ActivityStateWire value. */
204
240
  export declare function isActivityStateWire(value: unknown): value is ActivityStateWire;
205
241
  /** True for a well-formed ActivityReasonWire value. */