| 1 | import type * as bedrock from "@distilled.cloud/aws/bedrock-agent"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { DataSource } from "./DataSource.ts"; |
| 5 | |
| 6 | /** |
| 7 | * The `GetIngestionJob` request with the binding-injected `knowledgeBaseId` |
| 8 | * and `dataSourceId` removed — they are supplied automatically from the |
| 9 | * bound {@link DataSource}. |
| 10 | */ |
| 11 | export interface GetIngestionJobRequest extends Omit< |
| 12 | bedrock.GetIngestionJobRequest, |
| 13 | "knowledgeBaseId" | "dataSourceId" |
| 14 | > {} |
| 15 | |
| 16 | /** |
| 17 | * Runtime binding for `bedrock-agent:GetIngestionJob` — read the status and |
| 18 | * statistics of an ingestion job started on the bound {@link DataSource}. |
| 19 | * |
| 20 | * The binding grants the function `bedrock:GetIngestionJob` scoped to the |
| 21 | * data source's parent knowledge base. |
| 22 | * |
| 23 | * ### Syncing a Data Source |
| 24 | * **Example:** Poll an Ingestion Job to Completion |
| 25 | * ```typescript |
| 26 | * // init |
| 27 | * const getIngestionJob = yield* Bedrock.GetIngestionJob(dataSource); |
| 28 | * |
| 29 | * // runtime |
| 30 | * const { ingestionJob } = yield* getIngestionJob({ |
| 31 | * ingestionJobId: jobId, |
| 32 | * }).pipe( |
| 33 | * Effect.repeat({ |
| 34 | * schedule: Schedule.spaced("5 seconds"), |
| 35 | * until: (r) => |
| 36 | * r.ingestionJob.status === "COMPLETE" || |
| 37 | * r.ingestionJob.status === "FAILED", |
| 38 | * times: 36, |
| 39 | * }), |
| 40 | * ); |
| 41 | * ``` |
| 42 | * |
| 43 | * @binding |
| 44 | */ |
| 45 | export interface GetIngestionJob extends Binding.Service< |
| 46 | GetIngestionJob, |
| 47 | "AWS.Bedrock.GetIngestionJob", |
| 48 | <D extends DataSource>( |
| 49 | dataSource: D, |
| 50 | ) => Effect.Effect< |
| 51 | ( |
| 52 | request: GetIngestionJobRequest, |
| 53 | ) => Effect.Effect< |
| 54 | bedrock.GetIngestionJobResponse, |
| 55 | bedrock.GetIngestionJobError |
| 56 | > |
| 57 | > |
| 58 | > {} |
| 59 | export const GetIngestionJob = Binding.Service<GetIngestionJob>( |
| 60 | "AWS.Bedrock.GetIngestionJob", |
| 61 | ); |