File size: 1,360 Bytes
4e23b01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { WIRE_PROTOCOL_VERSION } from './migration/migration';
export const AGENT_WIRE_RECORD_KEY = 'wire.jsonl';
export type PartsTransformer = (parts: readonly unknown[]) => Promise<readonly unknown[]>;
export type RecordDehydrator = (
record: WireRecord,
transform: PartsTransformer,
) => WireRecord | Promise<WireRecord>;
export interface WireLineRange {
readonly start: number;
readonly end: number;
}
export interface WireRecord {
readonly type: string;
readonly time?: number;
readonly [key: string]: unknown;
}
export interface WireMetadataRecord extends WireRecord {
readonly type: 'metadata';
readonly protocol_version: string;
readonly created_at: number;
}
export function isWireRecord(record: unknown): record is WireRecord {
return (
record !== null &&
typeof record === 'object' &&
!Array.isArray(record) &&
typeof (record as { type?: unknown }).type === 'string'
);
}
export function createWireMetadataRecord(now = Date.now()): WireMetadataRecord {
return {
type: 'metadata',
protocol_version: WIRE_PROTOCOL_VERSION,
created_at: now,
};
}
export function isWireMetadataRecord(record: WireRecord): record is WireMetadataRecord {
return (
record.type === 'metadata' &&
typeof record['protocol_version'] === 'string' &&
typeof record['created_at'] === 'number'
);
}
|