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

orchestratorMcp.ts

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