| 1 | import type * as Lambda from "@distilled.cloud/aws/lambda"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Function } from "./Function.ts"; |
| 5 | |
| 6 | export interface InvokeWithResponseStreamRequest extends Omit< |
| 7 | Lambda.InvokeWithResponseStreamRequest, |
| 8 | "FunctionName" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `lambda:InvokeFunction` over the response-streaming |
| 13 | * API. Invokes the bound {@link Function} and returns the streaming |
| 14 | * response — `EventStream` yields `PayloadChunk` events followed by a final |
| 15 | * `InvokeComplete` event. |
| 16 | * |
| 17 | * Provide the `InvokeWithResponseStreamHttp` layer on the Function to |
| 18 | * satisfy the binding. |
| 19 | * ### Invoking Functions |
| 20 | * **Example:** Stream a function's response |
| 21 | * ```typescript |
| 22 | * const invokeStream = yield* AWS.Lambda.InvokeWithResponseStream(target); |
| 23 | * |
| 24 | * const response = yield* invokeStream({ |
| 25 | * Payload: new TextEncoder().encode(JSON.stringify({ prompt: "hi" })), |
| 26 | * }); |
| 27 | * const chunks = yield* Stream.runCollect(response.EventStream!); |
| 28 | * ``` |
| 29 | * |
| 30 | * @binding |
| 31 | */ |
| 32 | export interface InvokeWithResponseStream extends Binding.Service< |
| 33 | InvokeWithResponseStream, |
| 34 | "AWS.Lambda.InvokeWithResponseStream", |
| 35 | ( |
| 36 | func: Function, |
| 37 | ) => Effect.Effect< |
| 38 | ( |
| 39 | request?: InvokeWithResponseStreamRequest, |
| 40 | ) => Effect.Effect< |
| 41 | Lambda.InvokeWithResponseStreamResponse, |
| 42 | Lambda.InvokeWithResponseStreamError |
| 43 | > |
| 44 | > |
| 45 | > {} |
| 46 | export const InvokeWithResponseStream = |
| 47 | Binding.Service<InvokeWithResponseStream>( |
| 48 | "AWS.Lambda.InvokeWithResponseStream", |
| 49 | ); |