| 1 | import type * as agentcore from "@distilled.cloud/aws/bedrock-agentcore"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Memory } from "./Memory.ts"; |
| 5 | |
| 6 | export interface CreateEventRequest extends Omit< |
| 7 | agentcore.CreateEventInput, |
| 8 | "memoryId" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Records an interaction event into a memory's short-term store. |
| 13 | * |
| 14 | * Bind a {@link Memory} inside a function runtime to get a callable that |
| 15 | * appends conversational turns (or binary blobs) to an actor's session. |
| 16 | * Provide `AgentCore.CreateEventHttp` on the Function effect to implement |
| 17 | * the binding over the AgentCore data-plane API. |
| 18 | * |
| 19 | * ### Recording Events |
| 20 | * **Example:** Record a Conversational Turn from a Lambda Function |
| 21 | * ```typescript |
| 22 | * import * as AgentCore from "alchemy/AWS/BedrockAgentCore"; |
| 23 | * |
| 24 | * export default MyFunction.make( |
| 25 | * { main: import.meta.url, functionUrl: true }, |
| 26 | * Effect.gen(function* () { |
| 27 | * const memory = yield* AgentCore.Memory("AgentMemory", { |
| 28 | * eventExpiryDuration: "30 days", |
| 29 | * }); |
| 30 | * |
| 31 | * // init |
| 32 | * const createEvent = yield* AgentCore.CreateEvent(memory); |
| 33 | * |
| 34 | * return { |
| 35 | * fetch: Effect.gen(function* () { |
| 36 | * // runtime |
| 37 | * const result = yield* createEvent({ |
| 38 | * actorId: "user-1", |
| 39 | * sessionId: "session-1", |
| 40 | * eventTimestamp: new Date(), |
| 41 | * payload: [ |
| 42 | * { |
| 43 | * conversational: { |
| 44 | * role: "USER", |
| 45 | * content: { text: "My favorite color is teal." }, |
| 46 | * }, |
| 47 | * }, |
| 48 | * ], |
| 49 | * }); |
| 50 | * return HttpServerResponse.json({ eventId: result.event.eventId }); |
| 51 | * }), |
| 52 | * }; |
| 53 | * }).pipe(Effect.provide(AgentCore.CreateEventHttp)), |
| 54 | * ); |
| 55 | * ``` |
| 56 | * |
| 57 | * @binding |
| 58 | */ |
| 59 | export interface CreateEvent extends Binding.Service< |
| 60 | CreateEvent, |
| 61 | "AWS.BedrockAgentCore.CreateEvent", |
| 62 | <R extends Memory>( |
| 63 | memory: R, |
| 64 | ) => Effect.Effect< |
| 65 | ( |
| 66 | request: CreateEventRequest, |
| 67 | ) => Effect.Effect<agentcore.CreateEventOutput, agentcore.CreateEventError> |
| 68 | > |
| 69 | > {} |
| 70 | export const CreateEvent = Binding.Service<CreateEvent>( |
| 71 | "AWS.BedrockAgentCore.CreateEvent", |
| 72 | ); |