| 1 | import type * as agentcore from "@distilled.cloud/aws/bedrock-agentcore"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { CodeInterpreter } from "./CodeInterpreter.ts"; |
| 5 | |
| 6 | export interface InvokeCodeInterpreterRequest extends Omit< |
| 7 | agentcore.InvokeCodeInterpreterRequest, |
| 8 | "codeInterpreterIdentifier" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Executes a tool (e.g. `executeCode`) inside a code interpreter session. |
| 13 | * The response carries a result stream. |
| 14 | * |
| 15 | * Bind a {@link CodeInterpreter} inside a function runtime and call it with |
| 16 | * a session id obtained from `StartCodeInterpreterSession`. Provide |
| 17 | * `AgentCore.InvokeCodeInterpreterHttp` on the Function effect to implement |
| 18 | * the binding. |
| 19 | * |
| 20 | * ### Executing Code |
| 21 | * **Example:** Run Python in a Session |
| 22 | * ```typescript |
| 23 | * // init |
| 24 | * const invoke = yield* AgentCore.InvokeCodeInterpreter(interpreter); |
| 25 | * |
| 26 | * // runtime (inside the handler, with an open session) |
| 27 | * const result = yield* invoke({ |
| 28 | * sessionId: session.sessionId, |
| 29 | * name: "executeCode", |
| 30 | * arguments: { language: "python", code: "print(21 * 2)" }, |
| 31 | * }); |
| 32 | * const chunks = yield* Stream.runCollect(result.stream); |
| 33 | * ``` |
| 34 | * |
| 35 | * @binding |
| 36 | */ |
| 37 | export interface InvokeCodeInterpreter extends Binding.Service< |
| 38 | InvokeCodeInterpreter, |
| 39 | "AWS.BedrockAgentCore.InvokeCodeInterpreter", |
| 40 | <R extends CodeInterpreter>( |
| 41 | codeInterpreter: R, |
| 42 | ) => Effect.Effect< |
| 43 | ( |
| 44 | request: InvokeCodeInterpreterRequest, |
| 45 | ) => Effect.Effect< |
| 46 | agentcore.InvokeCodeInterpreterResponse, |
| 47 | agentcore.InvokeCodeInterpreterError |
| 48 | > |
| 49 | > |
| 50 | > {} |
| 51 | export const InvokeCodeInterpreter = Binding.Service<InvokeCodeInterpreter>( |
| 52 | "AWS.BedrockAgentCore.InvokeCodeInterpreter", |
| 53 | ); |