-
-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathtypes.ts
More file actions
167 lines (145 loc) · 5.01 KB
/
types.ts
File metadata and controls
167 lines (145 loc) · 5.01 KB
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
import {
AgentStateSchema,
AttachmentMetadataSchema,
CodexCollaborationModeSchema,
MetadataSchema,
PermissionModeSchema,
TodosSchema
} from '@hapi/protocol/schemas'
import type { CodexCollaborationMode, PermissionMode } from '@hapi/protocol/types'
import { z } from 'zod'
import { UsageSchema } from '@/claude/types'
export type Usage = z.infer<typeof UsageSchema>
export type {
AgentState,
AttachmentMetadata,
ClaudePermissionMode,
CodexCollaborationMode,
CodexPermissionMode,
Metadata,
Session
} from '@hapi/protocol/types'
export type SessionPermissionMode = PermissionMode
export type SessionCollaborationMode = CodexCollaborationMode
export type SessionModel = string | null
export type SessionEffort = string | null
export { AgentStateSchema, AttachmentMetadataSchema, MetadataSchema }
export const MachineMetadataSchema = z.object({
host: z.string(),
platform: z.string(),
happyCliVersion: z.string(),
displayName: z.string().optional(),
homeDir: z.string(),
happyHomeDir: z.string(),
happyLibDir: z.string()
})
export type MachineMetadata = z.infer<typeof MachineMetadataSchema>
export const RunnerStateSchema = z.object({
status: z.union([z.enum(['running', 'shutting-down']), z.string()]),
pid: z.number().optional(),
httpPort: z.number().optional(),
startedAt: z.number().optional(),
shutdownRequestedAt: z.number().optional(),
shutdownSource: z.union([z.enum(['mobile-app', 'cli', 'os-signal', 'unknown']), z.string()]).optional(),
lastSpawnError: z.object({
message: z.string(),
pid: z.number().optional(),
exitCode: z.number().nullable().optional(),
signal: z.string().nullable().optional(),
at: z.number()
}).nullable().optional()
})
export type RunnerState = z.infer<typeof RunnerStateSchema>
export type Machine = {
id: string
seq: number
createdAt: number
updatedAt: number
active: boolean
activeAt: number
metadata: MachineMetadata | null
metadataVersion: number
runnerState: RunnerState | null
runnerStateVersion: number
}
export const CliMessagesResponseSchema = z.object({
messages: z.array(z.object({
id: z.string(),
seq: z.number(),
createdAt: z.number(),
localId: z.string().nullable().optional(),
content: z.unknown()
}))
})
export type CliMessagesResponse = z.infer<typeof CliMessagesResponseSchema>
export const CreateSessionResponseSchema = z.object({
session: z.object({
id: z.string(),
namespace: z.string(),
seq: z.number(),
createdAt: z.number(),
updatedAt: z.number(),
active: z.boolean(),
activeAt: z.number(),
metadata: z.unknown().nullable(),
metadataVersion: z.number(),
agentState: z.unknown().nullable(),
agentStateVersion: z.number(),
thinking: z.boolean(),
thinkingAt: z.number(),
todos: TodosSchema.optional(),
model: z.string().nullable(),
effort: z.string().nullable(),
permissionMode: PermissionModeSchema.optional(),
collaborationMode: CodexCollaborationModeSchema.optional()
})
})
export type CreateSessionResponse = z.infer<typeof CreateSessionResponseSchema>
export const CreateMachineResponseSchema = z.object({
machine: z.object({
id: z.string(),
seq: z.number(),
createdAt: z.number(),
updatedAt: z.number(),
active: z.boolean(),
activeAt: z.number(),
metadata: z.unknown().nullable(),
metadataVersion: z.number(),
runnerState: z.unknown().nullable(),
runnerStateVersion: z.number()
})
})
export type CreateMachineResponse = z.infer<typeof CreateMachineResponseSchema>
export const MessageMetaSchema = z.object({
sentFrom: z.string().optional(),
fallbackModel: z.string().nullable().optional(),
customSystemPrompt: z.string().nullable().optional(),
appendSystemPrompt: z.string().nullable().optional(),
allowedTools: z.array(z.string()).nullable().optional(),
disallowedTools: z.array(z.string()).nullable().optional(),
isSidechain: z.boolean().optional(),
sidechainKey: z.string().optional()
})
export type MessageMeta = z.infer<typeof MessageMetaSchema>
export const UserMessageSchema = z.object({
role: z.literal('user'),
content: z.object({
type: z.literal('text'),
text: z.string(),
attachments: z.array(AttachmentMetadataSchema).optional()
}),
localKey: z.string().optional(),
meta: MessageMetaSchema.optional()
})
export type UserMessage = z.infer<typeof UserMessageSchema>
export const AgentMessageSchema = z.object({
role: z.literal('agent'),
content: z.object({
type: z.literal('output'),
data: z.unknown()
}),
meta: MessageMetaSchema.optional()
})
export type AgentMessage = z.infer<typeof AgentMessageSchema>
export const MessageContentSchema = z.union([UserMessageSchema, AgentMessageSchema])
export type MessageContent = z.infer<typeof MessageContentSchema>