| 1 | import type * as lexr from "@distilled.cloud/aws/lex-runtime-v2"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { BotAlias } from "./BotAlias.ts"; |
| 5 | |
| 6 | /** |
| 7 | * The `RecognizeText` request with the binding-injected `botId` and |
| 8 | * `botAliasId` removed. `localeId` selects the conversation language and |
| 9 | * `sessionId` identifies the conversation — both remain caller-supplied. |
| 10 | */ |
| 11 | export interface RecognizeTextRequest extends Omit< |
| 12 | lexr.RecognizeTextRequest, |
| 13 | "botId" | "botAliasId" |
| 14 | > {} |
| 15 | |
| 16 | /** |
| 17 | * Runtime binding for `lex:RecognizeText` — send user text to an Amazon Lex |
| 18 | * V2 bot alias and receive the interpreted intent and response messages. |
| 19 | * |
| 20 | * The alias must point at a built bot version (see `BotVersion`). |
| 21 | * |
| 22 | * ### Conversing with a Bot |
| 23 | * **Example:** Recognize Text |
| 24 | * ```typescript |
| 25 | * // init |
| 26 | * const recognizeText = yield* AWS.LexV2.RecognizeText(alias); |
| 27 | * |
| 28 | * // runtime |
| 29 | * const reply = yield* recognizeText({ |
| 30 | * localeId: "en_US", |
| 31 | * sessionId: "user-123", |
| 32 | * text: "hello", |
| 33 | * }); |
| 34 | * const intent = reply.sessionState?.intent?.name; |
| 35 | * ``` |
| 36 | * |
| 37 | * **Example:** Wire into a Lambda Function |
| 38 | * ```typescript |
| 39 | * // Bind the alias in the init phase, call in the handler, and provide |
| 40 | * // the RecognizeTextHttp layer on the Function's init Effect. |
| 41 | * export default ChatFunction.make( |
| 42 | * { main: import.meta.url, functionUrl: true }, |
| 43 | * Effect.gen(function* () { |
| 44 | * const alias = yield* AWS.LexV2.BotAlias("Live", { |
| 45 | * botId: version.botId, |
| 46 | * botVersion: version.botVersion, |
| 47 | * }); |
| 48 | * const recognizeText = yield* AWS.LexV2.RecognizeText(alias); |
| 49 | * return { |
| 50 | * fetch: Effect.gen(function* () { |
| 51 | * const reply = yield* recognizeText({ |
| 52 | * localeId: "en_US", |
| 53 | * sessionId: "user-123", |
| 54 | * text: "hello", |
| 55 | * }); |
| 56 | * return HttpServerResponse.json({ |
| 57 | * intent: reply.sessionState?.intent?.name ?? null, |
| 58 | * }); |
| 59 | * }), |
| 60 | * }; |
| 61 | * }).pipe(Effect.provide(AWS.LexV2.RecognizeTextHttp)), |
| 62 | * ); |
| 63 | * ``` |
| 64 | * |
| 65 | * @binding |
| 66 | */ |
| 67 | export interface RecognizeText extends Binding.Service< |
| 68 | RecognizeText, |
| 69 | "AWS.LexV2.RecognizeText", |
| 70 | ( |
| 71 | alias: BotAlias, |
| 72 | ) => Effect.Effect< |
| 73 | ( |
| 74 | request: RecognizeTextRequest, |
| 75 | ) => Effect.Effect<lexr.RecognizeTextResponse, lexr.RecognizeTextError> |
| 76 | > |
| 77 | > {} |
| 78 | |
| 79 | export const RecognizeText = Binding.Service<RecognizeText>( |
| 80 | "AWS.LexV2.RecognizeText", |
| 81 | ); |