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

ProviderAdapter.ts

653 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 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 }),
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 /**
123 * Raw output from a running command. Never persisted: the session manager
124 * hands it to the command output hub, which only clients showing the row see.
125 * The item's final output still arrives in its `turn_item.updated`.
126 */
127 Schema.Struct({
128 type: Schema.Literal("command_output.delta"),
129 driver: ProviderDriverKind,
130 threadId: ThreadId,
131 itemId: TurnItemId,
132 chunk: Schema.String,
133 }),
134 Schema.Struct({
135 type: Schema.Literal("runtime_request.updated"),
136 driver: ProviderDriverKind,
137 threadId: Schema.optional(ThreadId),
138 runtimeRequest: OrchestrationV2RuntimeRequest,
139 }),
140 Schema.Struct({
141 type: Schema.Literal("plan.updated"),
142 driver: ProviderDriverKind,
143 plan: OrchestrationV2PlanArtifact,
144 }),
145 Schema.Struct({
146 type: Schema.Literal("turn.terminal"),
147 driver: ProviderDriverKind,
148 providerThreadId: ProviderThreadId,
149 providerTurnId: ProviderTurnId,
150 runOrdinal: PositiveInt,
151 status: Schema.Literals(["completed", "interrupted", "cancelled"]),
152 failure: Schema.Null,
153 threadDisposition: Schema.Literals(["reusable", "broken"]),
154 }),
155 Schema.Struct({
156 type: Schema.Literal("turn.terminal"),
157 driver: ProviderDriverKind,
158 providerThreadId: ProviderThreadId,
159 providerTurnId: ProviderTurnId,
160 runOrdinal: PositiveInt,
161 failureItemOrdinal: PositiveInt,
162 status: Schema.Literal("failed"),
163 failure: OrchestrationV2ProviderFailure,
164 retry: Schema.optional(OrchestrationV2ProviderRetry),
165 retryStartedAt: Schema.optional(Schema.DateTimeUtc),
166 threadDisposition: Schema.Literals(["reusable", "broken"]),
167 /**
168 * Child turns the root started outlive its failure and will report their
169 * own terminals, as after a completed root. Without it, the run settles
170 * every child it still sees as open.
171 */
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 }
188​
189export class ProviderAdapterOpenSessionError extends Schema.TaggedError<ProviderAdapterOpenSessionError>()(
190 "ProviderAdapterOpenSessionError",
191 {
192 driver: ProviderDriverKind,
193 providerSessionId: ProviderSessionId,
194 cause: Schema.optional(Schema.Defect()),
195 },
196) {
197 override get message(): string {
198 return `Failed to open ${this.driver} provider session ${this.providerSessionId}.`;
199 }
201​
202export class ProviderAdapterCloseSessionError extends Schema.TaggedError<ProviderAdapterCloseSessionError>()(
203 "ProviderAdapterCloseSessionError",
204 {
205 driver: ProviderDriverKind,
206 providerSessionId: ProviderSessionId,
207 cause: Schema.optional(Schema.Defect()),
208 },
209) {
210 override get message(): string {
211 return `Failed to close ${this.driver} provider session ${this.providerSessionId}.`;
212 }
214​
215export class ProviderAdapterResumeThreadError extends Schema.TaggedError<ProviderAdapterResumeThreadError>()(
216 "ProviderAdapterResumeThreadError",
217 {
218 driver: ProviderDriverKind,
219 providerSessionId: ProviderSessionId,
220 providerThreadId: ProviderThreadId,
221 cause: Schema.optional(Schema.Defect()),
222 },
223) {
224 override get message(): string {
225 return `Failed to resume ${this.driver} provider thread ${this.providerThreadId}.`;
226 }
228​
229export class ProviderAdapterEnsureThreadError extends Schema.TaggedError<ProviderAdapterEnsureThreadError>()(
230 "ProviderAdapterEnsureThreadError",
231 {
232 driver: ProviderDriverKind,
233 threadId: ThreadId,
234 cause: Schema.optional(Schema.Defect()),
235 },
236) {
237 override get message(): string {
238 return `Failed to ensure ${this.driver} provider thread for app thread ${this.threadId}.`;
239 }
241​
242export class ProviderAdapterReadThreadSnapshotError extends Schema.TaggedError<ProviderAdapterReadThreadSnapshotError>()(
243 "ProviderAdapterReadThreadSnapshotError",
244 {
245 driver: ProviderDriverKind,
246 providerThreadId: ProviderThreadId,
247 cause: Schema.optional(Schema.Defect()),
248 },
249) {
250 override get message(): string {
251 return `Failed to read ${this.driver} provider thread snapshot ${this.providerThreadId}.`;
252 }
254​
255export class ProviderAdapterRollbackThreadError extends Schema.TaggedError<ProviderAdapterRollbackThreadError>()(
256 "ProviderAdapterRollbackThreadError",
257 {
258 driver: ProviderDriverKind,
259 providerThreadId: ProviderThreadId,
260 checkpointId: Schema.optional(CheckpointId),
261 cause: Schema.optional(Schema.Defect()),
262 },
263) {
264 override get message(): string {
265 return `Failed to roll back ${this.driver} provider thread ${this.providerThreadId}.`;
266 }
268​
269export class ProviderAdapterForkThreadError extends Schema.TaggedError<ProviderAdapterForkThreadError>()(
270 "ProviderAdapterForkThreadError",
271 {
272 driver: ProviderDriverKind,
273 providerThreadId: ProviderThreadId,
274 cause: Schema.optional(Schema.Defect()),
275 },
276) {
277 override get message(): string {
278 return `Failed to fork ${this.driver} provider thread ${this.providerThreadId}.`;
279 }
281​
282export class ProviderAdapterTurnStartError extends Schema.TaggedError<ProviderAdapterTurnStartError>()(
283 "ProviderAdapterTurnStartError",
284 {
285 driver: ProviderDriverKind,
286 threadId: ThreadId,
287 providerThreadId: ProviderThreadId,
288 runId: RunId,
289 cause: Schema.optional(Schema.Defect()),
290 },
291) {
292 override get message(): string {
293 return `Failed to start run ${this.runId} on ${this.driver} provider thread ${this.providerThreadId}.`;
294 }
296​
297export class ProviderAdapterSteerRunUnsupportedError extends Schema.TaggedError<ProviderAdapterSteerRunUnsupportedError>()(
298 "ProviderAdapterSteerRunUnsupportedError",
299 {
300 driver: ProviderDriverKind,
301 providerThreadId: ProviderThreadId,
302 },
303) {
304 override get message(): string {
305 return `${this.driver} provider thread ${this.providerThreadId} does not support active-run steering.`;
306 }
308​
309export class ProviderAdapterSteerRunError extends Schema.TaggedError<ProviderAdapterSteerRunError>()(
310 "ProviderAdapterSteerRunError",
311 {
312 driver: ProviderDriverKind,
313 providerThreadId: ProviderThreadId,
314 providerTurnId: ProviderTurnId,
315 cause: Schema.optional(Schema.Defect()),
316 },
317) {
318 override get message(): string {
319 return `Failed to steer active run ${this.providerTurnId} on ${this.driver} provider thread ${this.providerThreadId}.`;
320 }
322​
323export class ProviderAdapterInterruptError extends Schema.TaggedError<ProviderAdapterInterruptError>()(
324 "ProviderAdapterInterruptError",
325 {
326 driver: ProviderDriverKind,
327 providerThreadId: ProviderThreadId,
328 providerTurnId: ProviderTurnId,
329 cause: Schema.optional(Schema.Defect()),
330 },
331) {
332 override get message(): string {
333 return `Failed to interrupt ${this.driver} provider turn ${this.providerTurnId}.`;
334 }
336​
337export class ProviderAdapterRuntimeRequestResponseError extends Schema.TaggedError<ProviderAdapterRuntimeRequestResponseError>()(
338 "ProviderAdapterRuntimeRequestResponseError",
339 {
340 driver: ProviderDriverKind,
341 requestId: RuntimeRequestId,
342 cause: Schema.optional(Schema.Defect()),
343 },
344) {
345 override get message(): string {
346 return `Failed to respond to ${this.driver} runtime request ${this.requestId}.`;
347 }
349​
350export class ProviderAdapterEventStreamError extends Schema.TaggedError<ProviderAdapterEventStreamError>()(
351 "ProviderAdapterEventStreamError",
352 {
353 driver: ProviderDriverKind,
354 providerSessionId: ProviderSessionId,
355 cause: Schema.optional(Schema.Defect()),
356 },
357) {
358 override get message(): string {
359 return `Failed while streaming ${this.driver} provider session ${this.providerSessionId} events.`;
360 }
362​
363export class ProviderAdapterProtocolError extends Schema.TaggedError<ProviderAdapterProtocolError>()(
364 "ProviderAdapterProtocolError",
365 {
366 driver: ProviderDriverKind,
367 detail: Schema.String,
368 cause: Schema.optional(Schema.Defect()),
369 payload: Schema.optional(Schema.Unknown),
370 },
371) {
372 override get message(): string {
373 return `${this.driver} provider protocol error: ${this.detail}.`;
374 }
376​
377export const ProviderAdapterV2Error = Schema.Union([
378 ProviderAdapterCapabilitiesError,
379 ProviderAdapterOpenSessionError,
380 ProviderAdapterCloseSessionError,
381 ProviderAdapterResumeThreadError,
382 ProviderAdapterEnsureThreadError,
383 ProviderAdapterReadThreadSnapshotError,
384 ProviderAdapterRollbackThreadError,
385 ProviderAdapterForkThreadError,
386 ProviderAdapterTurnStartError,
387 ProviderAdapterSteerRunUnsupportedError,
388 ProviderAdapterSteerRunError,
389 ProviderAdapterInterruptError,
390 ProviderAdapterRuntimeRequestResponseError,
391 ProviderAdapterEventStreamError,
392 ProviderAdapterProtocolError,
393]);
394export type ProviderAdapterV2Error = typeof ProviderAdapterV2Error.Type;
395​
396export interface ProviderAdapterV2OpenSessionInput {
397 readonly threadId: ThreadId;
398 readonly providerSessionId: ProviderSessionId;
399 readonly modelSelection: ModelSelection;
400 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
401 readonly resumeFromSession?: OrchestrationV2ProviderSession;
402 readonly initialNativeThreadId?: string;
403 readonly initialProviderItemIdentityVersion?: 2;
405​
406export interface ProviderAdapterV2EnsureThreadInput {
407 readonly threadId: ThreadId;
408 readonly title?: string;
409 readonly modelSelection: ModelSelection;
410 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
411 readonly providerSessionId?: ProviderSessionId;
412 readonly existingProviderThread?: OrchestrationV2ProviderThread;
414​
415export interface ProviderAdapterV2TurnInput {
416 readonly appThread: OrchestrationV2AppThread;
417 readonly threadId: ThreadId;
418 readonly runId: RunId;
419 readonly runOrdinal: number;
420 readonly nativeThreadHasTurns?: boolean;
421 readonly providerTurnOrdinal: number;
422 readonly restartContinuationOfRunId?: RunId;
423 readonly attemptId: RunAttemptId;
424 readonly rootNodeId: NodeId;
425 readonly providerThread: OrchestrationV2ProviderThread;
426 readonly message: ProviderAdapterV2TurnMessage;
427 readonly modelSelection: ModelSelection;
428 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
429 readonly appContext?: ReadonlyArray<{ readonly key: string; readonly text: string }>;
431​
432export interface ProviderAdapterV2SteerInput {
433 readonly threadId: ThreadId;
434 readonly runId: RunId;
435 readonly providerThread: OrchestrationV2ProviderThread;
436 readonly providerTurnId: ProviderTurnId;
437 readonly message: ProviderAdapterV2TurnMessage;
439​
440export interface ProviderAdapterV2InterruptInput {
441 readonly providerThread: OrchestrationV2ProviderThread;
442 readonly providerTurnId: ProviderTurnId;
443 readonly requestRuntimeRestart?: boolean;
445​
446export interface ProviderAdapterV2RuntimeRequestResponseInput {
447 readonly requestId: RuntimeRequestId;
448 readonly decision?: ProviderApprovalDecision;
449 readonly answers?: ProviderUserInputAnswers;
450 readonly response?: unknown;
452​
453export interface ProviderAdapterV2ThreadSnapshot {
454 readonly providerThread: OrchestrationV2ProviderThread;
455 readonly providerTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
456 readonly messages: ReadonlyArray<OrchestrationV2ConversationMessage>;
457 readonly runtimeRequests: ReadonlyArray<OrchestrationV2RuntimeRequest>;
458 readonly providerPayload?: unknown;
460​
461export interface ProviderAdapterV2ReadThreadSnapshotInput {
462 readonly providerThread: OrchestrationV2ProviderThread;
464​
465export type ProviderAdapterV2RollbackTarget =
466 | {
467 readonly type: "thread_start";
468 readonly checkpointId: CheckpointId;
469 readonly appRunOrdinal: 0;
470 }
471 | {
472 readonly type: "provider_turn";
473 readonly checkpointId: CheckpointId;
474 readonly appRunOrdinal: number;
475 readonly providerTurn: OrchestrationV2ProviderTurn;
476 };
477​
478export interface ProviderAdapterV2RollbackThreadInput {
479 readonly providerThread: OrchestrationV2ProviderThread;
480 readonly target: ProviderAdapterV2RollbackTarget;
481 readonly providerThreadTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
483​
484export interface ProviderAdapterV2ForkThreadInput {
485 readonly sourceProviderThread: OrchestrationV2ProviderThread;
486 readonly sourceProviderTurns?: ReadonlyArray<OrchestrationV2ProviderTurn>;
487 readonly providerTurnId?: ProviderTurnId;
488 readonly targetThreadId: ThreadId;
489 readonly ownerNodeId?: NodeId;
490 readonly modelSelection?: ModelSelection;
491 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
493​
494export interface ProviderAdapterV2EventSubscription {
495 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
496 readonly close: Effect.Effect<void>;
498​
499export interface ProviderAdapterV2HistoricalContext {
500 readonly messages: ReadonlyArray<OrchestrationV2HistoricalMessage>;
501 readonly context: string;
503​
504export interface ProviderAdapterV2McpTool {
505 readonly name: string;
506 readonly _meta?: unknown;
507 readonly annotations?: unknown;
509​
510export interface ProviderAdapterV2McpCallToolResult {
511 readonly content: ReadonlyArray<unknown>;
512 readonly structuredContent?: unknown;
513 readonly isError?: boolean;
514 readonly _meta?: unknown;
516​
517export interface ProviderAdapterV2McpApps {
518 readonly listTools: (input: {
519 readonly providerThread: OrchestrationV2ProviderThread;
520 readonly server: string;
521 }) => Effect.Effect<ReadonlyArray<ProviderAdapterV2McpTool>, ProviderAdapterV2Error>;
522 readonly callTool: (input: {
523 readonly providerThread: OrchestrationV2ProviderThread;
524 readonly server: string;
525 readonly tool: string;
526 readonly arguments: Record<string, unknown>;
527 }) => Effect.Effect<ProviderAdapterV2McpCallToolResult, ProviderAdapterV2Error>;
528 readonly readResource: (input: {
529 readonly providerThread: OrchestrationV2ProviderThread;
530 readonly server: string;
531 readonly uri: string;
532 }) => Effect.Effect<{ readonly contents: ReadonlyArray<unknown> }, ProviderAdapterV2Error>;
534​
535export type ProviderAdapterV2SubagentOutcome = {
536 readonly status: "completed" | "failed" | "cancelled";
537 readonly completedAt: NonNullable<OrchestrationV2Subagent["completedAt"]>;
538 readonly result: OrchestrationV2Subagent["result"];
539};
540​
541export interface ProviderAdapterV2SessionRuntime {
542 readonly instanceId: ProviderInstanceId;
543 readonly driver: ProviderDriverKind;
544 readonly providerSessionId: ProviderSessionId;
545 readonly providerSession: OrchestrationV2ProviderSession;
546 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
547 /**
548 * Manager-owned runtimes expose a synchronous subscription so concurrent
549 * provider threads receive independent copies of the process event stream.
550 * Adapter runtimes may omit this and expose only their single-consumer event stream.
551 */
552 readonly subscribeEvents?: Effect.Effect<ProviderAdapterV2EventSubscription>;
553 readonly hasPendingBackgroundWork?: Effect.Effect<boolean>;
554 /**
555 * When present, RunExecutionService uses only this probe (never the
556 * session-wide hasPendingBackgroundWork) so sibling native threads cannot pin
557 * an unrelated root subscription open.
558 */
559 readonly hasPendingBackgroundWorkForThread?: (
560 providerThread: OrchestrationV2ProviderThread,
561 ) => Effect.Effect<boolean>;
562 /**
563 * Set when every background task this session lists on its provider threads
564 * runs inside the session's own process and ends when it closes. Leave unset
565 * when a task can outlive the session, for example on a shared server, so its
566 * thread keeps showing Waiting.
567 */
568 readonly backgroundTasksEndWithProcess?: true;
569 readonly getModelContextWindow?: (
570 modelSelection: ModelSelection,
571 cwd?: string | null,
572 ) => number | undefined;
573 readonly canReuseContextUsage?: (previous: ModelSelection, next: ModelSelection) => boolean;
574 readonly ensureThread: (
575 input: ProviderAdapterV2EnsureThreadInput,
576 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
577 readonly resumeThread: (input: {
578 readonly providerThread: OrchestrationV2ProviderThread;
579 readonly threadId?: ThreadId;
580 readonly modelSelection?: ModelSelection;
581 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
582 }) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
583 /** False means the native protocol explicitly does not support history injection. */
584 readonly injectHistory?: (
585 input: ProviderAdapterV2HistoricalContext & {
586 readonly providerThread: OrchestrationV2ProviderThread;
587 },
588 ) => Effect.Effect<boolean, ProviderAdapterV2Error>;
589 readonly startTurn: (
590 input: ProviderAdapterV2TurnInput,
591 ) => Effect.Effect<void, ProviderAdapterV2Error>;
592 readonly compactThread?: (
593 input: ProviderAdapterV2TurnInput,
594 ) => Effect.Effect<void, ProviderAdapterV2Error>;
595 readonly steerTurn: (
596 input: ProviderAdapterV2SteerInput,
597 ) => Effect.Effect<void, ProviderAdapterV2Error>;
598 readonly stopTask?: (input: {
599 readonly providerThread: OrchestrationV2ProviderThread;
600 readonly taskId: string;
601 }) => Effect.Effect<void, ProviderAdapterV2Error>;
602 readonly interruptTurn: (
603 input: ProviderAdapterV2InterruptInput,
604 ) => Effect.Effect<void, ProviderAdapterV2Error>;
605 readonly stopSubagent?: (input: {
606 readonly providerThread: OrchestrationV2ProviderThread;
607 readonly nativeTaskId: string;
608 /** A delayed Stop must not interrupt a task resumed after this request. */
609 readonly requestedAt?: NonNullable<OrchestrationV2Subagent["startedAt"]>;
610 }) => Effect.Effect<void | ProviderAdapterV2SubagentOutcome, ProviderAdapterV2Error>;
611 readonly unloadThread?: (input: {
612 readonly providerThread: OrchestrationV2ProviderThread;
613 }) => Effect.Effect<void, ProviderAdapterV2Error>;
614 readonly respondToRuntimeRequest: (
615 input: ProviderAdapterV2RuntimeRequestResponseInput,
616 ) => Effect.Effect<void, ProviderAdapterV2Error>;
617 readonly readThreadSnapshot: (
618 input: ProviderAdapterV2ReadThreadSnapshotInput,
619 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
620 readonly uploadFeedback?: (input: {
621 readonly providerThread: OrchestrationV2ProviderThread;
622 readonly reason?: string;
623 }) => Effect.Effect<{ readonly feedbackId: string }, ProviderAdapterV2Error>;
624 /**
625 * Absent means apps from this provider are not interactive and their tool
626 * calls stay plain tool rows.
627 */
628 readonly mcpApps?: ProviderAdapterV2McpApps;
629 readonly rollbackThread: (
630 input: ProviderAdapterV2RollbackThreadInput,
631 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
632 readonly forkThread: (
633 input: ProviderAdapterV2ForkThreadInput,
634 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
636​
637export class ProviderAdapterV2 extends Context.Service<
638 ProviderAdapterV2,
639 {
640 readonly instanceId: ProviderInstanceId;
641 readonly driver: ProviderDriverKind;
642 readonly getCapabilities: () => Effect.Effect<
643 OrchestrationV2ProviderCapabilities,
644 ProviderAdapterV2Error
645 >;
646 readonly planSelectionTransition: (
647 input: ProviderSelectionTransitionInput,
648 ) => Effect.Effect<ProviderSelectionTransitionPlan, ProviderAdapterV2Error>;
649 readonly openSession: (
650 input: ProviderAdapterV2OpenSessionInput,
651 ) => Effect.Effect<ProviderAdapterV2SessionRuntime, ProviderAdapterV2Error, Scope.Scope>;
652 }
653>()("@t3tools/provider-core/server/ProviderAdapter/ProviderAdapterV2") {}