The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as ccaip from "@distilled.cloud/gcp/contactcenteraiplatform_v1alpha1"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { waitForOperation as waitForLongRunning, type LongRunningOperation } from "../Operation.ts"; |
| 4 | |
| 5 | /** Contact center instance provisioning takes 30–45 minutes. */ |
| 6 | const OPERATION_BUDGET = "60 minutes"; |
| 7 | |
| 8 | /** |
| 9 | * Wait for a long-running operation. ALREADY_EXISTS (code 6) means a |
| 10 | * concurrent create won the race; reconcile observes the resource next. |
| 11 | */ |
| 12 | export const waitForOperation = (operation: LongRunningOperation) => |
| 13 | waitForLongRunning(operation, (name) => ccaip.getProjectsLocationsOperations({ name }), { |
| 14 | budget: OPERATION_BUDGET, |
| 15 | }).pipe( |
| 16 | Effect.catchIf( |
| 17 | (error) => error._tag === "GCP.OperationFailed" && error.code === 6, |
| 18 | () => Effect.succeed(operation), |
| 19 | ), |
| 20 | ); |
| 21 | |
| 22 | /** |
| 23 | * Wait for a delete operation. A vanished operation or NOT_FOUND (code 5) |
| 24 | * means the resource is already gone. |
| 25 | */ |
| 26 | export const waitForDeleteOperation = (operation: LongRunningOperation) => |
| 27 | waitForOperation(operation).pipe( |
| 28 | Effect.catchIf( |
| 29 | (error) => |
| 30 | error._tag === "NotFound" || (error._tag === "GCP.OperationFailed" && error.code === 5), |
| 31 | () => Effect.succeed(operation), |
| 32 | ), |
| 33 | ); |