kanna-code 0.1.4 → 0.2.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.
@@ -0,0 +1,440 @@
1
+ // Minimal typed subset vendored from `codex app-server generate-ts`.
2
+ // Keep names and field shapes aligned with the official app-server protocol.
3
+
4
+ import type { CodexReasoningEffort, ServiceTier } from "../shared/types"
5
+
6
+ export type CodexRequestId = string | number
7
+
8
+ export interface JsonRpcResponse<TResult = unknown> {
9
+ id: CodexRequestId
10
+ result?: TResult
11
+ error?: {
12
+ code?: number
13
+ message?: string
14
+ }
15
+ }
16
+
17
+ export interface InitializeParams {
18
+ clientInfo: {
19
+ name: string
20
+ title: string
21
+ version: string
22
+ }
23
+ capabilities: {
24
+ experimentalApi: boolean
25
+ }
26
+ }
27
+
28
+ export interface ThreadStartParams {
29
+ model?: string | null
30
+ cwd?: string | null
31
+ serviceTier?: ServiceTier | null
32
+ approvalPolicy?: "never" | "on-request" | "on-failure" | "untrusted" | null
33
+ sandbox?: "read-only" | "workspace-write" | "danger-full-access" | null
34
+ experimentalRawEvents: boolean
35
+ persistExtendedHistory: boolean
36
+ }
37
+
38
+ export interface ThreadResumeParams {
39
+ threadId: string
40
+ model?: string | null
41
+ cwd?: string | null
42
+ serviceTier?: ServiceTier | null
43
+ approvalPolicy?: "never" | "on-request" | "on-failure" | "untrusted" | null
44
+ sandbox?: "read-only" | "workspace-write" | "danger-full-access" | null
45
+ persistExtendedHistory: boolean
46
+ }
47
+
48
+ export interface TextUserInput {
49
+ type: "text"
50
+ text: string
51
+ text_elements: []
52
+ }
53
+
54
+ export type CodexUserInput = TextUserInput
55
+
56
+ export interface CollaborationMode {
57
+ mode: "default" | "plan"
58
+ settings: {
59
+ model: string | null
60
+ reasoning_effort: ReasoningEffort | null
61
+ developer_instructions: string | null
62
+ }
63
+ }
64
+
65
+ export type ReasoningEffort = CodexReasoningEffort
66
+
67
+ export interface TurnStartParams {
68
+ threadId: string
69
+ input: CodexUserInput[]
70
+ approvalPolicy?: "never" | "on-request" | "on-failure" | "untrusted" | null
71
+ model?: string | null
72
+ effort?: ReasoningEffort | null
73
+ serviceTier?: ServiceTier | null
74
+ collaborationMode?: CollaborationMode | null
75
+ }
76
+
77
+ export interface TurnInterruptParams {
78
+ threadId: string
79
+ turnId: string
80
+ }
81
+
82
+ export interface ThreadSummary {
83
+ id: string
84
+ }
85
+
86
+ export interface ThreadStartResponse {
87
+ thread: ThreadSummary
88
+ model: string
89
+ reasoningEffort: ReasoningEffort | null
90
+ }
91
+
92
+ export type ThreadResumeResponse = ThreadStartResponse
93
+
94
+ export interface TurnSummary {
95
+ id: string
96
+ status: "inProgress" | "completed" | "failed" | "interrupted"
97
+ error: {
98
+ message?: string
99
+ } | null
100
+ }
101
+
102
+ export interface TurnStartResponse {
103
+ turn: TurnSummary
104
+ }
105
+
106
+ export interface ThreadStartedNotification {
107
+ thread: ThreadSummary
108
+ }
109
+
110
+ export interface TurnStartedNotification {
111
+ threadId: string
112
+ turn: TurnSummary
113
+ }
114
+
115
+ export interface TurnCompletedNotification {
116
+ threadId: string
117
+ turn: TurnSummary
118
+ }
119
+
120
+ export interface TurnPlanStep {
121
+ step: string
122
+ status: "pending" | "inProgress" | "completed"
123
+ }
124
+
125
+ export interface TurnPlanUpdatedNotification {
126
+ threadId: string
127
+ turnId: string
128
+ explanation: string | null
129
+ plan: TurnPlanStep[]
130
+ }
131
+
132
+ export interface PlanDeltaNotification {
133
+ threadId: string
134
+ turnId: string
135
+ itemId: string
136
+ delta: string
137
+ }
138
+
139
+ export interface ContextCompactedNotification {
140
+ threadId: string
141
+ turnId: string
142
+ }
143
+
144
+ export interface ToolRequestUserInputOption {
145
+ label: string
146
+ description?: string | null
147
+ }
148
+
149
+ export interface ToolRequestUserInputQuestion {
150
+ id: string
151
+ header: string
152
+ question: string
153
+ isOther: boolean
154
+ isSecret: boolean
155
+ options: ToolRequestUserInputOption[] | null
156
+ }
157
+
158
+ export interface ToolRequestUserInputParams {
159
+ threadId: string
160
+ turnId: string
161
+ itemId: string
162
+ questions: ToolRequestUserInputQuestion[]
163
+ }
164
+
165
+ export interface ToolRequestUserInputResponse {
166
+ answers: Record<string, { answers: string[] }>
167
+ }
168
+
169
+ export interface CommandExecutionRequestApprovalParams {
170
+ threadId: string
171
+ turnId: string
172
+ itemId: string
173
+ approvalId?: string | null
174
+ reason?: string | null
175
+ command?: string | null
176
+ cwd?: string | null
177
+ }
178
+
179
+ export interface FileChangeRequestApprovalParams {
180
+ threadId: string
181
+ turnId: string
182
+ itemId: string
183
+ reason?: string | null
184
+ grantRoot?: string | null
185
+ }
186
+
187
+ export type CommandExecutionApprovalDecision =
188
+ | "accept"
189
+ | "acceptForSession"
190
+ | "decline"
191
+ | "cancel"
192
+
193
+ export type FileChangeApprovalDecision =
194
+ | "accept"
195
+ | "acceptForSession"
196
+ | "decline"
197
+ | "cancel"
198
+
199
+ export interface CommandExecutionRequestApprovalResponse {
200
+ decision: CommandExecutionApprovalDecision
201
+ }
202
+
203
+ export interface FileChangeRequestApprovalResponse {
204
+ decision: FileChangeApprovalDecision
205
+ }
206
+
207
+ export interface ToolRequestUserInputRequest {
208
+ id: CodexRequestId
209
+ method: "item/tool/requestUserInput"
210
+ params: ToolRequestUserInputParams
211
+ }
212
+
213
+ export interface DynamicToolCallParams {
214
+ threadId: string
215
+ turnId: string
216
+ callId: string
217
+ tool: string
218
+ arguments: Record<string, unknown> | unknown[] | string | number | boolean | null
219
+ }
220
+
221
+ export interface DynamicToolCallOutputContentItem {
222
+ type: "inputText" | "inputImage"
223
+ text?: string
224
+ imageUrl?: string
225
+ }
226
+
227
+ export interface DynamicToolCallResponse {
228
+ contentItems: DynamicToolCallOutputContentItem[]
229
+ success: boolean
230
+ }
231
+
232
+ export interface DynamicToolCallRequest {
233
+ id: CodexRequestId
234
+ method: "item/tool/call"
235
+ params: DynamicToolCallParams
236
+ }
237
+
238
+ export interface CommandExecutionRequestApprovalRequest {
239
+ id: CodexRequestId
240
+ method: "item/commandExecution/requestApproval"
241
+ params: CommandExecutionRequestApprovalParams
242
+ }
243
+
244
+ export interface FileChangeRequestApprovalRequest {
245
+ id: CodexRequestId
246
+ method: "item/fileChange/requestApproval"
247
+ params: FileChangeRequestApprovalParams
248
+ }
249
+
250
+ export type ServerRequest =
251
+ | ToolRequestUserInputRequest
252
+ | DynamicToolCallRequest
253
+ | CommandExecutionRequestApprovalRequest
254
+ | FileChangeRequestApprovalRequest
255
+
256
+ export interface UserMessageItem {
257
+ type: "userMessage"
258
+ id: string
259
+ content: Array<{
260
+ type: "text"
261
+ text: string
262
+ text_elements: []
263
+ }>
264
+ }
265
+
266
+ export interface ReasoningItem {
267
+ type: "reasoning"
268
+ id: string
269
+ summary: unknown[]
270
+ content: unknown[]
271
+ }
272
+
273
+ export interface AgentMessageItem {
274
+ type: "agentMessage"
275
+ id: string
276
+ text: string
277
+ phase?: string
278
+ }
279
+
280
+ export interface PlanItem {
281
+ type: "plan"
282
+ id: string
283
+ text: string
284
+ }
285
+
286
+ export interface CommandExecutionItem {
287
+ type: "commandExecution"
288
+ id: string
289
+ command: string
290
+ cwd?: string
291
+ processId?: string
292
+ status: "inProgress" | "completed" | "failed" | "declined"
293
+ aggregatedOutput?: string | null
294
+ exitCode?: number | null
295
+ durationMs?: number | null
296
+ }
297
+
298
+ export interface McpToolCallItem {
299
+ type: "mcpToolCall"
300
+ id: string
301
+ server: string
302
+ tool: string
303
+ arguments?: Record<string, unknown> | null
304
+ result?: {
305
+ content?: unknown[]
306
+ structuredContent?: unknown
307
+ } | null
308
+ error?: {
309
+ message?: string
310
+ } | null
311
+ status: "inProgress" | "completed" | "failed"
312
+ }
313
+
314
+ export interface DynamicToolCallItem {
315
+ type: "dynamicToolCall"
316
+ id: string
317
+ tool: string
318
+ arguments?: Record<string, unknown> | unknown[] | string | number | boolean | null
319
+ status: "inProgress" | "completed" | "failed"
320
+ contentItems?: DynamicToolCallOutputContentItem[] | null
321
+ success?: boolean | null
322
+ durationMs?: number | null
323
+ }
324
+
325
+ export interface CollabAgentToolCallItem {
326
+ type: "collabAgentToolCall"
327
+ id: string
328
+ tool: "spawnAgent" | "sendInput" | "resumeAgent" | "wait" | "closeAgent"
329
+ status: "inProgress" | "completed" | "failed"
330
+ senderThreadId: string
331
+ receiverThreadIds: string[]
332
+ prompt?: string | null
333
+ agentsStates?: Record<string, { status: string; message: string | null }> | null
334
+ }
335
+
336
+ export interface WebSearchItem {
337
+ type: "webSearch"
338
+ id: string
339
+ query: string
340
+ action?: {
341
+ type?: string
342
+ query?: string
343
+ queries?: string[]
344
+ } | null
345
+ }
346
+
347
+ export interface FileChangeItem {
348
+ type: "fileChange"
349
+ id: string
350
+ changes: Array<{
351
+ path: string
352
+ kind:
353
+ | "add"
354
+ | "delete"
355
+ | "update"
356
+ | {
357
+ type: "add" | "delete" | "update"
358
+ move_path?: string | null
359
+ }
360
+ diff?: string | null
361
+ }>
362
+ status: "inProgress" | "completed" | "failed" | "declined"
363
+ }
364
+
365
+ export interface ErrorItem {
366
+ type: "error"
367
+ id: string
368
+ message: string
369
+ }
370
+
371
+ export type ThreadItem =
372
+ | UserMessageItem
373
+ | ReasoningItem
374
+ | AgentMessageItem
375
+ | PlanItem
376
+ | CommandExecutionItem
377
+ | McpToolCallItem
378
+ | DynamicToolCallItem
379
+ | CollabAgentToolCallItem
380
+ | WebSearchItem
381
+ | FileChangeItem
382
+ | ErrorItem
383
+
384
+ export interface ItemStartedNotification {
385
+ item: ThreadItem
386
+ threadId: string
387
+ turnId: string
388
+ }
389
+
390
+ export interface ItemCompletedNotification {
391
+ item: ThreadItem
392
+ threadId: string
393
+ turnId: string
394
+ }
395
+
396
+ export interface ErrorNotification {
397
+ message: string
398
+ }
399
+
400
+ export type ServerNotification =
401
+ | { method: "thread/started"; params: ThreadStartedNotification }
402
+ | { method: "turn/started"; params: TurnStartedNotification }
403
+ | { method: "turn/completed"; params: TurnCompletedNotification }
404
+ | { method: "turn/plan/updated"; params: TurnPlanUpdatedNotification }
405
+ | { method: "item/started"; params: ItemStartedNotification }
406
+ | { method: "item/completed"; params: ItemCompletedNotification }
407
+ | { method: "item/plan/delta"; params: PlanDeltaNotification }
408
+ | { method: "thread/compacted"; params: ContextCompactedNotification }
409
+ | { method: "error"; params: ErrorNotification }
410
+
411
+ export function isJsonRpcResponse(value: unknown): value is JsonRpcResponse {
412
+ return Boolean(value) && typeof value === "object" && "id" in (value as Record<string, unknown>)
413
+ && ("result" in (value as Record<string, unknown>) || "error" in (value as Record<string, unknown>))
414
+ && !("method" in (value as Record<string, unknown>))
415
+ }
416
+
417
+ export function isServerRequest(value: unknown): value is ServerRequest {
418
+ if (!value || typeof value !== "object") return false
419
+ const candidate = value as Record<string, unknown>
420
+ if (typeof candidate.method !== "string" || !("id" in candidate)) return false
421
+ return candidate.method === "item/tool/requestUserInput"
422
+ || candidate.method === "item/tool/call"
423
+ || candidate.method === "item/commandExecution/requestApproval"
424
+ || candidate.method === "item/fileChange/requestApproval"
425
+ }
426
+
427
+ export function isServerNotification(value: unknown): value is ServerNotification {
428
+ if (!value || typeof value !== "object") return false
429
+ const candidate = value as Record<string, unknown>
430
+ if (typeof candidate.method !== "string" || "id" in candidate) return false
431
+ return candidate.method === "thread/started"
432
+ || candidate.method === "turn/started"
433
+ || candidate.method === "turn/completed"
434
+ || candidate.method === "turn/plan/updated"
435
+ || candidate.method === "item/started"
436
+ || candidate.method === "item/completed"
437
+ || candidate.method === "item/plan/delta"
438
+ || candidate.method === "thread/compacted"
439
+ || candidate.method === "error"
440
+ }