| 1 | import type * as agentcore from "@distilled.cloud/aws/bedrock-agentcore"; |
| 2 | import type * as Duration from "effect/Duration"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import type { BrowserCustom } from "./BrowserCustom.ts"; |
| 6 | |
| 7 | export interface StartBrowserSessionRequest extends Omit< |
| 8 | agentcore.StartBrowserSessionRequest, |
| 9 | "browserIdentifier" | "sessionTimeoutSeconds" |
| 10 | > { |
| 11 | /** |
| 12 | * How long the session may sit idle before AgentCore terminates it, e.g. |
| 13 | * `"5 minutes"` or `Duration.minutes(5)` (a bare number is milliseconds). |
| 14 | */ |
| 15 | sessionTimeout?: Duration.Input; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Starts a managed, sandboxed browser session on a custom browser. |
| 20 | * |
| 21 | * Bind a {@link BrowserCustom} inside a function runtime to open cloud |
| 22 | * browser sessions for web automation; pair with `GetBrowserSession`, |
| 23 | * `InvokeBrowser`, and `StopBrowserSession`. Provide |
| 24 | * `AgentCore.StartBrowserSessionHttp` on the Function effect to implement |
| 25 | * the binding. |
| 26 | * |
| 27 | * ### Browser Sessions |
| 28 | * **Example:** Start and Stop a Browser Session |
| 29 | * ```typescript |
| 30 | * // init |
| 31 | * const startBrowserSession = yield* AgentCore.StartBrowserSession(browser); |
| 32 | * const stopBrowserSession = yield* AgentCore.StopBrowserSession(browser); |
| 33 | * |
| 34 | * return { |
| 35 | * fetch: Effect.gen(function* () { |
| 36 | * // runtime |
| 37 | * const session = yield* startBrowserSession({ |
| 38 | * sessionTimeout: "5 minutes", |
| 39 | * }); |
| 40 | * yield* stopBrowserSession({ sessionId: session.sessionId }); |
| 41 | * return HttpServerResponse.json({ sessionId: session.sessionId }); |
| 42 | * }), |
| 43 | * }; |
| 44 | * ``` |
| 45 | * |
| 46 | * @binding |
| 47 | */ |
| 48 | export interface StartBrowserSession extends Binding.Service< |
| 49 | StartBrowserSession, |
| 50 | "AWS.BedrockAgentCore.StartBrowserSession", |
| 51 | <R extends BrowserCustom>( |
| 52 | browser: R, |
| 53 | ) => Effect.Effect< |
| 54 | ( |
| 55 | request: StartBrowserSessionRequest, |
| 56 | ) => Effect.Effect< |
| 57 | agentcore.StartBrowserSessionResponse, |
| 58 | agentcore.StartBrowserSessionError |
| 59 | > |
| 60 | > |
| 61 | > {} |
| 62 | export const StartBrowserSession = Binding.Service<StartBrowserSession>( |
| 63 | "AWS.BedrockAgentCore.StartBrowserSession", |
| 64 | ); |