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

ProviderAdapter.ts

645 lines22.8 KB

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} from "@t3tools/contracts";
36import * as Context from "effect/Context";
37import * as Schema from "effect/Schema";
38import type * as Effect from "effect/Effect";
39import type * as Scope from "effect/Scope";
40import type * as Stream from "effect/Stream";
41​
42import type {
43 ProviderSelectionTransitionInput,
44 ProviderSelectionTransitionPlan,
45} from "./ProviderSelectionTransition.ts";
46​
47export const ProviderAdapterV2RuntimePolicy = Schema.Struct({
48 runtimeMode: RuntimeMode,
49 interactionMode: ProviderInteractionMode,
50 cwd: Schema.NullOr(Schema.String),
51 approvalPolicy: Schema.optional(Schema.Unknown),
52 sandboxPolicy: Schema.optional(Schema.Unknown),
53 reasoningEffort: Schema.optional(Schema.String),
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 }),
84 Schema.Struct({
85 type: Schema.Literal("provider_session.updated"),
86 driver: ProviderDriverKind,
87 providerSession: OrchestrationV2ProviderSession,
88 }),
89 Schema.Struct({
90 type: Schema.Literal("provider_thread.updated"),
91 driver: ProviderDriverKind,
92 providerThread: OrchestrationV2ProviderThread,
93 }),
94 Schema.Struct({
95 type: Schema.Literal("provider_turn.updated"),
96 driver: ProviderDriverKind,
97 threadId: Schema.optional(ThreadId),
98 providerTurn: OrchestrationV2ProviderTurn,
99 }),
100 Schema.Struct({
101 type: Schema.Literal("node.updated"),
102 driver: ProviderDriverKind,
103 node: OrchestrationV2ExecutionNode,
104 }),
105 Schema.Struct({
106 type: Schema.Literal("subagent.updated"),
107 driver: ProviderDriverKind,
108 subagent: OrchestrationV2Subagent,
109 }),
110 Schema.Struct({
111 type: Schema.Literal("message.updated"),
112 driver: ProviderDriverKind,
113 message: OrchestrationV2ConversationMessage,
114 }),
115 Schema.Struct({
116 type: Schema.Literal("turn_item.updated"),
117 driver: ProviderDriverKind,
118 turnItem: OrchestrationV2TurnItem,
119 }),
120 Schema.Struct({
121 type: Schema.Literal("runtime_request.updated"),
122 driver: ProviderDriverKind,
123 threadId: Schema.optional(ThreadId),
124 runtimeRequest: OrchestrationV2RuntimeRequest,
125 }),
126 Schema.Struct({
127 type: Schema.Literal("plan.updated"),
128 driver: ProviderDriverKind,
129 plan: OrchestrationV2PlanArtifact,
130 }),
131 Schema.Struct({
132 type: Schema.Literal("turn.terminal"),
133 driver: ProviderDriverKind,
134 providerThreadId: ProviderThreadId,
135 providerTurnId: ProviderTurnId,
136 runOrdinal: PositiveInt,
137 status: Schema.Literals(["completed", "interrupted", "cancelled"]),
138 failure: Schema.Null,
139 threadDisposition: Schema.Literals(["reusable", "broken"]),
140 }),
141 Schema.Struct({
142 type: Schema.Literal("turn.terminal"),
143 driver: ProviderDriverKind,
144 providerThreadId: ProviderThreadId,
145 providerTurnId: ProviderTurnId,
146 runOrdinal: PositiveInt,
147 failureItemOrdinal: PositiveInt,
148 status: Schema.Literal("failed"),
149 failure: OrchestrationV2ProviderFailure,
150 retry: Schema.optional(OrchestrationV2ProviderRetry),
151 retryStartedAt: Schema.optional(Schema.DateTimeUtc),
152 threadDisposition: Schema.Literals(["reusable", "broken"]),
153 }),
154]);
155export type ProviderAdapterV2Event = typeof ProviderAdapterV2Event.Type;
156​
157export class ProviderAdapterCapabilitiesError extends Schema.TaggedError<ProviderAdapterCapabilitiesError>()(
158 "ProviderAdapterCapabilitiesError",
159 {
160 driver: ProviderDriverKind,
161 cause: Schema.optional(Schema.Defect()),
162 },
163) {
164 override get message(): string {
165 return `Failed to read ${this.driver} provider capabilities.`;
166 }
168​
169export class ProviderAdapterOpenSessionError extends Schema.TaggedError<ProviderAdapterOpenSessionError>()(
170 "ProviderAdapterOpenSessionError",
171 {
172 driver: ProviderDriverKind,
173 providerSessionId: ProviderSessionId,
174 cause: Schema.optional(Schema.Defect()),
175 },
176) {
177 override get message(): string {
178 return `Failed to open ${this.driver} provider session ${this.providerSessionId}.`;
179 }
181​
182export class ProviderAdapterCloseSessionError extends Schema.TaggedError<ProviderAdapterCloseSessionError>()(
183 "ProviderAdapterCloseSessionError",
184 {
185 driver: ProviderDriverKind,
186 providerSessionId: ProviderSessionId,
187 cause: Schema.optional(Schema.Defect()),
188 },
189) {
190 override get message(): string {
191 return `Failed to close ${this.driver} provider session ${this.providerSessionId}.`;
192 }
194​
195export class ProviderAdapterResumeThreadError extends Schema.TaggedError<ProviderAdapterResumeThreadError>()(
196 "ProviderAdapterResumeThreadError",
197 {
198 driver: ProviderDriverKind,
199 providerSessionId: ProviderSessionId,
200 providerThreadId: ProviderThreadId,
201 cause: Schema.optional(Schema.Defect()),
202 },
203) {
204 override get message(): string {
205 return `Failed to resume ${this.driver} provider thread ${this.providerThreadId}.`;
206 }
208​
209export class ProviderAdapterEnsureThreadError extends Schema.TaggedError<ProviderAdapterEnsureThreadError>()(
210 "ProviderAdapterEnsureThreadError",
211 {
212 driver: ProviderDriverKind,
213 threadId: ThreadId,
214 cause: Schema.optional(Schema.Defect()),
215 },
216) {
217 override get message(): string {
218 return `Failed to ensure ${this.driver} provider thread for app thread ${this.threadId}.`;
219 }
221​
222export class ProviderAdapterReadThreadSnapshotError extends Schema.TaggedError<ProviderAdapterReadThreadSnapshotError>()(
223 "ProviderAdapterReadThreadSnapshotError",
224 {
225 driver: ProviderDriverKind,
226 providerThreadId: ProviderThreadId,
227 cause: Schema.optional(Schema.Defect()),
228 },
229) {
230 override get message(): string {
231 return `Failed to read ${this.driver} provider thread snapshot ${this.providerThreadId}.`;
232 }
234​
235export class ProviderAdapterRollbackThreadError extends Schema.TaggedError<ProviderAdapterRollbackThreadError>()(
236 "ProviderAdapterRollbackThreadError",
237 {
238 driver: ProviderDriverKind,
239 providerThreadId: ProviderThreadId,
240 checkpointId: Schema.optional(CheckpointId),
241 cause: Schema.optional(Schema.Defect()),
242 },
243) {
244 override get message(): string {
245 return `Failed to roll back ${this.driver} provider thread ${this.providerThreadId}.`;
246 }
248​
249export class ProviderAdapterForkThreadError extends Schema.TaggedError<ProviderAdapterForkThreadError>()(
250 "ProviderAdapterForkThreadError",
251 {
252 driver: ProviderDriverKind,
253 providerThreadId: ProviderThreadId,
254 cause: Schema.optional(Schema.Defect()),
255 },
256) {
257 override get message(): string {
258 return `Failed to fork ${this.driver} provider thread ${this.providerThreadId}.`;
259 }
261​
262export class ProviderAdapterTurnStartError extends Schema.TaggedError<ProviderAdapterTurnStartError>()(
263 "ProviderAdapterTurnStartError",
264 {
265 driver: ProviderDriverKind,
266 threadId: ThreadId,
267 providerThreadId: ProviderThreadId,
268 runId: RunId,
269 cause: Schema.optional(Schema.Defect()),
270 },
271) {
272 override get message(): string {
273 return `Failed to start run ${this.runId} on ${this.driver} provider thread ${this.providerThreadId}.`;
274 }
276​
277export class ProviderAdapterSteerRunUnsupportedError extends Schema.TaggedError<ProviderAdapterSteerRunUnsupportedError>()(
278 "ProviderAdapterSteerRunUnsupportedError",
279 {
280 driver: ProviderDriverKind,
281 providerThreadId: ProviderThreadId,
282 },
283) {
284 override get message(): string {
285 return `${this.driver} provider thread ${this.providerThreadId} does not support active-run steering.`;
286 }
288​
289export class ProviderAdapterSteerRunError extends Schema.TaggedError<ProviderAdapterSteerRunError>()(
290 "ProviderAdapterSteerRunError",
291 {
292 driver: ProviderDriverKind,
293 providerThreadId: ProviderThreadId,
294 providerTurnId: ProviderTurnId,
295 cause: Schema.optional(Schema.Defect()),
296 },
297) {
298 override get message(): string {
299 return `Failed to steer active run ${this.providerTurnId} on ${this.driver} provider thread ${this.providerThreadId}.`;
300 }
302​
303export class ProviderAdapterInterruptError extends Schema.TaggedError<ProviderAdapterInterruptError>()(
304 "ProviderAdapterInterruptError",
305 {
306 driver: ProviderDriverKind,
307 providerThreadId: ProviderThreadId,
308 providerTurnId: ProviderTurnId,
309 cause: Schema.optional(Schema.Defect()),
310 },
311) {
312 override get message(): string {
313 return `Failed to interrupt ${this.driver} provider turn ${this.providerTurnId}.`;
314 }
316​
317export class ProviderAdapterRuntimeRequestResponseError extends Schema.TaggedError<ProviderAdapterRuntimeRequestResponseError>()(
318 "ProviderAdapterRuntimeRequestResponseError",
319 {
320 driver: ProviderDriverKind,
321 requestId: RuntimeRequestId,
322 cause: Schema.optional(Schema.Defect()),
323 },
324) {
325 override get message(): string {
326 return `Failed to respond to ${this.driver} runtime request ${this.requestId}.`;
327 }
329​
330export class ProviderAdapterEventStreamError extends Schema.TaggedError<ProviderAdapterEventStreamError>()(
331 "ProviderAdapterEventStreamError",
332 {
333 driver: ProviderDriverKind,
334 providerSessionId: ProviderSessionId,
335 cause: Schema.optional(Schema.Defect()),
336 },
337) {
338 override get message(): string {
339 return `Failed while streaming ${this.driver} provider session ${this.providerSessionId} events.`;
340 }
342​
343export class ProviderAdapterProtocolError extends Schema.TaggedError<ProviderAdapterProtocolError>()(
344 "ProviderAdapterProtocolError",
345 {
346 driver: ProviderDriverKind,
347 detail: Schema.String,
348 cause: Schema.optional(Schema.Defect()),
349 payload: Schema.optional(Schema.Unknown),
350 },
351) {
352 override get message(): string {
353 return `${this.driver} provider protocol error: ${this.detail}.`;
354 }
356​
357export const ProviderAdapterV2Error = Schema.Union([
358 ProviderAdapterCapabilitiesError,
359 ProviderAdapterOpenSessionError,
360 ProviderAdapterCloseSessionError,
361 ProviderAdapterResumeThreadError,
362 ProviderAdapterEnsureThreadError,
363 ProviderAdapterReadThreadSnapshotError,
364 ProviderAdapterRollbackThreadError,
365 ProviderAdapterForkThreadError,
366 ProviderAdapterTurnStartError,
367 ProviderAdapterSteerRunUnsupportedError,
368 ProviderAdapterSteerRunError,
369 ProviderAdapterInterruptError,
370 ProviderAdapterRuntimeRequestResponseError,
371 ProviderAdapterEventStreamError,
372 ProviderAdapterProtocolError,
373]);
374export type ProviderAdapterV2Error = typeof ProviderAdapterV2Error.Type;
375​
376export interface ProviderAdapterV2OpenSessionInput {
377 readonly threadId: ThreadId;
378 readonly providerSessionId: ProviderSessionId;
379 readonly modelSelection: ModelSelection;
380 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
381 readonly resumeFromSession?: OrchestrationV2ProviderSession;
382 /** Native thread to activate while an eager adapter opens its provider process. */
383 readonly initialNativeThreadId?: string;
384 /** Preserves provider item identity across eager activation of a persisted thread. */
385 readonly initialProviderItemIdentityVersion?: 2;
387​
388export interface ProviderAdapterV2EnsureThreadInput {
389 readonly threadId: ThreadId;
390 readonly modelSelection: ModelSelection;
391 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
392 readonly providerSessionId?: ProviderSessionId;
393 readonly existingProviderThread?: OrchestrationV2ProviderThread;
395​
396export interface ProviderAdapterV2TurnInput {
397 readonly appThread: OrchestrationV2AppThread;
398 readonly threadId: ThreadId;
399 readonly runId: RunId;
400 readonly runOrdinal: number;
401 /** Whether the current native session has an accepted turn; omitted when unknown. */
402 readonly nativeThreadHasTurns?: boolean;
403 readonly providerTurnOrdinal: number;
404 readonly restartContinuationOfRunId?: RunId;
405 readonly attemptId: RunAttemptId;
406 readonly rootNodeId: NodeId;
407 readonly providerThread: OrchestrationV2ProviderThread;
408 readonly message: ProviderAdapterV2TurnMessage;
409 readonly modelSelection: ModelSelection;
410 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
411 /**
412 * What the thread's MCP Apps want the agent to know (`ui/update-model-context`),
413 * latest per app, keyed stably per app. Adapters that host apps deliver it as
414 * application context; others never receive any.
415 */
416 readonly appContext?: ReadonlyArray<{ readonly key: string; readonly text: string }>;
418​
419export interface ProviderAdapterV2SteerInput {
420 readonly threadId: ThreadId;
421 readonly runId: RunId;
422 readonly providerThread: OrchestrationV2ProviderThread;
423 readonly providerTurnId: ProviderTurnId;
424 readonly message: ProviderAdapterV2TurnMessage;
426​
427export interface ProviderAdapterV2InterruptInput {
428 readonly providerThread: OrchestrationV2ProviderThread;
429 readonly providerTurnId: ProviderTurnId;
430 /** When true, the next `startTurn` may respawn the provider runtime (Grok Stop recovery). */
431 readonly requestRuntimeRestart?: boolean;
433​
434export interface ProviderAdapterV2RuntimeRequestResponseInput {
435 readonly requestId: RuntimeRequestId;
436 readonly decision?: ProviderApprovalDecision;
437 readonly answers?: ProviderUserInputAnswers;
438 readonly response?: unknown;
440​
441export interface ProviderAdapterV2ThreadSnapshot {
442 readonly providerThread: OrchestrationV2ProviderThread;
443 readonly providerTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
444 readonly messages: ReadonlyArray<OrchestrationV2ConversationMessage>;
445 readonly runtimeRequests: ReadonlyArray<OrchestrationV2RuntimeRequest>;
446 readonly providerPayload?: unknown;
448​
449export interface ProviderAdapterV2ReadThreadSnapshotInput {
450 readonly providerThread: OrchestrationV2ProviderThread;
452​
453export type ProviderAdapterV2RollbackTarget =
454 | {
455 readonly type: "thread_start";
456 readonly checkpointId: CheckpointId;
457 readonly appRunOrdinal: 0;
458 }
459 | {
460 readonly type: "provider_turn";
461 readonly checkpointId: CheckpointId;
462 readonly appRunOrdinal: number;
463 readonly providerTurn: OrchestrationV2ProviderTurn;
464 };
465​
466export interface ProviderAdapterV2RollbackThreadInput {
467 readonly providerThread: OrchestrationV2ProviderThread;
468 readonly target: ProviderAdapterV2RollbackTarget;
469 readonly providerThreadTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
471​
472export interface ProviderAdapterV2ForkThreadInput {
473 readonly sourceProviderThread: OrchestrationV2ProviderThread;
474 readonly sourceProviderTurns?: ReadonlyArray<OrchestrationV2ProviderTurn>;
475 readonly providerTurnId?: ProviderTurnId;
476 readonly targetThreadId: ThreadId;
477 readonly ownerNodeId?: NodeId;
478 readonly modelSelection?: ModelSelection;
479 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
481​
482export interface ProviderAdapterV2EventSubscription {
483 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
484 readonly close: Effect.Effect<void>;
486​
487export interface ProviderAdapterV2HistoricalContext {
488 readonly messages: ReadonlyArray<OrchestrationV2HistoricalMessage>;
489 readonly context: string;
491​
492/** An MCP tool as the provider's MCP client lists it. */
493export interface ProviderAdapterV2McpTool {
494 readonly name: string;
495 readonly _meta?: unknown;
496 readonly annotations?: unknown;
498​
499/** MCP `CallToolResult` / `ReadResourceResult` shapes, passed through unchanged. */
500export interface ProviderAdapterV2McpCallToolResult {
501 readonly content: ReadonlyArray<unknown>;
502 readonly structuredContent?: unknown;
503 readonly isError?: boolean;
504 readonly _meta?: unknown;
506​
507export interface ProviderAdapterV2McpApps {
508 readonly listTools: (input: {
509 readonly providerThread: OrchestrationV2ProviderThread;
510 readonly server: string;
511 }) => Effect.Effect<ReadonlyArray<ProviderAdapterV2McpTool>, ProviderAdapterV2Error>;
512 readonly callTool: (input: {
513 readonly providerThread: OrchestrationV2ProviderThread;
514 readonly server: string;
515 readonly tool: string;
516 readonly arguments: Record<string, unknown>;
517 }) => Effect.Effect<ProviderAdapterV2McpCallToolResult, ProviderAdapterV2Error>;
518 readonly readResource: (input: {
519 readonly providerThread: OrchestrationV2ProviderThread;
520 readonly server: string;
521 readonly uri: string;
522 }) => Effect.Effect<{ readonly contents: ReadonlyArray<unknown> }, ProviderAdapterV2Error>;
524​
525export interface ProviderAdapterV2SessionRuntime {
526 readonly instanceId: ProviderInstanceId;
527 readonly driver: ProviderDriverKind;
528 readonly providerSessionId: ProviderSessionId;
529 readonly providerSession: OrchestrationV2ProviderSession;
530 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
531 /**
532 * Manager-owned runtimes expose a synchronous subscription so concurrent
533 * provider threads receive independent copies of the process event stream.
534 * Adapter runtimes may omit this and expose only their single-consumer event stream.
535 */
536 readonly subscribeEvents?: Effect.Effect<ProviderAdapterV2EventSubscription>;
537 /**
538 * Adapters whose native runtime can hold pending work outside an active
539 * turn (for example Claude background tasks and their wake turns) report it
540 * here so the session manager defers idle release while it is pending.
541 */
542 readonly hasPendingBackgroundWork?: Effect.Effect<boolean>;
543 /**
544 * Per-provider-thread pending work for root-run ingestion stop gates. When
545 * present, RunExecutionService uses only this probe (never the session-wide
546 * hasPendingBackgroundWork) so sibling native threads cannot pin an
547 * unrelated root subscription open.
548 */
549 readonly hasPendingBackgroundWorkForThread?: (
550 providerThread: OrchestrationV2ProviderThread,
551 ) => Effect.Effect<boolean>;
552 /**
553 * Capacity for the requested model/options, independent of native thread usage.
554 * `cwd` is the thread's working directory, for providers whose project config
555 * can change a model's limits.
556 */
557 readonly getModelContextWindow?: (
558 modelSelection: ModelSelection,
559 cwd?: string | null,
560 ) => number | undefined;
561 /** Whether an option-only change preserves measured native usage and capacity.
562 * Compaction thresholds are still discarded. Unknown transitions invalidate usage.
563 */
564 readonly canReuseContextUsage?: (previous: ModelSelection, next: ModelSelection) => boolean;
565 readonly ensureThread: (
566 input: ProviderAdapterV2EnsureThreadInput,
567 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
568 readonly resumeThread: (input: {
569 readonly providerThread: OrchestrationV2ProviderThread;
570 readonly threadId?: ThreadId;
571 readonly modelSelection?: ModelSelection;
572 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
573 }) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
574 /** False means the native protocol explicitly does not support history injection. */
575 readonly injectHistory?: (
576 input: ProviderAdapterV2HistoricalContext & {
577 readonly providerThread: OrchestrationV2ProviderThread;
578 },
579 ) => Effect.Effect<boolean, ProviderAdapterV2Error>;
580 readonly startTurn: (
581 input: ProviderAdapterV2TurnInput,
582 ) => Effect.Effect<void, ProviderAdapterV2Error>;
583 readonly compactThread?: (
584 input: ProviderAdapterV2TurnInput,
585 ) => Effect.Effect<void, ProviderAdapterV2Error>;
586 readonly steerTurn: (
587 input: ProviderAdapterV2SteerInput,
588 ) => Effect.Effect<void, ProviderAdapterV2Error>;
589 readonly interruptTurn: (
590 input: ProviderAdapterV2InterruptInput,
591 ) => Effect.Effect<void, ProviderAdapterV2Error>;
592 /**
593 * Lets a runtime shared by several app threads unload one provider thread's
594 * native state (and its MCP servers) when that app thread detaches, while
595 * the runtime keeps serving the others. A later resume reloads it.
596 */
597 readonly unloadThread?: (input: {
598 readonly providerThread: OrchestrationV2ProviderThread;
599 }) => Effect.Effect<void, ProviderAdapterV2Error>;
600 readonly respondToRuntimeRequest: (
601 input: ProviderAdapterV2RuntimeRequestResponseInput,
602 ) => Effect.Effect<void, ProviderAdapterV2Error>;
603 readonly readThreadSnapshot: (
604 input: ProviderAdapterV2ReadThreadSnapshotInput,
605 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
606 /**
607 * Providers that accept product feedback for a thread (#7949, Codex → OpenAI)
608 * expose it here; absent means the driver has no feedback channel.
609 */
610 readonly uploadFeedback?: (input: {
611 readonly providerThread: OrchestrationV2ProviderThread;
612 readonly reason?: string;
613 }) => Effect.Effect<{ readonly feedbackId: string }, ProviderAdapterV2Error>;
614 /**
615 * MCP Apps host operations through the provider's own MCP client, for
616 * drivers whose protocol exposes them (Codex). Absent means apps from this
617 * provider are not interactive and their tool calls stay plain tool rows.
618 */
619 readonly mcpApps?: ProviderAdapterV2McpApps;
620 readonly rollbackThread: (
621 input: ProviderAdapterV2RollbackThreadInput,
622 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
623 readonly forkThread: (
624 input: ProviderAdapterV2ForkThreadInput,
625 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
627​
628export interface ProviderAdapterV2Shape {
629 readonly instanceId: ProviderInstanceId;
630 readonly driver: ProviderDriverKind;
631 readonly getCapabilities: () => Effect.Effect<
632 OrchestrationV2ProviderCapabilities,
633 ProviderAdapterV2Error
634 >;
635 readonly planSelectionTransition: (
636 input: ProviderSelectionTransitionInput,
637 ) => Effect.Effect<ProviderSelectionTransitionPlan, ProviderAdapterV2Error>;
638 readonly openSession: (
639 input: ProviderAdapterV2OpenSessionInput,
640 ) => Effect.Effect<ProviderAdapterV2SessionRuntime, ProviderAdapterV2Error, Scope.Scope>;
642​
643export class ProviderAdapterV2 extends Context.Service<ProviderAdapterV2, ProviderAdapterV2Shape>()(
644 "t3/orchestration-v2/ProviderAdapter/ProviderAdapterV2",
645) {}