@yefengr/remote-pi 0.7.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.
- package/LICENSE +21 -0
- package/README.md +674 -0
- package/dist/actions/handlers.d.ts +122 -0
- package/dist/actions/handlers.js +160 -0
- package/dist/actions/handlers.js.map +1 -0
- package/dist/actions/registry.d.ts +39 -0
- package/dist/actions/registry.js +58 -0
- package/dist/actions/registry.js.map +1 -0
- package/dist/bin/supervisord.d.ts +2 -0
- package/dist/bin/supervisord.js +86 -0
- package/dist/bin/supervisord.js.map +1 -0
- package/dist/config.d.ts +55 -0
- package/dist/config.js +118 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon/client.d.ts +20 -0
- package/dist/daemon/client.js +131 -0
- package/dist/daemon/client.js.map +1 -0
- package/dist/daemon/control_protocol.d.ts +176 -0
- package/dist/daemon/control_protocol.js +63 -0
- package/dist/daemon/control_protocol.js.map +1 -0
- package/dist/daemon/cron_log.d.ts +45 -0
- package/dist/daemon/cron_log.js +72 -0
- package/dist/daemon/cron_log.js.map +1 -0
- package/dist/daemon/cron_registry.d.ts +80 -0
- package/dist/daemon/cron_registry.js +194 -0
- package/dist/daemon/cron_registry.js.map +1 -0
- package/dist/daemon/id.d.ts +24 -0
- package/dist/daemon/id.js +36 -0
- package/dist/daemon/id.js.map +1 -0
- package/dist/daemon/install.d.ts +170 -0
- package/dist/daemon/install.js +547 -0
- package/dist/daemon/install.js.map +1 -0
- package/dist/daemon/registry.d.ts +63 -0
- package/dist/daemon/registry.js +153 -0
- package/dist/daemon/registry.js.map +1 -0
- package/dist/daemon/rpc_child.d.ts +194 -0
- package/dist/daemon/rpc_child.js +389 -0
- package/dist/daemon/rpc_child.js.map +1 -0
- package/dist/daemon/supervisor.d.ts +93 -0
- package/dist/daemon/supervisor.js +596 -0
- package/dist/daemon/supervisor.js.map +1 -0
- package/dist/extension_ui_bridge.d.ts +26 -0
- package/dist/extension_ui_bridge.js +341 -0
- package/dist/extension_ui_bridge.js.map +1 -0
- package/dist/index.d.ts +214 -0
- package/dist/index.js +5410 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/mesh_result.d.ts +10 -0
- package/dist/mcp/mesh_result.js +42 -0
- package/dist/mcp/mesh_result.js.map +1 -0
- package/dist/mcp/mesh_server.d.ts +16 -0
- package/dist/mcp/mesh_server.js +327 -0
- package/dist/mcp/mesh_server.js.map +1 -0
- package/dist/mesh/canonical.d.ts +30 -0
- package/dist/mesh/canonical.js +61 -0
- package/dist/mesh/canonical.js.map +1 -0
- package/dist/mesh/client.d.ts +18 -0
- package/dist/mesh/client.js +125 -0
- package/dist/mesh/client.js.map +1 -0
- package/dist/mesh/encoding.d.ts +38 -0
- package/dist/mesh/encoding.js +216 -0
- package/dist/mesh/encoding.js.map +1 -0
- package/dist/mesh/self_revoke.d.ts +73 -0
- package/dist/mesh/self_revoke.js +401 -0
- package/dist/mesh/self_revoke.js.map +1 -0
- package/dist/mesh/siblings.d.ts +49 -0
- package/dist/mesh/siblings.js +159 -0
- package/dist/mesh/siblings.js.map +1 -0
- package/dist/mesh/types.d.ts +34 -0
- package/dist/mesh/types.js +11 -0
- package/dist/mesh/types.js.map +1 -0
- package/dist/mesh/verify.d.ts +17 -0
- package/dist/mesh/verify.js +86 -0
- package/dist/mesh/verify.js.map +1 -0
- package/dist/pairing/crypto.d.ts +8 -0
- package/dist/pairing/crypto.js +22 -0
- package/dist/pairing/crypto.js.map +1 -0
- package/dist/pairing/qr.d.ts +59 -0
- package/dist/pairing/qr.js +125 -0
- package/dist/pairing/qr.js.map +1 -0
- package/dist/pairing/storage.d.ts +120 -0
- package/dist/pairing/storage.js +604 -0
- package/dist/pairing/storage.js.map +1 -0
- package/dist/protocol/codec.d.ts +7 -0
- package/dist/protocol/codec.js +49 -0
- package/dist/protocol/codec.js.map +1 -0
- package/dist/protocol/types.d.ts +393 -0
- package/dist/protocol/types.js +2 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/protocol/v2/codec.d.ts +26 -0
- package/dist/protocol/v2/codec.js +207 -0
- package/dist/protocol/v2/codec.js.map +1 -0
- package/dist/protocol/v2/index.d.ts +3 -0
- package/dist/protocol/v2/index.js +4 -0
- package/dist/protocol/v2/index.js.map +1 -0
- package/dist/protocol/v2/schemas.d.ts +1939 -0
- package/dist/protocol/v2/schemas.js +409 -0
- package/dist/protocol/v2/schemas.js.map +1 -0
- package/dist/protocol/v2/session_state.d.ts +75 -0
- package/dist/protocol/v2/session_state.js +176 -0
- package/dist/protocol/v2/session_state.js.map +1 -0
- package/dist/rooms.d.ts +29 -0
- package/dist/rooms.js +57 -0
- package/dist/rooms.js.map +1 -0
- package/dist/session/bridge.d.ts +37 -0
- package/dist/session/bridge.js +130 -0
- package/dist/session/bridge.js.map +1 -0
- package/dist/session/broker.d.ts +189 -0
- package/dist/session/broker.js +507 -0
- package/dist/session/broker.js.map +1 -0
- package/dist/session/broker_remote.d.ts +74 -0
- package/dist/session/broker_remote.js +583 -0
- package/dist/session/broker_remote.js.map +1 -0
- package/dist/session/cwd_lock.d.ts +33 -0
- package/dist/session/cwd_lock.js +126 -0
- package/dist/session/cwd_lock.js.map +1 -0
- package/dist/session/envelope.d.ts +33 -0
- package/dist/session/envelope.js +117 -0
- package/dist/session/envelope.js.map +1 -0
- package/dist/session/global_config.d.ts +33 -0
- package/dist/session/global_config.js +73 -0
- package/dist/session/global_config.js.map +1 -0
- package/dist/session/ipc.d.ts +27 -0
- package/dist/session/ipc.js +22 -0
- package/dist/session/ipc.js.map +1 -0
- package/dist/session/leader_election.d.ts +32 -0
- package/dist/session/leader_election.js +106 -0
- package/dist/session/leader_election.js.map +1 -0
- package/dist/session/local_config.d.ts +55 -0
- package/dist/session/local_config.js +157 -0
- package/dist/session/local_config.js.map +1 -0
- package/dist/session/mesh_node.d.ts +116 -0
- package/dist/session/mesh_node.js +573 -0
- package/dist/session/mesh_node.js.map +1 -0
- package/dist/session/peer.d.ts +139 -0
- package/dist/session/peer.js +451 -0
- package/dist/session/peer.js.map +1 -0
- package/dist/session/peer_inventory.d.ts +13 -0
- package/dist/session/peer_inventory.js +48 -0
- package/dist/session/peer_inventory.js.map +1 -0
- package/dist/session/peer_limits.d.ts +9 -0
- package/dist/session/peer_limits.js +21 -0
- package/dist/session/peer_limits.js.map +1 -0
- package/dist/session/setup_wizard.d.ts +39 -0
- package/dist/session/setup_wizard.js +63 -0
- package/dist/session/setup_wizard.js.map +1 -0
- package/dist/session/tools.d.ts +24 -0
- package/dist/session/tools.js +252 -0
- package/dist/session/tools.js.map +1 -0
- package/dist/session/wizard.d.ts +13 -0
- package/dist/session/wizard.js +20 -0
- package/dist/session/wizard.js.map +1 -0
- package/dist/timeline/history.d.ts +35 -0
- package/dist/timeline/history.js +381 -0
- package/dist/timeline/history.js.map +1 -0
- package/dist/timeline/runtime.d.ts +76 -0
- package/dist/timeline/runtime.js +428 -0
- package/dist/timeline/runtime.js.map +1 -0
- package/dist/timeline/v2_service.d.ts +54 -0
- package/dist/timeline/v2_service.js +351 -0
- package/dist/timeline/v2_service.js.map +1 -0
- package/dist/transport/peer_channel.d.ts +57 -0
- package/dist/transport/peer_channel.js +170 -0
- package/dist/transport/peer_channel.js.map +1 -0
- package/dist/transport/pi_forward_client.d.ts +29 -0
- package/dist/transport/pi_forward_client.js +62 -0
- package/dist/transport/pi_forward_client.js.map +1 -0
- package/dist/transport/relay_client.d.ts +91 -0
- package/dist/transport/relay_client.js +206 -0
- package/dist/transport/relay_client.js.map +1 -0
- package/dist/ui/footer.d.ts +32 -0
- package/dist/ui/footer.js +34 -0
- package/dist/ui/footer.js.map +1 -0
- package/docs/daemon.md +289 -0
- package/package.json +87 -0
- package/service-templates/launchd.plist.template +35 -0
- package/service-templates/systemd.service.template +19 -0
- package/service-templates/task-launcher.vbs.template +10 -0
- package/service-templates/task-scheduler.xml.template +38 -0
- package/skills/agent-network/SKILL.md +310 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const SERVER_TYPES = new Set([
|
|
2
|
+
"pair_ok",
|
|
3
|
+
"pair_error",
|
|
4
|
+
"user_input",
|
|
5
|
+
"queued_message_state",
|
|
6
|
+
"agent_chunk",
|
|
7
|
+
"agent_done",
|
|
8
|
+
"agent_message",
|
|
9
|
+
"tool_request",
|
|
10
|
+
"tool_result",
|
|
11
|
+
"error",
|
|
12
|
+
"cancelled",
|
|
13
|
+
"pong",
|
|
14
|
+
"bye",
|
|
15
|
+
"session_history",
|
|
16
|
+
// Plan/57 — interactive extension prompt (ask_user via pi-ask).
|
|
17
|
+
"extension_ui_request",
|
|
18
|
+
]);
|
|
19
|
+
export class DecodeError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
constructor(code, message) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.name = "DecodeError";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function encodeClient(msg) {
|
|
28
|
+
return JSON.stringify(msg) + "\n";
|
|
29
|
+
}
|
|
30
|
+
export function decodeServer(line) {
|
|
31
|
+
let obj;
|
|
32
|
+
try {
|
|
33
|
+
obj = JSON.parse(line.trim());
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new DecodeError("invalid_message", `not JSON: ${e.message}`);
|
|
37
|
+
}
|
|
38
|
+
if (!obj ||
|
|
39
|
+
typeof obj !== "object" ||
|
|
40
|
+
typeof obj.type !== "string") {
|
|
41
|
+
throw new DecodeError("invalid_message", "missing 'type'");
|
|
42
|
+
}
|
|
43
|
+
const t = obj.type;
|
|
44
|
+
if (!SERVER_TYPES.has(t)) {
|
|
45
|
+
throw new DecodeError("unsupported_type", `unknown type: ${t}`);
|
|
46
|
+
}
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/protocol/codec.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,IAAI,GAAG,CAAwB;IAClD,SAAS;IACT,YAAY;IACZ,YAAY;IACZ,sBAAsB;IACtB,aAAa;IACb,YAAY;IACZ,eAAe;IACf,cAAc;IACd,aAAa;IACb,OAAO;IACP,WAAW;IACX,MAAM;IACN,KAAK;IACL,iBAAiB;IACjB,gEAAgE;IAChE,sBAAsB;CACvB,CAAC,CAAC;AAEH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAElB;IADlB,YACkB,IAA4C,EAC5D,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAwC;QAI5D,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,GAAkB;IAC7C,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,WAAW,CAAC,iBAAiB,EAAE,aAAc,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;IAChF,CAAC;IACD,IACE,CAAC,GAAG;QACJ,OAAO,GAAG,KAAK,QAAQ;QACvB,OAAQ,GAA+B,CAAC,IAAI,KAAK,QAAQ,EACzD,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;IAC7D,CAAC;IACD,MAAM,CAAC,GAAI,GAA+B,CAAC,IAAc,CAAC;IAC1D,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAA0B,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,WAAW,CAAC,kBAAkB,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,GAAoB,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
export type PairErrorCode = "token_expired" | "token_consumed" | "token_unknown" | "internal_error";
|
|
2
|
+
export type StreamingBehavior = "steer";
|
|
3
|
+
export type QueuedMessageItem = {
|
|
4
|
+
id: string;
|
|
5
|
+
text: string;
|
|
6
|
+
editable: boolean;
|
|
7
|
+
created_at: number;
|
|
8
|
+
};
|
|
9
|
+
export type ExtensionUiMethod = "select" | "confirm" | "input" | "editor" | "notify";
|
|
10
|
+
export type AskQuestionWireType = "single" | "multi" | "preview";
|
|
11
|
+
export interface AskOptionWire {
|
|
12
|
+
value: string;
|
|
13
|
+
label: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
/** Preview-pane content (preview questions only). */
|
|
16
|
+
preview?: string;
|
|
17
|
+
/** pi-ask addition: option allows freeform custom entry. */
|
|
18
|
+
freeform?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface AskQuestionWire {
|
|
21
|
+
id: string;
|
|
22
|
+
label: string;
|
|
23
|
+
prompt: string;
|
|
24
|
+
type: AskQuestionWireType;
|
|
25
|
+
required: boolean;
|
|
26
|
+
/** pi-ask addition: type actually presented after live toggle / policy. */
|
|
27
|
+
presentedType?: AskQuestionWireType;
|
|
28
|
+
/** pi-ask addition: type originally requested by the model. */
|
|
29
|
+
requestedType?: AskQuestionWireType;
|
|
30
|
+
options: AskOptionWire[];
|
|
31
|
+
}
|
|
32
|
+
/** Optional pi-ask enrichment on an extension_ui_request — lets the app render
|
|
33
|
+
* the full flow (multi/preview/notes) instead of the degraded SDK select. A
|
|
34
|
+
* flow maps to ONE request carrying every question; the app renders a
|
|
35
|
+
* full-screen modal and submits ONE response with all answers (pi-ask resolves
|
|
36
|
+
* a flow in a single submit). When `ask` is absent the SDK method/options
|
|
37
|
+
* drive rendering (future generic prompts). */
|
|
38
|
+
export interface AskEnrichmentWire {
|
|
39
|
+
flow_id: string;
|
|
40
|
+
tool_call_id: string | null;
|
|
41
|
+
/** pi-ask RemoteAskSource: "tool" | "answer" | "answer:again" | "ask:replay". */
|
|
42
|
+
source: string;
|
|
43
|
+
title: string | null;
|
|
44
|
+
questions: AskQuestionWire[];
|
|
45
|
+
}
|
|
46
|
+
/** pi-ask RemoteAskAnswer — one question's answered parts.
|
|
47
|
+
*
|
|
48
|
+
* CASING EXCEPTION: inside the `ask` envelope the keys mirror pi-ask's own
|
|
49
|
+
* schema VERBATIM (camelCase: `presentedType`, `requestedType`, `customText`,
|
|
50
|
+
* `optionNotes`) so the bridge can forward the response to pi-ask's submit
|
|
51
|
+
* event without a remap pass. The snake_case convention of this protocol
|
|
52
|
+
* applies at the frame level (`flow_id`, `tool_call_id`, `notify_type`). */
|
|
53
|
+
export interface AskAnswerWire {
|
|
54
|
+
values?: string[];
|
|
55
|
+
customText?: string;
|
|
56
|
+
note?: string;
|
|
57
|
+
optionNotes?: Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
/** Optional pi-ask enrichment on an extension_ui_response — carries the
|
|
60
|
+
* structured answer so multi/preview/notes survive the round-trip. */
|
|
61
|
+
export type AskResponseEnrichmentWire = {
|
|
62
|
+
flow_id: string;
|
|
63
|
+
kind: "answer";
|
|
64
|
+
mode?: "submit" | "elaborate";
|
|
65
|
+
answers: Record<string, AskAnswerWire>;
|
|
66
|
+
} | {
|
|
67
|
+
flow_id: string;
|
|
68
|
+
kind: "cancel";
|
|
69
|
+
};
|
|
70
|
+
/** ServerMessage: interactive extension prompt. Mirrors RpcExtensionUIRequest
|
|
71
|
+
* (select/confirm/input/editor/notify). The `ask` envelope is present when the
|
|
72
|
+
* prompt originates from a pi-ask flow, carrying the full question schema. */
|
|
73
|
+
export type ExtensionUiRequestWire = {
|
|
74
|
+
type: "extension_ui_request";
|
|
75
|
+
id: string;
|
|
76
|
+
method: "select";
|
|
77
|
+
title: string;
|
|
78
|
+
options: string[];
|
|
79
|
+
ask?: AskEnrichmentWire;
|
|
80
|
+
} | {
|
|
81
|
+
type: "extension_ui_request";
|
|
82
|
+
id: string;
|
|
83
|
+
method: "confirm";
|
|
84
|
+
title: string;
|
|
85
|
+
message: string;
|
|
86
|
+
ask?: AskEnrichmentWire;
|
|
87
|
+
} | {
|
|
88
|
+
type: "extension_ui_request";
|
|
89
|
+
id: string;
|
|
90
|
+
method: "input";
|
|
91
|
+
title: string;
|
|
92
|
+
placeholder?: string;
|
|
93
|
+
ask?: AskEnrichmentWire;
|
|
94
|
+
} | {
|
|
95
|
+
type: "extension_ui_request";
|
|
96
|
+
id: string;
|
|
97
|
+
method: "editor";
|
|
98
|
+
title: string;
|
|
99
|
+
prefill?: string;
|
|
100
|
+
ask?: AskEnrichmentWire;
|
|
101
|
+
} | {
|
|
102
|
+
type: "extension_ui_request";
|
|
103
|
+
id: string;
|
|
104
|
+
method: "notify";
|
|
105
|
+
message: string;
|
|
106
|
+
notify_type?: "info" | "warning" | "error";
|
|
107
|
+
};
|
|
108
|
+
/** ClientMessage: response to an extension_ui_request. Mirrors
|
|
109
|
+
* RpcExtensionUIResponse (value / confirmed / cancelled). The `ask` envelope
|
|
110
|
+
* carries pi-ask's structured answer when the app rendered the rich flow. */
|
|
111
|
+
export type ExtensionUiResponseWire = {
|
|
112
|
+
type: "extension_ui_response";
|
|
113
|
+
id: string;
|
|
114
|
+
value: string;
|
|
115
|
+
ask?: AskResponseEnrichmentWire;
|
|
116
|
+
} | {
|
|
117
|
+
type: "extension_ui_response";
|
|
118
|
+
id: string;
|
|
119
|
+
confirmed: boolean;
|
|
120
|
+
ask?: AskResponseEnrichmentWire;
|
|
121
|
+
} | {
|
|
122
|
+
type: "extension_ui_response";
|
|
123
|
+
id: string;
|
|
124
|
+
cancelled: true;
|
|
125
|
+
ask?: AskResponseEnrichmentWire;
|
|
126
|
+
} | {
|
|
127
|
+
type: "extension_ui_response";
|
|
128
|
+
id: string;
|
|
129
|
+
ask: AskResponseEnrichmentWire;
|
|
130
|
+
};
|
|
131
|
+
export type ClientMessage = {
|
|
132
|
+
type: "pair_request";
|
|
133
|
+
id: string;
|
|
134
|
+
token: string;
|
|
135
|
+
device_name: string;
|
|
136
|
+
} | {
|
|
137
|
+
type: "user_message";
|
|
138
|
+
id: string;
|
|
139
|
+
text: string;
|
|
140
|
+
images?: WireImage[];
|
|
141
|
+
streaming_behavior?: StreamingBehavior;
|
|
142
|
+
} | {
|
|
143
|
+
type: "queued_message_set";
|
|
144
|
+
id: string;
|
|
145
|
+
text: string;
|
|
146
|
+
} | {
|
|
147
|
+
type: "queued_message_clear";
|
|
148
|
+
id: string;
|
|
149
|
+
target_id?: string;
|
|
150
|
+
} | {
|
|
151
|
+
type: "approve_tool";
|
|
152
|
+
id: string;
|
|
153
|
+
tool_call_id: string;
|
|
154
|
+
decision: "allow" | "deny";
|
|
155
|
+
} | {
|
|
156
|
+
type: "cancel";
|
|
157
|
+
id: string;
|
|
158
|
+
target_id: string;
|
|
159
|
+
} | {
|
|
160
|
+
type: "ping";
|
|
161
|
+
id: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: "session_sync";
|
|
164
|
+
id: string;
|
|
165
|
+
limit?: number;
|
|
166
|
+
} | {
|
|
167
|
+
type: "session_new";
|
|
168
|
+
id: string;
|
|
169
|
+
} | {
|
|
170
|
+
type: "session_compact";
|
|
171
|
+
id: string;
|
|
172
|
+
} | {
|
|
173
|
+
type: "model_set";
|
|
174
|
+
id: string;
|
|
175
|
+
provider: string;
|
|
176
|
+
model_id: string;
|
|
177
|
+
} | {
|
|
178
|
+
type: "thinking_set";
|
|
179
|
+
id: string;
|
|
180
|
+
level: ThinkingLevel;
|
|
181
|
+
} | {
|
|
182
|
+
type: "list_models";
|
|
183
|
+
id: string;
|
|
184
|
+
} | ExtensionUiResponseWire;
|
|
185
|
+
/**
|
|
186
|
+
* Plan/30 — one inline image attachment on a `user_message`. Mirrors the
|
|
187
|
+
* SDK's `ImageContent` ({@link https }) split across the wire: `data` is the
|
|
188
|
+
* base64-encoded (compressed) image bytes, `mime` its content type
|
|
189
|
+
* (e.g. `"image/jpeg"`). The Pi maps `{ data, mime }` → the SDK's
|
|
190
|
+
* `{ type:"image", data, mimeType }` before handing it to the model.
|
|
191
|
+
*/
|
|
192
|
+
export interface WireImage {
|
|
193
|
+
/** Base64-encoded image bytes (compressed app-side). */
|
|
194
|
+
data: string;
|
|
195
|
+
/** MIME type, e.g. `"image/jpeg"`. Maps to the SDK's `mimeType`. */
|
|
196
|
+
mime: string;
|
|
197
|
+
}
|
|
198
|
+
export type Usage = {
|
|
199
|
+
input_tokens: number;
|
|
200
|
+
output_tokens: number;
|
|
201
|
+
};
|
|
202
|
+
export type KnownErrorCode = "tool_approval_required" | "invalid_message" | "unsupported_type" | "too_large" | "rate_limited" | "timeout" | "internal_error";
|
|
203
|
+
export type ErrorCode = KnownErrorCode | (string & {});
|
|
204
|
+
export type SessionHistoryEvent = {
|
|
205
|
+
ts: number;
|
|
206
|
+
type: "user_input";
|
|
207
|
+
id: string;
|
|
208
|
+
text: string;
|
|
209
|
+
images?: WireImage[];
|
|
210
|
+
} | {
|
|
211
|
+
ts: number;
|
|
212
|
+
type: "tool_request";
|
|
213
|
+
tool_call_id: string;
|
|
214
|
+
tool: string;
|
|
215
|
+
args: Record<string, unknown>;
|
|
216
|
+
} | {
|
|
217
|
+
ts: number;
|
|
218
|
+
type: "tool_result";
|
|
219
|
+
tool_call_id: string;
|
|
220
|
+
result?: unknown;
|
|
221
|
+
error?: string;
|
|
222
|
+
} | {
|
|
223
|
+
ts: number;
|
|
224
|
+
type: "agent_message";
|
|
225
|
+
in_reply_to: string;
|
|
226
|
+
text: string;
|
|
227
|
+
usage?: Usage;
|
|
228
|
+
} | {
|
|
229
|
+
ts: number;
|
|
230
|
+
type: "compaction";
|
|
231
|
+
summary: string;
|
|
232
|
+
tokens_before: number;
|
|
233
|
+
};
|
|
234
|
+
export type ServerMessage = {
|
|
235
|
+
type: "pair_ok";
|
|
236
|
+
in_reply_to: string;
|
|
237
|
+
session_name: string;
|
|
238
|
+
session_started_at: number;
|
|
239
|
+
room_id: string;
|
|
240
|
+
/**
|
|
241
|
+
* Plan/27 Wave A: identifies the host coding agent driving this
|
|
242
|
+
* pi-extension instance. `name` is hardcoded to "Pi coding agent"
|
|
243
|
+
* today; future Pi forks (Claude Code, OpenCode) populate their own
|
|
244
|
+
* here. `version` is the pi-extension `package.json` version.
|
|
245
|
+
* Optional in the wire schema so app-side parsing tolerates older
|
|
246
|
+
* Pi builds that predate this field — every new pairing emits both.
|
|
247
|
+
*/
|
|
248
|
+
harness?: {
|
|
249
|
+
name: string;
|
|
250
|
+
version: string;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Plan/27 Wave A: `os.hostname()` of the machine the Pi runs on.
|
|
254
|
+
* App displays it in the device list so the user can distinguish
|
|
255
|
+
* two paired PCs that happen to share a nickname or sit in the
|
|
256
|
+
* same project folder.
|
|
257
|
+
*/
|
|
258
|
+
hostname?: string;
|
|
259
|
+
} | {
|
|
260
|
+
type: "pair_error";
|
|
261
|
+
in_reply_to: string;
|
|
262
|
+
code: PairErrorCode;
|
|
263
|
+
message: string;
|
|
264
|
+
} | {
|
|
265
|
+
type: "user_input";
|
|
266
|
+
id: string;
|
|
267
|
+
text: string;
|
|
268
|
+
streaming_behavior?: StreamingBehavior;
|
|
269
|
+
} | {
|
|
270
|
+
type: "user_message";
|
|
271
|
+
id: string;
|
|
272
|
+
text: string;
|
|
273
|
+
images?: WireImage[];
|
|
274
|
+
streaming_behavior?: StreamingBehavior;
|
|
275
|
+
} | {
|
|
276
|
+
type: "queued_message_state";
|
|
277
|
+
id?: string;
|
|
278
|
+
text?: string;
|
|
279
|
+
items?: QueuedMessageItem[];
|
|
280
|
+
} | {
|
|
281
|
+
type: "steer_consumed";
|
|
282
|
+
id: string;
|
|
283
|
+
} | {
|
|
284
|
+
type: "agent_chunk";
|
|
285
|
+
in_reply_to: string;
|
|
286
|
+
delta: string;
|
|
287
|
+
} | {
|
|
288
|
+
type: "agent_done";
|
|
289
|
+
in_reply_to: string;
|
|
290
|
+
usage?: Usage;
|
|
291
|
+
} | {
|
|
292
|
+
type: "agent_message";
|
|
293
|
+
in_reply_to: string;
|
|
294
|
+
text: string;
|
|
295
|
+
usage?: Usage;
|
|
296
|
+
} | {
|
|
297
|
+
type: "compaction";
|
|
298
|
+
summary: string;
|
|
299
|
+
tokens_before: number;
|
|
300
|
+
ts?: number;
|
|
301
|
+
} | {
|
|
302
|
+
type: "tool_request";
|
|
303
|
+
tool_call_id: string;
|
|
304
|
+
tool: string;
|
|
305
|
+
args: Record<string, unknown>;
|
|
306
|
+
} | {
|
|
307
|
+
type: "tool_result";
|
|
308
|
+
tool_call_id: string;
|
|
309
|
+
result?: unknown;
|
|
310
|
+
error?: string;
|
|
311
|
+
} | {
|
|
312
|
+
type: "error";
|
|
313
|
+
in_reply_to?: string;
|
|
314
|
+
code: ErrorCode;
|
|
315
|
+
message: string;
|
|
316
|
+
} | {
|
|
317
|
+
type: "cancelled";
|
|
318
|
+
in_reply_to: string;
|
|
319
|
+
target_id: string;
|
|
320
|
+
} | {
|
|
321
|
+
type: "pong";
|
|
322
|
+
in_reply_to: string;
|
|
323
|
+
} | {
|
|
324
|
+
type: "bye";
|
|
325
|
+
reason: ByeReason;
|
|
326
|
+
} | {
|
|
327
|
+
type: "session_history";
|
|
328
|
+
in_reply_to: string;
|
|
329
|
+
session_started_at: number;
|
|
330
|
+
events: SessionHistoryEvent[];
|
|
331
|
+
eos: boolean;
|
|
332
|
+
truncated: boolean;
|
|
333
|
+
} | {
|
|
334
|
+
type: "action_ok";
|
|
335
|
+
in_reply_to: string;
|
|
336
|
+
action: ActionName;
|
|
337
|
+
} | {
|
|
338
|
+
type: "action_error";
|
|
339
|
+
in_reply_to: string;
|
|
340
|
+
action: ActionName;
|
|
341
|
+
error: string;
|
|
342
|
+
} | {
|
|
343
|
+
type: "models_list";
|
|
344
|
+
in_reply_to: string;
|
|
345
|
+
models: WireModel[];
|
|
346
|
+
current?: WireModel;
|
|
347
|
+
} | ExtensionUiRequestWire;
|
|
348
|
+
/**
|
|
349
|
+
* Plan/28 — Stable names for the typed actions the app can request. Kept
|
|
350
|
+
* as a closed string union so a switch in either side gets exhaustiveness
|
|
351
|
+
* checking from the compiler.
|
|
352
|
+
*/
|
|
353
|
+
export type ActionName = "session_new" | "session_compact" | "model_set" | "thinking_set";
|
|
354
|
+
/**
|
|
355
|
+
* Plan/28 — Mirror of the SDK's `ThinkingLevel` (defined in
|
|
356
|
+
* `@earendil-works/pi-agent-core/types`). Re-declared locally so the wire
|
|
357
|
+
* protocol owns its own enum and we don't leak SDK-internal types onto
|
|
358
|
+
* the app's network surface.
|
|
359
|
+
*
|
|
360
|
+
* Note: `"xhigh"` is only honored by select model families — the SDK uses
|
|
361
|
+
* each `Model.thinkingLevelMap` to decide if the requested level is
|
|
362
|
+
* supported, falling back to a sensible neighbour when not. The app
|
|
363
|
+
* surfaces all 6 buttons but can grey out unsupported ones using the
|
|
364
|
+
* model's metadata if the picker fetches it later.
|
|
365
|
+
*/
|
|
366
|
+
export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
367
|
+
/**
|
|
368
|
+
* Plan/28 — Wire shape for one model entry in the app's model picker.
|
|
369
|
+
*
|
|
370
|
+
* Subset of the SDK's `Model<Api>` interface — only the fields the app
|
|
371
|
+
* actually renders. Cost / max-tokens / API class are left off the wire
|
|
372
|
+
* deliberately; if the app's picker grows to need them, they get added
|
|
373
|
+
* here and to the handler's mapping in `index.ts` in one diff.
|
|
374
|
+
*/
|
|
375
|
+
export interface WireModel {
|
|
376
|
+
/** Stable identifier inside the provider's catalog. E.g. `"claude-opus-4-7"`. */
|
|
377
|
+
id: string;
|
|
378
|
+
/** Display name for the picker row. E.g. `"Claude Opus 4.7"`. */
|
|
379
|
+
name: string;
|
|
380
|
+
/** Provider slug. E.g. `"anthropic"`, `"openai"`. */
|
|
381
|
+
provider: string;
|
|
382
|
+
/** Whether the model supports the thinking surface (`reasoning: true`
|
|
383
|
+
* in the SDK). Useful so the app can decide whether the thinking
|
|
384
|
+
* segmented control should be enabled when this model is selected. */
|
|
385
|
+
reasoning: boolean;
|
|
386
|
+
/** Context window in tokens, for display in the picker subtitle. */
|
|
387
|
+
context_window: number;
|
|
388
|
+
/** Plan/30: true when the model accepts image input (SDK `Model.input`
|
|
389
|
+
* includes `"image"`). The app uses it to enable/disable the attach
|
|
390
|
+
* button — a text-only model greys out image attachments. */
|
|
391
|
+
vision: boolean;
|
|
392
|
+
}
|
|
393
|
+
export type ByeReason = "peer_stop" | "session_replaced" | "shutdown";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/protocol/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ClientFrame, JsonValue, MarkerV2, ServerFrame, TimelineEvent, TimelinePartial } from "./schemas.js";
|
|
2
|
+
export type DecodeErrorCode = "invalid" | "unsupported" | "version" | "schema" | "size" | "direction";
|
|
3
|
+
export declare class DecodeError extends Error {
|
|
4
|
+
readonly code: DecodeErrorCode;
|
|
5
|
+
readonly name = "DecodeError";
|
|
6
|
+
constructor(code: DecodeErrorCode, message: string, options?: {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export declare function getUtf8ByteLengthV2(value: unknown): number;
|
|
11
|
+
export declare function decodeClientFrameV2(raw: unknown): ClientFrame;
|
|
12
|
+
export declare function decodeServerFrameV2(raw: unknown): ServerFrame;
|
|
13
|
+
export declare function encodeClientFrameV2(frame: ClientFrame): string;
|
|
14
|
+
export declare function encodeServerFrameV2(frame: ServerFrame): string;
|
|
15
|
+
export declare function validateFragmentSizeV2(fragment: unknown): number;
|
|
16
|
+
export declare function validateHistoryChunkSizeV2(chunk: unknown): number;
|
|
17
|
+
export declare function validateWindowSizeV2(events: readonly unknown[]): number;
|
|
18
|
+
export declare function validateEncodedSizeV2(value: unknown, maxBytes?: number): number;
|
|
19
|
+
export declare function parseTimelineEventV2(raw: unknown): TimelineEvent;
|
|
20
|
+
export declare function parseTimelinePartialV2(raw: unknown): TimelinePartial;
|
|
21
|
+
export declare function parseMarkerV2(raw: unknown): MarkerV2;
|
|
22
|
+
export { HistoryFragmentSchema, TimelineEventFragmentSchema, SessionHistoryChunkSchema } from "./schemas.js";
|
|
23
|
+
export declare const validateTimelineEventFragmentV2: typeof validateFragmentSizeV2;
|
|
24
|
+
export declare const validateSessionHistoryChunkV2: typeof validateHistoryChunkSizeV2;
|
|
25
|
+
export declare const validateTimelineWindowV2: typeof validateWindowSizeV2;
|
|
26
|
+
export type JsonValueV2 = JsonValue;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { ClientFrameSchema, ClientFrameTypes, MAX_FRAME_BYTES, MAX_FRAGMENT_DECODE_BYTES, MAX_HISTORY_CHUNK_BYTES, MAX_WINDOW_DECODE_BYTES, MarkerSchemaV2, ServerFrameSchema, ServerFrameTypes, HistoryFragmentSchema, SessionHistoryChunkSchema, TimelineEventFragmentSchema, TimelineEventSchema, TimelinePartialSchema, } from "./schemas.js";
|
|
2
|
+
export class DecodeError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
name = "DecodeError";
|
|
5
|
+
constructor(code, message, options) {
|
|
6
|
+
super(message, options);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const textEncoder = new TextEncoder();
|
|
11
|
+
const textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function byteLength(value) {
|
|
16
|
+
return textEncoder.encode(value).byteLength;
|
|
17
|
+
}
|
|
18
|
+
export function getUtf8ByteLengthV2(value) {
|
|
19
|
+
try {
|
|
20
|
+
const encoded = JSON.stringify(value);
|
|
21
|
+
if (encoded === undefined)
|
|
22
|
+
throw new Error("value is not JSON serializable");
|
|
23
|
+
return byteLength(encoded);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new DecodeError("invalid", "value is not JSON serializable", { cause: error });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function parseRaw(raw, maxBytes = MAX_WINDOW_DECODE_BYTES) {
|
|
30
|
+
if (typeof raw === "string") {
|
|
31
|
+
const bytes = byteLength(raw);
|
|
32
|
+
if (bytes > maxBytes) {
|
|
33
|
+
throw new DecodeError("size", `raw value exceeds ${maxBytes} bytes`);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return { value: JSON.parse(raw), bytes };
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new DecodeError("invalid", "raw string is not valid JSON", { cause: error });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (raw instanceof Uint8Array) {
|
|
43
|
+
if (raw.byteLength > maxBytes) {
|
|
44
|
+
throw new DecodeError("size", `raw value exceeds ${maxBytes} bytes`);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return { value: JSON.parse(textDecoder.decode(raw)), bytes: raw.byteLength };
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw new DecodeError("invalid", "raw bytes are not valid UTF-8 JSON", { cause: error });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (isRecord(raw)) {
|
|
54
|
+
const bytes = getUtf8ByteLengthV2(raw);
|
|
55
|
+
if (bytes > maxBytes) {
|
|
56
|
+
throw new DecodeError("size", `raw value exceeds ${maxBytes} bytes`);
|
|
57
|
+
}
|
|
58
|
+
return { value: raw, bytes };
|
|
59
|
+
}
|
|
60
|
+
throw new DecodeError("invalid", "raw frame must be an object, JSON string, or Uint8Array");
|
|
61
|
+
}
|
|
62
|
+
function schemaMessage(error) {
|
|
63
|
+
return error.issues.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`).join("; ");
|
|
64
|
+
}
|
|
65
|
+
function checkProtocolVersion(value) {
|
|
66
|
+
if (value.protocol_version !== 2) {
|
|
67
|
+
throw new DecodeError("version", "protocol_version must be 2");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function checkFrameBytes(value, bytes) {
|
|
71
|
+
if (bytes > MAX_FRAME_BYTES) {
|
|
72
|
+
throw new DecodeError("size", `${String(value.type)} exceeds ${MAX_FRAME_BYTES} encoded UTF-8 bytes`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function parseFrame(raw, direction) {
|
|
76
|
+
const { value, bytes } = parseRaw(raw, MAX_FRAME_BYTES);
|
|
77
|
+
if (!isRecord(value) || typeof value.type !== "string") {
|
|
78
|
+
throw new DecodeError("invalid", "frame must contain a string type");
|
|
79
|
+
}
|
|
80
|
+
const clientKnown = ClientFrameTypes.has(value.type);
|
|
81
|
+
const serverKnown = ServerFrameTypes.has(value.type);
|
|
82
|
+
if (!clientKnown && !serverKnown)
|
|
83
|
+
throw new DecodeError("unsupported", `unknown frame type: ${value.type}`);
|
|
84
|
+
if (direction === "client" && !clientKnown)
|
|
85
|
+
throw new DecodeError("direction", `${value.type} is a server frame`);
|
|
86
|
+
if (direction === "server" && !serverKnown)
|
|
87
|
+
throw new DecodeError("direction", `${value.type} is a client frame`);
|
|
88
|
+
checkProtocolVersion(value);
|
|
89
|
+
const result = direction === "client" ? ClientFrameSchema.safeParse(value) : ServerFrameSchema.safeParse(value);
|
|
90
|
+
if (!result.success)
|
|
91
|
+
throw new DecodeError("schema", schemaMessage(result.error), { cause: result.error });
|
|
92
|
+
checkFrameBytes(value, bytes);
|
|
93
|
+
if (value.type === "timeline_event_fragment")
|
|
94
|
+
validateFragmentSizeV2(value);
|
|
95
|
+
if (value.type === "session_history_chunk")
|
|
96
|
+
validateHistoryChunkSizeV2(value);
|
|
97
|
+
return result.data;
|
|
98
|
+
}
|
|
99
|
+
export function decodeClientFrameV2(raw) {
|
|
100
|
+
return parseFrame(raw, "client");
|
|
101
|
+
}
|
|
102
|
+
export function decodeServerFrameV2(raw) {
|
|
103
|
+
return parseFrame(raw, "server");
|
|
104
|
+
}
|
|
105
|
+
function encodeFrame(frame, direction) {
|
|
106
|
+
const parsed = parseFrame(frame, direction);
|
|
107
|
+
const encoded = JSON.stringify(parsed);
|
|
108
|
+
if (encoded === undefined)
|
|
109
|
+
throw new DecodeError("invalid", "frame is not JSON serializable");
|
|
110
|
+
return encoded;
|
|
111
|
+
}
|
|
112
|
+
export function encodeClientFrameV2(frame) {
|
|
113
|
+
return encodeFrame(frame, "client");
|
|
114
|
+
}
|
|
115
|
+
export function encodeServerFrameV2(frame) {
|
|
116
|
+
return encodeFrame(frame, "server");
|
|
117
|
+
}
|
|
118
|
+
function decodeBase64Bytes(value) {
|
|
119
|
+
try {
|
|
120
|
+
return Uint8Array.from(Buffer.from(value, "base64"));
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
throw new DecodeError("schema", "data_base64 is not valid base64", { cause: error });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function validateFragmentSizeV2(fragment) {
|
|
127
|
+
const realtimeResult = TimelineEventFragmentSchema.safeParse(fragment);
|
|
128
|
+
const historyResult = HistoryFragmentSchema.safeParse(fragment);
|
|
129
|
+
if (!realtimeResult.success && !historyResult.success) {
|
|
130
|
+
throw new DecodeError("schema", schemaMessage(realtimeResult.error), { cause: realtimeResult.error });
|
|
131
|
+
}
|
|
132
|
+
const dataBase64 = realtimeResult.success
|
|
133
|
+
? realtimeResult.data.data_base64
|
|
134
|
+
: historyResult.success
|
|
135
|
+
? historyResult.data.data_base64
|
|
136
|
+
: undefined;
|
|
137
|
+
if (dataBase64 === undefined)
|
|
138
|
+
throw new DecodeError("schema", "fragment data is missing");
|
|
139
|
+
const bytes = decodeBase64Bytes(dataBase64).byteLength;
|
|
140
|
+
if (bytes > MAX_FRAGMENT_DECODE_BYTES) {
|
|
141
|
+
throw new DecodeError("size", `fragment exceeds ${MAX_FRAGMENT_DECODE_BYTES} decoded bytes`);
|
|
142
|
+
}
|
|
143
|
+
return bytes;
|
|
144
|
+
}
|
|
145
|
+
export function validateHistoryChunkSizeV2(chunk) {
|
|
146
|
+
const result = SessionHistoryChunkSchema.safeParse(chunk);
|
|
147
|
+
if (!result.success)
|
|
148
|
+
throw new DecodeError("schema", schemaMessage(result.error), { cause: result.error });
|
|
149
|
+
const parsed = result.data;
|
|
150
|
+
const bytes = getUtf8ByteLengthV2(parsed);
|
|
151
|
+
if (bytes > MAX_HISTORY_CHUNK_BYTES) {
|
|
152
|
+
throw new DecodeError("size", `history chunk exceeds ${MAX_HISTORY_CHUNK_BYTES} encoded UTF-8 bytes`);
|
|
153
|
+
}
|
|
154
|
+
for (const fragment of parsed.fragments)
|
|
155
|
+
validateFragmentSizeV2(fragment);
|
|
156
|
+
return bytes;
|
|
157
|
+
}
|
|
158
|
+
export function validateWindowSizeV2(events) {
|
|
159
|
+
let total = 0;
|
|
160
|
+
for (const event of events) {
|
|
161
|
+
const result = TimelineEventSchema.safeParse(event);
|
|
162
|
+
if (!result.success)
|
|
163
|
+
throw new DecodeError("schema", schemaMessage(result.error), { cause: result.error });
|
|
164
|
+
total += getUtf8ByteLengthV2(result.data);
|
|
165
|
+
if (total > MAX_WINDOW_DECODE_BYTES) {
|
|
166
|
+
throw new DecodeError("size", `decoded window exceeds ${MAX_WINDOW_DECODE_BYTES} bytes`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return total;
|
|
170
|
+
}
|
|
171
|
+
export function validateEncodedSizeV2(value, maxBytes = MAX_WINDOW_DECODE_BYTES) {
|
|
172
|
+
const bytes = getUtf8ByteLengthV2(value);
|
|
173
|
+
if (bytes > maxBytes)
|
|
174
|
+
throw new DecodeError("size", `encoded value exceeds ${maxBytes} bytes`);
|
|
175
|
+
return bytes;
|
|
176
|
+
}
|
|
177
|
+
export function parseTimelineEventV2(raw) {
|
|
178
|
+
const { value } = parseRaw(raw);
|
|
179
|
+
const result = TimelineEventSchema.safeParse(value);
|
|
180
|
+
if (!result.success)
|
|
181
|
+
throw new DecodeError("schema", schemaMessage(result.error), { cause: result.error });
|
|
182
|
+
const event = result.data;
|
|
183
|
+
validateEncodedSizeV2(event, MAX_WINDOW_DECODE_BYTES);
|
|
184
|
+
return event;
|
|
185
|
+
}
|
|
186
|
+
export function parseTimelinePartialV2(raw) {
|
|
187
|
+
const { value } = parseRaw(raw);
|
|
188
|
+
const result = TimelinePartialSchema.safeParse(value);
|
|
189
|
+
if (!result.success)
|
|
190
|
+
throw new DecodeError("schema", schemaMessage(result.error), { cause: result.error });
|
|
191
|
+
validateEncodedSizeV2(result.data, MAX_HISTORY_CHUNK_BYTES);
|
|
192
|
+
return result.data;
|
|
193
|
+
}
|
|
194
|
+
export function parseMarkerV2(raw) {
|
|
195
|
+
const { value } = parseRaw(raw);
|
|
196
|
+
const result = MarkerSchemaV2.safeParse(value);
|
|
197
|
+
if (!result.success)
|
|
198
|
+
throw new DecodeError("schema", schemaMessage(result.error), { cause: result.error });
|
|
199
|
+
validateEncodedSizeV2(result.data, MAX_FRAGMENT_DECODE_BYTES);
|
|
200
|
+
return result.data;
|
|
201
|
+
}
|
|
202
|
+
// These aliases keep validation available without exposing scanner or production wiring.
|
|
203
|
+
export { HistoryFragmentSchema, TimelineEventFragmentSchema, SessionHistoryChunkSchema } from "./schemas.js";
|
|
204
|
+
export const validateTimelineEventFragmentV2 = validateFragmentSizeV2;
|
|
205
|
+
export const validateSessionHistoryChunkV2 = validateHistoryChunkSizeV2;
|
|
206
|
+
export const validateTimelineWindowV2 = validateWindowSizeV2;
|
|
207
|
+
//# sourceMappingURL=codec.js.map
|