@standardagents/builder 0.16.0 → 0.16.1-next.1e58032
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/dist/built-in-routes.js +189 -142
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/UsersView.js +1 -1
- package/dist/{index-EaxysUHv.d.ts → index-BnrKzXpJ.d.ts} +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +63 -22
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +10 -7
- package/dist/runtime.js +63 -22
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +4 -4
package/dist/built-in-routes.js
CHANGED
|
@@ -874,11 +874,38 @@ var init_TestProvider = __esm({
|
|
|
874
874
|
}
|
|
875
875
|
});
|
|
876
876
|
|
|
877
|
+
// src/agents/providers/platform-routing.ts
|
|
878
|
+
function stringEnv(value) {
|
|
879
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
880
|
+
}
|
|
881
|
+
function resolvePlatformRouting(providerName, env2) {
|
|
882
|
+
const apiKey = stringEnv(env2.STANDARD_AGENTS_API_KEY) ?? stringEnv(env2.PLATFORM_API_KEY);
|
|
883
|
+
if (!apiKey) return null;
|
|
884
|
+
const origin = (stringEnv(env2.STANDARD_AGENTS_PROXY_URL) ?? stringEnv(env2.PLATFORM_ENDPOINT) ?? stringEnv(env2.STANDARD_AGENTS_API_URL) ?? DEFAULT_PLATFORM_PROXY_ORIGIN).replace(/\/+$/, "");
|
|
885
|
+
const provider = providerName.toLowerCase();
|
|
886
|
+
const basePath = PROVIDER_BASE_PATHS[provider] ?? "";
|
|
887
|
+
return {
|
|
888
|
+
apiKey,
|
|
889
|
+
origin,
|
|
890
|
+
baseUrl: `${origin}/v1/proxy/${encodeURIComponent(provider)}${basePath}`
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
var DEFAULT_PLATFORM_PROXY_ORIGIN, PROVIDER_BASE_PATHS;
|
|
894
|
+
var init_platform_routing = __esm({
|
|
895
|
+
"src/agents/providers/platform-routing.ts"() {
|
|
896
|
+
DEFAULT_PLATFORM_PROXY_ORIGIN = "https://proxy.standardagents.ai";
|
|
897
|
+
PROVIDER_BASE_PATHS = {
|
|
898
|
+
cloudflare: "/ai/v1"
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
|
|
877
903
|
// src/agents/providers/ProviderRegistry.ts
|
|
878
904
|
var ProviderRegistryImpl, ProviderRegistry;
|
|
879
905
|
var init_ProviderRegistry = __esm({
|
|
880
906
|
"src/agents/providers/ProviderRegistry.ts"() {
|
|
881
907
|
init_TestProvider();
|
|
908
|
+
init_platform_routing();
|
|
882
909
|
ProviderRegistryImpl = class {
|
|
883
910
|
providerCache = /* @__PURE__ */ new Map();
|
|
884
911
|
providerOverrideFn = null;
|
|
@@ -916,9 +943,9 @@ var init_ProviderRegistry = __esm({
|
|
|
916
943
|
const fingerprint = this.getProviderFingerprint(providerName, modelDef);
|
|
917
944
|
const cached = this.providerCache.get(modelName);
|
|
918
945
|
if (cached?.fingerprint === fingerprint) {
|
|
919
|
-
return this.buildResult(cached.provider, modelDef);
|
|
946
|
+
return this.buildResult(cached.provider, modelDef, false);
|
|
920
947
|
}
|
|
921
|
-
return this.cacheAndReturn(modelName, createTestProvider(), modelDef, fingerprint);
|
|
948
|
+
return this.cacheAndReturn(modelName, createTestProvider(), modelDef, fingerprint, false);
|
|
922
949
|
}
|
|
923
950
|
const apiKey = this.getApiKeyForProvider(providerName, env2);
|
|
924
951
|
if (apiKey) {
|
|
@@ -935,34 +962,47 @@ var init_ProviderRegistry = __esm({
|
|
|
935
962
|
const fingerprint = this.getProviderFingerprint(providerName, modelDef, config);
|
|
936
963
|
const cached = this.providerCache.get(modelName);
|
|
937
964
|
if (cached?.fingerprint === fingerprint) {
|
|
938
|
-
return this.buildResult(cached.provider, modelDef);
|
|
965
|
+
return this.buildResult(cached.provider, modelDef, false);
|
|
939
966
|
}
|
|
940
|
-
return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint);
|
|
967
|
+
return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, false);
|
|
941
968
|
}
|
|
942
969
|
if (this.providerOverrideFn) {
|
|
943
970
|
const overrideFingerprint = this.getProviderFingerprint(`override:${this.providerOverrideRevision}`, modelDef);
|
|
944
971
|
const overrideCached = this.providerCache.get(modelName);
|
|
945
972
|
if (overrideCached?.fingerprint === overrideFingerprint) {
|
|
946
|
-
return this.buildResult(overrideCached.provider, modelDef);
|
|
973
|
+
return this.buildResult(overrideCached.provider, modelDef, true);
|
|
947
974
|
}
|
|
948
975
|
const overrideProvider = this.providerOverrideFn(modelName, modelDef, env2);
|
|
949
976
|
if (overrideProvider) {
|
|
950
|
-
return this.cacheAndReturn(modelName, overrideProvider, modelDef, overrideFingerprint);
|
|
977
|
+
return this.cacheAndReturn(modelName, overrideProvider, modelDef, overrideFingerprint, true);
|
|
951
978
|
}
|
|
952
979
|
}
|
|
980
|
+
const routing = resolvePlatformRouting(providerName, env2);
|
|
981
|
+
if (routing) {
|
|
982
|
+
const config = {
|
|
983
|
+
apiKey: routing.apiKey,
|
|
984
|
+
baseUrl: routing.baseUrl
|
|
985
|
+
};
|
|
986
|
+
const fingerprint = this.getProviderFingerprint(`platform:${providerName}`, modelDef, config);
|
|
987
|
+
const cached = this.providerCache.get(modelName);
|
|
988
|
+
if (cached?.fingerprint === fingerprint) {
|
|
989
|
+
return this.buildResult(cached.provider, modelDef, true);
|
|
990
|
+
}
|
|
991
|
+
return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true);
|
|
992
|
+
}
|
|
953
993
|
throw new Error(`No API key found for provider: ${providerName}. Set the provider key or STANDARD_AGENTS_API_KEY.`);
|
|
954
994
|
}
|
|
955
|
-
buildResult(provider, modelDef) {
|
|
956
|
-
return { provider, modelName: modelDef.model, modelDef };
|
|
995
|
+
buildResult(provider, modelDef, viaPlatform) {
|
|
996
|
+
return { provider, modelName: modelDef.model, modelDef, viaPlatform };
|
|
957
997
|
}
|
|
958
|
-
cacheAndReturn(modelName, provider, modelDef, fingerprint) {
|
|
959
|
-
this.providerCache.set(modelName, { provider, fingerprint });
|
|
960
|
-
return this.buildResult(provider, modelDef);
|
|
998
|
+
cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform) {
|
|
999
|
+
this.providerCache.set(modelName, { provider, fingerprint, viaPlatform });
|
|
1000
|
+
return this.buildResult(provider, modelDef, viaPlatform);
|
|
961
1001
|
}
|
|
962
1002
|
getProviderFingerprint(providerName, modelDef, config) {
|
|
963
1003
|
return JSON.stringify({
|
|
964
1004
|
providerName,
|
|
965
|
-
baseUrl: modelDef.providerOptions?.baseUrl ?? null,
|
|
1005
|
+
baseUrl: config?.baseUrl ?? modelDef.providerOptions?.baseUrl ?? null,
|
|
966
1006
|
apiKey: config?.apiKey ?? null,
|
|
967
1007
|
accountId: config?.accountId ?? null
|
|
968
1008
|
});
|
|
@@ -1638,7 +1678,7 @@ var init_LLMRequest = __esm({
|
|
|
1638
1678
|
*/
|
|
1639
1679
|
static async callModel(modelId, context, state, logId) {
|
|
1640
1680
|
const { ProviderRegistry: ProviderRegistry2 } = await Promise.resolve().then(() => (init_providers(), providers_exports));
|
|
1641
|
-
const { provider, modelName, modelDef } = await ProviderRegistry2.getProvider(
|
|
1681
|
+
const { provider, modelName, modelDef, viaPlatform } = await ProviderRegistry2.getProvider(
|
|
1642
1682
|
modelId,
|
|
1643
1683
|
state.env,
|
|
1644
1684
|
state.thread.instance
|
|
@@ -1772,6 +1812,7 @@ var init_LLMRequest = __esm({
|
|
|
1772
1812
|
}
|
|
1773
1813
|
};
|
|
1774
1814
|
response._provider = provider;
|
|
1815
|
+
response._viaPlatform = viaPlatform;
|
|
1775
1816
|
response._providerResponseId = providerResponseId;
|
|
1776
1817
|
response._aggregate_response = {
|
|
1777
1818
|
id: responseId,
|
|
@@ -1849,7 +1890,7 @@ var init_LLMRequest = __esm({
|
|
|
1849
1890
|
try {
|
|
1850
1891
|
const toolsCalled = response.tool_calls ? JSON.stringify(response.tool_calls.map((tc) => tc.function.name)) : null;
|
|
1851
1892
|
const providerName = response._provider?.name;
|
|
1852
|
-
const standardAgentsRouterUsed = providerName === "platform";
|
|
1893
|
+
const standardAgentsRouterUsed = response._viaPlatform === true || providerName === "platform";
|
|
1853
1894
|
const resolvedPricing = resolveModelPricing(modelDef, providerName);
|
|
1854
1895
|
const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
|
|
1855
1896
|
const providerReportedCost = typeof response.usage.cost === "number" ? response.usage.cost : typeof response.usage.cost === "string" ? parseFloat(response.usage.cost) : null;
|
|
@@ -5861,7 +5902,7 @@ var init_FlowEngine = __esm({
|
|
|
5861
5902
|
max_session_turns: newAgentDef.maxSessionTurns ?? null,
|
|
5862
5903
|
side_a_label: newAgentDef.sideA?.label ?? null,
|
|
5863
5904
|
side_a_agent_prompt: newAgentDef.sideA?.prompt ?? null,
|
|
5864
|
-
side_a_stop_on_response: newAgentDef.sideA?.stopOnResponse ??
|
|
5905
|
+
side_a_stop_on_response: newAgentDef.sideA?.stopOnResponse ?? true,
|
|
5865
5906
|
side_a_stop_tool: newAgentDef.sideA?.stopTool ?? null,
|
|
5866
5907
|
side_a_stop_tool_response_property: newAgentDef.sideA?.stopToolResponseProperty ?? null,
|
|
5867
5908
|
side_a_max_steps: newAgentDef.sideA?.maxSteps ?? null,
|
|
@@ -5876,7 +5917,7 @@ var init_FlowEngine = __esm({
|
|
|
5876
5917
|
side_a_session_status_attachments_property: sideASession.status.attachmentsProperty,
|
|
5877
5918
|
side_b_label: newAgentDef.sideB?.label ?? null,
|
|
5878
5919
|
side_b_agent_prompt: newAgentDef.sideB?.prompt ?? null,
|
|
5879
|
-
side_b_stop_on_response: newAgentDef.sideB?.stopOnResponse ??
|
|
5920
|
+
side_b_stop_on_response: newAgentDef.sideB?.stopOnResponse ?? true,
|
|
5880
5921
|
side_b_stop_tool: newAgentDef.sideB?.stopTool ?? null,
|
|
5881
5922
|
side_b_stop_tool_response_property: newAgentDef.sideB?.stopToolResponseProperty ?? null,
|
|
5882
5923
|
side_b_max_steps: newAgentDef.sideB?.maxSteps ?? null,
|
|
@@ -12783,6 +12824,9 @@ var init_CloudflareProvider = __esm({
|
|
|
12783
12824
|
if (accountScopedMatch) {
|
|
12784
12825
|
return `${accountScopedMatch[1]}/ai/models/search`;
|
|
12785
12826
|
}
|
|
12827
|
+
if (baseUrl.endsWith("/ai/v1")) {
|
|
12828
|
+
return `${baseUrl.slice(0, -"/ai/v1".length)}/ai/models/search`;
|
|
12829
|
+
}
|
|
12786
12830
|
throw new ProviderError(
|
|
12787
12831
|
"Cloudflare model discovery requires CLOUDFLARE_ACCOUNT_ID or an account-scoped baseUrl.",
|
|
12788
12832
|
"invalid_request"
|
|
@@ -61688,7 +61732,7 @@ async function getPlatformIdentity(env2) {
|
|
|
61688
61732
|
const endpoint = platformEndpoint(env2);
|
|
61689
61733
|
const verifiedAccount = await fetchPlatformAccount(endpoint, token);
|
|
61690
61734
|
const account = verifiedAccount ?? await fallbackAccountForToken(token);
|
|
61691
|
-
const username = sanitizeUsername(
|
|
61735
|
+
const username = sanitizeUsername(account.slug);
|
|
61692
61736
|
return {
|
|
61693
61737
|
connected: true,
|
|
61694
61738
|
verified: verifiedAccount !== null,
|
|
@@ -61716,11 +61760,17 @@ async function createPlatformLocalSession(env2) {
|
|
|
61716
61760
|
const username = identity.user.username;
|
|
61717
61761
|
let user = await agentBuilder.getUserByUsername(username);
|
|
61718
61762
|
if (!user) {
|
|
61719
|
-
|
|
61720
|
-
|
|
61721
|
-
|
|
61722
|
-
|
|
61723
|
-
}
|
|
61763
|
+
const legacyUsername = sanitizeUsername(`standard-agents-${identity.account.slug}`);
|
|
61764
|
+
const legacyUser = legacyUsername !== username ? await agentBuilder.getUserByUsername(legacyUsername) : null;
|
|
61765
|
+
if (legacyUser) {
|
|
61766
|
+
user = await agentBuilder.updateUser(legacyUser.id, { username }) ?? legacyUser;
|
|
61767
|
+
} else {
|
|
61768
|
+
user = await agentBuilder.createUser({
|
|
61769
|
+
username,
|
|
61770
|
+
password_hash: await hashPassword(crypto.randomUUID()),
|
|
61771
|
+
role: "admin"
|
|
61772
|
+
});
|
|
61773
|
+
}
|
|
61724
61774
|
}
|
|
61725
61775
|
const token = generateUserToken();
|
|
61726
61776
|
const tokenHash = await hashToken(token);
|
|
@@ -62830,7 +62880,17 @@ var index_get_default2 = defineController2(async ({ req, env: env2 }) => {
|
|
|
62830
62880
|
const agentBuilderId = env2.AGENT_BUILDER.idFromName("singleton");
|
|
62831
62881
|
const agentBuilder = env2.AGENT_BUILDER.get(agentBuilderId);
|
|
62832
62882
|
const users = await agentBuilder.listUsers();
|
|
62833
|
-
|
|
62883
|
+
let platformUsername = null;
|
|
62884
|
+
const platformEnv = env2;
|
|
62885
|
+
if (hasPlatformApiKey(platformEnv)) {
|
|
62886
|
+
const identity = await getPlatformIdentity(platformEnv).catch(() => null);
|
|
62887
|
+
platformUsername = identity?.user.username ?? null;
|
|
62888
|
+
}
|
|
62889
|
+
const usersWithSource = users.map((user) => ({
|
|
62890
|
+
...user,
|
|
62891
|
+
source: platformUsername && user.username === platformUsername ? "standard_agents" : "local"
|
|
62892
|
+
}));
|
|
62893
|
+
return Response.json({ users: usersWithSource });
|
|
62834
62894
|
} catch (error) {
|
|
62835
62895
|
console.error("List users error:", error);
|
|
62836
62896
|
return Response.json(
|
|
@@ -64159,34 +64219,8 @@ var instance_patch_default = defineController2(async ({ req, env: env2 }) => {
|
|
|
64159
64219
|
}
|
|
64160
64220
|
});
|
|
64161
64221
|
|
|
64162
|
-
// src/api/models/
|
|
64163
|
-
|
|
64164
|
-
var CLOUDFLARE_PROVIDER_MODEL_ID = /^@cf\//i;
|
|
64165
|
-
function isOpaqueModelId(modelId) {
|
|
64166
|
-
if (!modelId) return true;
|
|
64167
|
-
return UUID_LIKE_MODEL_ID.test(modelId) || CLOUDFLARE_PROVIDER_MODEL_ID.test(modelId);
|
|
64168
|
-
}
|
|
64169
|
-
function getModelIconLookup(model) {
|
|
64170
|
-
if (model.id && !isOpaqueModelId(model.id)) {
|
|
64171
|
-
return model.id;
|
|
64172
|
-
}
|
|
64173
|
-
return model.slug || model.name || model.id;
|
|
64174
|
-
}
|
|
64175
|
-
function getExecutableModelId(provider, model) {
|
|
64176
|
-
if (model.id && !isOpaqueModelId(model.id)) {
|
|
64177
|
-
return model.id;
|
|
64178
|
-
}
|
|
64179
|
-
if (provider === "cloudflare") {
|
|
64180
|
-
const publicCloudflareId = [model.name, model.slug].find((value) => typeof value === "string" && value.length > 0 && value.includes("/"));
|
|
64181
|
-
if (publicCloudflareId) {
|
|
64182
|
-
return publicCloudflareId.startsWith("@cf/") ? publicCloudflareId : `@cf/${publicCloudflareId.replace(/^@cf\//, "")}`;
|
|
64183
|
-
}
|
|
64184
|
-
}
|
|
64185
|
-
return model.slug || model.name || model.id;
|
|
64186
|
-
}
|
|
64187
|
-
function getProviderModelIconUrl(provider, model) {
|
|
64188
|
-
return `/api/providers/${encodeURIComponent(provider)}/icon?model=${encodeURIComponent(getModelIconLookup(model))}`;
|
|
64189
|
-
}
|
|
64222
|
+
// src/api/models/_provider-config.ts
|
|
64223
|
+
init_platform_routing();
|
|
64190
64224
|
var PROVIDER_CONFIGS = {
|
|
64191
64225
|
cloudflare: {
|
|
64192
64226
|
envKey: "CLOUDFLARE_API_TOKEN",
|
|
@@ -64195,54 +64229,102 @@ var PROVIDER_CONFIGS = {
|
|
|
64195
64229
|
accountId: env2.CLOUDFLARE_ACCOUNT_ID,
|
|
64196
64230
|
baseUrl: env2.CLOUDFLARE_ACCOUNT_ID ? `https://api.cloudflare.com/client/v4/accounts/${env2.CLOUDFLARE_ACCOUNT_ID}/ai/v1` : void 0
|
|
64197
64231
|
}),
|
|
64198
|
-
|
|
64232
|
+
importFactory: async () => {
|
|
64199
64233
|
const { cloudflare: cloudflare2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
64200
64234
|
return cloudflare2;
|
|
64201
64235
|
}
|
|
64202
64236
|
},
|
|
64203
64237
|
cerebras: {
|
|
64204
64238
|
envKey: "CEREBRAS_API_KEY",
|
|
64205
|
-
|
|
64239
|
+
importFactory: async () => {
|
|
64206
64240
|
const { cerebras: cerebras2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
|
|
64207
64241
|
return cerebras2;
|
|
64208
64242
|
}
|
|
64209
64243
|
},
|
|
64210
64244
|
google: {
|
|
64211
64245
|
envKey: "GOOGLE_API_KEY",
|
|
64212
|
-
|
|
64246
|
+
importFactory: async () => {
|
|
64213
64247
|
const { google: google2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports2));
|
|
64214
64248
|
return google2;
|
|
64215
64249
|
}
|
|
64216
64250
|
},
|
|
64217
64251
|
groq: {
|
|
64218
64252
|
envKey: "GROQ_API_KEY",
|
|
64219
|
-
|
|
64253
|
+
importFactory: async () => {
|
|
64220
64254
|
const { groq: groq2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports3));
|
|
64221
64255
|
return groq2;
|
|
64222
64256
|
}
|
|
64223
64257
|
},
|
|
64224
64258
|
openai: {
|
|
64225
64259
|
envKey: "OPENAI_API_KEY",
|
|
64226
|
-
|
|
64260
|
+
importFactory: async () => {
|
|
64227
64261
|
const { openai: openai2 } = await Promise.resolve().then(() => (init_dist4(), dist_exports4));
|
|
64228
64262
|
return openai2;
|
|
64229
64263
|
}
|
|
64230
64264
|
},
|
|
64231
64265
|
openrouter: {
|
|
64232
64266
|
envKey: "OPENROUTER_API_KEY",
|
|
64233
|
-
|
|
64267
|
+
importFactory: async () => {
|
|
64234
64268
|
const { openrouter: openrouter2 } = await Promise.resolve().then(() => (init_dist5(), dist_exports5));
|
|
64235
64269
|
return openrouter2;
|
|
64236
64270
|
}
|
|
64237
64271
|
},
|
|
64238
64272
|
xai: {
|
|
64239
64273
|
envKey: "XAI_API_KEY",
|
|
64240
|
-
|
|
64274
|
+
importFactory: async () => {
|
|
64241
64275
|
const { xai: xai3 } = await Promise.resolve().then(() => (init_dist10(), dist_exports6));
|
|
64242
64276
|
return xai3;
|
|
64243
64277
|
}
|
|
64244
64278
|
}
|
|
64245
64279
|
};
|
|
64280
|
+
function resolveProviderClientConfig(provider, env2) {
|
|
64281
|
+
const config = PROVIDER_CONFIGS[provider];
|
|
64282
|
+
if (!config) return null;
|
|
64283
|
+
const apiKey = env2[config.envKey];
|
|
64284
|
+
if (apiKey) {
|
|
64285
|
+
return {
|
|
64286
|
+
providerConfig: config.getConfig?.(env2, apiKey) ?? { apiKey },
|
|
64287
|
+
viaPlatform: false
|
|
64288
|
+
};
|
|
64289
|
+
}
|
|
64290
|
+
const routing = resolvePlatformRouting(provider, env2);
|
|
64291
|
+
if (routing) {
|
|
64292
|
+
return {
|
|
64293
|
+
providerConfig: { apiKey: routing.apiKey, baseUrl: routing.baseUrl },
|
|
64294
|
+
viaPlatform: true
|
|
64295
|
+
};
|
|
64296
|
+
}
|
|
64297
|
+
return null;
|
|
64298
|
+
}
|
|
64299
|
+
|
|
64300
|
+
// src/api/models/available.post.ts
|
|
64301
|
+
var UUID_LIKE_MODEL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
64302
|
+
var CLOUDFLARE_PROVIDER_MODEL_ID = /^@cf\//i;
|
|
64303
|
+
function isOpaqueModelId(modelId) {
|
|
64304
|
+
if (!modelId) return true;
|
|
64305
|
+
return UUID_LIKE_MODEL_ID.test(modelId) || CLOUDFLARE_PROVIDER_MODEL_ID.test(modelId);
|
|
64306
|
+
}
|
|
64307
|
+
function getModelIconLookup(model) {
|
|
64308
|
+
if (model.id && !isOpaqueModelId(model.id)) {
|
|
64309
|
+
return model.id;
|
|
64310
|
+
}
|
|
64311
|
+
return model.slug || model.name || model.id;
|
|
64312
|
+
}
|
|
64313
|
+
function getExecutableModelId(provider, model) {
|
|
64314
|
+
if (model.id && !isOpaqueModelId(model.id)) {
|
|
64315
|
+
return model.id;
|
|
64316
|
+
}
|
|
64317
|
+
if (provider === "cloudflare") {
|
|
64318
|
+
const publicCloudflareId = [model.name, model.slug].find((value) => typeof value === "string" && value.length > 0 && value.includes("/"));
|
|
64319
|
+
if (publicCloudflareId) {
|
|
64320
|
+
return publicCloudflareId.startsWith("@cf/") ? publicCloudflareId : `@cf/${publicCloudflareId.replace(/^@cf\//, "")}`;
|
|
64321
|
+
}
|
|
64322
|
+
}
|
|
64323
|
+
return model.slug || model.name || model.id;
|
|
64324
|
+
}
|
|
64325
|
+
function getProviderModelIconUrl(provider, model) {
|
|
64326
|
+
return `/api/providers/${encodeURIComponent(provider)}/icon?model=${encodeURIComponent(getModelIconLookup(model))}`;
|
|
64327
|
+
}
|
|
64246
64328
|
var available_post_default = defineController2(async ({ req, env: env2 }) => {
|
|
64247
64329
|
const body = await req.json().catch(() => ({}));
|
|
64248
64330
|
const {
|
|
@@ -64262,17 +64344,16 @@ var available_post_default = defineController2(async ({ req, env: env2 }) => {
|
|
|
64262
64344
|
{ status: 400 }
|
|
64263
64345
|
);
|
|
64264
64346
|
}
|
|
64265
|
-
const
|
|
64266
|
-
if (!
|
|
64347
|
+
const resolved = resolveProviderClientConfig(provider, env2);
|
|
64348
|
+
if (!resolved && provider !== "openrouter") {
|
|
64267
64349
|
return Response.json(
|
|
64268
|
-
{ error: `API key not configured for ${provider}. Set ${config.envKey}
|
|
64350
|
+
{ error: `API key not configured for ${provider}. Set ${config.envKey} or STANDARD_AGENTS_API_KEY.` },
|
|
64269
64351
|
{ status: 401 }
|
|
64270
64352
|
);
|
|
64271
64353
|
}
|
|
64272
64354
|
try {
|
|
64273
|
-
const factory = await config.
|
|
64274
|
-
const
|
|
64275
|
-
const providerInstance = factory(providerConfig);
|
|
64355
|
+
const factory = await config.importFactory();
|
|
64356
|
+
const providerInstance = factory(resolved?.providerConfig ?? { apiKey: "" });
|
|
64276
64357
|
if (!providerInstance.getModels && !providerInstance.getModelsPage) {
|
|
64277
64358
|
return Response.json({ models: [], hasNextPage: false });
|
|
64278
64359
|
}
|
|
@@ -64315,62 +64396,6 @@ var available_post_default = defineController2(async ({ req, env: env2 }) => {
|
|
|
64315
64396
|
});
|
|
64316
64397
|
|
|
64317
64398
|
// src/api/models/capabilities.post.ts
|
|
64318
|
-
var PROVIDER_CONFIGS2 = {
|
|
64319
|
-
cloudflare: {
|
|
64320
|
-
envKey: "CLOUDFLARE_API_TOKEN",
|
|
64321
|
-
getConfig: (env2, apiKey) => ({
|
|
64322
|
-
apiKey,
|
|
64323
|
-
accountId: env2.CLOUDFLARE_ACCOUNT_ID,
|
|
64324
|
-
baseUrl: env2.CLOUDFLARE_ACCOUNT_ID ? `https://api.cloudflare.com/client/v4/accounts/${env2.CLOUDFLARE_ACCOUNT_ID}/ai/v1` : void 0
|
|
64325
|
-
}),
|
|
64326
|
-
getFactory: async () => {
|
|
64327
|
-
const { cloudflare: cloudflare2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
64328
|
-
return cloudflare2;
|
|
64329
|
-
}
|
|
64330
|
-
},
|
|
64331
|
-
cerebras: {
|
|
64332
|
-
envKey: "CEREBRAS_API_KEY",
|
|
64333
|
-
getFactory: async () => {
|
|
64334
|
-
const { cerebras: cerebras2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
|
|
64335
|
-
return cerebras2;
|
|
64336
|
-
}
|
|
64337
|
-
},
|
|
64338
|
-
google: {
|
|
64339
|
-
envKey: "GOOGLE_API_KEY",
|
|
64340
|
-
getFactory: async () => {
|
|
64341
|
-
const { google: google2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports2));
|
|
64342
|
-
return google2;
|
|
64343
|
-
}
|
|
64344
|
-
},
|
|
64345
|
-
groq: {
|
|
64346
|
-
envKey: "GROQ_API_KEY",
|
|
64347
|
-
getFactory: async () => {
|
|
64348
|
-
const { groq: groq2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports3));
|
|
64349
|
-
return groq2;
|
|
64350
|
-
}
|
|
64351
|
-
},
|
|
64352
|
-
openai: {
|
|
64353
|
-
envKey: "OPENAI_API_KEY",
|
|
64354
|
-
getFactory: async () => {
|
|
64355
|
-
const { openai: openai2 } = await Promise.resolve().then(() => (init_dist4(), dist_exports4));
|
|
64356
|
-
return openai2;
|
|
64357
|
-
}
|
|
64358
|
-
},
|
|
64359
|
-
openrouter: {
|
|
64360
|
-
envKey: "OPENROUTER_API_KEY",
|
|
64361
|
-
getFactory: async () => {
|
|
64362
|
-
const { openrouter: openrouter2 } = await Promise.resolve().then(() => (init_dist5(), dist_exports5));
|
|
64363
|
-
return openrouter2;
|
|
64364
|
-
}
|
|
64365
|
-
},
|
|
64366
|
-
xai: {
|
|
64367
|
-
envKey: "XAI_API_KEY",
|
|
64368
|
-
getFactory: async () => {
|
|
64369
|
-
const { xai: xai3 } = await Promise.resolve().then(() => (init_dist10(), dist_exports6));
|
|
64370
|
-
return xai3;
|
|
64371
|
-
}
|
|
64372
|
-
}
|
|
64373
|
-
};
|
|
64374
64399
|
var capabilities_post_default = defineController2(async ({ req, env: env2 }) => {
|
|
64375
64400
|
const body = await req.json().catch(() => ({}));
|
|
64376
64401
|
const { provider, modelId } = body;
|
|
@@ -64380,24 +64405,23 @@ var capabilities_post_default = defineController2(async ({ req, env: env2 }) =>
|
|
|
64380
64405
|
if (!modelId) {
|
|
64381
64406
|
return Response.json({ error: "Model ID is required" }, { status: 400 });
|
|
64382
64407
|
}
|
|
64383
|
-
const config =
|
|
64408
|
+
const config = PROVIDER_CONFIGS[provider];
|
|
64384
64409
|
if (!config) {
|
|
64385
64410
|
return Response.json(
|
|
64386
|
-
{ error: `Unknown provider: ${provider}. Supported: ${Object.keys(
|
|
64411
|
+
{ error: `Unknown provider: ${provider}. Supported: ${Object.keys(PROVIDER_CONFIGS).join(", ")}` },
|
|
64387
64412
|
{ status: 400 }
|
|
64388
64413
|
);
|
|
64389
64414
|
}
|
|
64390
|
-
const
|
|
64391
|
-
if (!
|
|
64415
|
+
const resolved = resolveProviderClientConfig(provider, env2);
|
|
64416
|
+
if (!resolved && provider !== "openrouter") {
|
|
64392
64417
|
return Response.json(
|
|
64393
|
-
{ error: `API key not configured for ${provider}. Set ${config.envKey}
|
|
64418
|
+
{ error: `API key not configured for ${provider}. Set ${config.envKey} or STANDARD_AGENTS_API_KEY.` },
|
|
64394
64419
|
{ status: 401 }
|
|
64395
64420
|
);
|
|
64396
64421
|
}
|
|
64397
64422
|
try {
|
|
64398
|
-
const factory = await config.
|
|
64399
|
-
const
|
|
64400
|
-
const providerInstance = factory(providerConfig);
|
|
64423
|
+
const factory = await config.importFactory();
|
|
64424
|
+
const providerInstance = factory(resolved?.providerConfig ?? { apiKey: "" });
|
|
64401
64425
|
if (!providerInstance.getModelCapabilities) {
|
|
64402
64426
|
return Response.json({ capabilities: null });
|
|
64403
64427
|
}
|
|
@@ -65535,13 +65559,25 @@ var tenvs_get_default = defineController2(async ({ params, agents, prompts, tool
|
|
|
65535
65559
|
});
|
|
65536
65560
|
|
|
65537
65561
|
// src/api/models/[name]/curl-data.get.ts
|
|
65562
|
+
init_platform_routing();
|
|
65538
65563
|
var PROVIDER_ENDPOINTS = {
|
|
65539
65564
|
cloudflare: (env2) => env2.CLOUDFLARE_ACCOUNT_ID ? `https://api.cloudflare.com/client/v4/accounts/${env2.CLOUDFLARE_ACCOUNT_ID}/ai/v1/chat/completions` : "https://api.cloudflare.com/client/v4/accounts/{CLOUDFLARE_ACCOUNT_ID}/ai/v1/chat/completions",
|
|
65540
65565
|
cerebras: () => "https://api.cerebras.ai/v1/chat/completions",
|
|
65541
65566
|
openai: () => "https://api.openai.com/v1/responses",
|
|
65542
65567
|
openrouter: () => "https://openrouter.ai/api/v1/responses",
|
|
65543
65568
|
anthropic: () => "https://api.anthropic.com/v1/messages",
|
|
65544
|
-
google: () => "https://generativelanguage.googleapis.com/v1beta/models"
|
|
65569
|
+
google: () => "https://generativelanguage.googleapis.com/v1beta/models",
|
|
65570
|
+
groq: () => "https://api.groq.com/openai/v1/chat/completions",
|
|
65571
|
+
xai: () => "https://api.x.ai/v1/chat/completions"
|
|
65572
|
+
};
|
|
65573
|
+
var PLATFORM_ENDPOINT_PATHS = {
|
|
65574
|
+
cloudflare: "/chat/completions",
|
|
65575
|
+
cerebras: "/chat/completions",
|
|
65576
|
+
openai: "/responses",
|
|
65577
|
+
openrouter: "/responses",
|
|
65578
|
+
google: "/v1beta/models",
|
|
65579
|
+
groq: "/chat/completions",
|
|
65580
|
+
xai: "/chat/completions"
|
|
65545
65581
|
};
|
|
65546
65582
|
var API_KEY_ENV_VARS = {
|
|
65547
65583
|
cloudflare: ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"],
|
|
@@ -65549,7 +65585,9 @@ var API_KEY_ENV_VARS = {
|
|
|
65549
65585
|
openai: ["OPENAI_API_KEY"],
|
|
65550
65586
|
openrouter: ["OPENROUTER_API_KEY"],
|
|
65551
65587
|
anthropic: ["ANTHROPIC_API_KEY"],
|
|
65552
|
-
google: ["GOOGLE_API_KEY"]
|
|
65588
|
+
google: ["GOOGLE_API_KEY"],
|
|
65589
|
+
groq: ["GROQ_API_KEY"],
|
|
65590
|
+
xai: ["XAI_API_KEY"]
|
|
65553
65591
|
};
|
|
65554
65592
|
var curl_data_get_default = defineController2(async ({ params, models, env: env2 }) => {
|
|
65555
65593
|
const name15 = params.name ? decodeURIComponent(params.name) : void 0;
|
|
@@ -65569,21 +65607,30 @@ var curl_data_get_default = defineController2(async ({ params, models, env: env2
|
|
|
65569
65607
|
if (!providerName) {
|
|
65570
65608
|
return Response.json({ error: "Could not determine provider" }, { status: 500 });
|
|
65571
65609
|
}
|
|
65572
|
-
const
|
|
65610
|
+
const provider = providerName.toLowerCase();
|
|
65611
|
+
const envVarNames = API_KEY_ENV_VARS[provider] || [];
|
|
65573
65612
|
const apiKeyEnvName = envVarNames[0];
|
|
65574
65613
|
const apiKey = apiKeyEnvName ? env2[apiKeyEnvName] : null;
|
|
65575
|
-
if (
|
|
65614
|
+
if (apiKey) {
|
|
65615
|
+
const endpointResolver = PROVIDER_ENDPOINTS[provider];
|
|
65616
|
+
const endpoint = endpointResolver ? endpointResolver(env2) : `https://api.${provider}.com/v1/chat/completions`;
|
|
65617
|
+
return Response.json({
|
|
65618
|
+
endpoint,
|
|
65619
|
+
api_key: apiKey,
|
|
65620
|
+
sdk: provider
|
|
65621
|
+
});
|
|
65622
|
+
}
|
|
65623
|
+
const routing = resolvePlatformRouting(provider, env2);
|
|
65624
|
+
if (routing) {
|
|
65576
65625
|
return Response.json({
|
|
65577
|
-
|
|
65578
|
-
|
|
65626
|
+
endpoint: `${routing.baseUrl}${PLATFORM_ENDPOINT_PATHS[provider] ?? "/chat/completions"}`,
|
|
65627
|
+
api_key: routing.apiKey,
|
|
65628
|
+
sdk: provider
|
|
65629
|
+
});
|
|
65579
65630
|
}
|
|
65580
|
-
const endpointResolver = PROVIDER_ENDPOINTS[providerName.toLowerCase()];
|
|
65581
|
-
const endpoint = endpointResolver ? endpointResolver(env2) : `https://api.${providerName.toLowerCase()}.com/v1/chat/completions`;
|
|
65582
65631
|
return Response.json({
|
|
65583
|
-
|
|
65584
|
-
|
|
65585
|
-
sdk: providerName.toLowerCase()
|
|
65586
|
-
});
|
|
65632
|
+
error: `API key not found for provider: ${providerName}. Set ${apiKeyEnvName} or STANDARD_AGENTS_API_KEY in your environment.`
|
|
65633
|
+
}, { status: 500 });
|
|
65587
65634
|
} catch (error) {
|
|
65588
65635
|
console.error(`Error loading model ${name15}:`, error);
|
|
65589
65636
|
return Response.json(
|
|
@@ -65845,7 +65892,7 @@ var tenvs_get_default2 = defineController2(async ({ params, prompts, agents, too
|
|
|
65845
65892
|
});
|
|
65846
65893
|
|
|
65847
65894
|
// src/api/providers/[name]/icon.get.ts
|
|
65848
|
-
var
|
|
65895
|
+
var PROVIDER_CONFIGS2 = {
|
|
65849
65896
|
cloudflare: {
|
|
65850
65897
|
getFactory: async () => {
|
|
65851
65898
|
const { cloudflare: cloudflare2 } = await Promise.resolve().then(() => (init_src(), src_exports));
|
|
@@ -65910,7 +65957,7 @@ var icon_get_default = defineController2(async ({ params, url }) => {
|
|
|
65910
65957
|
if (!providerName) {
|
|
65911
65958
|
return Response.json({ error: "Provider name is required" }, { status: 400 });
|
|
65912
65959
|
}
|
|
65913
|
-
const config =
|
|
65960
|
+
const config = PROVIDER_CONFIGS2[providerName];
|
|
65914
65961
|
if (!config) {
|
|
65915
65962
|
return new Response(placeholderSvg(providerName), {
|
|
65916
65963
|
headers: { "Content-Type": "image/svg+xml", "Cache-Control": ICON_CACHE_CONTROL }
|