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

main
ts 355 lines 11.6 KB
Raw
1 import type * as Effect from "effect/Effect";
2 import type * as Stream from "effect/Stream";
3 import {
4 consumeBusEvents,
5 type EventRecord,
6 type EventRouteProps,
7 } from "../EventBridge/EventSource.ts";
8
9 /**
10 * The `detail` payload Amazon Transcribe delivers to EventBridge when a
11 * batch transcription job finishes (`Transcribe Job State Change`, statuses
12 * `COMPLETED` and `FAILED` only — Transcribe does not emit intermediate
13 * states).
14 */
15 export interface TranscriptionJobEventDetail {
16 /** The transcription job's name. */
17 TranscriptionJobName?: string;
18 /** The terminal status: `COMPLETED` or `FAILED`. */
19 TranscriptionJobStatus?: string;
20 /** Why the job failed — only present on `FAILED` events. */
21 FailureReason?: string;
22 /** Additional event fields (the schema grows over time). */
23 [key: string]: unknown;
24 }
25
26 /** A Transcribe job EventBridge event delivered to the handler. */
27 export type TranscriptionJobEvent = EventRecord<TranscriptionJobEventDetail>;
28
29 /**
30 * The `detail` payload for `Call Analytics Job State Change` events.
31 */
32 export interface CallAnalyticsJobEventDetail {
33 /** The Call Analytics job's name. */
34 JobName?: string;
35 /** The terminal status: `COMPLETED` or `FAILED`. */
36 JobStatus?: string;
37 /** Why the job failed — only present on `FAILED` events. */
38 FailureReason?: string;
39 /** Additional event fields (the schema grows over time). */
40 [key: string]: unknown;
41 }
42
43 /** A Call Analytics job EventBridge event delivered to the handler. */
44 export type CallAnalyticsJobEvent = EventRecord<CallAnalyticsJobEventDetail>;
45
46 /**
47 * The `detail` payload for `Medical Scribe Job State Change` events.
48 */
49 export interface MedicalScribeJobEventDetail {
50 /** The Medical Scribe job's name. */
51 MedicalScribeJobName?: string;
52 /** The terminal status: `COMPLETED` or `FAILED`. */
53 MedicalScribeJobStatus?: string;
54 /** Why the job failed — only present on `FAILED` events. */
55 FailureReason?: string;
56 /** Additional event fields (the schema grows over time). */
57 [key: string]: unknown;
58 }
59
60 /** A Medical Scribe job EventBridge event delivered to the handler. */
61 export type MedicalScribeJobEvent = EventRecord<MedicalScribeJobEventDetail>;
62
63 /**
64 * The `detail` payload for `Vocabulary State Change` events (custom
65 * vocabulary processing finished).
66 */
67 export interface VocabularyEventDetail {
68 /** The custom vocabulary's name. */
69 VocabularyName?: string;
70 /** The terminal state: `READY` or `FAILED`. */
71 VocabularyState?: string;
72 /** Why processing failed — only present on `FAILED` events. */
73 FailureReason?: string;
74 /** Additional event fields (the schema grows over time). */
75 [key: string]: unknown;
76 }
77
78 /** A vocabulary EventBridge event delivered to the handler. */
79 export type VocabularyEvent = EventRecord<VocabularyEventDetail>;
80
81 /**
82 * The `detail` payload for `Language Model State Change` events (custom
83 * language model training finished).
84 */
85 export interface LanguageModelEventDetail {
86 /** The custom language model's name. */
87 ModelName?: string;
88 /** The terminal status: `COMPLETED` or `FAILED`. */
89 ModelStatus?: string;
90 /** Why training failed — only present on `FAILED` events. */
91 FailureReason?: string;
92 /** Additional event fields (the schema grows over time). */
93 [key: string]: unknown;
94 }
95
96 /** A language model EventBridge event delivered to the handler. */
97 export type LanguageModelEvent = EventRecord<LanguageModelEventDetail>;
98
99 export interface TranscriptionJobEventSourceProps extends EventRouteProps {
100 /**
101 * Logical id for the backing EventBridge rule.
102 * @default "TranscribeJobEvents"
103 */
104 id?: string;
105 /**
106 * Only deliver events with these `detail.TranscriptionJobStatus` values
107 * (e.g. `["COMPLETED"]`).
108 * @default all statuses
109 */
110 statuses?: readonly string[];
111 }
112
113 /**
114 * Event source connecting Amazon Transcribe batch job completions to the
115 * hosting compute. Transcribe publishes a `Transcribe Job State Change`
116 * event (source `aws.transcribe`) to the account's default EventBridge bus
117 * when a batch transcription job reaches `COMPLETED` or `FAILED`; this
118 * subscribes the host Function to those events so it can chain
119 * post-transcription processing without polling {@link GetTranscriptionJob}.
120 *
121 * Transcribe publishes to EventBridge automatically — no additional
122 * resource is created besides the EventBridge rule targeting the host.
123 * Provide the host-specific implementation layer (e.g.
124 * `AWS.Lambda.EventSource`) on the Function effect.
125 *
126 * ### Consuming Job Events
127 * **Example:** React To Finished Transcriptions
128 * ```typescript
129 * import * as AWS from "@alchemy.run/aws";
130 *
131 * export default TranscriptReactor.make(
132 * { main: import.meta.url },
133 * Effect.gen(function* () {
134 * yield* AWS.Transcribe.consumeTranscriptionJobEvents(
135 * { statuses: ["COMPLETED", "FAILED"] },
136 * (events) =>
137 * Stream.runForEach(events, (event) =>
138 * event.detail.TranscriptionJobStatus === "FAILED"
139 * ? Effect.log(`job ${event.detail.TranscriptionJobName} failed: ${event.detail.FailureReason}`)
140 * : Effect.log(`job ${event.detail.TranscriptionJobName} complete`),
141 * ),
142 * );
143 * return {};
144 * }).pipe(Effect.provide(AWS.Lambda.EventSource)),
145 * );
146 * ```
147 */
148 export const consumeTranscriptionJobEvents = <StreamReq = never, Req = never>(
149 props: TranscriptionJobEventSourceProps,
150 process: (
151 events: Stream.Stream<TranscriptionJobEvent, never, StreamReq>,
152 ) => Effect.Effect<void, never, Req>,
153 ) =>
154 consumeBusEvents(
155 props.id ?? "TranscribeJobEvents",
156 {
157 source: ["aws.transcribe"],
158 "detail-type": ["Transcribe Job State Change"],
159 ...(props.statuses ? { detail: { TranscriptionJobStatus: [...props.statuses] } } : {}),
160 },
161 { description: props.description, state: props.state },
162 process,
163 );
164
165 export interface CallAnalyticsJobEventSourceProps extends EventRouteProps {
166 /**
167 * Logical id for the backing EventBridge rule.
168 * @default "TranscribeCallAnalyticsJobEvents"
169 */
170 id?: string;
171 /**
172 * Only deliver events with these `detail.JobStatus` values.
173 * @default all statuses
174 */
175 statuses?: readonly string[];
176 }
177
178 /**
179 * Event source for Amazon Transcribe `Call Analytics Job State Change`
180 * events (source `aws.transcribe`) — fires when a Call Analytics job
181 * reaches `COMPLETED` or `FAILED`.
182 *
183 * ### Consuming Job Events
184 * **Example:** React To Finished Call Analytics Jobs
185 * ```typescript
186 * yield* AWS.Transcribe.consumeCallAnalyticsJobEvents(
187 * { statuses: ["COMPLETED"] },
188 * (events) =>
189 * Stream.runForEach(events, (event) =>
190 * Effect.log(`call ${event.detail.JobName} analyzed`),
191 * ),
192 * );
193 * ```
194 */
195 export const consumeCallAnalyticsJobEvents = <StreamReq = never, Req = never>(
196 props: CallAnalyticsJobEventSourceProps,
197 process: (
198 events: Stream.Stream<CallAnalyticsJobEvent, never, StreamReq>,
199 ) => Effect.Effect<void, never, Req>,
200 ) =>
201 consumeBusEvents(
202 props.id ?? "TranscribeCallAnalyticsJobEvents",
203 {
204 source: ["aws.transcribe"],
205 "detail-type": ["Call Analytics Job State Change"],
206 ...(props.statuses ? { detail: { JobStatus: [...props.statuses] } } : {}),
207 },
208 { description: props.description, state: props.state },
209 process,
210 );
211
212 export interface MedicalScribeJobEventSourceProps extends EventRouteProps {
213 /**
214 * Logical id for the backing EventBridge rule.
215 * @default "TranscribeMedicalScribeJobEvents"
216 */
217 id?: string;
218 /**
219 * Only deliver events with these `detail.MedicalScribeJobStatus` values.
220 * @default all statuses
221 */
222 statuses?: readonly string[];
223 }
224
225 /**
226 * Event source for AWS HealthScribe `Medical Scribe Job State Change`
227 * events (source `aws.transcribe`) — fires when a Medical Scribe job
228 * reaches `COMPLETED` or `FAILED`.
229 *
230 * ### Consuming Job Events
231 * **Example:** React To Finished Medical Scribe Jobs
232 * ```typescript
233 * yield* AWS.Transcribe.consumeMedicalScribeJobEvents(
234 * { statuses: ["COMPLETED"] },
235 * (events) =>
236 * Stream.runForEach(events, (event) =>
237 * Effect.log(`visit ${event.detail.MedicalScribeJobName} summarized`),
238 * ),
239 * );
240 * ```
241 */
242 export const consumeMedicalScribeJobEvents = <StreamReq = never, Req = never>(
243 props: MedicalScribeJobEventSourceProps,
244 process: (
245 events: Stream.Stream<MedicalScribeJobEvent, never, StreamReq>,
246 ) => Effect.Effect<void, never, Req>,
247 ) =>
248 consumeBusEvents(
249 props.id ?? "TranscribeMedicalScribeJobEvents",
250 {
251 source: ["aws.transcribe"],
252 "detail-type": ["Medical Scribe Job State Change"],
253 ...(props.statuses ? { detail: { MedicalScribeJobStatus: [...props.statuses] } } : {}),
254 },
255 { description: props.description, state: props.state },
256 process,
257 );
258
259 export interface VocabularyEventSourceProps extends EventRouteProps {
260 /**
261 * Logical id for the backing EventBridge rule.
262 * @default "TranscribeVocabularyEvents"
263 */
264 id?: string;
265 /**
266 * Only deliver events with these `detail.VocabularyState` values
267 * (e.g. `["READY"]`).
268 * @default all states
269 */
270 states?: readonly string[];
271 }
272
273 /**
274 * Event source for Amazon Transcribe `Vocabulary State Change` events
275 * (source `aws.transcribe`) — fires when custom vocabulary processing
276 * reaches `READY` or `FAILED`, so runtime-created vocabularies (e.g.
277 * per-tenant via {@link CreateVocabulary}) can be used the moment they are
278 * ready.
279 *
280 * ### Consuming Job Events
281 * **Example:** React To Ready Vocabularies
282 * ```typescript
283 * yield* AWS.Transcribe.consumeVocabularyEvents(
284 * { states: ["READY"] },
285 * (events) =>
286 * Stream.runForEach(events, (event) =>
287 * Effect.log(`vocabulary ${event.detail.VocabularyName} ready`),
288 * ),
289 * );
290 * ```
291 */
292 export const consumeVocabularyEvents = <StreamReq = never, Req = never>(
293 props: VocabularyEventSourceProps,
294 process: (
295 events: Stream.Stream<VocabularyEvent, never, StreamReq>,
296 ) => Effect.Effect<void, never, Req>,
297 ) =>
298 consumeBusEvents(
299 props.id ?? "TranscribeVocabularyEvents",
300 {
301 source: ["aws.transcribe"],
302 "detail-type": ["Vocabulary State Change"],
303 ...(props.states ? { detail: { VocabularyState: [...props.states] } } : {}),
304 },
305 { description: props.description, state: props.state },
306 process,
307 );
308
309 export interface LanguageModelEventSourceProps extends EventRouteProps {
310 /**
311 * Logical id for the backing EventBridge rule.
312 * @default "TranscribeLanguageModelEvents"
313 */
314 id?: string;
315 /**
316 * Only deliver events with these `detail.ModelStatus` values.
317 * @default all statuses
318 */
319 statuses?: readonly string[];
320 }
321
322 /**
323 * Event source for Amazon Transcribe `Language Model State Change` events
324 * (source `aws.transcribe`) — fires when custom language model training
325 * (started with {@link CreateLanguageModel}) reaches `COMPLETED` or
326 * `FAILED`.
327 *
328 * ### Consuming Job Events
329 * **Example:** React To Trained Language Models
330 * ```typescript
331 * yield* AWS.Transcribe.consumeLanguageModelEvents(
332 * { statuses: ["COMPLETED"] },
333 * (events) =>
334 * Stream.runForEach(events, (event) =>
335 * Effect.log(`model ${event.detail.ModelName} trained`),
336 * ),
337 * );
338 * ```
339 */
340 export const consumeLanguageModelEvents = <StreamReq = never, Req = never>(
341 props: LanguageModelEventSourceProps,
342 process: (
343 events: Stream.Stream<LanguageModelEvent, never, StreamReq>,
344 ) => Effect.Effect<void, never, Req>,
345 ) =>
346 consumeBusEvents(
347 props.id ?? "TranscribeLanguageModelEvents",
348 {
349 source: ["aws.transcribe"],
350 "detail-type": ["Language Model State Change"],
351 ...(props.statuses ? { detail: { ModelStatus: [...props.statuses] } } : {}),
352 },
353 { description: props.description, state: props.state },
354 process,
355 );