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

orchestratorMcp.ts

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