@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 41 lines 1.64 KB
Raw
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 { BrowserCustom } from "./BrowserCustom.ts";
7 import { StartBrowserSession, type StartBrowserSessionRequest } from "./StartBrowserSession.ts";
8
9 // Bespoke (not the shared scaffold): converts the ergonomic `sessionTimeout`
10 // Duration.Input to the wire `sessionTimeoutSeconds` field.
11 export const StartBrowserSessionHttp = Layer.effect(
12 StartBrowserSession,
13 Effect.gen(function* () {
14 const bind = yield* AWSBindings.Bind;
15 const startBrowserSession = yield* AWSBindings.withCredentials(agentcore.startBrowserSession);
16
17 return Effect.fn(function* <R extends BrowserCustom>(browser: R) {
18 const Identifier = yield* browser.browserId;
19 if (!globalThis.__ALCHEMY_RUNTIME__) {
20 yield* bind`AWS.BedrockAgentCore.StartBrowserSession(${browser})`({
21 policyStatements: [
22 {
23 Effect: "Allow",
24 Action: ["bedrock-agentcore:StartBrowserSession"],
25 Resource: [browser.browserArn],
26 },
27 ],
28 });
29 }
30 return Effect.fn(`AWS.BedrockAgentCore.StartBrowserSession(${browser.LogicalId})`)(
31 function* ({ sessionTimeout, ...request }: StartBrowserSessionRequest) {
32 return yield* startBrowserSession({
33 ...request,
34 sessionTimeoutSeconds: toWireSeconds(sessionTimeout),
35 browserIdentifier: yield* Identifier,
36 });
37 },
38 );
39 });
40 }),
41 );