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

ProviderAdapter.ts

647 lines22.5 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]);
169export type ProviderAdapterV2Event = typeof ProviderAdapterV2Event.Type;
170​
171export class ProviderAdapterCapabilitiesError extends Schema.TaggedError<ProviderAdapterCapabilitiesError>()(
172 "ProviderAdapterCapabilitiesError",
173 {
174 driver: ProviderDriverKind,
175 cause: Schema.optional(Schema.Defect()),
176 },
177) {
178 override get message(): string {
179 return `Failed to read ${this.driver} provider capabilities.`;
180 }
182​
183export class ProviderAdapterOpenSessionError extends Schema.TaggedError<ProviderAdapterOpenSessionError>()(
184 "ProviderAdapterOpenSessionError",
185 {
186 driver: ProviderDriverKind,
187 providerSessionId: ProviderSessionId,
188 cause: Schema.optional(Schema.Defect()),
189 },
190) {
191 override get message(): string {
192 return `Failed to open ${this.driver} provider session ${this.providerSessionId}.`;
193 }
195​
196export class ProviderAdapterCloseSessionError extends Schema.TaggedError<ProviderAdapterCloseSessionError>()(
197 "ProviderAdapterCloseSessionError",
198 {
199 driver: ProviderDriverKind,
200 providerSessionId: ProviderSessionId,
201 cause: Schema.optional(Schema.Defect()),
202 },
203) {
204 override get message(): string {
205 return `Failed to close ${this.driver} provider session ${this.providerSessionId}.`;
206 }
208​
209export class ProviderAdapterResumeThreadError extends Schema.TaggedError<ProviderAdapterResumeThreadError>()(
210 "ProviderAdapterResumeThreadError",
211 {
212 driver: ProviderDriverKind,
213 providerSessionId: ProviderSessionId,
214 providerThreadId: ProviderThreadId,
215 cause: Schema.optional(Schema.Defect()),
216 },
217) {
218 override get message(): string {
219 return `Failed to resume ${this.driver} provider thread ${this.providerThreadId}.`;
220 }
222​
223export class ProviderAdapterEnsureThreadError extends Schema.TaggedError<ProviderAdapterEnsureThreadError>()(
224 "ProviderAdapterEnsureThreadError",
225 {
226 driver: ProviderDriverKind,
227 threadId: ThreadId,
228 cause: Schema.optional(Schema.Defect()),
229 },
230) {
231 override get message(): string {
232 return `Failed to ensure ${this.driver} provider thread for app thread ${this.threadId}.`;
233 }
235​
236export class ProviderAdapterReadThreadSnapshotError extends Schema.TaggedError<ProviderAdapterReadThreadSnapshotError>()(
237 "ProviderAdapterReadThreadSnapshotError",
238 {
239 driver: ProviderDriverKind,
240 providerThreadId: ProviderThreadId,
241 cause: Schema.optional(Schema.Defect()),
242 },
243) {
244 override get message(): string {
245 return `Failed to read ${this.driver} provider thread snapshot ${this.providerThreadId}.`;
246 }
248​
249export class ProviderAdapterRollbackThreadError extends Schema.TaggedError<ProviderAdapterRollbackThreadError>()(
250 "ProviderAdapterRollbackThreadError",
251 {
252 driver: ProviderDriverKind,
253 providerThreadId: ProviderThreadId,
254 checkpointId: Schema.optional(CheckpointId),
255 cause: Schema.optional(Schema.Defect()),
256 },
257) {
258 override get message(): string {
259 return `Failed to roll back ${this.driver} provider thread ${this.providerThreadId}.`;
260 }
262​
263export class ProviderAdapterForkThreadError extends Schema.TaggedError<ProviderAdapterForkThreadError>()(
264 "ProviderAdapterForkThreadError",
265 {
266 driver: ProviderDriverKind,
267 providerThreadId: ProviderThreadId,
268 cause: Schema.optional(Schema.Defect()),
269 },
270) {
271 override get message(): string {
272 return `Failed to fork ${this.driver} provider thread ${this.providerThreadId}.`;
273 }
275​
276export class ProviderAdapterTurnStartError extends Schema.TaggedError<ProviderAdapterTurnStartError>()(
277 "ProviderAdapterTurnStartError",
278 {
279 driver: ProviderDriverKind,
280 threadId: ThreadId,
281 providerThreadId: ProviderThreadId,
282 runId: RunId,
283 cause: Schema.optional(Schema.Defect()),
284 },
285) {
286 override get message(): string {
287 return `Failed to start run ${this.runId} on ${this.driver} provider thread ${this.providerThreadId}.`;
288 }
290​
291export class ProviderAdapterSteerRunUnsupportedError extends Schema.TaggedError<ProviderAdapterSteerRunUnsupportedError>()(
292 "ProviderAdapterSteerRunUnsupportedError",
293 {
294 driver: ProviderDriverKind,
295 providerThreadId: ProviderThreadId,
296 },
297) {
298 override get message(): string {
299 return `${this.driver} provider thread ${this.providerThreadId} does not support active-run steering.`;
300 }
302​
303export class ProviderAdapterSteerRunError extends Schema.TaggedError<ProviderAdapterSteerRunError>()(
304 "ProviderAdapterSteerRunError",
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 steer active run ${this.providerTurnId} on ${this.driver} provider thread ${this.providerThreadId}.`;
314 }
316​
317export class ProviderAdapterInterruptError extends Schema.TaggedError<ProviderAdapterInterruptError>()(
318 "ProviderAdapterInterruptError",
319 {
320 driver: ProviderDriverKind,
321 providerThreadId: ProviderThreadId,
322 providerTurnId: ProviderTurnId,
323 cause: Schema.optional(Schema.Defect()),
324 },
325) {
326 override get message(): string {
327 return `Failed to interrupt ${this.driver} provider turn ${this.providerTurnId}.`;
328 }
330​
331export class ProviderAdapterRuntimeRequestResponseError extends Schema.TaggedError<ProviderAdapterRuntimeRequestResponseError>()(
332 "ProviderAdapterRuntimeRequestResponseError",
333 {
334 driver: ProviderDriverKind,
335 requestId: RuntimeRequestId,
336 cause: Schema.optional(Schema.Defect()),
337 },
338) {
339 override get message(): string {
340 return `Failed to respond to ${this.driver} runtime request ${this.requestId}.`;
341 }
343​
344export class ProviderAdapterEventStreamError extends Schema.TaggedError<ProviderAdapterEventStreamError>()(
345 "ProviderAdapterEventStreamError",
346 {
347 driver: ProviderDriverKind,
348 providerSessionId: ProviderSessionId,
349 cause: Schema.optional(Schema.Defect()),
350 },
351) {
352 override get message(): string {
353 return `Failed while streaming ${this.driver} provider session ${this.providerSessionId} events.`;
354 }
356​
357export class ProviderAdapterProtocolError extends Schema.TaggedError<ProviderAdapterProtocolError>()(
358 "ProviderAdapterProtocolError",
359 {
360 driver: ProviderDriverKind,
361 detail: Schema.String,
362 cause: Schema.optional(Schema.Defect()),
363 payload: Schema.optional(Schema.Unknown),
364 },
365) {
366 override get message(): string {
367 return `${this.driver} provider protocol error: ${this.detail}.`;
368 }
370​
371export const ProviderAdapterV2Error = Schema.Union([
372 ProviderAdapterCapabilitiesError,
373 ProviderAdapterOpenSessionError,
374 ProviderAdapterCloseSessionError,
375 ProviderAdapterResumeThreadError,
376 ProviderAdapterEnsureThreadError,
377 ProviderAdapterReadThreadSnapshotError,
378 ProviderAdapterRollbackThreadError,
379 ProviderAdapterForkThreadError,
380 ProviderAdapterTurnStartError,
381 ProviderAdapterSteerRunUnsupportedError,
382 ProviderAdapterSteerRunError,
383 ProviderAdapterInterruptError,
384 ProviderAdapterRuntimeRequestResponseError,
385 ProviderAdapterEventStreamError,
386 ProviderAdapterProtocolError,
387]);
388export type ProviderAdapterV2Error = typeof ProviderAdapterV2Error.Type;
389​
390export interface ProviderAdapterV2OpenSessionInput {
391 readonly threadId: ThreadId;
392 readonly providerSessionId: ProviderSessionId;
393 readonly modelSelection: ModelSelection;
394 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
395 readonly resumeFromSession?: OrchestrationV2ProviderSession;
396 readonly initialNativeThreadId?: string;
397 readonly initialProviderItemIdentityVersion?: 2;
399​
400export interface ProviderAdapterV2EnsureThreadInput {
401 readonly threadId: ThreadId;
402 readonly title?: string;
403 readonly modelSelection: ModelSelection;
404 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
405 readonly providerSessionId?: ProviderSessionId;
406 readonly existingProviderThread?: OrchestrationV2ProviderThread;
408​
409export interface ProviderAdapterV2TurnInput {
410 readonly appThread: OrchestrationV2AppThread;
411 readonly threadId: ThreadId;
412 readonly runId: RunId;
413 readonly runOrdinal: number;
414 readonly nativeThreadHasTurns?: boolean;
415 readonly providerTurnOrdinal: number;
416 readonly restartContinuationOfRunId?: RunId;
417 readonly attemptId: RunAttemptId;
418 readonly rootNodeId: NodeId;
419 readonly providerThread: OrchestrationV2ProviderThread;
420 readonly message: ProviderAdapterV2TurnMessage;
421 readonly modelSelection: ModelSelection;
422 readonly runtimePolicy: ProviderAdapterV2RuntimePolicy;
423 readonly appContext?: ReadonlyArray<{ readonly key: string; readonly text: string }>;
425​
426export interface ProviderAdapterV2SteerInput {
427 readonly threadId: ThreadId;
428 readonly runId: RunId;
429 readonly providerThread: OrchestrationV2ProviderThread;
430 readonly providerTurnId: ProviderTurnId;
431 readonly message: ProviderAdapterV2TurnMessage;
433​
434export interface ProviderAdapterV2InterruptInput {
435 readonly providerThread: OrchestrationV2ProviderThread;
436 readonly providerTurnId: ProviderTurnId;
437 readonly requestRuntimeRestart?: boolean;
439​
440export interface ProviderAdapterV2RuntimeRequestResponseInput {
441 readonly requestId: RuntimeRequestId;
442 readonly decision?: ProviderApprovalDecision;
443 readonly answers?: ProviderUserInputAnswers;
444 readonly response?: unknown;
446​
447export interface ProviderAdapterV2ThreadSnapshot {
448 readonly providerThread: OrchestrationV2ProviderThread;
449 readonly providerTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
450 readonly messages: ReadonlyArray<OrchestrationV2ConversationMessage>;
451 readonly runtimeRequests: ReadonlyArray<OrchestrationV2RuntimeRequest>;
452 readonly providerPayload?: unknown;
454​
455export interface ProviderAdapterV2ReadThreadSnapshotInput {
456 readonly providerThread: OrchestrationV2ProviderThread;
458​
459export type ProviderAdapterV2RollbackTarget =
460 | {
461 readonly type: "thread_start";
462 readonly checkpointId: CheckpointId;
463 readonly appRunOrdinal: 0;
464 }
465 | {
466 readonly type: "provider_turn";
467 readonly checkpointId: CheckpointId;
468 readonly appRunOrdinal: number;
469 readonly providerTurn: OrchestrationV2ProviderTurn;
470 };
471​
472export interface ProviderAdapterV2RollbackThreadInput {
473 readonly providerThread: OrchestrationV2ProviderThread;
474 readonly target: ProviderAdapterV2RollbackTarget;
475 readonly providerThreadTurns: ReadonlyArray<OrchestrationV2ProviderTurn>;
477​
478export interface ProviderAdapterV2ForkThreadInput {
479 readonly sourceProviderThread: OrchestrationV2ProviderThread;
480 readonly sourceProviderTurns?: ReadonlyArray<OrchestrationV2ProviderTurn>;
481 readonly providerTurnId?: ProviderTurnId;
482 readonly targetThreadId: ThreadId;
483 readonly ownerNodeId?: NodeId;
484 readonly modelSelection?: ModelSelection;
485 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
487​
488export interface ProviderAdapterV2EventSubscription {
489 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
490 readonly close: Effect.Effect<void>;
492​
493export interface ProviderAdapterV2HistoricalContext {
494 readonly messages: ReadonlyArray<OrchestrationV2HistoricalMessage>;
495 readonly context: string;
497​
498export interface ProviderAdapterV2McpTool {
499 readonly name: string;
500 readonly _meta?: unknown;
501 readonly annotations?: unknown;
503​
504export interface ProviderAdapterV2McpCallToolResult {
505 readonly content: ReadonlyArray<unknown>;
506 readonly structuredContent?: unknown;
507 readonly isError?: boolean;
508 readonly _meta?: unknown;
510​
511export interface ProviderAdapterV2McpApps {
512 readonly listTools: (input: {
513 readonly providerThread: OrchestrationV2ProviderThread;
514 readonly server: string;
515 }) => Effect.Effect<ReadonlyArray<ProviderAdapterV2McpTool>, ProviderAdapterV2Error>;
516 readonly callTool: (input: {
517 readonly providerThread: OrchestrationV2ProviderThread;
518 readonly server: string;
519 readonly tool: string;
520 readonly arguments: Record<string, unknown>;
521 }) => Effect.Effect<ProviderAdapterV2McpCallToolResult, ProviderAdapterV2Error>;
522 readonly readResource: (input: {
523 readonly providerThread: OrchestrationV2ProviderThread;
524 readonly server: string;
525 readonly uri: string;
526 }) => Effect.Effect<{ readonly contents: ReadonlyArray<unknown> }, ProviderAdapterV2Error>;
528​
529export type ProviderAdapterV2SubagentOutcome = {
530 readonly status: "completed" | "failed" | "cancelled";
531 readonly completedAt: NonNullable<OrchestrationV2Subagent["completedAt"]>;
532 readonly result: OrchestrationV2Subagent["result"];
533};
534​
535export interface ProviderAdapterV2SessionRuntime {
536 readonly instanceId: ProviderInstanceId;
537 readonly driver: ProviderDriverKind;
538 readonly providerSessionId: ProviderSessionId;
539 readonly providerSession: OrchestrationV2ProviderSession;
540 readonly events: Stream.Stream<ProviderAdapterV2Event, ProviderAdapterV2Error>;
541 /**
542 * Manager-owned runtimes expose a synchronous subscription so concurrent
543 * provider threads receive independent copies of the process event stream.
544 * Adapter runtimes may omit this and expose only their single-consumer event stream.
545 */
546 readonly subscribeEvents?: Effect.Effect<ProviderAdapterV2EventSubscription>;
547 readonly hasPendingBackgroundWork?: Effect.Effect<boolean>;
548 /**
549 * When present, RunExecutionService uses only this probe (never the
550 * session-wide hasPendingBackgroundWork) so sibling native threads cannot pin
551 * an unrelated root subscription open.
552 */
553 readonly hasPendingBackgroundWorkForThread?: (
554 providerThread: OrchestrationV2ProviderThread,
555 ) => Effect.Effect<boolean>;
556 /**
557 * Set when every background task this session lists on its provider threads
558 * runs inside the session's own process and ends when it closes. Leave unset
559 * when a task can outlive the session, for example on a shared server, so its
560 * thread keeps showing Waiting.
561 */
562 readonly backgroundTasksEndWithProcess?: true;
563 readonly getModelContextWindow?: (
564 modelSelection: ModelSelection,
565 cwd?: string | null,
566 ) => number | undefined;
567 readonly canReuseContextUsage?: (previous: ModelSelection, next: ModelSelection) => boolean;
568 readonly ensureThread: (
569 input: ProviderAdapterV2EnsureThreadInput,
570 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
571 readonly resumeThread: (input: {
572 readonly providerThread: OrchestrationV2ProviderThread;
573 readonly threadId?: ThreadId;
574 readonly modelSelection?: ModelSelection;
575 readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy;
576 }) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
577 /** False means the native protocol explicitly does not support history injection. */
578 readonly injectHistory?: (
579 input: ProviderAdapterV2HistoricalContext & {
580 readonly providerThread: OrchestrationV2ProviderThread;
581 },
582 ) => Effect.Effect<boolean, ProviderAdapterV2Error>;
583 readonly startTurn: (
584 input: ProviderAdapterV2TurnInput,
585 ) => Effect.Effect<void, ProviderAdapterV2Error>;
586 readonly compactThread?: (
587 input: ProviderAdapterV2TurnInput,
588 ) => Effect.Effect<void, ProviderAdapterV2Error>;
589 readonly steerTurn: (
590 input: ProviderAdapterV2SteerInput,
591 ) => Effect.Effect<void, ProviderAdapterV2Error>;
592 readonly stopTask?: (input: {
593 readonly providerThread: OrchestrationV2ProviderThread;
594 readonly taskId: string;
595 }) => Effect.Effect<void, ProviderAdapterV2Error>;
596 readonly interruptTurn: (
597 input: ProviderAdapterV2InterruptInput,
598 ) => Effect.Effect<void, ProviderAdapterV2Error>;
599 readonly stopSubagent?: (input: {
600 readonly providerThread: OrchestrationV2ProviderThread;
601 readonly nativeTaskId: string;
602 /** A delayed Stop must not interrupt a task resumed after this request. */
603 readonly requestedAt?: NonNullable<OrchestrationV2Subagent["startedAt"]>;
604 }) => Effect.Effect<void | ProviderAdapterV2SubagentOutcome, ProviderAdapterV2Error>;
605 readonly unloadThread?: (input: {
606 readonly providerThread: OrchestrationV2ProviderThread;
607 }) => Effect.Effect<void, ProviderAdapterV2Error>;
608 readonly respondToRuntimeRequest: (
609 input: ProviderAdapterV2RuntimeRequestResponseInput,
610 ) => Effect.Effect<void, ProviderAdapterV2Error>;
611 readonly readThreadSnapshot: (
612 input: ProviderAdapterV2ReadThreadSnapshotInput,
613 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
614 readonly uploadFeedback?: (input: {
615 readonly providerThread: OrchestrationV2ProviderThread;
616 readonly reason?: string;
617 }) => Effect.Effect<{ readonly feedbackId: string }, ProviderAdapterV2Error>;
618 /**
619 * Absent means apps from this provider are not interactive and their tool
620 * calls stay plain tool rows.
621 */
622 readonly mcpApps?: ProviderAdapterV2McpApps;
623 readonly rollbackThread: (
624 input: ProviderAdapterV2RollbackThreadInput,
625 ) => Effect.Effect<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error>;
626 readonly forkThread: (
627 input: ProviderAdapterV2ForkThreadInput,
628 ) => Effect.Effect<OrchestrationV2ProviderThread, ProviderAdapterV2Error>;
630​
631export class ProviderAdapterV2 extends Context.Service<
632 ProviderAdapterV2,
633 {
634 readonly instanceId: ProviderInstanceId;
635 readonly driver: ProviderDriverKind;
636 readonly getCapabilities: () => Effect.Effect<
637 OrchestrationV2ProviderCapabilities,
638 ProviderAdapterV2Error
639 >;
640 readonly planSelectionTransition: (
641 input: ProviderSelectionTransitionInput,
642 ) => Effect.Effect<ProviderSelectionTransitionPlan, ProviderAdapterV2Error>;
643 readonly openSession: (
644 input: ProviderAdapterV2OpenSessionInput,
645 ) => Effect.Effect<ProviderAdapterV2SessionRuntime, ProviderAdapterV2Error, Scope.Scope>;
646 }
647>()("@t3tools/provider-core/server/ProviderAdapter/ProviderAdapterV2") {}