forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProviderAdapter.ts
More file actions
126 lines (109 loc) · 3.31 KB
/
Copy pathProviderAdapter.ts
File metadata and controls
126 lines (109 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* ProviderAdapter - Provider-specific runtime adapter contract.
*
* Defines the provider-native session/protocol operations that `ProviderService`
* routes to after resolving the target provider. Implementations should focus
* on provider behavior only and avoid cross-provider orchestration concerns.
*
* @module ProviderAdapter
*/
import type {
ApprovalRequestId,
ProviderApprovalDecision,
ProviderDriverKind,
ProviderUserInputAnswers,
ProviderRuntimeEvent,
ProviderSendTurnInput,
ProviderSession,
ProviderSessionStartInput,
ThreadId,
ProviderTurnStartResult,
TurnId,
} from "@t3tools/contracts";
import type * as Effect from "effect/Effect";
import type * as Stream from "effect/Stream";
export type ProviderSessionModelSwitchMode = "in-session" | "unsupported";
export interface ProviderAdapterCapabilities {
/**
* Declares whether changing the model on an existing session is supported.
*/
readonly sessionModelSwitch: ProviderSessionModelSwitchMode;
}
export interface ProviderThreadTurnSnapshot {
readonly id: TurnId;
readonly items: ReadonlyArray<unknown>;
}
export interface ProviderThreadSnapshot {
readonly threadId: ThreadId;
readonly turns: ReadonlyArray<ProviderThreadTurnSnapshot>;
}
export interface ProviderAdapterShape<TError> {
/**
* Provider kind implemented by this adapter.
*/
readonly provider: ProviderDriverKind;
readonly capabilities: ProviderAdapterCapabilities;
/**
* Start a provider-backed session.
*/
readonly startSession: (
input: ProviderSessionStartInput,
) => Effect.Effect<ProviderSession, TError>;
/**
* Send a turn to an active provider session.
*/
readonly sendTurn: (
input: ProviderSendTurnInput,
) => Effect.Effect<ProviderTurnStartResult, TError>;
/**
* Interrupt an active turn.
*/
readonly interruptTurn: (threadId: ThreadId, turnId?: TurnId) => Effect.Effect<void, TError>;
/**
* Respond to an interactive approval request.
*/
readonly respondToRequest: (
threadId: ThreadId,
requestId: ApprovalRequestId,
decision: ProviderApprovalDecision,
) => Effect.Effect<void, TError>;
/**
* Respond to a structured user-input request.
*/
readonly respondToUserInput: (
threadId: ThreadId,
requestId: ApprovalRequestId,
answers: ProviderUserInputAnswers,
) => Effect.Effect<void, TError>;
/**
* Stop one provider session.
*/
readonly stopSession: (threadId: ThreadId) => Effect.Effect<void, TError>;
/**
* List currently active provider sessions for this adapter.
*/
readonly listSessions: () => Effect.Effect<ReadonlyArray<ProviderSession>>;
/**
* Check whether this adapter owns an active session id.
*/
readonly hasSession: (threadId: ThreadId) => Effect.Effect<boolean>;
/**
* Read a provider thread snapshot.
*/
readonly readThread: (threadId: ThreadId) => Effect.Effect<ProviderThreadSnapshot, TError>;
/**
* Roll back a provider thread by N turns.
*/
readonly rollbackThread: (
threadId: ThreadId,
numTurns: number,
) => Effect.Effect<ProviderThreadSnapshot, TError>;
/**
* Stop all sessions owned by this adapter.
*/
readonly stopAll: () => Effect.Effect<void, TError>;
/**
* Canonical runtime event stream emitted by this adapter.
*/
readonly streamEvents: Stream.Stream<ProviderRuntimeEvent>;
}