Open History to see the last commit
1import type { OrchestrationV2HistoricalMessage } from "@t3tools/contracts";
2import {
3 ChatAttachment,
4 CheckpointId,
5 MessageId,
6 ModelSelection,
7 NodeId,
8 OrchestrationV2AppThread,
9 OrchestrationV2ConversationMessage,
10 OrchestrationV2ExecutionNode,
11 OrchestrationV2ProviderSession,
12 OrchestrationV2PlanArtifact,
13 OrchestrationV2ProviderCapabilities,
14 OrchestrationV2ProviderFailure,
15 OrchestrationV2ProviderRetry,
16 OrchestrationV2ProviderThread,
17 OrchestrationV2ProviderTurn,
18 OrchestrationV2RuntimeRequest,
19 OrchestrationV2Subagent,
20 OrchestrationV2TurnItem,
21 ProviderApprovalDecision,
22 ProviderInteractionMode,
23 ProviderDriverKind,
24 ProviderInstanceId,
25 PositiveInt,
26 ProviderUserInputAnswers,
27 ProviderSessionId,
28 ProviderThreadId,
29 ProviderTurnId,
30 RuntimeMode,
31 RuntimeRequestId,
32 RunAttemptId,
33 RunId,
34 ThreadId,
35 TurnItemId,
36} from "@t3tools/contracts";
37import * as Context from "effect/Context";
38import * as Schema from "effect/Schema";
39import type * as Effect from "effect/Effect";
40import type * as Scope from "effect/Scope";
41import type * as Stream from "effect/Stream";
42
43import type {
44 ProviderSelectionTransitionInput,
45 ProviderSelectionTransitionPlan,
46} from "./selectionTransition.ts";
47
48export const ProviderAdapterV2RuntimePolicy = Schema.Struct({
49 runtimeMode: RuntimeMode,
50 interactionMode: ProviderInteractionMode,
51 cwd: Schema.NullOr(Schema.String),
52 approvalPolicy: Schema.optional(Schema.Unknown),
53 sandboxPolicy: Schema.optional(Schema.Unknown),
54});
55export type ProviderAdapterV2RuntimePolicy = typeof ProviderAdapterV2RuntimePolicy.Type;
56
57export const ProviderAdapterV2TurnMessage = Schema.Struct({
58 messageId: MessageId,
59 text: Schema.String,
60 attachments: Schema.Array(ChatAttachment),
61 createdBy: OrchestrationV2ConversationMessage.fields.createdBy,
62 creationSource: OrchestrationV2ConversationMessage.fields.creationSource,
63 scheduledTaskId: OrchestrationV2ConversationMessage.fields.scheduledTaskId,
64 senderThreadId: OrchestrationV2ConversationMessage.fields.senderThreadId,
65});
66export type ProviderAdapterV2TurnMessage = typeof ProviderAdapterV2TurnMessage.Type;
67
68export const ProviderAdapterV2SessionStatus = Schema.Literals([
69 "starting",
70 "ready",
71 "running",
72 "waiting",
73 "stopped",
74 "error",
75]);
76export type ProviderAdapterV2SessionStatus = typeof ProviderAdapterV2SessionStatus.Type;
77
78export const ProviderAdapterV2Event = Schema.Union([
79 Schema.Struct({
80 type: Schema.Literal("app_thread.created"),
81 driver: ProviderDriverKind,
82 appThread: OrchestrationV2AppThread,
83 createOnly: Schema.optional(Schema.Boolean),
84 }),
85 Schema.Struct({
86 type: Schema.Literal("provider_session.updated"),
87 driver: ProviderDriverKind,
88 providerSession: OrchestrationV2ProviderSession,
89 }),
90 Schema.Struct({
91 type: Schema.Literal("provider_thread.updated"),
92 driver: ProviderDriverKind,
93 providerThread: OrchestrationV2ProviderThread,
94 retainedNativeTurnIds: Schema.optional(Schema.Array(Schema.String)),
95 }),
96 Schema.Struct({
97 type: Schema.Literal("provider_turn.updated"),
98 driver: ProviderDriverKind,
99 threadId: Schema.optional(ThreadId),
100 providerTurn: OrchestrationV2ProviderTurn,
101 }),
102 Schema.Struct({
103 type: Schema.Literal("node.updated"),
104 driver: ProviderDriverKind,
105 node: OrchestrationV2ExecutionNode,
106 }),
107 Schema.Struct({
108 type: Schema.Literal("subagent.updated"),
109 driver: ProviderDriverKind,
110 subagent: OrchestrationV2Subagent,
111 }),
112 Schema.Struct({
113 type: Schema.Literal("message.updated"),
114 driver: ProviderDriverKind,
115 message: OrchestrationV2ConversationMessage,
116 }),
117 Schema.Struct({
118 type: Schema.Literal("turn_item.updated"),
119 driver: ProviderDriverKind,
120 turnItem: OrchestrationV2TurnItem,
121 }),
122 // Start before the root terminal; clear only after the final covered projection.
123 // Consumer lifetime cannot depend on a producer probe that runs ahead of its queue.
124 Schema.Struct({
125 type: Schema.Literal("background_work.updated"),
126 driver: ProviderDriverKind,
127 providerTurnId: ProviderTurnId,
128 pending: Schema.Boolean,
129 }),
130 /** Unpersisted deltas go only to clients showing the row; final output arrives in turn_item.updated. */
131 Schema.Struct({
132 type: Schema.Literal("command_output.delta"),
133 driver: ProviderDriverKind,
134 threadId: ThreadId,
135 itemId: TurnItemId,
136 chunk: Schema.String,
137 }),
138 Schema.Struct({
139 type: Schema.Literal("runtime_request.updated"),
140 driver: ProviderDriverKind,
141 threadId: Schema.optional(ThreadId),
142 runtimeRequest: OrchestrationV2RuntimeRequest,
143 }),
144 Schema.Struct({
145 type: Schema.Literal("plan.updated"),
146 driver: ProviderDriverKind,
147 plan: OrchestrationV2PlanArtifact,
148 }),
149 Schema.Struct({
150 type: Schema.Literal("turn.terminal"),
151 driver: ProviderDriverKind,
152 providerThreadId: ProviderThreadId,
153 providerTurnId: ProviderTurnId,
154 runOrdinal: PositiveInt,
155 status: Schema.Literals(["completed", "interrupted", "cancelled"]),
156 failure: Schema.Null,
157 threadDisposition: Schema.Literals(["reusable", "broken"]),
158 }),
159 Schema.Struct({
160 type: Schema.Literal("turn.terminal"),
161 driver: ProviderDriverKind,
162 providerThreadId: ProviderThreadId,
163 providerTurnId: ProviderTurnId,
164 runOrdinal: PositiveInt,
165 failureItemOrdinal: PositiveInt,
166 status: Schema.Literal("failed"),
167 failure: OrchestrationV2ProviderFailure,
168 retry: Schema.optional(OrchestrationV2ProviderRetry),
169 retryStartedAt: Schema.optional(Schema.DateTimeUtc),
170 threadDisposition: Schema.Literals(["reusable", "broken"]),
171 /** Child turns outlive root failure and report their own terminals; otherwise open children settle. */
172 childTurnsContinue: Schema.optional(Schema.Literal(true)),
173 }),
174]);
175export type ProviderAdapterV2Event = typeof ProviderAdapterV2Event.Type;
176
177export class ProviderAdapterCapabilitiesError extends Schema.TaggedError<ProviderAdapterCapabilitiesError>()(
178 "ProviderAdapterCapabilitiesError",
179 {
180 driver: ProviderDriverKind,
181 cause: Schema.optional(Schema.Defect()),
182 },
183) {
184 override get message(): string {
185 return `Failed to read ${this.driver} provider capabilities.`;
186 }
187}
188
189export class ProviderAdapterOpenSessionError extends Schema.TaggedError<ProviderAdapterOpenSessionError>()(
190 "ProviderAdapterOpenSessionError",
191 {
192 driver: ProviderDriverKind,
193 providerSessionId: ProviderSessionId,
194 requiresSignIn: Schema.optional(Schema.Literal(true)),
195 cause: Schema.optional(Schema.Defect()),
196 },
197) {
198 override get message(): string {
199 return `Failed to open ${this.driver} provider session ${this.providerSessionId}.`;
200 }
201}
202
203export class ProviderAdapterCloseSessionError extends Schema.TaggedError<ProviderAdapterCloseSessionError>()(
204 "ProviderAdapterCloseSessionError",
205 {
206 driver: ProviderDriverKind,
207 providerSessionId: ProviderSessionId,
208 cause: Schema.optional(Schema.Defect()),
209 },
210) {
211 override get message(): string {
212 return `Failed to close ${this.driver} provider session ${this.providerSessionId}.`;
213 }
214}
215
216export class ProviderAdapterResumeThreadError extends Schema.TaggedError<ProviderAdapterResumeThreadError>()(
217 "ProviderAdapterResumeThreadError",
218 {
219 driver: ProviderDriverKind,
220 providerSessionId: ProviderSessionId,
221 providerThreadId: ProviderThreadId,
222 cause: Schema.optional(Schema.Defect()),
223 },
224) {
225 override get message(): string {
226 return `Failed to resume ${this.driver} provider thread ${this.providerThreadId}.`;
227 }
228}
229
230export class ProviderAdapterEnsureThreadError extends Schema.TaggedError<ProviderAdapterEnsureThreadError>()(
231 "ProviderAdapterEnsureThreadError",
232 {
233 driver: ProviderDriverKind,
234 threadId: ThreadId,
235 cause: Schema.optional(Schema.Defect()),
236 },
237) {
238 override get message(): string {
239 return `Failed to ensure ${this.driver} provider thread for app thread ${this.threadId}.`;
240 }
241}
242
243export class ProviderAdapterReadThreadSnapshotError extends Schema.TaggedError<ProviderAdapterReadThreadSnapshotError>()(
244 "ProviderAdapterReadThreadSnapshotError",
245 {
246 driver: ProviderDriverKind,
247 providerThreadId: ProviderThreadId,
248 cause: Schema.optional(Schema.Defect()),
249 },
250) {
251 override get message(): string {
252 return `Failed to read ${this.driver} provider thread snapshot ${this.providerThreadId}.`;
253 }
254}
255
256export class ProviderAdapterRollbackThreadError extends Schema.TaggedError<ProviderAdapterRollbackThreadError>()(
257 "ProviderAdapterRollbackThreadError",
258 {
259 driver: ProviderDriverKind,
260 providerThreadId: ProviderThreadId,
261 checkpointId: Schema.optional(CheckpointId),
262 cause: Schema.optional(Schema.Defect()),
263 },
264) {
265 override get message(): string {
266 return `Failed to roll back ${this.driver} provider thread ${this.providerThreadId}.`;
267 }
268}
269
270export class ProviderAdapterForkThreadError extends Schema.TaggedError<ProviderAdapterForkThreadError>()(
271 "ProviderAdapterForkThreadError",
272 {
273 driver: ProviderDriverKind,
274 providerThreadId: ProviderThreadId,
275 cause: Schema.optional(Schema.Defect()),
276 },
277) {
278 override get message(): string {
279 return `Failed to fork ${this.driver} provider thread ${this.providerThreadId}.`;
280 }
281}
282
283export class ProviderAdapterTurnStartError extends Schema.TaggedError<ProviderAdapterTurnStartError>()(
284 "ProviderAdapterTurnStartError",
285 {
286 driver: ProviderDriverKind,
287 threadId: ThreadId,
288 providerThreadId: ProviderThreadId,
289 runId: RunId,
290 cause: Schema.optional(Schema.Defect()),
291 },
292) {
293 override get message(): string {
294 return `Failed to start run ${this.runId} on ${this.driver} provider thread ${this.providerThreadId}.`;
295 }
296}
297
298export class ProviderAdapterSteerRunUnsupportedError extends Schema.TaggedError<ProviderAdapterSteerRunUnsupportedError>()(
299 "ProviderAdapterSteerRunUnsupportedError",
300 {
301 driver: ProviderDriverKind,
302 providerThreadId: ProviderThreadId,
303 },
304) {
305 override get message(): string {
306 return `${this.driver} provider thread ${this.providerThreadId} does not support active-run steering.`;
307 }
308}
309
310export class ProviderAdapterSteerRunError extends Schema.TaggedError<ProviderAdapterSteerRunError>()(
311 "ProviderAdapterSteerRunError",
312 {
313 driver: ProviderDriverKind,
314 providerThreadId: ProviderThreadId,
315 providerTurnId: ProviderTurnId,
316 cause: Schema.optional(Schema.Defect()),
317 },
318) {
319 override get message(): string {
320 return `Failed to steer active run ${this.providerTurnId} on ${this.driver} provider thread ${this.providerThreadId}.`;
321 }
322}
323
324export class ProviderAdapterInterruptError extends Schema.TaggedError<ProviderAdapterInterruptError>()(
325 "ProviderAdapterInterruptError",
326 {
327 driver: ProviderDriverKind,
328 providerThreadId: ProviderThreadId,
329 providerTurnId: ProviderTurnId,
330 cause: Schema.optional(Schema.Defect()),
331 },
332) {
333 override get message(): string {
334 return `Failed to interrupt ${this.driver} provider turn ${this.providerTurnId}.`;
335 }
336}
337
338/** The provider did not confirm a stop in time; its processes may still be running. */
339export class ProviderAdapterInterruptTimeoutError extends Schema.TaggedError<ProviderAdapterInterruptTimeoutError>()(
340 "ProviderAdapterInterruptTimeoutError",
341 {
342 driver: ProviderDriverKind,
343 providerThreadId: ProviderThreadId,
344 providerTurnId: ProviderTurnId,
345 timeoutMs: Schema.Number,
346 },
347) {
348 override get message(): string {
349 return `The ${this.driver} provider did not confirm stopping turn ${this.providerTurnId} within ${this.timeoutMs} ms.`;
350 }
351}
352
353export class ProviderAdapterRuntimeRequestResponseError extends Schema.TaggedError<ProviderAdapterRuntimeRequestResponseError>()(
354 "ProviderAdapterRuntimeRequestResponseError",
355 {
356 driver: ProviderDriverKind,
357 requestId: RuntimeRequestId,
358 cause: Schema.optional(Schema.Defect()),
359 },
360) {
361 override get message(): string {
362 return `Failed to respond to ${this.driver} runtime request ${this.requestId}.`;
363 }
364}
365
366export class ProviderAdapterEventStreamError extends Schema.TaggedError<ProviderAdapterEventStreamError>()(
367 "ProviderAdapterEventStreamError",
368 {
369 driver: ProviderDriverKind,
370 providerSessionId: ProviderSessionId,
371 cause: Schema.optional(Schema.Defect()),
372 },
373) {
374 override get message(): string {
375 return `Failed while streaming ${this.driver} provider session ${this.providerSessionId} events.`;
376 }
377}
378
379// Only fixed reasons reach failure messages; detail can contain private configuration.
380const ProviderAdapterFailureReason = Schema.Literals([
381 "previous_turn_active",
382 "attachment_unreadable",
383]);
384export type ProviderAdapterFailureReason = typeof ProviderAdapterFailureReason.Type;
385
386export class ProviderAdapterProtocolError extends Schema.TaggedError<ProviderAdapterProtocolError>()(
387 "ProviderAdapterProtocolError",
388 {
389 driver: ProviderDriverKind,
390 detail: Schema.String,
391 reason: Schema.optional(ProviderAdapterFailureReason),
392 cause: Schema.optional(Schema.Defect()),
393 payload: Schema.optional(Schema.Unknown),
394 },
395) {
396 override get message(): string {
397 return `${this.driver} provider protocol error: ${this.detail}.`;
398 }
399}
400
401export const ProviderAdapterV2Error = Schema.Union([
402 ProviderAdapterCapabilitiesError,
403 ProviderAdapterOpenSessionError,
404 ProviderAdapterCloseSessionError,
405 ProviderAdapterResumeThreadError,
406 ProviderAdapterEnsureThreadError,
407 ProviderAdapterReadThreadSnapshotError,
408 ProviderAdapterRollbackThreadError,
409 ProviderAdapterForkThreadError,
410 ProviderAdapterTurnStartError,
411 ProviderAdapterSteerRunUnsupportedError,
412 ProviderAdapterSteerRunError,
413 ProviderAdapterInterruptError,
414 ProviderAdapterInterruptTimeoutError,
415 ProviderAdapterRuntimeRequestResponseError,
416 ProviderAdapterEventStreamError,
417 ProviderAdapterProtocolError,
418]);
419export type ProviderAdapterV2Error = typeof ProviderAdapterV2Error.Type;
420
421export interface ProviderAdapterV2OpenSessionInput {
422 readonly threadId: ThreadId;
423 readonly providerSessionId: ProviderSessionId;
424 readonly modelSelection: ModelSelection;
425 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
426 readonly resumeFromSession?: OrchestrationV2ProviderSession;
427 readonly initialNativeThreadId?: string;
428 readonly initialProviderItemIdentityVersion?: 2;
429}
430
431export interface ProviderAdapterV2EnsureThreadInput {
432 readonly threadId: ThreadId;
433 readonly title?: string;
434 readonly modelSelection: ModelSelection;
435 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
436 readonly providerSessionId?: ProviderSessionId;
437 readonly existingProviderThread?: OrchestrationV2ProviderThread;
438 readonly forceNewNativeThread?: boolean;
439}
440
441export interface ProviderAdapterV2TurnInput {
442 readonly appThread: OrchestrationV2AppThread;
443 readonly threadId: ThreadId;
444 readonly runId: RunId;
445 readonly runOrdinal: number;
446 readonly nativeThreadHasTurns?: boolean;
447 readonly providerTurnOrdinal: number;
448 readonly restartContinuationOfRunId?: RunId;
449 readonly attemptId: RunAttemptId;
450 readonly rootNodeId: NodeId;
451 readonly providerThread: OrchestrationV2ProviderThread;
452 readonly message: ProviderAdapterV2TurnMessage;
453 readonly modelSelection: ModelSelection;
454 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
455 readonly appContext?: ReadonlyArray<{ readonly key: string; readonly text: string }>;
456}
457
458export interface ProviderAdapterV2SteerInput {
459 readonly threadId: ThreadId;
460 readonly runId: RunId;
461 readonly providerThread: OrchestrationV2ProviderThread;
462 readonly providerTurnId: ProviderTurnId;
463 readonly message: ProviderAdapterV2TurnMessage;
464}
465
466export interface ProviderAdapterV2InterruptInput {
467 readonly providerThread: OrchestrationV2ProviderThread;
468 readonly providerTurnId: ProviderTurnId;
469 readonly requestRuntimeRestart?: boolean;
470}
471
472export interface ProviderAdapterV2RuntimeRequestResponseInput {
473 readonly requestId: RuntimeRequestId;
474 readonly decision?: ProviderApprovalDecision;
475 readonly feedback?: string;
476 readonly answers?: ProviderUserInputAnswers;
477}
478
479export interface ProviderAdapterV2ThreadSnapshot {
480 readonly providerThread: OrchestrationV2ProviderThread;
481 readonly providerTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
482 readonly messages: ReadonlyArray<OrchestrationV2ConversationMessage>;
483 readonly runtimeRequests: ReadonlyArray<OrchestrationV2RuntimeRequest>;
484 readonly providerPayload?: unknown;
485}
486
487export interface ProviderAdapterV2ReadThreadSnapshotInput {
488 readonly providerThread: OrchestrationV2ProviderThread;
489}
490
491export type ProviderAdapterV2RollbackTarget =
492 | {
493 readonly type: "thread_start";
494 readonly checkpointId: CheckpointId;
495 readonly appRunOrdinal: 0;
496 }
497 | {
498 readonly type: "provider_turn";
499 readonly checkpointId: CheckpointId;
500 readonly appRunOrdinal: number;
501 readonly providerTurn: OrchestrationV2ProviderTurn;
502 };
503
504export interface ProviderAdapterV2RollbackThreadInput {
505 readonly providerThread: OrchestrationV2ProviderThread;
506 readonly target: ProviderAdapterV2RollbackTarget;
507 readonly providerThreadTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
508}
509
510export interface ProviderAdapterV2ForkThreadInput {
511 readonly sourceProviderThread: OrchestrationV2ProviderThread;
512 readonly sourceProviderTurns?: ReadonlyArray<OrchestrationV2ProviderTurn>;
513 readonly providerTurnId?: ProviderTurnId;
514 readonly targetThreadId: ThreadId;
515 readonly ownerNodeId?: NodeId;
516 readonly modelSelection?: ModelSelection;
517 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
518}
519
520export interface ProviderAdapterV2EventSubscription {
521 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
522 readonly close: Effect.Effect<void>;
523}
524
525export interface ProviderAdapterV2HistoricalContext {
526 readonly messages: ReadonlyArray<OrchestrationV2HistoricalMessage>;
527 readonly context: string;
528}
529
530export interface ProviderAdapterV2McpTool {
531 readonly name: string;
532 readonly _meta?: unknown;
533 readonly annotations?: unknown;
534}
535
536export interface ProviderAdapterV2McpCallToolResult {
537 readonly content: ReadonlyArray<unknown>;
538 readonly structuredContent?: unknown;
539 readonly isError?: boolean;
540 readonly _meta?: unknown;
541}
542
543export interface ProviderAdapterV2McpApps {
544 readonly listTools: (input: {
545 readonly providerThread: OrchestrationV2ProviderThread;
546 readonly server: string;
547 }) => Effect.Effect<ReadonlyArray<ProviderAdapterV2McpTool>, ProviderAdapterV2Error>;
548 readonly callTool: (input: {
549 readonly providerThread: OrchestrationV2ProviderThread;
550 readonly server: string;
551 readonly tool: string;
552 readonly arguments: Record<string, unknown>;
553 }) => Effect.Effect<ProviderAdapterV2McpCallToolResult, ProviderAdapterV2Error>;
554 readonly readResource: (input: {
555 readonly providerThread: OrchestrationV2ProviderThread;
556 readonly server: string;
557 readonly uri: string;
558 }) => Effect.Effect<{ readonly contents: ReadonlyArray<unknown> }, ProviderAdapterV2Error>;
559}
560
561export type ProviderAdapterV2SubagentOutcome = {
562 readonly status: "completed" | "failed" | "cancelled";
563 readonly completedAt: NonNullable<OrchestrationV2Subagent["completedAt"]>;
564 readonly result: OrchestrationV2Subagent["result"];
565};
566
567export interface ProviderAdapterV2SessionRuntime {
568 readonly instanceId: ProviderInstanceId;
569 readonly driver: ProviderDriverKind;
570 readonly providerSessionId: ProviderSessionId;
571 readonly providerSession: OrchestrationV2ProviderSession;
572 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
573 /** Manager runtimes broadcast independent subscriptions; adapters may expose only a single-consumer stream. */
574 readonly subscribeEvents?: Effect.Effect<ProviderAdapterV2EventSubscription>;
575 readonly hasPendingBackgroundWork?: Effect.Effect<boolean>;
576 /** Root-subscription probe; replacement checks opt in to subagents owned by the live process. */
577 readonly hasPendingBackgroundWorkForThread?: (
578 providerThread: OrchestrationV2ProviderThread,
579 options?: { readonly includeSubagents?: boolean },
580 ) => Effect.Effect<boolean>;
581 /** Set only if all session background tasks end with its process; otherwise threads must keep Waiting. */
582 readonly backgroundTasksEndWithProcess?: true;
583 readonly getModelContextWindow?: (
584 modelSelection: ModelSelection,
585 cwd?: string | null,
586 ) => number | undefined;
587 readonly canReuseContextUsage?: (previous: ModelSelection, next: ModelSelection) => boolean;
588 readonly ensureThread: (
589 input: ProviderAdapterV2EnsureThreadInput,
590 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
591 readonly resumeThread: (input: {
592 readonly providerThread: OrchestrationV2ProviderThread;
593 readonly threadId?: ThreadId;
594 readonly modelSelection?: ModelSelection;
595 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
596 }) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
597 /** False means the native protocol explicitly does not support history injection. */
598 readonly injectHistory?: (
599 input: ProviderAdapterV2HistoricalContext & {
600 readonly providerThread: OrchestrationV2ProviderThread;
601 },
602 ) => Effect.Effect<boolean, ProviderAdapterV2Error>;
603 readonly startTurn: (
604 input: ProviderAdapterV2TurnInput,
605 ) => Effect.Effect<void, ProviderAdapterV2Error>;
606 readonly compactThread?: (
607 input: ProviderAdapterV2TurnInput,
608 ) => Effect.Effect<void, ProviderAdapterV2Error>;
609 readonly steerTurn: (
610 input: ProviderAdapterV2SteerInput,
611 ) => Effect.Effect<void, ProviderAdapterV2Error>;
612 readonly stopTask?: (input: {
613 readonly providerThread: OrchestrationV2ProviderThread;
614 readonly taskId: string;
615 }) => Effect.Effect<void, ProviderAdapterV2Error>;
616 /**
617 * Marks or unmarks background tasks the agent will resume from, using the ids the agent saw.
618 * Ids not running on this provider thread come back unmatched and change nothing.
619 */
620 readonly awaitBackgroundTasks?: (input: {
621 readonly providerThread: OrchestrationV2ProviderThread;
622 readonly taskIds: ReadonlyArray<string>;
623 readonly awaited: boolean;
624 }) => Effect.Effect<{ readonly matched: ReadonlyArray<string> }, ProviderAdapterV2Error>;
625 readonly interruptTurn: (
626 input: ProviderAdapterV2InterruptInput,
627 ) => Effect.Effect<void, ProviderAdapterV2Error>;
628 readonly stopSubagent?: (input: {
629 readonly providerThread: OrchestrationV2ProviderThread;
630 readonly nativeTaskId: string;
631 /** A delayed Stop must not interrupt a task resumed after this request. */
632 readonly requestedAt?: NonNullable<OrchestrationV2Subagent["startedAt"]>;
633 }) => Effect.Effect<void | ProviderAdapterV2SubagentOutcome, ProviderAdapterV2Error>;
634 readonly unloadThread?: (input: {
635 readonly providerThread: OrchestrationV2ProviderThread;
636 }) => Effect.Effect<void, ProviderAdapterV2Error>;
637 readonly respondToRuntimeRequest: (
638 input: ProviderAdapterV2RuntimeRequestResponseInput,
639 ) => Effect.Effect<void, ProviderAdapterV2Error>;
640 readonly readThreadSnapshot: (
641 input: ProviderAdapterV2ReadThreadSnapshotInput,
642 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
643 readonly uploadFeedback?: (input: {
644 readonly providerThread: OrchestrationV2ProviderThread;
645 readonly reason?: string;
646 }) => Effect.Effect<{ readonly feedbackId: string }, ProviderAdapterV2Error>;
647 /** Absent means non-interactive apps with plain tool rows. */
648 readonly mcpApps?: ProviderAdapterV2McpApps;
649 readonly rollbackThread: (
650 input: ProviderAdapterV2RollbackThreadInput,
651 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
652 readonly forkThread: (
653 input: ProviderAdapterV2ForkThreadInput,
654 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
655}
656
657export class ProviderAdapterV2 extends Context.Service<
658 ProviderAdapterV2,
659 {
660 readonly instanceId: ProviderInstanceId;
661 readonly driver: ProviderDriverKind;
662 readonly getCapabilities: () => Effect.Effect<
663 OrchestrationV2ProviderCapabilities,
664 ProviderAdapterV2Error
665 >;
666 readonly planSelectionTransition: (
667 input: ProviderSelectionTransitionInput,
668 ) => Effect.Effect<ProviderSelectionTransitionPlan, ProviderAdapterV2Error>;
669 readonly openSession: (
670 input: ProviderAdapterV2OpenSessionInput,
671 ) => Effect.Effect<ProviderAdapterV2SessionRuntime, ProviderAdapterV2Error, Scope.Scope>;
672 }
673>()("@t3tools/provider-core/server/ProviderAdapter/ProviderAdapterV2") {}