-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathschemas.ts
More file actions
171 lines (139 loc) · 4.26 KB
/
schemas.ts
File metadata and controls
171 lines (139 loc) · 4.26 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
168
169
170
171
import { z } from "zod";
// Session credentials schema
export const credentialsSchema = z.object({
apiKey: z.string(),
apiHost: z.string(),
projectId: z.number(),
});
export type Credentials = z.infer<typeof credentialsSchema>;
// Agent framework schema
export const agentFrameworkSchema = z.enum(["claude", "codex"]);
export type AgentFramework = z.infer<typeof agentFrameworkSchema>;
// Execution mode schema
export const executionModeSchema = z.enum(["plan"]);
export type ExecutionMode = z.infer<typeof executionModeSchema>;
// Session config schema
export const sessionConfigSchema = z.object({
taskId: z.string(),
taskRunId: z.string(),
repoPath: z.string(),
credentials: credentialsSchema,
logUrl: z.string().optional(),
sdkSessionId: z.string().optional(),
model: z.string().optional(),
framework: agentFrameworkSchema.optional(),
executionMode: executionModeSchema.optional(),
});
export type SessionConfig = z.infer<typeof sessionConfigSchema>;
// Start session input/output
export const startSessionInput = z.object({
taskId: z.string(),
taskRunId: z.string(),
repoPath: z.string(),
apiKey: z.string(),
apiHost: z.string(),
projectId: z.number(),
permissionMode: z.string().optional(),
autoProgress: z.boolean().optional(),
model: z.string().optional(),
framework: agentFrameworkSchema.optional().default("claude"),
executionMode: z.enum(["plan"]).optional(),
runMode: z.enum(["local", "cloud"]).optional(),
createPR: z.boolean().optional(),
});
export type StartSessionInput = z.infer<typeof startSessionInput>;
export const sessionResponseSchema = z.object({
sessionId: z.string(),
channel: z.string(),
});
export type SessionResponse = z.infer<typeof sessionResponseSchema>;
// Prompt input/output
export const contentBlockSchema = z
.object({
type: z.string(),
text: z.string().optional(),
_meta: z.record(z.string(), z.unknown()).optional(),
})
.passthrough();
export const promptInput = z.object({
sessionId: z.string(),
prompt: z.array(contentBlockSchema),
});
export type PromptInput = z.infer<typeof promptInput>;
export const promptOutput = z.object({
stopReason: z.string(),
});
export type PromptOutput = z.infer<typeof promptOutput>;
// Cancel session input
export const cancelSessionInput = z.object({
sessionId: z.string(),
});
// Cancel prompt input
export const cancelPromptInput = z.object({
sessionId: z.string(),
});
// Reconnect session input
export const reconnectSessionInput = z.object({
taskId: z.string(),
taskRunId: z.string(),
repoPath: z.string(),
apiKey: z.string(),
apiHost: z.string(),
projectId: z.number(),
logUrl: z.string().optional(),
sdkSessionId: z.string().optional(),
});
export type ReconnectSessionInput = z.infer<typeof reconnectSessionInput>;
// Token refresh input
export const tokenRefreshInput = z.object({
taskRunId: z.string(),
newToken: z.string(),
});
// Set model input
export const setModelInput = z.object({
sessionId: z.string(),
modelId: z.string(),
});
// Subscribe to session events input
export const subscribeSessionInput = z.object({
sessionId: z.string(),
});
// Agent events
export const AgentServiceEvent = {
SessionEvent: "session-event",
PermissionRequest: "permission-request",
} as const;
export interface AgentSessionEventPayload {
sessionId: string;
payload: unknown;
}
export interface PermissionOption {
kind: "allow_once" | "allow_always" | "reject_once" | "reject_always";
name: string;
optionId: string;
description?: string;
}
export interface PermissionRequestPayload {
sessionId: string;
toolCallId: string;
title: string;
options: PermissionOption[];
rawInput: unknown;
}
export interface AgentServiceEvents {
[AgentServiceEvent.SessionEvent]: AgentSessionEventPayload;
[AgentServiceEvent.PermissionRequest]: PermissionRequestPayload;
}
// Permission response input for tRPC
export const respondToPermissionInput = z.object({
sessionId: z.string(),
toolCallId: z.string(),
optionId: z.string(),
});
export type RespondToPermissionInput = z.infer<typeof respondToPermissionInput>;
// Permission cancellation input for tRPC
export const cancelPermissionInput = z.object({
sessionId: z.string(),
toolCallId: z.string(),
});
export type CancelPermissionInput = z.infer<typeof cancelPermissionInput>;