codex-relay 1.0.1 → 1.0.2
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.
- package/README.md +31 -24
- package/api-schema.ts +1 -0
- package/dist/api-schema.js +2 -0
- package/dist/api-schema2.js +1349 -0
- package/dist/cli.js +39 -20
- package/dist/collaboration-mode-templates/default.md +11 -0
- package/dist/collaboration-mode-templates/execute.md +45 -0
- package/dist/collaboration-mode-templates/pair_programming.md +7 -0
- package/dist/collaboration-mode-templates/plan.md +128 -0
- package/dist/paths.js +25 -0
- package/dist/src.js +5349 -696
- package/package.json +12 -5
- package/src/api-schema.ts +1453 -0
- package/dist/src2.js +0 -2911
|
@@ -0,0 +1,1453 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const IsoDateTimeSchema = z.string().datetime();
|
|
4
|
+
|
|
5
|
+
export const ThreadStateSchema = z.enum(["idle", "running", "completed", "failed"]);
|
|
6
|
+
|
|
7
|
+
export const ChatMessageRoleSchema = z.enum([
|
|
8
|
+
"user",
|
|
9
|
+
"assistant",
|
|
10
|
+
"status",
|
|
11
|
+
"tool",
|
|
12
|
+
"reasoning",
|
|
13
|
+
"error",
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
export const ChatMessageStateSchema = z.enum(["streaming", "completed", "failed"]);
|
|
17
|
+
export const ChatMessageKindSchema = z.enum([
|
|
18
|
+
"chat",
|
|
19
|
+
"thinking",
|
|
20
|
+
"toolActivity",
|
|
21
|
+
"commandExecution",
|
|
22
|
+
"fileChange",
|
|
23
|
+
"plan",
|
|
24
|
+
"approvalRequest",
|
|
25
|
+
"structuredUserInput",
|
|
26
|
+
"subagentAction",
|
|
27
|
+
"webSearch",
|
|
28
|
+
"unknown",
|
|
29
|
+
]);
|
|
30
|
+
export const ApprovalModeSchema = z.enum(["on-request", "on-failure", "never"]);
|
|
31
|
+
export const RuntimeModeSchema = z.enum(["default", "auto", "full-access", "on-request"]);
|
|
32
|
+
export const SandboxModeSchema = z.enum(["workspace-write", "danger-full-access", "read-only"]);
|
|
33
|
+
export const ReasoningEffortSchema = z.enum(["minimal", "low", "medium", "high", "xhigh"]);
|
|
34
|
+
export const ThreadCollaborationModeSchema = z.enum(["default", "plan"]);
|
|
35
|
+
|
|
36
|
+
export const VersionResponseSchema = z.object({
|
|
37
|
+
ok: z.boolean(),
|
|
38
|
+
service: z.literal("codex-relay-server"),
|
|
39
|
+
packageName: z.literal("codex-relay"),
|
|
40
|
+
packageVersion: z.string().min(1),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const ThreadRunOptionsSchema = z.object({
|
|
44
|
+
model: z.string().trim().min(1).optional(),
|
|
45
|
+
runtimeMode: RuntimeModeSchema.optional(),
|
|
46
|
+
approvalPolicy: ApprovalModeSchema.optional(),
|
|
47
|
+
sandboxMode: SandboxModeSchema.optional(),
|
|
48
|
+
reasoningEffort: ReasoningEffortSchema.optional(),
|
|
49
|
+
collaborationMode: ThreadCollaborationModeSchema.optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const RuntimePreferencesSchema = z.object({
|
|
53
|
+
model: z.string().trim().min(1).optional(),
|
|
54
|
+
runtimeMode: RuntimeModeSchema.default("default"),
|
|
55
|
+
reasoningEffort: ReasoningEffortSchema.optional(),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const RuntimePreferencesByWorkspacePathSchema = z.record(
|
|
59
|
+
z.string().trim().min(1),
|
|
60
|
+
RuntimePreferencesSchema,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const UpdateRuntimePreferencesRequestSchema = z.object({
|
|
64
|
+
model: z.string().trim().min(1).nullable().optional(),
|
|
65
|
+
runtimeMode: RuntimeModeSchema.optional(),
|
|
66
|
+
reasoningEffort: ReasoningEffortSchema.nullable().optional(),
|
|
67
|
+
threadId: z.string().trim().min(1).optional(),
|
|
68
|
+
workspacePath: z.string().trim().min(1).optional(),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const RuntimePreferencesResponseSchema = z.object({
|
|
72
|
+
preferences: RuntimePreferencesSchema,
|
|
73
|
+
runtimePreferencesByWorkspacePath: RuntimePreferencesByWorkspacePathSchema.default({}),
|
|
74
|
+
threadId: z.string().trim().min(1).optional(),
|
|
75
|
+
workspacePath: z.string().trim().min(1).optional(),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const CodexModelSchema = z.object({
|
|
79
|
+
id: z.string().min(1),
|
|
80
|
+
model: z.string().min(1),
|
|
81
|
+
displayName: z.string().min(1),
|
|
82
|
+
description: z.string().optional(),
|
|
83
|
+
isDefault: z.boolean().default(false),
|
|
84
|
+
defaultReasoningEffort: ReasoningEffortSchema.optional(),
|
|
85
|
+
supportedReasoningEfforts: z.array(ReasoningEffortSchema).default([]),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
export const AgentSkillSourceSchema = z.enum(["workspace", "personal", "system", "plugin"]);
|
|
89
|
+
|
|
90
|
+
export const AgentSkillSchema = z.object({
|
|
91
|
+
id: z.string().min(1),
|
|
92
|
+
name: z.string().min(1),
|
|
93
|
+
displayName: z.string().min(1),
|
|
94
|
+
description: z.string().optional(),
|
|
95
|
+
path: z.string().trim().min(1),
|
|
96
|
+
source: AgentSkillSourceSchema,
|
|
97
|
+
sourceLabel: z.string().min(1),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export const ContextWindowUsageSchema = z.object({
|
|
101
|
+
tokensUsed: z.number().int().nonnegative(),
|
|
102
|
+
tokenLimit: z.number().int().positive(),
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const RateLimitWindowSchema = z.object({
|
|
106
|
+
usedPercent: z.number().int().min(0).max(100),
|
|
107
|
+
windowDurationMins: z.number().int().positive().nullable().optional(),
|
|
108
|
+
resetsAt: z.number().int().positive().nullable().optional(),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export const RateLimitBucketSchema = z.object({
|
|
112
|
+
limitId: z.string().min(1),
|
|
113
|
+
limitName: z.string().nullable().optional(),
|
|
114
|
+
planType: z.string().nullable().optional(),
|
|
115
|
+
primary: RateLimitWindowSchema.nullable().optional(),
|
|
116
|
+
secondary: RateLimitWindowSchema.nullable().optional(),
|
|
117
|
+
rateLimitReachedType: z.string().nullable().optional(),
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export const RateLimitsResponseSchema = z.object({
|
|
121
|
+
buckets: z.array(RateLimitBucketSchema),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export const ThreadContextWindowResponseSchema = z.object({
|
|
125
|
+
threadId: z.string().min(1),
|
|
126
|
+
usage: ContextWindowUsageSchema.nullable(),
|
|
127
|
+
rolloutPath: z.string().nullable().optional(),
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const PromptAttachmentBaseSchema = z.object({
|
|
131
|
+
type: z.literal("image"),
|
|
132
|
+
mimeType: z.string().trim().startsWith("image/").optional(),
|
|
133
|
+
name: z.string().trim().min(1).max(160).optional(),
|
|
134
|
+
path: z.string().trim().min(1).optional(),
|
|
135
|
+
url: z.string().trim().min(1).optional(),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export const PromptAttachmentSchema = PromptAttachmentBaseSchema.refine(
|
|
139
|
+
(attachment) => Boolean(attachment.path || attachment.url),
|
|
140
|
+
{
|
|
141
|
+
message: "Image attachments require path or url.",
|
|
142
|
+
},
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
export const PromptSkillSchema = AgentSkillSchema.pick({
|
|
146
|
+
name: true,
|
|
147
|
+
path: true,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export const PromptContextSchema = z.object({
|
|
151
|
+
attachments: z.array(PromptAttachmentSchema).max(6).default([]),
|
|
152
|
+
skills: z.array(PromptSkillSchema).max(12).default([]),
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export const PromptContextInputSchema = PromptContextSchema.partial();
|
|
156
|
+
|
|
157
|
+
export const PromptAttachmentSummarySchema = PromptAttachmentBaseSchema.pick({
|
|
158
|
+
mimeType: true,
|
|
159
|
+
name: true,
|
|
160
|
+
path: true,
|
|
161
|
+
type: true,
|
|
162
|
+
url: true,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
export const ChatMessagePromptDetailsSchema = z
|
|
166
|
+
.object({
|
|
167
|
+
attachments: z.array(PromptAttachmentSummarySchema).max(6).optional(),
|
|
168
|
+
})
|
|
169
|
+
.passthrough();
|
|
170
|
+
|
|
171
|
+
export const WorkspaceFileMentionSchema = z.object({
|
|
172
|
+
directory: z.string(),
|
|
173
|
+
kind: z.enum(["directory", "file"]),
|
|
174
|
+
name: z.string().min(1),
|
|
175
|
+
path: z.string().min(1),
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
export const ListWorkspaceFilesResponseSchema = z.object({
|
|
179
|
+
files: z.array(WorkspaceFileMentionSchema),
|
|
180
|
+
query: z.string(),
|
|
181
|
+
workspacePath: z.string().min(1),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export const PendingInputRequestOptionSchema = z.object({
|
|
185
|
+
label: z.string().min(1),
|
|
186
|
+
description: z.string().optional(),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export const PendingInputRequestQuestionSchema = z.object({
|
|
190
|
+
header: z.string().optional(),
|
|
191
|
+
id: z.string().min(1),
|
|
192
|
+
options: z.array(PendingInputRequestOptionSchema).optional(),
|
|
193
|
+
question: z.string().min(1),
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
export const PendingInputRequestSchema = z.object({
|
|
197
|
+
id: z.string().min(1),
|
|
198
|
+
questions: z.array(PendingInputRequestQuestionSchema),
|
|
199
|
+
threadId: z.string().min(1),
|
|
200
|
+
turnId: z.string().optional(),
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
export const ChatMessageSchema = z.object({
|
|
204
|
+
id: z.string().min(1),
|
|
205
|
+
threadId: z.string().min(1),
|
|
206
|
+
role: ChatMessageRoleSchema,
|
|
207
|
+
kind: ChatMessageKindSchema.default("chat"),
|
|
208
|
+
content: z.string(),
|
|
209
|
+
details: z.record(z.string(), z.unknown()).optional(),
|
|
210
|
+
createdAt: IsoDateTimeSchema,
|
|
211
|
+
updatedAt: IsoDateTimeSchema.optional(),
|
|
212
|
+
turnId: z.string().optional(),
|
|
213
|
+
state: ChatMessageStateSchema.optional(),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
export const ThreadSummarySchema = z.object({
|
|
217
|
+
id: z.string().min(1),
|
|
218
|
+
title: z.string().min(1),
|
|
219
|
+
createdAt: IsoDateTimeSchema,
|
|
220
|
+
updatedAt: IsoDateTimeSchema,
|
|
221
|
+
state: ThreadStateSchema,
|
|
222
|
+
model: z.string().optional(),
|
|
223
|
+
runtimeMode: RuntimeModeSchema.optional(),
|
|
224
|
+
approvalPolicy: ApprovalModeSchema.optional(),
|
|
225
|
+
sandboxMode: SandboxModeSchema.optional(),
|
|
226
|
+
reasoningEffort: ReasoningEffortSchema.optional(),
|
|
227
|
+
collaborationMode: ThreadCollaborationModeSchema.optional(),
|
|
228
|
+
cwd: z.string().optional(),
|
|
229
|
+
source: z.string().optional(),
|
|
230
|
+
messageCount: z.number().int().nonnegative().default(0),
|
|
231
|
+
lastMessagePreview: z.string().optional(),
|
|
232
|
+
lastActivityAt: IsoDateTimeSchema.optional(),
|
|
233
|
+
lastPrompt: z.string().optional(),
|
|
234
|
+
lastResult: z.string().optional(),
|
|
235
|
+
lastError: z.string().optional(),
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
export const StatusResponseSchema = z.object({
|
|
239
|
+
ok: z.boolean(),
|
|
240
|
+
service: z.literal("codex-relay-server"),
|
|
241
|
+
sdkAvailable: z.boolean(),
|
|
242
|
+
machineName: z.string().min(1),
|
|
243
|
+
workspacePath: z.string(),
|
|
244
|
+
threadCount: z.number().int().nonnegative(),
|
|
245
|
+
appServerAvailable: z.boolean().default(false),
|
|
246
|
+
preferences: RuntimePreferencesSchema.default({ runtimeMode: "default" }),
|
|
247
|
+
runtimePreferencesByWorkspacePath: RuntimePreferencesByWorkspacePathSchema.default({}),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
export const WorkspaceDirectoryEntrySchema = z.object({
|
|
251
|
+
name: z.string().min(1),
|
|
252
|
+
path: z.string().min(1),
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
export const ListWorkspaceDirectoriesResponseSchema = z.object({
|
|
256
|
+
rootPath: z.string().min(1),
|
|
257
|
+
path: z.string().min(1),
|
|
258
|
+
parentPath: z.string().min(1).nullable(),
|
|
259
|
+
directories: z.array(WorkspaceDirectoryEntrySchema),
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
export const WorkspaceChangesResponseSchema = z.object({
|
|
263
|
+
workspacePath: z.string().min(1),
|
|
264
|
+
status: z.string(),
|
|
265
|
+
diff: z.string(),
|
|
266
|
+
hasChanges: z.boolean(),
|
|
267
|
+
currentBranch: z.string().nullable().default(null),
|
|
268
|
+
branches: z
|
|
269
|
+
.array(
|
|
270
|
+
z.object({
|
|
271
|
+
current: z.boolean().default(false),
|
|
272
|
+
name: z.string().min(1),
|
|
273
|
+
}),
|
|
274
|
+
)
|
|
275
|
+
.default([]),
|
|
276
|
+
stats: z
|
|
277
|
+
.object({
|
|
278
|
+
additions: z.number().int().nonnegative(),
|
|
279
|
+
deletions: z.number().int().nonnegative(),
|
|
280
|
+
filesChanged: z.number().int().nonnegative(),
|
|
281
|
+
})
|
|
282
|
+
.default({ additions: 0, deletions: 0, filesChanged: 0 }),
|
|
283
|
+
files: z
|
|
284
|
+
.array(
|
|
285
|
+
z.object({
|
|
286
|
+
additions: z.number().int().nonnegative(),
|
|
287
|
+
deletions: z.number().int().nonnegative(),
|
|
288
|
+
isBinary: z.boolean().default(false),
|
|
289
|
+
oldPath: z.string().nullable(),
|
|
290
|
+
path: z.string().min(1),
|
|
291
|
+
patch: z.string(),
|
|
292
|
+
stagedStatus: z.string().nullable(),
|
|
293
|
+
status: z.string().min(1),
|
|
294
|
+
worktreeStatus: z.string().nullable(),
|
|
295
|
+
}),
|
|
296
|
+
)
|
|
297
|
+
.default([]),
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
export const WorkspaceSelectionRequestSchema = z.object({
|
|
301
|
+
workspacePath: z.string().trim().min(1).optional(),
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
export const CheckoutWorkspaceBranchRequestSchema = WorkspaceSelectionRequestSchema.extend({
|
|
305
|
+
branch: z
|
|
306
|
+
.string()
|
|
307
|
+
.trim()
|
|
308
|
+
.min(1)
|
|
309
|
+
.refine((branch) => !branch.startsWith("-"), "Branch name cannot start with '-'."),
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
export const CommitPushWorkspaceRequestSchema = WorkspaceSelectionRequestSchema.extend({
|
|
313
|
+
message: z.string().trim().min(1).max(240),
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
export const WorkspaceGitActionResponseSchema = z.object({
|
|
317
|
+
branch: z.string().nullable(),
|
|
318
|
+
message: z.string().min(1),
|
|
319
|
+
output: z.string().default(""),
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
export const WebPreviewTargetSchema = z.object({
|
|
323
|
+
kind: z.literal("web"),
|
|
324
|
+
url: z.string().url(),
|
|
325
|
+
port: z.number().int().positive(),
|
|
326
|
+
label: z.string().min(1).optional(),
|
|
327
|
+
source: z.enum(["detected-port", "codex-output", "user-entered"]),
|
|
328
|
+
confidence: z.enum(["low", "medium", "high"]),
|
|
329
|
+
detectedAt: IsoDateTimeSchema,
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
export const PairRequestSchema = z.object({
|
|
333
|
+
clientSessionId: z.string().trim().min(1).max(120).optional(),
|
|
334
|
+
clientName: z.string().trim().min(1).max(80).optional(),
|
|
335
|
+
secure: z
|
|
336
|
+
.object({
|
|
337
|
+
clientEphemeralPublicKey: z.string().min(1),
|
|
338
|
+
clientNonce: z.string().min(1),
|
|
339
|
+
protocolVersion: z.literal(1),
|
|
340
|
+
})
|
|
341
|
+
.optional(),
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
export const PairResponseSchema = z.object({
|
|
345
|
+
approvalCode: z.string().min(1).optional(),
|
|
346
|
+
approvalExpiresAt: IsoDateTimeSchema.optional(),
|
|
347
|
+
clientToken: z.string().min(1).optional(),
|
|
348
|
+
clientTokenExpiresAt: IsoDateTimeSchema.optional(),
|
|
349
|
+
secure: z
|
|
350
|
+
.object({
|
|
351
|
+
encryptedPayload: z.string().min(1),
|
|
352
|
+
keyEpoch: z.number().int().nonnegative(),
|
|
353
|
+
protocolVersion: z.literal(1),
|
|
354
|
+
serverEphemeralPublicKey: z.string().min(1),
|
|
355
|
+
serverNonce: z.string().min(1),
|
|
356
|
+
serverSignature: z.string().min(1),
|
|
357
|
+
})
|
|
358
|
+
.optional(),
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
export const EncryptedPayloadSchema = z.object({
|
|
362
|
+
ciphertext: z.string().min(1),
|
|
363
|
+
counter: z.number().int().nonnegative(),
|
|
364
|
+
keyEpoch: z.number().int().nonnegative(),
|
|
365
|
+
protocolVersion: z.literal(1),
|
|
366
|
+
sender: z.enum(["mobile", "server"]),
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
export const PairEncryptedPayloadSchema = z.object({
|
|
370
|
+
clientToken: z.string().min(1),
|
|
371
|
+
clientTokenExpiresAt: IsoDateTimeSchema,
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
export const ErrorResponseSchema = z.object({
|
|
375
|
+
error: z.object({
|
|
376
|
+
code: z.string(),
|
|
377
|
+
message: z.string(),
|
|
378
|
+
issues: z.array(z.string()).optional(),
|
|
379
|
+
}),
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
export const CreateThreadRequestSchema = z
|
|
383
|
+
.object({
|
|
384
|
+
prompt: z.string().trim().min(1).optional(),
|
|
385
|
+
title: z.string().trim().min(1).max(120).optional(),
|
|
386
|
+
workspacePath: z.string().trim().min(1).optional(),
|
|
387
|
+
})
|
|
388
|
+
.merge(PromptContextInputSchema)
|
|
389
|
+
.merge(ThreadRunOptionsSchema.partial());
|
|
390
|
+
|
|
391
|
+
export const CreateThreadResponseSchema = z.object({
|
|
392
|
+
thread: ThreadSummarySchema,
|
|
393
|
+
messages: z.array(ChatMessageSchema).default([]),
|
|
394
|
+
result: z.string().optional(),
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
export const RunThreadRequestSchema = z
|
|
398
|
+
.object({
|
|
399
|
+
prompt: z.string().trim().min(1),
|
|
400
|
+
})
|
|
401
|
+
.merge(PromptContextInputSchema)
|
|
402
|
+
.merge(ThreadRunOptionsSchema.partial());
|
|
403
|
+
|
|
404
|
+
export const StreamThreadRunRequestSchema = RunThreadRequestSchema.or(
|
|
405
|
+
ThreadRunOptionsSchema.partial()
|
|
406
|
+
.extend({
|
|
407
|
+
prompt: z.string().trim().min(1).optional(),
|
|
408
|
+
})
|
|
409
|
+
.merge(PromptContextInputSchema),
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
export const RunThreadResponseSchema = z.object({
|
|
413
|
+
thread: ThreadSummarySchema,
|
|
414
|
+
messages: z.array(ChatMessageSchema).default([]),
|
|
415
|
+
result: z.string(),
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
export const ImageAttachmentUploadResponseSchema = z.object({
|
|
419
|
+
attachments: z
|
|
420
|
+
.array(
|
|
421
|
+
PromptAttachmentBaseSchema.pick({
|
|
422
|
+
mimeType: true,
|
|
423
|
+
name: true,
|
|
424
|
+
path: true,
|
|
425
|
+
type: true,
|
|
426
|
+
url: true,
|
|
427
|
+
}).required({
|
|
428
|
+
path: true,
|
|
429
|
+
url: true,
|
|
430
|
+
}),
|
|
431
|
+
)
|
|
432
|
+
.max(6),
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
export const QueuedThreadInputSchema = z.object({
|
|
436
|
+
attachments: PromptContextSchema.shape.attachments,
|
|
437
|
+
id: z.string().min(1),
|
|
438
|
+
prompt: z.string().min(1),
|
|
439
|
+
skills: PromptContextSchema.shape.skills,
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
export const SubmitThreadInputResponseSchema = z.object({
|
|
443
|
+
acceptedAs: z.enum(["steering", "queued"]),
|
|
444
|
+
input: QueuedThreadInputSchema.optional(),
|
|
445
|
+
queueLength: z.number().int().nonnegative(),
|
|
446
|
+
thread: ThreadSummarySchema,
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
export const QueuedThreadInputActionResponseSchema = z.object({
|
|
450
|
+
input: QueuedThreadInputSchema.optional(),
|
|
451
|
+
queueLength: z.number().int().nonnegative(),
|
|
452
|
+
thread: ThreadSummarySchema,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
export const InterruptThreadRunResponseSchema = z.object({
|
|
456
|
+
thread: ThreadSummarySchema,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
export const ListQueuedThreadInputsResponseSchema = z.object({
|
|
460
|
+
inputs: z.array(QueuedThreadInputSchema),
|
|
461
|
+
queueLength: z.number().int().nonnegative(),
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
export const ApprovalDecisionSchema = z.enum(["approve", "approve-for-session", "deny", "cancel"]);
|
|
465
|
+
|
|
466
|
+
export const ResolveApprovalRequestSchema = z.object({
|
|
467
|
+
decision: ApprovalDecisionSchema,
|
|
468
|
+
answers: z.array(z.string()).optional(),
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
export const ResolveApprovalResponseSchema = z.object({
|
|
472
|
+
ok: z.boolean(),
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
export const ListThreadsResponseSchema = z.object({
|
|
476
|
+
threads: z.array(ThreadSummarySchema),
|
|
477
|
+
source: z.enum(["app-server", "memory"]).default("memory"),
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
export const ArchiveThreadResponseSchema = z.object({
|
|
481
|
+
archivedThreadId: z.string().min(1),
|
|
482
|
+
threads: z.array(ThreadSummarySchema),
|
|
483
|
+
source: z.enum(["app-server", "memory"]).default("memory"),
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
export const ListModelsResponseSchema = z.object({
|
|
487
|
+
models: z.array(CodexModelSchema),
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
export const ListSkillsResponseSchema = z.object({
|
|
491
|
+
skills: z.array(AgentSkillSchema),
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
export const ThreadDetailResponseSchema = z.object({
|
|
495
|
+
thread: ThreadSummarySchema,
|
|
496
|
+
messages: z.array(ChatMessageSchema),
|
|
497
|
+
pendingInputRequests: z.array(PendingInputRequestSchema).default([]),
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
export const ThreadMessageDetailFieldSchema = z.enum(["output", "patch"]);
|
|
501
|
+
|
|
502
|
+
export const ThreadMessageDetailResponseSchema = z.object({
|
|
503
|
+
field: ThreadMessageDetailFieldSchema,
|
|
504
|
+
messageId: z.string().min(1),
|
|
505
|
+
originalLength: z.number().int().nonnegative(),
|
|
506
|
+
value: z.string(),
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
export const StreamThreadRunEventSchema = z.discriminatedUnion("type", [
|
|
510
|
+
z.object({
|
|
511
|
+
type: z.literal("thread.message.created"),
|
|
512
|
+
thread: ThreadSummarySchema,
|
|
513
|
+
message: ChatMessageSchema,
|
|
514
|
+
}),
|
|
515
|
+
z.object({
|
|
516
|
+
type: z.literal("thread.message.delta"),
|
|
517
|
+
threadId: z.string().min(1),
|
|
518
|
+
messageId: z.string().min(1),
|
|
519
|
+
delta: z.string(),
|
|
520
|
+
}),
|
|
521
|
+
z.object({
|
|
522
|
+
type: z.literal("thread.message.completed"),
|
|
523
|
+
thread: ThreadSummarySchema,
|
|
524
|
+
message: ChatMessageSchema,
|
|
525
|
+
}),
|
|
526
|
+
z.object({
|
|
527
|
+
type: z.literal("thread.state.changed"),
|
|
528
|
+
thread: ThreadSummarySchema,
|
|
529
|
+
}),
|
|
530
|
+
z.object({
|
|
531
|
+
type: z.literal("thread.error"),
|
|
532
|
+
thread: ThreadSummarySchema.optional(),
|
|
533
|
+
error: ErrorResponseSchema.shape.error,
|
|
534
|
+
}),
|
|
535
|
+
z.object({
|
|
536
|
+
type: z.literal("thread.preview_target.detected"),
|
|
537
|
+
threadId: z.string().min(1),
|
|
538
|
+
target: WebPreviewTargetSchema,
|
|
539
|
+
}),
|
|
540
|
+
z.object({
|
|
541
|
+
type: z.literal("thread.input_request.created"),
|
|
542
|
+
request: PendingInputRequestSchema,
|
|
543
|
+
thread: ThreadSummarySchema,
|
|
544
|
+
}),
|
|
545
|
+
z.object({
|
|
546
|
+
type: z.literal("thread.input_request.resolved"),
|
|
547
|
+
requestId: z.string().min(1),
|
|
548
|
+
threadId: z.string().min(1),
|
|
549
|
+
}),
|
|
550
|
+
]);
|
|
551
|
+
|
|
552
|
+
export type ThreadState = z.infer<typeof ThreadStateSchema>;
|
|
553
|
+
export type ChatMessageRole = z.infer<typeof ChatMessageRoleSchema>;
|
|
554
|
+
export type ChatMessageState = z.infer<typeof ChatMessageStateSchema>;
|
|
555
|
+
export type ChatMessageKind = z.infer<typeof ChatMessageKindSchema>;
|
|
556
|
+
export type ApprovalMode = z.infer<typeof ApprovalModeSchema>;
|
|
557
|
+
export type ReasoningEffort = z.infer<typeof ReasoningEffortSchema>;
|
|
558
|
+
export type RuntimeMode = z.infer<typeof RuntimeModeSchema>;
|
|
559
|
+
export type SandboxMode = z.infer<typeof SandboxModeSchema>;
|
|
560
|
+
export type ThreadCollaborationMode = z.infer<typeof ThreadCollaborationModeSchema>;
|
|
561
|
+
export type ThreadRunOptions = z.infer<typeof ThreadRunOptionsSchema>;
|
|
562
|
+
export type CodexModel = z.infer<typeof CodexModelSchema>;
|
|
563
|
+
export type AgentSkillSource = z.infer<typeof AgentSkillSourceSchema>;
|
|
564
|
+
export type AgentSkill = z.infer<typeof AgentSkillSchema>;
|
|
565
|
+
export type PromptSkill = z.infer<typeof PromptSkillSchema>;
|
|
566
|
+
export type PromptContext = z.infer<typeof PromptContextSchema>;
|
|
567
|
+
export type PromptAttachmentSummary = z.infer<typeof PromptAttachmentSummarySchema>;
|
|
568
|
+
export type ChatMessagePromptDetails = z.infer<typeof ChatMessagePromptDetailsSchema>;
|
|
569
|
+
export type RuntimePreferences = z.infer<typeof RuntimePreferencesSchema>;
|
|
570
|
+
export type RuntimePreferencesByWorkspacePath = z.infer<
|
|
571
|
+
typeof RuntimePreferencesByWorkspacePathSchema
|
|
572
|
+
>;
|
|
573
|
+
export type RuntimePreferencesResponse = z.infer<typeof RuntimePreferencesResponseSchema>;
|
|
574
|
+
export type ContextWindowUsage = z.infer<typeof ContextWindowUsageSchema>;
|
|
575
|
+
export type RateLimitBucket = z.infer<typeof RateLimitBucketSchema>;
|
|
576
|
+
export type RateLimitWindow = z.infer<typeof RateLimitWindowSchema>;
|
|
577
|
+
export type RateLimitsResponse = z.infer<typeof RateLimitsResponseSchema>;
|
|
578
|
+
export type ThreadContextWindowResponse = z.infer<typeof ThreadContextWindowResponseSchema>;
|
|
579
|
+
export type PromptAttachment = z.infer<typeof PromptAttachmentSchema>;
|
|
580
|
+
export type PendingInputRequest = z.infer<typeof PendingInputRequestSchema>;
|
|
581
|
+
export type PendingInputRequestQuestion = z.infer<typeof PendingInputRequestQuestionSchema>;
|
|
582
|
+
export type PendingInputRequestOption = z.infer<typeof PendingInputRequestOptionSchema>;
|
|
583
|
+
export type ChatMessage = z.infer<typeof ChatMessageSchema>;
|
|
584
|
+
export type ThreadSummary = z.infer<typeof ThreadSummarySchema>;
|
|
585
|
+
export type StatusResponse = z.infer<typeof StatusResponseSchema>;
|
|
586
|
+
export type WorkspaceDirectoryEntry = z.infer<typeof WorkspaceDirectoryEntrySchema>;
|
|
587
|
+
export type ListWorkspaceDirectoriesResponse = z.infer<
|
|
588
|
+
typeof ListWorkspaceDirectoriesResponseSchema
|
|
589
|
+
>;
|
|
590
|
+
export type WorkspaceChangesResponse = z.infer<typeof WorkspaceChangesResponseSchema>;
|
|
591
|
+
export type WorkspaceSelectionRequest = z.infer<typeof WorkspaceSelectionRequestSchema>;
|
|
592
|
+
export type CheckoutWorkspaceBranchRequest = z.infer<typeof CheckoutWorkspaceBranchRequestSchema>;
|
|
593
|
+
export type CommitPushWorkspaceRequest = z.infer<typeof CommitPushWorkspaceRequestSchema>;
|
|
594
|
+
export type WorkspaceGitActionResponse = z.infer<typeof WorkspaceGitActionResponseSchema>;
|
|
595
|
+
export type WebPreviewTarget = z.infer<typeof WebPreviewTargetSchema>;
|
|
596
|
+
export type PairRequest = z.infer<typeof PairRequestSchema>;
|
|
597
|
+
export type PairResponse = z.infer<typeof PairResponseSchema>;
|
|
598
|
+
export type EncryptedPayload = z.infer<typeof EncryptedPayloadSchema>;
|
|
599
|
+
export type PairEncryptedPayload = z.infer<typeof PairEncryptedPayloadSchema>;
|
|
600
|
+
export type ErrorResponse = z.infer<typeof ErrorResponseSchema>;
|
|
601
|
+
export type CreateThreadRequest = z.infer<typeof CreateThreadRequestSchema>;
|
|
602
|
+
export type CreateThreadResponse = z.infer<typeof CreateThreadResponseSchema>;
|
|
603
|
+
export type RunThreadRequest = z.infer<typeof RunThreadRequestSchema>;
|
|
604
|
+
export type StreamThreadRunRequest = z.infer<typeof StreamThreadRunRequestSchema>;
|
|
605
|
+
export type RunThreadResponse = z.infer<typeof RunThreadResponseSchema>;
|
|
606
|
+
export type ImageAttachmentUploadResponse = z.infer<typeof ImageAttachmentUploadResponseSchema>;
|
|
607
|
+
export type QueuedThreadInput = z.infer<typeof QueuedThreadInputSchema>;
|
|
608
|
+
export type SubmitThreadInputResponse = z.infer<typeof SubmitThreadInputResponseSchema>;
|
|
609
|
+
export type QueuedThreadInputActionResponse = z.infer<typeof QueuedThreadInputActionResponseSchema>;
|
|
610
|
+
export type InterruptThreadRunResponse = z.infer<typeof InterruptThreadRunResponseSchema>;
|
|
611
|
+
export type ListQueuedThreadInputsResponse = z.infer<typeof ListQueuedThreadInputsResponseSchema>;
|
|
612
|
+
export type ApprovalDecision = z.infer<typeof ApprovalDecisionSchema>;
|
|
613
|
+
export type ResolveApprovalRequest = z.infer<typeof ResolveApprovalRequestSchema>;
|
|
614
|
+
export type ResolveApprovalResponse = z.infer<typeof ResolveApprovalResponseSchema>;
|
|
615
|
+
export type UpdateRuntimePreferencesRequest = z.infer<typeof UpdateRuntimePreferencesRequestSchema>;
|
|
616
|
+
export type VersionResponse = z.infer<typeof VersionResponseSchema>;
|
|
617
|
+
export type ListThreadsResponse = z.infer<typeof ListThreadsResponseSchema>;
|
|
618
|
+
export type ArchiveThreadResponse = z.infer<typeof ArchiveThreadResponseSchema>;
|
|
619
|
+
export type ListModelsResponse = z.infer<typeof ListModelsResponseSchema>;
|
|
620
|
+
export type ListSkillsResponse = z.infer<typeof ListSkillsResponseSchema>;
|
|
621
|
+
export type ListWorkspaceFilesResponse = z.infer<typeof ListWorkspaceFilesResponseSchema>;
|
|
622
|
+
|
|
623
|
+
export function normalizePromptContext(input?: {
|
|
624
|
+
attachments?: PromptAttachment[] | null;
|
|
625
|
+
skills?: PromptSkill[] | null;
|
|
626
|
+
}): PromptContext {
|
|
627
|
+
return PromptContextSchema.parse({
|
|
628
|
+
attachments: input?.attachments ? [...input.attachments] : [],
|
|
629
|
+
skills: input?.skills ? [...input.skills] : [],
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
export function chatMessageDetailsFromPromptContext(
|
|
634
|
+
input: {
|
|
635
|
+
attachments?: PromptAttachment[] | null;
|
|
636
|
+
},
|
|
637
|
+
extraDetails: Record<string, unknown> = {},
|
|
638
|
+
) {
|
|
639
|
+
const context = normalizePromptContext(input);
|
|
640
|
+
const details: Record<string, unknown> = { ...extraDetails };
|
|
641
|
+
|
|
642
|
+
if (context.attachments.length > 0) {
|
|
643
|
+
details.attachments = context.attachments.map(({ mimeType, name, path, type, url }) => ({
|
|
644
|
+
mimeType,
|
|
645
|
+
name,
|
|
646
|
+
path,
|
|
647
|
+
type,
|
|
648
|
+
url,
|
|
649
|
+
}));
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
return Object.keys(details).length > 0 ? details : undefined;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export function promptSkillDisplayName(skill: PromptSkill) {
|
|
656
|
+
const parts = skill.name.split(/[-_:]/).filter(Boolean);
|
|
657
|
+
const displayParts =
|
|
658
|
+
parts.length === 2 && parts[0]?.toLowerCase() === parts[1]?.toLowerCase() ? [parts[1]] : parts;
|
|
659
|
+
return displayParts.filter(Boolean).map(formatPromptSkillDisplayPart).join(" ");
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
function formatPromptSkillDisplayPart(part: string) {
|
|
663
|
+
const knownDisplayParts: Record<string, string> = {
|
|
664
|
+
api: "API",
|
|
665
|
+
github: "GitHub",
|
|
666
|
+
ios: "iOS",
|
|
667
|
+
openai: "OpenAI",
|
|
668
|
+
ota: "OTA",
|
|
669
|
+
pr: "PR",
|
|
670
|
+
qa: "QA",
|
|
671
|
+
ui: "UI",
|
|
672
|
+
ux: "UX",
|
|
673
|
+
};
|
|
674
|
+
return knownDisplayParts[part.toLowerCase()] ?? `${part.charAt(0).toUpperCase()}${part.slice(1)}`;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
export function promptSkillMentionLabel(skill: PromptSkill) {
|
|
678
|
+
return `$${skill.name}`;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export function promptSkillMentionMarkdown(skill: PromptSkill) {
|
|
682
|
+
return `[${escapePromptSkillMarkdownLabel(promptSkillMentionLabel(skill))}](${skill.path})`;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
export function promptMarkdownWithSkills(prompt: string, skills: PromptSkill[]) {
|
|
686
|
+
const seenSkills = new Set<string>();
|
|
687
|
+
const markdown = promptMarkdownWithInlineSkills(prompt, skills, seenSkills).trim();
|
|
688
|
+
const missingSkillMentions = skills
|
|
689
|
+
.filter((skill) => !seenSkills.has(promptSkillKey(skill)))
|
|
690
|
+
.map((skill) => promptSkillMentionMarkdown(skill))
|
|
691
|
+
.join(" ");
|
|
692
|
+
return [markdown, missingSkillMentions]
|
|
693
|
+
.filter(Boolean)
|
|
694
|
+
.join(markdown.includes("\n") ? "\n\n" : " ");
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
export function promptSkillMentionTextCandidates(skill: PromptSkill) {
|
|
698
|
+
const displayName = promptSkillDisplayName(skill);
|
|
699
|
+
return [promptSkillMentionLabel(skill), skill.name, `$${displayName}`, displayName];
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export function isPromptSkillMarkdownMention(label: string, url: string, skills: PromptSkill[]) {
|
|
703
|
+
const mentionText = unescapePromptSkillMarkdownLabel(label).trim();
|
|
704
|
+
const normalizedUrl = safeDecodePromptSkillMarkdownUrl(url);
|
|
705
|
+
return skills.some(
|
|
706
|
+
(skill) =>
|
|
707
|
+
normalizedUrl === skill.path && promptSkillMentionTextCandidates(skill).includes(mentionText),
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export function stripPromptSkillMentions(prompt: string, skills: PromptSkill[]) {
|
|
712
|
+
let nextPrompt = prompt.replace(
|
|
713
|
+
/\[((?:\\.|[^\]\\])*)\]\(([^)]*)\)/g,
|
|
714
|
+
(match, label: string, url: string) =>
|
|
715
|
+
isPromptSkillMarkdownMention(label, url, skills) ? "" : match,
|
|
716
|
+
);
|
|
717
|
+
for (const skill of skills) {
|
|
718
|
+
for (const candidate of promptSkillMentionTextCandidates(skill)) {
|
|
719
|
+
nextPrompt = nextPrompt.replace(
|
|
720
|
+
new RegExp(`(^|\\s)${escapePromptSkillRegExp(candidate)}(?=\\s|$)`, "g"),
|
|
721
|
+
"$1",
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
return nextPrompt.replace(/\s{2,}/g, " ").trim();
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function promptMarkdownWithInlineSkills(
|
|
729
|
+
prompt: string,
|
|
730
|
+
skills: PromptSkill[],
|
|
731
|
+
seenSkills: Set<string>,
|
|
732
|
+
) {
|
|
733
|
+
const linkRegex = /\[((?:\\.|[^\]\\])*)\]\(([^)]*)\)/g;
|
|
734
|
+
let nextPrompt = prompt.replace(linkRegex, (match, label: string, url: string) => {
|
|
735
|
+
const skill = skills.find((candidate) => isPromptSkillMarkdownMention(label, url, [candidate]));
|
|
736
|
+
if (!skill) {
|
|
737
|
+
return match;
|
|
738
|
+
}
|
|
739
|
+
seenSkills.add(promptSkillKey(skill));
|
|
740
|
+
return promptSkillMentionMarkdown(skill);
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
for (const skill of skills) {
|
|
744
|
+
for (const candidate of promptSkillMentionTextCandidates(skill)) {
|
|
745
|
+
nextPrompt = replacePromptSkillTextMention(nextPrompt, candidate, skill, seenSkills);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
return nextPrompt;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function replacePromptSkillTextMention(
|
|
752
|
+
prompt: string,
|
|
753
|
+
candidate: string,
|
|
754
|
+
skill: PromptSkill,
|
|
755
|
+
seenSkills: Set<string>,
|
|
756
|
+
) {
|
|
757
|
+
const linkRegex = /\[((?:\\.|[^\]\\])*)\]\([^)]*\)/g;
|
|
758
|
+
let result = "";
|
|
759
|
+
let cursor = 0;
|
|
760
|
+
let linkMatch: RegExpExecArray | null;
|
|
761
|
+
while ((linkMatch = linkRegex.exec(prompt))) {
|
|
762
|
+
result += replacePromptSkillTextMentionSegment(
|
|
763
|
+
prompt.slice(cursor, linkMatch.index),
|
|
764
|
+
candidate,
|
|
765
|
+
skill,
|
|
766
|
+
seenSkills,
|
|
767
|
+
);
|
|
768
|
+
result += linkMatch[0];
|
|
769
|
+
cursor = linkMatch.index + linkMatch[0].length;
|
|
770
|
+
}
|
|
771
|
+
result += replacePromptSkillTextMentionSegment(
|
|
772
|
+
prompt.slice(cursor),
|
|
773
|
+
candidate,
|
|
774
|
+
skill,
|
|
775
|
+
seenSkills,
|
|
776
|
+
);
|
|
777
|
+
return result;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function replacePromptSkillTextMentionSegment(
|
|
781
|
+
segment: string,
|
|
782
|
+
candidate: string,
|
|
783
|
+
skill: PromptSkill,
|
|
784
|
+
seenSkills: Set<string>,
|
|
785
|
+
) {
|
|
786
|
+
return segment.replace(
|
|
787
|
+
new RegExp(`(^|\\s)${escapePromptSkillRegExp(candidate)}(?=\\s|$)`, "g"),
|
|
788
|
+
(_match, prefix: string) => {
|
|
789
|
+
seenSkills.add(promptSkillKey(skill));
|
|
790
|
+
return `${prefix}${promptSkillMentionMarkdown(skill)}`;
|
|
791
|
+
},
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function promptSkillKey(skill: PromptSkill) {
|
|
796
|
+
return `${skill.name}\n${skill.path}`;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function unescapePromptSkillMarkdownLabel(value: string) {
|
|
800
|
+
return value.replace(/\\([\\[\]])/g, "$1");
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function escapePromptSkillMarkdownLabel(value: string) {
|
|
804
|
+
return value.replaceAll("\\", "\\\\").replaceAll("[", "\\[").replaceAll("]", "\\]");
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
function safeDecodePromptSkillMarkdownUrl(value: string) {
|
|
808
|
+
try {
|
|
809
|
+
return decodeURIComponent(value);
|
|
810
|
+
} catch {
|
|
811
|
+
return value;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function escapePromptSkillRegExp(value: string) {
|
|
816
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
817
|
+
}
|
|
818
|
+
export type ThreadDetailResponse = z.infer<typeof ThreadDetailResponseSchema>;
|
|
819
|
+
export type ThreadMessageDetailField = z.infer<typeof ThreadMessageDetailFieldSchema>;
|
|
820
|
+
export type ThreadMessageDetailResponse = z.infer<typeof ThreadMessageDetailResponseSchema>;
|
|
821
|
+
export type StreamThreadRunEvent = z.infer<typeof StreamThreadRunEventSchema>;
|
|
822
|
+
|
|
823
|
+
export const apiPaths = {
|
|
824
|
+
version: "/version",
|
|
825
|
+
pair: "/v1/pair",
|
|
826
|
+
pairApproval: (approvalCode: string) => `/v1/pair/${encodeURIComponent(approvalCode)}`,
|
|
827
|
+
pairApprove: "/v1/pair/approve",
|
|
828
|
+
sessionRefresh: "/v1/session/refresh",
|
|
829
|
+
status: "/v1/status",
|
|
830
|
+
preferences: "/v1/preferences",
|
|
831
|
+
rateLimits: "/v1/rate-limits",
|
|
832
|
+
models: "/v1/models",
|
|
833
|
+
skills: "/v1/skills",
|
|
834
|
+
workspaceFiles: "/v1/workspace/files",
|
|
835
|
+
workspaceDirectories: "/v1/workspace-directories",
|
|
836
|
+
workspaceChanges: "/v1/workspace/changes",
|
|
837
|
+
workspaceCheckout: "/v1/workspace/checkout",
|
|
838
|
+
workspaceCommitPush: "/v1/workspace/commit-push",
|
|
839
|
+
imageAttachments: "/v1/attachments/images",
|
|
840
|
+
imageAttachment: (attachmentId: string) =>
|
|
841
|
+
`/v1/attachments/images/${encodeURIComponent(attachmentId)}`,
|
|
842
|
+
threads: "/v1/threads",
|
|
843
|
+
thread: (threadId: string) => `/v1/threads/${encodeURIComponent(threadId)}`,
|
|
844
|
+
threadArchive: (threadId: string) => `/v1/threads/${encodeURIComponent(threadId)}`,
|
|
845
|
+
threadContextWindow: (threadId: string) =>
|
|
846
|
+
`/v1/threads/${encodeURIComponent(threadId)}/context-window`,
|
|
847
|
+
threadMessageDetail: (threadId: string, messageId: string, field: ThreadMessageDetailField) =>
|
|
848
|
+
`/v1/threads/${encodeURIComponent(threadId)}/messages/${encodeURIComponent(messageId)}/details/${encodeURIComponent(field)}`,
|
|
849
|
+
approval: (approvalId: string) => `/v1/approvals/${encodeURIComponent(approvalId)}`,
|
|
850
|
+
threadInput: (threadId: string) => `/v1/threads/${encodeURIComponent(threadId)}/input`,
|
|
851
|
+
threadQueuedInput: (threadId: string, inputId: string) =>
|
|
852
|
+
`/v1/threads/${encodeURIComponent(threadId)}/input/${encodeURIComponent(inputId)}`,
|
|
853
|
+
threadQueuedInputSteer: (threadId: string, inputId: string) =>
|
|
854
|
+
`/v1/threads/${encodeURIComponent(threadId)}/input/${encodeURIComponent(inputId)}/steer`,
|
|
855
|
+
threadRuns: (threadId: string) => `/v1/threads/${encodeURIComponent(threadId)}/runs`,
|
|
856
|
+
threadRunInterrupt: (threadId: string) =>
|
|
857
|
+
`/v1/threads/${encodeURIComponent(threadId)}/runs/interrupt`,
|
|
858
|
+
threadRunStream: (threadId: string) => `/v1/threads/${encodeURIComponent(threadId)}/runs/stream`,
|
|
859
|
+
} as const;
|
|
860
|
+
|
|
861
|
+
export function createOpenApiDocument() {
|
|
862
|
+
return {
|
|
863
|
+
openapi: "3.1.0",
|
|
864
|
+
info: {
|
|
865
|
+
title: "Codex Relay Local Codex API",
|
|
866
|
+
version: "0.1.0",
|
|
867
|
+
},
|
|
868
|
+
paths: {
|
|
869
|
+
"/version": {
|
|
870
|
+
get: {
|
|
871
|
+
summary: "Relay package version",
|
|
872
|
+
responses: {
|
|
873
|
+
"200": jsonResponse("VersionResponse"),
|
|
874
|
+
},
|
|
875
|
+
},
|
|
876
|
+
},
|
|
877
|
+
"/v1/status": {
|
|
878
|
+
get: {
|
|
879
|
+
summary: "Local server status",
|
|
880
|
+
responses: {
|
|
881
|
+
"200": jsonResponse("StatusResponse"),
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
},
|
|
885
|
+
"/v1/preferences": {
|
|
886
|
+
patch: {
|
|
887
|
+
summary: "Update default runtime preferences",
|
|
888
|
+
requestBody: jsonRequest("UpdateRuntimePreferencesRequest"),
|
|
889
|
+
responses: {
|
|
890
|
+
"200": jsonResponse("RuntimePreferencesResponse"),
|
|
891
|
+
"400": jsonResponse("ErrorResponse"),
|
|
892
|
+
},
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
"/v1/threads": {
|
|
896
|
+
get: {
|
|
897
|
+
summary: "List locally known threads",
|
|
898
|
+
responses: {
|
|
899
|
+
"200": jsonResponse("ListThreadsResponse"),
|
|
900
|
+
},
|
|
901
|
+
},
|
|
902
|
+
post: {
|
|
903
|
+
summary: "Start a Codex thread",
|
|
904
|
+
requestBody: jsonRequest("CreateThreadRequest"),
|
|
905
|
+
responses: {
|
|
906
|
+
"201": jsonResponse("CreateThreadResponse"),
|
|
907
|
+
"400": jsonResponse("ErrorResponse"),
|
|
908
|
+
},
|
|
909
|
+
},
|
|
910
|
+
},
|
|
911
|
+
"/v1/threads/{threadId}": {
|
|
912
|
+
get: {
|
|
913
|
+
summary: "Read a Codex thread with full available message history",
|
|
914
|
+
parameters: [
|
|
915
|
+
{
|
|
916
|
+
name: "threadId",
|
|
917
|
+
in: "path",
|
|
918
|
+
required: true,
|
|
919
|
+
schema: { type: "string" },
|
|
920
|
+
},
|
|
921
|
+
],
|
|
922
|
+
responses: {
|
|
923
|
+
"200": jsonResponse("ThreadDetailResponse"),
|
|
924
|
+
"404": jsonResponse("ErrorResponse"),
|
|
925
|
+
},
|
|
926
|
+
},
|
|
927
|
+
delete: {
|
|
928
|
+
summary: "Archive a Codex thread",
|
|
929
|
+
parameters: [
|
|
930
|
+
{
|
|
931
|
+
name: "threadId",
|
|
932
|
+
in: "path",
|
|
933
|
+
required: true,
|
|
934
|
+
schema: { type: "string" },
|
|
935
|
+
},
|
|
936
|
+
],
|
|
937
|
+
responses: {
|
|
938
|
+
"200": jsonResponse("ArchiveThreadResponse"),
|
|
939
|
+
"404": jsonResponse("ErrorResponse"),
|
|
940
|
+
"502": jsonResponse("ErrorResponse"),
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
"/v1/workspace-directories": {
|
|
945
|
+
get: {
|
|
946
|
+
summary: "List directories under the configured workspace",
|
|
947
|
+
responses: {
|
|
948
|
+
"200": jsonResponse("ListWorkspaceDirectoriesResponse"),
|
|
949
|
+
"400": jsonResponse("ErrorResponse"),
|
|
950
|
+
},
|
|
951
|
+
},
|
|
952
|
+
},
|
|
953
|
+
"/v1/threads/{threadId}/runs": {
|
|
954
|
+
post: {
|
|
955
|
+
summary: "Run a prompt on a Codex thread",
|
|
956
|
+
parameters: [
|
|
957
|
+
{
|
|
958
|
+
name: "threadId",
|
|
959
|
+
in: "path",
|
|
960
|
+
required: true,
|
|
961
|
+
schema: { type: "string" },
|
|
962
|
+
},
|
|
963
|
+
],
|
|
964
|
+
requestBody: jsonRequest("RunThreadRequest"),
|
|
965
|
+
responses: {
|
|
966
|
+
"200": jsonResponse("RunThreadResponse"),
|
|
967
|
+
"400": jsonResponse("ErrorResponse"),
|
|
968
|
+
"404": jsonResponse("ErrorResponse"),
|
|
969
|
+
},
|
|
970
|
+
},
|
|
971
|
+
},
|
|
972
|
+
"/v1/threads/{threadId}/runs/interrupt": {
|
|
973
|
+
post: {
|
|
974
|
+
summary: "Interrupt the active Codex app-server turn",
|
|
975
|
+
parameters: [
|
|
976
|
+
{
|
|
977
|
+
name: "threadId",
|
|
978
|
+
in: "path",
|
|
979
|
+
required: true,
|
|
980
|
+
schema: { type: "string" },
|
|
981
|
+
},
|
|
982
|
+
],
|
|
983
|
+
responses: {
|
|
984
|
+
"200": jsonResponse("InterruptThreadRunResponse"),
|
|
985
|
+
"404": jsonResponse("ErrorResponse"),
|
|
986
|
+
"409": jsonResponse("ErrorResponse"),
|
|
987
|
+
},
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
"/v1/threads/{threadId}/input": {
|
|
991
|
+
post: {
|
|
992
|
+
summary: "Submit input to an already-running Codex thread",
|
|
993
|
+
requestBody: jsonRequest("RunThreadRequest"),
|
|
994
|
+
responses: {
|
|
995
|
+
"202": jsonResponse("SubmitThreadInputResponse"),
|
|
996
|
+
"400": jsonResponse("ErrorResponse"),
|
|
997
|
+
"404": jsonResponse("ErrorResponse"),
|
|
998
|
+
"409": jsonResponse("ErrorResponse"),
|
|
999
|
+
},
|
|
1000
|
+
},
|
|
1001
|
+
get: {
|
|
1002
|
+
summary: "List queued input for an already-running Codex thread",
|
|
1003
|
+
responses: {
|
|
1004
|
+
"200": jsonResponse("ListQueuedThreadInputsResponse"),
|
|
1005
|
+
"404": jsonResponse("ErrorResponse"),
|
|
1006
|
+
},
|
|
1007
|
+
},
|
|
1008
|
+
},
|
|
1009
|
+
"/v1/threads/{threadId}/runs/stream": {
|
|
1010
|
+
post: {
|
|
1011
|
+
summary: "Run a prompt or attach to an already-running Codex thread and stream events",
|
|
1012
|
+
requestBody: jsonRequest("StreamThreadRunRequest"),
|
|
1013
|
+
responses: {
|
|
1014
|
+
"200": {
|
|
1015
|
+
description: "Server-sent events containing StreamThreadRunEvent payloads",
|
|
1016
|
+
content: {
|
|
1017
|
+
"text/event-stream": {
|
|
1018
|
+
schema: { $ref: "#/components/schemas/StreamThreadRunEvent" },
|
|
1019
|
+
},
|
|
1020
|
+
},
|
|
1021
|
+
},
|
|
1022
|
+
"400": jsonResponse("ErrorResponse"),
|
|
1023
|
+
"404": jsonResponse("ErrorResponse"),
|
|
1024
|
+
},
|
|
1025
|
+
},
|
|
1026
|
+
},
|
|
1027
|
+
},
|
|
1028
|
+
components: {
|
|
1029
|
+
schemas: {
|
|
1030
|
+
ThreadState: { type: "string", enum: ThreadStateSchema.options },
|
|
1031
|
+
ChatMessage: {
|
|
1032
|
+
type: "object",
|
|
1033
|
+
required: ["id", "threadId", "role", "content", "createdAt"],
|
|
1034
|
+
properties: {
|
|
1035
|
+
id: { type: "string" },
|
|
1036
|
+
threadId: { type: "string" },
|
|
1037
|
+
role: { type: "string", enum: ChatMessageRoleSchema.options },
|
|
1038
|
+
kind: { type: "string", enum: ChatMessageKindSchema.options },
|
|
1039
|
+
content: { type: "string" },
|
|
1040
|
+
details: { type: "object", additionalProperties: true },
|
|
1041
|
+
createdAt: { type: "string", format: "date-time" },
|
|
1042
|
+
updatedAt: { type: "string", format: "date-time" },
|
|
1043
|
+
turnId: { type: "string" },
|
|
1044
|
+
state: { type: "string", enum: ChatMessageStateSchema.options },
|
|
1045
|
+
},
|
|
1046
|
+
},
|
|
1047
|
+
ThreadSummary: {
|
|
1048
|
+
type: "object",
|
|
1049
|
+
required: ["id", "title", "createdAt", "updatedAt", "state", "messageCount"],
|
|
1050
|
+
properties: {
|
|
1051
|
+
id: { type: "string" },
|
|
1052
|
+
title: { type: "string" },
|
|
1053
|
+
createdAt: { type: "string", format: "date-time" },
|
|
1054
|
+
updatedAt: { type: "string", format: "date-time" },
|
|
1055
|
+
state: { $ref: "#/components/schemas/ThreadState" },
|
|
1056
|
+
messageCount: { type: "integer", minimum: 0 },
|
|
1057
|
+
model: { type: "string" },
|
|
1058
|
+
runtimeMode: { $ref: "#/components/schemas/RuntimeMode" },
|
|
1059
|
+
approvalPolicy: { type: "string", enum: ["on-request", "on-failure", "never"] },
|
|
1060
|
+
sandboxMode: {
|
|
1061
|
+
type: "string",
|
|
1062
|
+
enum: ["workspace-write", "danger-full-access", "read-only"],
|
|
1063
|
+
},
|
|
1064
|
+
reasoningEffort: { $ref: "#/components/schemas/ReasoningEffort" },
|
|
1065
|
+
cwd: { type: "string" },
|
|
1066
|
+
source: { type: "string" },
|
|
1067
|
+
lastMessagePreview: { type: "string" },
|
|
1068
|
+
lastActivityAt: { type: "string", format: "date-time" },
|
|
1069
|
+
lastPrompt: { type: "string" },
|
|
1070
|
+
lastResult: { type: "string" },
|
|
1071
|
+
lastError: { type: "string" },
|
|
1072
|
+
},
|
|
1073
|
+
},
|
|
1074
|
+
StatusResponse: {
|
|
1075
|
+
type: "object",
|
|
1076
|
+
required: [
|
|
1077
|
+
"ok",
|
|
1078
|
+
"service",
|
|
1079
|
+
"sdkAvailable",
|
|
1080
|
+
"machineName",
|
|
1081
|
+
"workspacePath",
|
|
1082
|
+
"threadCount",
|
|
1083
|
+
],
|
|
1084
|
+
properties: {
|
|
1085
|
+
ok: { type: "boolean" },
|
|
1086
|
+
service: { type: "string", const: "codex-relay-server" },
|
|
1087
|
+
sdkAvailable: { type: "boolean" },
|
|
1088
|
+
machineName: { type: "string" },
|
|
1089
|
+
workspacePath: { type: "string" },
|
|
1090
|
+
threadCount: { type: "integer", minimum: 0 },
|
|
1091
|
+
appServerAvailable: { type: "boolean" },
|
|
1092
|
+
preferences: { $ref: "#/components/schemas/RuntimePreferences" },
|
|
1093
|
+
runtimePreferencesByWorkspacePath: {
|
|
1094
|
+
type: "object",
|
|
1095
|
+
additionalProperties: { $ref: "#/components/schemas/RuntimePreferences" },
|
|
1096
|
+
},
|
|
1097
|
+
},
|
|
1098
|
+
},
|
|
1099
|
+
VersionResponse: {
|
|
1100
|
+
type: "object",
|
|
1101
|
+
required: ["ok", "service", "packageName", "packageVersion"],
|
|
1102
|
+
properties: {
|
|
1103
|
+
ok: { type: "boolean" },
|
|
1104
|
+
service: { type: "string", const: "codex-relay-server" },
|
|
1105
|
+
packageName: { type: "string", const: "codex-relay" },
|
|
1106
|
+
packageVersion: { type: "string" },
|
|
1107
|
+
},
|
|
1108
|
+
},
|
|
1109
|
+
RuntimePreferences: {
|
|
1110
|
+
type: "object",
|
|
1111
|
+
required: ["runtimeMode"],
|
|
1112
|
+
properties: {
|
|
1113
|
+
model: { type: "string" },
|
|
1114
|
+
runtimeMode: {
|
|
1115
|
+
type: "string",
|
|
1116
|
+
enum: ["default", "auto", "full-access", "on-request"],
|
|
1117
|
+
default: "default",
|
|
1118
|
+
},
|
|
1119
|
+
reasoningEffort: {
|
|
1120
|
+
type: "string",
|
|
1121
|
+
enum: ["minimal", "low", "medium", "high", "xhigh"],
|
|
1122
|
+
},
|
|
1123
|
+
},
|
|
1124
|
+
},
|
|
1125
|
+
UpdateRuntimePreferencesRequest: {
|
|
1126
|
+
type: "object",
|
|
1127
|
+
properties: {
|
|
1128
|
+
threadId: { type: "string" },
|
|
1129
|
+
workspacePath: { type: "string" },
|
|
1130
|
+
model: { type: "string", nullable: true },
|
|
1131
|
+
runtimeMode: {
|
|
1132
|
+
type: "string",
|
|
1133
|
+
enum: ["default", "auto", "full-access", "on-request"],
|
|
1134
|
+
},
|
|
1135
|
+
reasoningEffort: {
|
|
1136
|
+
type: "string",
|
|
1137
|
+
enum: ["minimal", "low", "medium", "high", "xhigh"],
|
|
1138
|
+
nullable: true,
|
|
1139
|
+
},
|
|
1140
|
+
},
|
|
1141
|
+
},
|
|
1142
|
+
RuntimePreferencesResponse: {
|
|
1143
|
+
type: "object",
|
|
1144
|
+
required: ["preferences"],
|
|
1145
|
+
properties: {
|
|
1146
|
+
preferences: { $ref: "#/components/schemas/RuntimePreferences" },
|
|
1147
|
+
runtimePreferencesByWorkspacePath: {
|
|
1148
|
+
type: "object",
|
|
1149
|
+
additionalProperties: { $ref: "#/components/schemas/RuntimePreferences" },
|
|
1150
|
+
},
|
|
1151
|
+
threadId: { type: "string" },
|
|
1152
|
+
workspacePath: { type: "string" },
|
|
1153
|
+
},
|
|
1154
|
+
},
|
|
1155
|
+
WorkspaceDirectoryEntry: {
|
|
1156
|
+
type: "object",
|
|
1157
|
+
required: ["name", "path"],
|
|
1158
|
+
properties: {
|
|
1159
|
+
name: { type: "string" },
|
|
1160
|
+
path: { type: "string" },
|
|
1161
|
+
},
|
|
1162
|
+
},
|
|
1163
|
+
ListWorkspaceDirectoriesResponse: {
|
|
1164
|
+
type: "object",
|
|
1165
|
+
required: ["rootPath", "path", "parentPath", "directories"],
|
|
1166
|
+
properties: {
|
|
1167
|
+
rootPath: { type: "string" },
|
|
1168
|
+
path: { type: "string" },
|
|
1169
|
+
parentPath: { type: "string", nullable: true },
|
|
1170
|
+
directories: {
|
|
1171
|
+
type: "array",
|
|
1172
|
+
items: { $ref: "#/components/schemas/WorkspaceDirectoryEntry" },
|
|
1173
|
+
},
|
|
1174
|
+
},
|
|
1175
|
+
},
|
|
1176
|
+
CreateThreadRequest: {
|
|
1177
|
+
type: "object",
|
|
1178
|
+
properties: {
|
|
1179
|
+
attachments: {
|
|
1180
|
+
type: "array",
|
|
1181
|
+
maxItems: 6,
|
|
1182
|
+
items: { $ref: "#/components/schemas/PromptAttachment" },
|
|
1183
|
+
},
|
|
1184
|
+
prompt: { type: "string" },
|
|
1185
|
+
skills: {
|
|
1186
|
+
type: "array",
|
|
1187
|
+
maxItems: 12,
|
|
1188
|
+
items: { $ref: "#/components/schemas/PromptSkill" },
|
|
1189
|
+
},
|
|
1190
|
+
title: { type: "string", maxLength: 120 },
|
|
1191
|
+
workspacePath: { type: "string" },
|
|
1192
|
+
collaborationMode: { type: "string", enum: ["default", "plan"], default: "default" },
|
|
1193
|
+
},
|
|
1194
|
+
},
|
|
1195
|
+
PromptAttachment: {
|
|
1196
|
+
type: "object",
|
|
1197
|
+
required: ["type"],
|
|
1198
|
+
properties: {
|
|
1199
|
+
type: { type: "string", const: "image" },
|
|
1200
|
+
mimeType: { type: "string", pattern: "^image/" },
|
|
1201
|
+
name: { type: "string", maxLength: 160 },
|
|
1202
|
+
path: { type: "string" },
|
|
1203
|
+
url: { type: "string" },
|
|
1204
|
+
},
|
|
1205
|
+
},
|
|
1206
|
+
PromptSkill: {
|
|
1207
|
+
type: "object",
|
|
1208
|
+
required: ["name", "path"],
|
|
1209
|
+
properties: {
|
|
1210
|
+
name: { type: "string" },
|
|
1211
|
+
path: { type: "string" },
|
|
1212
|
+
},
|
|
1213
|
+
},
|
|
1214
|
+
CreateThreadResponse: {
|
|
1215
|
+
type: "object",
|
|
1216
|
+
required: ["thread"],
|
|
1217
|
+
properties: {
|
|
1218
|
+
thread: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1219
|
+
messages: { type: "array", items: { $ref: "#/components/schemas/ChatMessage" } },
|
|
1220
|
+
result: { type: "string" },
|
|
1221
|
+
},
|
|
1222
|
+
},
|
|
1223
|
+
RunThreadRequest: {
|
|
1224
|
+
type: "object",
|
|
1225
|
+
required: ["prompt"],
|
|
1226
|
+
properties: {
|
|
1227
|
+
attachments: {
|
|
1228
|
+
type: "array",
|
|
1229
|
+
maxItems: 6,
|
|
1230
|
+
items: { $ref: "#/components/schemas/PromptAttachment" },
|
|
1231
|
+
},
|
|
1232
|
+
prompt: { type: "string" },
|
|
1233
|
+
skills: {
|
|
1234
|
+
type: "array",
|
|
1235
|
+
maxItems: 12,
|
|
1236
|
+
items: { $ref: "#/components/schemas/PromptSkill" },
|
|
1237
|
+
},
|
|
1238
|
+
collaborationMode: { type: "string", enum: ["default", "plan"], default: "default" },
|
|
1239
|
+
},
|
|
1240
|
+
},
|
|
1241
|
+
StreamThreadRunRequest: {
|
|
1242
|
+
type: "object",
|
|
1243
|
+
properties: {
|
|
1244
|
+
attachments: {
|
|
1245
|
+
type: "array",
|
|
1246
|
+
maxItems: 6,
|
|
1247
|
+
items: { $ref: "#/components/schemas/PromptAttachment" },
|
|
1248
|
+
},
|
|
1249
|
+
prompt: { type: "string" },
|
|
1250
|
+
skills: {
|
|
1251
|
+
type: "array",
|
|
1252
|
+
maxItems: 12,
|
|
1253
|
+
items: { $ref: "#/components/schemas/PromptSkill" },
|
|
1254
|
+
},
|
|
1255
|
+
collaborationMode: { type: "string", enum: ["default", "plan"], default: "default" },
|
|
1256
|
+
},
|
|
1257
|
+
},
|
|
1258
|
+
RunThreadResponse: {
|
|
1259
|
+
type: "object",
|
|
1260
|
+
required: ["thread", "result"],
|
|
1261
|
+
properties: {
|
|
1262
|
+
thread: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1263
|
+
messages: { type: "array", items: { $ref: "#/components/schemas/ChatMessage" } },
|
|
1264
|
+
result: { type: "string" },
|
|
1265
|
+
},
|
|
1266
|
+
},
|
|
1267
|
+
SubmitThreadInputResponse: {
|
|
1268
|
+
type: "object",
|
|
1269
|
+
required: ["acceptedAs", "queueLength", "thread"],
|
|
1270
|
+
properties: {
|
|
1271
|
+
acceptedAs: { type: "string", enum: ["steering", "queued"] },
|
|
1272
|
+
input: { $ref: "#/components/schemas/QueuedThreadInput" },
|
|
1273
|
+
queueLength: { type: "integer", minimum: 0 },
|
|
1274
|
+
thread: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1275
|
+
},
|
|
1276
|
+
},
|
|
1277
|
+
QueuedThreadInput: {
|
|
1278
|
+
type: "object",
|
|
1279
|
+
required: ["attachments", "id", "prompt", "skills"],
|
|
1280
|
+
properties: {
|
|
1281
|
+
attachments: {
|
|
1282
|
+
type: "array",
|
|
1283
|
+
maxItems: 6,
|
|
1284
|
+
items: { $ref: "#/components/schemas/PromptAttachment" },
|
|
1285
|
+
},
|
|
1286
|
+
id: { type: "string" },
|
|
1287
|
+
prompt: { type: "string" },
|
|
1288
|
+
skills: {
|
|
1289
|
+
type: "array",
|
|
1290
|
+
maxItems: 12,
|
|
1291
|
+
items: { $ref: "#/components/schemas/PromptSkill" },
|
|
1292
|
+
},
|
|
1293
|
+
},
|
|
1294
|
+
},
|
|
1295
|
+
QueuedThreadInputActionResponse: {
|
|
1296
|
+
type: "object",
|
|
1297
|
+
required: ["queueLength", "thread"],
|
|
1298
|
+
properties: {
|
|
1299
|
+
input: { $ref: "#/components/schemas/QueuedThreadInput" },
|
|
1300
|
+
queueLength: { type: "integer", minimum: 0 },
|
|
1301
|
+
thread: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1302
|
+
},
|
|
1303
|
+
},
|
|
1304
|
+
InterruptThreadRunResponse: {
|
|
1305
|
+
type: "object",
|
|
1306
|
+
required: ["thread"],
|
|
1307
|
+
properties: {
|
|
1308
|
+
thread: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1309
|
+
},
|
|
1310
|
+
},
|
|
1311
|
+
ListQueuedThreadInputsResponse: {
|
|
1312
|
+
type: "object",
|
|
1313
|
+
required: ["inputs", "queueLength"],
|
|
1314
|
+
properties: {
|
|
1315
|
+
inputs: {
|
|
1316
|
+
type: "array",
|
|
1317
|
+
items: { $ref: "#/components/schemas/QueuedThreadInput" },
|
|
1318
|
+
},
|
|
1319
|
+
queueLength: { type: "integer", minimum: 0 },
|
|
1320
|
+
},
|
|
1321
|
+
},
|
|
1322
|
+
PendingInputRequest: {
|
|
1323
|
+
type: "object",
|
|
1324
|
+
required: ["id", "questions", "threadId"],
|
|
1325
|
+
properties: {
|
|
1326
|
+
id: { type: "string" },
|
|
1327
|
+
questions: {
|
|
1328
|
+
type: "array",
|
|
1329
|
+
items: { $ref: "#/components/schemas/PendingInputRequestQuestion" },
|
|
1330
|
+
},
|
|
1331
|
+
threadId: { type: "string" },
|
|
1332
|
+
turnId: { type: "string" },
|
|
1333
|
+
},
|
|
1334
|
+
},
|
|
1335
|
+
PendingInputRequestQuestion: {
|
|
1336
|
+
type: "object",
|
|
1337
|
+
required: ["id", "question"],
|
|
1338
|
+
properties: {
|
|
1339
|
+
header: { type: "string" },
|
|
1340
|
+
id: { type: "string" },
|
|
1341
|
+
options: {
|
|
1342
|
+
type: "array",
|
|
1343
|
+
items: { $ref: "#/components/schemas/PendingInputRequestOption" },
|
|
1344
|
+
},
|
|
1345
|
+
question: { type: "string" },
|
|
1346
|
+
},
|
|
1347
|
+
},
|
|
1348
|
+
PendingInputRequestOption: {
|
|
1349
|
+
type: "object",
|
|
1350
|
+
required: ["label"],
|
|
1351
|
+
properties: {
|
|
1352
|
+
label: { type: "string" },
|
|
1353
|
+
description: { type: "string" },
|
|
1354
|
+
},
|
|
1355
|
+
},
|
|
1356
|
+
ThreadDetailResponse: {
|
|
1357
|
+
type: "object",
|
|
1358
|
+
required: ["thread", "messages"],
|
|
1359
|
+
properties: {
|
|
1360
|
+
thread: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1361
|
+
messages: { type: "array", items: { $ref: "#/components/schemas/ChatMessage" } },
|
|
1362
|
+
pendingInputRequests: {
|
|
1363
|
+
type: "array",
|
|
1364
|
+
items: { $ref: "#/components/schemas/PendingInputRequest" },
|
|
1365
|
+
},
|
|
1366
|
+
},
|
|
1367
|
+
},
|
|
1368
|
+
ThreadMessageDetailResponse: {
|
|
1369
|
+
type: "object",
|
|
1370
|
+
required: ["field", "messageId", "originalLength", "value"],
|
|
1371
|
+
properties: {
|
|
1372
|
+
field: { type: "string", enum: ["output", "patch"] },
|
|
1373
|
+
messageId: { type: "string" },
|
|
1374
|
+
originalLength: { type: "integer", minimum: 0 },
|
|
1375
|
+
value: { type: "string" },
|
|
1376
|
+
},
|
|
1377
|
+
},
|
|
1378
|
+
StreamThreadRunEvent: {
|
|
1379
|
+
oneOf: [
|
|
1380
|
+
{ type: "object", properties: { type: { const: "thread.message.created" } } },
|
|
1381
|
+
{ type: "object", properties: { type: { const: "thread.message.delta" } } },
|
|
1382
|
+
{ type: "object", properties: { type: { const: "thread.message.completed" } } },
|
|
1383
|
+
{ type: "object", properties: { type: { const: "thread.state.changed" } } },
|
|
1384
|
+
{ type: "object", properties: { type: { const: "thread.error" } } },
|
|
1385
|
+
{
|
|
1386
|
+
type: "object",
|
|
1387
|
+
properties: { type: { const: "thread.preview_target.detected" } },
|
|
1388
|
+
},
|
|
1389
|
+
],
|
|
1390
|
+
},
|
|
1391
|
+
ListThreadsResponse: {
|
|
1392
|
+
type: "object",
|
|
1393
|
+
required: ["threads"],
|
|
1394
|
+
properties: {
|
|
1395
|
+
threads: {
|
|
1396
|
+
type: "array",
|
|
1397
|
+
items: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1398
|
+
},
|
|
1399
|
+
},
|
|
1400
|
+
},
|
|
1401
|
+
ArchiveThreadResponse: {
|
|
1402
|
+
type: "object",
|
|
1403
|
+
required: ["archivedThreadId", "threads"],
|
|
1404
|
+
properties: {
|
|
1405
|
+
archivedThreadId: { type: "string" },
|
|
1406
|
+
source: { type: "string", enum: ["app-server", "memory"] },
|
|
1407
|
+
threads: {
|
|
1408
|
+
type: "array",
|
|
1409
|
+
items: { $ref: "#/components/schemas/ThreadSummary" },
|
|
1410
|
+
},
|
|
1411
|
+
},
|
|
1412
|
+
},
|
|
1413
|
+
ErrorResponse: {
|
|
1414
|
+
type: "object",
|
|
1415
|
+
required: ["error"],
|
|
1416
|
+
properties: {
|
|
1417
|
+
error: {
|
|
1418
|
+
type: "object",
|
|
1419
|
+
required: ["code", "message"],
|
|
1420
|
+
properties: {
|
|
1421
|
+
code: { type: "string" },
|
|
1422
|
+
message: { type: "string" },
|
|
1423
|
+
issues: { type: "array", items: { type: "string" } },
|
|
1424
|
+
},
|
|
1425
|
+
},
|
|
1426
|
+
},
|
|
1427
|
+
},
|
|
1428
|
+
},
|
|
1429
|
+
},
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
function jsonRequest(schemaName: string) {
|
|
1434
|
+
return {
|
|
1435
|
+
required: true,
|
|
1436
|
+
content: {
|
|
1437
|
+
"application/json": {
|
|
1438
|
+
schema: { $ref: `#/components/schemas/${schemaName}` },
|
|
1439
|
+
},
|
|
1440
|
+
},
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
function jsonResponse(schemaName: string) {
|
|
1445
|
+
return {
|
|
1446
|
+
description: schemaName,
|
|
1447
|
+
content: {
|
|
1448
|
+
"application/json": {
|
|
1449
|
+
schema: { $ref: `#/components/schemas/${schemaName}` },
|
|
1450
|
+
},
|
|
1451
|
+
},
|
|
1452
|
+
};
|
|
1453
|
+
}
|