pi-trace-viewer 0.1.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/src/types.ts ADDED
@@ -0,0 +1,126 @@
1
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
2
+ import type { Api, AssistantMessageEvent, Model, Tool } from "@earendil-works/pi-ai";
3
+ import type { SessionEntry, SessionHeader, ToolInfo } from "@earendil-works/pi-coding-agent";
4
+
5
+ export const TRACE_SCHEMA_VERSION = 1;
6
+
7
+ export type CallKind = "agent" | "compaction" | "branch_summary" | "unknown";
8
+
9
+ export interface TraceModel {
10
+ provider: string;
11
+ id: string;
12
+ api?: string;
13
+ }
14
+
15
+ export interface GenericContext {
16
+ systemPrompt: string;
17
+ messages: AgentMessage[];
18
+ tools: Tool[];
19
+ }
20
+
21
+ export interface CompactionContext {
22
+ reason: "manual" | "threshold" | "overflow";
23
+ willRetry: boolean;
24
+ customInstructions?: string;
25
+ firstKeptEntryId: string;
26
+ isSplitTurn: boolean;
27
+ tokensBefore: number;
28
+ previousSummary?: string;
29
+ messagesToSummarize: AgentMessage[];
30
+ turnPrefixMessages: AgentMessage[];
31
+ settings: { enabled: boolean; reserveTokens: number; keepRecentTokens: number };
32
+ fileOps: { read: string[]; written: string[]; edited: string[] };
33
+ }
34
+
35
+ export interface TraceRecordBase {
36
+ schemaVersion: typeof TRACE_SCHEMA_VERSION;
37
+ sessionId: string;
38
+ sequence: number;
39
+ timestamp: string;
40
+ }
41
+
42
+ export type TraceRecord = TraceRecordBase &
43
+ (
44
+ | { type: "trace_header"; sessionFile?: string; cwd: string }
45
+ | {
46
+ type: "call_started";
47
+ callId: string;
48
+ kind: CallKind;
49
+ turnIndex?: number;
50
+ leafId?: string | null;
51
+ model?: TraceModel;
52
+ captureSource?: "live" | "session_entry";
53
+ sourceEntryId?: string;
54
+ }
55
+ | { type: "generic_context"; callId: string; context: GenericContext }
56
+ | { type: "compaction_context"; callId: string; context: CompactionContext }
57
+ | { type: "provider_request"; callId: string; attempt: number; payload: unknown }
58
+ | {
59
+ type: "provider_response";
60
+ callId: string;
61
+ attempt: number;
62
+ status: number;
63
+ headers: Record<string, string>;
64
+ }
65
+ | { type: "output_event"; callId: string; event: CompactAssistantEvent }
66
+ | { type: "call_completed"; callId: string; message: AgentMessage; leafId?: string | null }
67
+ | { type: "call_failed"; callId: string; error: string }
68
+ | { type: "compaction_completed"; callId: string; summary: string; tokensBefore: number; sourceEntryId?: string }
69
+ | { type: "branch_summary_completed"; callId: string; summary: string; leafId?: string | null }
70
+ );
71
+
72
+ type WithoutPartial<T> = T extends unknown ? Omit<T, "partial"> : never;
73
+ export type CompactAssistantEvent = WithoutPartial<AssistantMessageEvent>;
74
+
75
+ export interface SessionSnapshot {
76
+ id: string;
77
+ name?: string;
78
+ cwd: string;
79
+ file?: string;
80
+ header: SessionHeader | null;
81
+ entries: SessionEntry[];
82
+ leafId: string | null;
83
+ systemPrompt?: string;
84
+ tools: ToolInfo[];
85
+ active: boolean;
86
+ updatedAt: string;
87
+ }
88
+
89
+ export interface SessionRegistration {
90
+ id: string;
91
+ cwd: string;
92
+ file?: string;
93
+ getSnapshot?: () => SessionSnapshot;
94
+ snapshot: SessionSnapshot;
95
+ }
96
+
97
+ export interface TracePersistence {
98
+ status: "persisted" | "memory_only";
99
+ filePath?: string;
100
+ error?: string;
101
+ }
102
+
103
+ export interface CallView {
104
+ callId: string;
105
+ kind: CallKind;
106
+ startedAt: string;
107
+ completedAt?: string;
108
+ turnIndex?: number;
109
+ leafId?: string | null;
110
+ model?: TraceModel;
111
+ captureSource?: "live" | "session_entry";
112
+ sourceEntryId?: string;
113
+ status: "running" | "success" | "error";
114
+ context?: GenericContext;
115
+ compactionContext?: CompactionContext;
116
+ providerRequests: Array<{ attempt: number; timestamp: string; payload: unknown }>;
117
+ providerResponses: Array<{ attempt: number; timestamp: string; status: number; headers: Record<string, string> }>;
118
+ outputEvents: Array<{ timestamp: string; event: CompactAssistantEvent }>;
119
+ finalMessage?: unknown;
120
+ error?: string;
121
+ }
122
+
123
+ export function toTraceModel(model: Model<Api> | undefined): TraceModel | undefined {
124
+ if (!model) return undefined;
125
+ return { provider: model.provider, id: model.id, api: model.api };
126
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2023",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "noEmit": true,
8
+ "allowImportingTsExtensions": true,
9
+ "verbatimModuleSyntax": true,
10
+ "skipLibCheck": true,
11
+ "types": ["node", "vitest/globals"]
12
+ },
13
+ "include": ["src/**/*.ts", "test/**/*.ts"]
14
+ }