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

ProviderAdapter.ts

662 lines23.2 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 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 reasoningEffort: Schema.optional(Schema.String),
55});
56export type ProviderAdapterV2RuntimePolicy = typeof ProviderAdapterV2RuntimePolicy.Type;
57​
58export const ProviderAdapterV2TurnMessage = Schema.Struct({
59 messageId: MessageId,
60 text: Schema.String,
61 attachments: Schema.Array(ChatAttachment),
62 createdBy: OrchestrationV2ConversationMessage.fields.createdBy,
63 creationSource: OrchestrationV2ConversationMessage.fields.creationSource,
64 scheduledTaskId: OrchestrationV2ConversationMessage.fields.scheduledTaskId,
65 senderThreadId: OrchestrationV2ConversationMessage.fields.senderThreadId,
66});
67export type ProviderAdapterV2TurnMessage = typeof ProviderAdapterV2TurnMessage.Type;
68​
69export const ProviderAdapterV2SessionStatus = Schema.Literals([
70 "starting",
71 "ready",
72 "running",
73 "waiting",
74 "stopped",
75 "error",
76]);
77export type ProviderAdapterV2SessionStatus = typeof ProviderAdapterV2SessionStatus.Type;
78​
79export const ProviderAdapterV2Event = Schema.Union([
80 Schema.Struct({
81 type: Schema.Literal("app_thread.created"),
82 driver: ProviderDriverKind,
83 appThread: OrchestrationV2AppThread,
84 createOnly: Schema.optional(Schema.Boolean),
85 }),
86 Schema.Struct({
87 type: Schema.Literal("provider_session.updated"),
88 driver: ProviderDriverKind,
89 providerSession: OrchestrationV2ProviderSession,
90 }),
91 Schema.Struct({
92 type: Schema.Literal("provider_thread.updated"),
93 driver: ProviderDriverKind,
94 providerThread: OrchestrationV2ProviderThread,
95 retainedNativeTurnIds: Schema.optional(Schema.Array(Schema.String)),
96 }),
97 Schema.Struct({
98 type: Schema.Literal("provider_turn.updated"),
99 driver: ProviderDriverKind,
100 threadId: Schema.optional(ThreadId),
101 providerTurn: OrchestrationV2ProviderTurn,
102 }),
103 Schema.Struct({
104 type: Schema.Literal("node.updated"),
105 driver: ProviderDriverKind,
106 node: OrchestrationV2ExecutionNode,
107 }),
108 Schema.Struct({
109 type: Schema.Literal("subagent.updated"),
110 driver: ProviderDriverKind,
111 subagent: OrchestrationV2Subagent,
112 }),
113 Schema.Struct({
114 type: Schema.Literal("message.updated"),
115 driver: ProviderDriverKind,
116 message: OrchestrationV2ConversationMessage,
117 }),
118 Schema.Struct({
119 type: Schema.Literal("turn_item.updated"),
120 driver: ProviderDriverKind,
121 turnItem: OrchestrationV2TurnItem,
122 }),
123 /**
124 * Raw output from a running command. Never persisted: the session manager
125 * hands it to the command output hub, which only clients showing the row see.
126 * The item's final output still arrives in its `turn_item.updated`.
127 */
128 Schema.Struct({
129 type: Schema.Literal("command_output.delta"),
130 driver: ProviderDriverKind,
131 threadId: ThreadId,
132 itemId: TurnItemId,
133 chunk: Schema.String,
134 }),
135 Schema.Struct({
136 type: Schema.Literal("runtime_request.updated"),
137 driver: ProviderDriverKind,
138 threadId: Schema.optional(ThreadId),
139 runtimeRequest: OrchestrationV2RuntimeRequest,
140 }),
141 Schema.Struct({
142 type: Schema.Literal("plan.updated"),
143 driver: ProviderDriverKind,
144 plan: OrchestrationV2PlanArtifact,
145 }),
146 Schema.Struct({
147 type: Schema.Literal("turn.terminal"),
148 driver: ProviderDriverKind,
149 providerThreadId: ProviderThreadId,
150 providerTurnId: ProviderTurnId,
151 runOrdinal: PositiveInt,
152 status: Schema.Literals(["completed", "interrupted", "cancelled"]),
153 failure: Schema.Null,
154 threadDisposition: Schema.Literals(["reusable", "broken"]),
155 }),
156 Schema.Struct({
157 type: Schema.Literal("turn.terminal"),
158 driver: ProviderDriverKind,
159 providerThreadId: ProviderThreadId,
160 providerTurnId: ProviderTurnId,
161 runOrdinal: PositiveInt,
162 failureItemOrdinal: PositiveInt,
163 status: Schema.Literal("failed"),
164 failure: OrchestrationV2ProviderFailure,
165 retry: Schema.optional(OrchestrationV2ProviderRetry),
166 retryStartedAt: Schema.optional(Schema.DateTimeUtc),
167 threadDisposition: Schema.Literals(["reusable", "broken"]),
168 /**
169 * Child turns the root started outlive its failure and will report their
170 * own terminals, as after a completed root. Without it, the run settles
171 * every child it still sees as open.
172 */
173 childTurnsContinue: Schema.optional(Schema.Literal(true)),
174 }),
175]);
176export type ProviderAdapterV2Event = typeof ProviderAdapterV2Event.Type;
177​
178export class ProviderAdapterCapabilitiesError extends Schema.TaggedError<ProviderAdapterCapabilitiesError>()(
179 "ProviderAdapterCapabilitiesError",
180 {
181 driver: ProviderDriverKind,
182 cause: Schema.optional(Schema.Defect()),
183 },
184) {
185 override get message(): string {
186 return `Failed to read ${this.driver} provider capabilities.`;
187 }
189​
190export class ProviderAdapterOpenSessionError extends Schema.TaggedError<ProviderAdapterOpenSessionError>()(
191 "ProviderAdapterOpenSessionError",
192 {
193 driver: ProviderDriverKind,
194 providerSessionId: ProviderSessionId,
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
337​
338export class ProviderAdapterRuntimeRequestResponseError extends Schema.TaggedError<ProviderAdapterRuntimeRequestResponseError>()(
339 "ProviderAdapterRuntimeRequestResponseError",
340 {
341 driver: ProviderDriverKind,
342 requestId: RuntimeRequestId,
343 cause: Schema.optional(Schema.Defect()),
344 },
345) {
346 override get message(): string {
347 return `Failed to respond to ${this.driver} runtime request ${this.requestId}.`;
348 }
350​
351export class ProviderAdapterEventStreamError extends Schema.TaggedError<ProviderAdapterEventStreamError>()(
352 "ProviderAdapterEventStreamError",
353 {
354 driver: ProviderDriverKind,
355 providerSessionId: ProviderSessionId,
356 cause: Schema.optional(Schema.Defect()),
357 },
358) {
359 override get message(): string {
360 return `Failed while streaming ${this.driver} provider session ${this.providerSessionId} events.`;
361 }
363​
364// Only fixed reasons reach failure messages; detail can contain private configuration.
365const ProviderAdapterFailureReason = Schema.Literals([
366 "previous_turn_active",
367 "attachment_unreadable",
368]);
369export type ProviderAdapterFailureReason = typeof ProviderAdapterFailureReason.Type;
370​
371export class ProviderAdapterProtocolError extends Schema.TaggedError<ProviderAdapterProtocolError>()(
372 "ProviderAdapterProtocolError",
373 {
374 driver: ProviderDriverKind,
375 detail: Schema.String,
376 reason: Schema.optional(ProviderAdapterFailureReason),
377 cause: Schema.optional(Schema.Defect()),
378 payload: Schema.optional(Schema.Unknown),
379 },
380) {
381 override get message(): string {
382 return `${this.driver} provider protocol error: ${this.detail}.`;
383 }
385​
386export const ProviderAdapterV2Error = Schema.Union([
387 ProviderAdapterCapabilitiesError,
388 ProviderAdapterOpenSessionError,
389 ProviderAdapterCloseSessionError,
390 ProviderAdapterResumeThreadError,
391 ProviderAdapterEnsureThreadError,
392 ProviderAdapterReadThreadSnapshotError,
393 ProviderAdapterRollbackThreadError,
394 ProviderAdapterForkThreadError,
395 ProviderAdapterTurnStartError,
396 ProviderAdapterSteerRunUnsupportedError,
397 ProviderAdapterSteerRunError,
398 ProviderAdapterInterruptError,
399 ProviderAdapterRuntimeRequestResponseError,
400 ProviderAdapterEventStreamError,
401 ProviderAdapterProtocolError,
402]);
403export type ProviderAdapterV2Error = typeof ProviderAdapterV2Error.Type;
404​
405export interface ProviderAdapterV2OpenSessionInput {
406 readonly threadId: ThreadId;
407 readonly providerSessionId: ProviderSessionId;
408 readonly modelSelection: ModelSelection;
409 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
410 readonly resumeFromSession?: OrchestrationV2ProviderSession;
411 readonly initialNativeThreadId?: string;
412 readonly initialProviderItemIdentityVersion?: 2;
414​
415export interface ProviderAdapterV2EnsureThreadInput {
416 readonly threadId: ThreadId;
417 readonly title?: string;
418 readonly modelSelection: ModelSelection;
419 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
420 readonly providerSessionId?: ProviderSessionId;
421 readonly existingProviderThread?: OrchestrationV2ProviderThread;
423​
424export interface ProviderAdapterV2TurnInput {
425 readonly appThread: OrchestrationV2AppThread;
426 readonly threadId: ThreadId;
427 readonly runId: RunId;
428 readonly runOrdinal: number;
429 readonly nativeThreadHasTurns?: boolean;
430 readonly providerTurnOrdinal: number;
431 readonly restartContinuationOfRunId?: RunId;
432 readonly attemptId: RunAttemptId;
433 readonly rootNodeId: NodeId;
434 readonly providerThread: OrchestrationV2ProviderThread;
435 readonly message: ProviderAdapterV2TurnMessage;
436 readonly modelSelection: ModelSelection;
437 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
438 readonly appContext?: ReadonlyArray<{ readonly key: string; readonly text: string }>;
440​
441export interface ProviderAdapterV2SteerInput {
442 readonly threadId: ThreadId;
443 readonly runId: RunId;
444 readonly providerThread: OrchestrationV2ProviderThread;
445 readonly providerTurnId: ProviderTurnId;
446 readonly message: ProviderAdapterV2TurnMessage;
448​
449export interface ProviderAdapterV2InterruptInput {
450 readonly providerThread: OrchestrationV2ProviderThread;
451 readonly providerTurnId: ProviderTurnId;
452 readonly requestRuntimeRestart?: boolean;
454​
455export interface ProviderAdapterV2RuntimeRequestResponseInput {
456 readonly requestId: RuntimeRequestId;
457 readonly decision?: ProviderApprovalDecision;
458 readonly answers?: ProviderUserInputAnswers;
459 readonly response?: unknown;
461​
462export interface ProviderAdapterV2ThreadSnapshot {
463 readonly providerThread: OrchestrationV2ProviderThread;
464 readonly providerTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
465 readonly messages: ReadonlyArray<OrchestrationV2ConversationMessage>;
466 readonly runtimeRequests: ReadonlyArray<OrchestrationV2RuntimeRequest>;
467 readonly providerPayload?: unknown;
469​
470export interface ProviderAdapterV2ReadThreadSnapshotInput {
471 readonly providerThread: OrchestrationV2ProviderThread;
473​
474export type ProviderAdapterV2RollbackTarget =
475 | {
476 readonly type: "thread_start";
477 readonly checkpointId: CheckpointId;
478 readonly appRunOrdinal: 0;
479 }
480 | {
481 readonly type: "provider_turn";
482 readonly checkpointId: CheckpointId;
483 readonly appRunOrdinal: number;
484 readonly providerTurn: OrchestrationV2ProviderTurn;
485 };
486​
487export interface ProviderAdapterV2RollbackThreadInput {
488 readonly providerThread: OrchestrationV2ProviderThread;
489 readonly target: ProviderAdapterV2RollbackTarget;
490 readonly providerThreadTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
492​
493export interface ProviderAdapterV2ForkThreadInput {
494 readonly sourceProviderThread: OrchestrationV2ProviderThread;
495 readonly sourceProviderTurns?: ReadonlyArray<OrchestrationV2ProviderTurn>;
496 readonly providerTurnId?: ProviderTurnId;
497 readonly targetThreadId: ThreadId;
498 readonly ownerNodeId?: NodeId;
499 readonly modelSelection?: ModelSelection;
500 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
502​
503export interface ProviderAdapterV2EventSubscription {
504 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
505 readonly close: Effect.Effect<void>;
507​
508export interface ProviderAdapterV2HistoricalContext {
509 readonly messages: ReadonlyArray<OrchestrationV2HistoricalMessage>;
510 readonly context: string;
512​
513export interface ProviderAdapterV2McpTool {
514 readonly name: string;
515 readonly _meta?: unknown;
516 readonly annotations?: unknown;
518​
519export interface ProviderAdapterV2McpCallToolResult {
520 readonly content: ReadonlyArray<unknown>;
521 readonly structuredContent?: unknown;
522 readonly isError?: boolean;
523 readonly _meta?: unknown;
525​
526export interface ProviderAdapterV2McpApps {
527 readonly listTools: (input: {
528 readonly providerThread: OrchestrationV2ProviderThread;
529 readonly server: string;
530 }) => Effect.Effect<ReadonlyArray<ProviderAdapterV2McpTool>, ProviderAdapterV2Error>;
531 readonly callTool: (input: {
532 readonly providerThread: OrchestrationV2ProviderThread;
533 readonly server: string;
534 readonly tool: string;
535 readonly arguments: Record<string, unknown>;
536 }) => Effect.Effect<ProviderAdapterV2McpCallToolResult, ProviderAdapterV2Error>;
537 readonly readResource: (input: {
538 readonly providerThread: OrchestrationV2ProviderThread;
539 readonly server: string;
540 readonly uri: string;
541 }) => Effect.Effect<{ readonly contents: ReadonlyArray<unknown> }, ProviderAdapterV2Error>;
543​
544export type ProviderAdapterV2SubagentOutcome = {
545 readonly status: "completed" | "failed" | "cancelled";
546 readonly completedAt: NonNullable<OrchestrationV2Subagent["completedAt"]>;
547 readonly result: OrchestrationV2Subagent["result"];
548};
549​
550export interface ProviderAdapterV2SessionRuntime {
551 readonly instanceId: ProviderInstanceId;
552 readonly driver: ProviderDriverKind;
553 readonly providerSessionId: ProviderSessionId;
554 readonly providerSession: OrchestrationV2ProviderSession;
555 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
556 /**
557 * Manager-owned runtimes expose a synchronous subscription so concurrent
558 * provider threads receive independent copies of the process event stream.
559 * Adapter runtimes may omit this and expose only their single-consumer event stream.
560 */
561 readonly subscribeEvents?: Effect.Effect<ProviderAdapterV2EventSubscription>;
562 readonly hasPendingBackgroundWork?: Effect.Effect<boolean>;
563 /**
564 * When present, RunExecutionService uses only this probe (never the
565 * session-wide hasPendingBackgroundWork) so sibling native threads cannot pin
566 * an unrelated root subscription open.
567 */
568 readonly hasPendingBackgroundWorkForThread?: (
569 providerThread: OrchestrationV2ProviderThread,
570 ) => Effect.Effect<boolean>;
571 /**
572 * Set when every background task this session lists on its provider threads
573 * runs inside the session's own process and ends when it closes. Leave unset
574 * when a task can outlive the session, for example on a shared server, so its
575 * thread keeps showing Waiting.
576 */
577 readonly backgroundTasksEndWithProcess?: true;
578 readonly getModelContextWindow?: (
579 modelSelection: ModelSelection,
580 cwd?: string | null,
581 ) => number | undefined;
582 readonly canReuseContextUsage?: (previous: ModelSelection, next: ModelSelection) => boolean;
583 readonly ensureThread: (
584 input: ProviderAdapterV2EnsureThreadInput,
585 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
586 readonly resumeThread: (input: {
587 readonly providerThread: OrchestrationV2ProviderThread;
588 readonly threadId?: ThreadId;
589 readonly modelSelection?: ModelSelection;
590 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
591 }) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
592 /** False means the native protocol explicitly does not support history injection. */
593 readonly injectHistory?: (
594 input: ProviderAdapterV2HistoricalContext & {
595 readonly providerThread: OrchestrationV2ProviderThread;
596 },
597 ) => Effect.Effect<boolean, ProviderAdapterV2Error>;
598 readonly startTurn: (
599 input: ProviderAdapterV2TurnInput,
600 ) => Effect.Effect<void, ProviderAdapterV2Error>;
601 readonly compactThread?: (
602 input: ProviderAdapterV2TurnInput,
603 ) => Effect.Effect<void, ProviderAdapterV2Error>;
604 readonly steerTurn: (
605 input: ProviderAdapterV2SteerInput,
606 ) => Effect.Effect<void, ProviderAdapterV2Error>;
607 readonly stopTask?: (input: {
608 readonly providerThread: OrchestrationV2ProviderThread;
609 readonly taskId: string;
610 }) => Effect.Effect<void, ProviderAdapterV2Error>;
611 readonly interruptTurn: (
612 input: ProviderAdapterV2InterruptInput,
613 ) => Effect.Effect<void, ProviderAdapterV2Error>;
614 readonly stopSubagent?: (input: {
615 readonly providerThread: OrchestrationV2ProviderThread;
616 readonly nativeTaskId: string;
617 /** A delayed Stop must not interrupt a task resumed after this request. */
618 readonly requestedAt?: NonNullable<OrchestrationV2Subagent["startedAt"]>;
619 }) => Effect.Effect<void | ProviderAdapterV2SubagentOutcome, ProviderAdapterV2Error>;
620 readonly unloadThread?: (input: {
621 readonly providerThread: OrchestrationV2ProviderThread;
622 }) => Effect.Effect<void, ProviderAdapterV2Error>;
623 readonly respondToRuntimeRequest: (
624 input: ProviderAdapterV2RuntimeRequestResponseInput,
625 ) => Effect.Effect<void, ProviderAdapterV2Error>;
626 readonly readThreadSnapshot: (
627 input: ProviderAdapterV2ReadThreadSnapshotInput,
628 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
629 readonly uploadFeedback?: (input: {
630 readonly providerThread: OrchestrationV2ProviderThread;
631 readonly reason?: string;
632 }) => Effect.Effect<{ readonly feedbackId: string }, ProviderAdapterV2Error>;
633 /**
634 * Absent means apps from this provider are not interactive and their tool
635 * calls stay plain tool rows.
636 */
637 readonly mcpApps?: ProviderAdapterV2McpApps;
638 readonly rollbackThread: (
639 input: ProviderAdapterV2RollbackThreadInput,
640 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
641 readonly forkThread: (
642 input: ProviderAdapterV2ForkThreadInput,
643 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
645​
646export class ProviderAdapterV2 extends Context.Service<
647 ProviderAdapterV2,
648 {
649 readonly instanceId: ProviderInstanceId;
650 readonly driver: ProviderDriverKind;
651 readonly getCapabilities: () => Effect.Effect<
652 OrchestrationV2ProviderCapabilities,
653 ProviderAdapterV2Error
654 >;
655 readonly planSelectionTransition: (
656 input: ProviderSelectionTransitionInput,
657 ) => Effect.Effect<ProviderSelectionTransitionPlan, ProviderAdapterV2Error>;
658 readonly openSession: (
659 input: ProviderAdapterV2OpenSessionInput,
660 ) => Effect.Effect<ProviderAdapterV2SessionRuntime, ProviderAdapterV2Error, Scope.Scope>;
661 }
662>()("@t3tools/provider-core/server/ProviderAdapter/ProviderAdapterV2") {}