308 lines
6.5 KiB
TypeScript
308 lines
6.5 KiB
TypeScript
|
|
export type JsonPrimitive = string | number | boolean | null;
|
||
|
|
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
||
|
|
export type JsonObject = { [key: string]: JsonValue };
|
||
|
|
|
||
|
|
export interface HeaderRule {
|
||
|
|
header: string;
|
||
|
|
action: 'block' | 'set' | 'replace';
|
||
|
|
value?: string;
|
||
|
|
find?: string;
|
||
|
|
enabled: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ProxySettings {
|
||
|
|
requestHeaderRules: HeaderRule[];
|
||
|
|
responseHeaderRules: HeaderRule[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface CacheControl {
|
||
|
|
type: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface SystemMessage {
|
||
|
|
text: string;
|
||
|
|
type: string;
|
||
|
|
cache_control?: CacheControl;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ToolInput extends Record<string, unknown> {
|
||
|
|
file_path?: string;
|
||
|
|
old_string?: string;
|
||
|
|
new_string?: string;
|
||
|
|
command?: string;
|
||
|
|
description?: string;
|
||
|
|
offset?: number;
|
||
|
|
limit?: number;
|
||
|
|
replace_all?: boolean;
|
||
|
|
content?: string;
|
||
|
|
pattern?: string;
|
||
|
|
glob?: string;
|
||
|
|
path?: string;
|
||
|
|
prompt?: string;
|
||
|
|
todos?: TodoItem[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ToolParameterSchema extends Record<string, unknown> {
|
||
|
|
type?: string | string[];
|
||
|
|
properties?: Record<string, Record<string, unknown>>;
|
||
|
|
required?: string[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ToolDefinition {
|
||
|
|
name: string;
|
||
|
|
description: string;
|
||
|
|
input_schema?: ToolParameterSchema;
|
||
|
|
parameters?: ToolParameterSchema;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface TodoItem extends Record<string, unknown> {
|
||
|
|
task?: string;
|
||
|
|
description?: string;
|
||
|
|
content?: string;
|
||
|
|
title?: string;
|
||
|
|
text?: string;
|
||
|
|
priority: 'high' | 'medium' | 'low';
|
||
|
|
status: 'pending' | 'in_progress' | 'completed';
|
||
|
|
}
|
||
|
|
|
||
|
|
interface BaseContentBlock extends Record<string, unknown> {
|
||
|
|
type: string;
|
||
|
|
text?: string;
|
||
|
|
name?: string;
|
||
|
|
id?: string;
|
||
|
|
input?: ToolInput;
|
||
|
|
thinking?: string;
|
||
|
|
content?: unknown;
|
||
|
|
tool_use_id?: string;
|
||
|
|
tool_call_id?: string;
|
||
|
|
is_error?: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface TextContentBlock extends BaseContentBlock {
|
||
|
|
type: 'text';
|
||
|
|
text: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ToolUseContentBlock extends BaseContentBlock {
|
||
|
|
type: 'tool_use';
|
||
|
|
id?: string;
|
||
|
|
name?: string;
|
||
|
|
input?: ToolInput;
|
||
|
|
text?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ToolResultContentBlock extends BaseContentBlock {
|
||
|
|
type: 'tool_result';
|
||
|
|
id?: string;
|
||
|
|
tool_use_id?: string;
|
||
|
|
tool_call_id?: string;
|
||
|
|
content?: unknown;
|
||
|
|
text?: string;
|
||
|
|
is_error?: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ImageContentBlock extends BaseContentBlock {
|
||
|
|
type: 'image';
|
||
|
|
source?: {
|
||
|
|
type: string;
|
||
|
|
media_type: string;
|
||
|
|
data: string;
|
||
|
|
};
|
||
|
|
data?: string;
|
||
|
|
media_type?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ThinkingContentBlock extends BaseContentBlock {
|
||
|
|
type: 'thinking';
|
||
|
|
thinking?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface GenericContentBlock extends BaseContentBlock {
|
||
|
|
type: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export type ContentBlock =
|
||
|
|
| TextContentBlock
|
||
|
|
| ToolUseContentBlock
|
||
|
|
| ToolResultContentBlock
|
||
|
|
| ImageContentBlock
|
||
|
|
| ThinkingContentBlock
|
||
|
|
| GenericContentBlock;
|
||
|
|
|
||
|
|
export type MessageContent = string | ContentBlock | ContentBlock[] | Record<string, unknown>;
|
||
|
|
|
||
|
|
export interface RequestMessage {
|
||
|
|
role: string;
|
||
|
|
content: MessageContent;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface PromptGrade {
|
||
|
|
score: number;
|
||
|
|
maxScore?: number;
|
||
|
|
feedback: string;
|
||
|
|
improvedPrompt: string;
|
||
|
|
criteria: Record<string, { score: number; feedback: string }>;
|
||
|
|
gradingTimestamp: string;
|
||
|
|
isProcessing?: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface Request {
|
||
|
|
id: string;
|
||
|
|
conversationId?: string;
|
||
|
|
turnNumber?: number;
|
||
|
|
isRoot?: boolean;
|
||
|
|
timestamp: string;
|
||
|
|
method: string;
|
||
|
|
endpoint: string;
|
||
|
|
headers: Record<string, string[]>;
|
||
|
|
originalModel?: string;
|
||
|
|
routedModel?: string;
|
||
|
|
body?: {
|
||
|
|
model?: string;
|
||
|
|
messages?: RequestMessage[];
|
||
|
|
system?: SystemMessage[];
|
||
|
|
tools?: ToolDefinition[];
|
||
|
|
max_tokens?: number;
|
||
|
|
temperature?: number;
|
||
|
|
stream?: boolean;
|
||
|
|
};
|
||
|
|
response?: {
|
||
|
|
statusCode: number;
|
||
|
|
headers: Record<string, string[]>;
|
||
|
|
body?: {
|
||
|
|
usage?: {
|
||
|
|
input_tokens?: number;
|
||
|
|
output_tokens?: number;
|
||
|
|
cache_creation_input_tokens?: number;
|
||
|
|
cache_read_input_tokens?: number;
|
||
|
|
service_tier?: string;
|
||
|
|
};
|
||
|
|
content?: MessageContent;
|
||
|
|
[key: string]: unknown;
|
||
|
|
};
|
||
|
|
bodyText?: string;
|
||
|
|
responseTime: number;
|
||
|
|
streamingChunks?: string[];
|
||
|
|
isStreaming: boolean;
|
||
|
|
completedAt: string;
|
||
|
|
};
|
||
|
|
promptGrade?: PromptGrade;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ConversationSummary {
|
||
|
|
id: string;
|
||
|
|
requestCount: number;
|
||
|
|
startTime: string;
|
||
|
|
lastActivity: string;
|
||
|
|
duration: number;
|
||
|
|
firstMessage: string;
|
||
|
|
lastMessage: string;
|
||
|
|
projectPath: string;
|
||
|
|
projectName: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface Conversation {
|
||
|
|
sessionId: string;
|
||
|
|
projectPath: string;
|
||
|
|
projectName: string;
|
||
|
|
messages: Array<{
|
||
|
|
parentUuid: string | null;
|
||
|
|
isSidechain: boolean;
|
||
|
|
userType: string;
|
||
|
|
cwd: string;
|
||
|
|
sessionId: string;
|
||
|
|
version: string;
|
||
|
|
type: 'user' | 'assistant' | 'system';
|
||
|
|
message: unknown;
|
||
|
|
uuid: string;
|
||
|
|
timestamp: string;
|
||
|
|
}>;
|
||
|
|
startTime: string;
|
||
|
|
endTime: string;
|
||
|
|
messageCount: number;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface RequestSummary {
|
||
|
|
requestId: string;
|
||
|
|
timestamp: string;
|
||
|
|
method: string;
|
||
|
|
endpoint: string;
|
||
|
|
model?: string;
|
||
|
|
originalModel?: string;
|
||
|
|
routedModel?: string;
|
||
|
|
statusCode?: number;
|
||
|
|
responseTime?: number;
|
||
|
|
usage?: {
|
||
|
|
input_tokens?: number;
|
||
|
|
output_tokens?: number;
|
||
|
|
cache_creation_input_tokens?: number;
|
||
|
|
cache_read_input_tokens?: number;
|
||
|
|
service_tier?: string;
|
||
|
|
};
|
||
|
|
conversationHash?: string;
|
||
|
|
messageCount?: number;
|
||
|
|
stopReason?: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ConversationGroup {
|
||
|
|
conversationHash: string;
|
||
|
|
latestRequest: RequestSummary;
|
||
|
|
turnCount: number;
|
||
|
|
totalTokens: number;
|
||
|
|
totalResponseTime: number;
|
||
|
|
firstTimestamp: string;
|
||
|
|
lastTimestamp: string;
|
||
|
|
requestIds: string[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface DashboardStats {
|
||
|
|
dailyStats: DailyTokens[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface DailyTokens {
|
||
|
|
date: string;
|
||
|
|
tokens: number;
|
||
|
|
requests: number;
|
||
|
|
models?: Record<string, { tokens: number; requests: number }>;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface HourlyStatsResponse {
|
||
|
|
hourlyStats: HourlyTokens[];
|
||
|
|
todayTokens: number;
|
||
|
|
todayRequests: number;
|
||
|
|
avgResponseTime: number;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface HourlyTokens {
|
||
|
|
hour: number;
|
||
|
|
label?: string;
|
||
|
|
tokens: number;
|
||
|
|
requests: number;
|
||
|
|
models?: Record<string, { tokens: number; requests: number }>;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ModelStatsResponse {
|
||
|
|
modelStats: ModelTokens[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ModelTokens {
|
||
|
|
model: string;
|
||
|
|
tokens: number;
|
||
|
|
requests: number;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface UsageStats {
|
||
|
|
total_requests: number;
|
||
|
|
total_input_tokens: number;
|
||
|
|
total_output_tokens: number;
|
||
|
|
total_cache_tokens: number;
|
||
|
|
requests_by_model: Record<string, {
|
||
|
|
request_count: number;
|
||
|
|
input_tokens: number;
|
||
|
|
output_tokens: number;
|
||
|
|
cache_tokens: number;
|
||
|
|
}>;
|
||
|
|
start_date?: string;
|
||
|
|
end_date?: string;
|
||
|
|
}
|