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 { AuthMcpClientAccess } from "./auth.ts";
6import {
7 ContextTransferId,
8 EnvironmentId,
9 IsoDateTime,
10 MessageId,
11 NodeId,
12 NonNegativeInt,
13 PositiveInt,
14 ProjectId,
15 RunId,
16 RuntimeRequestId,
17 ScheduledTaskId,
18 SecretRef,
19 ThreadId,
20 TrimmedNonEmptyString,
21 TurnItemId,
22} from "./baseSchemas.ts";
23import {
24 ScheduledTaskRunStatus,
25 ScheduledTaskSchedule,
26 ScheduledTaskUpsertSchedule,
27} from "./scheduledTask.ts";
28import { ProviderInteractionMode, ProviderRequestKind, RuntimeMode } from "./providerPolicy.ts";
29import { PullRequestState } from "./pullRequest.ts";
30import {
31 ThreadLinkedPullRequest,
32 ThreadPullRequestKey,
33 ThreadPullRequestLinkSource,
34} from "./threadPullRequest.ts";
35import { secretRequestPageUrl } from "./secretRequest.ts";
36import { hasOnlyPairedSurrogates } from "./threadMetadataMcp.ts";
37import { LastThreadTitleRegeneration, ThreadTitleRegeneration } from "./threadTitle.ts";
38import {
39 OrchestrationV2Actor,
40 OrchestrationV2CreationSource,
41 OrchestrationV2RunStatus,
42 OrchestrationV2TurnItemStatus,
43} from "./orchestrationV2.ts";
44import { ProviderOptionSelection, ProviderOptionSelectionValue } from "./model.ts";
45import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
46
47const OrchestratorMcpPrompt = TrimmedNonEmptyString.check(Schema.isMaxLength(120_000));
48const OrchestratorMcpTitle = TrimmedNonEmptyString.check(Schema.isMaxLength(512));
49export const OrchestratorMcpClientRequestId = TrimmedNonEmptyString.check(Schema.isMaxLength(256))
50 .check(
51 Schema.makeFilter((value) =>
52 hasOnlyPairedSurrogates(value)
53 ? true
54 : "clientRequestId must contain valid paired Unicode surrogates.",
55 ),
56 )
57 .annotate({ description: "Reuse it to retry the same call. A new call gets a new key." });
58
59// OpenCode 1.15 serializes nested MCP union objects as JSON strings; decode that form at the boundary.
60const OrchestratorMcpScheduleFromJsonString = Schema.fromJsonString(
61 ScheduledTaskUpsertSchedule,
62).annotate({
63 description: "JSON-text schedule. Prefer the object form.",
64});
65
66const OrchestratorMcpSchedule = Schema.Union([
67 ScheduledTaskUpsertSchedule,
68 OrchestratorMcpScheduleFromJsonString,
69]).annotate({
70 description:
71 "Trigger: {type:'interval',everyMs}, {type:'fixed_time',timeOfDay,weekdays?}, {type:'once',runAt}, or {type:'webhook'}.",
72});
73
74const OrchestratorMcpTargetOptionsFromRecord = Schema.Record(
75 Schema.String,
76 ProviderOptionSelectionValue,
77).pipe(
78 Schema.decodeTo(
79 Schema.Array(ProviderOptionSelection),
80 SchemaTransformation.transformEffect({
81 decode: (record) =>
82 Effect.succeed(Object.entries(record).map(([id, value]) => ({ id, value }))),
83 encode: (selections: ReadonlyArray<ProviderOptionSelection>) =>
84 Effect.succeed(
85 Object.fromEntries(selections.map((selection) => [selection.id, selection.value])),
86 ),
87 }),
88 ),
89);
90
91export const OrchestratorMcpTargetOptions = Schema.Union([
92 Schema.Array(ProviderOptionSelection),
93 OrchestratorMcpTargetOptionsFromRecord,
94]);
95export type OrchestratorMcpTargetOptions = typeof OrchestratorMcpTargetOptions.Type;
96
97export const OrchestratorMcpTarget = Schema.Struct({
98 providerInstanceId: Schema.optional(
99 ProviderInstanceId.annotate({
100 description: "Provider instance id from `orchestrator_capabilities`.",
101 }),
102 ),
103 driverKind: Schema.optional(
104 ProviderDriverKind.annotate({
105 description: "Prefer `providerInstanceId`.",
106 }),
107 ),
108 model: Schema.optional(TrimmedNonEmptyString),
109 options: Schema.optional(
110 OrchestratorMcpTargetOptions.annotate({
111 description:
112 "Options from `orchestrator_capabilities`, such as {effort:'max'}. Given values override inherited. [] or {} clears.",
113 }),
114 ),
115 environmentId: Schema.optional(
116 EnvironmentId.annotate({
117 description:
118 "Linked environment to run in. Provider and model default to yours; others come from `orchestrator_capabilities` with this `environmentId`.",
119 }),
120 ),
121 projectId: Schema.optional(
122 ProjectId.annotate({
123 description:
124 "With `environmentId`: its project to run in. Default: the one with this project's repository.",
125 }),
126 ),
127});
128export type OrchestratorMcpTarget = typeof OrchestratorMcpTarget.Type;
129
130export const OrchestratorMcpRuntimeMode = Schema.Union([Schema.Literal("inherit"), RuntimeMode]);
131export type OrchestratorMcpRuntimeMode = typeof OrchestratorMcpRuntimeMode.Type;
132
133export const OrchestratorMcpInteractionMode = Schema.Union([
134 Schema.Literal("inherit"),
135 ProviderInteractionMode,
136]);
137export type OrchestratorMcpInteractionMode = typeof OrchestratorMcpInteractionMode.Type;
138
139export const OrchestratorMcpTaskRole = Schema.Literals([
140 "implementation",
141 "research",
142 "review",
143 "design",
144 "test",
145 "general",
146]);
147export type OrchestratorMcpTaskRole = typeof OrchestratorMcpTaskRole.Type;
148
149export const OrchestratorMcpDelegatedTaskStatus = Schema.Literals([
150 "queued",
151 "starting",
152 "running",
153 "waiting",
154 "completed",
155 "failed",
156 "cancelled",
157 "interrupted",
158]);
159export type OrchestratorMcpDelegatedTaskStatus = typeof OrchestratorMcpDelegatedTaskStatus.Type;
160
161export const OrchestratorMcpTerminalDelegatedTaskStatus = Schema.Literals([
162 "completed",
163 "failed",
164 "cancelled",
165 "interrupted",
166]);
167export type OrchestratorMcpTerminalDelegatedTaskStatus =
168 typeof OrchestratorMcpTerminalDelegatedTaskStatus.Type;
169
170export const OrchestratorMcpDelegateTaskInput = Schema.Struct({
171 task: OrchestratorMcpPrompt,
172 target: Schema.optional(OrchestratorMcpTarget),
173 title: Schema.optional(OrchestratorMcpTitle),
174 role: Schema.optional(OrchestratorMcpTaskRole),
175 isolation: Schema.optional(
176 Schema.Literals(["shared", "worktree"]).annotate({
177 description:
178 "'shared' (default): parent checkout. 'worktree': new prepared checkout from the parent commit, for a separate checkout or PR per child. Uncommitted edits stay out.",
179 }),
180 ),
181 mode: Schema.optional(
182 Schema.Literals(["async", "wait"]).annotate({
183 description:
184 "Default 'async'. 'wait' only if this turn needs the result. A question or approval ends the wait.",
185 }),
186 ),
187 timeoutMs: Schema.optional(Schema.Finite).annotate({
188 description: "Mode 'wait' only. Default 4 min. A timeout does not cancel the child.",
189 }),
190 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
191 runtimeMode: Schema.optional(
192 OrchestratorMcpRuntimeMode.annotate({
193 description:
194 "Omit unless the user asks for a supervised child. Narrow modes pause for human approval, not read-only. Above yours is rejected.",
195 }),
196 ),
197 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
198});
199export type OrchestratorMcpDelegateTaskInput = typeof OrchestratorMcpDelegateTaskInput.Type;
200
201// Set only on results for still-running tasks whose completion will wake the parent.
202export const ORCHESTRATOR_MCP_RUNNING_TASK_NEXT =
203 "Completion wakes this thread. Do not wait on it or poll it. Continue other work, and end your turn when none is left.";
204// A string, not a literal: linked environments on other versions send their own wording.
205const OrchestratorMcpRunningTaskNext = Schema.String;
206
207// Optional: linked environments on older versions omit it.
208const OrchestratorMcpExecutedModel = Schema.NullOr(Schema.String).annotate({
209 description:
210 "Model the provider reported running, or null when unavailable. Can differ from the requested `model`.",
211});
212
213export const OrchestratorMcpDelegateTaskResult = Schema.Struct({
214 taskId: NodeId,
215 /** Null for a task that runs in a linked environment; see `remoteChild`. */
216 childThreadId: Schema.NullOr(ThreadId),
217 /** The linked environment and thread a remote task runs as. */
218 remoteChild: Schema.optional(
219 Schema.Struct({ environmentId: EnvironmentId, threadId: ThreadId, label: Schema.String }),
220 ),
221 link: Schema.optional(Schema.String),
222 childRunId: Schema.NullOr(RunId),
223 childNodeId: NodeId,
224 status: OrchestratorMcpDelegatedTaskStatus.annotate({
225 description:
226 "starting means the child's provider has not started its turn yet, so no work has begun.",
227 }),
228 workState: Schema.Literals(["working", "waiting_for_children", "result_available"]),
229 hasPendingChildRuns: Schema.Boolean,
230 latestTerminalRunId: Schema.NullOr(RunId),
231 latestTerminalStatus: Schema.NullOr(OrchestratorMcpTerminalDelegatedTaskStatus),
232 latestTerminalSummary: Schema.NullOr(Schema.String),
233 latestTerminalResultContextTransferId: Schema.NullOr(ContextTransferId),
234 providerInstanceId: ProviderInstanceId,
235 model: Schema.NullOr(Schema.String),
236 executedModel: Schema.optional(OrchestratorMcpExecutedModel),
237 options: Schema.optional(Schema.Array(ProviderOptionSelection)),
238 summary: Schema.NullOr(Schema.String),
239 resultContextTransferId: Schema.NullOr(ContextTransferId),
240 hasPendingQuestion: Schema.Boolean.annotate({
241 description:
242 "A question blocks the child and ends a wait. Answer via `t3_pending_request` on `childThreadId`, or the user does.",
243 }),
244 pendingApproval: Schema.NullOr(
245 Schema.Struct({ requestId: RuntimeRequestId, kind: ProviderRequestKind, runId: RunId }),
246 ).annotate({
247 description: "Oldest pending approval, or null. Ends a wait. Grants no approval rights.",
248 }),
249 waitTimedOut: Schema.Boolean.annotate({
250 description: "True only on the timed-out wait call. The child keeps running.",
251 }),
252 next: Schema.optional(OrchestratorMcpRunningTaskNext),
253});
254export type OrchestratorMcpDelegateTaskResult = typeof OrchestratorMcpDelegateTaskResult.Type;
255
256export const OrchestratorMcpTaskStatusInput = Schema.Struct({
257 taskId: NodeId,
258});
259export type OrchestratorMcpTaskStatusInput = typeof OrchestratorMcpTaskStatusInput.Type;
260
261export const OrchestratorMcpTaskCancelInput = Schema.Struct({
262 taskId: NodeId,
263 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
264 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
265});
266export type OrchestratorMcpTaskCancelInput = typeof OrchestratorMcpTaskCancelInput.Type;
267
268export const OrchestratorMcpTaskCancelResult = Schema.Struct({
269 taskId: NodeId,
270 status: Schema.Literals(["cancel_requested", "completed", "failed", "cancelled", "interrupted"]),
271});
272export type OrchestratorMcpTaskCancelResult = typeof OrchestratorMcpTaskCancelResult.Type;
273
274export const OrchestratorMcpCreateThreadRequest = Schema.Struct({
275 prompt: Schema.optional(OrchestratorMcpPrompt),
276 title: Schema.optional(OrchestratorMcpTitle),
277 target: Schema.optional(OrchestratorMcpTarget),
278 runtimeMode: Schema.optional(OrchestratorMcpRuntimeMode),
279 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
280});
281export type OrchestratorMcpCreateThreadRequest = typeof OrchestratorMcpCreateThreadRequest.Type;
282
283export const OrchestratorMcpCreateThreadsInput = Schema.Struct({
284 threads: Schema.Array(OrchestratorMcpCreateThreadRequest).check(
285 Schema.isMinLength(1),
286 Schema.isMaxLength(20),
287 ),
288 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
289});
290export type OrchestratorMcpCreateThreadsInput = typeof OrchestratorMcpCreateThreadsInput.Type;
291
292export const OrchestratorMcpCreatedThreadStatus = Schema.Union([
293 Schema.Literal("idle"),
294 Schema.Literal("preparing"),
295 OrchestratorMcpDelegatedTaskStatus,
296 Schema.Literal("rolled_back"),
297]);
298export type OrchestratorMcpCreatedThreadStatus = typeof OrchestratorMcpCreatedThreadStatus.Type;
299
300export const OrchestratorMcpCreatedThread = Schema.Struct({
301 threadId: ThreadId,
302 link: Schema.optional(Schema.String),
303 runId: Schema.NullOr(RunId),
304 status: OrchestratorMcpCreatedThreadStatus,
305 title: Schema.String,
306 createdBy: OrchestrationV2Actor,
307 creationSource: OrchestrationV2CreationSource,
308 providerInstanceId: ProviderInstanceId,
309 model: Schema.String,
310});
311export type OrchestratorMcpCreatedThread = typeof OrchestratorMcpCreatedThread.Type;
312
313export const OrchestratorMcpCreateThreadsResult = Schema.Struct({
314 threads: Schema.Array(OrchestratorMcpCreatedThread),
315});
316export type OrchestratorMcpCreateThreadsResult = typeof OrchestratorMcpCreateThreadsResult.Type;
317
318export const OrchestratorMcpThreadStatus = Schema.Union([
319 Schema.Literal("idle"),
320 OrchestrationV2RunStatus,
321]);
322export type OrchestratorMcpThreadStatus = typeof OrchestratorMcpThreadStatus.Type;
323
324const OrchestratorMcpProjectTarget = Schema.optional(
325 ProjectId.annotate({
326 description: "Project to use. Default: your thread's project. Required outside a thread.",
327 }),
328);
329
330/**
331 * A linked environment to act in instead of this one. The tools that take it
332 * forward the call there, where the link's access and the caller's own modes
333 * both apply.
334 */
335export const OrchestratorMcpEnvironmentTarget = Schema.optional(
336 EnvironmentId.annotate({
337 description:
338 "Linked environment to act in. Omit for this one. Ids are then that environment's.",
339 }),
340);
341
342export const OrchestratorMcpThreadListInput = Schema.Struct({
343 environmentId: OrchestratorMcpEnvironmentTarget,
344 projectId: OrchestratorMcpProjectTarget,
345 allProjects: Schema.optional(Schema.Boolean),
346 statuses: Schema.optional(
347 Schema.Array(OrchestratorMcpThreadStatus).check(Schema.isMaxLength(10)),
348 ),
349 titleContains: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(256))),
350 settled: Schema.optional(Schema.Boolean),
351 snoozed: Schema.optional(Schema.Boolean),
352 includeSubagents: Schema.optional(Schema.Boolean),
353 cursor: Schema.optional(NonNegativeInt),
354 limit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(100))),
355});
356export type OrchestratorMcpThreadListInput = typeof OrchestratorMcpThreadListInput.Type;
357
358/** state is null until the host is read. */
359export const OrchestratorMcpThreadPullRequest = Schema.Struct({
360 ...ThreadPullRequestKey.fields,
361 url: TrimmedNonEmptyString,
362 source: ThreadPullRequestLinkSource,
363 state: Schema.NullOr(PullRequestState),
364 watching: Schema.Boolean,
365 watchStartedAt: Schema.NullOr(IsoDateTime),
366});
367export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
368
369/** Background work still open on the thread, as its provider reported it. */
370export const OrchestratorMcpThreadBackgroundTask = Schema.Struct({
371 taskId: TrimmedNonEmptyString,
372 kind: Schema.Literals(["subagent", "command", "monitor", "background_task"]),
373 description: Schema.optional(TrimmedNonEmptyString),
374 /** The agent waits on this command or monitor. Other kinds always hold the thread. */
375 awaited: Schema.optional(Schema.Literal(true)),
376 childThreadId: Schema.optional(ThreadId),
377});
378export type OrchestratorMcpThreadBackgroundTask = typeof OrchestratorMcpThreadBackgroundTask.Type;
379
380export const OrchestratorMcpThreadListItem = Schema.Struct({
381 threadId: ThreadId,
382 projectId: ProjectId,
383 title: Schema.String,
384 link: Schema.optional(Schema.String),
385 createdBy: OrchestrationV2Actor,
386 creationSource: OrchestrationV2CreationSource,
387 status: OrchestratorMcpThreadStatus,
388 latestRunId: Schema.NullOr(RunId),
389 providerInstanceId: ProviderInstanceId,
390 model: Schema.String,
391 runtimeMode: RuntimeMode,
392 interactionMode: ProviderInteractionMode,
393 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
394 /** Up to 5 open linked pull requests, watched first; list_thread_pull_requests pages all of them. */
395 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
396 pullRequestCount: Schema.optional(NonNegativeInt),
397 openPullRequestCount: Schema.optional(NonNegativeInt),
398 settled: Schema.Boolean,
399 settledAt: Schema.NullOr(IsoDateTime),
400 snoozed: Schema.Boolean,
401 snoozedUntil: Schema.NullOr(IsoDateTime),
402 /** Absent from linked environments that predate it. */
403 blockedOnThreadWait: Schema.optional(Schema.Boolean),
404 /** Absent from linked environments that predate it. */
405 pendingBackgroundTasks: Schema.optional(Schema.Array(OrchestratorMcpThreadBackgroundTask)),
406 parentThreadId: Schema.NullOr(ThreadId),
407 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
408 itemCount: NonNegativeInt,
409 createdAt: IsoDateTime,
410 updatedAt: IsoDateTime,
411});
412export type OrchestratorMcpThreadListItem = typeof OrchestratorMcpThreadListItem.Type;
413
414export const OrchestratorMcpThreadListResult = Schema.Struct({
415 /** null with `allProjects`. */
416 projectId: Schema.NullOr(ProjectId),
417 currentThreadId: Schema.NullOr(ThreadId),
418 threads: Schema.Array(OrchestratorMcpThreadListItem),
419 nextCursor: Schema.NullOr(NonNegativeInt),
420 total: NonNegativeInt,
421});
422export type OrchestratorMcpThreadListResult = typeof OrchestratorMcpThreadListResult.Type;
423
424// Codex hides `minimum` and `maximum` from the model, so a value above the maximum clamps on
425// decode instead of failing the call; pagination returns the rest. Values below 1 still fail:
426// 0 asks for nothing, and answering it with one item would be a different request.
427const clampedPositiveInt = (maximum: number) =>
428 PositiveInt.pipe(
429 Schema.decodeTo(
430 PositiveInt.check(Schema.isLessThanOrEqualTo(maximum)),
431 SchemaTransformation.transform({
432 decode: (value) => Math.min(value, maximum),
433 encode: (value) => value,
434 }),
435 ),
436 );
437
438export const OrchestratorMcpThreadReadInput = Schema.Struct({
439 environmentId: OrchestratorMcpEnvironmentTarget,
440 threadId: ThreadId,
441 itemId: Schema.optional(TurnItemId),
442 textOffset: Schema.optional(NonNegativeInt),
443 view: Schema.optional(Schema.Literals(["messages", "activity"])),
444 afterPosition: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(-1))),
445 beforePosition: Schema.optional(NonNegativeInt),
446 limit: Schema.optional(clampedPositiveInt(100)).annotate({ description: "Max 100." }),
447 runLimit: Schema.optional(clampedPositiveInt(50)).annotate({ description: "Max 50." }),
448 maxCharsPerItem: Schema.optional(clampedPositiveInt(20_000)).annotate({
449 description: "Max 20000.",
450 }),
451});
452export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type;
453
454export const OrchestratorMcpThreadDetail = Schema.Struct({
455 threadId: ThreadId,
456 projectId: ProjectId,
457 title: Schema.String,
458 link: Schema.optional(Schema.String),
459 createdBy: OrchestrationV2Actor,
460 creationSource: OrchestrationV2CreationSource,
461 status: OrchestratorMcpThreadStatus,
462 latestRunId: Schema.NullOr(RunId),
463 activeRunId: Schema.NullOr(RunId),
464 providerInstanceId: ProviderInstanceId,
465 model: Schema.String,
466 runtimeMode: RuntimeMode,
467 interactionMode: ProviderInteractionMode,
468 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
469 /** Up to 5 open linked pull requests, watched first, on the first page only; list_thread_pull_requests pages all of them. */
470 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
471 pullRequestCount: Schema.optional(NonNegativeInt),
472 openPullRequestCount: Schema.optional(NonNegativeInt),
473 titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
474 lastTitleRegeneration: Schema.optional(Schema.NullOr(LastThreadTitleRegeneration)),
475 branch: Schema.NullOr(Schema.String),
476 worktreePath: Schema.NullOr(Schema.String),
477 parentThreadId: Schema.NullOr(ThreadId),
478 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
479 runCount: NonNegativeInt,
480 itemCount: NonNegativeInt,
481 pendingRequestCount: NonNegativeInt,
482 archived: Schema.Boolean,
483 settled: Schema.Boolean,
484 settledAt: Schema.NullOr(IsoDateTime),
485 snoozed: Schema.Boolean,
486 snoozedUntil: Schema.NullOr(IsoDateTime),
487 /** Absent from linked environments that predate it. */
488 blockedOnThreadWait: Schema.optional(Schema.Boolean),
489 /** Absent from linked environments that predate it. */
490 pendingBackgroundTasks: Schema.optional(Schema.Array(OrchestratorMcpThreadBackgroundTask)),
491 createdAt: IsoDateTime,
492 updatedAt: IsoDateTime,
493});
494export type OrchestratorMcpThreadDetail = typeof OrchestratorMcpThreadDetail.Type;
495
496export const OrchestratorMcpThreadRun = Schema.Struct({
497 runId: RunId,
498 ordinal: PositiveInt,
499 status: OrchestrationV2RunStatus,
500 providerInstanceId: ProviderInstanceId,
501 model: Schema.String,
502 executedModel: Schema.optional(OrchestratorMcpExecutedModel),
503 requestedAt: IsoDateTime,
504 startedAt: Schema.NullOr(IsoDateTime),
505 completedAt: Schema.NullOr(IsoDateTime),
506});
507export type OrchestratorMcpThreadRun = typeof OrchestratorMcpThreadRun.Type;
508
509export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
510 position: NonNegativeInt,
511 visibility: Schema.Literals(["local", "inherited", "synthetic"]),
512 sourceThreadId: ThreadId,
513 itemId: TurnItemId,
514 subagentId: Schema.optional(NodeId),
515 runId: Schema.NullOr(RunId),
516 messageId: Schema.NullOr(MessageId),
517 createdBy: Schema.NullOr(OrchestrationV2Actor),
518 creationSource: Schema.NullOr(OrchestrationV2CreationSource),
519 senderThreadId: Schema.optional(ThreadId),
520 type: Schema.String,
521 status: OrchestrationV2TurnItemStatus,
522 title: Schema.NullOr(Schema.String),
523 text: Schema.NullOr(Schema.String),
524 textTruncated: Schema.Boolean,
525 nextTextOffset: Schema.optional(Schema.NullOr(NonNegativeInt)),
526 updatedAt: IsoDateTime,
527});
528export type OrchestratorMcpThreadTimelineItem = typeof OrchestratorMcpThreadTimelineItem.Type;
529
530export const OrchestratorMcpThreadReadResult = Schema.Struct({
531 thread: OrchestratorMcpThreadDetail,
532 recentRuns: Schema.Array(OrchestratorMcpThreadRun),
533 items: Schema.Array(OrchestratorMcpThreadTimelineItem),
534 nextPosition: Schema.NullOr(NonNegativeInt),
535 hasMore: Schema.Boolean,
536 /** null when nothing is older than the page. Missing from peers that only read forward. */
537 earlierPosition: Schema.optional(Schema.NullOr(NonNegativeInt)),
538});
539export type OrchestratorMcpThreadReadResult = typeof OrchestratorMcpThreadReadResult.Type;
540
541export const OrchestratorMcpThreadSendInput = Schema.Struct({
542 environmentId: OrchestratorMcpEnvironmentTarget,
543 threadId: ThreadId,
544 message: OrchestratorMcpPrompt,
545 mode: Schema.optional(Schema.Literals(["auto", "queue", "steer", "restart"])),
546 freshContext: Schema.optional(
547 Schema.Boolean.annotate({
548 description:
549 "Start a new provider session without the thread's earlier context, like /clear. Never steers.",
550 }),
551 ),
552 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
553});
554export type OrchestratorMcpThreadSendInput = typeof OrchestratorMcpThreadSendInput.Type;
555
556export const OrchestratorMcpThreadSendResult = Schema.Struct({
557 threadId: ThreadId,
558 link: Schema.optional(Schema.String),
559 messageId: MessageId,
560 runId: RunId,
561 taskId: Schema.optional(NodeId),
562 status: OrchestrationV2RunStatus,
563 delivery: Schema.Literals(["started", "queued", "steered", "restarted"]),
564});
565export type OrchestratorMcpThreadSendResult = typeof OrchestratorMcpThreadSendResult.Type;
566
567export const OrchestratorMcpThreadWaitInput = Schema.Struct({
568 environmentId: OrchestratorMcpEnvironmentTarget,
569 threadId: ThreadId,
570 runId: Schema.optional(RunId),
571 timeoutMs: Schema.optional(Schema.Finite),
572 untilDelegatedWorkSettled: Schema.optional(
573 Schema.Boolean.annotate({
574 description:
575 "Also wait for its delegated and background tasks and their completions to settle. `resultRun` then names the run with its final answer.",
576 }),
577 ),
578});
579export type OrchestratorMcpThreadWaitInput = typeof OrchestratorMcpThreadWaitInput.Type;
580
581export const OrchestratorMcpThreadWaitResult = Schema.Struct({
582 threadId: ThreadId,
583 runId: Schema.NullOr(RunId),
584 status: OrchestratorMcpThreadStatus,
585 timedOut: Schema.Boolean,
586 next: Schema.optional(OrchestratorMcpRunningTaskNext),
587 /** With untilDelegatedWorkSettled, once settled: the run whose reply is the thread's result. */
588 resultRun: Schema.optional(Schema.Struct({ runId: RunId, status: OrchestrationV2RunStatus })),
589});
590export type OrchestratorMcpThreadWaitResult = typeof OrchestratorMcpThreadWaitResult.Type;
591
592export const OrchestratorMcpThreadInterruptInput = Schema.Struct({
593 environmentId: OrchestratorMcpEnvironmentTarget,
594 threadId: ThreadId,
595 runId: Schema.optional(RunId),
596 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
597 /**
598 * Stop the thread as its Stop button does instead: interrupt its running
599 * turn whichever run that is, hold its queued messages, end its pull request
600 * watches and stop every task it delegated. `runId` is then not used.
601 */
602 stop: Schema.optional(Schema.Boolean),
603 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
604});
605export type OrchestratorMcpThreadInterruptInput = typeof OrchestratorMcpThreadInterruptInput.Type;
606
607export const OrchestratorMcpThreadInterruptResult = Schema.Struct({
608 threadId: ThreadId,
609 runId: Schema.NullOr(RunId),
610 status: Schema.Union([
611 Schema.Literal("interrupt_requested"),
612 Schema.Literal("no_active_run"),
613 Schema.Literals(["completed", "failed", "cancelled", "interrupted", "rolled_back"]),
614 ]),
615});
616export type OrchestratorMcpThreadInterruptResult = typeof OrchestratorMcpThreadInterruptResult.Type;
617
618export const OrchestratorMcpCapabilitiesInput = Schema.Struct({
619 environmentId: OrchestratorMcpEnvironmentTarget,
620 search: Schema.optional(
621 TrimmedNonEmptyString.check(Schema.isMaxLength(200)).annotate({
622 description: "Match model ids and labels. Replaces the short list.",
623 }),
624 ),
625});
626export type OrchestratorMcpCapabilitiesInput = typeof OrchestratorMcpCapabilitiesInput.Type;
627
628export const OrchestratorMcpModelOption = Schema.Struct({
629 id: Schema.String,
630 values: Schema.Array(ProviderOptionSelectionValue),
631 default: Schema.optional(ProviderOptionSelectionValue),
632});
633export type OrchestratorMcpModelOption = typeof OrchestratorMcpModelOption.Type;
634
635export const OrchestratorMcpProviderCapability = Schema.Struct({
636 providerInstanceId: ProviderInstanceId,
637 driverKind: ProviderDriverKind,
638 displayName: Schema.NullOr(Schema.String),
639 models: Schema.Array(
640 Schema.Struct({
641 id: Schema.String,
642 /** Omitted when it only restates the id. */
643 label: Schema.optional(Schema.String),
644 options: Schema.optional(Schema.Array(OrchestratorMcpModelOption)),
645 }),
646 ),
647 /** Models left out of `models`: unlisted visible models, or matches past the cap with `search`. */
648 omittedModels: Schema.optional(NonNegativeInt),
649 runtimeModes: Schema.optional(Schema.Array(RuntimeMode)),
650 canRunChildTask: Schema.Boolean,
651 canRunCrossProviderChildTask: Schema.Boolean,
652 constraints: Schema.Array(Schema.String),
653});
654export type OrchestratorMcpProviderCapability = typeof OrchestratorMcpProviderCapability.Type;
655
656export const OrchestratorMcpEnvironmentLink = Schema.Struct({
657 environmentId: EnvironmentId,
658 label: Schema.String,
659 /** Whether it answered just now. An expired link must be linked again there. */
660 status: Schema.Literals(["reachable", "unreachable", "expired"]),
661 /** The most the linked environment lets this one's agents do there. */
662 access: AuthMcpClientAccess,
663 expiresAt: IsoDateTime,
664 lastError: Schema.NullOr(Schema.String),
665});
666export type OrchestratorMcpEnvironmentLink = typeof OrchestratorMcpEnvironmentLink.Type;
667
668export const OrchestratorMcpEnvironmentLinksResult = Schema.Struct({
669 environmentId: EnvironmentId,
670 links: Schema.Array(OrchestratorMcpEnvironmentLink),
671 /** What to do when the machine the user means is not among `links`. */
672 notListed: Schema.String,
673});
674export type OrchestratorMcpEnvironmentLinksResult =
675 typeof OrchestratorMcpEnvironmentLinksResult.Type;
676
677export const OrchestratorMcpCapabilitiesResult = Schema.Struct({
678 parentThreadId: Schema.NullOr(ThreadId),
679 inheritedProviderInstanceId: Schema.NullOr(ProviderInstanceId),
680 inheritedModel: Schema.NullOr(Schema.String),
681 inheritedOptions: Schema.optional(Schema.Array(ProviderOptionSelection)),
682 runtimeMode: RuntimeMode,
683 interactionMode: ProviderInteractionMode,
684 providers: Schema.Array(OrchestratorMcpProviderCapability),
685 features: Schema.Struct({
686 appOwnedSubagents: Schema.Boolean,
687 asyncPolling: Schema.Boolean,
688 cancellation: Schema.Boolean,
689 batchThreadCreation: Schema.Boolean,
690 threadManagement: Schema.Boolean,
691 incrementalThreadRead: Schema.Boolean,
692 scheduledTasks: Schema.Boolean,
693 maxBatchThreads: Schema.Number,
694 }),
695});
696export type OrchestratorMcpCapabilitiesResult = typeof OrchestratorMcpCapabilitiesResult.Type;
697
698export const OrchestratorMcpScheduleTaskInput = Schema.Struct({
699 environmentId: OrchestratorMcpEnvironmentTarget,
700 projectId: OrchestratorMcpProjectTarget,
701 prompt: OrchestratorMcpPrompt,
702 schedule: OrchestratorMcpSchedule,
703 title: Schema.optional(OrchestratorMcpTitle),
704 enabled: Schema.optional(Schema.Boolean.annotate({ description: "Default true." })),
705 bindToCurrentThread: Schema.optional(
706 Schema.Boolean.annotate({
707 description:
708 "Post here, else new thread per run. Unset: true in own project, else false; updates keep it.",
709 }),
710 ),
711 freshSession: Schema.optional(
712 Schema.Boolean.annotate({
713 description:
714 "Runs share one thread but each starts a fresh session. Unbound: the first run makes the thread.",
715 }),
716 ),
717 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
718});
719export type OrchestratorMcpScheduleTaskInput = typeof OrchestratorMcpScheduleTaskInput.Type;
720
721/** `schedule_task` creates a task, or updates one when `scheduledTaskId` is given. */
722export const OrchestratorMcpSaveScheduledTaskInput = Schema.Struct({
723 ...OrchestratorMcpScheduleTaskInput.fields,
724 scheduledTaskId: Schema.optional(ScheduledTaskId),
725 prompt: Schema.optional(OrchestratorMcpPrompt),
726 schedule: Schema.optional(OrchestratorMcpSchedule),
727});
728export type OrchestratorMcpSaveScheduledTaskInput =
729 typeof OrchestratorMcpSaveScheduledTaskInput.Type;
730
731export const OrchestratorMcpScheduledTask = Schema.Struct({
732 scheduledTaskId: ScheduledTaskId,
733 title: Schema.String,
734 prompt: Schema.String,
735 enabled: Schema.Boolean,
736 projectId: ProjectId,
737 boundThreadId: Schema.NullOr(ThreadId),
738 freshSession: Schema.Boolean,
739 schedule: ScheduledTaskSchedule,
740 nextRunAt: Schema.NullOr(IsoDateTime),
741 lastRunStatus: ScheduledTaskRunStatus,
742 webhookUrl: Schema.optional(Schema.String).annotate({
743 description:
744 "Public URL for the sender. Absent: no T3 Connect tunnel. The user must enable T3 Connect remote access.",
745 }),
746 webhookSignature: Schema.optional(Schema.Literals(["none", "set"])),
747 blockedByPolicy: Schema.optional(Schema.String).annotate({
748 description: "Present when an administrator's policy stops this task from running.",
749 }),
750});
751export type OrchestratorMcpScheduledTask = typeof OrchestratorMcpScheduledTask.Type;
752
753export const OrchestratorMcpScheduleTaskResult = OrchestratorMcpScheduledTask;
754export type OrchestratorMcpScheduleTaskResult = typeof OrchestratorMcpScheduleTaskResult.Type;
755
756export const OrchestratorMcpListScheduledTasksInput = Schema.Struct({
757 environmentId: OrchestratorMcpEnvironmentTarget,
758 projectId: Schema.optional(
759 ProjectId.annotate({
760 description: "Default: your thread's project, or all outside a thread.",
761 }),
762 ),
763});
764export type OrchestratorMcpListScheduledTasksInput =
765 typeof OrchestratorMcpListScheduledTasksInput.Type;
766
767export const OrchestratorMcpListScheduledTasksResult = Schema.Struct({
768 tasks: Schema.Array(OrchestratorMcpScheduledTask),
769});
770export type OrchestratorMcpListScheduledTasksResult =
771 typeof OrchestratorMcpListScheduledTasksResult.Type;
772
773export const OrchestratorMcpUpdateScheduledTaskInput = Schema.Struct({
774 environmentId: OrchestratorMcpEnvironmentTarget,
775 scheduledTaskId: ScheduledTaskId,
776 prompt: Schema.optional(OrchestratorMcpPrompt),
777 title: Schema.optional(OrchestratorMcpTitle),
778 schedule: Schema.optional(OrchestratorMcpSchedule),
779 enabled: Schema.optional(Schema.Boolean),
780 bindToCurrentThread: Schema.optional(Schema.Boolean),
781 freshSession: Schema.optional(Schema.Boolean),
782});
783export type OrchestratorMcpUpdateScheduledTaskInput =
784 typeof OrchestratorMcpUpdateScheduledTaskInput.Type;
785
786// Not trimmed: whitespace in a password matters. The check stays out of the advertised schema.
787const PastedSecretValue = Schema.String.check(
788 Schema.makeFilter((value: string) => value.length > 0, { expected: "a non-empty string" }),
789);
790
791export const OrchestratorMcpRequestSecretInput = Schema.Struct({
792 label: TrimmedNonEmptyString.annotate({
793 description: "Card title, such as 'GitHub webhook secret'.",
794 }),
795 reason: TrimmedNonEmptyString.annotate({
796 description: "What it is for and where to get it. A link goes in `url`.",
797 }),
798 url: Schema.optional(
799 TrimmedNonEmptyString.check(
800 Schema.makeFilter((value) => secretRequestPageUrl(value) !== null, {
801 expected: "an http(s) URL",
802 }),
803 ),
804 ).annotate({
805 description: "Sign-in or setup page for the value. Shown as a button.",
806 }),
807 placeholder: Schema.optional(TrimmedNonEmptyString),
808 delivery: Schema.optional(Schema.Literals(["secretRef", "file"])).annotate({
809 description: "secretRef (default) for a T3 tool; file for a command.",
810 }),
811 value: Schema.optional(PastedSecretValue).annotate({
812 description: "Pasted in this thread; no card.",
813 }),
814 /** Default 10 minutes. */
815 timeoutMs: Schema.optional(
816 Schema.Int.check(Schema.isBetween({ minimum: 1_000, maximum: 60 * 60 * 1_000 })),
817 ),
818 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId).annotate({
819 description: "Retry key.",
820 }),
821});
822export type OrchestratorMcpRequestSecretInput = typeof OrchestratorMcpRequestSecretInput.Type;
823
824export const OrchestratorMcpRequestSecretResult = Schema.Union([
825 Schema.Struct({
826 status: Schema.Literal("saved"),
827 secretRef: SecretRef.annotate({
828 description: "One-use. Pass to a tool that accepts a secretRef. You never see the value.",
829 }),
830 }),
831 Schema.Struct({
832 status: Schema.Literal("saved").annotate({ description: "file holds the value." }),
833 file: Schema.String.annotate({
834 description:
835 "Owner-only file with the value. Read it inside commands and never print it. Deleted after 24 hours.",
836 }),
837 }),
838 Schema.Struct({
839 status: Schema.Literals(["declined", "cancelled", "timed_out"]).annotate({
840 description:
841 "declined: user chose not to; don't ask again. cancelled: ended with the run. timed_out: no answer in time. After cancelled or timed_out, ask again with a new `clientRequestId` only if still needed.",
842 }),
843 note: Schema.optional(Schema.String).annotate({ description: "What to do next." }),
844 }),
845]);
846export type OrchestratorMcpRequestSecretResult = typeof OrchestratorMcpRequestSecretResult.Type;
847
848export const OrchestratorMcpEnvironmentLinkInput = Schema.Struct({
849 environmentId: Schema.optional(EnvironmentId).annotate({
850 description:
851 "The machine, when known, e.g. from a mentioned machine. Otherwise the user picks it in the card.",
852 }),
853 url: Schema.optional(TrimmedNonEmptyString).annotate({
854 description:
855 "Only an address the user gave: https, Tailscale, LAN or loopback. Never guess one.",
856 }),
857 hint: Schema.optional(TrimmedNonEmptyString).annotate({
858 description: 'The user\'s words for the machine, e.g. "vps". Preselects it in the card.',
859 }),
860 reason: Schema.optional(TrimmedNonEmptyString).annotate({
861 description: "One sentence for the card.",
862 }),
863 requestedAccess: Schema.optional(AuthMcpClientAccess).annotate({
864 description: "Suggested access. The user picks; default approval-required.",
865 }),
866 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
867});
868export type OrchestratorMcpEnvironmentLinkInput = typeof OrchestratorMcpEnvironmentLinkInput.Type;
869
870export const OrchestratorMcpEnvironmentLinkResult = Schema.Union([
871 Schema.Struct({
872 status: Schema.Literal("pending").annotate({
873 description:
874 "The card is waiting for the user. Their answer arrives as a message in this thread.",
875 }),
876 turnItemId: TurnItemId,
877 }),
878 Schema.Struct({
879 status: Schema.Literal("linked"),
880 environmentId: EnvironmentId.annotate({
881 description: "Pass it as environmentId to act there; t3_environment_links lists it.",
882 }),
883 label: Schema.String,
884 access: AuthMcpClientAccess.annotate({ description: "The access the user chose." }),
885 }),
886 Schema.Struct({
887 status: Schema.Literals(["declined", "cancelled"]).annotate({
888 description:
889 "declined: the user chose not to. cancelled: the card closed unanswered, when the thread was stopped or archived.",
890 }),
891 }),
892 Schema.Struct({
893 status: Schema.Literal("failed"),
894 message: Schema.String.annotate({
895 description: "Why the other environment refused the link, as the user saw it.",
896 }),
897 }),
898]);
899export type OrchestratorMcpEnvironmentLinkResult = typeof OrchestratorMcpEnvironmentLinkResult.Type;
900
901export const OrchestratorMcpEnvironmentUnlinkInput = Schema.Struct({
902 environmentId: EnvironmentId.annotate({
903 description: "The linked environment to forget, from t3_environment_links.",
904 }),
905});
906export type OrchestratorMcpEnvironmentUnlinkInput =
907 typeof OrchestratorMcpEnvironmentUnlinkInput.Type;
908
909export const OrchestratorMcpEnvironmentUnlinkResult = Schema.Struct({
910 environmentId: EnvironmentId,
911 removed: Schema.Boolean,
912});
913export type OrchestratorMcpEnvironmentUnlinkResult =
914 typeof OrchestratorMcpEnvironmentUnlinkResult.Type;
915
916export const OrchestratorMcpDeleteScheduledTaskInput = Schema.Struct({
917 environmentId: OrchestratorMcpEnvironmentTarget,
918 scheduledTaskId: ScheduledTaskId,
919});
920export type OrchestratorMcpDeleteScheduledTaskInput =
921 typeof OrchestratorMcpDeleteScheduledTaskInput.Type;
922
923export const OrchestratorMcpDeleteScheduledTaskResult = Schema.Struct({
924 scheduledTaskId: ScheduledTaskId,
925 deleted: Schema.Boolean,
926});
927export type OrchestratorMcpDeleteScheduledTaskResult =
928 typeof OrchestratorMcpDeleteScheduledTaskResult.Type;
929
930export class OrchestratorMcpFailure extends Schema.TaggedError<OrchestratorMcpFailure>()(
931 "OrchestratorMcpFailure",
932 {
933 code: Schema.Literals([
934 "capability_denied",
935 "parent_not_active",
936 "provider_unavailable",
937 "model_unavailable",
938 "runtime_mode_escalation_denied",
939 "interaction_mode_escalation_denied",
940 "task_not_found",
941 "task_not_cancellable",
942 "thread_not_found",
943 "run_not_found",
944 "thread_not_sendable",
945 "thread_not_interruptible",
946 "invalid_request",
947 "orchestration_error",
948 "thread_credential_required",
949 "target_required",
950 ]),
951 message: Schema.String,
952 },
953) {}