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

main
ts 36 lines 1.34 KB
Raw
1 import * as ces from "@distilled.cloud/gcp/ces_v1";
2 import * as Effect from "effect/Effect";
3 import { waitForOperation as waitForLongRunning, type LongRunningOperation } from "../Operation.ts";
4
5 // A display-name clash ("App with display name … already exists") also reports
6 // ALREADY_EXISTS but means our resource was never created, so it must fail.
7
8 /** CES app and agent operations finish within a few minutes. */
9 const OPERATION_BUDGET = "10 minutes";
10
11 /**
12 * Wait for a long-running operation. ALREADY_EXISTS (code 6) means a
13 * concurrent create won the race; reconcile observes the resource next.
14 */
15 export const waitForOperation = (operation: LongRunningOperation) =>
16 waitForLongRunning(operation, (name) => ces.getProjectsLocationsOperations({ name }), {
17 budget: OPERATION_BUDGET,
18 }).pipe(
19 Effect.catchIf(
20 (error) => error._tag === "GCP.OperationFailed" && error.code === 6,
21 () => Effect.succeed(operation),
22 ),
23 );
24
25 /**
26 * Wait for a delete operation. A vanished operation or NOT_FOUND (code 5)
27 * means the resource is already gone.
28 */
29 export const waitForDeleteOperation = (operation: LongRunningOperation) =>
30 waitForOperation(operation).pipe(
31 Effect.catchIf(
32 (error) =>
33 error._tag === "NotFound" || (error._tag === "GCP.OperationFailed" && error.code === 5),
34 () => Effect.succeed(operation),
35 ),
36 );