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)).annotate({
44 description: "Complete task or message text for the target agent.",
45});
46const OrchestratorMcpTitle = TrimmedNonEmptyString.check(Schema.isMaxLength(512)).annotate({
47 description: "Optional concise display title.",
48});
49const OrchestratorMcpClientRequestId = TrimmedNonEmptyString.check(
50 Schema.isMaxLength(256),
51).annotate({ description: "Stable idempotency key to reuse when retrying this mutation." });
52
53/**
54 * OpenCode 1.15 has been observed serializing nested MCP union objects as JSON
55 * strings. Keep the structured object as the documented form while accepting
56 * that compatibility shape at the tool boundary and decoding it immediately.
57 */
58const OrchestratorMcpScheduleFromJsonString = Schema.fromJsonString(
59 ScheduledTaskUpsertSchedule,
60).annotate({
61 description:
62 "Compatibility-only JSON encoding of the schedule object. Prefer a structured object.",
63});
64
65const OrchestratorMcpSchedule = Schema.Union([
66 ScheduledTaskUpsertSchedule,
67 OrchestratorMcpScheduleFromJsonString,
68]).annotate({
69 description:
70 "Trigger object: {type:'interval', everyMs}, {type:'fixed_time', timeOfDay, weekdays?}, or {type:'webhook'} to run on each request to a generated URL. Never stringify it unless the provider requires the compatibility form.",
71});
72
73const OrchestratorMcpTargetOptionsFromRecord = Schema.Record(
74 Schema.String,
75 ProviderOptionSelectionValue,
76).pipe(
77 Schema.decodeTo(
78 Schema.Array(ProviderOptionSelection),
79 SchemaTransformation.transformEffect({
80 decode: (record) =>
81 Effect.succeed(Object.entries(record).map(([id, value]) => ({ id, value }))),
82 encode: (selections: ReadonlyArray<ProviderOptionSelection>) =>
83 Effect.succeed(
84 Object.fromEntries(selections.map((selection) => [selection.id, selection.value])),
85 ),
86 }),
87 ),
88);
89
90export const OrchestratorMcpTargetOptions = Schema.Union([
91 Schema.Array(ProviderOptionSelection),
92 OrchestratorMcpTargetOptionsFromRecord,
93]);
94export type OrchestratorMcpTargetOptions = typeof OrchestratorMcpTargetOptions.Type;
95
96export const OrchestratorMcpTarget = Schema.Struct({
97 providerInstanceId: Schema.optional(
98 ProviderInstanceId.annotate({
99 description: "Configured provider instance id from orchestrator_capabilities.",
100 }),
101 ),
102 driverKind: Schema.optional(
103 ProviderDriverKind.annotate({
104 description: "Provider driver kind; prefer providerInstanceId when available.",
105 }),
106 ),
107 model: Schema.optional(
108 TrimmedNonEmptyString.annotate({
109 description: "Model id advertised for the selected provider instance.",
110 }),
111 ),
112 options: Schema.optional(
113 OrchestratorMcpTargetOptions.annotate({
114 description:
115 "Model options from orchestrator_capabilities. For the same provider instance and model, overrides individual inherited values; [] or {} clears them. Claude: {effort: 'max', fastMode: true}; Codex: {reasoningEffort: 'max', serviceTier: 'priority'}. Only use options advertised by the selected model.",
116 }),
117 ),
118});
119export type OrchestratorMcpTarget = typeof OrchestratorMcpTarget.Type;
120
121export const OrchestratorMcpRuntimeMode = Schema.Union([Schema.Literal("inherit"), RuntimeMode]);
122export type OrchestratorMcpRuntimeMode = typeof OrchestratorMcpRuntimeMode.Type;
123
124export const OrchestratorMcpInteractionMode = Schema.Union([
125 Schema.Literal("inherit"),
126 ProviderInteractionMode,
127]);
128export type OrchestratorMcpInteractionMode = typeof OrchestratorMcpInteractionMode.Type;
129
130export const OrchestratorMcpTaskRole = Schema.Literals([
131 "implementation",
132 "research",
133 "review",
134 "design",
135 "test",
136 "general",
137]);
138export type OrchestratorMcpTaskRole = typeof OrchestratorMcpTaskRole.Type;
139
140export const OrchestratorMcpDelegatedTaskStatus = Schema.Literals([
141 "queued",
142 "running",
143 "waiting",
144 "completed",
145 "failed",
146 "cancelled",
147 "interrupted",
148]);
149export type OrchestratorMcpDelegatedTaskStatus = typeof OrchestratorMcpDelegatedTaskStatus.Type;
150
151export const OrchestratorMcpTerminalDelegatedTaskStatus = Schema.Literals([
152 "completed",
153 "failed",
154 "cancelled",
155 "interrupted",
156]);
157export type OrchestratorMcpTerminalDelegatedTaskStatus =
158 typeof OrchestratorMcpTerminalDelegatedTaskStatus.Type;
159
160export const OrchestratorMcpDelegateTaskInput = Schema.Struct({
161 task: OrchestratorMcpPrompt.annotate({
162 description: "Self-contained task for one delegated child agent/subagent.",
163 }),
164 target: Schema.optional(OrchestratorMcpTarget),
165 title: Schema.optional(OrchestratorMcpTitle),
166 role: Schema.optional(OrchestratorMcpTaskRole),
167 isolation: Schema.optional(
168 Schema.Literals(["shared", "worktree"]).annotate({
169 description:
170 "Defaults to shared: use the parent's checkout. Worktree creates a separate checkout from the parent's current local commit before starting the child. Uncommitted edits are not copied.",
171 }),
172 ),
173 mode: Schema.optional(
174 Schema.Literals(["async", "wait"]).annotate({
175 description:
176 "Defaults to async. Use wait only when this turn needs the child's result before you can continue. A blocking question or a pending approval in the child ends the wait early with the task still running.",
177 }),
178 ),
179 timeoutMs: Schema.optional(Schema.Finite).annotate({
180 description:
181 "Wait budget for mode=wait only. Default 10 minutes. Elapsing it returns waitTimedOut=true on that call and does not cancel the child.",
182 }),
183 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
184 runtimeMode: Schema.optional(
185 OrchestratorMcpRuntimeMode.annotate({
186 description:
187 "Defaults to inherit; omit it unless the user asks for a supervised child. A narrower mode is not a read-only switch: on most providers, approval-required and auto-accept-edits pause the child at each action that needs approval until a person approves it in the child's thread, which this thread cannot do. To limit what the child does, say so in the task. A mode ranked above this thread's is rejected; that ranking does not promise the child's provider permissions are narrower than this thread's.",
188 }),
189 ),
190 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
191});
192export type OrchestratorMcpDelegateTaskInput = typeof OrchestratorMcpDelegateTaskInput.Type;
193
194export const OrchestratorMcpDelegateTaskResult = Schema.Struct({
195 taskId: NodeId,
196 childThreadId: ThreadId,
197 childRunId: Schema.NullOr(RunId),
198 childNodeId: NodeId,
199 status: OrchestratorMcpDelegatedTaskStatus,
200 workState: Schema.Literals(["working", "waiting_for_children", "result_available"]),
201 hasPendingChildRuns: Schema.Boolean,
202 latestTerminalRunId: Schema.NullOr(RunId),
203 latestTerminalStatus: Schema.NullOr(OrchestratorMcpTerminalDelegatedTaskStatus),
204 latestTerminalSummary: Schema.NullOr(Schema.String),
205 latestTerminalResultContextTransferId: Schema.NullOr(ContextTransferId),
206 providerInstanceId: ProviderInstanceId,
207 model: Schema.NullOr(Schema.String),
208 options: Schema.optional(
209 Schema.Array(ProviderOptionSelection).annotate({
210 description:
211 "Stored model option selections for the child run, or its thread before a run starts. Omitted selections use provider defaults.",
212 }),
213 ),
214 summary: Schema.NullOr(Schema.String),
215 resultContextTransferId: Schema.NullOr(ContextTransferId),
216 hasPendingQuestion: Schema.Boolean.annotate({
217 description:
218 "Blocking question ends mode=wait. Pass threadId=childThreadId to t3_pending_request_list, t3_pending_request_read (with requestId) and t3_pending_request_respond, or ask the user; the task's completion still wakes this thread.",
219 }),
220 pendingApproval: Schema.NullOr(
221 Schema.Struct({ requestId: RuntimeRequestId, kind: ProviderRequestKind, runId: RunId }),
222 ).annotate({
223 description:
224 "Identity of the oldest pending live approval for this task's own unfinished work, or null. Ends mode=wait without cancelling the child; completion still wakes this thread. This grants no approval authority. Read the fresh full request in childThreadId before responding: the record can outlive its provider callback. Decisions remain with the child's existing approval holder; pending request tools answer questions only.",
225 }),
226 waitTimedOut: Schema.Boolean.annotate({
227 description:
228 "True only on that mode=wait call when timeoutMs elapsed. The timeout does not cancel the child. Later task_status reads return false and use status for liveness.",
229 }),
230});
231export type OrchestratorMcpDelegateTaskResult = typeof OrchestratorMcpDelegateTaskResult.Type;
232
233export const OrchestratorMcpTaskStatusInput = Schema.Struct({
234 taskId: NodeId,
235});
236export type OrchestratorMcpTaskStatusInput = typeof OrchestratorMcpTaskStatusInput.Type;
237
238export const OrchestratorMcpTaskCancelInput = Schema.Struct({
239 taskId: NodeId,
240 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
241 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
242});
243export type OrchestratorMcpTaskCancelInput = typeof OrchestratorMcpTaskCancelInput.Type;
244
245export const OrchestratorMcpTaskCancelResult = Schema.Struct({
246 taskId: NodeId,
247 status: Schema.Literals(["cancel_requested", "completed", "failed", "cancelled", "interrupted"]),
248});
249export type OrchestratorMcpTaskCancelResult = typeof OrchestratorMcpTaskCancelResult.Type;
250
251export const OrchestratorMcpCreateThreadRequest = Schema.Struct({
252 prompt: Schema.optional(OrchestratorMcpPrompt),
253 title: Schema.optional(OrchestratorMcpTitle),
254 target: Schema.optional(OrchestratorMcpTarget),
255 runtimeMode: Schema.optional(OrchestratorMcpRuntimeMode),
256 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
257});
258export type OrchestratorMcpCreateThreadRequest = typeof OrchestratorMcpCreateThreadRequest.Type;
259
260export const OrchestratorMcpCreateThreadsInput = Schema.Struct({
261 threads: Schema.Array(OrchestratorMcpCreateThreadRequest).check(
262 Schema.isMinLength(1),
263 Schema.isMaxLength(20),
264 ),
265 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
266});
267export type OrchestratorMcpCreateThreadsInput = typeof OrchestratorMcpCreateThreadsInput.Type;
268
269export const OrchestratorMcpCreatedThreadStatus = Schema.Union([
270 Schema.Literal("idle"),
271 Schema.Literal("preparing"),
272 Schema.Literal("starting"),
273 OrchestratorMcpDelegatedTaskStatus,
274 Schema.Literal("rolled_back"),
275]);
276export type OrchestratorMcpCreatedThreadStatus = typeof OrchestratorMcpCreatedThreadStatus.Type;
277
278export const OrchestratorMcpCreatedThread = Schema.Struct({
279 threadId: ThreadId,
280 runId: Schema.NullOr(RunId),
281 status: OrchestratorMcpCreatedThreadStatus,
282 title: Schema.String,
283 createdBy: OrchestrationV2Actor,
284 creationSource: OrchestrationV2CreationSource,
285 providerInstanceId: ProviderInstanceId,
286 model: Schema.String,
287});
288export type OrchestratorMcpCreatedThread = typeof OrchestratorMcpCreatedThread.Type;
289
290export const OrchestratorMcpCreateThreadsResult = Schema.Struct({
291 threads: Schema.Array(OrchestratorMcpCreatedThread),
292});
293export type OrchestratorMcpCreateThreadsResult = typeof OrchestratorMcpCreateThreadsResult.Type;
294
295export const OrchestratorMcpThreadStatus = Schema.Union([
296 Schema.Literal("idle"),
297 OrchestrationV2RunStatus,
298]);
299export type OrchestratorMcpThreadStatus = typeof OrchestratorMcpThreadStatus.Type;
300
301const OrchestratorMcpProjectTarget = Schema.optional(
302 ProjectId.annotate({
303 description:
304 "Project to act on. Omit for the calling thread's project; required when the caller is not a T3 thread.",
305 }),
306);
307
308export const OrchestratorMcpThreadListInput = Schema.Struct({
309 projectId: OrchestratorMcpProjectTarget,
310 statuses: Schema.optional(
311 Schema.Array(OrchestratorMcpThreadStatus).check(Schema.isMaxLength(10)),
312 ),
313 titleContains: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(256))),
314 settled: Schema.optional(Schema.Boolean),
315 snoozed: Schema.optional(Schema.Boolean),
316 includeSubagents: Schema.optional(Schema.Boolean),
317 cursor: Schema.optional(NonNegativeInt),
318 limit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(100))),
319});
320export type OrchestratorMcpThreadListInput = typeof OrchestratorMcpThreadListInput.Type;
321
322/** A pull request linked to a thread; `state` is null until the host has been read. */
323export const OrchestratorMcpThreadPullRequest = Schema.Struct({
324 ...ThreadPullRequestKey.fields,
325 url: TrimmedNonEmptyString,
326 source: ThreadPullRequestLinkSource,
327 state: Schema.NullOr(PullRequestState),
328});
329export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
330
331export const OrchestratorMcpThreadListItem = Schema.Struct({
332 threadId: ThreadId,
333 title: Schema.String,
334 createdBy: OrchestrationV2Actor,
335 creationSource: OrchestrationV2CreationSource,
336 status: OrchestratorMcpThreadStatus,
337 latestRunId: Schema.NullOr(RunId),
338 providerInstanceId: ProviderInstanceId,
339 model: Schema.String,
340 runtimeMode: RuntimeMode,
341 interactionMode: ProviderInteractionMode,
342 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
343 /** Missing on older servers. */
344 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
345 settled: Schema.Boolean,
346 settledAt: Schema.NullOr(IsoDateTime),
347 snoozed: Schema.Boolean,
348 snoozedUntil: Schema.NullOr(IsoDateTime),
349 parentThreadId: Schema.NullOr(ThreadId),
350 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
351 itemCount: NonNegativeInt,
352 createdAt: IsoDateTime,
353 updatedAt: IsoDateTime,
354});
355export type OrchestratorMcpThreadListItem = typeof OrchestratorMcpThreadListItem.Type;
356
357export const OrchestratorMcpThreadListResult = Schema.Struct({
358 projectId: ProjectId,
359 currentThreadId: Schema.NullOr(ThreadId),
360 threads: Schema.Array(OrchestratorMcpThreadListItem),
361 nextCursor: Schema.NullOr(NonNegativeInt),
362 total: NonNegativeInt,
363});
364export type OrchestratorMcpThreadListResult = typeof OrchestratorMcpThreadListResult.Type;
365
366// Codex hides `minimum` and `maximum` from the model, so a value above the maximum clamps on
367// decode instead of failing the call; pagination returns the rest. Values below 1 still fail:
368// 0 asks for nothing, and answering it with one item would be a different request.
369const clampedPositiveInt = (maximum: number) =>
370 PositiveInt.pipe(
371 Schema.decodeTo(
372 PositiveInt.check(Schema.isLessThanOrEqualTo(maximum)),
373 SchemaTransformation.transform({
374 decode: (value) => Math.min(value, maximum),
375 encode: (value) => value,
376 }),
377 ),
378 );
379
380export const OrchestratorMcpThreadReadInput = Schema.Struct({
381 threadId: ThreadId,
382 itemId: Schema.optional(TurnItemId),
383 textOffset: Schema.optional(NonNegativeInt),
384 view: Schema.optional(Schema.Literals(["messages", "activity"])),
385 afterPosition: Schema.optional(NonNegativeInt),
386 limit: Schema.optional(clampedPositiveInt(100)).annotate({
387 description: "Maximum timeline items to return, from 1 to 100.",
388 }),
389 runLimit: Schema.optional(clampedPositiveInt(50)).annotate({
390 description: "Maximum recent runs to return, from 1 to 50.",
391 }),
392 maxCharsPerItem: Schema.optional(clampedPositiveInt(50_000)).annotate({
393 description: "Maximum text characters per item, from 1 to 50000.",
394 }),
395});
396export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type;
397
398export const OrchestratorMcpThreadDetail = Schema.Struct({
399 threadId: ThreadId,
400 projectId: ProjectId,
401 title: Schema.String,
402 createdBy: OrchestrationV2Actor,
403 creationSource: OrchestrationV2CreationSource,
404 status: OrchestratorMcpThreadStatus,
405 latestRunId: Schema.NullOr(RunId),
406 activeRunId: Schema.NullOr(RunId),
407 providerInstanceId: ProviderInstanceId,
408 model: Schema.String,
409 runtimeMode: RuntimeMode,
410 interactionMode: ProviderInteractionMode,
411 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
412 /** Missing on older servers. */
413 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
414 titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
415 branch: Schema.NullOr(Schema.String),
416 worktreePath: Schema.NullOr(Schema.String),
417 parentThreadId: Schema.NullOr(ThreadId),
418 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
419 runCount: NonNegativeInt,
420 itemCount: NonNegativeInt,
421 pendingRequestCount: NonNegativeInt,
422 archived: Schema.Boolean,
423 settled: Schema.Boolean,
424 settledAt: Schema.NullOr(IsoDateTime),
425 snoozed: Schema.Boolean,
426 snoozedUntil: Schema.NullOr(IsoDateTime),
427 createdAt: IsoDateTime,
428 updatedAt: IsoDateTime,
429});
430export type OrchestratorMcpThreadDetail = typeof OrchestratorMcpThreadDetail.Type;
431
432export const OrchestratorMcpThreadRun = Schema.Struct({
433 runId: RunId,
434 ordinal: PositiveInt,
435 status: OrchestrationV2RunStatus,
436 providerInstanceId: ProviderInstanceId,
437 model: Schema.String,
438 requestedAt: IsoDateTime,
439 startedAt: Schema.NullOr(IsoDateTime),
440 completedAt: Schema.NullOr(IsoDateTime),
441});
442export type OrchestratorMcpThreadRun = typeof OrchestratorMcpThreadRun.Type;
443
444export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
445 position: NonNegativeInt,
446 visibility: Schema.Literals(["local", "inherited", "synthetic"]),
447 sourceThreadId: ThreadId,
448 itemId: TurnItemId,
449 subagentId: Schema.optional(NodeId),
450 runId: Schema.NullOr(RunId),
451 messageId: Schema.NullOr(MessageId),
452 createdBy: Schema.NullOr(OrchestrationV2Actor),
453 creationSource: Schema.NullOr(OrchestrationV2CreationSource),
454 senderThreadId: Schema.optional(ThreadId),
455 type: Schema.String,
456 status: OrchestrationV2TurnItemStatus,
457 title: Schema.NullOr(Schema.String),
458 text: Schema.NullOr(Schema.String),
459 textTruncated: Schema.Boolean,
460 nextTextOffset: Schema.optional(Schema.NullOr(NonNegativeInt)),
461 updatedAt: IsoDateTime,
462});
463export type OrchestratorMcpThreadTimelineItem = typeof OrchestratorMcpThreadTimelineItem.Type;
464
465export const OrchestratorMcpThreadReadResult = Schema.Struct({
466 thread: OrchestratorMcpThreadDetail,
467 recentRuns: Schema.Array(OrchestratorMcpThreadRun),
468 items: Schema.Array(OrchestratorMcpThreadTimelineItem),
469 nextPosition: Schema.NullOr(NonNegativeInt),
470 hasMore: Schema.Boolean,
471});
472export type OrchestratorMcpThreadReadResult = typeof OrchestratorMcpThreadReadResult.Type;
473
474export const OrchestratorMcpThreadSendInput = Schema.Struct({
475 threadId: ThreadId,
476 message: OrchestratorMcpPrompt,
477 mode: Schema.optional(Schema.Literals(["auto", "queue", "steer", "restart"])),
478 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
479});
480export type OrchestratorMcpThreadSendInput = typeof OrchestratorMcpThreadSendInput.Type;
481
482export const OrchestratorMcpThreadSendResult = Schema.Struct({
483 threadId: ThreadId,
484 messageId: MessageId,
485 runId: RunId,
486 taskId: Schema.optional(NodeId),
487 status: OrchestrationV2RunStatus,
488 delivery: Schema.Literals(["started", "queued", "steered", "restarted"]),
489});
490export type OrchestratorMcpThreadSendResult = typeof OrchestratorMcpThreadSendResult.Type;
491
492export const OrchestratorMcpThreadWaitInput = Schema.Struct({
493 threadId: ThreadId,
494 runId: Schema.optional(RunId),
495 timeoutMs: Schema.optional(Schema.Finite),
496});
497export type OrchestratorMcpThreadWaitInput = typeof OrchestratorMcpThreadWaitInput.Type;
498
499export const OrchestratorMcpThreadWaitResult = Schema.Struct({
500 threadId: ThreadId,
501 runId: Schema.NullOr(RunId),
502 status: OrchestratorMcpThreadStatus,
503 timedOut: Schema.Boolean,
504});
505export type OrchestratorMcpThreadWaitResult = typeof OrchestratorMcpThreadWaitResult.Type;
506
507export const OrchestratorMcpThreadInterruptInput = Schema.Struct({
508 threadId: ThreadId,
509 runId: Schema.optional(RunId),
510 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
511 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
512});
513export type OrchestratorMcpThreadInterruptInput = typeof OrchestratorMcpThreadInterruptInput.Type;
514
515export const OrchestratorMcpThreadInterruptResult = Schema.Struct({
516 threadId: ThreadId,
517 runId: Schema.NullOr(RunId),
518 status: Schema.Union([
519 Schema.Literal("interrupt_requested"),
520 Schema.Literal("no_active_run"),
521 Schema.Literals(["completed", "failed", "cancelled", "interrupted", "rolled_back"]),
522 ]),
523});
524export type OrchestratorMcpThreadInterruptResult = typeof OrchestratorMcpThreadInterruptResult.Type;
525
526export const OrchestratorMcpCapabilitiesInput = Schema.Struct({
527 search: Schema.optional(
528 TrimmedNonEmptyString.check(Schema.isMaxLength(200)).annotate({
529 description:
530 "Words to match against model ids and labels. Lists matching models instead of the default short list.",
531 }),
532 ),
533});
534export type OrchestratorMcpCapabilitiesInput = typeof OrchestratorMcpCapabilitiesInput.Type;
535
536export const OrchestratorMcpModelOption = Schema.Struct({
537 id: Schema.String,
538 values: Schema.Array(ProviderOptionSelectionValue),
539 default: Schema.optional(ProviderOptionSelectionValue),
540});
541export type OrchestratorMcpModelOption = typeof OrchestratorMcpModelOption.Type;
542
543export const OrchestratorMcpProviderCapability = Schema.Struct({
544 providerInstanceId: ProviderInstanceId,
545 driverKind: ProviderDriverKind,
546 displayName: Schema.NullOr(Schema.String),
547 models: Schema.Array(
548 Schema.Struct({
549 id: Schema.String,
550 /** Omitted when it only restates the id. */
551 label: Schema.optional(Schema.String),
552 options: Schema.optional(Schema.Array(OrchestratorMcpModelOption)),
553 }),
554 ),
555 /** Models left out of `models`: unlisted visible models, or matches past the cap with `search`. */
556 omittedModels: Schema.optional(NonNegativeInt),
557 runtimeModes: Schema.optional(Schema.Array(RuntimeMode)),
558 canRunChildTask: Schema.Boolean,
559 canRunCrossProviderChildTask: Schema.Boolean,
560 constraints: Schema.Array(Schema.String),
561});
562export type OrchestratorMcpProviderCapability = typeof OrchestratorMcpProviderCapability.Type;
563
564export const OrchestratorMcpCapabilitiesResult = Schema.Struct({
565 parentThreadId: Schema.NullOr(ThreadId),
566 inheritedProviderInstanceId: Schema.NullOr(ProviderInstanceId),
567 inheritedModel: Schema.NullOr(Schema.String),
568 inheritedOptions: Schema.optional(Schema.Array(ProviderOptionSelection)),
569 runtimeMode: RuntimeMode,
570 interactionMode: ProviderInteractionMode,
571 providers: Schema.Array(OrchestratorMcpProviderCapability),
572 features: Schema.Struct({
573 appOwnedSubagents: Schema.Boolean,
574 asyncPolling: Schema.Boolean,
575 cancellation: Schema.Boolean,
576 batchThreadCreation: Schema.Boolean,
577 threadManagement: Schema.Boolean,
578 incrementalThreadRead: Schema.Boolean,
579 scheduledTasks: Schema.Boolean,
580 maxBatchThreads: Schema.Number,
581 }),
582});
583export type OrchestratorMcpCapabilitiesResult = typeof OrchestratorMcpCapabilitiesResult.Type;
584
585export const OrchestratorMcpScheduleTaskInput = Schema.Struct({
586 projectId: OrchestratorMcpProjectTarget,
587 prompt: OrchestratorMcpPrompt.annotate({
588 description: "Prompt executed on every scheduled run.",
589 }),
590 schedule: OrchestratorMcpSchedule,
591 title: Schema.optional(OrchestratorMcpTitle),
592 enabled: Schema.optional(
593 Schema.Boolean.annotate({ description: "Whether the schedule starts enabled; defaults true." }),
594 ),
595 bindToCurrentThread: Schema.optional(
596 Schema.Boolean.annotate({
597 description:
598 "True (default) posts each run into this thread; false creates a fresh top-level thread per run.",
599 }),
600 ),
601 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
602});
603export type OrchestratorMcpScheduleTaskInput = typeof OrchestratorMcpScheduleTaskInput.Type;
604
605export const OrchestratorMcpScheduledTask = Schema.Struct({
606 scheduledTaskId: ScheduledTaskId,
607 title: Schema.String,
608 prompt: Schema.String,
609 enabled: Schema.Boolean,
610 projectId: ProjectId,
611 boundThreadId: Schema.NullOr(ThreadId),
612 schedule: ScheduledTaskSchedule,
613 nextRunAt: Schema.NullOr(IsoDateTime),
614 lastRunStatus: ScheduledTaskRunStatus,
615 webhookUrl: Schema.optional(Schema.String).annotate({
616 description:
617 "Public URL to give the sender. Absent when this environment has no T3 Connect managed tunnel; the user must enable T3 Connect remote access first.",
618 }),
619 webhookSignature: Schema.optional(Schema.Literals(["none", "set"])).annotate({
620 description: "Whether requests must carry a valid signature.",
621 }),
622});
623export type OrchestratorMcpScheduledTask = typeof OrchestratorMcpScheduledTask.Type;
624
625export const OrchestratorMcpScheduleTaskResult = OrchestratorMcpScheduledTask;
626export type OrchestratorMcpScheduleTaskResult = typeof OrchestratorMcpScheduleTaskResult.Type;
627
628export const OrchestratorMcpListScheduledTasksInput = Schema.Struct({
629 projectId: Schema.optional(
630 ProjectId.annotate({
631 description:
632 "Only list this project's tasks. Omit for the calling thread's project, or for every project when the caller is not a T3 thread.",
633 }),
634 ),
635});
636export type OrchestratorMcpListScheduledTasksInput =
637 typeof OrchestratorMcpListScheduledTasksInput.Type;
638
639export const OrchestratorMcpListScheduledTasksResult = Schema.Struct({
640 tasks: Schema.Array(OrchestratorMcpScheduledTask),
641});
642export type OrchestratorMcpListScheduledTasksResult =
643 typeof OrchestratorMcpListScheduledTasksResult.Type;
644
645export const OrchestratorMcpUpdateScheduledTaskInput = Schema.Struct({
646 scheduledTaskId: ScheduledTaskId,
647 prompt: Schema.optional(OrchestratorMcpPrompt),
648 title: Schema.optional(OrchestratorMcpTitle),
649 schedule: Schema.optional(OrchestratorMcpSchedule),
650 enabled: Schema.optional(Schema.Boolean),
651 bindToCurrentThread: Schema.optional(Schema.Boolean),
652});
653export type OrchestratorMcpUpdateScheduledTaskInput =
654 typeof OrchestratorMcpUpdateScheduledTaskInput.Type;
655
656export const OrchestratorMcpRequestSecretInput = Schema.Struct({
657 label: TrimmedNonEmptyString.annotate({
658 description: "What you need, shown as the card's title, e.g. 'GitHub webhook secret'.",
659 }),
660 reason: TrimmedNonEmptyString.annotate({
661 description:
662 "One or two sentences on what it is for and where the user gets or also enters it.",
663 }),
664 placeholder: Schema.optional(TrimmedNonEmptyString).annotate({
665 description: "Hint inside the input, e.g. 'Paste your GitHub token'.",
666 }),
667 timeoutMs: Schema.optional(
668 Schema.Int.check(Schema.isBetween({ minimum: 1_000, maximum: 60 * 60 * 1_000 })),
669 ).annotate({ description: "How long to wait for the user. Default 10 minutes." }),
670 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId).annotate({
671 description:
672 "Reuse when retrying a call that lost its result, so the user sees one card and its answer is returned again. Use a new id to ask again after timed_out or cancelled.",
673 }),
674});
675export type OrchestratorMcpRequestSecretInput = typeof OrchestratorMcpRequestSecretInput.Type;
676
677export const OrchestratorMcpRequestSecretResult = Schema.Union([
678 Schema.Struct({
679 status: Schema.Literal("saved").annotate({ description: "secretRef holds the value." }),
680 secretRef: SecretRef.annotate({
681 description:
682 "Pass it to a tool that accepts a secretRef; it works once, and you never see the value.",
683 }),
684 }),
685 Schema.Struct({
686 status: Schema.Literals(["declined", "cancelled", "timed_out"]).annotate({
687 description:
688 "declined: the user chose not to. cancelled: the request ended with the run. timed_out: the user did not answer in time; the card is closed, so ask again with a new clientRequestId if still needed.",
689 }),
690 }),
691]);
692export type OrchestratorMcpRequestSecretResult = typeof OrchestratorMcpRequestSecretResult.Type;
693
694export const OrchestratorMcpDeleteScheduledTaskInput = Schema.Struct({
695 scheduledTaskId: ScheduledTaskId,
696});
697export type OrchestratorMcpDeleteScheduledTaskInput =
698 typeof OrchestratorMcpDeleteScheduledTaskInput.Type;
699
700export const OrchestratorMcpDeleteScheduledTaskResult = Schema.Struct({
701 scheduledTaskId: ScheduledTaskId,
702 deleted: Schema.Boolean,
703});
704export type OrchestratorMcpDeleteScheduledTaskResult =
705 typeof OrchestratorMcpDeleteScheduledTaskResult.Type;
706
707export class OrchestratorMcpFailure extends Schema.TaggedError<OrchestratorMcpFailure>()(
708 "OrchestratorMcpFailure",
709 {
710 code: Schema.Literals([
711 "capability_denied",
712 "parent_not_active",
713 "provider_unavailable",
714 "model_unavailable",
715 "runtime_mode_escalation_denied",
716 "interaction_mode_escalation_denied",
717 "task_not_found",
718 "task_not_cancellable",
719 "thread_not_found",
720 "run_not_found",
721 "thread_not_sendable",
722 "thread_not_interruptible",
723 "invalid_request",
724 "orchestration_error",
725 "thread_credential_required",
726 "target_required",
727 ]),
728 message: Schema.String,
729 },
730) {}