@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 41 lines 1.26 KB
Raw
1 import * as ml from "@distilled.cloud/gcp/ml_v1";
2 import * as Effect from "effect/Effect";
3 import { waitForOperation as waitForGcpOperation } from "../Operation.ts";
4
5 const getOperation = (name: string) =>
6 name.includes("/locations/")
7 ? ml.getProjectsLocationsOperations({ name })
8 : ml.getProjectsOperations({ name });
9
10 /**
11 * Wait for an AI Platform (ML Engine) operation. Version deploys take
12 * several minutes. An operation that finished with `ALREADY_EXISTS` (6) is
13 * a lost create race; `notFoundOk` also accepts `NOT_FOUND` (5).
14 */
15 export const waitForOperation = (
16 operation: ml.GoogleLongrunning__Operation,
17 options?: { notFoundOk?: boolean },
18 ) =>
19 waitForGcpOperation(
20 operation,
21 (name) =>
22 getOperation(name).pipe(
23 Effect.catchTag("NotFound", (error) =>
24 options?.notFoundOk === true
25 ? Effect.succeed<ml.GoogleLongrunning__Operation>({
26 name,
27 done: true,
28 })
29 : Effect.fail(error),
30 ),
31 ),
32 { budget: "20 minutes" },
33 ).pipe(
34 Effect.catchIf(
35 (error) =>
36 error._tag === "GCP.OperationFailed" &&
37 (error.code === 6 || (options?.notFoundOk === true && error.code === 5)),
38 () => Effect.void,
39 ),
40 Effect.asVoid,
41 );