Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

orchestratorMcp.ts

966 lines38.5 KB

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