computesdk 1.9.5 → 1.9.6

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/index.js CHANGED
@@ -22,10 +22,16 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  CommandExitError: () => import_client2.CommandExitError,
24
24
  GATEWAY_URL: () => GATEWAY_URL,
25
+ PROVIDER_AUTH: () => PROVIDER_AUTH,
26
+ PROVIDER_DASHBOARD_URLS: () => PROVIDER_DASHBOARD_URLS,
27
+ PROVIDER_ENV_MAP: () => PROVIDER_ENV_MAP,
25
28
  PROVIDER_ENV_VARS: () => PROVIDER_ENV_VARS,
29
+ PROVIDER_HEADERS: () => PROVIDER_HEADERS,
30
+ PROVIDER_NAMES: () => PROVIDER_NAMES,
26
31
  PROVIDER_PRIORITY: () => PROVIDER_PRIORITY,
27
32
  Sandbox: () => import_client.Sandbox,
28
33
  autoConfigureCompute: () => autoConfigureCompute,
34
+ buildProviderHeaders: () => buildProviderHeaders,
29
35
  calculateBackoff: () => calculateBackoff,
30
36
  compute: () => compute,
31
37
  createCompute: () => createCompute,
@@ -33,10 +39,14 @@ __export(index_exports, {
33
39
  createProviderFromConfig: () => createProviderFromConfig,
34
40
  detectProvider: () => detectProvider,
35
41
  gateway: () => gateway,
42
+ getMissingEnvVars: () => getMissingEnvVars,
43
+ getProviderConfigFromEnv: () => getProviderConfigFromEnv,
36
44
  getProviderHeaders: () => getProviderHeaders,
37
45
  handleComputeRequest: () => handleComputeRequest,
38
46
  isCommandExitError: () => import_client2.isCommandExitError,
39
- isGatewayModeEnabled: () => isGatewayModeEnabled
47
+ isGatewayModeEnabled: () => isGatewayModeEnabled,
48
+ isProviderAuthComplete: () => isProviderAuthComplete,
49
+ isValidProvider: () => isValidProvider
40
50
  });
41
51
  module.exports = __toCommonJS(index_exports);
42
52
 
@@ -44,6 +54,159 @@ module.exports = __toCommonJS(index_exports);
44
54
  var import_client = require("@computesdk/client");
45
55
  var import_client2 = require("@computesdk/client");
46
56
 
57
+ // src/provider-config.ts
58
+ var PROVIDER_AUTH = {
59
+ e2b: [["E2B_API_KEY"]],
60
+ modal: [["MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET"]],
61
+ railway: [["RAILWAY_API_KEY", "RAILWAY_PROJECT_ID", "RAILWAY_ENVIRONMENT_ID"]],
62
+ daytona: [["DAYTONA_API_KEY"]],
63
+ vercel: [
64
+ ["VERCEL_OIDC_TOKEN"],
65
+ ["VERCEL_TOKEN", "VERCEL_TEAM_ID", "VERCEL_PROJECT_ID"]
66
+ ],
67
+ runloop: [["RUNLOOP_API_KEY"]],
68
+ cloudflare: [["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]],
69
+ codesandbox: [["CSB_API_KEY"]],
70
+ blaxel: [["BL_API_KEY", "BL_WORKSPACE"]]
71
+ };
72
+ var PROVIDER_NAMES = Object.keys(PROVIDER_AUTH);
73
+ var PROVIDER_HEADERS = {
74
+ e2b: {
75
+ apiKey: "X-E2B-API-Key"
76
+ },
77
+ modal: {
78
+ tokenId: "X-Modal-Token-Id",
79
+ tokenSecret: "X-Modal-Token-Secret"
80
+ },
81
+ railway: {
82
+ apiToken: "X-Railway-API-Token"
83
+ },
84
+ daytona: {
85
+ apiKey: "X-Daytona-API-Key"
86
+ },
87
+ vercel: {
88
+ oidcToken: "X-Vercel-OIDC-Token",
89
+ token: "X-Vercel-Token",
90
+ teamId: "X-Vercel-Team-Id",
91
+ projectId: "X-Vercel-Project-Id"
92
+ },
93
+ runloop: {
94
+ apiKey: "X-Runloop-API-Key"
95
+ },
96
+ cloudflare: {
97
+ apiToken: "X-Cloudflare-API-Token",
98
+ accountId: "X-Cloudflare-Account-Id"
99
+ },
100
+ codesandbox: {
101
+ apiKey: "X-CSB-API-Key"
102
+ },
103
+ blaxel: {
104
+ apiKey: "X-BL-API-Key",
105
+ workspace: "X-BL-Workspace"
106
+ }
107
+ };
108
+ var PROVIDER_ENV_MAP = {
109
+ e2b: {
110
+ E2B_API_KEY: "apiKey"
111
+ },
112
+ modal: {
113
+ MODAL_TOKEN_ID: "tokenId",
114
+ MODAL_TOKEN_SECRET: "tokenSecret"
115
+ },
116
+ railway: {
117
+ RAILWAY_API_KEY: "apiToken",
118
+ RAILWAY_PROJECT_ID: "projectId",
119
+ RAILWAY_ENVIRONMENT_ID: "environmentId"
120
+ },
121
+ daytona: {
122
+ DAYTONA_API_KEY: "apiKey"
123
+ },
124
+ vercel: {
125
+ VERCEL_OIDC_TOKEN: "oidcToken",
126
+ VERCEL_TOKEN: "token",
127
+ VERCEL_TEAM_ID: "teamId",
128
+ VERCEL_PROJECT_ID: "projectId"
129
+ },
130
+ runloop: {
131
+ RUNLOOP_API_KEY: "apiKey"
132
+ },
133
+ cloudflare: {
134
+ CLOUDFLARE_API_TOKEN: "apiToken",
135
+ CLOUDFLARE_ACCOUNT_ID: "accountId"
136
+ },
137
+ codesandbox: {
138
+ CSB_API_KEY: "apiKey"
139
+ },
140
+ blaxel: {
141
+ BL_API_KEY: "apiKey",
142
+ BL_WORKSPACE: "workspace"
143
+ }
144
+ };
145
+ var PROVIDER_DASHBOARD_URLS = {
146
+ e2b: "https://e2b.dev/dashboard",
147
+ modal: "https://modal.com/settings",
148
+ railway: "https://railway.app/account/tokens",
149
+ daytona: "https://daytona.io/dashboard",
150
+ vercel: "https://vercel.com/account/tokens",
151
+ runloop: "https://runloop.ai/dashboard",
152
+ cloudflare: "https://dash.cloudflare.com/profile/api-tokens",
153
+ codesandbox: "https://codesandbox.io/dashboard/settings",
154
+ blaxel: "https://blaxel.ai/dashboard"
155
+ };
156
+ function isValidProvider(name) {
157
+ return name in PROVIDER_AUTH;
158
+ }
159
+ function buildProviderHeaders(provider, config) {
160
+ const headers = {};
161
+ const headerMap = PROVIDER_HEADERS[provider];
162
+ for (const [configKey, headerName] of Object.entries(headerMap)) {
163
+ const value = config[configKey];
164
+ if (value) {
165
+ headers[headerName] = value;
166
+ }
167
+ }
168
+ return headers;
169
+ }
170
+ function getProviderConfigFromEnv(provider) {
171
+ const config = {};
172
+ const envMap = PROVIDER_ENV_MAP[provider];
173
+ for (const [envVar, configKey] of Object.entries(envMap)) {
174
+ const value = process.env[envVar];
175
+ if (value) {
176
+ config[configKey] = value;
177
+ }
178
+ }
179
+ return config;
180
+ }
181
+ function isProviderAuthComplete(provider) {
182
+ const authOptions = PROVIDER_AUTH[provider];
183
+ for (const option of authOptions) {
184
+ const allPresent = option.every((envVar) => !!process.env[envVar]);
185
+ if (allPresent) return true;
186
+ }
187
+ return false;
188
+ }
189
+ function getMissingEnvVars(provider) {
190
+ const authOptions = PROVIDER_AUTH[provider];
191
+ let bestOption = null;
192
+ for (const option of authOptions) {
193
+ const missing = [];
194
+ let presentCount = 0;
195
+ for (const envVar of option) {
196
+ if (process.env[envVar]) {
197
+ presentCount++;
198
+ } else {
199
+ missing.push(envVar);
200
+ }
201
+ }
202
+ if (missing.length === 0) return [];
203
+ if (!bestOption || presentCount > bestOption.presentCount) {
204
+ bestOption = { presentCount, missing };
205
+ }
206
+ }
207
+ return bestOption?.missing ?? [];
208
+ }
209
+
47
210
  // src/constants.ts
48
211
  var GATEWAY_URL = "https://gateway.computesdk.com";
49
212
  var PROVIDER_PRIORITY = [
@@ -774,72 +937,63 @@ Check your COMPUTESDK_GATEWAY_URL environment variable.`
774
937
  }
775
938
 
776
939
  // src/explicit-config.ts
777
- function buildProviderHeaders(config) {
940
+ function buildProviderHeaders2(config) {
778
941
  const headers = {};
779
- switch (config.provider) {
780
- case "e2b":
781
- if (config.e2b?.apiKey) {
782
- headers["X-E2B-API-Key"] = config.e2b.apiKey;
783
- }
784
- break;
785
- case "modal":
786
- if (config.modal?.tokenId) {
787
- headers["X-Modal-Token-Id"] = config.modal.tokenId;
788
- }
789
- if (config.modal?.tokenSecret) {
790
- headers["X-Modal-Token-Secret"] = config.modal.tokenSecret;
791
- }
792
- break;
793
- case "railway":
794
- if (config.railway?.apiToken) {
795
- headers["X-Railway-API-Token"] = config.railway.apiToken;
796
- }
797
- break;
798
- default: {
799
- const exhaustiveCheck = config.provider;
800
- throw new Error(`Unknown provider: ${exhaustiveCheck}`);
942
+ const provider = config.provider;
943
+ const headerMap = PROVIDER_HEADERS[provider];
944
+ const providerConfig = config[provider];
945
+ if (!providerConfig || !headerMap) return headers;
946
+ for (const [configKey, headerName] of Object.entries(headerMap)) {
947
+ const value = providerConfig[configKey];
948
+ if (value) {
949
+ headers[headerName] = value;
801
950
  }
802
951
  }
803
952
  return headers;
804
953
  }
805
954
  function validateProviderConfig(config) {
806
- const providerName = config.provider;
807
- switch (providerName) {
808
- case "e2b":
809
- if (!config.e2b?.apiKey) {
810
- throw new Error(
811
- `Missing E2B configuration. When using provider: 'e2b', you must provide:
812
- e2b: { apiKey: 'your-e2b-api-key' }
813
-
814
- Get your API key at: https://e2b.dev/dashboard`
815
- );
816
- }
817
- break;
818
- case "modal":
819
- if (!config.modal?.tokenId || !config.modal?.tokenSecret) {
820
- throw new Error(
821
- `Missing Modal configuration. When using provider: 'modal', you must provide:
822
- modal: { tokenId: '...', tokenSecret: '...' }
823
-
824
- Get your tokens at: https://modal.com/settings`
825
- );
826
- }
827
- break;
828
- case "railway":
829
- if (!config.railway?.apiToken) {
830
- throw new Error(
831
- `Missing Railway configuration. When using provider: 'railway', you must provide:
832
- railway: { apiToken: 'your-railway-token' }
955
+ const provider = config.provider;
956
+ const authOptions = PROVIDER_AUTH[provider];
957
+ const providerConfig = config[provider];
958
+ const dashboardUrl = PROVIDER_DASHBOARD_URLS[provider];
959
+ if (!authOptions) {
960
+ throw new Error(`Unknown provider: ${provider}`);
961
+ }
962
+ for (const option of authOptions) {
963
+ const allPresent = option.every((envVar) => {
964
+ const configField = envVarToConfigField(provider, envVar);
965
+ return providerConfig?.[configField];
966
+ });
967
+ if (allPresent) return;
968
+ }
969
+ const configExample = buildConfigExample(provider, authOptions);
970
+ throw new Error(
971
+ `Missing ${provider} configuration. When using provider: '${provider}', you must provide:
972
+ ${configExample}
833
973
 
834
- Get your token at: https://railway.app/account/tokens`
835
- );
836
- }
837
- break;
838
- default: {
839
- const exhaustiveCheck = providerName;
840
- throw new Error(`Unknown provider: ${exhaustiveCheck}`);
841
- }
974
+ Get your credentials at: ${dashboardUrl}`
975
+ );
976
+ }
977
+ function envVarToConfigField(provider, envVar) {
978
+ return PROVIDER_ENV_MAP[provider]?.[envVar] ?? envVar.toLowerCase();
979
+ }
980
+ function buildConfigExample(provider, authOptions) {
981
+ if (authOptions.length === 1) {
982
+ const fields = authOptions[0].map((envVar) => {
983
+ const field = envVarToConfigField(provider, envVar);
984
+ return `${field}: '...'`;
985
+ });
986
+ return ` ${provider}: { ${fields.join(", ")} }`;
842
987
  }
988
+ const options = authOptions.map((option, i) => {
989
+ const fields = option.map((envVar) => {
990
+ const field = envVarToConfigField(provider, envVar);
991
+ return `${field}: '...'`;
992
+ });
993
+ return ` Option ${i + 1}:
994
+ ${provider}: { ${fields.join(", ")} }`;
995
+ });
996
+ return options.join("\n\n");
843
997
  }
844
998
  function createProviderFromConfig(config) {
845
999
  if (!config.apiKey) {
@@ -850,7 +1004,7 @@ Get your API key at: https://computesdk.com/dashboard`
850
1004
  );
851
1005
  }
852
1006
  validateProviderConfig(config);
853
- const providerHeaders = buildProviderHeaders(config);
1007
+ const providerHeaders = buildProviderHeaders2(config);
854
1008
  return gateway({
855
1009
  apiKey: config.apiKey,
856
1010
  provider: config.provider,
@@ -1241,10 +1395,16 @@ async function handleComputeRequest(paramsOrRequestOrBody, provider) {
1241
1395
  0 && (module.exports = {
1242
1396
  CommandExitError,
1243
1397
  GATEWAY_URL,
1398
+ PROVIDER_AUTH,
1399
+ PROVIDER_DASHBOARD_URLS,
1400
+ PROVIDER_ENV_MAP,
1244
1401
  PROVIDER_ENV_VARS,
1402
+ PROVIDER_HEADERS,
1403
+ PROVIDER_NAMES,
1245
1404
  PROVIDER_PRIORITY,
1246
1405
  Sandbox,
1247
1406
  autoConfigureCompute,
1407
+ buildProviderHeaders,
1248
1408
  calculateBackoff,
1249
1409
  compute,
1250
1410
  createCompute,
@@ -1252,9 +1412,13 @@ async function handleComputeRequest(paramsOrRequestOrBody, provider) {
1252
1412
  createProviderFromConfig,
1253
1413
  detectProvider,
1254
1414
  gateway,
1415
+ getMissingEnvVars,
1416
+ getProviderConfigFromEnv,
1255
1417
  getProviderHeaders,
1256
1418
  handleComputeRequest,
1257
1419
  isCommandExitError,
1258
- isGatewayModeEnabled
1420
+ isGatewayModeEnabled,
1421
+ isProviderAuthComplete,
1422
+ isValidProvider
1259
1423
  });
1260
1424
  //# sourceMappingURL=index.js.map