The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as agentcore from "@distilled.cloud/aws/bedrock-agentcore"; |
| 2 | import { toWireSeconds } from "alchemy/Util/Duration"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as AWSBindings from "../AWSBindings.ts"; |
| 6 | import type { CodeInterpreter } from "./CodeInterpreter.ts"; |
| 7 | import { |
| 8 | StartCodeInterpreterSession, |
| 9 | type StartCodeInterpreterSessionRequest, |
| 10 | } from "./StartCodeInterpreterSession.ts"; |
| 11 | |
| 12 | // Bespoke (not the shared scaffold): converts the ergonomic `sessionTimeout` |
| 13 | // Duration.Input to the wire `sessionTimeoutSeconds` field. |
| 14 | export const StartCodeInterpreterSessionHttp = Layer.effect( |
| 15 | StartCodeInterpreterSession, |
| 16 | Effect.gen(function* () { |
| 17 | const bind = yield* AWSBindings.Bind; |
| 18 | const startCodeInterpreterSession = yield* AWSBindings.withCredentials( |
| 19 | agentcore.startCodeInterpreterSession, |
| 20 | ); |
| 21 | |
| 22 | return Effect.fn(function* <R extends CodeInterpreter>(codeInterpreter: R) { |
| 23 | const Identifier = yield* codeInterpreter.codeInterpreterId; |
| 24 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 25 | yield* bind`AWS.BedrockAgentCore.StartCodeInterpreterSession(${codeInterpreter})`({ |
| 26 | policyStatements: [ |
| 27 | { |
| 28 | Effect: "Allow", |
| 29 | Action: ["bedrock-agentcore:StartCodeInterpreterSession"], |
| 30 | Resource: [codeInterpreter.codeInterpreterArn], |
| 31 | }, |
| 32 | ], |
| 33 | }); |
| 34 | } |
| 35 | return Effect.fn( |
| 36 | `AWS.BedrockAgentCore.StartCodeInterpreterSession(${codeInterpreter.LogicalId})`, |
| 37 | )(function* ({ sessionTimeout, ...request }: StartCodeInterpreterSessionRequest) { |
| 38 | return yield* startCodeInterpreterSession({ |
| 39 | ...request, |
| 40 | sessionTimeoutSeconds: toWireSeconds(sessionTimeout), |
| 41 | codeInterpreterIdentifier: yield* Identifier, |
| 42 | }); |
| 43 | }); |
| 44 | }); |
| 45 | }), |
| 46 | ); |