alchemy 2.0.0-beta.28 → 2.0.0-beta.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/bin/exec.js +98 -6
  2. package/bin/exec.js.map +1 -1
  3. package/lib/AWS/IAM/SAMLProvider.d.ts +2 -1
  4. package/lib/AWS/IAM/SAMLProvider.d.ts.map +1 -1
  5. package/lib/AWS/IAM/SAMLProvider.js +30 -9
  6. package/lib/AWS/IAM/SAMLProvider.js.map +1 -1
  7. package/lib/Apply.d.ts.map +1 -1
  8. package/lib/Apply.js +55 -11
  9. package/lib/Apply.js.map +1 -1
  10. package/lib/Cli/commands/bootstrap.d.ts +1 -1
  11. package/lib/Cli/commands/bootstrap.d.ts.map +1 -1
  12. package/lib/Cli/commands/bootstrap.js +2 -1
  13. package/lib/Cli/commands/bootstrap.js.map +1 -1
  14. package/lib/Cloudflare/Access.d.ts +19 -0
  15. package/lib/Cloudflare/Access.d.ts.map +1 -0
  16. package/lib/Cloudflare/Access.js +64 -0
  17. package/lib/Cloudflare/Access.js.map +1 -0
  18. package/lib/Cloudflare/AiGateway/AiGateway.d.ts +244 -0
  19. package/lib/Cloudflare/AiGateway/AiGateway.d.ts.map +1 -0
  20. package/lib/Cloudflare/AiGateway/AiGateway.js +269 -0
  21. package/lib/Cloudflare/AiGateway/AiGateway.js.map +1 -0
  22. package/lib/Cloudflare/AiGateway/AiGatewayBinding.d.ts +103 -0
  23. package/lib/Cloudflare/AiGateway/AiGatewayBinding.d.ts.map +1 -0
  24. package/lib/Cloudflare/AiGateway/AiGatewayBinding.js +99 -0
  25. package/lib/Cloudflare/AiGateway/AiGatewayBinding.js.map +1 -0
  26. package/lib/Cloudflare/AiGateway/index.d.ts +3 -0
  27. package/lib/Cloudflare/AiGateway/index.d.ts.map +1 -0
  28. package/lib/Cloudflare/AiGateway/index.js +3 -0
  29. package/lib/Cloudflare/AiGateway/index.js.map +1 -0
  30. package/lib/Cloudflare/EdgeSession.d.ts +2 -1
  31. package/lib/Cloudflare/EdgeSession.d.ts.map +1 -1
  32. package/lib/Cloudflare/EdgeSession.js +8 -4
  33. package/lib/Cloudflare/EdgeSession.js.map +1 -1
  34. package/lib/Cloudflare/Providers.d.ts +2 -1
  35. package/lib/Cloudflare/Providers.d.ts.map +1 -1
  36. package/lib/Cloudflare/Providers.js +5 -1
  37. package/lib/Cloudflare/Providers.js.map +1 -1
  38. package/lib/Cloudflare/StateStore/Api.d.ts +10 -0
  39. package/lib/Cloudflare/StateStore/Api.d.ts.map +1 -1
  40. package/lib/Cloudflare/StateStore/Api.js +12 -1
  41. package/lib/Cloudflare/StateStore/Api.js.map +1 -1
  42. package/lib/Cloudflare/StateStore/State.d.ts +4 -3
  43. package/lib/Cloudflare/StateStore/State.d.ts.map +1 -1
  44. package/lib/Cloudflare/StateStore/State.js +103 -13
  45. package/lib/Cloudflare/StateStore/State.js.map +1 -1
  46. package/lib/Cloudflare/Workers/InferEnv.d.ts +1 -1
  47. package/lib/Cloudflare/Workers/InferEnv.d.ts.map +1 -1
  48. package/lib/Cloudflare/Workers/Worker.d.ts +2 -1
  49. package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
  50. package/lib/Cloudflare/Workers/Worker.js +40 -31
  51. package/lib/Cloudflare/Workers/Worker.js.map +1 -1
  52. package/lib/Cloudflare/index.d.ts +1 -0
  53. package/lib/Cloudflare/index.d.ts.map +1 -1
  54. package/lib/Cloudflare/index.js +1 -0
  55. package/lib/Cloudflare/index.js.map +1 -1
  56. package/lib/Plan.d.ts +8 -0
  57. package/lib/Plan.d.ts.map +1 -1
  58. package/lib/Plan.js +12 -5
  59. package/lib/Plan.js.map +1 -1
  60. package/lib/State/HttpStateApi.d.ts +19 -1
  61. package/lib/State/HttpStateApi.d.ts.map +1 -1
  62. package/lib/State/HttpStateApi.js +18 -1
  63. package/lib/State/HttpStateApi.js.map +1 -1
  64. package/lib/Util/cached-function.d.ts +38 -0
  65. package/lib/Util/cached-function.d.ts.map +1 -0
  66. package/lib/Util/cached-function.js +53 -0
  67. package/lib/Util/cached-function.js.map +1 -0
  68. package/lib/Util/scc.d.ts +12 -0
  69. package/lib/Util/scc.d.ts.map +1 -0
  70. package/lib/Util/scc.js +81 -0
  71. package/lib/Util/scc.js.map +1 -0
  72. package/lib/tsconfig.test.tsbuildinfo +1 -1
  73. package/package.json +2 -2
  74. package/src/AWS/IAM/SAMLProvider.ts +47 -18
  75. package/src/Apply.ts +72 -8
  76. package/src/Cli/commands/bootstrap.ts +2 -0
  77. package/src/Cloudflare/Access.ts +110 -0
  78. package/src/Cloudflare/AiGateway/AiGateway.ts +526 -0
  79. package/src/Cloudflare/AiGateway/AiGatewayBinding.ts +190 -0
  80. package/src/Cloudflare/AiGateway/index.ts +2 -0
  81. package/src/Cloudflare/EdgeSession.ts +15 -5
  82. package/src/Cloudflare/Providers.ts +7 -0
  83. package/src/Cloudflare/StateStore/Api.ts +18 -0
  84. package/src/Cloudflare/StateStore/State.ts +130 -12
  85. package/src/Cloudflare/Workers/InferEnv.ts +7 -5
  86. package/src/Cloudflare/Workers/Worker.ts +44 -33
  87. package/src/Cloudflare/index.ts +1 -0
  88. package/src/Plan.ts +21 -5
  89. package/src/State/HttpStateApi.ts +22 -1
  90. package/src/Util/cached-function.ts +75 -0
  91. package/src/Util/scc.ts +89 -0
@@ -0,0 +1,244 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Provider from "../../Provider.ts";
3
+ import { Resource } from "../../Resource.ts";
4
+ import { CloudflareEnvironment } from "../CloudflareEnvironment.ts";
5
+ import type { Providers } from "../Providers.ts";
6
+ import { AiGatewayBinding } from "./AiGatewayBinding.ts";
7
+ export type AiGatewayRateLimitingTechnique = "fixed" | "sliding";
8
+ export type AiGatewayLogManagementStrategy = "STOP_INSERTING" | "DELETE_OLDEST";
9
+ export type AiGatewayDlp = {
10
+ /**
11
+ * Action to take when a DLP profile matches.
12
+ */
13
+ action: "BLOCK" | "FLAG";
14
+ /**
15
+ * Whether DLP is enabled.
16
+ */
17
+ enabled: boolean;
18
+ /**
19
+ * DLP profile identifiers to apply.
20
+ */
21
+ profiles: string[];
22
+ } | {
23
+ /**
24
+ * Whether DLP is enabled.
25
+ */
26
+ enabled: boolean;
27
+ /**
28
+ * DLP policies to apply.
29
+ */
30
+ policies: {
31
+ /**
32
+ * DLP policy identifier.
33
+ */
34
+ id: string;
35
+ /**
36
+ * Action to take when the policy matches.
37
+ */
38
+ action: "FLAG" | "BLOCK";
39
+ /**
40
+ * Request or response phases checked by the policy.
41
+ */
42
+ check: ("REQUEST" | "RESPONSE")[];
43
+ /**
44
+ * Whether the policy is enabled.
45
+ */
46
+ enabled: boolean;
47
+ /**
48
+ * DLP profile identifiers to apply.
49
+ */
50
+ profiles: string[];
51
+ }[];
52
+ };
53
+ export type AiGatewayOtel = {
54
+ /**
55
+ * Authorization header value for the OpenTelemetry endpoint.
56
+ */
57
+ authorization: string;
58
+ /**
59
+ * Additional headers sent to the OpenTelemetry endpoint.
60
+ */
61
+ headers: Record<string, unknown>;
62
+ /**
63
+ * OpenTelemetry endpoint URL.
64
+ */
65
+ url: string;
66
+ };
67
+ export type AiGatewayStripe = {
68
+ /**
69
+ * Authorization header value for Stripe usage events.
70
+ */
71
+ authorization: string;
72
+ /**
73
+ * Stripe usage event payload definitions.
74
+ */
75
+ usageEvents: {
76
+ /**
77
+ * Usage event payload.
78
+ */
79
+ payload: string;
80
+ }[];
81
+ };
82
+ export type AiGatewayProps = {
83
+ /**
84
+ * Gateway identifier. If omitted, a unique ID will be generated.
85
+ *
86
+ * Must be 1-64 characters and match Cloudflare's AI Gateway ID pattern:
87
+ * lowercase letters, numbers, underscores, and hyphens.
88
+ *
89
+ * @default ${app}-${stage}-${id}
90
+ */
91
+ id?: string;
92
+ /**
93
+ * Whether cached responses are invalidated when a request changes.
94
+ *
95
+ * @default false
96
+ */
97
+ cacheInvalidateOnUpdate?: boolean;
98
+ /**
99
+ * Cache time-to-live in seconds. Set to `null` to disable caching.
100
+ *
101
+ * @default null
102
+ */
103
+ cacheTtl?: number | null;
104
+ /**
105
+ * Whether AI Gateway stores request logs.
106
+ *
107
+ * @default true
108
+ */
109
+ collectLogs?: boolean;
110
+ /**
111
+ * Rate limiting interval in seconds. Set to `null` to disable rate limiting.
112
+ *
113
+ * @default null
114
+ */
115
+ rateLimitingInterval?: number | null;
116
+ /**
117
+ * Maximum requests allowed during the rate limiting interval. Set to `null`
118
+ * to disable rate limiting.
119
+ *
120
+ * @default null
121
+ */
122
+ rateLimitingLimit?: number | null;
123
+ /**
124
+ * Rate limiting algorithm.
125
+ *
126
+ * @default "fixed"
127
+ */
128
+ rateLimitingTechnique?: AiGatewayRateLimitingTechnique;
129
+ /**
130
+ * Whether gateway authentication is enabled.
131
+ */
132
+ authentication?: boolean;
133
+ /**
134
+ * DLP configuration. The installed distilled Cloudflare client applies this
135
+ * through the update API after gateway creation.
136
+ */
137
+ dlp?: AiGatewayDlp;
138
+ /**
139
+ * Whether this gateway is the account default.
140
+ */
141
+ isDefault?: boolean;
142
+ /**
143
+ * Maximum number of log entries to retain.
144
+ */
145
+ logManagement?: number | null;
146
+ /**
147
+ * Strategy used when retained logs reach `logManagement`.
148
+ */
149
+ logManagementStrategy?: AiGatewayLogManagementStrategy | null;
150
+ /**
151
+ * Whether Logpush is enabled for this gateway.
152
+ */
153
+ logpush?: boolean;
154
+ /**
155
+ * Public key used for Logpush encryption.
156
+ */
157
+ logpushPublicKey?: string | null;
158
+ /**
159
+ * OpenTelemetry export configuration.
160
+ */
161
+ otel?: AiGatewayOtel[] | null;
162
+ /**
163
+ * Store identifier used by the gateway.
164
+ */
165
+ storeId?: string | null;
166
+ /**
167
+ * Stripe usage export configuration.
168
+ */
169
+ stripe?: AiGatewayStripe | null;
170
+ /**
171
+ * Whether Zero Data Retention is enabled.
172
+ */
173
+ zdr?: boolean;
174
+ };
175
+ export type AiGateway = Resource<"Cloudflare.AiGateway", AiGatewayProps, {
176
+ gatewayId: string;
177
+ accountId: string;
178
+ accountTag: string | undefined;
179
+ internalId: string | undefined;
180
+ cacheInvalidateOnUpdate: boolean;
181
+ cacheTtl: number | null;
182
+ collectLogs: boolean;
183
+ createdAt: string;
184
+ modifiedAt: string;
185
+ rateLimitingInterval: number | null;
186
+ rateLimitingLimit: number | null;
187
+ rateLimitingTechnique: AiGatewayRateLimitingTechnique;
188
+ authentication: boolean | undefined;
189
+ dlp: AiGatewayDlp | null | undefined;
190
+ isDefault: boolean | undefined;
191
+ logManagement: number | null | undefined;
192
+ logManagementStrategy: AiGatewayLogManagementStrategy | null | undefined;
193
+ logpush: boolean | undefined;
194
+ logpushPublicKey: string | null | undefined;
195
+ otel: AiGatewayOtel[] | null | undefined;
196
+ storeId: string | null | undefined;
197
+ stripe: AiGatewayStripe | null | undefined;
198
+ zdr: boolean | undefined;
199
+ }, never, Providers>;
200
+ export declare const isAiGateway: (value: unknown) => value is AiGateway;
201
+ /**
202
+ * A Cloudflare AI Gateway for observability, caching, rate limiting, and
203
+ * governance across AI provider requests.
204
+ *
205
+ * AI Gateway gives your application a stable gateway ID and account-scoped
206
+ * endpoint that can route model requests through Cloudflare.
207
+ *
208
+ * @section Creating a Gateway
209
+ * @example Basic gateway
210
+ * ```typescript
211
+ * const gateway = yield* Cloudflare.AiGateway("Gateway");
212
+ * ```
213
+ *
214
+ * @example Gateway with caching and rate limiting
215
+ * ```typescript
216
+ * const gateway = yield* Cloudflare.AiGateway("Gateway", {
217
+ * id: "my-gateway",
218
+ * cacheTtl: 300,
219
+ * cacheInvalidateOnUpdate: true,
220
+ * rateLimitingInterval: 60,
221
+ * rateLimitingLimit: 100,
222
+ * rateLimitingTechnique: "sliding",
223
+ * });
224
+ * ```
225
+ *
226
+ * @section Logging
227
+ * @example Gateway with log retention
228
+ * ```typescript
229
+ * const gateway = yield* Cloudflare.AiGateway("Gateway", {
230
+ * collectLogs: true,
231
+ * logManagement: 10000,
232
+ * logManagementStrategy: "STOP_INSERTING",
233
+ * });
234
+ * ```
235
+ */
236
+ export declare const AiGateway: import("../../Resource.ts").ResourceClassWithMethods<AiGateway, {
237
+ /**
238
+ * Bind this gateway to the surrounding Worker, returning an Effect-native
239
+ * client for the runtime AI Gateway binding.
240
+ */
241
+ readonly bind: (<Req = never>(args_0: AiGateway | Effect.Effect<AiGateway, never, Req>) => Effect.Effect<import("./AiGatewayBinding.ts").AiGatewayClient, never, AiGatewayBinding | Req>) & ((gateway: AiGateway) => Effect.Effect<any, any, any>);
242
+ }>;
243
+ export declare const AiGatewayProvider: () => import("effect/Layer").Layer<Provider.Provider<AiGateway>, never, import("effect/unstable/http/HttpClient").HttpClient | import("../../Stage.ts").Stage | import("../../Stack.ts").Stack | import("@distilled.cloud/cloudflare/Credentials").Credentials | CloudflareEnvironment>;
244
+ //# sourceMappingURL=AiGateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiGateway.d.ts","sourceRoot":"","sources":["../../../src/Cloudflare/AiGateway/AiGateway.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,MAAM,8BAA8B,GAAG,OAAO,GAAG,SAAS,CAAC;AAEjE,MAAM,MAAM,8BAA8B,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAEhF,MAAM,MAAM,YAAY,GACpB;IACE;;OAEG;IACH,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,G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E,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,qBAAqB,EAAE,8BAA8B,GAAG,IAAI,GAAG,SAAS,CAAC;IACzE,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC5C,IAAI,EAAE,aAAa,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IACzC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3C,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC;CAC1B,EACD,KAAK,EACL,SAAS,CACV,CAAC;AAQF,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,SAIA,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,SAAS;IACpB;;;OAGG;;EAEH,CAAC;AAEH,eAAO,MAAM,iBAAiB,yRA4P3B,CAAC"}
@@ -0,0 +1,269 @@
1
+ import * as aiGateway from "@distilled.cloud/cloudflare/ai-gateway";
2
+ import * as Effect from "effect/Effect";
3
+ import { deepEqual, isResolved } from "../../Diff.js";
4
+ import { createPhysicalName } from "../../PhysicalName.js";
5
+ import * as Provider from "../../Provider.js";
6
+ import { Resource } from "../../Resource.js";
7
+ import { CloudflareEnvironment } from "../CloudflareEnvironment.js";
8
+ import { AiGatewayBinding } from "./AiGatewayBinding.js";
9
+ // Cloudflare's AI Gateway API uses 0 to mean "disabled" for cache TTL and
10
+ // rate limiting fields. Normalize back to null so user-facing semantics
11
+ // match what was passed in.
12
+ const nullIfZero = (value) => value == null || value === 0 ? null : value;
13
+ export const isAiGateway = (value) => typeof value === "object" &&
14
+ value !== null &&
15
+ "Type" in value &&
16
+ value.Type === "Cloudflare.AiGateway";
17
+ /**
18
+ * A Cloudflare AI Gateway for observability, caching, rate limiting, and
19
+ * governance across AI provider requests.
20
+ *
21
+ * AI Gateway gives your application a stable gateway ID and account-scoped
22
+ * endpoint that can route model requests through Cloudflare.
23
+ *
24
+ * @section Creating a Gateway
25
+ * @example Basic gateway
26
+ * ```typescript
27
+ * const gateway = yield* Cloudflare.AiGateway("Gateway");
28
+ * ```
29
+ *
30
+ * @example Gateway with caching and rate limiting
31
+ * ```typescript
32
+ * const gateway = yield* Cloudflare.AiGateway("Gateway", {
33
+ * id: "my-gateway",
34
+ * cacheTtl: 300,
35
+ * cacheInvalidateOnUpdate: true,
36
+ * rateLimitingInterval: 60,
37
+ * rateLimitingLimit: 100,
38
+ * rateLimitingTechnique: "sliding",
39
+ * });
40
+ * ```
41
+ *
42
+ * @section Logging
43
+ * @example Gateway with log retention
44
+ * ```typescript
45
+ * const gateway = yield* Cloudflare.AiGateway("Gateway", {
46
+ * collectLogs: true,
47
+ * logManagement: 10000,
48
+ * logManagementStrategy: "STOP_INSERTING",
49
+ * });
50
+ * ```
51
+ */
52
+ export const AiGateway = Resource("Cloudflare.AiGateway")({
53
+ /**
54
+ * Bind this gateway to the surrounding Worker, returning an Effect-native
55
+ * client for the runtime AI Gateway binding.
56
+ */
57
+ bind: AiGatewayBinding.bind,
58
+ });
59
+ export const AiGatewayProvider = () => Provider.effect(AiGateway, Effect.gen(function* () {
60
+ const { accountId } = yield* CloudflareEnvironment;
61
+ const createAiGateway = yield* aiGateway.createAiGateway;
62
+ const getAiGateway = yield* aiGateway.getAiGateway;
63
+ const updateAiGateway = yield* aiGateway.updateAiGateway;
64
+ const deleteAiGateway = yield* aiGateway.deleteAiGateway;
65
+ const createGatewayId = (id, gatewayId) => Effect.gen(function* () {
66
+ if (gatewayId)
67
+ return gatewayId;
68
+ return yield* createPhysicalName({
69
+ id,
70
+ maxLength: 64,
71
+ lowercase: true,
72
+ });
73
+ });
74
+ const desired = (id, props) => Effect.gen(function* () {
75
+ return {
76
+ gatewayId: yield* createGatewayId(id, props?.id),
77
+ cacheInvalidateOnUpdate: props?.cacheInvalidateOnUpdate ?? false,
78
+ cacheTtl: props?.cacheTtl ?? null,
79
+ collectLogs: props?.collectLogs ?? true,
80
+ rateLimitingInterval: props?.rateLimitingInterval ?? null,
81
+ rateLimitingLimit: props?.rateLimitingLimit ?? null,
82
+ rateLimitingTechnique: props?.rateLimitingTechnique ?? "fixed",
83
+ authentication: props?.authentication,
84
+ dlp: props?.dlp,
85
+ isDefault: props?.isDefault,
86
+ logManagement: props?.logManagement,
87
+ logManagementStrategy: props?.logManagementStrategy,
88
+ logpush: props?.logpush,
89
+ logpushPublicKey: props?.logpushPublicKey,
90
+ otel: props?.otel,
91
+ storeId: props?.storeId,
92
+ stripe: props?.stripe,
93
+ zdr: props?.zdr,
94
+ };
95
+ });
96
+ const mapGateway = (gateway, accountId) => ({
97
+ gatewayId: gateway.id,
98
+ accountId,
99
+ accountTag: gateway.accountTag ?? undefined,
100
+ internalId: gateway.internalId ?? undefined,
101
+ cacheInvalidateOnUpdate: gateway.cacheInvalidateOnUpdate,
102
+ cacheTtl: nullIfZero(gateway.cacheTtl),
103
+ collectLogs: gateway.collectLogs,
104
+ createdAt: gateway.createdAt,
105
+ modifiedAt: gateway.modifiedAt,
106
+ rateLimitingInterval: nullIfZero(gateway.rateLimitingInterval),
107
+ rateLimitingLimit: nullIfZero(gateway.rateLimitingLimit),
108
+ rateLimitingTechnique: gateway.rateLimitingTechnique ?? "fixed",
109
+ authentication: gateway.authentication ?? undefined,
110
+ dlp: gateway.dlp,
111
+ isDefault: gateway.isDefault ?? undefined,
112
+ logManagement: gateway.logManagement,
113
+ logManagementStrategy: gateway.logManagementStrategy,
114
+ logpush: gateway.logpush ?? undefined,
115
+ logpushPublicKey: gateway.logpushPublicKey,
116
+ otel: gateway.otel,
117
+ storeId: gateway.storeId,
118
+ stripe: gateway.stripe,
119
+ zdr: gateway.zdr ?? undefined,
120
+ });
121
+ const mutable = (gateway) => ({
122
+ cacheInvalidateOnUpdate: gateway.cacheInvalidateOnUpdate,
123
+ cacheTtl: gateway.cacheTtl,
124
+ collectLogs: gateway.collectLogs,
125
+ rateLimitingInterval: gateway.rateLimitingInterval,
126
+ rateLimitingLimit: gateway.rateLimitingLimit,
127
+ rateLimitingTechnique: gateway.rateLimitingTechnique,
128
+ authentication: gateway.authentication,
129
+ dlp: gateway.dlp ?? undefined,
130
+ isDefault: gateway.isDefault,
131
+ logManagement: gateway.logManagement,
132
+ logManagementStrategy: gateway.logManagementStrategy,
133
+ logpush: gateway.logpush,
134
+ logpushPublicKey: gateway.logpushPublicKey,
135
+ otel: gateway.otel,
136
+ storeId: gateway.storeId,
137
+ stripe: gateway.stripe,
138
+ zdr: gateway.zdr,
139
+ });
140
+ const createRequest = Effect.fn(function* (id, props) {
141
+ const next = yield* desired(id, props);
142
+ return {
143
+ accountId,
144
+ id: next.gatewayId,
145
+ cacheInvalidateOnUpdate: next.cacheInvalidateOnUpdate,
146
+ cacheTtl: next.cacheTtl,
147
+ collectLogs: next.collectLogs,
148
+ rateLimitingInterval: next.rateLimitingInterval,
149
+ rateLimitingLimit: next.rateLimitingLimit,
150
+ rateLimitingTechnique: next.rateLimitingTechnique,
151
+ authentication: next.authentication,
152
+ isDefault: next.isDefault,
153
+ logManagement: next.logManagement,
154
+ logManagementStrategy: next.logManagementStrategy,
155
+ logpush: next.logpush,
156
+ logpushPublicKey: next.logpushPublicKey,
157
+ zdr: next.zdr,
158
+ };
159
+ });
160
+ const updateRequest = Effect.fn(function* (id, props, accountId) {
161
+ const next = yield* desired(id, props);
162
+ return {
163
+ accountId,
164
+ id: next.gatewayId,
165
+ cacheInvalidateOnUpdate: next.cacheInvalidateOnUpdate,
166
+ cacheTtl: next.cacheTtl,
167
+ collectLogs: next.collectLogs,
168
+ rateLimitingInterval: next.rateLimitingInterval,
169
+ rateLimitingLimit: next.rateLimitingLimit,
170
+ rateLimitingTechnique: next.rateLimitingTechnique,
171
+ authentication: next.authentication,
172
+ dlp: next.dlp,
173
+ isDefault: next.isDefault,
174
+ logManagement: next.logManagement,
175
+ logManagementStrategy: next.logManagementStrategy,
176
+ logpush: next.logpush,
177
+ logpushPublicKey: next.logpushPublicKey,
178
+ otel: next.otel,
179
+ storeId: next.storeId,
180
+ stripe: next.stripe,
181
+ zdr: next.zdr,
182
+ };
183
+ });
184
+ return {
185
+ stables: ["gatewayId", "accountId"],
186
+ diff: Effect.fn(function* ({ id, olds = {}, news = {}, output }) {
187
+ if (!isResolved(news))
188
+ return undefined;
189
+ const next = yield* desired(id, news);
190
+ const oldGatewayId = output?.gatewayId ?? (yield* createGatewayId(id, olds.id));
191
+ if ((output?.accountId ?? accountId) !== accountId ||
192
+ oldGatewayId !== next.gatewayId) {
193
+ return { action: "replace" };
194
+ }
195
+ const oldMutable = output
196
+ ? mutable(output)
197
+ : yield* desired(id, olds).pipe(Effect.map((old) => ({
198
+ cacheInvalidateOnUpdate: old.cacheInvalidateOnUpdate,
199
+ cacheTtl: old.cacheTtl,
200
+ collectLogs: old.collectLogs,
201
+ rateLimitingInterval: old.rateLimitingInterval,
202
+ rateLimitingLimit: old.rateLimitingLimit,
203
+ rateLimitingTechnique: old.rateLimitingTechnique,
204
+ authentication: old.authentication,
205
+ dlp: old.dlp,
206
+ isDefault: old.isDefault,
207
+ logManagement: old.logManagement,
208
+ logManagementStrategy: old.logManagementStrategy,
209
+ logpush: old.logpush,
210
+ logpushPublicKey: old.logpushPublicKey,
211
+ otel: old.otel,
212
+ storeId: old.storeId,
213
+ stripe: old.stripe,
214
+ zdr: old.zdr,
215
+ })));
216
+ const nextMutable = {
217
+ cacheInvalidateOnUpdate: next.cacheInvalidateOnUpdate,
218
+ cacheTtl: next.cacheTtl,
219
+ collectLogs: next.collectLogs,
220
+ rateLimitingInterval: next.rateLimitingInterval,
221
+ rateLimitingLimit: next.rateLimitingLimit,
222
+ rateLimitingTechnique: next.rateLimitingTechnique,
223
+ authentication: next.authentication,
224
+ dlp: next.dlp,
225
+ isDefault: next.isDefault,
226
+ logManagement: next.logManagement,
227
+ logManagementStrategy: next.logManagementStrategy,
228
+ logpush: next.logpush,
229
+ logpushPublicKey: next.logpushPublicKey,
230
+ otel: next.otel,
231
+ storeId: next.storeId,
232
+ stripe: next.stripe,
233
+ zdr: next.zdr,
234
+ };
235
+ if (!deepEqual(oldMutable, nextMutable)) {
236
+ return { action: "update" };
237
+ }
238
+ }),
239
+ create: Effect.fn(function* ({ id, news = {} }) {
240
+ const request = yield* createRequest(id, news);
241
+ const gateway = yield* createAiGateway(request).pipe(Effect.catchTag("GatewayAlreadyExists", () => getAiGateway({
242
+ accountId,
243
+ id: request.id,
244
+ })));
245
+ const update = yield* updateRequest(id, news, accountId);
246
+ return yield* updateAiGateway(update).pipe(Effect.map((gateway) => mapGateway(gateway, accountId)), Effect.catchTag("GatewayNotFound", () => Effect.succeed(mapGateway(gateway, accountId))));
247
+ }),
248
+ update: Effect.fn(function* ({ id, news = {}, output }) {
249
+ const request = yield* updateRequest(id, news, output.accountId);
250
+ const gateway = yield* updateAiGateway(request);
251
+ return mapGateway(gateway, output.accountId);
252
+ }),
253
+ delete: Effect.fn(function* ({ output }) {
254
+ yield* deleteAiGateway({
255
+ accountId: output.accountId,
256
+ id: output.gatewayId,
257
+ }).pipe(Effect.catchTag("GatewayNotFound", () => Effect.void));
258
+ }),
259
+ read: Effect.fn(function* ({ id, olds, output }) {
260
+ const gatewayId = output?.gatewayId ?? (yield* createGatewayId(id, olds?.id));
261
+ const acct = output?.accountId ?? accountId;
262
+ return yield* getAiGateway({
263
+ accountId: acct,
264
+ id: gatewayId,
265
+ }).pipe(Effect.map((gateway) => mapGateway(gateway, acct)), Effect.catchTag("GatewayNotFound", () => Effect.succeed(undefined)));
266
+ }),
267
+ };
268
+ }));
269
+ //# sourceMappingURL=AiGateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiGateway.js","sourceRoot":"","sources":["../../../src/Cloudflare/AiGateway/AiGateway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,wCAAwC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C,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE;YACrC,KAAK,CAAC,CAAC,eAAe,CAAC;gBACrB,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,EAAE,EAAE,MAAM,CAAC,SAAS;aACrB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC;QACF,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YAC7C,MAAM,SAAS,GACb,MAAM,EAAE,SAAS,IAAI,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;YAC9D,MAAM,IAAI,GAAG,MAAM,EAAE,SAAS,IAAI,SAAS,CAAC;YAC5C,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC;gBACzB,SAAS,EAAE,IAAI;gBACf,EAAE,EAAE,SAAS;aACd,CAAC,CAAC,IAAI,CACL,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,EAClD,MAAM,CAAC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CACpE,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CACH,CAAC"}
@@ -0,0 +1,103 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Layer from "effect/Layer";
3
+ import * as Binding from "../../Binding.ts";
4
+ import { WorkerEnvironment } from "../Workers/Worker.ts";
5
+ import type { AiGateway as AiGatewayResource } from "./AiGateway.ts";
6
+ declare const AiGatewayError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
7
+ readonly _tag: "AiGatewayError";
8
+ } & Readonly<A>;
9
+ /**
10
+ * Error raised by AI Gateway runtime operations.
11
+ */
12
+ export declare class AiGatewayError extends AiGatewayError_base<{
13
+ /**
14
+ * Human-readable runtime error message.
15
+ */
16
+ message: string;
17
+ /**
18
+ * Original error thrown by the Cloudflare runtime binding.
19
+ */
20
+ cause: unknown;
21
+ }> {
22
+ }
23
+ /**
24
+ * Effect-native client for a Cloudflare AI Gateway Worker binding.
25
+ *
26
+ * Wraps the runtime {@link AiGateway} binding so each operation returns an
27
+ * Effect tagged with {@link AiGatewayError}. Use
28
+ * `Cloudflare.AiGatewayBinding.bind(gateway)` inside a Worker's init phase.
29
+ */
30
+ export interface AiGatewayClient {
31
+ /**
32
+ * Effect resolving to the raw Workers AI binding.
33
+ */
34
+ raw: Effect.Effect<Ai, never, WorkerEnvironment>;
35
+ /**
36
+ * Effect resolving to the raw AI Gateway runtime binding.
37
+ */
38
+ gateway: Effect.Effect<AiGateway, never, WorkerEnvironment>;
39
+ /**
40
+ * Update metadata on an existing AI Gateway log entry.
41
+ */
42
+ patchLog(logId: string, data: Parameters<AiGateway["patchLog"]>[1]): Effect.Effect<void, AiGatewayError, WorkerEnvironment>;
43
+ /**
44
+ * Read an AI Gateway log entry by ID.
45
+ */
46
+ getLog(logId: string): Effect.Effect<AiGatewayLog, AiGatewayError, WorkerEnvironment>;
47
+ /**
48
+ * Build a provider URL routed through this gateway.
49
+ */
50
+ getUrl(provider?: Parameters<AiGateway["getUrl"]>[0]): Effect.Effect<string, AiGatewayError, WorkerEnvironment>;
51
+ /**
52
+ * Run an AI Gateway request through the Cloudflare runtime binding.
53
+ */
54
+ run(data: Parameters<AiGateway["run"]>[0], options?: Parameters<AiGateway["run"]>[1]): Effect.Effect<Response, AiGatewayError, WorkerEnvironment>;
55
+ }
56
+ declare const AiGatewayBinding_base: Binding.Service<AiGatewayBinding, "Cloudflare.AiGateway.Binding", (gateway: AiGatewayResource) => Effect.Effect<AiGatewayClient>> & {
57
+ bind: (gateway: AiGatewayResource) => Effect.Effect<any, any, any>;
58
+ };
59
+ /**
60
+ * Binding service that turns an {@link AiGatewayResource} resource into a typed
61
+ * {@link AiGatewayClient} for Worker runtime code.
62
+ *
63
+ * @section Calling AI Gateway
64
+ * Bind the gateway during the Worker's init phase, then use `run` or `getUrl`
65
+ * from request handlers.
66
+ *
67
+ * @example Run through a gateway
68
+ * ```typescript
69
+ * const aiGateway = yield* Cloudflare.AiGatewayBinding.bind(gateway);
70
+ *
71
+ * return {
72
+ * fetch: Effect.gen(function* () {
73
+ * return yield* aiGateway.run({
74
+ * provider: "workers-ai",
75
+ * endpoint: "@cf/meta/llama-3.1-8b-instruct",
76
+ * headers: { "content-type": "application/json" },
77
+ * query: { prompt: "Write a concise status update" },
78
+ * });
79
+ * }),
80
+ * };
81
+ * ```
82
+ *
83
+ * Provide {@link AiGatewayBindingLive} in the worker's runtime layer to
84
+ * resolve the underlying Cloudflare AI binding at request time.
85
+ */
86
+ export declare class AiGatewayBinding extends AiGatewayBinding_base {
87
+ }
88
+ /**
89
+ * Runtime layer for {@link AiGatewayBinding}.
90
+ */
91
+ export declare const AiGatewayBindingLive: Layer.Layer<AiGatewayBinding, never, import("../../ExecutionContext.ts").ExecutionContext<import("../../ExecutionContext.ts").BaseExecutionContext> | AiGatewayBindingPolicy>;
92
+ declare const AiGatewayBindingPolicy_base: Binding.Policy<AiGatewayBindingPolicy, "Policy<Cloudflare.AiGateway.Binding>", (gateway: AiGatewayResource) => Effect.Effect<void>>;
93
+ /**
94
+ * Deploy-time policy service that attaches an AI binding to Workers.
95
+ */
96
+ export declare class AiGatewayBindingPolicy extends AiGatewayBindingPolicy_base {
97
+ }
98
+ /**
99
+ * Live deploy-time policy layer for {@link AiGatewayBindingPolicy}.
100
+ */
101
+ export declare const AiGatewayBindingPolicyLive: Layer.Layer<AiGatewayBindingPolicy, never, never>;
102
+ export {};
103
+ //# sourceMappingURL=AiGatewayBinding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AiGatewayBinding.d.ts","sourceRoot":"","sources":["../../../src/Cloudflare/AiGateway/AiGatewayBinding.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAY,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,IAAI,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;;;;AAErE;;GAEG;AACH,qBAAa,cAAe,SAAQ,oBAAmC;IACrE;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;CAAG;AAEL;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACjD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IAC5D;;OAEG;IACH,QAAQ,CACN,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GACzC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC;IAC1D;;OAEG;IACH,MAAM,CACJ,KAAK,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC;IAClE;;OAEG;IACH,MAAM,CACJ,QAAQ,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,CA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