@blaxel/core 0.2.0-dev1

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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agents/index.d.ts +15 -0
  3. package/dist/agents/index.js +114 -0
  4. package/dist/authentication/apikey.d.ts +10 -0
  5. package/dist/authentication/apikey.js +24 -0
  6. package/dist/authentication/clientcredentials.d.ts +15 -0
  7. package/dist/authentication/clientcredentials.js +70 -0
  8. package/dist/authentication/credentials.d.ts +6 -0
  9. package/dist/authentication/credentials.js +17 -0
  10. package/dist/authentication/deviceMode.d.ts +15 -0
  11. package/dist/authentication/deviceMode.js +70 -0
  12. package/dist/authentication/index.d.ts +3 -0
  13. package/dist/authentication/index.js +63 -0
  14. package/dist/authentication/types.d.ts +9 -0
  15. package/dist/authentication/types.js +2 -0
  16. package/dist/cache/index.d.ts +1 -0
  17. package/dist/cache/index.js +26 -0
  18. package/dist/client/authentication.d.ts +25 -0
  19. package/dist/client/authentication.js +15 -0
  20. package/dist/client/client.d.ts +2 -0
  21. package/dist/client/client.gen.d.ts +12 -0
  22. package/dist/client/client.gen.js +8 -0
  23. package/dist/client/client.js +17 -0
  24. package/dist/client/index.d.ts +2 -0
  25. package/dist/client/index.js +19 -0
  26. package/dist/client/interceptors.d.ts +3 -0
  27. package/dist/client/interceptors.js +17 -0
  28. package/dist/client/sdk.gen.d.ts +410 -0
  29. package/dist/client/sdk.gen.js +1436 -0
  30. package/dist/client/types.gen.d.ts +3534 -0
  31. package/dist/client/types.gen.js +4 -0
  32. package/dist/common/autoload.d.ts +3 -0
  33. package/dist/common/autoload.js +27 -0
  34. package/dist/common/env.d.ts +5 -0
  35. package/dist/common/env.js +43 -0
  36. package/dist/common/errors.d.ts +1 -0
  37. package/dist/common/errors.js +17 -0
  38. package/dist/common/internal.d.ts +2 -0
  39. package/dist/common/internal.js +19 -0
  40. package/dist/common/logger.d.ts +1 -0
  41. package/dist/common/logger.js +4 -0
  42. package/dist/common/node.d.ts +3 -0
  43. package/dist/common/node.js +14 -0
  44. package/dist/common/settings.d.ts +26 -0
  45. package/dist/common/settings.js +84 -0
  46. package/dist/index.d.ts +14 -0
  47. package/dist/index.js +30 -0
  48. package/dist/mcp/client.d.ts +19 -0
  49. package/dist/mcp/client.js +151 -0
  50. package/dist/mcp/index.d.ts +2 -0
  51. package/dist/mcp/index.js +18 -0
  52. package/dist/mcp/server.d.ts +24 -0
  53. package/dist/mcp/server.js +213 -0
  54. package/dist/models/index.d.ts +8 -0
  55. package/dist/models/index.js +31 -0
  56. package/dist/sandbox/action.d.ts +18 -0
  57. package/dist/sandbox/action.js +74 -0
  58. package/dist/sandbox/client/client.gen.d.ts +12 -0
  59. package/dist/sandbox/client/client.gen.js +6 -0
  60. package/dist/sandbox/client/index.d.ts +2 -0
  61. package/dist/sandbox/client/index.js +19 -0
  62. package/dist/sandbox/client/sdk.gen.d.ts +83 -0
  63. package/dist/sandbox/client/sdk.gen.js +153 -0
  64. package/dist/sandbox/client/types.gen.d.ts +410 -0
  65. package/dist/sandbox/client/types.gen.js +4 -0
  66. package/dist/sandbox/filesystem.d.ts +18 -0
  67. package/dist/sandbox/filesystem.js +121 -0
  68. package/dist/sandbox/index.d.ts +1 -0
  69. package/dist/sandbox/index.js +17 -0
  70. package/dist/sandbox/network.d.ts +5 -0
  71. package/dist/sandbox/network.js +10 -0
  72. package/dist/sandbox/process.d.ts +12 -0
  73. package/dist/sandbox/process.js +61 -0
  74. package/dist/sandbox/sandbox.d.ts +23 -0
  75. package/dist/sandbox/sandbox.js +92 -0
  76. package/dist/telemetry/telemetry.d.ts +58 -0
  77. package/dist/telemetry/telemetry.js +59 -0
  78. package/dist/tools/index.d.ts +10 -0
  79. package/dist/tools/index.js +52 -0
  80. package/dist/tools/mcpTool.d.ts +21 -0
  81. package/dist/tools/mcpTool.js +193 -0
  82. package/dist/tools/types.d.ts +8 -0
  83. package/dist/tools/types.js +2 -0
  84. package/dist/tools/zodSchema.d.ts +9 -0
  85. package/dist/tools/zodSchema.js +46 -0
  86. package/package.json +76 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Beamlit, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,15 @@
1
+ import { Agent } from "../client/index.js";
2
+ declare class BlAgent {
3
+ agentName: string;
4
+ constructor(agentName: string);
5
+ get fallbackUrl(): import("url").URL | null;
6
+ get externalUrl(): import("url").URL;
7
+ get internalUrl(): import("url").URL;
8
+ get forcedUrl(): import("url").URL | null;
9
+ get url(): import("url").URL;
10
+ call(url: URL, input: Record<string, unknown> | string | undefined): Promise<Response>;
11
+ run(input: Record<string, unknown> | string | undefined): Promise<string>;
12
+ }
13
+ export declare const blAgent: (agentName: string) => BlAgent;
14
+ export declare const getAgentMetadata: (agent: string) => Promise<Agent | null>;
15
+ export {};
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAgentMetadata = exports.blAgent = void 0;
4
+ const index_js_1 = require("../cache/index.js");
5
+ const index_js_2 = require("../client/index.js");
6
+ const env_js_1 = require("../common/env.js");
7
+ const internal_js_1 = require("../common/internal.js");
8
+ const logger_js_1 = require("../common/logger.js");
9
+ const settings_js_1 = require("../common/settings.js");
10
+ const telemetry_js_1 = require("../telemetry/telemetry.js");
11
+ class BlAgent {
12
+ agentName;
13
+ constructor(agentName) {
14
+ this.agentName = agentName;
15
+ }
16
+ get fallbackUrl() {
17
+ if (this.externalUrl != this.url) {
18
+ return this.externalUrl;
19
+ }
20
+ return null;
21
+ }
22
+ get externalUrl() {
23
+ return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/agents/${this.agentName}`);
24
+ }
25
+ get internalUrl() {
26
+ const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, "agent", this.agentName);
27
+ return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
28
+ }
29
+ get forcedUrl() {
30
+ const envVar = this.agentName.replace(/-/g, "_").toUpperCase();
31
+ if (env_js_1.env[`BL_AGENT_${envVar}_URL`]) {
32
+ return new URL(env_js_1.env[`BL_AGENT_${envVar}_URL`]);
33
+ }
34
+ return null;
35
+ }
36
+ get url() {
37
+ if (this.forcedUrl)
38
+ return this.forcedUrl;
39
+ if (settings_js_1.settings.runInternalHostname)
40
+ return this.internalUrl;
41
+ return this.externalUrl;
42
+ }
43
+ async call(url, input) {
44
+ let body = input;
45
+ if (typeof body != "string") {
46
+ body = JSON.stringify(body);
47
+ }
48
+ const response = await fetch(url, {
49
+ method: "POST",
50
+ headers: {
51
+ ...settings_js_1.settings.headers,
52
+ "Content-Type": "application/json",
53
+ },
54
+ body,
55
+ });
56
+ return response;
57
+ }
58
+ async run(input) {
59
+ logger_js_1.logger.debug(`Agent Calling: ${this.agentName}`);
60
+ const span = (0, telemetry_js_1.startSpan)(this.agentName, {
61
+ attributes: {
62
+ "agent.name": this.agentName,
63
+ "agent.args": JSON.stringify(input),
64
+ "span.type": "agent.run",
65
+ },
66
+ isRoot: false,
67
+ });
68
+ try {
69
+ const response = await this.call(this.url, input);
70
+ span.setAttribute("agent.run.result", await response.text());
71
+ return await response.text();
72
+ }
73
+ catch (err) {
74
+ if (err instanceof Error) {
75
+ if (!this.fallbackUrl) {
76
+ span.setAttribute("agent.run.error", err.stack);
77
+ throw err;
78
+ }
79
+ try {
80
+ const response = await this.call(this.fallbackUrl, input);
81
+ span.setAttribute("agent.run.result", await response.text());
82
+ return await response.text();
83
+ }
84
+ catch (err) {
85
+ if (err instanceof Error) {
86
+ span.setAttribute("agent.run.error", err.stack);
87
+ }
88
+ throw err;
89
+ }
90
+ }
91
+ throw err;
92
+ }
93
+ finally {
94
+ span.end();
95
+ }
96
+ }
97
+ }
98
+ const blAgent = (agentName) => {
99
+ return new BlAgent(agentName);
100
+ };
101
+ exports.blAgent = blAgent;
102
+ const getAgentMetadata = async (agent) => {
103
+ const cacheData = await (0, index_js_1.findFromCache)("Agent", agent);
104
+ if (cacheData) {
105
+ return cacheData;
106
+ }
107
+ const { data } = await (0, index_js_2.getAgent)({
108
+ path: {
109
+ agentName: agent,
110
+ },
111
+ });
112
+ return data || null;
113
+ };
114
+ exports.getAgentMetadata = getAgentMetadata;
@@ -0,0 +1,10 @@
1
+ import { Credentials } from "./credentials.js";
2
+ import { CredentialsType } from "./types.js";
3
+ export declare class ApiKey extends Credentials {
4
+ private apiKey;
5
+ private credentials;
6
+ constructor(credentials: CredentialsType);
7
+ get workspace(): string;
8
+ get authorization(): string;
9
+ get token(): string;
10
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiKey = void 0;
4
+ const env_js_1 = require("../common/env.js");
5
+ const credentials_js_1 = require("./credentials.js");
6
+ class ApiKey extends credentials_js_1.Credentials {
7
+ apiKey;
8
+ credentials;
9
+ constructor(credentials) {
10
+ super();
11
+ this.apiKey = credentials.apiKey || "";
12
+ this.credentials = credentials;
13
+ }
14
+ get workspace() {
15
+ return this.credentials.workspace || env_js_1.env.BL_WORKSPACE || "";
16
+ }
17
+ get authorization() {
18
+ return `Bearer ${this.apiKey}`;
19
+ }
20
+ get token() {
21
+ return this.apiKey;
22
+ }
23
+ }
24
+ exports.ApiKey = ApiKey;
@@ -0,0 +1,15 @@
1
+ import { Credentials } from "./credentials.js";
2
+ import { CredentialsType } from "./types.js";
3
+ export declare class ClientCredentials extends Credentials {
4
+ private clientCredentials;
5
+ private accessToken;
6
+ private credentials;
7
+ private currentPromise;
8
+ constructor(credentials: CredentialsType);
9
+ get workspace(): string;
10
+ needRefresh(): boolean;
11
+ authenticate(): Promise<void>;
12
+ process(): Promise<void>;
13
+ get authorization(): string;
14
+ get token(): string;
15
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientCredentials = void 0;
4
+ const jwt_decode_1 = require("jwt-decode");
5
+ const authentication_js_1 = require("../client/authentication.js");
6
+ const env_js_1 = require("../common/env.js");
7
+ const credentials_js_1 = require("./credentials.js");
8
+ class ClientCredentials extends credentials_js_1.Credentials {
9
+ clientCredentials;
10
+ accessToken;
11
+ credentials;
12
+ currentPromise;
13
+ constructor(credentials) {
14
+ super();
15
+ this.clientCredentials = credentials.clientCredentials || "";
16
+ this.credentials = credentials;
17
+ this.accessToken = "";
18
+ this.currentPromise = null;
19
+ }
20
+ get workspace() {
21
+ return this.credentials.workspace || env_js_1.env.BL_WORKSPACE || "";
22
+ }
23
+ needRefresh() {
24
+ if (this.currentPromise)
25
+ return false;
26
+ if (this.accessToken) {
27
+ const decoded = (0, jwt_decode_1.jwtDecode)(this.accessToken);
28
+ const { exp, iat } = decoded;
29
+ if (!exp || !iat)
30
+ return true;
31
+ const expDate = new Date(exp * 1000);
32
+ const iatDate = new Date(iat * 1000);
33
+ const nowDate = new Date();
34
+ const diff = expDate.getTime() - nowDate.getTime();
35
+ const iatDiff = expDate.getTime() - iatDate.getTime();
36
+ const ratio = diff / iatDiff;
37
+ return ratio < 0.5;
38
+ }
39
+ return true;
40
+ }
41
+ async authenticate() {
42
+ if (!this.needRefresh()) {
43
+ return this.currentPromise || Promise.resolve();
44
+ }
45
+ this.currentPromise = this.process();
46
+ return this.currentPromise;
47
+ }
48
+ async process() {
49
+ const response = await (0, authentication_js_1.oauthToken)({
50
+ headers: {
51
+ Authorization: `Basic ${this.clientCredentials}`,
52
+ },
53
+ body: {
54
+ grant_type: "client_credentials",
55
+ },
56
+ });
57
+ if (response.error) {
58
+ throw new Error(response.error.error);
59
+ }
60
+ this.accessToken = response.data?.access_token || "";
61
+ this.currentPromise = null;
62
+ }
63
+ get authorization() {
64
+ return `Bearer ${this.accessToken}`;
65
+ }
66
+ get token() {
67
+ return this.accessToken;
68
+ }
69
+ }
70
+ exports.ClientCredentials = ClientCredentials;
@@ -0,0 +1,6 @@
1
+ export declare class Credentials {
2
+ authenticate(): Promise<void>;
3
+ get workspace(): string;
4
+ get authorization(): string;
5
+ get token(): string;
6
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Credentials = void 0;
4
+ const env_js_1 = require("../common/env.js");
5
+ class Credentials {
6
+ async authenticate() { }
7
+ get workspace() {
8
+ return env_js_1.env.BL_WORKSPACE || "";
9
+ }
10
+ get authorization() {
11
+ return "";
12
+ }
13
+ get token() {
14
+ return "";
15
+ }
16
+ }
17
+ exports.Credentials = Credentials;
@@ -0,0 +1,15 @@
1
+ import { CredentialsType } from "./types.js";
2
+ export declare class DeviceMode {
3
+ private refreshToken;
4
+ private deviceCode;
5
+ private accessToken;
6
+ private credentials;
7
+ private currentPromise;
8
+ constructor(credentials: CredentialsType);
9
+ get workspace(): string;
10
+ needRefresh(): boolean;
11
+ authenticate(): Promise<void>;
12
+ process(): Promise<void>;
13
+ get authorization(): string;
14
+ get token(): string;
15
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DeviceMode = void 0;
4
+ const jwt_decode_1 = require("jwt-decode");
5
+ const authentication_js_1 = require("../client/authentication.js");
6
+ const env_js_1 = require("../common/env.js");
7
+ class DeviceMode {
8
+ refreshToken;
9
+ deviceCode;
10
+ accessToken;
11
+ credentials;
12
+ currentPromise;
13
+ // private expireIn: number;
14
+ constructor(credentials) {
15
+ this.refreshToken = credentials.refresh_token || "";
16
+ this.deviceCode = credentials.device_code || "";
17
+ this.accessToken = credentials.access_token || "";
18
+ this.credentials = credentials;
19
+ this.currentPromise = null;
20
+ }
21
+ get workspace() {
22
+ return this.credentials.workspace || env_js_1.env.BL_WORKSPACE || "";
23
+ }
24
+ needRefresh() {
25
+ if (this.currentPromise)
26
+ return false;
27
+ if (this.accessToken) {
28
+ const decoded = (0, jwt_decode_1.jwtDecode)(this.accessToken);
29
+ const { exp, iat } = decoded;
30
+ if (!exp || !iat)
31
+ return true;
32
+ const expDate = new Date(exp * 1000);
33
+ const iatDate = new Date(iat * 1000);
34
+ const nowDate = new Date();
35
+ const diff = expDate.getTime() - nowDate.getTime();
36
+ const iatDiff = expDate.getTime() - iatDate.getTime();
37
+ const ratio = diff / iatDiff;
38
+ return ratio < 0.5;
39
+ }
40
+ return true;
41
+ }
42
+ async authenticate() {
43
+ if (!this.needRefresh()) {
44
+ return this.currentPromise || Promise.resolve();
45
+ }
46
+ this.currentPromise = this.process();
47
+ return this.currentPromise;
48
+ }
49
+ async process() {
50
+ const response = await (0, authentication_js_1.oauthToken)({
51
+ body: {
52
+ grant_type: "refresh_token",
53
+ device_code: this.deviceCode,
54
+ refresh_token: this.refreshToken,
55
+ },
56
+ });
57
+ if (response.error) {
58
+ throw new Error(response.error.error);
59
+ }
60
+ this.accessToken = response.data?.access_token || "";
61
+ this.currentPromise = null;
62
+ }
63
+ get authorization() {
64
+ return `Bearer ${this.accessToken}`;
65
+ }
66
+ get token() {
67
+ return this.accessToken;
68
+ }
69
+ }
70
+ exports.DeviceMode = DeviceMode;
@@ -0,0 +1,3 @@
1
+ import { Credentials } from "./credentials.js";
2
+ import { DeviceMode } from "./deviceMode.js";
3
+ export declare function authentication(): Credentials | DeviceMode;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.authentication = authentication;
7
+ const path_1 = require("path");
8
+ const yaml_1 = __importDefault(require("yaml"));
9
+ const env_js_1 = require("../common/env.js");
10
+ const node_js_1 = require("../common/node.js");
11
+ const apikey_js_1 = require("./apikey.js");
12
+ const clientcredentials_js_1 = require("./clientcredentials.js");
13
+ const credentials_js_1 = require("./credentials.js");
14
+ const deviceMode_js_1 = require("./deviceMode.js");
15
+ function getCredentials() {
16
+ if (env_js_1.env.BL_API_KEY) {
17
+ return {
18
+ apiKey: env_js_1.env.BL_API_KEY,
19
+ workspace: env_js_1.env.BL_WORKSPACE,
20
+ };
21
+ }
22
+ if (env_js_1.env.BL_CLIENT_CREDENTIALS) {
23
+ return {
24
+ clientCredentials: env_js_1.env.BL_CLIENT_CREDENTIALS,
25
+ workspace: env_js_1.env.BL_WORKSPACE,
26
+ };
27
+ }
28
+ if (node_js_1.os === null || node_js_1.fs === null) {
29
+ return null;
30
+ }
31
+ try {
32
+ const homeDir = node_js_1.os.homedir();
33
+ const config = node_js_1.fs.readFileSync((0, path_1.join)(homeDir, ".blaxel/config.yaml"), "utf8");
34
+ const configJson = yaml_1.default.parse(config);
35
+ const workspaceName = env_js_1.env.BL_WORKSPACE || configJson.context.workspace;
36
+ const credentials = configJson.workspaces.find((wk) => wk.name === workspaceName)?.credentials;
37
+ if (!credentials) {
38
+ return null;
39
+ }
40
+ credentials.workspace = workspaceName;
41
+ return credentials;
42
+ }
43
+ catch {
44
+ // If any error (e.g., running in browser), just return null
45
+ return null;
46
+ }
47
+ }
48
+ function authentication() {
49
+ const credentials = getCredentials();
50
+ if (!credentials) {
51
+ return new credentials_js_1.Credentials();
52
+ }
53
+ if (credentials.apiKey) {
54
+ return new apikey_js_1.ApiKey(credentials);
55
+ }
56
+ if (credentials.clientCredentials) {
57
+ return new clientcredentials_js_1.ClientCredentials(credentials);
58
+ }
59
+ if (credentials.device_code) {
60
+ return new deviceMode_js_1.DeviceMode(credentials);
61
+ }
62
+ return new credentials_js_1.Credentials();
63
+ }
@@ -0,0 +1,9 @@
1
+ export type CredentialsType = {
2
+ apiKey?: string;
3
+ clientCredentials?: string;
4
+ refresh_token?: string;
5
+ access_token?: string;
6
+ device_code?: string;
7
+ expires_in?: number;
8
+ workspace?: string;
9
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare function findFromCache(resource: string, name: string): Promise<unknown | null>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findFromCache = findFromCache;
7
+ const yaml_1 = __importDefault(require("yaml"));
8
+ const node_js_1 = require("../common/node.js");
9
+ const cache = new Map();
10
+ try {
11
+ if (node_js_1.fs) {
12
+ const cacheString = node_js_1.fs.readFileSync(".cache.yaml", "utf8");
13
+ const cacheData = yaml_1.default.parseAllDocuments(cacheString);
14
+ for (const doc of cacheData) {
15
+ const jsonDoc = doc.toJSON();
16
+ const cacheKey = `${jsonDoc.kind}/${jsonDoc.metadata.name}`;
17
+ cache.set(cacheKey, jsonDoc);
18
+ }
19
+ }
20
+ /* eslint-disable */
21
+ }
22
+ catch (error) { }
23
+ async function findFromCache(resource, name) {
24
+ const cacheKey = `${resource}/${name}`;
25
+ return cache.get(cacheKey);
26
+ }
@@ -0,0 +1,25 @@
1
+ import { OptionsLegacyParser } from "@hey-api/client-fetch";
2
+ type OauthTokenData = {
3
+ body: {
4
+ grant_type: 'client_credentials' | 'refresh_token' | 'device_code';
5
+ client_id?: string;
6
+ client_secret?: string;
7
+ device_code?: string;
8
+ refresh_token?: string;
9
+ };
10
+ authenticated?: boolean;
11
+ };
12
+ type OauthTokenResponse = {
13
+ access_token: string;
14
+ refresh_token: string;
15
+ expires_in: number;
16
+ token_type: string;
17
+ };
18
+ type OauthTokenError = {
19
+ error: string;
20
+ };
21
+ /**
22
+ * Get a new oauth token
23
+ */
24
+ export declare const oauthToken: <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<OauthTokenData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<OauthTokenResponse, OauthTokenError, ThrowOnError>;
25
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.oauthToken = void 0;
4
+ const client_gen_js_1 = require("./client.gen.js");
5
+ /**
6
+ * Get a new oauth token
7
+ */
8
+ const oauthToken = (options) => {
9
+ options.authenticated = false;
10
+ return client_gen_js_1.client.post({
11
+ ...options,
12
+ url: '/oauth/token',
13
+ });
14
+ };
15
+ exports.oauthToken = oauthToken;
@@ -0,0 +1,2 @@
1
+ export * from './index.js';
2
+ export { _Function as Function } from './types.gen.js';
@@ -0,0 +1,12 @@
1
+ import { type Config, type ClientOptions as DefaultClientOptions } from '@hey-api/client-fetch';
2
+ import type { ClientOptions } from './types.gen.js';
3
+ /**
4
+ * The `createClientConfig()` function will be called on client initialization
5
+ * and the returned object will become the client's initial configuration.
6
+ *
7
+ * You may want to initialize your client this way instead of calling
8
+ * `setConfig()`. This is useful for example if you're using Next.js
9
+ * to ensure your client always has the correct values.
10
+ */
11
+ export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
12
+ export declare const client: import("@hey-api/client-fetch").Client;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ // This file is auto-generated by @hey-api/openapi-ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.client = void 0;
5
+ const client_fetch_1 = require("@hey-api/client-fetch");
6
+ exports.client = (0, client_fetch_1.createClient)((0, client_fetch_1.createConfig)({
7
+ baseUrl: 'https://api.blaxel.ai/v0'
8
+ }));
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./index.js"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './types.gen.js';
2
+ export * from './sdk.gen.js';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // This file is auto-generated by @hey-api/openapi-ts
18
+ __exportStar(require("./types.gen.js"), exports);
19
+ __exportStar(require("./sdk.gen.js"), exports);
@@ -0,0 +1,3 @@
1
+ type Interceptor = (request: Request, options: Record<string, unknown>) => Promise<Request | Response>;
2
+ export declare const interceptors: Interceptor[];
3
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interceptors = void 0;
4
+ const settings_js_1 = require("../common/settings.js");
5
+ exports.interceptors = [
6
+ // Authentication interceptor
7
+ async (request, options) => {
8
+ if (options.authenticated === false) {
9
+ return request;
10
+ }
11
+ await settings_js_1.settings.authenticate();
12
+ for (const header in settings_js_1.settings.headers) {
13
+ request.headers.set(header, settings_js_1.settings.headers[header]);
14
+ }
15
+ return request;
16
+ },
17
+ ];