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