File size: 6,007 Bytes
6a2bc3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
 * UI-facing compatibility types for the released Webview.
 *
 * The extension host adapts v1 Node SDK events into this shape while the UI is
 * migrated without a visual rewrite. This file contains no legacy SDK runtime.
 */

export type ApprovalResponse = 'approve' | 'approve_for_session' | 'reject';

export type ContentPart =
  | { type: 'text'; text: string }
  | { type: 'think'; think: string; encrypted?: string | null }
  | { type: 'image_url'; image_url: { url: string; id?: string | null } }
  | { type: 'audio_url'; audio_url: { url: string; id?: string | null } }
  | { type: 'video_url'; video_url: { url: string; id?: string | null } };

export interface BriefBlock {
  type: 'brief';
  text: string;
}

export interface DiffBlock {
  type: 'diff';
  path: string;
  old_text: string;
  new_text: string;
}

export interface TodoBlock {
  type: 'todo';
  items: Array<{ title: string; status: 'pending' | 'in_progress' | 'done' }>;
}

export interface ShellBlock {
  type: 'shell';
  language: string;
  command: string;
}

export interface UnknownBlock {
  type: string;
  data?: Record<string, unknown>;
  [key: string]: unknown;
}

export type DisplayBlock = BriefBlock | DiffBlock | TodoBlock | ShellBlock | UnknownBlock;

export interface ToolCall {
  type: 'function';
  id: string;
  function: { name: string; arguments?: string | null };
  extras?: Record<string, unknown> | null;
}

export interface ToolReturnValue {
  is_error: boolean;
  output: string | ContentPart[];
  message: string;
  display: DisplayBlock[];
  extras?: Record<string, unknown> | null;
}

export interface ToolResult {
  tool_call_id: string;
  return_value: ToolReturnValue;
}

export interface TurnBegin {
  user_input: string | ContentPart[];
}

export interface TokenUsage {
  input_other: number;
  output: number;
  input_cache_read: number;
  input_cache_creation: number;
}

export interface StatusUpdate {
  context_usage?: number | null;
  token_usage?: TokenUsage | null;
  message_id?: string | null;
  plan_mode?: boolean | null;
  model?: string | null;
  thinking_effort?: string | null;
  retrying?: {
    next_attempt: number;
    max_attempts: number;
    delay_ms: number;
    message: string;
  } | null;
}

export interface ApprovalRequestPayload {
  id: string;
  tool_call_id: string;
  sender: string;
  action: string;
  description: string;
  display?: DisplayBlock[];
}

export interface QuestionOption {
  label: string;
  description?: string;
}

export interface QuestionItem {
  question: string;
  header?: string;
  options: QuestionOption[];
  multi_select?: boolean;
}

export interface QuestionRequest {
  id: string;
  tool_call_id: string;
  questions: QuestionItem[];
}

export interface QuestionResponse {
  request_id: string;
  answers: Record<string, string>;
}

export interface SubagentEvent {
  parent_tool_call_id: string;
  event: LegacyWireEvent;
}

export type LegacyWireEvent =
  | { type: 'TurnBegin'; payload: TurnBegin & { forkable?: boolean } }
  | { type: 'TurnEnd'; payload: Record<string, never> }
  | { type: 'StepBegin'; payload: { n: number } }
  | { type: 'StepInterrupted'; payload: Record<string, never> }
  | { type: 'CompactionBegin'; payload: Record<string, never> }
  | { type: 'CompactionEnd'; payload: Record<string, never> }
  | { type: 'StatusUpdate'; payload: StatusUpdate }
  | { type: 'ContentPart'; payload: ContentPart }
  | { type: 'ToolCall'; payload: ToolCall }
  | { type: 'ToolCallPart'; payload: { tool_call_id?: string; arguments_part?: string | null } }
  | { type: 'ToolResult'; payload: ToolResult }
  | { type: 'SteerInput'; payload: { user_input: string | ContentPart[] } }
  | { type: 'SubagentEvent'; payload: SubagentEvent }
  | { type: string; payload: unknown };

export type StreamEvent =
  | LegacyWireEvent
  | { type: 'ApprovalRequest'; payload: ApprovalRequestPayload }
  | { type: 'QuestionRequest'; payload: QuestionRequest }
  | { type: 'error'; code: string; message: string; raw?: string };

export interface RunResult {
  status: 'finished' | 'cancelled' | 'max_steps_reached';
  steps?: number;
}

export interface SlashCommandInfo {
  name: string;
  description: string;
  aliases: string[];
}

export interface ModelConfig {
  id: string;
  name: string;
  provider: string;
  capabilities: string[];
  adaptive_thinking?: boolean;
  support_efforts?: string[];
  default_effort?: string;
}

export interface KimiConfig {
  defaultModel: string | null;
  defaultThinking: boolean;
  defaultThinkingEffort?: string;
  models: ModelConfig[];
}

/** Placeholder returned to the Webview instead of a stored MCP credential. */
export const MCP_SECRET_MASK = '••••••••';

export interface MCPServerConfig {
  name: string;
  transport: 'http' | 'stdio';
  url?: string;
  command?: string;
  args?: string[];
  env?: Record<string, string>;
  headers?: Record<string, string>;
  auth?: 'oauth';
  bearerTokenEnvVar?: string;
  /** Unified management view tags; absent on cores predating the management plane. */
  source?: 'global' | 'plugin' | 'caller';
  /** global: defining file path; plugin: plugin id. */
  origin?: string;
  /** false for plugin / project-layer entries — the panel hides mutating actions for them. */
  mutable?: boolean;
}

export interface UpdateMCPServerRequest {
  originalName: string;
  server: MCPServerConfig;
}

export interface SessionInfo {
  id: string;
  workDir: string;
  updatedAt: number;
  brief: string;
}

export type ThinkingMode = 'none' | 'switch' | 'always' | 'effort';

export interface MCPTestResult {
  success: boolean;
  output: string;
}

export interface LoginResult {
  success: boolean;
  error?: string;
}

export function formatContentOutput(output: string | ContentPart[]): string {
  if (typeof output === 'string') return output;
  if (!Array.isArray(output)) return JSON.stringify(output);
  return output
    .map((item) => item.type === 'text' ? item.text : `[${item.type}]`)
    .filter(Boolean)
    .join('\n');
}