1import type * as agentcore from "@distilled.cloud/aws/bedrock-agentcore";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Runtime } from "./Runtime.ts";
5
6export interface InvokeAgentRuntimeCommandRequest extends Omit<
7 agentcore.InvokeAgentRuntimeCommandRequest,
8 "agentRuntimeArn"
9> {}
10
11/**
12 * Runs a shell command inside an agent hosted in an AgentCore Runtime and
13 * streams back the command output.
14 *
15 * Bind a {@link Runtime} inside a function runtime to execute commands in
16 * the hosted agent's sandbox (requests with the same `runtimeSessionId`
17 * land on the same sandbox). Provide
18 * `AgentCore.InvokeAgentRuntimeCommandHttp` on the Function effect to
19 * implement the binding.
20 *
21 * ### Invoking an Agent
22 * **Example:** Run a Command in a Hosted Agent
23 * ```typescript
24 * // init
25 * const invokeCommand = yield* AgentCore.InvokeAgentRuntimeCommand(runtime);
26 *
27 * return {
28 * fetch: Effect.gen(function* () {
29 * // runtime
30 * const response = yield* invokeCommand({
31 * runtimeSessionId: "session-0000000000000000000000000000000001",
32 * body: { command: "echo hello" },
33 * });
34 * const chunks = yield* Stream.runCollect(response.stream);
35 * return HttpServerResponse.json({ chunks: Array.from(chunks) });
36 * }),
37 * };
38 * ```
39 *
40 * @binding
41 */
42export interface InvokeAgentRuntimeCommand extends Binding.Service<
43 InvokeAgentRuntimeCommand,
44 "AWS.BedrockAgentCore.InvokeAgentRuntimeCommand",
45 <R extends Runtime>(
46 runtime: R,
47 ) => Effect.Effect<
48 (
49 request: InvokeAgentRuntimeCommandRequest,
50 ) => Effect.Effect<
51 agentcore.InvokeAgentRuntimeCommandResponse,
52 agentcore.InvokeAgentRuntimeCommandError
53 >
54 >
55> {}
56export const InvokeAgentRuntimeCommand =
57 Binding.Service<InvokeAgentRuntimeCommand>(
58 "AWS.BedrockAgentCore.InvokeAgentRuntimeCommand",
59 );