Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import * as SchemaTransformation from "effect/SchemaTransformation";
4
5import {
6 ContextTransferId,
7 IsoDateTime,
8 MessageId,
9 NodeId,
10 NonNegativeInt,
11 PositiveInt,
12 ProjectId,
13 RunId,
14 RuntimeRequestId,
15 ScheduledTaskId,
16 SecretRef,
17 ThreadId,
18 TrimmedNonEmptyString,
19 TurnItemId,
20} from "./baseSchemas.ts";
21import {
22 ScheduledTaskRunStatus,
23 ScheduledTaskSchedule,
24 ScheduledTaskUpsertSchedule,
25} from "./scheduledTask.ts";
26import { ProviderInteractionMode, ProviderRequestKind, RuntimeMode } from "./providerPolicy.ts";
27import { PullRequestState } from "./pullRequest.ts";
28import {
29 ThreadLinkedPullRequest,
30 ThreadPullRequestKey,
31 ThreadPullRequestLinkSource,
32} from "./threadPullRequest.ts";
33import { ThreadTitleRegeneration } from "./threadTitle.ts";
34import {
35 OrchestrationV2Actor,
36 OrchestrationV2CreationSource,
37 OrchestrationV2RunStatus,
38 OrchestrationV2TurnItemStatus,
39} from "./orchestrationV2.ts";
40import { ProviderOptionSelection, ProviderOptionSelectionValue } from "./model.ts";
41import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
42
43const OrchestratorMcpPrompt = TrimmedNonEmptyString.check(Schema.isMaxLength(120_000));
44const OrchestratorMcpTitle = TrimmedNonEmptyString.check(Schema.isMaxLength(512));
45const OrchestratorMcpClientRequestId = TrimmedNonEmptyString.check(
46 Schema.isMaxLength(256),
47).annotate({ description: "Reuse it to retry the same call. A new call gets a new key." });
48
49// OpenCode 1.15 serializes nested MCP union objects as JSON strings; decode that form at the boundary.
50const OrchestratorMcpScheduleFromJsonString = Schema.fromJsonString(
51 ScheduledTaskUpsertSchedule,
52).annotate({
53 description: "JSON-text schedule. Prefer the object form.",
54});
55
56const OrchestratorMcpSchedule = Schema.Union([
57 ScheduledTaskUpsertSchedule,
58 OrchestratorMcpScheduleFromJsonString,
59]).annotate({
60 description:
61 "Trigger: {type:'interval',everyMs}, {type:'fixed_time',timeOfDay,weekdays?}, or {type:'webhook'}.",
62});
63
64const OrchestratorMcpTargetOptionsFromRecord = Schema.Record(
65 Schema.String,
66 ProviderOptionSelectionValue,
67).pipe(
68 Schema.decodeTo(
69 Schema.Array(ProviderOptionSelection),
70 SchemaTransformation.transformEffect({
71 decode: (record) =>
72 Effect.succeed(Object.entries(record).map(([id, value]) => ({ id, value }))),
73 encode: (selections: ReadonlyArray<ProviderOptionSelection>) =>
74 Effect.succeed(
75 Object.fromEntries(selections.map((selection) => [selection.id, selection.value])),
76 ),
77 }),
78 ),
79);
80
81export const OrchestratorMcpTargetOptions = Schema.Union([
82 Schema.Array(ProviderOptionSelection),
83 OrchestratorMcpTargetOptionsFromRecord,
84]);
85export type OrchestratorMcpTargetOptions = typeof OrchestratorMcpTargetOptions.Type;
86
87export const OrchestratorMcpTarget = Schema.Struct({
88 providerInstanceId: Schema.optional(
89 ProviderInstanceId.annotate({
90 description: "Provider instance id from `orchestrator_capabilities`.",
91 }),
92 ),
93 driverKind: Schema.optional(
94 ProviderDriverKind.annotate({
95 description: "Prefer `providerInstanceId`.",
96 }),
97 ),
98 model: Schema.optional(TrimmedNonEmptyString),
99 options: Schema.optional(
100 OrchestratorMcpTargetOptions.annotate({
101 description:
102 "Options from `orchestrator_capabilities`, such as {effort:'max'}. Given values override inherited. [] or {} clears.",
103 }),
104 ),
105});
106export type OrchestratorMcpTarget = typeof OrchestratorMcpTarget.Type;
107
108export const OrchestratorMcpRuntimeMode = Schema.Union([Schema.Literal("inherit"), RuntimeMode]);
109export type OrchestratorMcpRuntimeMode = typeof OrchestratorMcpRuntimeMode.Type;
110
111export const OrchestratorMcpInteractionMode = Schema.Union([
112 Schema.Literal("inherit"),
113 ProviderInteractionMode,
114]);
115export type OrchestratorMcpInteractionMode = typeof OrchestratorMcpInteractionMode.Type;
116
117export const OrchestratorMcpTaskRole = Schema.Literals([
118 "implementation",
119 "research",
120 "review",
121 "design",
122 "test",
123 "general",
124]);
125export type OrchestratorMcpTaskRole = typeof OrchestratorMcpTaskRole.Type;
126
127export const OrchestratorMcpDelegatedTaskStatus = Schema.Literals([
128 "queued",
129 "running",
130 "waiting",
131 "completed",
132 "failed",
133 "cancelled",
134 "interrupted",
135]);
136export type OrchestratorMcpDelegatedTaskStatus = typeof OrchestratorMcpDelegatedTaskStatus.Type;
137
138export const OrchestratorMcpTerminalDelegatedTaskStatus = Schema.Literals([
139 "completed",
140 "failed",
141 "cancelled",
142 "interrupted",
143]);
144export type OrchestratorMcpTerminalDelegatedTaskStatus =
145 typeof OrchestratorMcpTerminalDelegatedTaskStatus.Type;
146
147export const OrchestratorMcpDelegateTaskInput = Schema.Struct({
148 task: OrchestratorMcpPrompt,
149 target: Schema.optional(OrchestratorMcpTarget),
150 title: Schema.optional(OrchestratorMcpTitle),
151 role: Schema.optional(OrchestratorMcpTaskRole),
152 isolation: Schema.optional(
153 Schema.Literals(["shared", "worktree"]).annotate({
154 description:
155 "'shared' (default): parent checkout. 'worktree': new prepared checkout from the parent commit, for a separate checkout or PR per child. Uncommitted edits stay out.",
156 }),
157 ),
158 mode: Schema.optional(
159 Schema.Literals(["async", "wait"]).annotate({
160 description:
161 "Default 'async'. 'wait' only if this turn needs the result. A question or approval ends the wait.",
162 }),
163 ),
164 timeoutMs: Schema.optional(Schema.Finite).annotate({
165 description: "Mode 'wait' only. Default 10 min. A timeout does not cancel the child.",
166 }),
167 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
168 runtimeMode: Schema.optional(
169 OrchestratorMcpRuntimeMode.annotate({
170 description:
171 "Omit unless the user asks for a supervised child. Narrow modes pause for human approval, not read-only. Above yours is rejected.",
172 }),
173 ),
174 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
175});
176export type OrchestratorMcpDelegateTaskInput = typeof OrchestratorMcpDelegateTaskInput.Type;
177
178// Set only on results for still-running tasks whose completion will wake the parent.
179export const ORCHESTRATOR_MCP_RUNNING_TASK_NEXT =
180 "Completion wakes this thread. End your turn unless you need this result now.";
181const OrchestratorMcpRunningTaskNext = Schema.Literal(ORCHESTRATOR_MCP_RUNNING_TASK_NEXT);
182
183export const OrchestratorMcpDelegateTaskResult = Schema.Struct({
184 taskId: NodeId,
185 childThreadId: ThreadId,
186 link: Schema.optional(Schema.String),
187 childRunId: Schema.NullOr(RunId),
188 childNodeId: NodeId,
189 status: OrchestratorMcpDelegatedTaskStatus,
190 workState: Schema.Literals(["working", "waiting_for_children", "result_available"]),
191 hasPendingChildRuns: Schema.Boolean,
192 latestTerminalRunId: Schema.NullOr(RunId),
193 latestTerminalStatus: Schema.NullOr(OrchestratorMcpTerminalDelegatedTaskStatus),
194 latestTerminalSummary: Schema.NullOr(Schema.String),
195 latestTerminalResultContextTransferId: Schema.NullOr(ContextTransferId),
196 providerInstanceId: ProviderInstanceId,
197 model: Schema.NullOr(Schema.String),
198 options: Schema.optional(Schema.Array(ProviderOptionSelection)),
199 summary: Schema.NullOr(Schema.String),
200 resultContextTransferId: Schema.NullOr(ContextTransferId),
201 hasPendingQuestion: Schema.Boolean.annotate({
202 description:
203 "A question blocks the child and ends a wait. Answer via `t3_pending_request_*` on `childThreadId`, or the user does.",
204 }),
205 pendingApproval: Schema.NullOr(
206 Schema.Struct({ requestId: RuntimeRequestId, kind: ProviderRequestKind, runId: RunId }),
207 ).annotate({
208 description: "Oldest pending approval, or null. Ends a wait. Grants no approval rights.",
209 }),
210 waitTimedOut: Schema.Boolean.annotate({
211 description: "True only on the timed-out wait call. The child keeps running.",
212 }),
213 next: Schema.optional(OrchestratorMcpRunningTaskNext),
214});
215export type OrchestratorMcpDelegateTaskResult = typeof OrchestratorMcpDelegateTaskResult.Type;
216
217export const OrchestratorMcpTaskStatusInput = Schema.Struct({
218 taskId: NodeId,
219});
220export type OrchestratorMcpTaskStatusInput = typeof OrchestratorMcpTaskStatusInput.Type;
221
222export const OrchestratorMcpTaskCancelInput = Schema.Struct({
223 taskId: NodeId,
224 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
225 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
226});
227export type OrchestratorMcpTaskCancelInput = typeof OrchestratorMcpTaskCancelInput.Type;
228
229export const OrchestratorMcpTaskCancelResult = Schema.Struct({
230 taskId: NodeId,
231 status: Schema.Literals(["cancel_requested", "completed", "failed", "cancelled", "interrupted"]),
232});
233export type OrchestratorMcpTaskCancelResult = typeof OrchestratorMcpTaskCancelResult.Type;
234
235export const OrchestratorMcpCreateThreadRequest = Schema.Struct({
236 prompt: Schema.optional(OrchestratorMcpPrompt),
237 title: Schema.optional(OrchestratorMcpTitle),
238 target: Schema.optional(OrchestratorMcpTarget),
239 runtimeMode: Schema.optional(OrchestratorMcpRuntimeMode),
240 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
241});
242export type OrchestratorMcpCreateThreadRequest = typeof OrchestratorMcpCreateThreadRequest.Type;
243
244export const OrchestratorMcpCreateThreadsInput = Schema.Struct({
245 threads: Schema.Array(OrchestratorMcpCreateThreadRequest).check(
246 Schema.isMinLength(1),
247 Schema.isMaxLength(20),
248 ),
249 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
250});
251export type OrchestratorMcpCreateThreadsInput = typeof OrchestratorMcpCreateThreadsInput.Type;
252
253export const OrchestratorMcpCreatedThreadStatus = Schema.Union([
254 Schema.Literal("idle"),
255 Schema.Literal("preparing"),
256 Schema.Literal("starting"),
257 OrchestratorMcpDelegatedTaskStatus,
258 Schema.Literal("rolled_back"),
259]);
260export type OrchestratorMcpCreatedThreadStatus = typeof OrchestratorMcpCreatedThreadStatus.Type;
261
262export const OrchestratorMcpCreatedThread = Schema.Struct({
263 threadId: ThreadId,
264 link: Schema.optional(Schema.String),
265 runId: Schema.NullOr(RunId),
266 status: OrchestratorMcpCreatedThreadStatus,
267 title: Schema.String,
268 createdBy: OrchestrationV2Actor,
269 creationSource: OrchestrationV2CreationSource,
270 providerInstanceId: ProviderInstanceId,
271 model: Schema.String,
272});
273export type OrchestratorMcpCreatedThread = typeof OrchestratorMcpCreatedThread.Type;
274
275export const OrchestratorMcpCreateThreadsResult = Schema.Struct({
276 threads: Schema.Array(OrchestratorMcpCreatedThread),
277});
278export type OrchestratorMcpCreateThreadsResult = typeof OrchestratorMcpCreateThreadsResult.Type;
279
280export const OrchestratorMcpThreadStatus = Schema.Union([
281 Schema.Literal("idle"),
282 OrchestrationV2RunStatus,
283]);
284export type OrchestratorMcpThreadStatus = typeof OrchestratorMcpThreadStatus.Type;
285
286const OrchestratorMcpProjectTarget = Schema.optional(
287 ProjectId.annotate({
288 description: "Project to use. Default: your thread's project. Required outside a thread.",
289 }),
290);
291
292export const OrchestratorMcpThreadListInput = Schema.Struct({
293 projectId: OrchestratorMcpProjectTarget,
294 statuses: Schema.optional(
295 Schema.Array(OrchestratorMcpThreadStatus).check(Schema.isMaxLength(10)),
296 ),
297 titleContains: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(256))),
298 settled: Schema.optional(Schema.Boolean),
299 snoozed: Schema.optional(Schema.Boolean),
300 includeSubagents: Schema.optional(Schema.Boolean),
301 cursor: Schema.optional(NonNegativeInt),
302 limit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(100))),
303});
304export type OrchestratorMcpThreadListInput = typeof OrchestratorMcpThreadListInput.Type;
305
306/** state is null until the host is read. */
307export const OrchestratorMcpThreadPullRequest = Schema.Struct({
308 ...ThreadPullRequestKey.fields,
309 url: TrimmedNonEmptyString,
310 source: ThreadPullRequestLinkSource,
311 state: Schema.NullOr(PullRequestState),
312});
313export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
314
315export const OrchestratorMcpThreadListItem = Schema.Struct({
316 threadId: ThreadId,
317 title: Schema.String,
318 link: Schema.optional(Schema.String),
319 createdBy: OrchestrationV2Actor,
320 creationSource: OrchestrationV2CreationSource,
321 status: OrchestratorMcpThreadStatus,
322 latestRunId: Schema.NullOr(RunId),
323 providerInstanceId: ProviderInstanceId,
324 model: Schema.String,
325 runtimeMode: RuntimeMode,
326 interactionMode: ProviderInteractionMode,
327 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
328 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
329 settled: Schema.Boolean,
330 settledAt: Schema.NullOr(IsoDateTime),
331 snoozed: Schema.Boolean,
332 snoozedUntil: Schema.NullOr(IsoDateTime),
333 parentThreadId: Schema.NullOr(ThreadId),
334 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
335 itemCount: NonNegativeInt,
336 createdAt: IsoDateTime,
337 updatedAt: IsoDateTime,
338});
339export type OrchestratorMcpThreadListItem = typeof OrchestratorMcpThreadListItem.Type;
340
341export const OrchestratorMcpThreadListResult = Schema.Struct({
342 projectId: ProjectId,
343 currentThreadId: Schema.NullOr(ThreadId),
344 threads: Schema.Array(OrchestratorMcpThreadListItem),
345 nextCursor: Schema.NullOr(NonNegativeInt),
346 total: NonNegativeInt,
347});
348export type OrchestratorMcpThreadListResult = typeof OrchestratorMcpThreadListResult.Type;
349
350// Codex hides `minimum` and `maximum` from the model, so a value above the maximum clamps on
351// decode instead of failing the call; pagination returns the rest. Values below 1 still fail:
352// 0 asks for nothing, and answering it with one item would be a different request.
353const clampedPositiveInt = (maximum: number) =>
354 PositiveInt.pipe(
355 Schema.decodeTo(
356 PositiveInt.check(Schema.isLessThanOrEqualTo(maximum)),
357 SchemaTransformation.transform({
358 decode: (value) => Math.min(value, maximum),
359 encode: (value) => value,
360 }),
361 ),
362 );
363
364export const OrchestratorMcpThreadReadInput = Schema.Struct({
365 threadId: ThreadId,
366 itemId: Schema.optional(TurnItemId),
367 textOffset: Schema.optional(NonNegativeInt),
368 view: Schema.optional(Schema.Literals(["messages", "activity"])),
369 afterPosition: Schema.optional(NonNegativeInt),
370 limit: Schema.optional(clampedPositiveInt(100)).annotate({
371 description: "Max items, 1 to 100.",
372 }),
373 runLimit: Schema.optional(clampedPositiveInt(50)).annotate({
374 description: "Max recent runs, 1 to 50.",
375 }),
376 maxCharsPerItem: Schema.optional(clampedPositiveInt(50_000)).annotate({
377 description: "Max chars per item, 1 to 50000.",
378 }),
379});
380export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type;
381
382export const OrchestratorMcpThreadDetail = Schema.Struct({
383 threadId: ThreadId,
384 projectId: ProjectId,
385 title: Schema.String,
386 link: Schema.optional(Schema.String),
387 createdBy: OrchestrationV2Actor,
388 creationSource: OrchestrationV2CreationSource,
389 status: OrchestratorMcpThreadStatus,
390 latestRunId: Schema.NullOr(RunId),
391 activeRunId: Schema.NullOr(RunId),
392 providerInstanceId: ProviderInstanceId,
393 model: Schema.String,
394 runtimeMode: RuntimeMode,
395 interactionMode: ProviderInteractionMode,
396 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
397 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
398 titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
399 branch: Schema.NullOr(Schema.String),
400 worktreePath: Schema.NullOr(Schema.String),
401 parentThreadId: Schema.NullOr(ThreadId),
402 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
403 runCount: NonNegativeInt,
404 itemCount: NonNegativeInt,
405 pendingRequestCount: NonNegativeInt,
406 archived: Schema.Boolean,
407 settled: Schema.Boolean,
408 settledAt: Schema.NullOr(IsoDateTime),
409 snoozed: Schema.Boolean,
410 snoozedUntil: Schema.NullOr(IsoDateTime),
411 createdAt: IsoDateTime,
412 updatedAt: IsoDateTime,
413});
414export type OrchestratorMcpThreadDetail = typeof OrchestratorMcpThreadDetail.Type;
415
416export const OrchestratorMcpThreadRun = Schema.Struct({
417 runId: RunId,
418 ordinal: PositiveInt,
419 status: OrchestrationV2RunStatus,
420 providerInstanceId: ProviderInstanceId,
421 model: Schema.String,
422 requestedAt: IsoDateTime,
423 startedAt: Schema.NullOr(IsoDateTime),
424 completedAt: Schema.NullOr(IsoDateTime),
425});
426export type OrchestratorMcpThreadRun = typeof OrchestratorMcpThreadRun.Type;
427
428export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
429 position: NonNegativeInt,
430 visibility: Schema.Literals(["local", "inherited", "synthetic"]),
431 sourceThreadId: ThreadId,
432 itemId: TurnItemId,
433 subagentId: Schema.optional(NodeId),
434 runId: Schema.NullOr(RunId),
435 messageId: Schema.NullOr(MessageId),
436 createdBy: Schema.NullOr(OrchestrationV2Actor),
437 creationSource: Schema.NullOr(OrchestrationV2CreationSource),
438 senderThreadId: Schema.optional(ThreadId),
439 type: Schema.String,
440 status: OrchestrationV2TurnItemStatus,
441 title: Schema.NullOr(Schema.String),
442 text: Schema.NullOr(Schema.String),
443 textTruncated: Schema.Boolean,
444 nextTextOffset: Schema.optional(Schema.NullOr(NonNegativeInt)),
445 updatedAt: IsoDateTime,
446});
447export type OrchestratorMcpThreadTimelineItem = typeof OrchestratorMcpThreadTimelineItem.Type;
448
449export const OrchestratorMcpThreadReadResult = Schema.Struct({
450 thread: OrchestratorMcpThreadDetail,
451 recentRuns: Schema.Array(OrchestratorMcpThreadRun),
452 items: Schema.Array(OrchestratorMcpThreadTimelineItem),
453 nextPosition: Schema.NullOr(NonNegativeInt),
454 hasMore: Schema.Boolean,
455});
456export type OrchestratorMcpThreadReadResult = typeof OrchestratorMcpThreadReadResult.Type;
457
458export const OrchestratorMcpThreadSendInput = Schema.Struct({
459 threadId: ThreadId,
460 message: OrchestratorMcpPrompt,
461 mode: Schema.optional(Schema.Literals(["auto", "queue", "steer", "restart"])),
462 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
463});
464export type OrchestratorMcpThreadSendInput = typeof OrchestratorMcpThreadSendInput.Type;
465
466export const OrchestratorMcpThreadSendResult = Schema.Struct({
467 threadId: ThreadId,
468 link: Schema.optional(Schema.String),
469 messageId: MessageId,
470 runId: RunId,
471 taskId: Schema.optional(NodeId),
472 status: OrchestrationV2RunStatus,
473 delivery: Schema.Literals(["started", "queued", "steered", "restarted"]),
474});
475export type OrchestratorMcpThreadSendResult = typeof OrchestratorMcpThreadSendResult.Type;
476
477export const OrchestratorMcpThreadWaitInput = Schema.Struct({
478 threadId: ThreadId,
479 runId: Schema.optional(RunId),
480 timeoutMs: Schema.optional(Schema.Finite),
481});
482export type OrchestratorMcpThreadWaitInput = typeof OrchestratorMcpThreadWaitInput.Type;
483
484export const OrchestratorMcpThreadWaitResult = Schema.Struct({
485 threadId: ThreadId,
486 runId: Schema.NullOr(RunId),
487 status: OrchestratorMcpThreadStatus,
488 timedOut: Schema.Boolean,
489 next: Schema.optional(OrchestratorMcpRunningTaskNext),
490});
491export type OrchestratorMcpThreadWaitResult = typeof OrchestratorMcpThreadWaitResult.Type;
492
493export const OrchestratorMcpThreadInterruptInput = Schema.Struct({
494 threadId: ThreadId,
495 runId: Schema.optional(RunId),
496 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
497 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
498});
499export type OrchestratorMcpThreadInterruptInput = typeof OrchestratorMcpThreadInterruptInput.Type;
500
501export const OrchestratorMcpThreadInterruptResult = Schema.Struct({
502 threadId: ThreadId,
503 runId: Schema.NullOr(RunId),
504 status: Schema.Union([
505 Schema.Literal("interrupt_requested"),
506 Schema.Literal("no_active_run"),
507 Schema.Literals(["completed", "failed", "cancelled", "interrupted", "rolled_back"]),
508 ]),
509});
510export type OrchestratorMcpThreadInterruptResult = typeof OrchestratorMcpThreadInterruptResult.Type;
511
512export const OrchestratorMcpCapabilitiesInput = Schema.Struct({
513 search: Schema.optional(
514 TrimmedNonEmptyString.check(Schema.isMaxLength(200)).annotate({
515 description: "Match model ids and labels. Replaces the short list.",
516 }),
517 ),
518});
519export type OrchestratorMcpCapabilitiesInput = typeof OrchestratorMcpCapabilitiesInput.Type;
520
521export const OrchestratorMcpModelOption = Schema.Struct({
522 id: Schema.String,
523 values: Schema.Array(ProviderOptionSelectionValue),
524 default: Schema.optional(ProviderOptionSelectionValue),
525});
526export type OrchestratorMcpModelOption = typeof OrchestratorMcpModelOption.Type;
527
528export const OrchestratorMcpProviderCapability = Schema.Struct({
529 providerInstanceId: ProviderInstanceId,
530 driverKind: ProviderDriverKind,
531 displayName: Schema.NullOr(Schema.String),
532 models: Schema.Array(
533 Schema.Struct({
534 id: Schema.String,
535 /** Omitted when it only restates the id. */
536 label: Schema.optional(Schema.String),
537 options: Schema.optional(Schema.Array(OrchestratorMcpModelOption)),
538 }),
539 ),
540 /** Models left out of `models`: unlisted visible models, or matches past the cap with `search`. */
541 omittedModels: Schema.optional(NonNegativeInt),
542 runtimeModes: Schema.optional(Schema.Array(RuntimeMode)),
543 canRunChildTask: Schema.Boolean,
544 canRunCrossProviderChildTask: Schema.Boolean,
545 constraints: Schema.Array(Schema.String),
546});
547export type OrchestratorMcpProviderCapability = typeof OrchestratorMcpProviderCapability.Type;
548
549export const OrchestratorMcpCapabilitiesResult = Schema.Struct({
550 parentThreadId: Schema.NullOr(ThreadId),
551 inheritedProviderInstanceId: Schema.NullOr(ProviderInstanceId),
552 inheritedModel: Schema.NullOr(Schema.String),
553 inheritedOptions: Schema.optional(Schema.Array(ProviderOptionSelection)),
554 runtimeMode: RuntimeMode,
555 interactionMode: ProviderInteractionMode,
556 providers: Schema.Array(OrchestratorMcpProviderCapability),
557 features: Schema.Struct({
558 appOwnedSubagents: Schema.Boolean,
559 asyncPolling: Schema.Boolean,
560 cancellation: Schema.Boolean,
561 batchThreadCreation: Schema.Boolean,
562 threadManagement: Schema.Boolean,
563 incrementalThreadRead: Schema.Boolean,
564 scheduledTasks: Schema.Boolean,
565 maxBatchThreads: Schema.Number,
566 }),
567});
568export type OrchestratorMcpCapabilitiesResult = typeof OrchestratorMcpCapabilitiesResult.Type;
569
570export const OrchestratorMcpScheduleTaskInput = Schema.Struct({
571 projectId: OrchestratorMcpProjectTarget,
572 prompt: OrchestratorMcpPrompt,
573 schedule: OrchestratorMcpSchedule,
574 title: Schema.optional(OrchestratorMcpTitle),
575 enabled: Schema.optional(Schema.Boolean.annotate({ description: "Default true." })),
576 bindToCurrentThread: Schema.optional(
577 Schema.Boolean.annotate({
578 description: "Default true: runs post in this thread. False: new thread per run.",
579 }),
580 ),
581 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
582});
583export type OrchestratorMcpScheduleTaskInput = typeof OrchestratorMcpScheduleTaskInput.Type;
584
585export const OrchestratorMcpScheduledTask = Schema.Struct({
586 scheduledTaskId: ScheduledTaskId,
587 title: Schema.String,
588 prompt: Schema.String,
589 enabled: Schema.Boolean,
590 projectId: ProjectId,
591 boundThreadId: Schema.NullOr(ThreadId),
592 schedule: ScheduledTaskSchedule,
593 nextRunAt: Schema.NullOr(IsoDateTime),
594 lastRunStatus: ScheduledTaskRunStatus,
595 webhookUrl: Schema.optional(Schema.String).annotate({
596 description:
597 "Public URL for the sender. Absent: no T3 Connect tunnel. The user must enable T3 Connect remote access.",
598 }),
599 webhookSignature: Schema.optional(Schema.Literals(["none", "set"])),
600});
601export type OrchestratorMcpScheduledTask = typeof OrchestratorMcpScheduledTask.Type;
602
603export const OrchestratorMcpScheduleTaskResult = OrchestratorMcpScheduledTask;
604export type OrchestratorMcpScheduleTaskResult = typeof OrchestratorMcpScheduleTaskResult.Type;
605
606export const OrchestratorMcpListScheduledTasksInput = Schema.Struct({
607 projectId: Schema.optional(
608 ProjectId.annotate({
609 description: "Default: your thread's project, or all outside a thread.",
610 }),
611 ),
612});
613export type OrchestratorMcpListScheduledTasksInput =
614 typeof OrchestratorMcpListScheduledTasksInput.Type;
615
616export const OrchestratorMcpListScheduledTasksResult = Schema.Struct({
617 tasks: Schema.Array(OrchestratorMcpScheduledTask),
618});
619export type OrchestratorMcpListScheduledTasksResult =
620 typeof OrchestratorMcpListScheduledTasksResult.Type;
621
622export const OrchestratorMcpUpdateScheduledTaskInput = Schema.Struct({
623 scheduledTaskId: ScheduledTaskId,
624 prompt: Schema.optional(OrchestratorMcpPrompt),
625 title: Schema.optional(OrchestratorMcpTitle),
626 schedule: Schema.optional(OrchestratorMcpSchedule),
627 enabled: Schema.optional(Schema.Boolean),
628 bindToCurrentThread: Schema.optional(Schema.Boolean),
629});
630export type OrchestratorMcpUpdateScheduledTaskInput =
631 typeof OrchestratorMcpUpdateScheduledTaskInput.Type;
632
633export const OrchestratorMcpRequestSecretInput = Schema.Struct({
634 label: TrimmedNonEmptyString.annotate({
635 description: "Card title, such as 'GitHub webhook secret'.",
636 }),
637 reason: TrimmedNonEmptyString.annotate({
638 description: "What it is for and where to get it.",
639 }),
640 placeholder: Schema.optional(TrimmedNonEmptyString),
641 delivery: Schema.optional(Schema.Literals(["secretRef", "file"])).annotate({
642 description:
643 'secretRef (default) for a T3 tool. file for a shell CLI: read the path in your command, e.g. TOKEN="$(cat <file>)" wrangler whoami.',
644 }),
645 timeoutMs: Schema.optional(
646 Schema.Int.check(Schema.isBetween({ minimum: 1_000, maximum: 60 * 60 * 1_000 })),
647 ).annotate({ description: "Default 10 min." }),
648 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId).annotate({
649 description: "Retry key for this ask. New key after a timeout or cancel.",
650 }),
651});
652export type OrchestratorMcpRequestSecretInput = typeof OrchestratorMcpRequestSecretInput.Type;
653
654export const OrchestratorMcpRequestSecretResult = Schema.Union([
655 Schema.Struct({
656 status: Schema.Literal("saved"),
657 secretRef: SecretRef.annotate({
658 description: "One-use. Pass to a tool that accepts a secretRef. You never see the value.",
659 }),
660 }),
661 Schema.Struct({
662 status: Schema.Literal("saved").annotate({ description: "file holds the value." }),
663 file: Schema.String.annotate({
664 description:
665 "Owner-only file with the value. Read it inside commands and never print it. Deleted after 24 hours.",
666 }),
667 }),
668 Schema.Struct({
669 status: Schema.Literals(["declined", "cancelled", "timed_out"]).annotate({
670 description:
671 "declined: user chose not to. cancelled: ended with the run. timed_out: no answer in time. Ask again with a new `clientRequestId` if still needed.",
672 }),
673 }),
674]);
675export type OrchestratorMcpRequestSecretResult = typeof OrchestratorMcpRequestSecretResult.Type;
676
677export const OrchestratorMcpDeleteScheduledTaskInput = Schema.Struct({
678 scheduledTaskId: ScheduledTaskId,
679});
680export type OrchestratorMcpDeleteScheduledTaskInput =
681 typeof OrchestratorMcpDeleteScheduledTaskInput.Type;
682
683export const OrchestratorMcpDeleteScheduledTaskResult = Schema.Struct({
684 scheduledTaskId: ScheduledTaskId,
685 deleted: Schema.Boolean,
686});
687export type OrchestratorMcpDeleteScheduledTaskResult =
688 typeof OrchestratorMcpDeleteScheduledTaskResult.Type;
689
690export class OrchestratorMcpFailure extends Schema.TaggedError<OrchestratorMcpFailure>()(
691 "OrchestratorMcpFailure",
692 {
693 code: Schema.Literals([
694 "capability_denied",
695 "parent_not_active",
696 "provider_unavailable",
697 "model_unavailable",
698 "runtime_mode_escalation_denied",
699 "interaction_mode_escalation_denied",
700 "task_not_found",
701 "task_not_cancellable",
702 "thread_not_found",
703 "run_not_found",
704 "thread_not_sendable",
705 "thread_not_interruptible",
706 "invalid_request",
707 "orchestration_error",
708 "thread_credential_required",
709 "target_required",
710 ]),
711 message: Schema.String,
712 },
713) {}