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

orchestratorMcp.ts

929 lines36.1 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 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 4 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 watching: Schema.Boolean,
361 watchStartedAt: Schema.NullOr(IsoDateTime),
362});
363export type OrchestratorMcpThreadPullRequest = typeof OrchestratorMcpThreadPullRequest.Type;
364​
365export const OrchestratorMcpThreadListItem = Schema.Struct({
366 threadId: ThreadId,
367 projectId: ProjectId,
368 title: Schema.String,
369 link: Schema.optional(Schema.String),
370 createdBy: OrchestrationV2Actor,
371 creationSource: OrchestrationV2CreationSource,
372 status: OrchestratorMcpThreadStatus,
373 latestRunId: Schema.NullOr(RunId),
374 providerInstanceId: ProviderInstanceId,
375 model: Schema.String,
376 runtimeMode: RuntimeMode,
377 interactionMode: ProviderInteractionMode,
378 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
379 /** Linked pull requests not yet merged or closed; list_thread_pull_requests has all of them. */
380 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
381 pullRequestCount: Schema.optional(NonNegativeInt),
382 settled: Schema.Boolean,
383 settledAt: Schema.NullOr(IsoDateTime),
384 snoozed: Schema.Boolean,
385 snoozedUntil: Schema.NullOr(IsoDateTime),
386 parentThreadId: Schema.NullOr(ThreadId),
387 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
388 itemCount: NonNegativeInt,
389 createdAt: IsoDateTime,
390 updatedAt: IsoDateTime,
391});
392export type OrchestratorMcpThreadListItem = typeof OrchestratorMcpThreadListItem.Type;
393​
394export const OrchestratorMcpThreadListResult = Schema.Struct({
395 /** null with `allProjects`. */
396 projectId: Schema.NullOr(ProjectId),
397 currentThreadId: Schema.NullOr(ThreadId),
398 threads: Schema.Array(OrchestratorMcpThreadListItem),
399 nextCursor: Schema.NullOr(NonNegativeInt),
400 total: NonNegativeInt,
401});
402export type OrchestratorMcpThreadListResult = typeof OrchestratorMcpThreadListResult.Type;
403​
404// Codex hides `minimum` and `maximum` from the model, so a value above the maximum clamps on
405// decode instead of failing the call; pagination returns the rest. Values below 1 still fail:
406// 0 asks for nothing, and answering it with one item would be a different request.
407const clampedPositiveInt = (maximum: number) =>
408 PositiveInt.pipe(
409 Schema.decodeTo(
410 PositiveInt.check(Schema.isLessThanOrEqualTo(maximum)),
411 SchemaTransformation.transform({
412 decode: (value) => Math.min(value, maximum),
413 encode: (value) => value,
414 }),
415 ),
416 );
417​
418export const OrchestratorMcpThreadReadInput = Schema.Struct({
419 environmentId: OrchestratorMcpEnvironmentTarget,
420 threadId: ThreadId,
421 itemId: Schema.optional(TurnItemId),
422 textOffset: Schema.optional(NonNegativeInt),
423 view: Schema.optional(Schema.Literals(["messages", "activity"])),
424 afterPosition: Schema.optional(NonNegativeInt),
425 limit: Schema.optional(clampedPositiveInt(100)).annotate({
426 description: "Max items, 1 to 100.",
427 }),
428 runLimit: Schema.optional(clampedPositiveInt(50)).annotate({
429 description: "Max recent runs, 1 to 50.",
430 }),
431 maxCharsPerItem: Schema.optional(clampedPositiveInt(50_000)).annotate({
432 description: "Max chars per item, 1 to 50000.",
433 }),
434});
435export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type;
436​
437export const OrchestratorMcpThreadDetail = Schema.Struct({
438 threadId: ThreadId,
439 projectId: ProjectId,
440 title: Schema.String,
441 link: Schema.optional(Schema.String),
442 createdBy: OrchestrationV2Actor,
443 creationSource: OrchestrationV2CreationSource,
444 status: OrchestratorMcpThreadStatus,
445 latestRunId: Schema.NullOr(RunId),
446 activeRunId: Schema.NullOr(RunId),
447 providerInstanceId: ProviderInstanceId,
448 model: Schema.String,
449 runtimeMode: RuntimeMode,
450 interactionMode: ProviderInteractionMode,
451 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
452 /** Open linked pull requests, on the first page only; list_thread_pull_requests has all of them. */
453 pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
454 pullRequestCount: Schema.optional(NonNegativeInt),
455 titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
456 lastTitleRegeneration: Schema.optional(Schema.NullOr(LastThreadTitleRegeneration)),
457 branch: Schema.NullOr(Schema.String),
458 worktreePath: Schema.NullOr(Schema.String),
459 parentThreadId: Schema.NullOr(ThreadId),
460 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
461 runCount: NonNegativeInt,
462 itemCount: NonNegativeInt,
463 pendingRequestCount: NonNegativeInt,
464 archived: Schema.Boolean,
465 settled: Schema.Boolean,
466 settledAt: Schema.NullOr(IsoDateTime),
467 snoozed: Schema.Boolean,
468 snoozedUntil: Schema.NullOr(IsoDateTime),
469 createdAt: IsoDateTime,
470 updatedAt: IsoDateTime,
471});
472export type OrchestratorMcpThreadDetail = typeof OrchestratorMcpThreadDetail.Type;
473​
474export const OrchestratorMcpThreadRun = Schema.Struct({
475 runId: RunId,
476 ordinal: PositiveInt,
477 status: OrchestrationV2RunStatus,
478 providerInstanceId: ProviderInstanceId,
479 model: Schema.String,
480 executedModel: Schema.optional(OrchestratorMcpExecutedModel),
481 requestedAt: IsoDateTime,
482 startedAt: Schema.NullOr(IsoDateTime),
483 completedAt: Schema.NullOr(IsoDateTime),
484});
485export type OrchestratorMcpThreadRun = typeof OrchestratorMcpThreadRun.Type;
486​
487export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
488 position: NonNegativeInt,
489 visibility: Schema.Literals(["local", "inherited", "synthetic"]),
490 sourceThreadId: ThreadId,
491 itemId: TurnItemId,
492 subagentId: Schema.optional(NodeId),
493 runId: Schema.NullOr(RunId),
494 messageId: Schema.NullOr(MessageId),
495 createdBy: Schema.NullOr(OrchestrationV2Actor),
496 creationSource: Schema.NullOr(OrchestrationV2CreationSource),
497 senderThreadId: Schema.optional(ThreadId),
498 type: Schema.String,
499 status: OrchestrationV2TurnItemStatus,
500 title: Schema.NullOr(Schema.String),
501 text: Schema.NullOr(Schema.String),
502 textTruncated: Schema.Boolean,
503 nextTextOffset: Schema.optional(Schema.NullOr(NonNegativeInt)),
504 updatedAt: IsoDateTime,
505});
506export type OrchestratorMcpThreadTimelineItem = typeof OrchestratorMcpThreadTimelineItem.Type;
507​
508export const OrchestratorMcpThreadReadResult = Schema.Struct({
509 thread: OrchestratorMcpThreadDetail,
510 recentRuns: Schema.Array(OrchestratorMcpThreadRun),
511 items: Schema.Array(OrchestratorMcpThreadTimelineItem),
512 nextPosition: Schema.NullOr(NonNegativeInt),
513 hasMore: Schema.Boolean,
514});
515export type OrchestratorMcpThreadReadResult = typeof OrchestratorMcpThreadReadResult.Type;
516​
517export const OrchestratorMcpThreadSendInput = Schema.Struct({
518 environmentId: OrchestratorMcpEnvironmentTarget,
519 threadId: ThreadId,
520 message: OrchestratorMcpPrompt,
521 mode: Schema.optional(Schema.Literals(["auto", "queue", "steer", "restart"])),
522 freshContext: Schema.optional(
523 Schema.Boolean.annotate({
524 description:
525 "Start a new provider session without the thread's earlier context, like /clear. Never steers.",
526 }),
527 ),
528 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
529});
530export type OrchestratorMcpThreadSendInput = typeof OrchestratorMcpThreadSendInput.Type;
531​
532export const OrchestratorMcpThreadSendResult = Schema.Struct({
533 threadId: ThreadId,
534 link: Schema.optional(Schema.String),
535 messageId: MessageId,
536 runId: RunId,
537 taskId: Schema.optional(NodeId),
538 status: OrchestrationV2RunStatus,
539 delivery: Schema.Literals(["started", "queued", "steered", "restarted"]),
540});
541export type OrchestratorMcpThreadSendResult = typeof OrchestratorMcpThreadSendResult.Type;
542​
543export const OrchestratorMcpThreadWaitInput = Schema.Struct({
544 environmentId: OrchestratorMcpEnvironmentTarget,
545 threadId: ThreadId,
546 runId: Schema.optional(RunId),
547 timeoutMs: Schema.optional(Schema.Finite),
548 untilDelegatedWorkSettled: Schema.optional(
549 Schema.Boolean.annotate({
550 description:
551 "Also wait for its delegated and background tasks and their completions to settle. `resultRun` then names the run with its final answer.",
552 }),
553 ),
554});
555export type OrchestratorMcpThreadWaitInput = typeof OrchestratorMcpThreadWaitInput.Type;
556​
557export const OrchestratorMcpThreadWaitResult = Schema.Struct({
558 threadId: ThreadId,
559 runId: Schema.NullOr(RunId),
560 status: OrchestratorMcpThreadStatus,
561 timedOut: Schema.Boolean,
562 next: Schema.optional(OrchestratorMcpRunningTaskNext),
563 /** With untilDelegatedWorkSettled, once settled: the run whose reply is the thread's result. */
564 resultRun: Schema.optional(Schema.Struct({ runId: RunId, status: OrchestrationV2RunStatus })),
565});
566export type OrchestratorMcpThreadWaitResult = typeof OrchestratorMcpThreadWaitResult.Type;
567​
568export const OrchestratorMcpThreadInterruptInput = Schema.Struct({
569 environmentId: OrchestratorMcpEnvironmentTarget,
570 threadId: ThreadId,
571 runId: Schema.optional(RunId),
572 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
573 /**
574 * Stop the thread as its Stop button does instead: interrupt its running
575 * turn whichever run that is, hold its queued messages, end its pull request
576 * watches and stop every task it delegated. `runId` is then not used.
577 */
578 stop: Schema.optional(Schema.Boolean),
579 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
580});
581export type OrchestratorMcpThreadInterruptInput = typeof OrchestratorMcpThreadInterruptInput.Type;
582​
583export const OrchestratorMcpThreadInterruptResult = Schema.Struct({
584 threadId: ThreadId,
585 runId: Schema.NullOr(RunId),
586 status: Schema.Union([
587 Schema.Literal("interrupt_requested"),
588 Schema.Literal("no_active_run"),
589 Schema.Literals(["completed", "failed", "cancelled", "interrupted", "rolled_back"]),
590 ]),
591});
592export type OrchestratorMcpThreadInterruptResult = typeof OrchestratorMcpThreadInterruptResult.Type;
593​
594export const OrchestratorMcpCapabilitiesInput = Schema.Struct({
595 environmentId: OrchestratorMcpEnvironmentTarget,
596 search: Schema.optional(
597 TrimmedNonEmptyString.check(Schema.isMaxLength(200)).annotate({
598 description: "Match model ids and labels. Replaces the short list.",
599 }),
600 ),
601});
602export type OrchestratorMcpCapabilitiesInput = typeof OrchestratorMcpCapabilitiesInput.Type;
603​
604export const OrchestratorMcpModelOption = Schema.Struct({
605 id: Schema.String,
606 values: Schema.Array(ProviderOptionSelectionValue),
607 default: Schema.optional(ProviderOptionSelectionValue),
608});
609export type OrchestratorMcpModelOption = typeof OrchestratorMcpModelOption.Type;
610​
611export const OrchestratorMcpProviderCapability = Schema.Struct({
612 providerInstanceId: ProviderInstanceId,
613 driverKind: ProviderDriverKind,
614 displayName: Schema.NullOr(Schema.String),
615 models: Schema.Array(
616 Schema.Struct({
617 id: Schema.String,
618 /** Omitted when it only restates the id. */
619 label: Schema.optional(Schema.String),
620 options: Schema.optional(Schema.Array(OrchestratorMcpModelOption)),
621 }),
622 ),
623 /** Models left out of `models`: unlisted visible models, or matches past the cap with `search`. */
624 omittedModels: Schema.optional(NonNegativeInt),
625 runtimeModes: Schema.optional(Schema.Array(RuntimeMode)),
626 canRunChildTask: Schema.Boolean,
627 canRunCrossProviderChildTask: Schema.Boolean,
628 constraints: Schema.Array(Schema.String),
629});
630export type OrchestratorMcpProviderCapability = typeof OrchestratorMcpProviderCapability.Type;
631​
632export const OrchestratorMcpEnvironmentLink = Schema.Struct({
633 environmentId: EnvironmentId,
634 label: Schema.String,
635 /** Whether it answered just now. An expired link must be linked again there. */
636 status: Schema.Literals(["reachable", "unreachable", "expired"]),
637 /** The most the linked environment lets this one's agents do there. */
638 access: AuthMcpClientAccess,
639 expiresAt: IsoDateTime,
640 lastError: Schema.NullOr(Schema.String),
641});
642export type OrchestratorMcpEnvironmentLink = typeof OrchestratorMcpEnvironmentLink.Type;
643​
644export const OrchestratorMcpEnvironmentLinksResult = Schema.Struct({
645 environmentId: EnvironmentId,
646 links: Schema.Array(OrchestratorMcpEnvironmentLink),
647 /** What to do when the machine the user means is not among `links`. */
648 notListed: Schema.String,
649});
650export type OrchestratorMcpEnvironmentLinksResult =
651 typeof OrchestratorMcpEnvironmentLinksResult.Type;
652​
653export const OrchestratorMcpCapabilitiesResult = Schema.Struct({
654 parentThreadId: Schema.NullOr(ThreadId),
655 inheritedProviderInstanceId: Schema.NullOr(ProviderInstanceId),
656 inheritedModel: Schema.NullOr(Schema.String),
657 inheritedOptions: Schema.optional(Schema.Array(ProviderOptionSelection)),
658 runtimeMode: RuntimeMode,
659 interactionMode: ProviderInteractionMode,
660 providers: Schema.Array(OrchestratorMcpProviderCapability),
661 features: Schema.Struct({
662 appOwnedSubagents: Schema.Boolean,
663 asyncPolling: Schema.Boolean,
664 cancellation: Schema.Boolean,
665 batchThreadCreation: Schema.Boolean,
666 threadManagement: Schema.Boolean,
667 incrementalThreadRead: Schema.Boolean,
668 scheduledTasks: Schema.Boolean,
669 maxBatchThreads: Schema.Number,
670 }),
671});
672export type OrchestratorMcpCapabilitiesResult = typeof OrchestratorMcpCapabilitiesResult.Type;
673​
674export const OrchestratorMcpScheduleTaskInput = Schema.Struct({
675 environmentId: OrchestratorMcpEnvironmentTarget,
676 projectId: OrchestratorMcpProjectTarget,
677 prompt: OrchestratorMcpPrompt,
678 schedule: OrchestratorMcpSchedule,
679 title: Schema.optional(OrchestratorMcpTitle),
680 enabled: Schema.optional(Schema.Boolean.annotate({ description: "Default true." })),
681 bindToCurrentThread: Schema.optional(
682 Schema.Boolean.annotate({
683 description:
684 "Post here, else new thread per run. Unset: true in own project, else false; updates keep it.",
685 }),
686 ),
687 freshSession: Schema.optional(
688 Schema.Boolean.annotate({
689 description:
690 "Runs share one thread but each starts a fresh session. Unbound: the first run makes the thread.",
691 }),
692 ),
693 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
694});
695export type OrchestratorMcpScheduleTaskInput = typeof OrchestratorMcpScheduleTaskInput.Type;
696​
697/** `schedule_task` creates a task, or updates one when `scheduledTaskId` is given. */
698export const OrchestratorMcpSaveScheduledTaskInput = Schema.Struct({
699 ...OrchestratorMcpScheduleTaskInput.fields,
700 scheduledTaskId: Schema.optional(ScheduledTaskId),
701 prompt: Schema.optional(OrchestratorMcpPrompt),
702 schedule: Schema.optional(OrchestratorMcpSchedule),
703});
704export type OrchestratorMcpSaveScheduledTaskInput =
705 typeof OrchestratorMcpSaveScheduledTaskInput.Type;
706​
707export const OrchestratorMcpScheduledTask = Schema.Struct({
708 scheduledTaskId: ScheduledTaskId,
709 title: Schema.String,
710 prompt: Schema.String,
711 enabled: Schema.Boolean,
712 projectId: ProjectId,
713 boundThreadId: Schema.NullOr(ThreadId),
714 freshSession: Schema.Boolean,
715 schedule: ScheduledTaskSchedule,
716 nextRunAt: Schema.NullOr(IsoDateTime),
717 lastRunStatus: ScheduledTaskRunStatus,
718 webhookUrl: Schema.optional(Schema.String).annotate({
719 description:
720 "Public URL for the sender. Absent: no T3 Connect tunnel. The user must enable T3 Connect remote access.",
721 }),
722 webhookSignature: Schema.optional(Schema.Literals(["none", "set"])),
723 blockedByPolicy: Schema.optional(Schema.String).annotate({
724 description: "Present when an administrator's policy stops this task from running.",
725 }),
726});
727export type OrchestratorMcpScheduledTask = typeof OrchestratorMcpScheduledTask.Type;
728​
729export const OrchestratorMcpScheduleTaskResult = OrchestratorMcpScheduledTask;
730export type OrchestratorMcpScheduleTaskResult = typeof OrchestratorMcpScheduleTaskResult.Type;
731​
732export const OrchestratorMcpListScheduledTasksInput = Schema.Struct({
733 environmentId: OrchestratorMcpEnvironmentTarget,
734 projectId: Schema.optional(
735 ProjectId.annotate({
736 description: "Default: your thread's project, or all outside a thread.",
737 }),
738 ),
739});
740export type OrchestratorMcpListScheduledTasksInput =
741 typeof OrchestratorMcpListScheduledTasksInput.Type;
742​
743export const OrchestratorMcpListScheduledTasksResult = Schema.Struct({
744 tasks: Schema.Array(OrchestratorMcpScheduledTask),
745});
746export type OrchestratorMcpListScheduledTasksResult =
747 typeof OrchestratorMcpListScheduledTasksResult.Type;
748​
749export const OrchestratorMcpUpdateScheduledTaskInput = Schema.Struct({
750 environmentId: OrchestratorMcpEnvironmentTarget,
751 scheduledTaskId: ScheduledTaskId,
752 prompt: Schema.optional(OrchestratorMcpPrompt),
753 title: Schema.optional(OrchestratorMcpTitle),
754 schedule: Schema.optional(OrchestratorMcpSchedule),
755 enabled: Schema.optional(Schema.Boolean),
756 bindToCurrentThread: Schema.optional(Schema.Boolean),
757 freshSession: Schema.optional(Schema.Boolean),
758});
759export type OrchestratorMcpUpdateScheduledTaskInput =
760 typeof OrchestratorMcpUpdateScheduledTaskInput.Type;
761​
762// Not trimmed: whitespace in a password matters. The check stays out of the advertised schema.
763const PastedSecretValue = Schema.String.check(
764 Schema.makeFilter((value: string) => value.length > 0, { expected: "a non-empty string" }),
765);
766​
767export const OrchestratorMcpRequestSecretInput = Schema.Struct({
768 label: TrimmedNonEmptyString.annotate({
769 description: "Card title, such as 'GitHub webhook secret'.",
770 }),
771 reason: TrimmedNonEmptyString.annotate({
772 description: "What it is for and where to get it. A link goes in `url`.",
773 }),
774 url: Schema.optional(
775 TrimmedNonEmptyString.check(
776 Schema.makeFilter((value) => secretRequestPageUrl(value) !== null, {
777 expected: "an http(s) URL",
778 }),
779 ),
780 ).annotate({
781 description: "Sign-in or setup page for the value. Shown as a button.",
782 }),
783 placeholder: Schema.optional(TrimmedNonEmptyString),
784 delivery: Schema.optional(Schema.Literals(["secretRef", "file"])).annotate({
785 description: "secretRef (default) for a T3 tool; file for a command.",
786 }),
787 value: Schema.optional(PastedSecretValue).annotate({
788 description: "Pasted in this thread; no card.",
789 }),
790 /** Default 10 minutes. */
791 timeoutMs: Schema.optional(
792 Schema.Int.check(Schema.isBetween({ minimum: 1_000, maximum: 60 * 60 * 1_000 })),
793 ),
794 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId).annotate({
795 description: "Retry key.",
796 }),
797});
798export type OrchestratorMcpRequestSecretInput = typeof OrchestratorMcpRequestSecretInput.Type;
799​
800export const OrchestratorMcpRequestSecretResult = Schema.Union([
801 Schema.Struct({
802 status: Schema.Literal("saved"),
803 secretRef: SecretRef.annotate({
804 description: "One-use. Pass to a tool that accepts a secretRef. You never see the value.",
805 }),
806 }),
807 Schema.Struct({
808 status: Schema.Literal("saved").annotate({ description: "file holds the value." }),
809 file: Schema.String.annotate({
810 description:
811 "Owner-only file with the value. Read it inside commands and never print it. Deleted after 24 hours.",
812 }),
813 }),
814 Schema.Struct({
815 status: Schema.Literals(["declined", "cancelled", "timed_out"]).annotate({
816 description:
817 "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.",
818 }),
819 note: Schema.optional(Schema.String).annotate({ description: "What to do next." }),
820 }),
821]);
822export type OrchestratorMcpRequestSecretResult = typeof OrchestratorMcpRequestSecretResult.Type;
823​
824export const OrchestratorMcpEnvironmentLinkInput = Schema.Struct({
825 environmentId: Schema.optional(EnvironmentId).annotate({
826 description:
827 "The machine, when known, e.g. from a mentioned machine. Otherwise the user picks it in the card.",
828 }),
829 url: Schema.optional(TrimmedNonEmptyString).annotate({
830 description:
831 "Only an address the user gave: https, Tailscale, LAN or loopback. Never guess one.",
832 }),
833 hint: Schema.optional(TrimmedNonEmptyString).annotate({
834 description: 'The user\'s words for the machine, e.g. "vps". Preselects it in the card.',
835 }),
836 reason: Schema.optional(TrimmedNonEmptyString).annotate({
837 description: "One sentence for the card.",
838 }),
839 requestedAccess: Schema.optional(AuthMcpClientAccess).annotate({
840 description: "Suggested access. The user picks; default approval-required.",
841 }),
842 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
843});
844export type OrchestratorMcpEnvironmentLinkInput = typeof OrchestratorMcpEnvironmentLinkInput.Type;
845​
846export const OrchestratorMcpEnvironmentLinkResult = Schema.Union([
847 Schema.Struct({
848 status: Schema.Literal("pending").annotate({
849 description:
850 "The card is waiting for the user. Their answer arrives as a message in this thread.",
851 }),
852 turnItemId: TurnItemId,
853 }),
854 Schema.Struct({
855 status: Schema.Literal("linked"),
856 environmentId: EnvironmentId.annotate({
857 description: "Pass it as environmentId to act there; t3_environment_links lists it.",
858 }),
859 label: Schema.String,
860 access: AuthMcpClientAccess.annotate({ description: "The access the user chose." }),
861 }),
862 Schema.Struct({
863 status: Schema.Literals(["declined", "cancelled"]).annotate({
864 description:
865 "declined: the user chose not to. cancelled: the card closed unanswered, when the thread was stopped or archived.",
866 }),
867 }),
868 Schema.Struct({
869 status: Schema.Literal("failed"),
870 message: Schema.String.annotate({
871 description: "Why the other environment refused the link, as the user saw it.",
872 }),
873 }),
874]);
875export type OrchestratorMcpEnvironmentLinkResult = typeof OrchestratorMcpEnvironmentLinkResult.Type;
876​
877export const OrchestratorMcpEnvironmentUnlinkInput = Schema.Struct({
878 environmentId: EnvironmentId.annotate({
879 description: "The linked environment to forget, from t3_environment_links.",
880 }),
881});
882export type OrchestratorMcpEnvironmentUnlinkInput =
883 typeof OrchestratorMcpEnvironmentUnlinkInput.Type;
884​
885export const OrchestratorMcpEnvironmentUnlinkResult = Schema.Struct({
886 environmentId: EnvironmentId,
887 removed: Schema.Boolean,
888});
889export type OrchestratorMcpEnvironmentUnlinkResult =
890 typeof OrchestratorMcpEnvironmentUnlinkResult.Type;
891​
892export const OrchestratorMcpDeleteScheduledTaskInput = Schema.Struct({
893 environmentId: OrchestratorMcpEnvironmentTarget,
894 scheduledTaskId: ScheduledTaskId,
895});
896export type OrchestratorMcpDeleteScheduledTaskInput =
897 typeof OrchestratorMcpDeleteScheduledTaskInput.Type;
898​
899export const OrchestratorMcpDeleteScheduledTaskResult = Schema.Struct({
900 scheduledTaskId: ScheduledTaskId,
901 deleted: Schema.Boolean,
902});
903export type OrchestratorMcpDeleteScheduledTaskResult =
904 typeof OrchestratorMcpDeleteScheduledTaskResult.Type;
905​
906export class OrchestratorMcpFailure extends Schema.TaggedError<OrchestratorMcpFailure>()(
907 "OrchestratorMcpFailure",
908 {
909 code: Schema.Literals([
910 "capability_denied",
911 "parent_not_active",
912 "provider_unavailable",
913 "model_unavailable",
914 "runtime_mode_escalation_denied",
915 "interaction_mode_escalation_denied",
916 "task_not_found",
917 "task_not_cancellable",
918 "thread_not_found",
919 "run_not_found",
920 "thread_not_sendable",
921 "thread_not_interruptible",
922 "invalid_request",
923 "orchestration_error",
924 "thread_credential_required",
925 "target_required",
926 ]),
927 message: Schema.String,
928 },
929) {}