@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,263 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { chmod, open, readFile, rename, unlink } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { generateEd25519Keypair } from "./crypto.js";
|
|
6
|
+
import { ensurePrivateIdentityDirectory, withIdentityLock, } from "./identity-lock.js";
|
|
7
|
+
import { NapiKeyringBackend, nativeBindingUnavailable, } from "./identity-keyring.js";
|
|
8
|
+
import { listPeers } from "./owner_storage.js";
|
|
9
|
+
export { addPeer, listPeers, listOwnerPubkeys, snapshotOwnerPubkeys, conditionalRemovePeer, conditionalRollbackPeer, removePeer, } from "./owner_storage.js";
|
|
10
|
+
export { _setKeyringOperationTimeoutForTest, _setNativeBindingErrorForTest, KeyringMutationTimeoutError, KeyringReadTimeoutError, } from "./identity-keyring.js";
|
|
11
|
+
export { IdentityLockTimeoutError } from "./identity-lock.js";
|
|
12
|
+
const KEYRING_SERVICE = "dev.pireach.pi";
|
|
13
|
+
const ACCOUNT = "longterm-ed25519";
|
|
14
|
+
const PI_DIR = join(homedir(), ".pi", "pi-reach");
|
|
15
|
+
const IDENTITY_FILE = join(PI_DIR, "identity.json");
|
|
16
|
+
const IDENTITY_LOCK_FILE = join(PI_DIR, "identity.lock");
|
|
17
|
+
let keyringReadAttempts = 3;
|
|
18
|
+
let keyringRetryDelayMs = 300;
|
|
19
|
+
let identityLockWaitTimeoutMs = 15_000;
|
|
20
|
+
let identityLockPollIntervalMs = 50;
|
|
21
|
+
export class KeyringUnavailableError extends Error {
|
|
22
|
+
constructor(cause) {
|
|
23
|
+
super("Platform keyring is unreadable and no file-backed identity exists. " +
|
|
24
|
+
"Refusing to generate a NEW identity (that would break existing pairing). " +
|
|
25
|
+
"Unlock your keychain / start your secret service and retry. " +
|
|
26
|
+
"Set PI_REACH_ALLOW_FILE_IDENTITY=1 to force a file-backed identity. " +
|
|
27
|
+
`Cause: ${String(cause)}`);
|
|
28
|
+
this.name = "KeyringUnavailableError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export class PairedIdentityMissingError extends Error {
|
|
32
|
+
constructor(pairedCount, cause) {
|
|
33
|
+
super(`No identity could be read, but ${pairedCount} device(s) are already paired. ` +
|
|
34
|
+
"Refusing to generate a NEW identity - that would revoke every paired device. " +
|
|
35
|
+
"Fix this process's keyring access, or pin the established identity to " +
|
|
36
|
+
"~/.pi/pi-reach/identity.json (0600). " +
|
|
37
|
+
`Cause: ${String(cause)}`);
|
|
38
|
+
this.name = "PairedIdentityMissingError";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class IdentityFileError extends Error {
|
|
42
|
+
identityPath;
|
|
43
|
+
category;
|
|
44
|
+
constructor(identityPath, category) {
|
|
45
|
+
super(`Identity file at ${identityPath} is unsafe to use (${category}). Refusing to replace it.`);
|
|
46
|
+
this.name = "IdentityFileError";
|
|
47
|
+
this.identityPath = identityPath;
|
|
48
|
+
this.category = category;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class KeyringIdentityError extends Error {
|
|
52
|
+
service;
|
|
53
|
+
constructor(service) {
|
|
54
|
+
super(`Stored identity in platform keyring service ${service} is invalid. Refusing to replace it.`);
|
|
55
|
+
this.name = "KeyringIdentityError";
|
|
56
|
+
this.service = service;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let backend = null;
|
|
60
|
+
let keyringExpectedOverride = null;
|
|
61
|
+
function getBackend() {
|
|
62
|
+
if (!backend)
|
|
63
|
+
backend = new NapiKeyringBackend();
|
|
64
|
+
return backend;
|
|
65
|
+
}
|
|
66
|
+
export function _setKeyStoreBackendForTest(value) {
|
|
67
|
+
backend = value;
|
|
68
|
+
}
|
|
69
|
+
function keyringExpectedAvailable() {
|
|
70
|
+
if (keyringExpectedOverride !== null)
|
|
71
|
+
return keyringExpectedOverride;
|
|
72
|
+
if (nativeBindingUnavailable())
|
|
73
|
+
return false;
|
|
74
|
+
return process.platform === "darwin" || process.platform === "win32";
|
|
75
|
+
}
|
|
76
|
+
export function _setKeyringExpectedForTest(value) {
|
|
77
|
+
keyringExpectedOverride = value;
|
|
78
|
+
}
|
|
79
|
+
export function _setKeyringRetryForTest(attempts, delayMs) {
|
|
80
|
+
keyringReadAttempts = attempts ?? 3;
|
|
81
|
+
keyringRetryDelayMs = delayMs ?? 300;
|
|
82
|
+
}
|
|
83
|
+
export function _setIdentityLockTimingForTest(waitTimeoutMs, pollIntervalMs) {
|
|
84
|
+
identityLockWaitTimeoutMs = waitTimeoutMs ?? 15_000;
|
|
85
|
+
identityLockPollIntervalMs = pollIntervalMs ?? 50;
|
|
86
|
+
}
|
|
87
|
+
function sleep(ms) {
|
|
88
|
+
return ms > 0 ? new Promise((resolve) => setTimeout(resolve, ms)) : Promise.resolve();
|
|
89
|
+
}
|
|
90
|
+
function serialize(kp) {
|
|
91
|
+
const payload = {
|
|
92
|
+
pk: Buffer.from(kp.publicKey).toString("base64"),
|
|
93
|
+
sk: Buffer.from(kp.secretKey).toString("base64"),
|
|
94
|
+
};
|
|
95
|
+
return JSON.stringify(payload);
|
|
96
|
+
}
|
|
97
|
+
function decodeCanonicalBase64(value, field) {
|
|
98
|
+
if (typeof value !== "string" || !/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {
|
|
99
|
+
throw new Error(`invalid ${field}`);
|
|
100
|
+
}
|
|
101
|
+
const decoded = Buffer.from(value, "base64");
|
|
102
|
+
if (decoded.toString("base64") !== value)
|
|
103
|
+
throw new Error(`invalid ${field}`);
|
|
104
|
+
return decoded;
|
|
105
|
+
}
|
|
106
|
+
function deserializeUnsafe(stored) {
|
|
107
|
+
const parsed = JSON.parse(stored);
|
|
108
|
+
const publicKey = decodeCanonicalBase64(parsed.pk, "pk");
|
|
109
|
+
const secretKey = decodeCanonicalBase64(parsed.sk, "sk");
|
|
110
|
+
if (publicKey.length !== 32 || (secretKey.length !== 32 && secretKey.length !== 64))
|
|
111
|
+
throw new Error("invalid key length");
|
|
112
|
+
return { publicKey, secretKey };
|
|
113
|
+
}
|
|
114
|
+
function deserializeKeyringIdentity(stored, service) {
|
|
115
|
+
try {
|
|
116
|
+
return deserializeUnsafe(stored);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
throw new KeyringIdentityError(service);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function isNodeErrorWithCode(error, code) {
|
|
123
|
+
return typeof error === "object" && error !== null && "code" in error &&
|
|
124
|
+
error.code === code;
|
|
125
|
+
}
|
|
126
|
+
async function readKeypairFromFile() {
|
|
127
|
+
let raw;
|
|
128
|
+
try {
|
|
129
|
+
raw = await readFile(IDENTITY_FILE, "utf8");
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (isNodeErrorWithCode(error, "ENOENT"))
|
|
133
|
+
return null;
|
|
134
|
+
throw new IdentityFileError(IDENTITY_FILE, "read_failed");
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
return deserializeUnsafe(raw);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
throw new IdentityFileError(IDENTITY_FILE, "invalid_format");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function syncIdentityDirectory() {
|
|
144
|
+
if (process.platform === "win32")
|
|
145
|
+
return;
|
|
146
|
+
const directory = await open(PI_DIR, "r");
|
|
147
|
+
try {
|
|
148
|
+
await directory.sync();
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
await directory.close();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function writeKeypairToFile(kp) {
|
|
155
|
+
await ensurePrivateIdentityDirectory(PI_DIR);
|
|
156
|
+
const temporaryPath = join(PI_DIR, `.identity.json.${process.pid}.${randomUUID()}.tmp`);
|
|
157
|
+
let handle = null;
|
|
158
|
+
let published = false;
|
|
159
|
+
try {
|
|
160
|
+
handle = await open(temporaryPath, "wx", 0o600);
|
|
161
|
+
await handle.writeFile(serialize(kp), "utf8");
|
|
162
|
+
await handle.sync();
|
|
163
|
+
await handle.close();
|
|
164
|
+
handle = null;
|
|
165
|
+
await rename(temporaryPath, IDENTITY_FILE);
|
|
166
|
+
published = true;
|
|
167
|
+
await chmod(IDENTITY_FILE, 0o600);
|
|
168
|
+
await syncIdentityDirectory();
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
if (handle)
|
|
172
|
+
await handle.close().catch(() => undefined);
|
|
173
|
+
if (!published) {
|
|
174
|
+
await unlink(temporaryPath).catch((error) => {
|
|
175
|
+
if (!isNodeErrorWithCode(error, "ENOENT"))
|
|
176
|
+
throw error;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
async function assertGenerationIsSafe(forceFile, cause) {
|
|
182
|
+
if (forceFile)
|
|
183
|
+
return;
|
|
184
|
+
const paired = await listPeers();
|
|
185
|
+
if (paired.length > 0)
|
|
186
|
+
throw new PairedIdentityMissingError(paired.length, cause);
|
|
187
|
+
}
|
|
188
|
+
async function resolveKeyringReads(store) {
|
|
189
|
+
let keyringError;
|
|
190
|
+
for (let attempt = 0; attempt < keyringReadAttempts; attempt++) {
|
|
191
|
+
try {
|
|
192
|
+
const existing = await store.read(KEYRING_SERVICE, ACCOUNT);
|
|
193
|
+
if (existing)
|
|
194
|
+
return { resolution: { kind: "stored", stored: existing }, error: undefined };
|
|
195
|
+
return { resolution: { kind: "empty" }, error: undefined };
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
keyringError = error;
|
|
199
|
+
if (attempt < keyringReadAttempts - 1) {
|
|
200
|
+
await sleep(keyringRetryDelayMs * (attempt + 1));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return { resolution: null, error: keyringError };
|
|
205
|
+
}
|
|
206
|
+
async function getOrCreateUnderLock() {
|
|
207
|
+
const existingFile = await readKeypairFromFile();
|
|
208
|
+
if (existingFile)
|
|
209
|
+
return existingFile;
|
|
210
|
+
const store = getBackend();
|
|
211
|
+
const { resolution, error: keyringError } = await resolveKeyringReads(store);
|
|
212
|
+
const forceFile = process.env.PI_REACH_ALLOW_FILE_IDENTITY === "1";
|
|
213
|
+
if (resolution?.kind === "stored") {
|
|
214
|
+
return deserializeKeyringIdentity(resolution.stored, KEYRING_SERVICE);
|
|
215
|
+
}
|
|
216
|
+
if (resolution?.kind === "empty") {
|
|
217
|
+
await assertGenerationIsSafe(forceFile, undefined);
|
|
218
|
+
const fresh = generateEd25519Keypair();
|
|
219
|
+
await store.write(KEYRING_SERVICE, ACCOUNT, serialize(fresh));
|
|
220
|
+
return fresh;
|
|
221
|
+
}
|
|
222
|
+
const fromFile = await readKeypairFromFile();
|
|
223
|
+
if (fromFile)
|
|
224
|
+
return fromFile;
|
|
225
|
+
if (keyringExpectedAvailable() && !forceFile) {
|
|
226
|
+
throw new KeyringUnavailableError(keyringError);
|
|
227
|
+
}
|
|
228
|
+
await assertGenerationIsSafe(forceFile, keyringError);
|
|
229
|
+
console.warn(nativeBindingUnavailable()
|
|
230
|
+
? "[pi-reach] @napi-rs/keyring native binding could not be loaded in this " +
|
|
231
|
+
`runtime; using file-backed identity at ${IDENTITY_FILE} (0600) instead. ${String(keyringError)}`
|
|
232
|
+
: "[pi-reach] keyring unavailable; using file-backed identity at " +
|
|
233
|
+
`${IDENTITY_FILE}. ${String(keyringError)}`);
|
|
234
|
+
const fresh = generateEd25519Keypair();
|
|
235
|
+
await writeKeypairToFile(fresh);
|
|
236
|
+
return fresh;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Returns the stable Host identity. Existing file identity wins; otherwise all
|
|
240
|
+
* keyring reads, generation, and persistence run under the fixed
|
|
241
|
+
* cross-process identity lock. Every source is read again after lock acquisition.
|
|
242
|
+
*/
|
|
243
|
+
export async function getOrCreateEd25519Keypair() {
|
|
244
|
+
const existingFile = await readKeypairFromFile();
|
|
245
|
+
if (existingFile)
|
|
246
|
+
return existingFile;
|
|
247
|
+
return withIdentityLock(PI_DIR, getOrCreateUnderLock, {
|
|
248
|
+
waitTimeoutMs: identityLockWaitTimeoutMs,
|
|
249
|
+
pollIntervalMs: identityLockPollIntervalMs,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
export const _IDENTITY_FILE_FOR_TEST = IDENTITY_FILE;
|
|
253
|
+
export const _IDENTITY_LOCK_FILE_FOR_TEST = IDENTITY_LOCK_FILE;
|
|
254
|
+
export const _unlinkIdentityFileForTest = async () => {
|
|
255
|
+
try {
|
|
256
|
+
await unlink(IDENTITY_FILE);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
if (!isNodeErrorWithCode(error, "ENOENT"))
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/pairing/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAAuB,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,8BAA8B,EAE9B,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GAEzB,MAAM,uBAAuB,CAAC;AAC/B,O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AuB,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;IACD,MAAM,sBAAsB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAEtD,OAAO,CAAC,IAAI,CACV,wBAAwB,EAAE;QACxB,CAAC,CAAC,yEAAyE;YACzE,0CAA0C,aAAa,oBAAoB,MAAM,CAAC,YAAY,CAAC,EAAE;QACnG,CAAC,CAAC,gEAAgE;YAChE,GAAG,aAAa,KAAK,MAAM,CAAC,YAAY,CAAC,EAAE,CAChD,CAAC;IACF,MAAM,KAAK,GAAG,sBAAsB,EAAE,CAAC;IACvC,MAAM,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAChC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,MAAM,YAAY,GAAG,MAAM,mBAAmB,EAAE,CAAC;IACjD,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IAEtC,OAAO,gBAAgB,CACrB,MAAM,EACN,oBAAoB,EACpB;QACE,aAAa,EAAE,yBAAyB;QACxC,cAAc,EAAE,0BAA0B;KAC3C,CACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AACrD,MAAM,CAAC,MAAM,4BAA4B,GAAG,kBAAkB,CAAC;AAC/D,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,IAAmB,EAAE;IAClE,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,MAAM,KAAK,CAAC;IACzD,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { WireImage, ThinkingLevel, WireModel } from "../vendor/protocol/session/index.js";
|
|
2
|
+
export type { WireImage, ThinkingLevel, WireModel } from "../vendor/protocol/session/index.js";
|
|
3
|
+
export type PairErrorCode = "token_expired" | "token_consumed" | "token_unknown" | "internal_error";
|
|
4
|
+
export type StreamingBehavior = "steer";
|
|
5
|
+
export type QueuedMessageItem = {
|
|
6
|
+
id: string;
|
|
7
|
+
text: string;
|
|
8
|
+
/** Omitted for text-only items so the existing no-image wire path is unchanged. */
|
|
9
|
+
images?: WireImage[];
|
|
10
|
+
sender_ref?: string;
|
|
11
|
+
editable: boolean;
|
|
12
|
+
created_at: number;
|
|
13
|
+
};
|
|
14
|
+
export type ClientMessage = {
|
|
15
|
+
type: "pair_request";
|
|
16
|
+
id: string;
|
|
17
|
+
code: string;
|
|
18
|
+
device_name: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "user_message";
|
|
21
|
+
id: string;
|
|
22
|
+
text: string;
|
|
23
|
+
images?: WireImage[];
|
|
24
|
+
streaming_behavior?: StreamingBehavior;
|
|
25
|
+
} | {
|
|
26
|
+
type: "queued_message_set";
|
|
27
|
+
id: string;
|
|
28
|
+
text: string;
|
|
29
|
+
images?: WireImage[];
|
|
30
|
+
} | {
|
|
31
|
+
type: "queued_message_clear";
|
|
32
|
+
id: string;
|
|
33
|
+
target_id?: string;
|
|
34
|
+
} | {
|
|
35
|
+
type: "approve_tool";
|
|
36
|
+
id: string;
|
|
37
|
+
tool_call_id: string;
|
|
38
|
+
decision: "allow" | "deny";
|
|
39
|
+
} | {
|
|
40
|
+
type: "cancel";
|
|
41
|
+
id: string;
|
|
42
|
+
target_id: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: "ping";
|
|
45
|
+
id: string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "session_sync";
|
|
48
|
+
id: string;
|
|
49
|
+
limit?: number;
|
|
50
|
+
} | {
|
|
51
|
+
type: "session_new";
|
|
52
|
+
id: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: "session_compact";
|
|
55
|
+
id: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: "model_set";
|
|
58
|
+
id: string;
|
|
59
|
+
provider: string;
|
|
60
|
+
model_id: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: "thinking_set";
|
|
63
|
+
id: string;
|
|
64
|
+
level: ThinkingLevel;
|
|
65
|
+
} | {
|
|
66
|
+
type: "list_models";
|
|
67
|
+
id: string;
|
|
68
|
+
};
|
|
69
|
+
export type Usage = {
|
|
70
|
+
input_tokens: number;
|
|
71
|
+
output_tokens: number;
|
|
72
|
+
};
|
|
73
|
+
export type KnownErrorCode = "tool_approval_required" | "invalid_message" | "unsupported_type" | "too_large" | "rate_limited" | "timeout" | "internal_error";
|
|
74
|
+
export type ErrorCode = KnownErrorCode | (string & {});
|
|
75
|
+
export type SessionHistoryEvent = {
|
|
76
|
+
ts: number;
|
|
77
|
+
type: "user_input";
|
|
78
|
+
id: string;
|
|
79
|
+
text: string;
|
|
80
|
+
images?: WireImage[];
|
|
81
|
+
} | {
|
|
82
|
+
ts: number;
|
|
83
|
+
type: "tool_request";
|
|
84
|
+
tool_call_id: string;
|
|
85
|
+
tool: string;
|
|
86
|
+
args: Record<string, unknown>;
|
|
87
|
+
} | {
|
|
88
|
+
ts: number;
|
|
89
|
+
type: "tool_result";
|
|
90
|
+
tool_call_id: string;
|
|
91
|
+
result?: unknown;
|
|
92
|
+
error?: string;
|
|
93
|
+
} | {
|
|
94
|
+
ts: number;
|
|
95
|
+
type: "agent_message";
|
|
96
|
+
in_reply_to: string;
|
|
97
|
+
text: string;
|
|
98
|
+
usage?: Usage;
|
|
99
|
+
} | {
|
|
100
|
+
ts: number;
|
|
101
|
+
type: "compaction";
|
|
102
|
+
summary: string;
|
|
103
|
+
tokens_before: number;
|
|
104
|
+
};
|
|
105
|
+
export type ServerMessage = {
|
|
106
|
+
type: "pair_ok";
|
|
107
|
+
in_reply_to: string;
|
|
108
|
+
session_name: string;
|
|
109
|
+
session_started_at: number;
|
|
110
|
+
endpoint_id: string;
|
|
111
|
+
/**
|
|
112
|
+
* Plan/27 Wave A: identifies the host coding agent driving this
|
|
113
|
+
* pi-extension instance. `name` is hardcoded to "Pi coding agent"
|
|
114
|
+
* today; future Pi forks (Claude Code, OpenCode) populate their own
|
|
115
|
+
* here. `version` is the pi-extension `package.json` version.
|
|
116
|
+
* Optional in the wire schema so app-side parsing tolerates older
|
|
117
|
+
* Pi builds that predate this field — every new pairing emits both.
|
|
118
|
+
*/
|
|
119
|
+
harness?: {
|
|
120
|
+
name: string;
|
|
121
|
+
version: string;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Plan/27 Wave A: `os.hostname()` of the machine the Pi runs on.
|
|
125
|
+
* App displays it in the device list so the user can distinguish
|
|
126
|
+
* two paired PCs that happen to share a nickname or sit in the
|
|
127
|
+
* same project folder.
|
|
128
|
+
*/
|
|
129
|
+
hostname?: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: "pair_error";
|
|
132
|
+
in_reply_to: string;
|
|
133
|
+
code: PairErrorCode;
|
|
134
|
+
message: string;
|
|
135
|
+
} | {
|
|
136
|
+
type: "user_input";
|
|
137
|
+
id: string;
|
|
138
|
+
text: string;
|
|
139
|
+
streaming_behavior?: StreamingBehavior;
|
|
140
|
+
} | {
|
|
141
|
+
type: "user_message";
|
|
142
|
+
id: string;
|
|
143
|
+
text: string;
|
|
144
|
+
images?: WireImage[];
|
|
145
|
+
streaming_behavior?: StreamingBehavior;
|
|
146
|
+
} | {
|
|
147
|
+
type: "queued_message_state";
|
|
148
|
+
id?: string;
|
|
149
|
+
text?: string;
|
|
150
|
+
items?: QueuedMessageItem[];
|
|
151
|
+
} | {
|
|
152
|
+
type: "steer_consumed";
|
|
153
|
+
id: string;
|
|
154
|
+
} | {
|
|
155
|
+
type: "agent_chunk";
|
|
156
|
+
in_reply_to: string;
|
|
157
|
+
delta: string;
|
|
158
|
+
} | {
|
|
159
|
+
type: "agent_done";
|
|
160
|
+
in_reply_to: string;
|
|
161
|
+
usage?: Usage;
|
|
162
|
+
} | {
|
|
163
|
+
type: "agent_message";
|
|
164
|
+
in_reply_to: string;
|
|
165
|
+
text: string;
|
|
166
|
+
usage?: Usage;
|
|
167
|
+
} | {
|
|
168
|
+
type: "compaction";
|
|
169
|
+
summary: string;
|
|
170
|
+
tokens_before: number;
|
|
171
|
+
ts?: number;
|
|
172
|
+
} | {
|
|
173
|
+
type: "tool_request";
|
|
174
|
+
tool_call_id: string;
|
|
175
|
+
tool: string;
|
|
176
|
+
args: Record<string, unknown>;
|
|
177
|
+
} | {
|
|
178
|
+
type: "tool_result";
|
|
179
|
+
tool_call_id: string;
|
|
180
|
+
result?: unknown;
|
|
181
|
+
error?: string;
|
|
182
|
+
} | {
|
|
183
|
+
type: "error";
|
|
184
|
+
in_reply_to?: string;
|
|
185
|
+
code: ErrorCode;
|
|
186
|
+
message: string;
|
|
187
|
+
} | {
|
|
188
|
+
type: "cancelled";
|
|
189
|
+
in_reply_to: string;
|
|
190
|
+
target_id: string;
|
|
191
|
+
} | {
|
|
192
|
+
type: "pong";
|
|
193
|
+
in_reply_to: string;
|
|
194
|
+
} | {
|
|
195
|
+
type: "bye";
|
|
196
|
+
reason: ByeReason;
|
|
197
|
+
} | {
|
|
198
|
+
type: "session_history";
|
|
199
|
+
in_reply_to: string;
|
|
200
|
+
session_started_at: number;
|
|
201
|
+
events: SessionHistoryEvent[];
|
|
202
|
+
eos: boolean;
|
|
203
|
+
truncated: boolean;
|
|
204
|
+
} | {
|
|
205
|
+
type: "action_ok";
|
|
206
|
+
in_reply_to: string;
|
|
207
|
+
action: ActionName;
|
|
208
|
+
} | {
|
|
209
|
+
type: "action_error";
|
|
210
|
+
in_reply_to: string;
|
|
211
|
+
action: ActionName;
|
|
212
|
+
error: string;
|
|
213
|
+
} | {
|
|
214
|
+
type: "models_list";
|
|
215
|
+
in_reply_to: string;
|
|
216
|
+
models: WireModel[];
|
|
217
|
+
current?: WireModel;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Plan/28 — Stable names for the typed actions the app can request. Kept
|
|
221
|
+
* as a closed string union so a switch in either side gets exhaustiveness
|
|
222
|
+
* checking from the compiler.
|
|
223
|
+
*/
|
|
224
|
+
export type ActionName = "session_new" | "session_compact" | "model_set" | "thinking_set";
|
|
225
|
+
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,6 @@
|
|
|
1
|
+
import type { JsonValue } from "../../vendor/protocol/session/index.js";
|
|
2
|
+
export { DECODE_ERROR_CODES, DecodeError, decodeClientFrameV2, decodeServerFrameV2, encodeClientFrameTextV2 as encodeClientFrameV2, encodeServerFrameTextV2 as encodeServerFrameV2, getUtf8ByteLengthV2, parseProtocolJsonV2, parseTimelineEventV2, parseTimelinePartialV2, validateEncodedSizeV2, validateFragmentSizeV2, validateHistoryChunkSizeV2, validateSessionHistoryChunkSize, validateSessionHistoryChunkV2, validateTimelineEventFragmentV2, validateTimelineWindowV2, validateWindowSizeV2, } from "../../vendor/protocol/session/index.js";
|
|
3
|
+
export type { DecodeErrorCode } from "../../vendor/protocol/session/index.js";
|
|
4
|
+
export { HistoryFragmentSchema, SessionHistoryChunkSchema, TimelineEventFragmentSchema, } from "./schemas.js";
|
|
5
|
+
export { parseMarkerV2 } from "./marker.js";
|
|
6
|
+
export type JsonValueV2 = JsonValue;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DECODE_ERROR_CODES, DecodeError, decodeClientFrameV2, decodeServerFrameV2, encodeClientFrameTextV2 as encodeClientFrameV2, encodeServerFrameTextV2 as encodeServerFrameV2, getUtf8ByteLengthV2, parseProtocolJsonV2, parseTimelineEventV2, parseTimelinePartialV2, validateEncodedSizeV2, validateFragmentSizeV2, validateHistoryChunkSizeV2, validateSessionHistoryChunkSize, validateSessionHistoryChunkV2, validateTimelineEventFragmentV2, validateTimelineWindowV2, validateWindowSizeV2, } from "../../vendor/protocol/session/index.js";
|
|
2
|
+
export { HistoryFragmentSchema, SessionHistoryChunkSchema, TimelineEventFragmentSchema, } from "./schemas.js";
|
|
3
|
+
export { parseMarkerV2 } from "./marker.js";
|
|
4
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../../src/protocol/v2/codec.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,IAAI,mBAAmB,EAC9C,uBAAuB,IAAI,mBAAmB,EAC9C,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,wBAAwB,EACxB,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/protocol/v2/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const TIMELINE_MARKER_NAME: "pi-reach:timeline-v2";
|
|
3
|
+
export declare const MarkerSchemaV2: z.ZodUnion<readonly [z.ZodObject<{
|
|
4
|
+
kind: z.ZodLiteral<"user">;
|
|
5
|
+
origin: z.ZodEnum<{
|
|
6
|
+
unknown: "unknown";
|
|
7
|
+
pwa: "pwa";
|
|
8
|
+
extension: "extension";
|
|
9
|
+
}>;
|
|
10
|
+
delivery: z.ZodEnum<{
|
|
11
|
+
unknown: "unknown";
|
|
12
|
+
normal: "normal";
|
|
13
|
+
queued: "queued";
|
|
14
|
+
}>;
|
|
15
|
+
sender_ref: z.ZodOptional<z.ZodString>;
|
|
16
|
+
version: z.ZodLiteral<2>;
|
|
17
|
+
group_id: z.ZodString;
|
|
18
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
+
kind: z.ZodEnum<{
|
|
20
|
+
assistant: "assistant";
|
|
21
|
+
tool: "tool";
|
|
22
|
+
provider_error: "provider_error";
|
|
23
|
+
}>;
|
|
24
|
+
version: z.ZodLiteral<2>;
|
|
25
|
+
group_id: z.ZodString;
|
|
26
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
27
|
+
kind: z.ZodLiteral<"run_end">;
|
|
28
|
+
status: z.ZodEnum<{
|
|
29
|
+
error: "error";
|
|
30
|
+
complete: "complete";
|
|
31
|
+
interrupted: "interrupted";
|
|
32
|
+
}>;
|
|
33
|
+
version: z.ZodLiteral<2>;
|
|
34
|
+
group_id: z.ZodString;
|
|
35
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
36
|
+
version: z.ZodLiteral<2>;
|
|
37
|
+
kind: z.ZodEnum<{
|
|
38
|
+
compaction: "compaction";
|
|
39
|
+
branch_summary: "branch_summary";
|
|
40
|
+
custom: "custom";
|
|
41
|
+
}>;
|
|
42
|
+
group_id: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strict>]>;
|
|
44
|
+
export type MarkerV2 = z.infer<typeof MarkerSchemaV2>;
|
|
45
|
+
export declare function parseMarkerV2(raw: unknown): MarkerV2;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DecodeError, idSchema, MAX_FRAGMENT_DECODE_BYTES, parseProtocolJsonV2, validateEncodedSizeV2, } from "../../vendor/protocol/session/index.js";
|
|
3
|
+
export const TIMELINE_MARKER_NAME = "pi-reach:timeline-v2";
|
|
4
|
+
const markerSystemKind = z.enum(["compaction", "branch_summary", "custom"]);
|
|
5
|
+
const markerGroupedBase = { version: z.literal(2), group_id: idSchema };
|
|
6
|
+
const markerUser = z.strictObject({
|
|
7
|
+
...markerGroupedBase,
|
|
8
|
+
kind: z.literal("user"),
|
|
9
|
+
origin: z.enum(["pwa", "extension", "unknown"]),
|
|
10
|
+
delivery: z.enum(["normal", "queued", "unknown"]),
|
|
11
|
+
sender_ref: idSchema.optional(),
|
|
12
|
+
}).superRefine((value, ctx) => {
|
|
13
|
+
if (value.origin === "pwa" && value.sender_ref === undefined) {
|
|
14
|
+
ctx.addIssue({ code: "custom", path: ["sender_ref"], message: "pwa marker users require sender_ref" });
|
|
15
|
+
}
|
|
16
|
+
if (value.origin !== "pwa" && value.sender_ref !== undefined) {
|
|
17
|
+
ctx.addIssue({ code: "custom", path: ["sender_ref"], message: "non-pwa marker users must not include sender_ref" });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const markerGrouped = z.strictObject({
|
|
21
|
+
...markerGroupedBase,
|
|
22
|
+
kind: z.enum(["assistant", "tool", "provider_error"]),
|
|
23
|
+
});
|
|
24
|
+
const markerRunEnd = z.strictObject({
|
|
25
|
+
...markerGroupedBase,
|
|
26
|
+
kind: z.literal("run_end"),
|
|
27
|
+
status: z.enum(["complete", "interrupted", "error"]),
|
|
28
|
+
});
|
|
29
|
+
const markerSystem = z.strictObject({
|
|
30
|
+
version: z.literal(2),
|
|
31
|
+
kind: markerSystemKind,
|
|
32
|
+
group_id: idSchema.optional(),
|
|
33
|
+
});
|
|
34
|
+
export const MarkerSchemaV2 = z.union([markerUser, markerGrouped, markerRunEnd, markerSystem]);
|
|
35
|
+
function schemaMessage(error) {
|
|
36
|
+
return error.issues.map((issue) => `${issue.path.join(".") || "<root>"}: ${issue.message}`).join("; ");
|
|
37
|
+
}
|
|
38
|
+
export function parseMarkerV2(raw) {
|
|
39
|
+
const value = parseProtocolJsonV2(raw);
|
|
40
|
+
const result = MarkerSchemaV2.safeParse(value);
|
|
41
|
+
if (!result.success) {
|
|
42
|
+
throw new DecodeError("schema", schemaMessage(result.error), { cause: result.error });
|
|
43
|
+
}
|
|
44
|
+
validateEncodedSizeV2(result.data, MAX_FRAGMENT_DECODE_BYTES);
|
|
45
|
+
return result.data;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=marker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"marker.js","sourceRoot":"","sources":["../../../src/protocol/v2/marker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAA+B,CAAC;AAEpE,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC5E,MAAM,iBAAiB,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AACxE,MAAM,UAAU,GAAG,CAAC,CAAC,YAAY,CAAC;IAChC,GAAG,iBAAiB;IACpB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACvB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAC/C,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACjD,UAAU,EAAE,QAAQ,CAAC,QAAQ,EAAE;CAChC,CAAC,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,GAAG,E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AAC,CAAC;AAG/F,SAAS,aAAa,CAAC,KAAiB;IACtC,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzG,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,MAAM,KAAK,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IACxF,CAAC;IACD,qBAAqB,CAAC,MAAM,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from "../../vendor/protocol/session/index.js";
|
|
2
|
+
export { assistantBlockSchema as TimelineAssistantBlockSchema, historyFragmentSchema as HistoryFragmentSchema, imageBlockSchema as TimelineImageBlockSchema, sessionHistoryChunkFrameSchema as SessionHistoryChunkSchema, textBlockSchema as TimelineTextBlockSchema, thinkingBlockSchema as TimelineThinkingBlockSchema, timelineEventFragmentFrameSchema as TimelineEventFragmentSchema, userBlockSchema as TimelineUserBlockSchema, } from "../../vendor/protocol/session/index.js";
|
|
3
|
+
export * from "./marker.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from "../../vendor/protocol/session/index.js";
|
|
2
|
+
export { assistantBlockSchema as TimelineAssistantBlockSchema, historyFragmentSchema as HistoryFragmentSchema, imageBlockSchema as TimelineImageBlockSchema, sessionHistoryChunkFrameSchema as SessionHistoryChunkSchema, textBlockSchema as TimelineTextBlockSchema, thinkingBlockSchema as TimelineThinkingBlockSchema, timelineEventFragmentFrameSchema as TimelineEventFragmentSchema, userBlockSchema as TimelineUserBlockSchema, } from "../../vendor/protocol/session/index.js";
|
|
3
|
+
export * from "./marker.js";
|
|
4
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/protocol/v2/schemas.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EACL,oBAAoB,IAAI,4BAA4B,EACpD,qBAAqB,IAAI,qBAAqB,EAC9C,gBAAgB,IAAI,wBAAwB,EAC5C,8BAA8B,IAAI,yBAAyB,EAC3D,eAAe,IAAI,uBAAuB,EAC1C,mBAAmB,IAAI,2BAA2B,EAClD,gCAAgC,IAAI,2BAA2B,EAC/D,eAAe,IAAI,uBAAuB,GAC3C,MAAM,4BAA4B,CAAC;AACpC,cAAc,aAAa,CAAC"}
|