@yefengr/pi-reach 0.0.0-stage → 0.0.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/LICENSE +22 -0
- package/README.md +110 -2
- package/dist/actions/handlers.d.ts +143 -0
- package/dist/actions/handlers.js +200 -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/actions/session_new_bridge.d.ts +35 -0
- package/dist/actions/session_new_bridge.js +88 -0
- package/dist/actions/session_new_bridge.js.map +1 -0
- package/dist/commands.d.ts +29 -0
- package/dist/commands.js +169 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +61 -0
- package/dist/config.js +115 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +618 -0
- package/dist/index.js.map +1 -0
- package/dist/pairing/crypto.d.ts +15 -0
- package/dist/pairing/crypto.js +72 -0
- package/dist/pairing/crypto.js.map +1 -0
- package/dist/pairing/identity-keyring.d.ts +22 -0
- package/dist/pairing/identity-keyring.js +94 -0
- package/dist/pairing/identity-keyring.js.map +1 -0
- package/dist/pairing/identity-lock.d.ts +14 -0
- package/dist/pairing/identity-lock.js +116 -0
- package/dist/pairing/identity-lock.js.map +1 -0
- package/dist/pairing/owner_storage.d.ts +61 -0
- package/dist/pairing/owner_storage.js +263 -0
- package/dist/pairing/owner_storage.js.map +1 -0
- package/dist/pairing/qr.d.ts +39 -0
- package/dist/pairing/qr.js +113 -0
- package/dist/pairing/qr.js.map +1 -0
- package/dist/pairing/storage.d.ts +36 -0
- package/dist/pairing/storage.js +263 -0
- package/dist/pairing/storage.js.map +1 -0
- package/dist/protocol/types.d.ts +225 -0
- package/dist/protocol/types.js +2 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/protocol/v2/codec.d.ts +6 -0
- package/dist/protocol/v2/codec.js +4 -0
- package/dist/protocol/v2/codec.js.map +1 -0
- package/dist/protocol/v2/index.d.ts +4 -0
- package/dist/protocol/v2/index.js +5 -0
- package/dist/protocol/v2/index.js.map +1 -0
- package/dist/protocol/v2/marker.d.ts +45 -0
- package/dist/protocol/v2/marker.js +47 -0
- package/dist/protocol/v2/marker.js.map +1 -0
- package/dist/protocol/v2/schemas.d.ts +3 -0
- package/dist/protocol/v2/schemas.js +4 -0
- package/dist/protocol/v2/schemas.js.map +1 -0
- package/dist/protocol/v2/session_state.d.ts +79 -0
- package/dist/protocol/v2/session_state.js +166 -0
- package/dist/protocol/v2/session_state.js.map +1 -0
- package/dist/runtime/endpoint_metadata.d.ts +14 -0
- package/dist/runtime/endpoint_metadata.js +18 -0
- package/dist/runtime/endpoint_metadata.js.map +1 -0
- package/dist/runtime/extension_owner.d.ts +12 -0
- package/dist/runtime/extension_owner.js +80 -0
- package/dist/runtime/extension_owner.js.map +1 -0
- package/dist/runtime/footer.d.ts +6 -0
- package/dist/runtime/footer.js +21 -0
- package/dist/runtime/footer.js.map +1 -0
- package/dist/runtime/owner_router.d.ts +16 -0
- package/dist/runtime/owner_router.js +41 -0
- package/dist/runtime/owner_router.js.map +1 -0
- package/dist/runtime/pairing_coordinator.d.ts +42 -0
- package/dist/runtime/pairing_coordinator.js +136 -0
- package/dist/runtime/pairing_coordinator.js.map +1 -0
- package/dist/runtime/relay_lifecycle.d.ts +64 -0
- package/dist/runtime/relay_lifecycle.js +275 -0
- package/dist/runtime/relay_lifecycle.js.map +1 -0
- package/dist/session/local_config.d.ts +7 -0
- package/dist/session/local_config.js +52 -0
- package/dist/session/local_config.js.map +1 -0
- package/dist/timeline/history.d.ts +30 -0
- package/dist/timeline/history.js +170 -0
- package/dist/timeline/history.js.map +1 -0
- package/dist/timeline/partial_delta.d.ts +2 -0
- package/dist/timeline/partial_delta.js +16 -0
- package/dist/timeline/partial_delta.js.map +1 -0
- package/dist/timeline/run_end.d.ts +16 -0
- package/dist/timeline/run_end.js +23 -0
- package/dist/timeline/run_end.js.map +1 -0
- package/dist/timeline/runtime.d.ts +89 -0
- package/dist/timeline/runtime.js +546 -0
- package/dist/timeline/runtime.js.map +1 -0
- package/dist/timeline/sequence.d.ts +7 -0
- package/dist/timeline/sequence.js +16 -0
- package/dist/timeline/sequence.js.map +1 -0
- package/dist/timeline/tool_lifecycle.d.ts +36 -0
- package/dist/timeline/tool_lifecycle.js +171 -0
- package/dist/timeline/tool_lifecycle.js.map +1 -0
- package/dist/timeline/user_delivery.d.ts +96 -0
- package/dist/timeline/user_delivery.js +360 -0
- package/dist/timeline/user_delivery.js.map +1 -0
- package/dist/timeline/user_delivery_binding.d.ts +43 -0
- package/dist/timeline/user_delivery_binding.js +107 -0
- package/dist/timeline/user_delivery_binding.js.map +1 -0
- package/dist/timeline/v2_service.d.ts +82 -0
- package/dist/timeline/v2_service.js +512 -0
- package/dist/timeline/v2_service.js.map +1 -0
- package/dist/transport/peer_channel.d.ts +34 -0
- package/dist/transport/peer_channel.js +116 -0
- package/dist/transport/peer_channel.js.map +1 -0
- package/dist/transport/relay_client.d.ts +54 -0
- package/dist/transport/relay_client.js +270 -0
- package/dist/transport/relay_client.js.map +1 -0
- package/dist/vendor/protocol/constants.d.ts +4 -0
- package/dist/vendor/protocol/constants.js +4 -0
- package/dist/vendor/protocol/encoding.d.ts +9 -0
- package/dist/vendor/protocol/encoding.js +66 -0
- package/dist/vendor/protocol/outer/codec.d.ts +13 -0
- package/dist/vendor/protocol/outer/codec.js +105 -0
- package/dist/vendor/protocol/outer/index.d.ts +4 -0
- package/dist/vendor/protocol/outer/index.js +4 -0
- package/dist/vendor/protocol/outer/types.d.ts +120 -0
- package/dist/vendor/protocol/outer/types.js +1 -0
- package/dist/vendor/protocol/session/codec.d.ts +41 -0
- package/dist/vendor/protocol/session/codec.js +236 -0
- package/dist/vendor/protocol/session/frames.d.ts +5220 -0
- package/dist/vendor/protocol/session/frames.js +83 -0
- package/dist/vendor/protocol/session/index.d.ts +3 -0
- package/dist/vendor/protocol/session/index.js +3 -0
- package/dist/vendor/protocol/session/schema.d.ts +858 -0
- package/dist/vendor/protocol/session/schema.js +256 -0
- package/package.json +74 -3
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { TimelineEventSchema, V2SessionState, MAX_FRAME_BYTES, MAX_FRAGMENT_DECODE_BYTES, } from "../protocol/v2/index.js";
|
|
3
|
+
import { TimelineHistoryPager } from "./history.js";
|
|
4
|
+
export class TimelineV2Service {
|
|
5
|
+
state;
|
|
6
|
+
pager;
|
|
7
|
+
sessionManager;
|
|
8
|
+
senderRef;
|
|
9
|
+
runtime;
|
|
10
|
+
onUserMessage;
|
|
11
|
+
onCancel;
|
|
12
|
+
onAction;
|
|
13
|
+
onQueueSnapshot;
|
|
14
|
+
onQueuedMessageClear;
|
|
15
|
+
onQueuedMessageSteer;
|
|
16
|
+
onListModels;
|
|
17
|
+
requestChannels = new Map();
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.sessionManager = options.sessionManager;
|
|
20
|
+
this.senderRef = options.senderRef;
|
|
21
|
+
this.state = new V2SessionState({ sessionId: options.sessionManager.getSessionId(), leafId: options.sessionManager.getLeafId() ?? null });
|
|
22
|
+
this.runtime = options.runtime;
|
|
23
|
+
this.onUserMessage = options.onUserMessage;
|
|
24
|
+
this.onCancel = options.onCancel;
|
|
25
|
+
this.onAction = options.onAction;
|
|
26
|
+
this.onQueueSnapshot = options.onQueueSnapshot;
|
|
27
|
+
this.onQueuedMessageClear = options.onQueuedMessageClear;
|
|
28
|
+
this.onQueuedMessageSteer = options.onQueuedMessageSteer;
|
|
29
|
+
this.onListModels = options.onListModels;
|
|
30
|
+
this.pager = new TimelineHistoryPager(this.sessionManager, (manager) => this.runtime.recover(manager));
|
|
31
|
+
}
|
|
32
|
+
get sessionId() {
|
|
33
|
+
return this.sessionManager.getSessionId();
|
|
34
|
+
}
|
|
35
|
+
get leafId() {
|
|
36
|
+
return this.sessionManager.getLeafId() ?? null;
|
|
37
|
+
}
|
|
38
|
+
canQueueItem(item) {
|
|
39
|
+
// 为非最终分块与后续 chunk_index 预留序列化空间。
|
|
40
|
+
return this.frameBytes(this.queueFrame(randomUUID(), Number.MAX_SAFE_INTEGER, false, [item])) <= MAX_FRAME_BYTES;
|
|
41
|
+
}
|
|
42
|
+
queueSnapshot(items) {
|
|
43
|
+
const snapshotId = randomUUID();
|
|
44
|
+
if (items.length === 0)
|
|
45
|
+
return [this.queueFrame(snapshotId, 0, true, [])];
|
|
46
|
+
const frames = [];
|
|
47
|
+
let chunk = [];
|
|
48
|
+
for (const item of items) {
|
|
49
|
+
const candidate = [...chunk, item];
|
|
50
|
+
if (this.frameBytes(this.queueFrame(snapshotId, frames.length, false, candidate)) <= MAX_FRAME_BYTES) {
|
|
51
|
+
chunk = candidate;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (chunk.length === 0)
|
|
55
|
+
throw new Error("queued message item exceeds the frame limit");
|
|
56
|
+
frames.push(this.queueFrame(snapshotId, frames.length, false, chunk));
|
|
57
|
+
chunk = [item];
|
|
58
|
+
}
|
|
59
|
+
const final = this.queueFrame(snapshotId, frames.length, true, chunk);
|
|
60
|
+
if (this.frameBytes(final) > MAX_FRAME_BYTES)
|
|
61
|
+
throw new Error("queued message item exceeds the frame limit");
|
|
62
|
+
frames.push(final);
|
|
63
|
+
return frames;
|
|
64
|
+
}
|
|
65
|
+
reset(reason) {
|
|
66
|
+
return this.state.snapshot().channels.map((channel) => ({
|
|
67
|
+
protocol_version: 2,
|
|
68
|
+
type: "reset",
|
|
69
|
+
target_channel_id: channel.channelId,
|
|
70
|
+
session_id: this.sessionId,
|
|
71
|
+
leaf_id: this.leafId,
|
|
72
|
+
reason,
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
refreshScope() {
|
|
76
|
+
const sessionId = this.sessionId;
|
|
77
|
+
const leafId = this.leafId;
|
|
78
|
+
if (sessionId === this.state.sessionId && leafId === this.state.leafId)
|
|
79
|
+
return false;
|
|
80
|
+
this.state.setScope(sessionId, leafId);
|
|
81
|
+
this.requestChannels.clear();
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
handle(frame) {
|
|
85
|
+
switch (frame.type) {
|
|
86
|
+
case "session_hello":
|
|
87
|
+
return [this.ready(frame), ...this.currentQueueSnapshot()];
|
|
88
|
+
case "pair_request":
|
|
89
|
+
return [this.error(frame.id, "protocol_upgrade_required", "pairing is handled before session_hello")];
|
|
90
|
+
case "session_sync":
|
|
91
|
+
return this.handleHistory(frame);
|
|
92
|
+
case "ping":
|
|
93
|
+
return this.handlePing(frame);
|
|
94
|
+
case "cancel":
|
|
95
|
+
return this.handleCancel(frame);
|
|
96
|
+
case "user_message":
|
|
97
|
+
return this.handleUserMessage(frame);
|
|
98
|
+
case "user_message_observed":
|
|
99
|
+
return this.handleObserved(frame);
|
|
100
|
+
case "session_new":
|
|
101
|
+
case "session_compact":
|
|
102
|
+
case "model_set":
|
|
103
|
+
case "thinking_set":
|
|
104
|
+
return this.handleAction(frame);
|
|
105
|
+
case "queued_message_set":
|
|
106
|
+
case "approve_tool":
|
|
107
|
+
return this.requireReady(frame);
|
|
108
|
+
case "list_models":
|
|
109
|
+
return this.handleListModels(frame);
|
|
110
|
+
case "queued_message_clear":
|
|
111
|
+
return this.handleQueuedMessageClear(frame);
|
|
112
|
+
case "queued_message_steer":
|
|
113
|
+
return this.handleQueuedMessageSteer(frame);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
started(started) {
|
|
117
|
+
const clientRequestId = started.correlation.clientRequestId;
|
|
118
|
+
if (!clientRequestId)
|
|
119
|
+
return [];
|
|
120
|
+
const request = this.findRecord(clientRequestId);
|
|
121
|
+
if (!request)
|
|
122
|
+
return [];
|
|
123
|
+
this.state.update(request.key, "accepted", { messageId: started.eventId, groupId: started.groupId });
|
|
124
|
+
const message = {
|
|
125
|
+
id: started.eventId,
|
|
126
|
+
group_id: started.groupId,
|
|
127
|
+
blocks: started.blocks,
|
|
128
|
+
origin: started.correlation.origin,
|
|
129
|
+
...(started.correlation.senderRef ? { sender_ref: started.correlation.senderRef } : {}),
|
|
130
|
+
delivery: started.correlation.delivery,
|
|
131
|
+
};
|
|
132
|
+
return [
|
|
133
|
+
...this.direct(request.channelId, {
|
|
134
|
+
type: "user_message_status",
|
|
135
|
+
in_reply_to: started.correlation.requestId ?? clientRequestId,
|
|
136
|
+
session_id: this.sessionId,
|
|
137
|
+
leaf_id: this.leafId,
|
|
138
|
+
client_request_id: clientRequestId,
|
|
139
|
+
status: "accepted",
|
|
140
|
+
message_id: started.eventId,
|
|
141
|
+
group_id: started.groupId,
|
|
142
|
+
}),
|
|
143
|
+
...this.direct(request.channelId, {
|
|
144
|
+
type: "user_message_started",
|
|
145
|
+
in_reply_to: started.correlation.requestId ?? clientRequestId,
|
|
146
|
+
session_id: this.sessionId,
|
|
147
|
+
leaf_id: this.leafId,
|
|
148
|
+
message,
|
|
149
|
+
}),
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
commit(clientRequestId, messageId, groupId) {
|
|
153
|
+
const request = this.findRecord(clientRequestId);
|
|
154
|
+
if (!request)
|
|
155
|
+
return [];
|
|
156
|
+
const record = this.state.update(request.key, "committed", { messageId, groupId });
|
|
157
|
+
if (!record)
|
|
158
|
+
return [];
|
|
159
|
+
return this.direct(request.channelId, {
|
|
160
|
+
type: "user_message_status",
|
|
161
|
+
in_reply_to: clientRequestId,
|
|
162
|
+
session_id: this.sessionId,
|
|
163
|
+
leaf_id: this.leafId,
|
|
164
|
+
client_request_id: clientRequestId,
|
|
165
|
+
status: "committed",
|
|
166
|
+
message_id: messageId,
|
|
167
|
+
...(groupId ? { group_id: groupId } : {}),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
canDrain(clientRequestId) {
|
|
171
|
+
const status = this.findRecord(clientRequestId)?.status;
|
|
172
|
+
return status === "received" || status === "queued";
|
|
173
|
+
}
|
|
174
|
+
unknownDelivery(clientRequestId) {
|
|
175
|
+
const request = this.findRecord(clientRequestId);
|
|
176
|
+
if (!request)
|
|
177
|
+
return [];
|
|
178
|
+
const updated = this.state.rememberUnknownDelivery(request.key);
|
|
179
|
+
if (!updated)
|
|
180
|
+
return [];
|
|
181
|
+
return this.direct(request.channelId, {
|
|
182
|
+
type: "user_message_status",
|
|
183
|
+
in_reply_to: clientRequestId,
|
|
184
|
+
session_id: this.sessionId,
|
|
185
|
+
leaf_id: this.leafId,
|
|
186
|
+
client_request_id: clientRequestId,
|
|
187
|
+
status: "unknown_delivery",
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
partial(partial) {
|
|
191
|
+
if (partial.session_id !== this.sessionId || partial.leaf_id !== this.leafId)
|
|
192
|
+
return null;
|
|
193
|
+
return partial;
|
|
194
|
+
}
|
|
195
|
+
publish(event) {
|
|
196
|
+
return this.publishFrames(event)[0] ?? null;
|
|
197
|
+
}
|
|
198
|
+
publishFrames(event) {
|
|
199
|
+
const parsed = TimelineEventSchema.safeParse(event);
|
|
200
|
+
if (!parsed.success || parsed.data.event_seq === undefined || parsed.data.session_id !== this.sessionId || parsed.data.leaf_id !== this.leafId)
|
|
201
|
+
return [];
|
|
202
|
+
const complete = {
|
|
203
|
+
protocol_version: 2,
|
|
204
|
+
type: "timeline_event",
|
|
205
|
+
session_id: this.sessionId,
|
|
206
|
+
leaf_id: this.leafId,
|
|
207
|
+
event: parsed.data,
|
|
208
|
+
};
|
|
209
|
+
if (new TextEncoder().encode(JSON.stringify(complete)).byteLength <= MAX_FRAME_BYTES)
|
|
210
|
+
return [complete];
|
|
211
|
+
const bytes = new TextEncoder().encode(JSON.stringify(parsed.data));
|
|
212
|
+
const frames = [];
|
|
213
|
+
for (let offset = 0, index = 0; offset < bytes.byteLength; offset += MAX_FRAGMENT_DECODE_BYTES, index += 1) {
|
|
214
|
+
const slice = bytes.slice(offset, offset + MAX_FRAGMENT_DECODE_BYTES);
|
|
215
|
+
frames.push({
|
|
216
|
+
protocol_version: 2,
|
|
217
|
+
type: "timeline_event_fragment",
|
|
218
|
+
session_id: this.sessionId,
|
|
219
|
+
leaf_id: this.leafId,
|
|
220
|
+
event_id: parsed.data.event_id,
|
|
221
|
+
index,
|
|
222
|
+
data_base64: Buffer.from(slice).toString("base64"),
|
|
223
|
+
final: offset + slice.byteLength >= bytes.byteLength,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return frames;
|
|
227
|
+
}
|
|
228
|
+
ready(frame) {
|
|
229
|
+
this.state.hello(this.senderRef, frame.channel_id);
|
|
230
|
+
const headSeq = this.runtime.recover(this.sessionManager).at(-1)?.event_seq ?? 0;
|
|
231
|
+
return {
|
|
232
|
+
protocol_version: 2,
|
|
233
|
+
type: "session_ready",
|
|
234
|
+
in_reply_to: frame.id,
|
|
235
|
+
target_channel_id: frame.channel_id,
|
|
236
|
+
session_id: this.sessionId,
|
|
237
|
+
leaf_id: this.leafId,
|
|
238
|
+
self_sender_ref: this.senderRef,
|
|
239
|
+
head_seq: headSeq,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
handleHistory(frame) {
|
|
243
|
+
const error = this.ensureReady(frame);
|
|
244
|
+
if (error)
|
|
245
|
+
return [error];
|
|
246
|
+
return this.pager.sync({
|
|
247
|
+
requestId: frame.id,
|
|
248
|
+
targetChannelId: frame.channel_id,
|
|
249
|
+
leafId: frame.leaf_id,
|
|
250
|
+
before: frame.before,
|
|
251
|
+
limit: frame.limit,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
handlePing(frame) {
|
|
255
|
+
const error = this.ensureReady(frame);
|
|
256
|
+
if (error)
|
|
257
|
+
return [error];
|
|
258
|
+
return this.direct(frame.channel_id, { type: "pong", in_reply_to: frame.id });
|
|
259
|
+
}
|
|
260
|
+
handleQueuedMessageClear(frame) {
|
|
261
|
+
const error = this.ensureReady(frame);
|
|
262
|
+
if (error)
|
|
263
|
+
return [error];
|
|
264
|
+
if (!this.onQueuedMessageClear) {
|
|
265
|
+
return [this.error(frame.id, "unsupported_type", "Queued messages are unavailable.", frame.channel_id), ...this.currentQueueSnapshot()];
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const removed = this.onQueuedMessageClear(frame.target_id);
|
|
269
|
+
for (const clientRequestId of removed)
|
|
270
|
+
this.terminateQueuedRequest(clientRequestId);
|
|
271
|
+
if (frame.target_id !== undefined && !removed.includes(frame.target_id)) {
|
|
272
|
+
return [this.error(frame.id, "invalid_message", "This message has already started sending or is no longer queued.", frame.channel_id), ...this.currentQueueSnapshot()];
|
|
273
|
+
}
|
|
274
|
+
return this.currentQueueSnapshot();
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
return [this.error(frame.id, "internal_error", "Could not clear queued messages.", frame.channel_id), ...this.currentQueueSnapshot()];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
handleQueuedMessageSteer(frame) {
|
|
281
|
+
const error = this.ensureReady(frame);
|
|
282
|
+
if (error)
|
|
283
|
+
return [error];
|
|
284
|
+
if (!this.onQueuedMessageSteer) {
|
|
285
|
+
return [this.error(frame.id, "unsupported_type", "Queued messages are unavailable.", frame.channel_id), ...this.currentQueueSnapshot()];
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
const result = this.onQueuedMessageSteer(frame.target_id);
|
|
289
|
+
if (result === "sent") {
|
|
290
|
+
this.terminateQueuedRequest(frame.target_id);
|
|
291
|
+
return this.currentQueueSnapshot();
|
|
292
|
+
}
|
|
293
|
+
const message = result === "failed"
|
|
294
|
+
? "Could not steer this queued message; it remains queued."
|
|
295
|
+
: "This queued message is no longer available to steer.";
|
|
296
|
+
return [this.error(frame.id, "invalid_message", message, frame.channel_id), ...this.currentQueueSnapshot()];
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return [this.error(frame.id, "internal_error", "Could not steer this queued message.", frame.channel_id), ...this.currentQueueSnapshot()];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
handleCancel(frame) {
|
|
303
|
+
const error = this.ensureReady(frame);
|
|
304
|
+
if (error)
|
|
305
|
+
return [error];
|
|
306
|
+
try {
|
|
307
|
+
if (!(this.onCancel?.() ?? false)) {
|
|
308
|
+
return [this.error(frame.id, "internal_error", "no active request to cancel", frame.channel_id)];
|
|
309
|
+
}
|
|
310
|
+
return this.direct(frame.channel_id, {
|
|
311
|
+
type: "cancelled",
|
|
312
|
+
in_reply_to: frame.id,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
catch (cancelError) {
|
|
316
|
+
const detail = cancelError instanceof Error ? cancelError.message : String(cancelError);
|
|
317
|
+
return [this.error(frame.id, "internal_error", `cancel failed: ${detail}`, frame.channel_id)];
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
handleObserved(frame) {
|
|
321
|
+
const error = this.ensureReady(frame);
|
|
322
|
+
if (error)
|
|
323
|
+
return [error];
|
|
324
|
+
const record = this.findRecord(frame.client_request_id);
|
|
325
|
+
if (!record || record.senderRef !== this.senderRef) {
|
|
326
|
+
return [this.error(frame.id, "invalid_message", "unknown observed request", frame.channel_id)];
|
|
327
|
+
}
|
|
328
|
+
this.state.forget(record.key);
|
|
329
|
+
this.requestChannels.delete(frame.client_request_id);
|
|
330
|
+
return [];
|
|
331
|
+
}
|
|
332
|
+
handleUserMessage(frame) {
|
|
333
|
+
const error = this.ensureReady(frame);
|
|
334
|
+
if (error)
|
|
335
|
+
return [error];
|
|
336
|
+
const result = this.state.begin({
|
|
337
|
+
senderRef: this.senderRef,
|
|
338
|
+
clientRequestId: frame.client_request_id,
|
|
339
|
+
payload: this.idempotencyPayload(frame),
|
|
340
|
+
});
|
|
341
|
+
if (result.kind === "conflict") {
|
|
342
|
+
return [this.error(frame.id, "invalid_message", "client_request_id payload conflict", frame.channel_id)];
|
|
343
|
+
}
|
|
344
|
+
if (result.kind === "replay")
|
|
345
|
+
return this.replay(frame, result.record);
|
|
346
|
+
this.requestChannels.set(frame.client_request_id, frame.channel_id);
|
|
347
|
+
const correlation = frame.streaming_behavior === "steer"
|
|
348
|
+
? { origin: "unknown", delivery: "unknown", channelId: frame.channel_id, requestId: frame.id }
|
|
349
|
+
: {
|
|
350
|
+
origin: "pwa",
|
|
351
|
+
delivery: "normal",
|
|
352
|
+
senderRef: this.senderRef,
|
|
353
|
+
channelId: frame.channel_id,
|
|
354
|
+
requestId: frame.id,
|
|
355
|
+
clientRequestId: frame.client_request_id,
|
|
356
|
+
};
|
|
357
|
+
try {
|
|
358
|
+
const acceptedForDelivery = this.onUserMessage(frame, correlation);
|
|
359
|
+
if (acceptedForDelivery === "rejected") {
|
|
360
|
+
this.state.forget(result.record.key);
|
|
361
|
+
this.requestChannels.delete(frame.client_request_id);
|
|
362
|
+
return [this.error(frame.id, "too_large", "The message is too large or the queue is full; retry after queued work drains.", frame.channel_id), ...this.currentQueueSnapshot()];
|
|
363
|
+
}
|
|
364
|
+
if (acceptedForDelivery === "conflict") {
|
|
365
|
+
this.state.forget(result.record.key);
|
|
366
|
+
this.requestChannels.delete(frame.client_request_id);
|
|
367
|
+
return [this.error(frame.id, "invalid_message", "client_request_id payload conflict", frame.channel_id), ...this.currentQueueSnapshot()];
|
|
368
|
+
}
|
|
369
|
+
if (!acceptedForDelivery)
|
|
370
|
+
return this.unknownDelivery(frame.client_request_id);
|
|
371
|
+
if (acceptedForDelivery === "queued" || acceptedForDelivery === "duplicate") {
|
|
372
|
+
this.state.update(result.record.key, "queued");
|
|
373
|
+
return [this.status(frame, "accepted"), ...this.currentQueueSnapshot()];
|
|
374
|
+
}
|
|
375
|
+
if (frame.streaming_behavior === "steer")
|
|
376
|
+
return this.unknownDelivery(frame.client_request_id);
|
|
377
|
+
return [this.status(frame, "received")];
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
return this.unknownDelivery(frame.client_request_id);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
replay(frame, record) {
|
|
384
|
+
if (record.status === "unknown_delivery")
|
|
385
|
+
return this.unknownDelivery(frame.client_request_id);
|
|
386
|
+
if (record.status === "received")
|
|
387
|
+
return [this.status(frame, "received")];
|
|
388
|
+
if (record.status === "queued")
|
|
389
|
+
return [this.status(frame, "accepted"), ...this.currentQueueSnapshot()];
|
|
390
|
+
return [this.status(frame, record.status === "committed" ? "committed" : "accepted", record.messageId, record.groupId)];
|
|
391
|
+
}
|
|
392
|
+
status(frame, status, messageId, groupId) {
|
|
393
|
+
return this.direct(frame.channel_id, {
|
|
394
|
+
type: "user_message_status",
|
|
395
|
+
in_reply_to: frame.id,
|
|
396
|
+
session_id: this.sessionId,
|
|
397
|
+
leaf_id: this.leafId,
|
|
398
|
+
client_request_id: frame.client_request_id,
|
|
399
|
+
status,
|
|
400
|
+
...(messageId ? { message_id: messageId } : {}),
|
|
401
|
+
...(groupId ? { group_id: groupId } : {}),
|
|
402
|
+
})[0];
|
|
403
|
+
}
|
|
404
|
+
handleListModels(frame) {
|
|
405
|
+
const error = this.ensureReady(frame);
|
|
406
|
+
if (error)
|
|
407
|
+
return [error];
|
|
408
|
+
if (!this.onListModels)
|
|
409
|
+
return [this.error(frame.id, "unsupported_type", "model listing is unavailable", frame.channel_id)];
|
|
410
|
+
try {
|
|
411
|
+
return this.direct(frame.channel_id, { type: "models_list", ...this.onListModels(), in_reply_to: frame.id });
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
return [this.error(frame.id, "internal_error", "Could not list available models.", frame.channel_id)];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
handleAction(frame) {
|
|
418
|
+
const error = this.ensureReady(frame);
|
|
419
|
+
if (error)
|
|
420
|
+
return [error];
|
|
421
|
+
if (!this.onAction) {
|
|
422
|
+
return [this.error(frame.id, "unsupported_type", "session action is unavailable", frame.channel_id)];
|
|
423
|
+
}
|
|
424
|
+
try {
|
|
425
|
+
this.onAction(frame);
|
|
426
|
+
return [];
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
return [this.error(frame.id, "internal_error", "Could not execute session action.", frame.channel_id)];
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
requireReady(frame) {
|
|
433
|
+
const error = this.ensureReady(frame);
|
|
434
|
+
return [error ?? this.error("id" in frame ? frame.id : "v2", "unsupported_type", "frame is not implemented", "channel_id" in frame ? frame.channel_id : undefined)];
|
|
435
|
+
}
|
|
436
|
+
ensureReady(frame) {
|
|
437
|
+
if (!("channel_id" in frame) || !this.state.get(this.senderRef, frame.channel_id)) {
|
|
438
|
+
return this.error("id" in frame ? frame.id : "v2", "invalid_channel", "session_hello required", "channel_id" in frame ? frame.channel_id : undefined);
|
|
439
|
+
}
|
|
440
|
+
const sessionMismatch = "session_id" in frame && frame.session_id !== this.sessionId;
|
|
441
|
+
const leafMismatch = "leaf_id" in frame && frame.leaf_id !== this.leafId;
|
|
442
|
+
if (sessionMismatch || leafMismatch) {
|
|
443
|
+
return {
|
|
444
|
+
protocol_version: 2,
|
|
445
|
+
type: "reset",
|
|
446
|
+
target_channel_id: frame.channel_id,
|
|
447
|
+
session_id: this.sessionId,
|
|
448
|
+
leaf_id: this.leafId,
|
|
449
|
+
reason: sessionMismatch ? "session_replaced" : "branch_changed",
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
this.state.touch(this.senderRef, frame.channel_id);
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
currentQueueSnapshot() {
|
|
456
|
+
return this.onQueueSnapshot?.() ?? this.queueSnapshot([]);
|
|
457
|
+
}
|
|
458
|
+
queueFrame(snapshotId, chunkIndex, final, items) {
|
|
459
|
+
return {
|
|
460
|
+
protocol_version: 2,
|
|
461
|
+
type: "queued_message_state",
|
|
462
|
+
session_id: this.sessionId,
|
|
463
|
+
leaf_id: this.leafId,
|
|
464
|
+
snapshot_id: snapshotId,
|
|
465
|
+
chunk_index: chunkIndex,
|
|
466
|
+
final,
|
|
467
|
+
items: [...items],
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
frameBytes(frame) {
|
|
471
|
+
return Buffer.byteLength(JSON.stringify(frame), "utf8");
|
|
472
|
+
}
|
|
473
|
+
terminateQueuedRequest(clientRequestId) {
|
|
474
|
+
const record = this.state.getRecord(this.recordKey(clientRequestId));
|
|
475
|
+
if (record?.senderRef === this.senderRef)
|
|
476
|
+
this.state.rememberUnknownDelivery(record.key);
|
|
477
|
+
}
|
|
478
|
+
direct(channelId, frame) {
|
|
479
|
+
return [{ ...frame, protocol_version: 2, target_channel_id: channelId }];
|
|
480
|
+
}
|
|
481
|
+
error(inReplyTo, code, message, channelId) {
|
|
482
|
+
return {
|
|
483
|
+
protocol_version: 2,
|
|
484
|
+
type: "protocol_error",
|
|
485
|
+
...(channelId ? { target_channel_id: channelId } : {}),
|
|
486
|
+
in_reply_to: inReplyTo,
|
|
487
|
+
code,
|
|
488
|
+
message,
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
idempotencyPayload(frame) {
|
|
492
|
+
return {
|
|
493
|
+
text: frame.text,
|
|
494
|
+
images: frame.images ?? [],
|
|
495
|
+
streaming_behavior: frame.streaming_behavior ?? null,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
recordKey(clientRequestId) {
|
|
499
|
+
return `${this.sessionId}\u0000${this.leafId ?? ""}\u0000${this.senderRef}\u0000${clientRequestId}`;
|
|
500
|
+
}
|
|
501
|
+
findRecord(clientRequestId) {
|
|
502
|
+
const channelId = this.requestChannels.get(clientRequestId);
|
|
503
|
+
if (!channelId)
|
|
504
|
+
return undefined;
|
|
505
|
+
const current = this.state.getRecord(this.recordKey(clientRequestId));
|
|
506
|
+
if (current)
|
|
507
|
+
return { ...current, channelId };
|
|
508
|
+
const fallback = this.state.snapshot().records.find((record) => record.senderRef === this.senderRef && record.clientRequestId === clientRequestId);
|
|
509
|
+
return fallback ? { ...fallback, channelId } : undefined;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
//# sourceMappingURL=v2_service.js.map
|
|
@@ -0,0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CAAC,eAAe,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC5D,IAAI,CAAC,SAAS;YAAE,OAAO,SAAS,CAAC;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC;QACtE,IAAI,OAAO;YAAE,OAAO,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC;QAC9C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,KAAK,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,eAAe,KAAK,eAAe,CAAC,CAAC;QACnJ,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ClientFrame, type ServerFrame } from "../protocol/v2/index.js";
|
|
2
|
+
import type { RelayClient } from "./relay_client.js";
|
|
3
|
+
import { type RouteFrame, type RoutePurpose } from "../vendor/protocol/outer/index.js";
|
|
4
|
+
export type { RouteFrame, RoutePurpose } from "../vendor/protocol/outer/index.js";
|
|
5
|
+
export type HostRouteIdentity = {
|
|
6
|
+
deviceId: string;
|
|
7
|
+
endpointId: string;
|
|
8
|
+
runtimeInstanceId: string;
|
|
9
|
+
};
|
|
10
|
+
export interface V2Channel {
|
|
11
|
+
getPeerId(): string;
|
|
12
|
+
sendV2(msg: ServerFrame): void;
|
|
13
|
+
detach(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A Host-side protocol-v2 channel for one authorized Owner. The relay
|
|
17
|
+
* authenticates and injects `source_owner_id` for Owner-to-Host routes; this
|
|
18
|
+
* channel only accepts routes for its immutable endpoint identity and owner.
|
|
19
|
+
*/
|
|
20
|
+
export declare class V2PeerChannel implements V2Channel {
|
|
21
|
+
private readonly relay;
|
|
22
|
+
private readonly ownerId;
|
|
23
|
+
private readonly host;
|
|
24
|
+
private readonly onMessage;
|
|
25
|
+
private readonly unsubscribe;
|
|
26
|
+
constructor(relay: RelayClient, ownerId: string, host: HostRouteIdentity, onMessage: (msg: ClientFrame) => void);
|
|
27
|
+
getPeerId(): string;
|
|
28
|
+
sendV2(msg: ServerFrame): boolean;
|
|
29
|
+
detach(): void;
|
|
30
|
+
private onLine;
|
|
31
|
+
private sendUpgradeRequired;
|
|
32
|
+
}
|
|
33
|
+
export declare function parseIncomingRoute(line: string, host: HostRouteIdentity, ownerId?: string): RouteFrame | null;
|
|
34
|
+
export declare function sendRoute(relay: RelayClient, host: HostRouteIdentity, ownerId: string, purpose: RoutePurpose, ct: string): void;
|