cc-wiretap 1.0.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/dist/index.d.ts +313 -0
- package/dist/index.js +968 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/assets/index-Bhvfo4aN.css +1 -0
- package/dist/ui/assets/index-NhZc47IQ.js +14 -0
- package/dist/ui/index.html +14 -0
- package/dist/ui/vite.svg +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import * as mockttp from 'mockttp';
|
|
2
|
+
import { CompletedRequest } from 'mockttp';
|
|
3
|
+
import { Server } from 'http';
|
|
4
|
+
|
|
5
|
+
interface CAConfig {
|
|
6
|
+
certPath: string;
|
|
7
|
+
keyPath: string;
|
|
8
|
+
cert: string;
|
|
9
|
+
key: string;
|
|
10
|
+
}
|
|
11
|
+
declare function loadOrGenerateCA(): Promise<CAConfig>;
|
|
12
|
+
declare function getCAPath(): string;
|
|
13
|
+
|
|
14
|
+
interface ClaudeMessage {
|
|
15
|
+
role: 'user' | 'assistant';
|
|
16
|
+
content: string | ClaudeContent[];
|
|
17
|
+
}
|
|
18
|
+
type ClaudeContent = TextContent | ImageContent | ToolUseContent | ToolResultContent;
|
|
19
|
+
interface TextContent {
|
|
20
|
+
type: 'text';
|
|
21
|
+
text: string;
|
|
22
|
+
}
|
|
23
|
+
interface ImageContent {
|
|
24
|
+
type: 'image';
|
|
25
|
+
source: {
|
|
26
|
+
type: 'base64';
|
|
27
|
+
media_type: string;
|
|
28
|
+
data: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
interface ToolUseContent {
|
|
32
|
+
type: 'tool_use';
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
input: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
interface ToolResultContent {
|
|
38
|
+
type: 'tool_result';
|
|
39
|
+
tool_use_id: string;
|
|
40
|
+
content: string | ClaudeContent[];
|
|
41
|
+
is_error?: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface ClaudeRequest {
|
|
44
|
+
model: string;
|
|
45
|
+
max_tokens: number;
|
|
46
|
+
messages: ClaudeMessage[];
|
|
47
|
+
system?: string | SystemBlock[];
|
|
48
|
+
stream?: boolean;
|
|
49
|
+
tools?: ClaudeTool[];
|
|
50
|
+
tool_choice?: ToolChoice;
|
|
51
|
+
metadata?: Record<string, unknown>;
|
|
52
|
+
stop_sequences?: string[];
|
|
53
|
+
temperature?: number;
|
|
54
|
+
top_p?: number;
|
|
55
|
+
top_k?: number;
|
|
56
|
+
}
|
|
57
|
+
interface SystemBlock {
|
|
58
|
+
type: 'text';
|
|
59
|
+
text: string;
|
|
60
|
+
cache_control?: {
|
|
61
|
+
type: 'ephemeral';
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
interface ClaudeTool {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
input_schema: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
interface ToolChoice {
|
|
70
|
+
type: 'auto' | 'any' | 'tool';
|
|
71
|
+
name?: string;
|
|
72
|
+
}
|
|
73
|
+
interface ClaudeMessageResponse {
|
|
74
|
+
id: string;
|
|
75
|
+
type: 'message';
|
|
76
|
+
role: 'assistant';
|
|
77
|
+
content: ClaudeContent[];
|
|
78
|
+
model: string;
|
|
79
|
+
stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | null;
|
|
80
|
+
stop_sequence: string | null;
|
|
81
|
+
usage: TokenUsage;
|
|
82
|
+
}
|
|
83
|
+
interface ClaudeErrorResponse {
|
|
84
|
+
type: 'error';
|
|
85
|
+
error: {
|
|
86
|
+
type: string;
|
|
87
|
+
message: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
type ClaudeResponse = ClaudeMessageResponse | ClaudeErrorResponse;
|
|
91
|
+
interface TokenUsage {
|
|
92
|
+
input_tokens: number;
|
|
93
|
+
output_tokens: number;
|
|
94
|
+
cache_creation_input_tokens?: number;
|
|
95
|
+
cache_read_input_tokens?: number;
|
|
96
|
+
}
|
|
97
|
+
type SSEEvent = MessageStartEvent | ContentBlockStartEvent | ContentBlockDeltaEvent | ContentBlockStopEvent | MessageDeltaEvent | MessageStopEvent | PingEvent | ErrorEvent;
|
|
98
|
+
interface MessageStartEvent {
|
|
99
|
+
type: 'message_start';
|
|
100
|
+
message: {
|
|
101
|
+
id: string;
|
|
102
|
+
type: 'message';
|
|
103
|
+
role: 'assistant';
|
|
104
|
+
content: [];
|
|
105
|
+
model: string;
|
|
106
|
+
stop_reason: null;
|
|
107
|
+
stop_sequence: null;
|
|
108
|
+
usage: TokenUsage;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
interface ContentBlockStartEvent {
|
|
112
|
+
type: 'content_block_start';
|
|
113
|
+
index: number;
|
|
114
|
+
content_block: TextContent | ToolUseBlockStart;
|
|
115
|
+
}
|
|
116
|
+
interface ToolUseBlockStart {
|
|
117
|
+
type: 'tool_use';
|
|
118
|
+
id: string;
|
|
119
|
+
name: string;
|
|
120
|
+
input: Record<string, unknown>;
|
|
121
|
+
}
|
|
122
|
+
interface ContentBlockDeltaEvent {
|
|
123
|
+
type: 'content_block_delta';
|
|
124
|
+
index: number;
|
|
125
|
+
delta: TextDelta | InputJsonDelta;
|
|
126
|
+
}
|
|
127
|
+
interface TextDelta {
|
|
128
|
+
type: 'text_delta';
|
|
129
|
+
text: string;
|
|
130
|
+
}
|
|
131
|
+
interface InputJsonDelta {
|
|
132
|
+
type: 'input_json_delta';
|
|
133
|
+
partial_json: string;
|
|
134
|
+
}
|
|
135
|
+
interface ContentBlockStopEvent {
|
|
136
|
+
type: 'content_block_stop';
|
|
137
|
+
index: number;
|
|
138
|
+
}
|
|
139
|
+
interface MessageDeltaEvent {
|
|
140
|
+
type: 'message_delta';
|
|
141
|
+
delta: {
|
|
142
|
+
stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use';
|
|
143
|
+
stop_sequence: string | null;
|
|
144
|
+
};
|
|
145
|
+
usage: {
|
|
146
|
+
output_tokens: number;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
interface MessageStopEvent {
|
|
150
|
+
type: 'message_stop';
|
|
151
|
+
}
|
|
152
|
+
interface PingEvent {
|
|
153
|
+
type: 'ping';
|
|
154
|
+
}
|
|
155
|
+
interface ErrorEvent {
|
|
156
|
+
type: 'error';
|
|
157
|
+
error: {
|
|
158
|
+
type: string;
|
|
159
|
+
message: string;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
type WSMessage = WSRequestStart | WSRequestBody | WSResponseStart | WSResponseChunk | WSResponseComplete | WSError | WSClearAll | WSHistorySync;
|
|
163
|
+
interface WSHistorySync {
|
|
164
|
+
type: 'history_sync';
|
|
165
|
+
requests: InterceptedRequest[];
|
|
166
|
+
}
|
|
167
|
+
interface WSClearAll {
|
|
168
|
+
type: 'clear_all';
|
|
169
|
+
}
|
|
170
|
+
interface WSRequestStart {
|
|
171
|
+
type: 'request_start';
|
|
172
|
+
requestId: string;
|
|
173
|
+
timestamp: number;
|
|
174
|
+
method: string;
|
|
175
|
+
url: string;
|
|
176
|
+
headers: Record<string, string>;
|
|
177
|
+
}
|
|
178
|
+
interface WSRequestBody {
|
|
179
|
+
type: 'request_body';
|
|
180
|
+
requestId: string;
|
|
181
|
+
body: ClaudeRequest;
|
|
182
|
+
}
|
|
183
|
+
interface WSResponseStart {
|
|
184
|
+
type: 'response_start';
|
|
185
|
+
requestId: string;
|
|
186
|
+
timestamp: number;
|
|
187
|
+
statusCode: number;
|
|
188
|
+
headers: Record<string, string>;
|
|
189
|
+
}
|
|
190
|
+
interface WSResponseChunk {
|
|
191
|
+
type: 'response_chunk';
|
|
192
|
+
requestId: string;
|
|
193
|
+
event: SSEEvent;
|
|
194
|
+
}
|
|
195
|
+
interface WSResponseComplete {
|
|
196
|
+
type: 'response_complete';
|
|
197
|
+
requestId: string;
|
|
198
|
+
timestamp: number;
|
|
199
|
+
response: ClaudeResponse;
|
|
200
|
+
durationMs: number;
|
|
201
|
+
}
|
|
202
|
+
interface WSError {
|
|
203
|
+
type: 'error';
|
|
204
|
+
requestId?: string;
|
|
205
|
+
error: string;
|
|
206
|
+
timestamp: number;
|
|
207
|
+
}
|
|
208
|
+
interface InterceptedRequest {
|
|
209
|
+
id: string;
|
|
210
|
+
timestamp: number;
|
|
211
|
+
method: string;
|
|
212
|
+
url: string;
|
|
213
|
+
requestHeaders: Record<string, string>;
|
|
214
|
+
requestBody?: ClaudeRequest;
|
|
215
|
+
responseStartTime?: number;
|
|
216
|
+
statusCode?: number;
|
|
217
|
+
responseHeaders?: Record<string, string>;
|
|
218
|
+
sseEvents: SSEEvent[];
|
|
219
|
+
response?: ClaudeResponse;
|
|
220
|
+
durationMs?: number;
|
|
221
|
+
error?: string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
interface WiretapWebSocketServerOptions {
|
|
225
|
+
port?: number;
|
|
226
|
+
server?: Server;
|
|
227
|
+
}
|
|
228
|
+
declare class WiretapWebSocketServer {
|
|
229
|
+
private wss;
|
|
230
|
+
private clients;
|
|
231
|
+
private requests;
|
|
232
|
+
constructor(options?: WiretapWebSocketServerOptions);
|
|
233
|
+
private sendCurrentState;
|
|
234
|
+
private sendToClient;
|
|
235
|
+
broadcast(message: WSMessage): void;
|
|
236
|
+
addRequest(request: InterceptedRequest): void;
|
|
237
|
+
getRequest(requestId: string): InterceptedRequest | undefined;
|
|
238
|
+
getClientCount(): number;
|
|
239
|
+
getRequestCount(): number;
|
|
240
|
+
close(): Promise<void>;
|
|
241
|
+
getPort(): number | undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
declare const CLAUDE_API_HOSTS: string[];
|
|
245
|
+
declare class ClaudeInterceptor {
|
|
246
|
+
private wsServer;
|
|
247
|
+
private activeRequests;
|
|
248
|
+
constructor(wsServer: WiretapWebSocketServer);
|
|
249
|
+
isClaudeRequest(request: CompletedRequest): boolean;
|
|
250
|
+
handleRequest(request: CompletedRequest): Promise<string | null>;
|
|
251
|
+
handleResponseStart(requestId: string, statusCode: number, headers: Record<string, string>): Promise<void>;
|
|
252
|
+
handleResponseChunk(requestId: string, chunk: Buffer | string): void;
|
|
253
|
+
handleResponseComplete(requestId: string): Promise<void>;
|
|
254
|
+
handleResponseError(requestId: string, error: Error): void;
|
|
255
|
+
handleNonStreamingResponse(requestId: string, _statusCode: number, bodyText: string): void;
|
|
256
|
+
private headersToRecord;
|
|
257
|
+
getActiveRequestCount(): number;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
interface ProxyOptions {
|
|
261
|
+
port: number;
|
|
262
|
+
ca: CAConfig;
|
|
263
|
+
wsServer: WiretapWebSocketServer;
|
|
264
|
+
}
|
|
265
|
+
interface ProxyServer {
|
|
266
|
+
server: mockttp.Mockttp;
|
|
267
|
+
interceptor: ClaudeInterceptor;
|
|
268
|
+
stop: () => Promise<void>;
|
|
269
|
+
}
|
|
270
|
+
declare function createProxy(options: ProxyOptions): Promise<ProxyServer>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Parses a complete SSE stream chunk (may contain multiple events)
|
|
274
|
+
*/
|
|
275
|
+
declare function parseSSEChunk(chunk: string): SSEEvent[];
|
|
276
|
+
/**
|
|
277
|
+
* SSE Stream Parser class for handling streaming data
|
|
278
|
+
*/
|
|
279
|
+
declare class SSEStreamParser {
|
|
280
|
+
private buffer;
|
|
281
|
+
private events;
|
|
282
|
+
/**
|
|
283
|
+
* Feed data to the parser
|
|
284
|
+
*/
|
|
285
|
+
feed(data: string): SSEEvent[];
|
|
286
|
+
/**
|
|
287
|
+
* Flush any remaining buffered data
|
|
288
|
+
*/
|
|
289
|
+
flush(): SSEEvent[];
|
|
290
|
+
/**
|
|
291
|
+
* Get all parsed events
|
|
292
|
+
*/
|
|
293
|
+
getAllEvents(): SSEEvent[];
|
|
294
|
+
/**
|
|
295
|
+
* Reset the parser
|
|
296
|
+
*/
|
|
297
|
+
reset(): void;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Reconstructs a complete ClaudeMessageResponse from SSE events.
|
|
301
|
+
* Streaming responses are always message responses (errors are non-streaming).
|
|
302
|
+
*/
|
|
303
|
+
declare function reconstructResponseFromEvents(events: SSEEvent[]): ClaudeMessageResponse | null;
|
|
304
|
+
|
|
305
|
+
declare function createSetupServer(proxyPort: number): Server;
|
|
306
|
+
declare function getSetupCommand(): string;
|
|
307
|
+
|
|
308
|
+
interface UIServerOptions {
|
|
309
|
+
port: number;
|
|
310
|
+
}
|
|
311
|
+
declare function createUIServer(options: UIServerOptions): Server | null;
|
|
312
|
+
|
|
313
|
+
export { CLAUDE_API_HOSTS, type ClaudeContent, type ClaudeErrorResponse, ClaudeInterceptor, type ClaudeMessage, type ClaudeMessageResponse, type ClaudeRequest, type ClaudeResponse, type ClaudeTool, type ContentBlockDeltaEvent, type ContentBlockStartEvent, type ContentBlockStopEvent, type ErrorEvent, type ImageContent, type InputJsonDelta, type InterceptedRequest, type MessageDeltaEvent, type MessageStartEvent, type MessageStopEvent, type PingEvent, type SSEEvent, SSEStreamParser, type SystemBlock, type TextContent, type TextDelta, type TokenUsage, type ToolChoice, type ToolResultContent, type ToolUseBlockStart, type ToolUseContent, type WSClearAll, type WSError, type WSHistorySync, type WSMessage, type WSRequestBody, type WSRequestStart, type WSResponseChunk, type WSResponseComplete, type WSResponseStart, WiretapWebSocketServer, createProxy, createSetupServer, createUIServer, getCAPath, getSetupCommand, loadOrGenerateCA, parseSSEChunk, reconstructResponseFromEvents };
|