Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.6 kB · 45 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import { createAiGateway, GatewayNotFound, getAiGateway,} from "@distilled.cloud/cloudflare/ai-gateway";import { NotFound } from "@distilled.cloud/cloudflare/Errors";import * as Effect from "effect/Effect";import type { CloudflareAccount } from "./cloudflare-account.ts";import { ResourceConflict } from "./deployment-errors.ts";import { object } from "./deployment-values.ts";export function ensureModelGateway(client: CloudflareAccount) { return Effect.gen(function* () { const gatewayId = "default"; let gateway = yield* client.sdk( getAiGateway({ accountId: client.accountId, id: gatewayId }).pipe( Effect.catchIf( (error) => error instanceof NotFound || error instanceof GatewayNotFound, () => Effect.succeed(null), ), ), ); if (gateway === null) { yield* client.sdk( createAiGateway({ accountId: client.accountId, id: gatewayId, cacheInvalidateOnUpdate: true, cacheTtl: 0, collectLogs: false, rateLimitingInterval: 0, rateLimitingLimit: 0, authentication: true, }), ); gateway = yield* client.sdk( getAiGateway({ accountId: client.accountId, id: gatewayId }), ); } if (!object(gateway) || gateway.id !== gatewayId) return yield* new ResourceConflict(); // Gateways are account-shared. Preserve existing billing, logging, limits // and authentication settings rather than replacing them with our defaults. });}