11import { z } from 'zod/v4'
22
3- import { costModes } from './old-constants'
43import { GrantTypeValues } from './types/grant'
54import { mcpConfigSchema } from './types/mcp'
65import { toolMessageSchema } from './types/messages/codebuff-message'
7- import {
8- toolResultOutputSchema ,
9- textPartSchema ,
10- imagePartSchema ,
11- } from './types/messages/content-part'
126import { printModeEventSchema } from './types/print-mode'
137import {
148 AgentOutputSchema ,
159 SessionStateSchema ,
1610 toolCallSchema ,
1711} from './types/session-state'
18- import { ProjectFileContextSchema } from './util/file'
12+
13+ import type { CostMode } from './old-constants'
14+ import type { ToolMessage } from './types/messages/codebuff-message'
15+ import type {
16+ TextPart ,
17+ ImagePart ,
18+ ToolResultOutput ,
19+ } from './types/messages/content-part'
20+ import type { SessionState } from './types/session-state'
21+ import type { ProjectFileContext } from './util/file'
1922
2023export const FileChangeSchema = z . object ( {
2124 type : z . enum ( [ 'patch' , 'file' ] ) ,
@@ -26,63 +29,75 @@ export type FileChange = z.infer<typeof FileChangeSchema>
2629export const CHANGES = z . array ( FileChangeSchema )
2730export type FileChanges = z . infer < typeof CHANGES >
2831
29- export const CLIENT_ACTION_SCHEMA = z . discriminatedUnion ( 'type' , [
30- z . object ( {
31- type : z . literal ( 'prompt' ) ,
32- promptId : z . string ( ) ,
33- prompt : z . string ( ) . or ( z . undefined ( ) ) ,
34- content : z . array ( z . union ( [ textPartSchema , imagePartSchema ] ) ) . optional ( ) ,
35- promptParams : z . record ( z . string ( ) , z . any ( ) ) . optional ( ) , // Additional json params.
36- fingerprintId : z . string ( ) ,
37- authToken : z . string ( ) . optional ( ) ,
38- costMode : z . enum ( costModes ) . optional ( ) . default ( 'normal' ) ,
39- sessionState : SessionStateSchema ,
40- toolResults : z . array ( toolMessageSchema ) ,
41- model : z . string ( ) . optional ( ) ,
42- repoUrl : z . string ( ) . optional ( ) ,
43- agentId : z . string ( ) . optional ( ) ,
44- } ) ,
45- z . object ( {
46- type : z . literal ( 'read-files-response' ) ,
47- files : z . record ( z . string ( ) , z . union ( [ z . string ( ) , z . null ( ) ] ) ) ,
48- requestId : z . string ( ) . optional ( ) ,
49- } ) ,
50- z . object ( {
51- type : z . literal ( 'init' ) ,
52- fingerprintId : z . string ( ) ,
53- authToken : z . string ( ) . optional ( ) ,
54- fileContext : ProjectFileContextSchema ,
55- repoUrl : z . string ( ) . optional ( ) ,
56- } ) ,
57- z . object ( {
58- type : z . literal ( 'tool-call-response' ) ,
59- requestId : z . string ( ) ,
60- output : toolResultOutputSchema . array ( ) ,
61- } ) ,
62- z . object ( {
63- type : z . literal ( 'cancel-user-input' ) ,
64- authToken : z . string ( ) ,
65- promptId : z . string ( ) ,
66- } ) ,
67- z . object ( {
68- type : z . literal ( 'mcp-tool-data' ) ,
69- requestId : z . string ( ) ,
70- tools : z
71- . object ( {
72- name : z . string ( ) ,
73- description : z . string ( ) . optional ( ) ,
74- inputSchema : z . looseObject ( {
75- type : z . literal ( 'object' ) ,
76- } ) ,
77- } )
78- . array ( ) ,
79- } ) ,
80- ] )
32+ type ClientActionPrompt = {
33+ type : 'prompt'
34+ promptId : string
35+ prompt : string | undefined
36+ content ?: ( TextPart | ImagePart ) [ ]
37+ promptParams ?: Record < string , any > // Additional json params.
38+ fingerprintId : string
39+ authToken ?: string
40+ costMode ?: CostMode
41+ sessionState : SessionState
42+ toolResults : ToolMessage [ ]
43+ model ?: string
44+ repoUrl ?: string
45+ agentId ?: string
46+ }
47+
48+ type ClientActionReadFilesResponse = {
49+ type : 'read-files-response'
50+ files : Record < string , string | null >
51+ requestId ?: string
52+ }
53+
54+ type ClientActionInit = {
55+ type : 'init'
56+ fingerprintId : string
57+ authToken ?: string
58+ fileContext : ProjectFileContext
59+ repoUrl ?: string
60+ }
61+
62+ type ClientActionToolCallResponse = {
63+ type : 'tool-call-response'
64+ requestId : string
65+ output : ToolResultOutput [ ]
66+ }
67+
68+ type ClientActionCancelUserInput = {
69+ type : 'cancel-user-input'
70+ authToken : string
71+ promptId : string
72+ }
73+
74+ type ClientActionMcpToolData = {
75+ type : 'mcp-tool-data'
76+ requestId : string
77+ tools : {
78+ name : string
79+ description ?: string
80+ inputSchema : { type : 'object' ; [ k : string ] : unknown }
81+ } [ ]
82+ }
8183
82- type ClientActionAny = z . infer < typeof CLIENT_ACTION_SCHEMA >
84+ type ClientActionAny =
85+ | ClientActionPrompt
86+ | ClientActionReadFilesResponse
87+ | ClientActionInit
88+ | ClientActionToolCallResponse
89+ | ClientActionCancelUserInput
90+ | ClientActionMcpToolData
8391export type ClientAction <
8492 T extends ClientActionAny [ 'type' ] = ClientActionAny [ 'type' ] ,
85- > = Extract < ClientActionAny , { type : T } >
93+ > = {
94+ [ K in T ] : Extract <
95+ ClientActionAny ,
96+ {
97+ type : K
98+ }
99+ >
100+ } [ T ]
86101
87102export const UsageReponseSchema = z . object ( {
88103 type : z . literal ( 'usage-response' ) ,
0 commit comments