@use-lattice/litmus 0.121.3
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.
- package/LICENSE +19 -0
- package/dist/src/accounts-Bt1oJb1Z.cjs +219 -0
- package/dist/src/accounts-DjOU8Rm3.js +178 -0
- package/dist/src/agentic-utils-D03IiXQc.js +153 -0
- package/dist/src/agentic-utils-Dh7xaMQM.cjs +180 -0
- package/dist/src/agents-C6BIMlZa.js +231 -0
- package/dist/src/agents-DvIpNX1L.cjs +666 -0
- package/dist/src/agents-ZP0RP9vV.cjs +231 -0
- package/dist/src/agents-maJXdjbR.js +665 -0
- package/dist/src/aimlapi-BTbQjG2E.cjs +30 -0
- package/dist/src/aimlapi-CwMxqfXP.js +30 -0
- package/dist/src/audio-BBUdvsde.cjs +97 -0
- package/dist/src/audio-D5DPZ7I-.js +97 -0
- package/dist/src/base-BEysXrkq.cjs +222 -0
- package/dist/src/base-C451JQfq.js +193 -0
- package/dist/src/blobs-BY8MDmpo.js +230 -0
- package/dist/src/blobs-BgcNn97m.cjs +256 -0
- package/dist/src/cache-BBE_lsTA.cjs +4 -0
- package/dist/src/cache-BkrqU5Ba.js +237 -0
- package/dist/src/cache-DsCxFlsZ.cjs +297 -0
- package/dist/src/chat-CPJWDP6a.cjs +289 -0
- package/dist/src/chat-CXX3xzkk.cjs +811 -0
- package/dist/src/chat-CcDgZFJ4.js +787 -0
- package/dist/src/chat-Dz5ZeGO2.js +289 -0
- package/dist/src/chatkit-Dw0mKkML.cjs +1158 -0
- package/dist/src/chatkit-swAIVuea.js +1157 -0
- package/dist/src/chunk-DEq-mXcV.js +15 -0
- package/dist/src/claude-agent-sdk-BXZJtOg6.js +379 -0
- package/dist/src/claude-agent-sdk-CkfyjDoG.cjs +383 -0
- package/dist/src/cloudflare-ai-BzpJcqUH.js +161 -0
- package/dist/src/cloudflare-ai-Cmy_R1y2.cjs +161 -0
- package/dist/src/cloudflare-gateway-B9tVQKok.cjs +272 -0
- package/dist/src/cloudflare-gateway-DrD3ew3H.js +272 -0
- package/dist/src/codex-sdk-Dezj9Nwm.js +1056 -0
- package/dist/src/codex-sdk-Dl9D4k5B.cjs +1060 -0
- package/dist/src/cometapi-C-9YvCHC.js +54 -0
- package/dist/src/cometapi-DHgDKoO2.cjs +54 -0
- package/dist/src/completion-B8Ctyxpr.js +120 -0
- package/dist/src/completion-Cxrt08sj.cjs +131 -0
- package/dist/src/createHash-BwgE13yv.cjs +27 -0
- package/dist/src/createHash-DmPQkvBh.js +15 -0
- package/dist/src/docker-BiqcTwLv.js +80 -0
- package/dist/src/docker-C7tEJnP-.cjs +80 -0
- package/dist/src/esm-C62Zofr1.cjs +409 -0
- package/dist/src/esm-DMVc93eh.js +379 -0
- package/dist/src/evalResult-C3NJPQOo.cjs +301 -0
- package/dist/src/evalResult-C7JJAPBb.js +295 -0
- package/dist/src/evalResult-DoVTZZWI.cjs +2 -0
- package/dist/src/extractor-DnMD3fwt.cjs +391 -0
- package/dist/src/extractor-DtlL28vL.js +374 -0
- package/dist/src/fetch-BTxakTSg.cjs +1133 -0
- package/dist/src/fetch-DQckpUFz.js +928 -0
- package/dist/src/fileExtensions-DnqA1y9x.js +85 -0
- package/dist/src/fileExtensions-bYh77CN8.cjs +114 -0
- package/dist/src/genaiTracer-CyZrmaK0.cjs +268 -0
- package/dist/src/genaiTracer-D3fD9dNV.js +256 -0
- package/dist/src/graders-BNscxFrU.js +13644 -0
- package/dist/src/graders-D2oE9Msq.js +2 -0
- package/dist/src/graders-c0Ez_w-9.cjs +2 -0
- package/dist/src/graders-d0F2M3e9.cjs +14056 -0
- package/dist/src/image-0ZhE0VlR.cjs +280 -0
- package/dist/src/image-CWE1pdNv.js +257 -0
- package/dist/src/image-D9ZK6hwL.js +163 -0
- package/dist/src/image-DKZgZITg.cjs +163 -0
- package/dist/src/index.cjs +11366 -0
- package/dist/src/index.d.cts +19640 -0
- package/dist/src/index.d.ts +19641 -0
- package/dist/src/index.js +11306 -0
- package/dist/src/invariant-Ddh24eXh.js +25 -0
- package/dist/src/invariant-kfQ8Bu82.cjs +30 -0
- package/dist/src/knowledgeBase-BgPyGFUd.cjs +122 -0
- package/dist/src/knowledgeBase-DyHilYaP.js +122 -0
- package/dist/src/litellm-CyMeneHS.js +135 -0
- package/dist/src/litellm-DWDF73yF.cjs +135 -0
- package/dist/src/logger-C40ZGil9.js +717 -0
- package/dist/src/logger-DyfK9PBt.cjs +917 -0
- package/dist/src/luma-ray-BAU9X_ep.cjs +315 -0
- package/dist/src/luma-ray-nwVseBbv.js +313 -0
- package/dist/src/messages-B5ADWTTv.js +245 -0
- package/dist/src/messages-BCnZfqrS.cjs +257 -0
- package/dist/src/meteor-DLZZ3osF.cjs +134 -0
- package/dist/src/meteor-DUiCJRC-.js +134 -0
- package/dist/src/modelslab-00cveB8L.cjs +163 -0
- package/dist/src/modelslab-D9sCU_L7.js +163 -0
- package/dist/src/nova-reel-CTapvqYH.js +276 -0
- package/dist/src/nova-reel-DlWuuroF.cjs +278 -0
- package/dist/src/nova-sonic-5UPWfeMv.cjs +363 -0
- package/dist/src/nova-sonic-BhSwQNym.js +363 -0
- package/dist/src/openai-BWrJK9d8.cjs +52 -0
- package/dist/src/openai-DumO8WQn.js +47 -0
- package/dist/src/openclaw-B8brrjC_.cjs +577 -0
- package/dist/src/openclaw-Bkayww9q.js +571 -0
- package/dist/src/opencode-sdk-7xjoDNiM.cjs +562 -0
- package/dist/src/opencode-sdk-SGwAPxht.js +558 -0
- package/dist/src/otlpReceiver-CoAHfAN9.cjs +15 -0
- package/dist/src/otlpReceiver-oO3EQwI9.js +14 -0
- package/dist/src/providerRegistry-4yjhaEM8.js +45 -0
- package/dist/src/providerRegistry-DhV4rJIc.cjs +50 -0
- package/dist/src/providers-B5RJVG-7.cjs +33609 -0
- package/dist/src/providers-BdmZCLzV.js +33262 -0
- package/dist/src/providers-CxtRxn8e.js +2 -0
- package/dist/src/providers-DnQLNbx1.cjs +3 -0
- package/dist/src/pythonUtils-BD0druiM.cjs +275 -0
- package/dist/src/pythonUtils-IBhn5YGR.js +249 -0
- package/dist/src/quiverai-BDOwZBsM.cjs +213 -0
- package/dist/src/quiverai-D3JTF5lD.js +213 -0
- package/dist/src/responses-B2LCDCXZ.js +667 -0
- package/dist/src/responses-BvNm4Xv9.cjs +685 -0
- package/dist/src/rubyUtils-B0NwnfpY.cjs +245 -0
- package/dist/src/rubyUtils-BroxzZ7c.cjs +2 -0
- package/dist/src/rubyUtils-hqVw5UvJ.js +222 -0
- package/dist/src/sagemaker-Cno2V-Sx.js +689 -0
- package/dist/src/sagemaker-fV_KUgs5.cjs +691 -0
- package/dist/src/server-BOuAXb06.cjs +238 -0
- package/dist/src/server-CtI-EWzm.cjs +2 -0
- package/dist/src/server-Cy3DZymt.js +189 -0
- package/dist/src/slack-CP8xBePa.js +135 -0
- package/dist/src/slack-DSQ1yXVb.cjs +135 -0
- package/dist/src/store-BwDDaBjb.cjs +246 -0
- package/dist/src/store-DcbLC593.cjs +2 -0
- package/dist/src/store-IGpqMIkv.js +240 -0
- package/dist/src/tables-3Q2cL7So.cjs +373 -0
- package/dist/src/tables-Bi2fjr4W.js +288 -0
- package/dist/src/telemetry-Bg2WqF79.js +161 -0
- package/dist/src/telemetry-D0x6u5kX.cjs +166 -0
- package/dist/src/telemetry-DXNimrI0.cjs +2 -0
- package/dist/src/text-B_UCRPp2.js +22 -0
- package/dist/src/text-CW1cyrwj.cjs +33 -0
- package/dist/src/tokenUsageUtils-NYT-WKS6.js +138 -0
- package/dist/src/tokenUsageUtils-bVa1ga6f.cjs +173 -0
- package/dist/src/transcription-Cl_W16Pr.js +122 -0
- package/dist/src/transcription-yt1EecY8.cjs +124 -0
- package/dist/src/transform-BCtGrl_W.cjs +228 -0
- package/dist/src/transform-Bv6gG2MJ.cjs +1688 -0
- package/dist/src/transform-CY1wbpRy.js +1507 -0
- package/dist/src/transform-DU8rUL9P.cjs +2 -0
- package/dist/src/transform-yWaShiKr.js +216 -0
- package/dist/src/transformersAvailability-BGkzavwb.js +35 -0
- package/dist/src/transformersAvailability-DKoRtQLy.cjs +35 -0
- package/dist/src/types-5aqHpBwE.cjs +3769 -0
- package/dist/src/types-Bn6D9c4U.js +3300 -0
- package/dist/src/util-BkKlTkI2.js +293 -0
- package/dist/src/util-CTh0bfOm.cjs +1119 -0
- package/dist/src/util-D17oBwo7.cjs +328 -0
- package/dist/src/util-DsS_-v4p.js +613 -0
- package/dist/src/util-DuntT1Ga.js +951 -0
- package/dist/src/util-aWjdCYMI.cjs +667 -0
- package/dist/src/utils-CisQwpjA.js +94 -0
- package/dist/src/utils-yWamDvmz.cjs +123 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/drizzle/0000_lush_hellion.sql +36 -0
- package/drizzle/0001_wide_calypso.sql +3 -0
- package/drizzle/0002_tidy_juggernaut.sql +1 -0
- package/drizzle/0003_lively_naoko.sql +8 -0
- package/drizzle/0004_minor_peter_quill.sql +19 -0
- package/drizzle/0005_silky_millenium_guard.sql +2 -0
- package/drizzle/0006_harsh_caretaker.sql +42 -0
- package/drizzle/0007_cloudy_wong.sql +1 -0
- package/drizzle/0008_broad_boomer.sql +2 -0
- package/drizzle/0009_strong_marten_broadcloak.sql +19 -0
- package/drizzle/0010_needy_bishop.sql +11 -0
- package/drizzle/0011_moaning_millenium_guard.sql +1 -0
- package/drizzle/0012_late_marten_broadcloak.sql +2 -0
- package/drizzle/0013_previous_dormammu.sql +9 -0
- package/drizzle/0014_lazy_captain_universe.sql +2 -0
- package/drizzle/0015_zippy_wallop.sql +29 -0
- package/drizzle/0016_jazzy_zemo.sql +2 -0
- package/drizzle/0017_reflective_praxagora.sql +4 -0
- package/drizzle/0018_fat_vanisher.sql +22 -0
- package/drizzle/0019_new_clint_barton.sql +8 -0
- package/drizzle/0020_skinny_maverick.sql +1 -0
- package/drizzle/0021_mysterious_madelyne_pryor.sql +13 -0
- package/drizzle/0022_sleepy_ultimo.sql +25 -0
- package/drizzle/0023_wooden_mandrill.sql +2 -0
- package/drizzle/AGENTS.md +68 -0
- package/drizzle/CLAUDE.md +1 -0
- package/drizzle/meta/0000_snapshot.json +221 -0
- package/drizzle/meta/0001_snapshot.json +214 -0
- package/drizzle/meta/0002_snapshot.json +221 -0
- package/drizzle/meta/0005_snapshot.json +369 -0
- package/drizzle/meta/0006_snapshot.json +638 -0
- package/drizzle/meta/0007_snapshot.json +640 -0
- package/drizzle/meta/0008_snapshot.json +649 -0
- package/drizzle/meta/0009_snapshot.json +554 -0
- package/drizzle/meta/0010_snapshot.json +619 -0
- package/drizzle/meta/0011_snapshot.json +627 -0
- package/drizzle/meta/0012_snapshot.json +639 -0
- package/drizzle/meta/0013_snapshot.json +717 -0
- package/drizzle/meta/0014_snapshot.json +717 -0
- package/drizzle/meta/0015_snapshot.json +897 -0
- package/drizzle/meta/0016_snapshot.json +1031 -0
- package/drizzle/meta/0018_snapshot.json +1210 -0
- package/drizzle/meta/0019_snapshot.json +1165 -0
- package/drizzle/meta/0020_snapshot.json +1232 -0
- package/drizzle/meta/0021_snapshot.json +1311 -0
- package/drizzle/meta/0022_snapshot.json +1481 -0
- package/drizzle/meta/0023_snapshot.json +1496 -0
- package/drizzle/meta/_journal.json +174 -0
- package/package.json +240 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
const require_logger = require("./logger-DyfK9PBt.cjs");
|
|
2
|
+
const require_invariant = require("./invariant-kfQ8Bu82.cjs");
|
|
3
|
+
const require_chat = require("./chat-CXX3xzkk.cjs");
|
|
4
|
+
const require_completion = require("./completion-Cxrt08sj.cjs");
|
|
5
|
+
//#region src/providers/cloudflare-ai.ts
|
|
6
|
+
function getCloudflareApiConfig(config, env) {
|
|
7
|
+
const apiTokenCandidate = config?.apiKey || (config?.apiKeyEnvar ? require_logger.getEnvString(config.apiKeyEnvar) || env?.[config.apiKeyEnvar] : void 0) || env?.CLOUDFLARE_API_KEY || require_logger.getEnvString("CLOUDFLARE_API_KEY");
|
|
8
|
+
require_invariant.invariant(apiTokenCandidate, "Cloudflare API token required. Supply it via config apiKey or apiKeyEnvar, or the CLOUDFLARE_API_KEY environment variable");
|
|
9
|
+
const accountIdCandidate = config?.accountId || (config?.accountIdEnvar ? require_logger.getEnvString(config.accountIdEnvar) || env?.[config.accountIdEnvar] : void 0) || env?.CLOUDFLARE_ACCOUNT_ID || require_logger.getEnvString("CLOUDFLARE_ACCOUNT_ID");
|
|
10
|
+
require_invariant.invariant(accountIdCandidate, "Cloudflare account ID required. Supply it via config accountId or accountIdEnvar, or the CLOUDFLARE_ACCOUNT_ID environment variable");
|
|
11
|
+
return {
|
|
12
|
+
apiToken: apiTokenCandidate,
|
|
13
|
+
accountId: accountIdCandidate
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function getApiBaseUrl(config, env) {
|
|
17
|
+
if (config?.apiBaseUrl) return config.apiBaseUrl;
|
|
18
|
+
const { accountId } = getCloudflareApiConfig(config, env);
|
|
19
|
+
return `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1`;
|
|
20
|
+
}
|
|
21
|
+
function getPassthroughConfig(config) {
|
|
22
|
+
const { accountId: _accountId, accountIdEnvar: _accountIdEnvar, apiKey: _apiKey, apiKeyEnvar: _apiKeyEnvar, apiBaseUrl: _apiBaseUrl, ...passthrough } = config || {};
|
|
23
|
+
return passthrough;
|
|
24
|
+
}
|
|
25
|
+
var CloudflareAiChatCompletionProvider = class extends require_chat.OpenAiChatCompletionProvider {
|
|
26
|
+
cloudflareConfig;
|
|
27
|
+
modelType = "chat";
|
|
28
|
+
constructor(modelName, providerOptions) {
|
|
29
|
+
const apiBaseUrl = getApiBaseUrl(providerOptions.config, providerOptions.env);
|
|
30
|
+
const passthrough = getPassthroughConfig(providerOptions.config);
|
|
31
|
+
const config = {
|
|
32
|
+
...providerOptions.config,
|
|
33
|
+
apiKeyEnvar: "CLOUDFLARE_API_KEY",
|
|
34
|
+
apiBaseUrl,
|
|
35
|
+
passthrough
|
|
36
|
+
};
|
|
37
|
+
super(modelName, {
|
|
38
|
+
...providerOptions,
|
|
39
|
+
config
|
|
40
|
+
});
|
|
41
|
+
this.cloudflareConfig = providerOptions.config || {};
|
|
42
|
+
}
|
|
43
|
+
id() {
|
|
44
|
+
return `cloudflare-ai:${this.modelType}:${this.modelName}`;
|
|
45
|
+
}
|
|
46
|
+
toString() {
|
|
47
|
+
return `[Cloudflare AI ${this.modelType} Provider ${this.modelName}]`;
|
|
48
|
+
}
|
|
49
|
+
getApiKey() {
|
|
50
|
+
const { apiToken } = getCloudflareApiConfig(this.cloudflareConfig, this.env);
|
|
51
|
+
return apiToken;
|
|
52
|
+
}
|
|
53
|
+
toJSON() {
|
|
54
|
+
return {
|
|
55
|
+
provider: "cloudflare-ai",
|
|
56
|
+
model: this.modelName,
|
|
57
|
+
modelType: this.modelType,
|
|
58
|
+
config: {
|
|
59
|
+
...this.config,
|
|
60
|
+
...this.getApiKey() && { apiKey: void 0 }
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var CloudflareAiCompletionProvider = class extends require_completion.OpenAiCompletionProvider {
|
|
66
|
+
cloudflareConfig;
|
|
67
|
+
modelType = "completion";
|
|
68
|
+
constructor(modelName, providerOptions) {
|
|
69
|
+
const apiBaseUrl = getApiBaseUrl(providerOptions.config, providerOptions.env);
|
|
70
|
+
const passthrough = getPassthroughConfig(providerOptions.config);
|
|
71
|
+
const config = {
|
|
72
|
+
...providerOptions.config,
|
|
73
|
+
apiKeyEnvar: "CLOUDFLARE_API_KEY",
|
|
74
|
+
apiBaseUrl,
|
|
75
|
+
passthrough
|
|
76
|
+
};
|
|
77
|
+
super(modelName, {
|
|
78
|
+
...providerOptions,
|
|
79
|
+
config
|
|
80
|
+
});
|
|
81
|
+
this.cloudflareConfig = providerOptions.config || {};
|
|
82
|
+
}
|
|
83
|
+
id() {
|
|
84
|
+
return `cloudflare-ai:${this.modelType}:${this.modelName}`;
|
|
85
|
+
}
|
|
86
|
+
toString() {
|
|
87
|
+
return `[Cloudflare AI ${this.modelType} Provider ${this.modelName}]`;
|
|
88
|
+
}
|
|
89
|
+
getApiKey() {
|
|
90
|
+
const { apiToken } = getCloudflareApiConfig(this.cloudflareConfig, this.env);
|
|
91
|
+
return apiToken;
|
|
92
|
+
}
|
|
93
|
+
toJSON() {
|
|
94
|
+
return {
|
|
95
|
+
provider: "cloudflare-ai",
|
|
96
|
+
model: this.modelName,
|
|
97
|
+
modelType: this.modelType,
|
|
98
|
+
config: {
|
|
99
|
+
...this.config,
|
|
100
|
+
...this.getApiKey() && { apiKey: void 0 }
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var CloudflareAiEmbeddingProvider = class extends require_completion.OpenAiEmbeddingProvider {
|
|
106
|
+
cloudflareConfig;
|
|
107
|
+
modelType = "embedding";
|
|
108
|
+
constructor(modelName, providerOptions) {
|
|
109
|
+
const apiBaseUrl = getApiBaseUrl(providerOptions.config, providerOptions.env);
|
|
110
|
+
const passthrough = getPassthroughConfig(providerOptions.config);
|
|
111
|
+
const config = {
|
|
112
|
+
...providerOptions.config,
|
|
113
|
+
apiKeyEnvar: "CLOUDFLARE_API_KEY",
|
|
114
|
+
apiBaseUrl,
|
|
115
|
+
passthrough
|
|
116
|
+
};
|
|
117
|
+
super(modelName, {
|
|
118
|
+
...providerOptions,
|
|
119
|
+
config
|
|
120
|
+
});
|
|
121
|
+
this.cloudflareConfig = providerOptions.config || {};
|
|
122
|
+
}
|
|
123
|
+
id() {
|
|
124
|
+
return `cloudflare-ai:${this.modelType}:${this.modelName}`;
|
|
125
|
+
}
|
|
126
|
+
toString() {
|
|
127
|
+
return `[Cloudflare AI ${this.modelType} Provider ${this.modelName}]`;
|
|
128
|
+
}
|
|
129
|
+
getApiKey() {
|
|
130
|
+
const { apiToken } = getCloudflareApiConfig(this.cloudflareConfig, this.env);
|
|
131
|
+
return apiToken;
|
|
132
|
+
}
|
|
133
|
+
toJSON() {
|
|
134
|
+
return {
|
|
135
|
+
provider: "cloudflare-ai",
|
|
136
|
+
model: this.modelName,
|
|
137
|
+
modelType: this.modelType,
|
|
138
|
+
config: {
|
|
139
|
+
...this.config,
|
|
140
|
+
...this.getApiKey() && { apiKey: void 0 }
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
function createCloudflareAiProvider(providerPath, options = {}) {
|
|
146
|
+
const splits = providerPath.split(":");
|
|
147
|
+
const modelType = splits[1];
|
|
148
|
+
const modelName = splits.slice(2).join(":");
|
|
149
|
+
require_invariant.invariant(modelName, "Model name is required");
|
|
150
|
+
switch (modelType) {
|
|
151
|
+
case "chat": return new CloudflareAiChatCompletionProvider(modelName, options);
|
|
152
|
+
case "completion": return new CloudflareAiCompletionProvider(modelName, options);
|
|
153
|
+
case "embedding":
|
|
154
|
+
case "embeddings": return new CloudflareAiEmbeddingProvider(modelName, options);
|
|
155
|
+
default: throw new Error(`Unknown Cloudflare AI model type: ${modelType}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
exports.createCloudflareAiProvider = createCloudflareAiProvider;
|
|
160
|
+
|
|
161
|
+
//# sourceMappingURL=cloudflare-ai-Cmy_R1y2.cjs.map
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
const require_logger = require("./logger-DyfK9PBt.cjs");
|
|
2
|
+
const require_invariant = require("./invariant-kfQ8Bu82.cjs");
|
|
3
|
+
const require_chat = require("./chat-CXX3xzkk.cjs");
|
|
4
|
+
const require_messages = require("./messages-BCnZfqrS.cjs");
|
|
5
|
+
//#region src/providers/cloudflare-gateway.ts
|
|
6
|
+
/**
|
|
7
|
+
* Cloudflare AI Gateway Provider
|
|
8
|
+
*
|
|
9
|
+
* Routes requests to AI providers (OpenAI, Anthropic, etc.) through Cloudflare AI Gateway.
|
|
10
|
+
* Provides caching, rate limiting, analytics, and cost tracking.
|
|
11
|
+
*
|
|
12
|
+
* Gateway URL format: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/{provider}
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* cloudflare-gateway:openai:gpt-4o
|
|
16
|
+
* cloudflare-gateway:anthropic:claude-sonnet-4-20250514
|
|
17
|
+
* cloudflare-gateway:groq:llama-3.3-70b-versatile
|
|
18
|
+
*
|
|
19
|
+
* @see https://developers.cloudflare.com/ai-gateway/
|
|
20
|
+
*/
|
|
21
|
+
const CLOUDFLARE_GATEWAY_BASE_URL = "https://gateway.ai.cloudflare.com/v1";
|
|
22
|
+
/**
|
|
23
|
+
* Supported provider configurations for Cloudflare AI Gateway
|
|
24
|
+
*
|
|
25
|
+
* Note: Some providers have special URL requirements:
|
|
26
|
+
* - azure-openai: Requires resourceName and deploymentName in config
|
|
27
|
+
* - workers-ai: Model name is appended to URL path
|
|
28
|
+
*
|
|
29
|
+
* AWS Bedrock is NOT supported because it requires AWS request signing
|
|
30
|
+
* which is incompatible with the gateway proxy approach.
|
|
31
|
+
*/
|
|
32
|
+
const PROVIDER_CONFIGS = {
|
|
33
|
+
openai: { apiKeyEnvar: "OPENAI_API_KEY" },
|
|
34
|
+
anthropic: { apiKeyEnvar: "ANTHROPIC_API_KEY" },
|
|
35
|
+
groq: { apiKeyEnvar: "GROQ_API_KEY" },
|
|
36
|
+
"perplexity-ai": { apiKeyEnvar: "PERPLEXITY_API_KEY" },
|
|
37
|
+
"google-ai-studio": { apiKeyEnvar: "GOOGLE_API_KEY" },
|
|
38
|
+
mistral: { apiKeyEnvar: "MISTRAL_API_KEY" },
|
|
39
|
+
cohere: { apiKeyEnvar: "COHERE_API_KEY" },
|
|
40
|
+
"azure-openai": { apiKeyEnvar: "AZURE_OPENAI_API_KEY" },
|
|
41
|
+
"workers-ai": { apiKeyEnvar: "CLOUDFLARE_API_KEY" },
|
|
42
|
+
huggingface: { apiKeyEnvar: "HUGGINGFACE_API_KEY" },
|
|
43
|
+
replicate: { apiKeyEnvar: "REPLICATE_API_KEY" },
|
|
44
|
+
grok: { apiKeyEnvar: "XAI_API_KEY" }
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Get a custom environment variable value safely
|
|
48
|
+
* Uses process.env directly for arbitrary env var names to avoid type casting issues
|
|
49
|
+
*/
|
|
50
|
+
function getCustomEnvValue(envVarName, env) {
|
|
51
|
+
const envOverrideValue = env?.[envVarName];
|
|
52
|
+
if (envOverrideValue) return envOverrideValue;
|
|
53
|
+
return process.env[envVarName];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the Cloudflare account ID from config or environment
|
|
57
|
+
*/
|
|
58
|
+
function getAccountId(config, env) {
|
|
59
|
+
if (config?.accountId) return config.accountId;
|
|
60
|
+
if (config?.accountIdEnvar) {
|
|
61
|
+
const customValue = getCustomEnvValue(config.accountIdEnvar, env);
|
|
62
|
+
if (customValue) return customValue;
|
|
63
|
+
require_logger.logger.warn(`[CloudflareGateway] Custom account ID environment variable '${config.accountIdEnvar}' is not set. Falling back to CLOUDFLARE_ACCOUNT_ID.`);
|
|
64
|
+
}
|
|
65
|
+
const accountIdCandidate = env?.CLOUDFLARE_ACCOUNT_ID || require_logger.getEnvString("CLOUDFLARE_ACCOUNT_ID");
|
|
66
|
+
require_invariant.invariant(accountIdCandidate, "Cloudflare account ID required. Supply it via config accountId or accountIdEnvar, or the CLOUDFLARE_ACCOUNT_ID environment variable");
|
|
67
|
+
return accountIdCandidate;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the Cloudflare AI Gateway ID from config or environment
|
|
71
|
+
*/
|
|
72
|
+
function getGatewayId(config, env) {
|
|
73
|
+
if (config?.gatewayId) return config.gatewayId;
|
|
74
|
+
if (config?.gatewayIdEnvar) {
|
|
75
|
+
const customValue = getCustomEnvValue(config.gatewayIdEnvar, env);
|
|
76
|
+
if (customValue) return customValue;
|
|
77
|
+
require_logger.logger.warn(`[CloudflareGateway] Custom gateway ID environment variable '${config.gatewayIdEnvar}' is not set. Falling back to CLOUDFLARE_GATEWAY_ID.`);
|
|
78
|
+
}
|
|
79
|
+
const gatewayIdCandidate = env?.CLOUDFLARE_GATEWAY_ID || require_logger.getEnvString("CLOUDFLARE_GATEWAY_ID");
|
|
80
|
+
require_invariant.invariant(gatewayIdCandidate, "Cloudflare AI Gateway ID required. Supply it via config gatewayId or gatewayIdEnvar, or the CLOUDFLARE_GATEWAY_ID environment variable");
|
|
81
|
+
return gatewayIdCandidate;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get the optional Cloudflare AI Gateway authentication token
|
|
85
|
+
*/
|
|
86
|
+
function getCfAigToken(config, env) {
|
|
87
|
+
if (config?.cfAigToken) return config.cfAigToken;
|
|
88
|
+
if (config?.cfAigTokenEnvar) {
|
|
89
|
+
const customValue = getCustomEnvValue(config.cfAigTokenEnvar, env);
|
|
90
|
+
if (customValue) return customValue;
|
|
91
|
+
}
|
|
92
|
+
return env?.CF_AIG_TOKEN || require_logger.getEnvString("CF_AIG_TOKEN");
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Build the Cloudflare AI Gateway URL for a specific provider
|
|
96
|
+
*
|
|
97
|
+
* Most providers use: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/{provider}
|
|
98
|
+
* Azure OpenAI uses: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/azure-openai/{resource_name}/{deployment_name}
|
|
99
|
+
* Workers AI uses: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/workers-ai/{model_id}
|
|
100
|
+
*/
|
|
101
|
+
function buildGatewayUrl(accountId, gatewayId, provider, config, modelName) {
|
|
102
|
+
const baseUrl = `${CLOUDFLARE_GATEWAY_BASE_URL}/${accountId}/${gatewayId}`;
|
|
103
|
+
if (provider === "azure-openai") {
|
|
104
|
+
const resourceName = config?.resourceName;
|
|
105
|
+
const deploymentName = config?.deploymentName;
|
|
106
|
+
require_invariant.invariant(resourceName, "Azure OpenAI requires resourceName in config. Example: cloudflare-gateway:azure-openai:gpt-4 with config.resourceName set");
|
|
107
|
+
require_invariant.invariant(deploymentName, "Azure OpenAI requires deploymentName in config. Example: cloudflare-gateway:azure-openai:gpt-4 with config.deploymentName set");
|
|
108
|
+
return `${baseUrl}/azure-openai/${resourceName}/${deploymentName}`;
|
|
109
|
+
}
|
|
110
|
+
if (provider === "workers-ai") {
|
|
111
|
+
require_invariant.invariant(modelName, "Workers AI requires a model name (e.g., @cf/meta/llama-3.1-8b-instruct)");
|
|
112
|
+
return `${baseUrl}/workers-ai/${modelName}`;
|
|
113
|
+
}
|
|
114
|
+
return `${baseUrl}/${provider}`;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Extract Cloudflare-specific config keys that shouldn't be passed to the underlying provider
|
|
118
|
+
*/
|
|
119
|
+
function getPassthroughConfig(config) {
|
|
120
|
+
const { accountId: _accountId, accountIdEnvar: _accountIdEnvar, gatewayId: _gatewayId, gatewayIdEnvar: _gatewayIdEnvar, cfAigToken: _cfAigToken, cfAigTokenEnvar: _cfAigTokenEnvar, resourceName: _resourceName, deploymentName: _deploymentName, apiVersion: _apiVersion, ...passthrough } = config || {};
|
|
121
|
+
return passthrough;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Cloudflare AI Gateway provider for OpenAI-compatible APIs
|
|
125
|
+
*
|
|
126
|
+
* Routes requests to OpenAI, Groq, Perplexity, Mistral, etc. through Cloudflare AI Gateway
|
|
127
|
+
*/
|
|
128
|
+
var CloudflareGatewayOpenAiProvider = class extends require_chat.OpenAiChatCompletionProvider {
|
|
129
|
+
underlyingProvider;
|
|
130
|
+
constructor(underlyingProvider, modelName, providerOptions) {
|
|
131
|
+
const gatewayUrl = buildGatewayUrl(getAccountId(providerOptions.config, providerOptions.env), getGatewayId(providerOptions.config, providerOptions.env), underlyingProvider, providerOptions.config, modelName);
|
|
132
|
+
const passthrough = getPassthroughConfig(providerOptions.config);
|
|
133
|
+
const providerConfig = PROVIDER_CONFIGS[underlyingProvider];
|
|
134
|
+
const cfAigToken = getCfAigToken(providerOptions.config, providerOptions.env);
|
|
135
|
+
const headers = { ...providerOptions.config?.headers || {} };
|
|
136
|
+
if (cfAigToken) headers["cf-aig-authorization"] = `Bearer ${cfAigToken}`;
|
|
137
|
+
let finalGatewayUrl = gatewayUrl;
|
|
138
|
+
let apiKeyEnvar;
|
|
139
|
+
if (underlyingProvider === "azure-openai") {
|
|
140
|
+
const azureApiKey = providerOptions.config?.apiKey || require_logger.getEnvString("AZURE_OPENAI_API_KEY");
|
|
141
|
+
require_invariant.invariant(azureApiKey, "Azure OpenAI API key is required. Set the AZURE_OPENAI_API_KEY environment variable or add apiKey to the provider config.");
|
|
142
|
+
headers["api-key"] = azureApiKey;
|
|
143
|
+
apiKeyEnvar = void 0;
|
|
144
|
+
finalGatewayUrl = `${gatewayUrl}?api-version=${providerOptions.config?.apiVersion || "2024-12-01-preview"}`;
|
|
145
|
+
} else apiKeyEnvar = providerOptions.config?.apiKeyEnvar || providerConfig?.apiKeyEnvar;
|
|
146
|
+
const config = {
|
|
147
|
+
...passthrough,
|
|
148
|
+
apiKeyEnvar,
|
|
149
|
+
apiBaseUrl: finalGatewayUrl,
|
|
150
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
151
|
+
};
|
|
152
|
+
super(modelName, {
|
|
153
|
+
...providerOptions,
|
|
154
|
+
config
|
|
155
|
+
});
|
|
156
|
+
this.underlyingProvider = underlyingProvider;
|
|
157
|
+
require_logger.logger.debug(`[CloudflareGateway] Configured ${underlyingProvider}:${modelName}`, {
|
|
158
|
+
gatewayUrl: finalGatewayUrl,
|
|
159
|
+
hasApiKey: !!providerOptions.config?.apiKey,
|
|
160
|
+
hasCfAigToken: !!cfAigToken
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
id() {
|
|
164
|
+
return `cloudflare-gateway:${this.underlyingProvider}:${this.modelName}`;
|
|
165
|
+
}
|
|
166
|
+
toString() {
|
|
167
|
+
return `[Cloudflare AI Gateway ${this.underlyingProvider} Provider ${this.modelName}]`;
|
|
168
|
+
}
|
|
169
|
+
toJSON() {
|
|
170
|
+
return {
|
|
171
|
+
provider: "cloudflare-gateway",
|
|
172
|
+
underlyingProvider: this.underlyingProvider,
|
|
173
|
+
model: this.modelName,
|
|
174
|
+
config: {
|
|
175
|
+
...this.config,
|
|
176
|
+
apiKey: void 0
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Extract Anthropic-compatible options from the gateway config
|
|
183
|
+
*/
|
|
184
|
+
function getAnthropicPassthroughConfig(config) {
|
|
185
|
+
if (!config) return {};
|
|
186
|
+
const { apiKey, max_tokens, temperature, top_p, cost } = config;
|
|
187
|
+
const top_k = config.top_k;
|
|
188
|
+
return {
|
|
189
|
+
...apiKey !== void 0 && { apiKey },
|
|
190
|
+
...max_tokens !== void 0 && { max_tokens },
|
|
191
|
+
...temperature !== void 0 && { temperature },
|
|
192
|
+
...top_p !== void 0 && { top_p },
|
|
193
|
+
...top_k !== void 0 && { top_k },
|
|
194
|
+
...cost !== void 0 && { cost }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Cloudflare AI Gateway provider for Anthropic
|
|
199
|
+
*
|
|
200
|
+
* Routes requests to Anthropic through Cloudflare AI Gateway
|
|
201
|
+
*/
|
|
202
|
+
var CloudflareGatewayAnthropicProvider = class extends require_messages.AnthropicMessagesProvider {
|
|
203
|
+
constructor(modelName, providerOptions) {
|
|
204
|
+
const gatewayUrl = buildGatewayUrl(getAccountId(providerOptions.config, providerOptions.env), getGatewayId(providerOptions.config, providerOptions.env), "anthropic");
|
|
205
|
+
const passthrough = getAnthropicPassthroughConfig(providerOptions.config);
|
|
206
|
+
const cfAigToken = getCfAigToken(providerOptions.config, providerOptions.env);
|
|
207
|
+
const headers = { ...providerOptions.config?.headers || {} };
|
|
208
|
+
if (cfAigToken) headers["cf-aig-authorization"] = `Bearer ${cfAigToken}`;
|
|
209
|
+
const config = {
|
|
210
|
+
...passthrough,
|
|
211
|
+
apiBaseUrl: gatewayUrl,
|
|
212
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0
|
|
213
|
+
};
|
|
214
|
+
super(modelName, {
|
|
215
|
+
...providerOptions,
|
|
216
|
+
config
|
|
217
|
+
});
|
|
218
|
+
require_logger.logger.debug(`[CloudflareGateway] Configured anthropic:${modelName}`, {
|
|
219
|
+
gatewayUrl,
|
|
220
|
+
hasApiKey: !!providerOptions.config?.apiKey,
|
|
221
|
+
hasCfAigToken: !!cfAigToken
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
id() {
|
|
225
|
+
return `cloudflare-gateway:anthropic:${this.modelName}`;
|
|
226
|
+
}
|
|
227
|
+
toString() {
|
|
228
|
+
return `[Cloudflare AI Gateway Anthropic Provider ${this.modelName}]`;
|
|
229
|
+
}
|
|
230
|
+
toJSON() {
|
|
231
|
+
return {
|
|
232
|
+
provider: "cloudflare-gateway",
|
|
233
|
+
underlyingProvider: "anthropic",
|
|
234
|
+
model: this.modelName,
|
|
235
|
+
config: {
|
|
236
|
+
...this.config,
|
|
237
|
+
apiKey: void 0
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Create a Cloudflare AI Gateway provider from a provider path
|
|
244
|
+
*
|
|
245
|
+
* @param providerPath - Provider path in format cloudflare-gateway:{provider}:{model}
|
|
246
|
+
* @param options - Provider options including config and environment
|
|
247
|
+
* @returns Configured provider instance
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```yaml
|
|
251
|
+
* providers:
|
|
252
|
+
* - id: cloudflare-gateway:openai:gpt-4o
|
|
253
|
+
* config:
|
|
254
|
+
* accountId: ${CLOUDFLARE_ACCOUNT_ID}
|
|
255
|
+
* gatewayId: ${CLOUDFLARE_GATEWAY_ID}
|
|
256
|
+
* temperature: 0.7
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
function createCloudflareGatewayProvider(providerPath, options = {}) {
|
|
260
|
+
const splits = providerPath.split(":");
|
|
261
|
+
if (splits.length < 3) throw new Error(`Invalid cloudflare-gateway provider path: "${providerPath}". Expected format: cloudflare-gateway:{provider}:{model} (e.g., cloudflare-gateway:openai:gpt-4o)`);
|
|
262
|
+
const underlyingProvider = splits[1];
|
|
263
|
+
const modelName = splits.slice(2).join(":");
|
|
264
|
+
require_invariant.invariant(modelName, "Model name is required for cloudflare-gateway provider");
|
|
265
|
+
if (!PROVIDER_CONFIGS[underlyingProvider]) throw new Error(`Unsupported Cloudflare AI Gateway provider: "${underlyingProvider}". Supported providers: ${Object.keys(PROVIDER_CONFIGS).join(", ")}`);
|
|
266
|
+
if (underlyingProvider === "anthropic") return new CloudflareGatewayAnthropicProvider(modelName, options);
|
|
267
|
+
return new CloudflareGatewayOpenAiProvider(underlyingProvider, modelName, options);
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
270
|
+
exports.createCloudflareGatewayProvider = createCloudflareGatewayProvider;
|
|
271
|
+
|
|
272
|
+
//# sourceMappingURL=cloudflare-gateway-B9tVQKok.cjs.map
|