Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import * as SchemaTransformation from "effect/SchemaTransformation";
4
5import {
6 ContextTransferId,
7 IsoDateTime,
8 MessageId,
9 NodeId,
10 NonNegativeInt,
11 PositiveInt,
12 ProjectId,
13 RunId,
14 ScheduledTaskId,
15 SecretRef,
16 ThreadId,
17 TrimmedNonEmptyString,
18 TurnItemId,
19} from "./baseSchemas.ts";
20import {
21 ScheduledTaskRunStatus,
22 ScheduledTaskSchedule,
23 ScheduledTaskUpsertSchedule,
24} from "./scheduledTask.ts";
25import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts";
26import { ThreadLinkedPullRequest } from "./threadPullRequest.ts";
27import { ThreadTitleRegeneration } from "./threadTitle.ts";
28import {
29 OrchestrationV2Actor,
30 OrchestrationV2CreationSource,
31 OrchestrationV2RunStatus,
32 OrchestrationV2TurnItemStatus,
33} from "./orchestrationV2.ts";
34import {
35 ProviderOptionDescriptor,
36 ProviderOptionSelection,
37 ProviderOptionSelectionValue,
38} from "./model.ts";
39import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
40
41const OrchestratorMcpPrompt = TrimmedNonEmptyString.check(Schema.isMaxLength(120_000)).annotate({
42 description: "Complete task or message text for the target agent.",
43});
44const OrchestratorMcpTitle = TrimmedNonEmptyString.check(Schema.isMaxLength(512)).annotate({
45 description: "Optional concise display title.",
46});
47const OrchestratorMcpClientRequestId = TrimmedNonEmptyString.check(
48 Schema.isMaxLength(256),
49).annotate({ description: "Stable idempotency key to reuse when retrying this mutation." });
50
51/**
52 * OpenCode 1.15 has been observed serializing nested MCP union objects as JSON
53 * strings. Keep the structured object as the documented form while accepting
54 * that compatibility shape at the tool boundary and decoding it immediately.
55 */
56const OrchestratorMcpScheduleFromJsonString = Schema.fromJsonString(
57 ScheduledTaskUpsertSchedule,
58).annotate({
59 description:
60 "Compatibility-only JSON encoding of the schedule object. Prefer a structured object.",
61});
62
63const OrchestratorMcpSchedule = Schema.Union([
64 ScheduledTaskUpsertSchedule,
65 OrchestratorMcpScheduleFromJsonString,
66]).annotate({
67 description:
68 "Trigger object: {type:'interval', everyMs}, {type:'fixed_time', timeOfDay, weekdays?}, or {type:'webhook'} to run on each request to a generated URL. Never stringify it unless the provider requires the compatibility form.",
69});
70
71/**
72 * Shorthand `{ id: value }` record form for target model options. Unlike the
73 * legacy-tolerant `ProviderOptionSelections` persistence schema, this decodes
74 * strictly: a value that is not a string or boolean fails the request rather
75 * than being silently dropped.
76 */
77const OrchestratorMcpTargetOptionsFromRecord = Schema.Record(
78 Schema.String,
79 ProviderOptionSelectionValue,
80).pipe(
81 Schema.decodeTo(
82 Schema.Array(ProviderOptionSelection),
83 SchemaTransformation.transformEffect({
84 decode: (record) =>
85 Effect.succeed(Object.entries(record).map(([id, value]) => ({ id, value }))),
86 encode: (selections: ReadonlyArray<ProviderOptionSelection>) =>
87 Effect.succeed(
88 Object.fromEntries(selections.map((selection) => [selection.id, selection.value])),
89 ),
90 }),
91 ),
92);
93
94export const OrchestratorMcpTargetOptions = Schema.Union([
95 Schema.Array(ProviderOptionSelection),
96 OrchestratorMcpTargetOptionsFromRecord,
97]);
98export type OrchestratorMcpTargetOptions = typeof OrchestratorMcpTargetOptions.Type;
99
100export const OrchestratorMcpTarget = Schema.Struct({
101 providerInstanceId: Schema.optional(
102 ProviderInstanceId.annotate({
103 description: "Configured provider instance id from orchestrator_capabilities.",
104 }),
105 ),
106 driverKind: Schema.optional(
107 ProviderDriverKind.annotate({
108 description: "Provider driver kind; prefer providerInstanceId when available.",
109 }),
110 ),
111 model: Schema.optional(
112 TrimmedNonEmptyString.annotate({
113 description: "Model id advertised for the selected provider instance.",
114 }),
115 ),
116 /**
117 * Model option selections for the child (for example reasoning effort).
118 * Accepts the canonical `[{ id, value }]` array or the shorthand
119 * `{ id: value }` record; valid ids come from the option descriptors
120 * advertised by orchestrator_capabilities. When omitted, options inherit
121 * from the parent only when the child runs the parent's provider and model.
122 */
123 options: Schema.optional(
124 OrchestratorMcpTargetOptions.annotate({
125 description: "Model option selections advertised by orchestrator_capabilities.",
126 }),
127 ),
128});
129export type OrchestratorMcpTarget = typeof OrchestratorMcpTarget.Type;
130
131export const OrchestratorMcpRuntimeMode = Schema.Union([Schema.Literal("inherit"), RuntimeMode]);
132export type OrchestratorMcpRuntimeMode = typeof OrchestratorMcpRuntimeMode.Type;
133
134export const OrchestratorMcpInteractionMode = Schema.Union([
135 Schema.Literal("inherit"),
136 ProviderInteractionMode,
137]);
138export type OrchestratorMcpInteractionMode = typeof OrchestratorMcpInteractionMode.Type;
139
140export const OrchestratorMcpTaskRole = Schema.Literals([
141 "implementation",
142 "research",
143 "review",
144 "design",
145 "test",
146 "general",
147]);
148export type OrchestratorMcpTaskRole = typeof OrchestratorMcpTaskRole.Type;
149
150export const OrchestratorMcpDelegatedTaskStatus = Schema.Literals([
151 "queued",
152 "running",
153 "waiting",
154 "completed",
155 "failed",
156 "cancelled",
157 "interrupted",
158]);
159export type OrchestratorMcpDelegatedTaskStatus = typeof OrchestratorMcpDelegatedTaskStatus.Type;
160
161export const OrchestratorMcpTerminalDelegatedTaskStatus = Schema.Literals([
162 "completed",
163 "failed",
164 "cancelled",
165 "interrupted",
166]);
167export type OrchestratorMcpTerminalDelegatedTaskStatus =
168 typeof OrchestratorMcpTerminalDelegatedTaskStatus.Type;
169
170export const OrchestratorMcpDelegateTaskInput = Schema.Struct({
171 task: OrchestratorMcpPrompt.annotate({
172 description: "Self-contained task for one delegated child agent/subagent.",
173 }),
174 target: Schema.optional(OrchestratorMcpTarget),
175 title: Schema.optional(OrchestratorMcpTitle),
176 role: Schema.optional(OrchestratorMcpTaskRole),
177 mode: Schema.optional(
178 Schema.Literals(["async", "wait"]).annotate({
179 description:
180 "Defaults to async. Use wait only when this turn needs the child's result before you can continue.",
181 }),
182 ),
183 timeoutMs: Schema.optional(Schema.Number).annotate({
184 description:
185 "Wait budget for mode=wait only. Default 10 minutes. Elapsing it returns waitTimedOut=true on that call and does not cancel the child.",
186 }),
187 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
188 runtimeMode: Schema.optional(OrchestratorMcpRuntimeMode),
189 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
190});
191export type OrchestratorMcpDelegateTaskInput = typeof OrchestratorMcpDelegateTaskInput.Type;
192
193export const OrchestratorMcpDelegateTaskResult = Schema.Struct({
194 taskId: NodeId,
195 childThreadId: ThreadId,
196 childRunId: Schema.NullOr(RunId),
197 childNodeId: NodeId,
198 status: OrchestratorMcpDelegatedTaskStatus,
199 workState: Schema.Literals(["working", "waiting_for_children", "result_available"]),
200 hasPendingChildRuns: Schema.Boolean,
201 latestTerminalRunId: Schema.NullOr(RunId),
202 latestTerminalStatus: Schema.NullOr(OrchestratorMcpTerminalDelegatedTaskStatus),
203 latestTerminalSummary: Schema.NullOr(Schema.String),
204 latestTerminalResultContextTransferId: Schema.NullOr(ContextTransferId),
205 providerInstanceId: ProviderInstanceId,
206 model: Schema.NullOr(Schema.String),
207 summary: Schema.NullOr(Schema.String),
208 resultContextTransferId: Schema.NullOr(ContextTransferId),
209 waitTimedOut: Schema.Boolean.annotate({
210 description:
211 "True only on that mode=wait call when timeoutMs elapsed. The timeout does not cancel the child. Later task_status reads return false and use status for liveness.",
212 }),
213});
214export type OrchestratorMcpDelegateTaskResult = typeof OrchestratorMcpDelegateTaskResult.Type;
215
216export const OrchestratorMcpTaskStatusInput = Schema.Struct({
217 taskId: NodeId,
218});
219export type OrchestratorMcpTaskStatusInput = typeof OrchestratorMcpTaskStatusInput.Type;
220
221export const OrchestratorMcpTaskCancelInput = Schema.Struct({
222 taskId: NodeId,
223 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
224 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
225});
226export type OrchestratorMcpTaskCancelInput = typeof OrchestratorMcpTaskCancelInput.Type;
227
228export const OrchestratorMcpTaskCancelResult = Schema.Struct({
229 taskId: NodeId,
230 status: Schema.Literals(["cancel_requested", "completed", "failed", "cancelled", "interrupted"]),
231});
232export type OrchestratorMcpTaskCancelResult = typeof OrchestratorMcpTaskCancelResult.Type;
233
234export const OrchestratorMcpCreateThreadRequest = Schema.Struct({
235 prompt: Schema.optional(OrchestratorMcpPrompt),
236 title: Schema.optional(OrchestratorMcpTitle),
237 target: Schema.optional(OrchestratorMcpTarget),
238 runtimeMode: Schema.optional(OrchestratorMcpRuntimeMode),
239 interactionMode: Schema.optional(OrchestratorMcpInteractionMode),
240});
241export type OrchestratorMcpCreateThreadRequest = typeof OrchestratorMcpCreateThreadRequest.Type;
242
243export const OrchestratorMcpCreateThreadsInput = Schema.Struct({
244 threads: Schema.Array(OrchestratorMcpCreateThreadRequest).check(
245 Schema.isMinLength(1),
246 Schema.isMaxLength(20),
247 ),
248 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
249});
250export type OrchestratorMcpCreateThreadsInput = typeof OrchestratorMcpCreateThreadsInput.Type;
251
252export const OrchestratorMcpCreatedThreadStatus = Schema.Union([
253 Schema.Literal("idle"),
254 Schema.Literal("preparing"),
255 Schema.Literal("starting"),
256 OrchestratorMcpDelegatedTaskStatus,
257 Schema.Literal("rolled_back"),
258]);
259export type OrchestratorMcpCreatedThreadStatus = typeof OrchestratorMcpCreatedThreadStatus.Type;
260
261export const OrchestratorMcpCreatedThread = Schema.Struct({
262 threadId: ThreadId,
263 runId: Schema.NullOr(RunId),
264 status: OrchestratorMcpCreatedThreadStatus,
265 title: Schema.String,
266 createdBy: OrchestrationV2Actor,
267 creationSource: OrchestrationV2CreationSource,
268 providerInstanceId: ProviderInstanceId,
269 model: Schema.String,
270});
271export type OrchestratorMcpCreatedThread = typeof OrchestratorMcpCreatedThread.Type;
272
273export const OrchestratorMcpCreateThreadsResult = Schema.Struct({
274 threads: Schema.Array(OrchestratorMcpCreatedThread),
275});
276export type OrchestratorMcpCreateThreadsResult = typeof OrchestratorMcpCreateThreadsResult.Type;
277
278export const OrchestratorMcpThreadStatus = Schema.Union([
279 Schema.Literal("idle"),
280 OrchestrationV2RunStatus,
281]);
282export type OrchestratorMcpThreadStatus = typeof OrchestratorMcpThreadStatus.Type;
283
284const OrchestratorMcpProjectTarget = Schema.optional(
285 ProjectId.annotate({
286 description:
287 "Project to act on. Omit for the calling thread's project; required when the caller is not a T3 thread.",
288 }),
289);
290
291export const OrchestratorMcpThreadListInput = Schema.Struct({
292 projectId: OrchestratorMcpProjectTarget,
293 statuses: Schema.optional(
294 Schema.Array(OrchestratorMcpThreadStatus).check(Schema.isMaxLength(10)),
295 ),
296 titleContains: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(256))),
297 settled: Schema.optional(Schema.Boolean),
298 snoozed: Schema.optional(Schema.Boolean),
299 includeSubagents: Schema.optional(Schema.Boolean),
300 cursor: Schema.optional(NonNegativeInt),
301 limit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(100))),
302});
303export type OrchestratorMcpThreadListInput = typeof OrchestratorMcpThreadListInput.Type;
304
305export const OrchestratorMcpThreadListItem = Schema.Struct({
306 threadId: ThreadId,
307 title: Schema.String,
308 createdBy: OrchestrationV2Actor,
309 creationSource: OrchestrationV2CreationSource,
310 status: OrchestratorMcpThreadStatus,
311 latestRunId: Schema.NullOr(RunId),
312 providerInstanceId: ProviderInstanceId,
313 model: Schema.String,
314 runtimeMode: RuntimeMode,
315 interactionMode: ProviderInteractionMode,
316 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
317 settled: Schema.Boolean,
318 settledAt: Schema.NullOr(IsoDateTime),
319 snoozed: Schema.Boolean,
320 /** When a snoozed thread wakes; null when it is not snoozed. */
321 snoozedUntil: Schema.NullOr(IsoDateTime),
322 parentThreadId: Schema.NullOr(ThreadId),
323 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
324 itemCount: NonNegativeInt,
325 createdAt: IsoDateTime,
326 updatedAt: IsoDateTime,
327});
328export type OrchestratorMcpThreadListItem = typeof OrchestratorMcpThreadListItem.Type;
329
330export const OrchestratorMcpThreadListResult = Schema.Struct({
331 projectId: ProjectId,
332 /** The calling thread, or null when the caller is not a T3 thread. */
333 currentThreadId: Schema.NullOr(ThreadId),
334 threads: Schema.Array(OrchestratorMcpThreadListItem),
335 nextCursor: Schema.NullOr(NonNegativeInt),
336 total: NonNegativeInt,
337});
338export type OrchestratorMcpThreadListResult = typeof OrchestratorMcpThreadListResult.Type;
339
340export const OrchestratorMcpThreadReadInput = Schema.Struct({
341 threadId: ThreadId,
342 itemId: Schema.optional(TurnItemId),
343 textOffset: Schema.optional(NonNegativeInt),
344 view: Schema.optional(Schema.Literals(["messages", "activity"])),
345 afterPosition: Schema.optional(NonNegativeInt),
346 limit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(100))),
347 runLimit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(50))),
348 maxCharsPerItem: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(50_000))),
349});
350export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type;
351
352export const OrchestratorMcpThreadDetail = Schema.Struct({
353 threadId: ThreadId,
354 projectId: ProjectId,
355 title: Schema.String,
356 createdBy: OrchestrationV2Actor,
357 creationSource: OrchestrationV2CreationSource,
358 status: OrchestratorMcpThreadStatus,
359 latestRunId: Schema.NullOr(RunId),
360 activeRunId: Schema.NullOr(RunId),
361 providerInstanceId: ProviderInstanceId,
362 model: Schema.String,
363 runtimeMode: RuntimeMode,
364 interactionMode: ProviderInteractionMode,
365 linkedPullRequest: Schema.NullOr(ThreadLinkedPullRequest),
366 titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
367 branch: Schema.NullOr(Schema.String),
368 worktreePath: Schema.NullOr(Schema.String),
369 parentThreadId: Schema.NullOr(ThreadId),
370 relationshipToParent: Schema.NullOr(Schema.Literals(["fork", "subagent"])),
371 runCount: NonNegativeInt,
372 itemCount: NonNegativeInt,
373 pendingRequestCount: NonNegativeInt,
374 archived: Schema.Boolean,
375 settled: Schema.Boolean,
376 settledAt: Schema.NullOr(IsoDateTime),
377 snoozed: Schema.Boolean,
378 /** When a snoozed thread wakes; null when it is not snoozed. */
379 snoozedUntil: Schema.NullOr(IsoDateTime),
380 createdAt: IsoDateTime,
381 updatedAt: IsoDateTime,
382});
383export type OrchestratorMcpThreadDetail = typeof OrchestratorMcpThreadDetail.Type;
384
385export const OrchestratorMcpThreadRun = Schema.Struct({
386 runId: RunId,
387 ordinal: PositiveInt,
388 status: OrchestrationV2RunStatus,
389 providerInstanceId: ProviderInstanceId,
390 model: Schema.String,
391 requestedAt: IsoDateTime,
392 startedAt: Schema.NullOr(IsoDateTime),
393 completedAt: Schema.NullOr(IsoDateTime),
394});
395export type OrchestratorMcpThreadRun = typeof OrchestratorMcpThreadRun.Type;
396
397export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
398 position: NonNegativeInt,
399 visibility: Schema.Literals(["local", "inherited", "synthetic"]),
400 sourceThreadId: ThreadId,
401 itemId: TurnItemId,
402 runId: Schema.NullOr(RunId),
403 messageId: Schema.NullOr(MessageId),
404 createdBy: Schema.NullOr(OrchestrationV2Actor),
405 creationSource: Schema.NullOr(OrchestrationV2CreationSource),
406 type: Schema.String,
407 status: OrchestrationV2TurnItemStatus,
408 title: Schema.NullOr(Schema.String),
409 text: Schema.NullOr(Schema.String),
410 textTruncated: Schema.Boolean,
411 nextTextOffset: Schema.optional(Schema.NullOr(NonNegativeInt)),
412 updatedAt: IsoDateTime,
413});
414export type OrchestratorMcpThreadTimelineItem = typeof OrchestratorMcpThreadTimelineItem.Type;
415
416export const OrchestratorMcpThreadReadResult = Schema.Struct({
417 thread: OrchestratorMcpThreadDetail,
418 recentRuns: Schema.Array(OrchestratorMcpThreadRun),
419 items: Schema.Array(OrchestratorMcpThreadTimelineItem),
420 nextPosition: Schema.NullOr(NonNegativeInt),
421 hasMore: Schema.Boolean,
422});
423export type OrchestratorMcpThreadReadResult = typeof OrchestratorMcpThreadReadResult.Type;
424
425export const OrchestratorMcpThreadSendInput = Schema.Struct({
426 threadId: ThreadId,
427 message: OrchestratorMcpPrompt,
428 mode: Schema.optional(Schema.Literals(["auto", "queue", "steer", "restart"])),
429 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
430});
431export type OrchestratorMcpThreadSendInput = typeof OrchestratorMcpThreadSendInput.Type;
432
433export const OrchestratorMcpThreadSendResult = Schema.Struct({
434 threadId: ThreadId,
435 messageId: MessageId,
436 runId: RunId,
437 status: OrchestrationV2RunStatus,
438 delivery: Schema.Literals(["started", "queued", "steered", "restarted"]),
439});
440export type OrchestratorMcpThreadSendResult = typeof OrchestratorMcpThreadSendResult.Type;
441
442export const OrchestratorMcpThreadWaitInput = Schema.Struct({
443 threadId: ThreadId,
444 runId: Schema.optional(RunId),
445 timeoutMs: Schema.optional(Schema.Number),
446});
447export type OrchestratorMcpThreadWaitInput = typeof OrchestratorMcpThreadWaitInput.Type;
448
449export const OrchestratorMcpThreadWaitResult = Schema.Struct({
450 threadId: ThreadId,
451 runId: Schema.NullOr(RunId),
452 status: OrchestratorMcpThreadStatus,
453 timedOut: Schema.Boolean,
454});
455export type OrchestratorMcpThreadWaitResult = typeof OrchestratorMcpThreadWaitResult.Type;
456
457export const OrchestratorMcpThreadInterruptInput = Schema.Struct({
458 threadId: ThreadId,
459 runId: Schema.optional(RunId),
460 reason: Schema.optional(Schema.String.check(Schema.isMaxLength(2_000))),
461 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
462});
463export type OrchestratorMcpThreadInterruptInput = typeof OrchestratorMcpThreadInterruptInput.Type;
464
465export const OrchestratorMcpThreadInterruptResult = Schema.Struct({
466 threadId: ThreadId,
467 runId: Schema.NullOr(RunId),
468 status: Schema.Union([
469 Schema.Literal("interrupt_requested"),
470 Schema.Literal("no_active_run"),
471 Schema.Literals(["completed", "failed", "cancelled", "interrupted", "rolled_back"]),
472 ]),
473});
474export type OrchestratorMcpThreadInterruptResult = typeof OrchestratorMcpThreadInterruptResult.Type;
475
476export const OrchestratorMcpProviderCapability = Schema.Struct({
477 providerInstanceId: ProviderInstanceId,
478 driverKind: ProviderDriverKind,
479 displayName: Schema.NullOr(Schema.String),
480 models: Schema.Array(
481 Schema.Struct({
482 id: Schema.String,
483 label: Schema.NullOr(Schema.String),
484 /** Model options a target may select (for example reasoning effort). */
485 options: Schema.optional(Schema.Array(ProviderOptionDescriptor)),
486 }),
487 ),
488 canRunChildTask: Schema.Boolean,
489 canRunCrossProviderChildTask: Schema.Boolean,
490 constraints: Schema.Array(Schema.String),
491});
492export type OrchestratorMcpProviderCapability = typeof OrchestratorMcpProviderCapability.Type;
493
494export const OrchestratorMcpCapabilitiesResult = Schema.Struct({
495 /** The calling thread, or null when the caller is not a T3 thread. */
496 parentThreadId: Schema.NullOr(ThreadId),
497 /** The calling thread's selection, or null when the caller is not a T3 thread. */
498 inheritedProviderInstanceId: Schema.NullOr(ProviderInstanceId),
499 inheritedModel: Schema.NullOr(Schema.String),
500 runtimeMode: RuntimeMode,
501 interactionMode: ProviderInteractionMode,
502 providers: Schema.Array(OrchestratorMcpProviderCapability),
503 features: Schema.Struct({
504 appOwnedSubagents: Schema.Boolean,
505 asyncPolling: Schema.Boolean,
506 cancellation: Schema.Boolean,
507 batchThreadCreation: Schema.Boolean,
508 threadManagement: Schema.Boolean,
509 incrementalThreadRead: Schema.Boolean,
510 scheduledTasks: Schema.Boolean,
511 maxBatchThreads: Schema.Number,
512 }),
513});
514export type OrchestratorMcpCapabilitiesResult = typeof OrchestratorMcpCapabilitiesResult.Type;
515
516export const OrchestratorMcpScheduleTaskInput = Schema.Struct({
517 projectId: OrchestratorMcpProjectTarget,
518 prompt: OrchestratorMcpPrompt.annotate({
519 description: "Prompt executed on every scheduled run.",
520 }),
521 schedule: OrchestratorMcpSchedule,
522 title: Schema.optional(OrchestratorMcpTitle),
523 enabled: Schema.optional(
524 Schema.Boolean.annotate({ description: "Whether the schedule starts enabled; defaults true." }),
525 ),
526 /**
527 * When true (the default), the scheduled task fires into the calling thread
528 * on each run instead of launching a fresh thread. This is the recurring
529 * "wake up in this thread" behaviour reserved for agent-created tasks.
530 */
531 bindToCurrentThread: Schema.optional(
532 Schema.Boolean.annotate({
533 description:
534 "True (default) posts each run into this thread; false creates a fresh top-level thread per run.",
535 }),
536 ),
537 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
538});
539export type OrchestratorMcpScheduleTaskInput = typeof OrchestratorMcpScheduleTaskInput.Type;
540
541/** Summary of a scheduled task returned by the schedule/list/update tools. */
542export const OrchestratorMcpScheduledTask = Schema.Struct({
543 scheduledTaskId: ScheduledTaskId,
544 title: Schema.String,
545 prompt: Schema.String,
546 enabled: Schema.Boolean,
547 projectId: ProjectId,
548 boundThreadId: Schema.NullOr(ThreadId),
549 schedule: ScheduledTaskSchedule,
550 nextRunAt: Schema.NullOr(IsoDateTime),
551 lastRunStatus: ScheduledTaskRunStatus,
552 /** For webhook tasks: the public T3 Connect URL. Absent when this environment has no managed tunnel. */
553 webhookUrl: Schema.optional(Schema.String).annotate({
554 description:
555 "Public URL to give the sender. Absent when this environment has no T3 Connect managed tunnel; the user must enable T3 Connect remote access first.",
556 }),
557 webhookSignature: Schema.optional(Schema.Literals(["none", "set"])).annotate({
558 description: "Whether requests must carry a valid signature.",
559 }),
560});
561export type OrchestratorMcpScheduledTask = typeof OrchestratorMcpScheduledTask.Type;
562
563export const OrchestratorMcpScheduleTaskResult = OrchestratorMcpScheduledTask;
564export type OrchestratorMcpScheduleTaskResult = typeof OrchestratorMcpScheduleTaskResult.Type;
565
566export const OrchestratorMcpListScheduledTasksInput = Schema.Struct({
567 projectId: Schema.optional(
568 ProjectId.annotate({
569 description:
570 "Only list this project's tasks. Omit for the calling thread's project, or for every project when the caller is not a T3 thread.",
571 }),
572 ),
573});
574export type OrchestratorMcpListScheduledTasksInput =
575 typeof OrchestratorMcpListScheduledTasksInput.Type;
576
577export const OrchestratorMcpListScheduledTasksResult = Schema.Struct({
578 tasks: Schema.Array(OrchestratorMcpScheduledTask),
579});
580export type OrchestratorMcpListScheduledTasksResult =
581 typeof OrchestratorMcpListScheduledTasksResult.Type;
582
583export const OrchestratorMcpUpdateScheduledTaskInput = Schema.Struct({
584 scheduledTaskId: ScheduledTaskId,
585 prompt: Schema.optional(OrchestratorMcpPrompt),
586 title: Schema.optional(OrchestratorMcpTitle),
587 schedule: Schema.optional(OrchestratorMcpSchedule),
588 enabled: Schema.optional(Schema.Boolean),
589 bindToCurrentThread: Schema.optional(Schema.Boolean),
590});
591export type OrchestratorMcpUpdateScheduledTaskInput =
592 typeof OrchestratorMcpUpdateScheduledTaskInput.Type;
593
594export const OrchestratorMcpRequestSecretInput = Schema.Struct({
595 label: TrimmedNonEmptyString.annotate({
596 description: "What you need, shown as the card's title, e.g. 'GitHub webhook secret'.",
597 }),
598 reason: TrimmedNonEmptyString.annotate({
599 description:
600 "One or two sentences on what it is for and where the user gets or also enters it.",
601 }),
602 placeholder: Schema.optional(TrimmedNonEmptyString).annotate({
603 description: "Hint inside the input, e.g. 'Paste your GitHub token'.",
604 }),
605 timeoutMs: Schema.optional(
606 Schema.Int.check(Schema.isBetween({ minimum: 1_000, maximum: 60 * 60 * 1_000 })),
607 ).annotate({ description: "How long to wait for the user. Default 10 minutes." }),
608 clientRequestId: Schema.optional(OrchestratorMcpClientRequestId).annotate({
609 description:
610 "Reuse when retrying a call that lost its result, so the user sees one card and its answer is returned again. Use a new id to ask again after timed_out or cancelled.",
611 }),
612});
613export type OrchestratorMcpRequestSecretInput = typeof OrchestratorMcpRequestSecretInput.Type;
614
615export const OrchestratorMcpRequestSecretResult = Schema.Union([
616 Schema.Struct({
617 status: Schema.Literal("saved").annotate({ description: "secretRef holds the value." }),
618 secretRef: SecretRef.annotate({
619 description:
620 "Pass it to a tool that accepts a secretRef; it works once, and you never see the value.",
621 }),
622 }),
623 Schema.Struct({
624 status: Schema.Literals(["declined", "cancelled", "timed_out"]).annotate({
625 description:
626 "declined: the user chose not to. cancelled: the request ended with the run. timed_out: the user did not answer in time; the card is closed, so ask again with a new clientRequestId if still needed.",
627 }),
628 }),
629]);
630export type OrchestratorMcpRequestSecretResult = typeof OrchestratorMcpRequestSecretResult.Type;
631
632export const OrchestratorMcpDeleteScheduledTaskInput = Schema.Struct({
633 scheduledTaskId: ScheduledTaskId,
634});
635export type OrchestratorMcpDeleteScheduledTaskInput =
636 typeof OrchestratorMcpDeleteScheduledTaskInput.Type;
637
638export const OrchestratorMcpDeleteScheduledTaskResult = Schema.Struct({
639 scheduledTaskId: ScheduledTaskId,
640 deleted: Schema.Boolean,
641});
642export type OrchestratorMcpDeleteScheduledTaskResult =
643 typeof OrchestratorMcpDeleteScheduledTaskResult.Type;
644
645export class OrchestratorMcpFailure extends Schema.TaggedError<OrchestratorMcpFailure>()(
646 "OrchestratorMcpFailure",
647 {
648 code: Schema.Literals([
649 "capability_denied",
650 "parent_not_active",
651 "provider_unavailable",
652 "model_unavailable",
653 "runtime_mode_escalation_denied",
654 "interaction_mode_escalation_denied",
655 "task_not_found",
656 "task_not_cancellable",
657 "thread_not_found",
658 "run_not_found",
659 "thread_not_sendable",
660 "thread_not_interruptible",
661 "invalid_request",
662 "orchestration_error",
663 "thread_credential_required",
664 "target_required",
665 ]),
666 message: Schema.String,
667 },
668) {}