feat: add Pi conversation worker pool

This commit is contained in:
2026-08-22 23:21:46 +08:00
parent 161f3f471b
commit 9f55eec9aa
15 changed files with 3600 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
export const PI_RUNTIME_MILESTONES = [
'worker.queue_wait',
'worker.spawn',
'rpc.ready',
'session.open',
'resources.ready',
'prompt.accepted',
] as const;
export type PiRuntimeMilestone = (typeof PI_RUNTIME_MILESTONES)[number];
export interface PiRuntimeTelemetryEvent {
milestone: PiRuntimeMilestone;
conversationRef: string;
workerGeneration: number;
spanId: string;
runRef?: string;
cold: boolean;
durationMs: number;
at: number;
}
export interface PiRuntimeMilestoneInput {
milestone: PiRuntimeMilestone;
conversationId: string;
workerGeneration: number;
runId?: string;
cold: boolean;
durationMs: number;
at: number;
}
function shortRef(value: string): string {
const normalized = value.replace(/[^A-Za-z0-9]/g, '');
return normalized.slice(-8).toLowerCase() || 'unknown';
}
export function createPiRuntimeTelemetryEvent(
input: PiRuntimeMilestoneInput,
): PiRuntimeTelemetryEvent {
const conversationRef = shortRef(input.conversationId);
const runRef = input.runId ? shortRef(input.runId) : undefined;
return {
milestone: input.milestone,
conversationRef,
workerGeneration: input.workerGeneration,
spanId: runRef
? `${conversationRef}:${runRef}`
: `${conversationRef}:worker-${input.workerGeneration}`,
...(runRef ? { runRef } : {}),
cold: input.cold,
durationMs: Math.max(0, Math.round(input.durationMs)),
at: input.at,
};
}