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
158 lines (138 loc) · 4.55 KB
/
Copy pathProviderAdapter.ts
File metadata and controls
158 lines (138 loc) · 4.55 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* 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,
ProviderUploadFeedbackInput,
ProviderUploadFeedbackResult,
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";
/**
* How ProviderService runs manual context compaction for an adapter.
* Native adapters expose a start call and must emit a compacted thread state
* when they finish. Slash-command adapters get the command sent as a turn.
*/
export type ProviderCompaction<TError> =
| {
readonly type: "native";
readonly start: (
threadId: ThreadId,
modelSelection?: ProviderSendTurnInput["modelSelection"],
) => Effect.Effect<void, TError>;
}
| { readonly type: "slash-command"; readonly command: `/${string}` };
export interface ProviderAdapterCapabilities {
/**
* Declares whether changing the model on an existing session is supported.
*/
readonly sessionModelSwitch: ProviderSessionModelSwitchMode;
/** Starts a resumed turn with no synthetic user prompt. Omitted means the
adapter needs an explicit continuation instruction. */
readonly promptlessTurnContinuation?: boolean;
/** False when native conversation history cannot be rewound. */
readonly supportsConversationRollback?: boolean;
}
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>;
/** Omitted when this adapter does not support manual context compaction. */
readonly compaction?: ProviderCompaction<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>;
/**
* Upload a thread to the provider when the adapter supports feedback.
*/
readonly uploadFeedback?: (
input: ProviderUploadFeedbackInput,
) => Effect.Effect<ProviderUploadFeedbackResult, 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>;
}