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

main
ts 66 lines 2.41 KB
Raw
1 import type * as bedrock from "@distilled.cloud/aws/bedrock-runtime";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4
5 /**
6 * The `ConverseStream` request with the binding-injected `modelId` made
7 * optional: it defaults to the first bound model id and may be overridden
8 * per call with any of the bound model ids.
9 */
10 export interface ConverseStreamRequest extends Omit<bedrock.ConverseStreamRequest, "modelId"> {
11 /**
12 * The model to run inference on for this call. Must be one of the model
13 * ids the binding was created with (IAM is scoped to exactly those).
14 * @default the first bound model id
15 */
16 modelId?: string;
17 }
18
19 /**
20 * Runtime binding for `bedrock-runtime:ConverseStream` — the streaming
21 * variant of {@link Converse}. The response arrives as an event `Stream` of
22 * `ConverseStreamOutput` events (`messageStart`, `contentBlockDelta`,
23 * `messageStop`, `metadata`, ...) instead of a single message.
24 *
25 * The binding grants the function `bedrock:InvokeModelWithResponseStream`
26 * (the IAM action streaming operations authorize against) scoped to exactly
27 * the bound models. A model reference may be a foundation-model id, a
28 * cross-region inference profile id (e.g. `us.amazon.nova-micro-v1:0`), or a
29 * full Bedrock ARN.
30 *
31 * Model access is an account entitlement — enable the model in the Bedrock
32 * console (Model access) before invoking, otherwise calls fail with
33 * `AccessDeniedException`.
34 *
35 * ### Streaming a Conversation
36 * **Example:** Aggregate Streamed Text Deltas
37 * ```typescript
38 * // init
39 * const converseStream = yield* Bedrock.ConverseStream("us.amazon.nova-micro-v1:0");
40 *
41 * // runtime
42 * const result = yield* converseStream({
43 * messages: [{ role: "user", content: [{ text: "Say hello." }] }],
44 * inferenceConfig: { maxTokens: 64 },
45 * });
46 * const events = yield* Stream.runCollect(result.stream ?? Stream.empty);
47 * const text = events
48 * .map((event) => event.contentBlockDelta?.delta.text ?? "")
49 * .join("");
50 * ```
51 *
52 * @binding
53 */
54 export interface ConverseStream extends Binding.Service<
55 ConverseStream,
56 "AWS.Bedrock.ConverseStream",
57 (
58 model: string,
59 ...additionalModels: string[]
60 ) => Effect.Effect<
61 (
62 request: ConverseStreamRequest,
63 ) => Effect.Effect<bedrock.ConverseStreamResponse, bedrock.ConverseStreamError>
64 >
65 > {}
66 export const ConverseStream = Binding.Service<ConverseStream>("AWS.Bedrock.ConverseStream");