| ... | @@ -28,10 +28,7 @@ import { | ... | @@ -28,10 +28,7 @@ import { |
| 28 | type ProviderAdapterError, | 28 | type ProviderAdapterError, |
| 29 | } from "../Errors.ts"; | 29 | } from "../Errors.ts"; |
| 30 | import { type ProviderThreadSnapshot } from "../Services/ProviderAdapter.ts"; | 30 | import { type ProviderThreadSnapshot } from "../Services/ProviderAdapter.ts"; |
| 31 | import { | 31 | import { ClaudeCodeAdapter, type ClaudeCodeAdapterShape } from "../Services/ClaudeCodeAdapter.ts"; |
| 32 | ClaudeCodeAdapter, | | |
| 33 | type ClaudeCodeAdapterShape, | | |
| 34 | } from "../Services/ClaudeCodeAdapter.ts"; | | |
| 35 | | 32 | |
| 36 | const PROVIDER = "claudeCode" as const; | 33 | const PROVIDER = "claudeCode" as const; |
| 37 | | 34 | |
| ... | @@ -188,10 +185,7 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => | ... | @@ -188,10 +185,7 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => |
| 188 | } | 185 | } |
| 189 | return makeUnavailableRuntime(); | 186 | return makeUnavailableRuntime(); |
| 190 | }), | 187 | }), |
| 191 | (runtime) => | 188 | (runtime) => runtime.stopAll(), |
| 192 | runtime.stopAll().pipe( | | |
| 193 | Effect.orElseSucceed(() => undefined), | | |
| 194 | ), | | |
| 195 | ); | 189 | ); |
| 196 | | 190 | |
| 197 | const startSession: ClaudeCodeAdapterShape["startSession"] = (input) => { | 191 | const startSession: ClaudeCodeAdapterShape["startSession"] = (input) => { |
| ... | @@ -219,19 +213,19 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => | ... | @@ -219,19 +213,19 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => |
| 219 | }; | 213 | }; |
| 220 | | 214 | |
| 221 | const sendTurn: ClaudeCodeAdapterShape["sendTurn"] = (input) => | 215 | const sendTurn: ClaudeCodeAdapterShape["sendTurn"] = (input) => |
| 222 | runtime.sendTurn(input).pipe( | 216 | runtime |
| 223 | Effect.mapError((cause) => toRequestError(input.sessionId, "turn/start", cause)), | 217 | .sendTurn(input) |
| 224 | ); | 218 | .pipe(Effect.mapError((cause) => toRequestError(input.sessionId, "turn/start", cause))); |
| 225 | | 219 | |
| 226 | const interruptTurn: ClaudeCodeAdapterShape["interruptTurn"] = (sessionId, turnId) => | 220 | const interruptTurn: ClaudeCodeAdapterShape["interruptTurn"] = (sessionId, turnId) => |
| 227 | runtime.interruptTurn(sessionId, turnId).pipe( | 221 | runtime |
| 228 | Effect.mapError((cause) => toRequestError(sessionId, "turn/interrupt", cause)), | 222 | .interruptTurn(sessionId, turnId) |
| 229 | ); | 223 | .pipe(Effect.mapError((cause) => toRequestError(sessionId, "turn/interrupt", cause))); |
| 230 | | 224 | |
| 231 | const readThread: ClaudeCodeAdapterShape["readThread"] = (sessionId) => | 225 | const readThread: ClaudeCodeAdapterShape["readThread"] = (sessionId) => |
| 232 | runtime.readThread(sessionId).pipe( | 226 | runtime |
| 233 | Effect.mapError((cause) => toRequestError(sessionId, "thread/read", cause)), | 227 | .readThread(sessionId) |
| 234 | ); | 228 | .pipe(Effect.mapError((cause) => toRequestError(sessionId, "thread/read", cause))); |
| 235 | | 229 | |
| 236 | const rollbackThread: ClaudeCodeAdapterShape["rollbackThread"] = (sessionId, numTurns) => { | 230 | const rollbackThread: ClaudeCodeAdapterShape["rollbackThread"] = (sessionId, numTurns) => { |
| 237 | if (!Number.isInteger(numTurns) || numTurns < 1) { | 231 | if (!Number.isInteger(numTurns) || numTurns < 1) { |
| ... | @@ -244,9 +238,9 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => | ... | @@ -244,9 +238,9 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => |
| 244 | ); | 238 | ); |
| 245 | } | 239 | } |
| 246 | | 240 | |
| 247 | return runtime.rollbackThread(sessionId, numTurns).pipe( | 241 | return runtime |
| 248 | Effect.mapError((cause) => toRequestError(sessionId, "thread/rollback", cause)), | 242 | .rollbackThread(sessionId, numTurns) |
| 249 | ); | 243 | .pipe(Effect.mapError((cause) => toRequestError(sessionId, "thread/rollback", cause))); |
| 250 | }; | 244 | }; |
| 251 | | 245 | |
| 252 | const respondToRequest: ClaudeCodeAdapterShape["respondToRequest"] = ( | 246 | const respondToRequest: ClaudeCodeAdapterShape["respondToRequest"] = ( |
| ... | @@ -254,15 +248,21 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => | ... | @@ -254,15 +248,21 @@ const makeClaudeCodeAdapter = (options?: ClaudeCodeAdapterLiveOptions) => |
| 254 | requestId, | 248 | requestId, |
| 255 | decision, | 249 | decision, |
| 256 | ) => | 250 | ) => |
| 257 | runtime.respondToRequest(sessionId, requestId, decision).pipe( | 251 | runtime |
| 258 | Effect.mapError((cause) => toRequestError(sessionId, "item/requestApproval/decision", cause)), | 252 | .respondToRequest(sessionId, requestId, decision) |
| 259 | ); | 253 | .pipe( |
| | 254 | Effect.mapError((cause) => |
| | 255 | toRequestError(sessionId, "item/requestApproval/decision", cause), |
| | 256 | ), |
| | 257 | ); |
| 260 | | 258 | |
| 261 | const stopSession: ClaudeCodeAdapterShape["stopSession"] = (sessionId) => runtime.stopSession(sessionId); | 259 | const stopSession: ClaudeCodeAdapterShape["stopSession"] = (sessionId) => |
| | 260 | runtime.stopSession(sessionId); |
| 262 | | 261 | |
| 263 | const listSessions: ClaudeCodeAdapterShape["listSessions"] = () => runtime.listSessions(); | 262 | const listSessions: ClaudeCodeAdapterShape["listSessions"] = () => runtime.listSessions(); |
| 264 | | 263 | |
| 265 | const hasSession: ClaudeCodeAdapterShape["hasSession"] = (sessionId) => runtime.hasSession(sessionId); | 264 | const hasSession: ClaudeCodeAdapterShape["hasSession"] = (sessionId) => |
| | 265 | runtime.hasSession(sessionId); |
| 266 | | 266 | |
| 267 | const stopAll: ClaudeCodeAdapterShape["stopAll"] = () => runtime.stopAll(); | 267 | const stopAll: ClaudeCodeAdapterShape["stopAll"] = () => runtime.stopAll(); |
| 268 | | 268 | |