@camerontaylor/paseo-plugin 0.8.0-fork.1
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/dist/attachments.d.ts +26 -0
- package/dist/attachments.js +17 -0
- package/dist/client/buttons.d.ts +64 -0
- package/dist/client/buttons.js +2 -0
- package/dist/client/client-state.d.ts +15 -0
- package/dist/client/client-state.js +32 -0
- package/dist/client/contracts.d.ts +201 -0
- package/dist/client/contracts.js +2 -0
- package/dist/client/host.d.ts +19 -0
- package/dist/client/host.js +12 -0
- package/dist/client/index.d.ts +10 -0
- package/dist/client/index.js +4 -0
- package/dist/client/paseo-context.d.ts +9 -0
- package/dist/client/paseo-context.js +16 -0
- package/dist/client/react-native.d.ts +46 -0
- package/dist/client/react-native.js +2 -0
- package/dist/client/rpc-context.d.ts +13 -0
- package/dist/client/rpc-context.js +18 -0
- package/dist/client/runtime-context-bridge.d.ts +5 -0
- package/dist/client/runtime-context-bridge.js +19 -0
- package/dist/client/shallow.d.ts +2 -0
- package/dist/client/shallow.js +45 -0
- package/dist/client/ui.d.ts +60 -0
- package/dist/client/ui.js +2 -0
- package/dist/contracts.d.ts +90 -0
- package/dist/contracts.js +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/rpc.d.ts +17 -0
- package/dist/rpc.js +13 -0
- package/dist/server/acp-internal/connection.d.ts +4 -0
- package/dist/server/acp-internal/connection.js +1187 -0
- package/dist/server/acp.d.ts +112 -0
- package/dist/server/acp.js +21 -0
- package/dist/server/contracts.d.ts +16 -0
- package/dist/server/contracts.js +2 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +2 -0
- package/dist/server/lifecycle.d.ts +92 -0
- package/dist/server/lifecycle.js +2 -0
- package/dist/server/provider.d.ts +610 -0
- package/dist/server/provider.js +811 -0
- package/dist/settings.d.ts +70 -0
- package/dist/settings.js +40 -0
- package/package.json +90 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const PROVIDER_PROTOCOL_VERSION = 1;
|
|
3
|
+
export const PROVIDER_CAPABILITIES = [
|
|
4
|
+
"prompt.message",
|
|
5
|
+
"prompt.command",
|
|
6
|
+
"prompt.image",
|
|
7
|
+
"prompt.output_schema",
|
|
8
|
+
"prompt.steer",
|
|
9
|
+
"session.archive",
|
|
10
|
+
"session.configure",
|
|
11
|
+
"session.list",
|
|
12
|
+
"session.persistence",
|
|
13
|
+
"session.revert.both",
|
|
14
|
+
"session.revert.conversation",
|
|
15
|
+
"session.revert.files",
|
|
16
|
+
"session.subsession",
|
|
17
|
+
"session.unarchive",
|
|
18
|
+
"permission",
|
|
19
|
+
"permission.tool_policy",
|
|
20
|
+
"timeline.plugin",
|
|
21
|
+
];
|
|
22
|
+
export function negotiateProviderCapabilities(offered, supported) {
|
|
23
|
+
const known = new Set(PROVIDER_CAPABILITIES);
|
|
24
|
+
const supportedCapabilities = new Set(supported.filter((capability) => known.has(capability)));
|
|
25
|
+
return offered.filter((capability, index) => isProviderCapability(capability) &&
|
|
26
|
+
supportedCapabilities.has(capability) &&
|
|
27
|
+
offered.indexOf(capability) === index);
|
|
28
|
+
}
|
|
29
|
+
export function isProviderCapability(capability) {
|
|
30
|
+
return new Set(PROVIDER_CAPABILITIES).has(capability);
|
|
31
|
+
}
|
|
32
|
+
function requiredPromptCapabilities(prompt) {
|
|
33
|
+
const capabilities = [];
|
|
34
|
+
if (prompt.delivery === "steer")
|
|
35
|
+
capabilities.push("prompt.steer");
|
|
36
|
+
if (prompt.input.type === "command")
|
|
37
|
+
capabilities.push("prompt.command");
|
|
38
|
+
else {
|
|
39
|
+
capabilities.push("prompt.message");
|
|
40
|
+
if (prompt.input.content.some((part) => part.type === "image")) {
|
|
41
|
+
capabilities.push("prompt.image");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (prompt.outputSchema !== undefined)
|
|
45
|
+
capabilities.push("prompt.output_schema");
|
|
46
|
+
return capabilities;
|
|
47
|
+
}
|
|
48
|
+
export function requiredProviderCapabilities(input) {
|
|
49
|
+
switch (input.type) {
|
|
50
|
+
case "catalog":
|
|
51
|
+
case "session.interrupt":
|
|
52
|
+
case "session.close":
|
|
53
|
+
return [];
|
|
54
|
+
case "sessions":
|
|
55
|
+
return ["session.list"];
|
|
56
|
+
case "session.open": {
|
|
57
|
+
const capabilities = [];
|
|
58
|
+
if (input.persistence)
|
|
59
|
+
capabilities.push("session.persistence");
|
|
60
|
+
if (input.config.toolPolicy)
|
|
61
|
+
capabilities.push("permission.tool_policy");
|
|
62
|
+
return capabilities;
|
|
63
|
+
}
|
|
64
|
+
case "session.prompt":
|
|
65
|
+
return requiredPromptCapabilities(input.prompt);
|
|
66
|
+
case "session.permission":
|
|
67
|
+
return ["permission"];
|
|
68
|
+
case "session.configure":
|
|
69
|
+
return ["session.configure"];
|
|
70
|
+
case "session.revert":
|
|
71
|
+
return [`session.revert.${input.scope}`];
|
|
72
|
+
case "session.archive":
|
|
73
|
+
return ["session.archive"];
|
|
74
|
+
case "session.unarchive":
|
|
75
|
+
return ["session.unarchive"];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
export function requireProviderCapabilities(capabilities, input) {
|
|
79
|
+
for (const capability of requiredProviderCapabilities(input)) {
|
|
80
|
+
if (!capabilities.includes(capability)) {
|
|
81
|
+
throw new Error(`Provider does not support ${capability}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const idSchema = z.string().min(1);
|
|
86
|
+
const jsonObjectSchema = z.record(z.string(), z.json());
|
|
87
|
+
const providerErrorSchema = z
|
|
88
|
+
.object({ message: z.string(), code: z.string().optional(), diagnostic: z.string().optional() })
|
|
89
|
+
.strip();
|
|
90
|
+
const persistenceSchema = z
|
|
91
|
+
.object({ version: z.number().int().nonnegative(), data: z.json() })
|
|
92
|
+
.strip();
|
|
93
|
+
const mcpServerSchema = z.discriminatedUnion("type", [
|
|
94
|
+
z
|
|
95
|
+
.object({
|
|
96
|
+
type: z.literal("stdio"),
|
|
97
|
+
command: z.string(),
|
|
98
|
+
args: z.array(z.string()).optional(),
|
|
99
|
+
env: z.record(z.string(), z.string()).optional(),
|
|
100
|
+
alwaysLoad: z.boolean().optional(),
|
|
101
|
+
})
|
|
102
|
+
.strict(),
|
|
103
|
+
z
|
|
104
|
+
.object({
|
|
105
|
+
type: z.literal("http"),
|
|
106
|
+
url: z.string(),
|
|
107
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
108
|
+
alwaysLoad: z.boolean().optional(),
|
|
109
|
+
})
|
|
110
|
+
.strict(),
|
|
111
|
+
z
|
|
112
|
+
.object({
|
|
113
|
+
type: z.literal("sse"),
|
|
114
|
+
url: z.string(),
|
|
115
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
116
|
+
alwaysLoad: z.boolean().optional(),
|
|
117
|
+
})
|
|
118
|
+
.strict(),
|
|
119
|
+
]);
|
|
120
|
+
const toolPolicySchema = z
|
|
121
|
+
.object({
|
|
122
|
+
preapproved: z.array(z.object({ kind: z.literal("mcp"), server: idSchema, tool: idSchema }).strict()),
|
|
123
|
+
})
|
|
124
|
+
.strict();
|
|
125
|
+
const providerPermissionResponseSchema = z.discriminatedUnion("behavior", [
|
|
126
|
+
z
|
|
127
|
+
.object({
|
|
128
|
+
behavior: z.literal("allow"),
|
|
129
|
+
selectedActionId: z.string().optional(),
|
|
130
|
+
updatedInput: jsonObjectSchema.optional(),
|
|
131
|
+
updatedPermissions: z.array(jsonObjectSchema).optional(),
|
|
132
|
+
})
|
|
133
|
+
.strip(),
|
|
134
|
+
z
|
|
135
|
+
.object({
|
|
136
|
+
behavior: z.literal("deny"),
|
|
137
|
+
selectedActionId: z.string().optional(),
|
|
138
|
+
message: z.string().optional(),
|
|
139
|
+
interrupt: z.boolean().optional(),
|
|
140
|
+
})
|
|
141
|
+
.strip(),
|
|
142
|
+
]);
|
|
143
|
+
const sessionConfigSchema = z
|
|
144
|
+
.object({
|
|
145
|
+
cwd: z.string(),
|
|
146
|
+
env: z.record(z.string(), z.string()),
|
|
147
|
+
systemPrompt: z.string().optional(),
|
|
148
|
+
mcpServers: z.record(z.string(), mcpServerSchema),
|
|
149
|
+
toolPolicy: toolPolicySchema.optional(),
|
|
150
|
+
model: z.string().optional(),
|
|
151
|
+
mode: z.string().optional(),
|
|
152
|
+
thinkingOption: z.string().optional(),
|
|
153
|
+
settings: jsonObjectSchema,
|
|
154
|
+
providerOptions: jsonObjectSchema.optional(),
|
|
155
|
+
title: z.string().optional(),
|
|
156
|
+
persist: z.boolean(),
|
|
157
|
+
})
|
|
158
|
+
.strict();
|
|
159
|
+
const externalResourceSchema = z
|
|
160
|
+
.object({
|
|
161
|
+
provider: z.string(),
|
|
162
|
+
providerLabel: z.string(),
|
|
163
|
+
resourceType: z.string(),
|
|
164
|
+
id: z.string(),
|
|
165
|
+
identifier: z.string(),
|
|
166
|
+
title: z.string(),
|
|
167
|
+
url: z.string(),
|
|
168
|
+
})
|
|
169
|
+
.strip();
|
|
170
|
+
const reviewContextLineSchema = z
|
|
171
|
+
.object({
|
|
172
|
+
oldLineNumber: z.number().int().positive().nullable(),
|
|
173
|
+
newLineNumber: z.number().int().positive().nullable(),
|
|
174
|
+
type: z.enum(["add", "remove", "context"]),
|
|
175
|
+
content: z.string(),
|
|
176
|
+
})
|
|
177
|
+
.strip();
|
|
178
|
+
const providerContentSchema = z.union([
|
|
179
|
+
z.object({ type: z.literal("text"), text: z.string() }).strict(),
|
|
180
|
+
z.object({ type: z.literal("image"), data: z.string(), mimeType: z.string() }).strict(),
|
|
181
|
+
z
|
|
182
|
+
.object({
|
|
183
|
+
type: z.literal("forge_change_request"),
|
|
184
|
+
mimeType: z.literal("application/paseo-forge-change-request"),
|
|
185
|
+
forge: z.string().optional(),
|
|
186
|
+
number: z.number().int().positive(),
|
|
187
|
+
title: z.string(),
|
|
188
|
+
url: z.string(),
|
|
189
|
+
body: z.string().nullable().optional(),
|
|
190
|
+
projectPath: z.string().optional(),
|
|
191
|
+
baseRefName: z.string().nullable().optional(),
|
|
192
|
+
headRefName: z.string().nullable().optional(),
|
|
193
|
+
})
|
|
194
|
+
.strip(),
|
|
195
|
+
z
|
|
196
|
+
.object({
|
|
197
|
+
type: z.literal("forge_issue"),
|
|
198
|
+
mimeType: z.literal("application/paseo-forge-issue"),
|
|
199
|
+
forge: z.string().optional(),
|
|
200
|
+
number: z.number().int().positive(),
|
|
201
|
+
title: z.string(),
|
|
202
|
+
url: z.string(),
|
|
203
|
+
body: z.string().nullable().optional(),
|
|
204
|
+
projectPath: z.string().optional(),
|
|
205
|
+
})
|
|
206
|
+
.strip(),
|
|
207
|
+
z
|
|
208
|
+
.object({
|
|
209
|
+
type: z.literal("github_pr"),
|
|
210
|
+
mimeType: z.literal("application/github-pr"),
|
|
211
|
+
number: z.number().int().positive(),
|
|
212
|
+
title: z.string(),
|
|
213
|
+
url: z.string(),
|
|
214
|
+
body: z.string().nullable().optional(),
|
|
215
|
+
baseRefName: z.string().nullable().optional(),
|
|
216
|
+
headRefName: z.string().nullable().optional(),
|
|
217
|
+
})
|
|
218
|
+
.strip(),
|
|
219
|
+
z
|
|
220
|
+
.object({
|
|
221
|
+
type: z.literal("github_issue"),
|
|
222
|
+
mimeType: z.literal("application/github-issue"),
|
|
223
|
+
number: z.number().int().positive(),
|
|
224
|
+
title: z.string(),
|
|
225
|
+
url: z.string(),
|
|
226
|
+
body: z.string().nullable().optional(),
|
|
227
|
+
})
|
|
228
|
+
.strip(),
|
|
229
|
+
z
|
|
230
|
+
.object({
|
|
231
|
+
type: z.literal("text"),
|
|
232
|
+
mimeType: z.literal("text/plain"),
|
|
233
|
+
contextKind: z.string().optional(),
|
|
234
|
+
title: z.string().nullable().optional(),
|
|
235
|
+
text: z.string(),
|
|
236
|
+
externalResource: externalResourceSchema.optional(),
|
|
237
|
+
})
|
|
238
|
+
.strip(),
|
|
239
|
+
z
|
|
240
|
+
.object({
|
|
241
|
+
type: z.literal("review"),
|
|
242
|
+
mimeType: z.literal("application/paseo-review"),
|
|
243
|
+
cwd: z.string(),
|
|
244
|
+
mode: z.enum(["uncommitted", "base"]),
|
|
245
|
+
baseRef: z.string().nullable().optional(),
|
|
246
|
+
comments: z.array(z
|
|
247
|
+
.object({
|
|
248
|
+
filePath: z.string(),
|
|
249
|
+
side: z.enum(["old", "new"]),
|
|
250
|
+
lineNumber: z.number().int().positive(),
|
|
251
|
+
body: z.string(),
|
|
252
|
+
context: z
|
|
253
|
+
.object({
|
|
254
|
+
hunkHeader: z.string(),
|
|
255
|
+
targetLine: reviewContextLineSchema,
|
|
256
|
+
lines: z.array(reviewContextLineSchema),
|
|
257
|
+
})
|
|
258
|
+
.strip(),
|
|
259
|
+
})
|
|
260
|
+
.strip()),
|
|
261
|
+
})
|
|
262
|
+
.strip(),
|
|
263
|
+
z
|
|
264
|
+
.object({
|
|
265
|
+
type: z.literal("uploaded_file"),
|
|
266
|
+
id: z.string(),
|
|
267
|
+
fileName: z.string(),
|
|
268
|
+
mimeType: z.string(),
|
|
269
|
+
size: z.number().int().nonnegative(),
|
|
270
|
+
path: z.string(),
|
|
271
|
+
})
|
|
272
|
+
.strip(),
|
|
273
|
+
]);
|
|
274
|
+
const promptSchema = z
|
|
275
|
+
.object({
|
|
276
|
+
clientMessageId: idSchema,
|
|
277
|
+
delivery: z.enum(["auto", "steer"]),
|
|
278
|
+
input: z.union([
|
|
279
|
+
z.object({ type: z.literal("message"), content: z.array(providerContentSchema) }).strict(),
|
|
280
|
+
z.object({ type: z.literal("command"), name: idSchema, arguments: z.string() }).strict(),
|
|
281
|
+
]),
|
|
282
|
+
outputSchema: z.json().optional(),
|
|
283
|
+
clearPendingPermissions: z.boolean().optional(),
|
|
284
|
+
})
|
|
285
|
+
.strict();
|
|
286
|
+
const configChangesSchema = z
|
|
287
|
+
.object({
|
|
288
|
+
model: z.string().nullable().optional(),
|
|
289
|
+
mode: z.string().nullable().optional(),
|
|
290
|
+
thinkingOption: z.string().nullable().optional(),
|
|
291
|
+
settings: jsonObjectSchema.optional(),
|
|
292
|
+
})
|
|
293
|
+
.strict();
|
|
294
|
+
export const ProviderInputSchema = z.discriminatedUnion("type", [
|
|
295
|
+
z
|
|
296
|
+
.object({ type: z.literal("catalog"), requestId: idSchema, cwd: z.string().optional() })
|
|
297
|
+
.strict(),
|
|
298
|
+
z
|
|
299
|
+
.object({
|
|
300
|
+
type: z.literal("sessions"),
|
|
301
|
+
requestId: idSchema,
|
|
302
|
+
query: z.string().optional(),
|
|
303
|
+
cwd: z.string().optional(),
|
|
304
|
+
limit: z.number().int().positive().optional(),
|
|
305
|
+
})
|
|
306
|
+
.strict(),
|
|
307
|
+
z
|
|
308
|
+
.object({
|
|
309
|
+
type: z.literal("session.open"),
|
|
310
|
+
requestId: idSchema,
|
|
311
|
+
sessionId: idSchema,
|
|
312
|
+
config: sessionConfigSchema,
|
|
313
|
+
persistence: persistenceSchema.optional(),
|
|
314
|
+
history: z.enum(["replay", "skip"]),
|
|
315
|
+
})
|
|
316
|
+
.strict(),
|
|
317
|
+
z
|
|
318
|
+
.object({ type: z.literal("session.prompt"), sessionId: idSchema, prompt: promptSchema })
|
|
319
|
+
.strict(),
|
|
320
|
+
z
|
|
321
|
+
.object({ type: z.literal("session.interrupt"), requestId: idSchema, sessionId: idSchema })
|
|
322
|
+
.strict(),
|
|
323
|
+
z
|
|
324
|
+
.object({
|
|
325
|
+
type: z.literal("session.permission"),
|
|
326
|
+
sessionId: idSchema,
|
|
327
|
+
permissionId: idSchema,
|
|
328
|
+
response: providerPermissionResponseSchema,
|
|
329
|
+
})
|
|
330
|
+
.strict(),
|
|
331
|
+
z
|
|
332
|
+
.object({
|
|
333
|
+
type: z.literal("session.configure"),
|
|
334
|
+
requestId: idSchema,
|
|
335
|
+
sessionId: idSchema,
|
|
336
|
+
changes: configChangesSchema,
|
|
337
|
+
})
|
|
338
|
+
.strict(),
|
|
339
|
+
z
|
|
340
|
+
.object({
|
|
341
|
+
type: z.literal("session.revert"),
|
|
342
|
+
requestId: idSchema,
|
|
343
|
+
sessionId: idSchema,
|
|
344
|
+
token: z.json(),
|
|
345
|
+
scope: z.enum(["conversation", "files", "both"]),
|
|
346
|
+
})
|
|
347
|
+
.strict(),
|
|
348
|
+
z
|
|
349
|
+
.object({
|
|
350
|
+
type: z.literal("session.archive"),
|
|
351
|
+
requestId: idSchema,
|
|
352
|
+
persistence: persistenceSchema,
|
|
353
|
+
})
|
|
354
|
+
.strict(),
|
|
355
|
+
z
|
|
356
|
+
.object({
|
|
357
|
+
type: z.literal("session.unarchive"),
|
|
358
|
+
requestId: idSchema,
|
|
359
|
+
persistence: persistenceSchema,
|
|
360
|
+
})
|
|
361
|
+
.strict(),
|
|
362
|
+
z.object({ type: z.literal("session.close"), requestId: idSchema, sessionId: idSchema }).strict(),
|
|
363
|
+
]);
|
|
364
|
+
const modeSchema = z
|
|
365
|
+
.object({
|
|
366
|
+
id: idSchema,
|
|
367
|
+
label: z.string(),
|
|
368
|
+
description: z.string().optional(),
|
|
369
|
+
icon: z.string().optional(),
|
|
370
|
+
colorTier: z.string().optional(),
|
|
371
|
+
isUnattended: z.boolean().optional(),
|
|
372
|
+
})
|
|
373
|
+
.strip();
|
|
374
|
+
const selectOptionSchema = z
|
|
375
|
+
.object({
|
|
376
|
+
id: idSchema,
|
|
377
|
+
label: z.string(),
|
|
378
|
+
description: z.string().optional(),
|
|
379
|
+
isDefault: z.boolean().optional(),
|
|
380
|
+
metadata: jsonObjectSchema.optional(),
|
|
381
|
+
})
|
|
382
|
+
.strip();
|
|
383
|
+
const modelSchema = z
|
|
384
|
+
.object({
|
|
385
|
+
id: idSchema,
|
|
386
|
+
aliases: z.array(z.string()).optional(),
|
|
387
|
+
isSelectable: z.boolean().optional(),
|
|
388
|
+
label: z.string(),
|
|
389
|
+
description: z.string().optional(),
|
|
390
|
+
isDefault: z.boolean().optional(),
|
|
391
|
+
metadata: jsonObjectSchema.optional(),
|
|
392
|
+
contextWindowMaxTokens: z.number().optional(),
|
|
393
|
+
thinkingOptions: z.array(selectOptionSchema).optional(),
|
|
394
|
+
defaultThinkingOptionId: z.string().optional(),
|
|
395
|
+
})
|
|
396
|
+
.strip();
|
|
397
|
+
const settingSchema = z.discriminatedUnion("type", [
|
|
398
|
+
z
|
|
399
|
+
.object({
|
|
400
|
+
type: z.literal("toggle"),
|
|
401
|
+
id: idSchema,
|
|
402
|
+
label: z.string(),
|
|
403
|
+
description: z.string().optional(),
|
|
404
|
+
value: z.boolean(),
|
|
405
|
+
})
|
|
406
|
+
.strip(),
|
|
407
|
+
z
|
|
408
|
+
.object({
|
|
409
|
+
type: z.literal("select"),
|
|
410
|
+
id: idSchema,
|
|
411
|
+
label: z.string(),
|
|
412
|
+
description: z.string().optional(),
|
|
413
|
+
value: z.string().nullable(),
|
|
414
|
+
options: z.array(z.object({ label: z.string(), value: z.string() }).strip()),
|
|
415
|
+
})
|
|
416
|
+
.strip(),
|
|
417
|
+
]);
|
|
418
|
+
const configStateSchema = z
|
|
419
|
+
.object({
|
|
420
|
+
model: z.string().optional(),
|
|
421
|
+
mode: z.string().optional(),
|
|
422
|
+
thinkingOption: z.string().optional(),
|
|
423
|
+
models: z.array(modelSchema),
|
|
424
|
+
modes: z.array(modeSchema),
|
|
425
|
+
thinkingOptions: z.array(selectOptionSchema),
|
|
426
|
+
settings: z.array(settingSchema),
|
|
427
|
+
})
|
|
428
|
+
.strip();
|
|
429
|
+
const catalogSchema = z
|
|
430
|
+
.object({
|
|
431
|
+
models: z.array(modelSchema),
|
|
432
|
+
modes: z.array(modeSchema),
|
|
433
|
+
thinkingOptions: z.array(selectOptionSchema).optional(),
|
|
434
|
+
defaultModel: z.string().optional(),
|
|
435
|
+
defaultMode: z.string().optional(),
|
|
436
|
+
defaultThinkingOption: z.string().optional(),
|
|
437
|
+
})
|
|
438
|
+
.strip();
|
|
439
|
+
const noticeSchema = z
|
|
440
|
+
.object({
|
|
441
|
+
id: idSchema,
|
|
442
|
+
severity: z.enum(["info", "warning", "error"]),
|
|
443
|
+
title: z.string(),
|
|
444
|
+
description: z.string().optional(),
|
|
445
|
+
dismissed: z.boolean().optional(),
|
|
446
|
+
})
|
|
447
|
+
.strip();
|
|
448
|
+
const commandSchema = z
|
|
449
|
+
.object({ name: idSchema, description: z.string(), argumentHint: z.string().optional() })
|
|
450
|
+
.strip();
|
|
451
|
+
const usageSchema = z
|
|
452
|
+
.object({
|
|
453
|
+
inputTokens: z.number().optional(),
|
|
454
|
+
cachedInputTokens: z.number().optional(),
|
|
455
|
+
outputTokens: z.number().optional(),
|
|
456
|
+
totalCostUsd: z.number().optional(),
|
|
457
|
+
contextWindowMaxTokens: z.number().optional(),
|
|
458
|
+
contextWindowUsedTokens: z.number().optional(),
|
|
459
|
+
})
|
|
460
|
+
.strip();
|
|
461
|
+
const worktreeCommandSchema = z
|
|
462
|
+
.object({
|
|
463
|
+
index: z.number().int().positive(),
|
|
464
|
+
command: z.string(),
|
|
465
|
+
cwd: z.string(),
|
|
466
|
+
log: z.string(),
|
|
467
|
+
status: z.enum(["running", "completed", "failed"]),
|
|
468
|
+
exitCode: z.number().nullable(),
|
|
469
|
+
durationMs: z.number().nonnegative().optional(),
|
|
470
|
+
})
|
|
471
|
+
.strip();
|
|
472
|
+
const toolCallDetailSchema = z.discriminatedUnion("type", [
|
|
473
|
+
z
|
|
474
|
+
.object({
|
|
475
|
+
type: z.literal("shell"),
|
|
476
|
+
command: z.string(),
|
|
477
|
+
cwd: z.string().optional(),
|
|
478
|
+
output: z.string().optional(),
|
|
479
|
+
exitCode: z.number().nullable().optional(),
|
|
480
|
+
})
|
|
481
|
+
.strip(),
|
|
482
|
+
z
|
|
483
|
+
.object({
|
|
484
|
+
type: z.literal("read"),
|
|
485
|
+
filePath: z.string(),
|
|
486
|
+
content: z.string().optional(),
|
|
487
|
+
offset: z.number().optional(),
|
|
488
|
+
limit: z.number().optional(),
|
|
489
|
+
})
|
|
490
|
+
.strip(),
|
|
491
|
+
z
|
|
492
|
+
.object({
|
|
493
|
+
type: z.literal("edit"),
|
|
494
|
+
filePath: z.string(),
|
|
495
|
+
oldString: z.string().optional(),
|
|
496
|
+
newString: z.string().optional(),
|
|
497
|
+
unifiedDiff: z.string().optional(),
|
|
498
|
+
})
|
|
499
|
+
.strip(),
|
|
500
|
+
z
|
|
501
|
+
.object({ type: z.literal("write"), filePath: z.string(), content: z.string().optional() })
|
|
502
|
+
.strip(),
|
|
503
|
+
z
|
|
504
|
+
.object({
|
|
505
|
+
type: z.literal("search"),
|
|
506
|
+
query: z.string(),
|
|
507
|
+
toolName: z.enum(["search", "grep", "glob", "web_search"]).optional(),
|
|
508
|
+
content: z.string().optional(),
|
|
509
|
+
filePaths: z.array(z.string()).optional(),
|
|
510
|
+
webResults: z.array(z.object({ title: z.string(), url: z.string() }).strip()).optional(),
|
|
511
|
+
annotations: z.array(z.string()).optional(),
|
|
512
|
+
numFiles: z.number().optional(),
|
|
513
|
+
numMatches: z.number().optional(),
|
|
514
|
+
durationMs: z.number().optional(),
|
|
515
|
+
durationSeconds: z.number().optional(),
|
|
516
|
+
truncated: z.boolean().optional(),
|
|
517
|
+
mode: z.enum(["content", "files_with_matches", "count"]).optional(),
|
|
518
|
+
})
|
|
519
|
+
.strip(),
|
|
520
|
+
z
|
|
521
|
+
.object({
|
|
522
|
+
type: z.literal("fetch"),
|
|
523
|
+
url: z.string(),
|
|
524
|
+
prompt: z.string().optional(),
|
|
525
|
+
result: z.string().optional(),
|
|
526
|
+
code: z.number().optional(),
|
|
527
|
+
codeText: z.string().optional(),
|
|
528
|
+
bytes: z.number().optional(),
|
|
529
|
+
durationMs: z.number().optional(),
|
|
530
|
+
})
|
|
531
|
+
.strip(),
|
|
532
|
+
z
|
|
533
|
+
.object({
|
|
534
|
+
type: z.literal("worktree_setup"),
|
|
535
|
+
worktreePath: z.string(),
|
|
536
|
+
branchName: z.string(),
|
|
537
|
+
log: z.string(),
|
|
538
|
+
commands: z.array(worktreeCommandSchema),
|
|
539
|
+
truncated: z.boolean().optional(),
|
|
540
|
+
})
|
|
541
|
+
.strip(),
|
|
542
|
+
z
|
|
543
|
+
.object({
|
|
544
|
+
type: z.literal("sub_agent"),
|
|
545
|
+
subAgentType: z.string().optional(),
|
|
546
|
+
description: z.string().optional(),
|
|
547
|
+
childSessionId: z.string().optional(),
|
|
548
|
+
log: z.string(),
|
|
549
|
+
actions: z
|
|
550
|
+
.array(z
|
|
551
|
+
.object({
|
|
552
|
+
index: z.number().int().positive(),
|
|
553
|
+
toolName: z.string(),
|
|
554
|
+
summary: z.string().optional(),
|
|
555
|
+
})
|
|
556
|
+
.strip())
|
|
557
|
+
.optional(),
|
|
558
|
+
})
|
|
559
|
+
.strip(),
|
|
560
|
+
z
|
|
561
|
+
.object({
|
|
562
|
+
type: z.literal("plain_text"),
|
|
563
|
+
label: z.string().optional(),
|
|
564
|
+
text: z.string().optional(),
|
|
565
|
+
icon: z
|
|
566
|
+
.enum([
|
|
567
|
+
"wrench",
|
|
568
|
+
"square_terminal",
|
|
569
|
+
"eye",
|
|
570
|
+
"pencil",
|
|
571
|
+
"search",
|
|
572
|
+
"bot",
|
|
573
|
+
"sparkles",
|
|
574
|
+
"brain",
|
|
575
|
+
"mic_vocal",
|
|
576
|
+
])
|
|
577
|
+
.optional(),
|
|
578
|
+
})
|
|
579
|
+
.strip(),
|
|
580
|
+
z.object({ type: z.literal("plan"), text: z.string() }).strip(),
|
|
581
|
+
z.object({ type: z.literal("unknown"), input: z.json(), output: z.json() }).strip(),
|
|
582
|
+
]);
|
|
583
|
+
const timelineIdentityShape = { id: idSchema, revertToken: z.json().optional() };
|
|
584
|
+
const toolCallBaseShape = {
|
|
585
|
+
...timelineIdentityShape,
|
|
586
|
+
type: z.literal("tool_call"),
|
|
587
|
+
callId: idSchema,
|
|
588
|
+
name: z.string(),
|
|
589
|
+
detail: toolCallDetailSchema,
|
|
590
|
+
metadata: jsonObjectSchema.optional(),
|
|
591
|
+
};
|
|
592
|
+
const timelineItemSchema = z.union([
|
|
593
|
+
z
|
|
594
|
+
.object({
|
|
595
|
+
...timelineIdentityShape,
|
|
596
|
+
type: z.literal("user_message"),
|
|
597
|
+
text: z.string(),
|
|
598
|
+
messageId: z.string().optional(),
|
|
599
|
+
clientMessageId: z.string().optional(),
|
|
600
|
+
})
|
|
601
|
+
.strip(),
|
|
602
|
+
z
|
|
603
|
+
.object({
|
|
604
|
+
...timelineIdentityShape,
|
|
605
|
+
type: z.literal("assistant_message"),
|
|
606
|
+
text: z.string(),
|
|
607
|
+
messageId: z.string().optional(),
|
|
608
|
+
})
|
|
609
|
+
.strip(),
|
|
610
|
+
z.object({ ...timelineIdentityShape, type: z.literal("reasoning"), text: z.string() }).strip(),
|
|
611
|
+
z.object({ ...toolCallBaseShape, status: z.literal("running"), error: z.null() }).strip(),
|
|
612
|
+
z.object({ ...toolCallBaseShape, status: z.literal("completed"), error: z.null() }).strip(),
|
|
613
|
+
z.object({ ...toolCallBaseShape, status: z.literal("failed"), error: z.json() }).strip(),
|
|
614
|
+
z.object({ ...toolCallBaseShape, status: z.literal("canceled"), error: z.null() }).strip(),
|
|
615
|
+
z
|
|
616
|
+
.object({
|
|
617
|
+
...timelineIdentityShape,
|
|
618
|
+
type: z.literal("todo"),
|
|
619
|
+
items: z.array(z
|
|
620
|
+
.object({
|
|
621
|
+
text: z.string(),
|
|
622
|
+
completed: z.boolean(),
|
|
623
|
+
id: z.string().optional(),
|
|
624
|
+
status: z.enum(["pending", "in_progress", "completed"]).optional(),
|
|
625
|
+
activeForm: z.string().optional(),
|
|
626
|
+
})
|
|
627
|
+
.strip()),
|
|
628
|
+
})
|
|
629
|
+
.strip(),
|
|
630
|
+
z.object({ ...timelineIdentityShape, type: z.literal("error"), message: z.string() }).strip(),
|
|
631
|
+
z
|
|
632
|
+
.object({
|
|
633
|
+
...timelineIdentityShape,
|
|
634
|
+
type: z.literal("notification"),
|
|
635
|
+
level: z.enum(["info", "warning", "error"]),
|
|
636
|
+
message: z.string(),
|
|
637
|
+
})
|
|
638
|
+
.strip(),
|
|
639
|
+
z
|
|
640
|
+
.object({
|
|
641
|
+
...timelineIdentityShape,
|
|
642
|
+
type: z.literal("compaction"),
|
|
643
|
+
status: z.enum(["loading", "completed"]),
|
|
644
|
+
trigger: z.enum(["auto", "manual"]).optional(),
|
|
645
|
+
preTokens: z.number().optional(),
|
|
646
|
+
})
|
|
647
|
+
.strip(),
|
|
648
|
+
z
|
|
649
|
+
.object({
|
|
650
|
+
...timelineIdentityShape,
|
|
651
|
+
type: z.literal("plugin"),
|
|
652
|
+
pluginId: idSchema,
|
|
653
|
+
kind: z.string(),
|
|
654
|
+
version: z.number(),
|
|
655
|
+
data: z.json(),
|
|
656
|
+
})
|
|
657
|
+
.strip(),
|
|
658
|
+
]);
|
|
659
|
+
const permissionActionSchema = z
|
|
660
|
+
.object({
|
|
661
|
+
id: idSchema,
|
|
662
|
+
label: z.string(),
|
|
663
|
+
behavior: z.enum(["allow", "deny"]),
|
|
664
|
+
variant: z.enum(["primary", "secondary", "danger"]).optional(),
|
|
665
|
+
intent: z.enum(["implement", "implement_resume", "dismiss"]).optional(),
|
|
666
|
+
})
|
|
667
|
+
.strip();
|
|
668
|
+
const providerPermissionRequestSchema = z
|
|
669
|
+
.object({
|
|
670
|
+
id: idSchema,
|
|
671
|
+
name: z.string(),
|
|
672
|
+
kind: z.enum(["tool", "plan", "question", "mode", "other"]),
|
|
673
|
+
title: z.string().optional(),
|
|
674
|
+
description: z.string().optional(),
|
|
675
|
+
input: jsonObjectSchema.optional(),
|
|
676
|
+
detail: toolCallDetailSchema.optional(),
|
|
677
|
+
suggestions: z.array(jsonObjectSchema).optional(),
|
|
678
|
+
actions: z.array(permissionActionSchema).optional(),
|
|
679
|
+
metadata: jsonObjectSchema.optional(),
|
|
680
|
+
})
|
|
681
|
+
.strip();
|
|
682
|
+
export const ProviderEventSchema = z.discriminatedUnion("type", [
|
|
683
|
+
z.object({ type: z.literal("catalog"), requestId: idSchema, catalog: catalogSchema }).strip(),
|
|
684
|
+
z
|
|
685
|
+
.object({
|
|
686
|
+
type: z.literal("sessions"),
|
|
687
|
+
requestId: idSchema,
|
|
688
|
+
sessions: z.array(z
|
|
689
|
+
.object({
|
|
690
|
+
persistence: persistenceSchema,
|
|
691
|
+
cwd: z.string(),
|
|
692
|
+
title: z.string().optional(),
|
|
693
|
+
description: z.string().optional(),
|
|
694
|
+
updatedAt: z.string().optional(),
|
|
695
|
+
})
|
|
696
|
+
.strip()),
|
|
697
|
+
})
|
|
698
|
+
.strip(),
|
|
699
|
+
z.object({ type: z.literal("request.completed"), requestId: idSchema }).strip(),
|
|
700
|
+
z
|
|
701
|
+
.object({ type: z.literal("request.failed"), requestId: idSchema, error: providerErrorSchema })
|
|
702
|
+
.strip(),
|
|
703
|
+
z
|
|
704
|
+
.object({
|
|
705
|
+
type: z.literal("session.opened"),
|
|
706
|
+
requestId: idSchema.optional(),
|
|
707
|
+
sessionId: idSchema,
|
|
708
|
+
parentSessionId: idSchema.optional(),
|
|
709
|
+
capabilities: z.array(z.string()),
|
|
710
|
+
restoration: z.enum(["core", "parent"]),
|
|
711
|
+
persistence: persistenceSchema.optional(),
|
|
712
|
+
title: z.string().optional(),
|
|
713
|
+
description: z.string().optional(),
|
|
714
|
+
cwd: z.string(),
|
|
715
|
+
})
|
|
716
|
+
.strip(),
|
|
717
|
+
z
|
|
718
|
+
.object({
|
|
719
|
+
type: z.literal("session.ready"),
|
|
720
|
+
requestId: idSchema.optional(),
|
|
721
|
+
sessionId: idSchema,
|
|
722
|
+
})
|
|
723
|
+
.strip(),
|
|
724
|
+
z
|
|
725
|
+
.object({
|
|
726
|
+
type: z.literal("session.closed"),
|
|
727
|
+
sessionId: idSchema,
|
|
728
|
+
error: providerErrorSchema.optional(),
|
|
729
|
+
})
|
|
730
|
+
.strip(),
|
|
731
|
+
z
|
|
732
|
+
.object({
|
|
733
|
+
type: z.literal("session.runtime_failed"),
|
|
734
|
+
sessionId: idSchema,
|
|
735
|
+
error: providerErrorSchema,
|
|
736
|
+
})
|
|
737
|
+
.strip(),
|
|
738
|
+
z
|
|
739
|
+
.object({
|
|
740
|
+
type: z.literal("session.persistence"),
|
|
741
|
+
sessionId: idSchema,
|
|
742
|
+
persistence: persistenceSchema,
|
|
743
|
+
})
|
|
744
|
+
.strip(),
|
|
745
|
+
z
|
|
746
|
+
.object({
|
|
747
|
+
type: z.literal("session.prompt_result"),
|
|
748
|
+
sessionId: idSchema,
|
|
749
|
+
clientMessageId: idSchema,
|
|
750
|
+
result: z.union([
|
|
751
|
+
z.object({ type: z.literal("turn"), turnId: idSchema }).strip(),
|
|
752
|
+
z.object({ type: z.literal("steer"), turnId: idSchema }).strip(),
|
|
753
|
+
z.object({ type: z.literal("completed") }).strip(),
|
|
754
|
+
z.object({ type: z.literal("failed"), error: providerErrorSchema }).strip(),
|
|
755
|
+
]),
|
|
756
|
+
})
|
|
757
|
+
.strip(),
|
|
758
|
+
z
|
|
759
|
+
.object({
|
|
760
|
+
type: z.literal("session.turn"),
|
|
761
|
+
sessionId: idSchema,
|
|
762
|
+
turnId: idSchema,
|
|
763
|
+
state: z.enum(["started", "completed", "failed", "canceled"]),
|
|
764
|
+
error: providerErrorSchema.optional(),
|
|
765
|
+
})
|
|
766
|
+
.strip(),
|
|
767
|
+
z
|
|
768
|
+
.object({
|
|
769
|
+
type: z.literal("session.usage"),
|
|
770
|
+
sessionId: idSchema,
|
|
771
|
+
turnId: idSchema.optional(),
|
|
772
|
+
usage: usageSchema,
|
|
773
|
+
})
|
|
774
|
+
.strip(),
|
|
775
|
+
z
|
|
776
|
+
.object({ type: z.literal("session.config"), sessionId: idSchema, config: configStateSchema })
|
|
777
|
+
.strip(),
|
|
778
|
+
z
|
|
779
|
+
.object({
|
|
780
|
+
type: z.literal("session.commands"),
|
|
781
|
+
sessionId: idSchema,
|
|
782
|
+
commands: z.array(commandSchema),
|
|
783
|
+
})
|
|
784
|
+
.strip(),
|
|
785
|
+
z
|
|
786
|
+
.object({
|
|
787
|
+
type: z.literal("session.permission"),
|
|
788
|
+
sessionId: idSchema,
|
|
789
|
+
request: providerPermissionRequestSchema,
|
|
790
|
+
})
|
|
791
|
+
.strip(),
|
|
792
|
+
z
|
|
793
|
+
.object({
|
|
794
|
+
type: z.literal("session.permission_resolved"),
|
|
795
|
+
sessionId: idSchema,
|
|
796
|
+
permissionId: idSchema,
|
|
797
|
+
})
|
|
798
|
+
.strip(),
|
|
799
|
+
z
|
|
800
|
+
.object({ type: z.literal("session.notice"), sessionId: idSchema, notice: noticeSchema })
|
|
801
|
+
.strip(),
|
|
802
|
+
z
|
|
803
|
+
.object({
|
|
804
|
+
type: z.literal("timeline.item"),
|
|
805
|
+
sessionId: idSchema,
|
|
806
|
+
item: timelineItemSchema,
|
|
807
|
+
timestamp: z.string().optional(),
|
|
808
|
+
})
|
|
809
|
+
.strip(),
|
|
810
|
+
]);
|
|
811
|
+
//# sourceMappingURL=provider.js.map
|