runpod-sdk 1.2.0-beta.1 → 2.0.0
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 +21 -0
- package/README.md +53 -200
- package/dist/index.cjs +247 -0
- package/dist/index.d.cts +127 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.js +208 -0
- package/package.json +55 -28
- package/dist/package.json +0 -24
- package/dist/src/graphql/client.d.ts +0 -22
- package/dist/src/graphql/client.js +0 -75
- package/dist/src/graphql/client.js.map +0 -1
- package/dist/src/graphql/generated/index.d.ts +0 -742
- package/dist/src/graphql/generated/index.js +0 -347
- package/dist/src/graphql/generated/index.js.map +0 -1
- package/dist/src/graphql/generated/operations.d.ts +0 -428
- package/dist/src/graphql/generated/operations.js +0 -2
- package/dist/src/graphql/generated/operations.js.map +0 -1
- package/dist/src/graphql/generated/sdk.d.ts +0 -31
- package/dist/src/graphql/generated/sdk.js +0 -232
- package/dist/src/graphql/generated/sdk.js.map +0 -1
- package/dist/src/graphql/generated/types.d.ts +0 -4281
- package/dist/src/graphql/generated/types.js +0 -2
- package/dist/src/graphql/generated/types.js.map +0 -1
- package/dist/src/index.d.ts +0 -170
- package/dist/src/index.js +0 -252
- package/dist/src/index.js.map +0 -1
- package/dist/src/pods/generated-gpu-types.d.ts +0 -299
- package/dist/src/pods/generated-gpu-types.js +0 -148
- package/dist/src/pods/generated-gpu-types.js.map +0 -1
- package/dist/src/pods/index.d.ts +0 -122
- package/dist/src/pods/index.js +0 -242
- package/dist/src/pods/index.js.map +0 -1
- package/schema.gql +0 -161
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { RunpodClient } from '@runpod/typescript-api-sdk';
|
|
2
|
+
export * from '@runpod/typescript-api-sdk';
|
|
3
|
+
|
|
4
|
+
declare const runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
|
|
5
|
+
declare const runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
|
|
6
|
+
type ExecutionPolicy = {
|
|
7
|
+
executionTimeout?: number;
|
|
8
|
+
lowPriority?: boolean;
|
|
9
|
+
ttl?: number;
|
|
10
|
+
};
|
|
11
|
+
type S3Config = {
|
|
12
|
+
accessId: string;
|
|
13
|
+
accessSecret: string;
|
|
14
|
+
bucketName: string;
|
|
15
|
+
endpointUrl: string;
|
|
16
|
+
objectPath?: string;
|
|
17
|
+
};
|
|
18
|
+
type EndpointInputPayload = {
|
|
19
|
+
input: any;
|
|
20
|
+
webhook?: string;
|
|
21
|
+
webhookV2?: string;
|
|
22
|
+
s3Config?: S3Config;
|
|
23
|
+
policy?: ExecutionPolicy;
|
|
24
|
+
};
|
|
25
|
+
type EndpointIncompleteOutput = {
|
|
26
|
+
delayTime?: number;
|
|
27
|
+
status: string;
|
|
28
|
+
id: string;
|
|
29
|
+
};
|
|
30
|
+
type EndpointCompletedOutput = {
|
|
31
|
+
status: string;
|
|
32
|
+
id: string;
|
|
33
|
+
output: any;
|
|
34
|
+
executionTime: number;
|
|
35
|
+
delayTime: number;
|
|
36
|
+
};
|
|
37
|
+
type EndpointOutput = EndpointCompletedOutput | EndpointIncompleteOutput;
|
|
38
|
+
type EndpointStreamOutput = {
|
|
39
|
+
status: string;
|
|
40
|
+
stream: any[];
|
|
41
|
+
};
|
|
42
|
+
type CancelOutput = {
|
|
43
|
+
status: string;
|
|
44
|
+
id: string;
|
|
45
|
+
executionTime: number;
|
|
46
|
+
delayTime: number;
|
|
47
|
+
};
|
|
48
|
+
type HealthCheck = {
|
|
49
|
+
jobs: {
|
|
50
|
+
completed: number;
|
|
51
|
+
failed: number;
|
|
52
|
+
inProgress: number;
|
|
53
|
+
inQueue: number;
|
|
54
|
+
retried: number;
|
|
55
|
+
};
|
|
56
|
+
workers: {
|
|
57
|
+
idle: number;
|
|
58
|
+
initializing: number;
|
|
59
|
+
ready: number;
|
|
60
|
+
running: number;
|
|
61
|
+
throttled: number;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
type PurgeQueueOutput = {
|
|
65
|
+
removed: number;
|
|
66
|
+
status: string;
|
|
67
|
+
};
|
|
68
|
+
/** Thrown when the Serverless job API answers with a non-2xx status. */
|
|
69
|
+
declare class RunpodServerlessError extends Error {
|
|
70
|
+
readonly status: number;
|
|
71
|
+
readonly statusText: string;
|
|
72
|
+
readonly body: string;
|
|
73
|
+
constructor(status: number, statusText: string, body: string, url: string);
|
|
74
|
+
}
|
|
75
|
+
/** POST /run: queue a job and return its id. */
|
|
76
|
+
declare function run(baseUrl: string, apiKey: string, endpointId: string, payload: EndpointInputPayload, timeout?: number): Promise<EndpointIncompleteOutput>;
|
|
77
|
+
/** GET /status/{requestId}. */
|
|
78
|
+
declare function status(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
79
|
+
/** GET /status-sync/{requestId}: wait on the server for up to `timeout` ms (1 to 90 s). */
|
|
80
|
+
declare function statusSync(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
81
|
+
/** POST /runsync, then poll /status-sync until the job ends or `timeout` ms pass. */
|
|
82
|
+
declare function runSync(baseUrl: string, apiKey: string, endpointId: string, payload: EndpointInputPayload, timeout?: number): Promise<EndpointCompletedOutput>;
|
|
83
|
+
/** Poll GET /stream/{requestId} and yield each streamed output until the job ends. */
|
|
84
|
+
declare function stream(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): AsyncGenerator<any>;
|
|
85
|
+
/** POST /cancel/{requestId}. */
|
|
86
|
+
declare function cancel(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): Promise<CancelOutput>;
|
|
87
|
+
/** GET /health: job and worker counts for the endpoint. */
|
|
88
|
+
declare function health(baseUrl: string, apiKey: string, endpointId: string, timeout?: number): Promise<HealthCheck>;
|
|
89
|
+
/** POST /purge-queue: remove every queued job. */
|
|
90
|
+
declare function purgeQueue(baseUrl: string, apiKey: string, endpointId: string, timeout?: number): Promise<PurgeQueueOutput>;
|
|
91
|
+
/** One Serverless endpoint, bound to an API key. */
|
|
92
|
+
declare class Endpoint {
|
|
93
|
+
endpointId: string;
|
|
94
|
+
baseUrl: string;
|
|
95
|
+
private apiKey;
|
|
96
|
+
constructor(baseUrl: string, apiKey: string, endpointId: string);
|
|
97
|
+
runSync(payload: EndpointInputPayload, timeout?: number): Promise<EndpointCompletedOutput>;
|
|
98
|
+
run(payload: EndpointInputPayload, timeout?: number): Promise<EndpointIncompleteOutput>;
|
|
99
|
+
status(requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
100
|
+
statusSync(requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
101
|
+
/** No timeout by default. */
|
|
102
|
+
stream(requestId: string, timeout?: number): AsyncGenerator<any, any, any>;
|
|
103
|
+
cancel(requestId: string, timeout?: number): Promise<CancelOutput>;
|
|
104
|
+
health(timeout?: number): Promise<HealthCheck>;
|
|
105
|
+
purgeQueue(timeout?: number): Promise<PurgeQueueOutput>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type SdkOptions = {
|
|
109
|
+
/** Serverless job API base URL. Defaults to https://api.runpod.ai/v2. */
|
|
110
|
+
baseUrl?: string;
|
|
111
|
+
/** REST v2 API base URL. Defaults to https://api.runpod.io. */
|
|
112
|
+
apiBaseUrl?: string;
|
|
113
|
+
};
|
|
114
|
+
declare class RunpodSdk {
|
|
115
|
+
baseUrl: string;
|
|
116
|
+
private apiKey;
|
|
117
|
+
private apiBaseUrl?;
|
|
118
|
+
private restClient?;
|
|
119
|
+
constructor(apiKey: string, options?: SdkOptions);
|
|
120
|
+
/** A Serverless endpoint client for job requests. */
|
|
121
|
+
endpoint(endpointId: string): Endpoint | null;
|
|
122
|
+
/** The typed REST v2 client, for pods, endpoints, templates, volumes, and more. */
|
|
123
|
+
get api(): RunpodClient;
|
|
124
|
+
}
|
|
125
|
+
declare function runpodSdk(apiKey: string, options?: SdkOptions): RunpodSdk;
|
|
126
|
+
|
|
127
|
+
export { type CancelOutput, Endpoint, type EndpointCompletedOutput, type EndpointIncompleteOutput, type EndpointInputPayload, type EndpointOutput, type EndpointStreamOutput, type ExecutionPolicy, type HealthCheck, type PurgeQueueOutput, RunpodSdk, RunpodServerlessError, type S3Config, type SdkOptions, cancel, runpodSdk as default, health, purgeQueue, run, runSync, runpodServerlessBaseUrlDev, runpodServerlessBaseUrlProd, status, statusSync, stream };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { createRunpodClient } from "@runpod/typescript-api-sdk";
|
|
3
|
+
|
|
4
|
+
// src/serverless.ts
|
|
5
|
+
var runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
|
|
6
|
+
var runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
|
|
7
|
+
var RunpodServerlessError = class extends Error {
|
|
8
|
+
status;
|
|
9
|
+
statusText;
|
|
10
|
+
body;
|
|
11
|
+
constructor(status2, statusText, body, url) {
|
|
12
|
+
super(`runpod: ${status2} ${statusText} from ${url}${body ? `: ${body}` : ""}`);
|
|
13
|
+
this.name = "RunpodServerlessError";
|
|
14
|
+
this.status = status2;
|
|
15
|
+
this.statusText = statusText;
|
|
16
|
+
this.body = body;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var TERMINAL_STATUSES = ["COMPLETED", "FAILED", "CANCELLED", "TIMED_OUT"];
|
|
20
|
+
var isCompleted = (status2) => TERMINAL_STATUSES.includes(status2);
|
|
21
|
+
var clamp = (min, max, value) => Math.min(max, Math.max(min, value));
|
|
22
|
+
var endpointUrl = (baseUrl, endpointId) => `${baseUrl}/${endpointId}`;
|
|
23
|
+
function getUserAgent() {
|
|
24
|
+
const version = true ? "2.0.0" : "dev";
|
|
25
|
+
const environment = typeof window !== "undefined" && window.navigator ? `Browser/${window.navigator.userAgent}` : "Unknown Environment";
|
|
26
|
+
return `RunPod-JS-SDK/${version} (${environment})`;
|
|
27
|
+
}
|
|
28
|
+
async function request(method, url, apiKey, body, timeout) {
|
|
29
|
+
const response = await fetch(url, {
|
|
30
|
+
method,
|
|
31
|
+
headers: {
|
|
32
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
"User-Agent": getUserAgent()
|
|
35
|
+
},
|
|
36
|
+
body: method === "POST" ? JSON.stringify(body ?? {}) : void 0,
|
|
37
|
+
signal: timeout > 0 ? AbortSignal.timeout(timeout) : void 0
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
const text = await response.text().catch(() => "");
|
|
41
|
+
throw new RunpodServerlessError(response.status, response.statusText, text, url);
|
|
42
|
+
}
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
async function readJson(response) {
|
|
46
|
+
if (response.status !== 200) {
|
|
47
|
+
return { status: response.status, statusText: response.statusText };
|
|
48
|
+
}
|
|
49
|
+
return response.json();
|
|
50
|
+
}
|
|
51
|
+
async function readStatus(response) {
|
|
52
|
+
if (response.status !== 200) {
|
|
53
|
+
return { status: response.status, statusText: response.statusText, started: false };
|
|
54
|
+
}
|
|
55
|
+
const data = await response.json();
|
|
56
|
+
return {
|
|
57
|
+
...data,
|
|
58
|
+
started: true,
|
|
59
|
+
completed: isCompleted(data.status),
|
|
60
|
+
succeeded: data.status === "COMPLETED"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function run(baseUrl, apiKey, endpointId, payload, timeout = 3e3) {
|
|
64
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/run`;
|
|
65
|
+
return readJson(await request("POST", url, apiKey, payload, timeout));
|
|
66
|
+
}
|
|
67
|
+
async function status(baseUrl, apiKey, endpointId, requestId, timeout = 3e3) {
|
|
68
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/status/${requestId}`;
|
|
69
|
+
return readStatus(await request("GET", url, apiKey, void 0, timeout));
|
|
70
|
+
}
|
|
71
|
+
async function statusSync(baseUrl, apiKey, endpointId, requestId, timeout = 9e4) {
|
|
72
|
+
const wait = clamp(1e3, 9e4, timeout);
|
|
73
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/status-sync/${requestId}?wait=${wait}`;
|
|
74
|
+
return readStatus(await request("GET", url, apiKey, void 0, 0));
|
|
75
|
+
}
|
|
76
|
+
async function runsyncOnce(baseUrl, apiKey, endpointId, payload, timeout) {
|
|
77
|
+
const wait = clamp(1e3, 9e4, timeout);
|
|
78
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/runsync?wait=${wait}`;
|
|
79
|
+
return readStatus(await request("POST", url, apiKey, payload, 0));
|
|
80
|
+
}
|
|
81
|
+
async function runSync(baseUrl, apiKey, endpointId, payload, timeout = 9e4) {
|
|
82
|
+
const startTime = Date.now();
|
|
83
|
+
const remaining = () => clamp(1e3, 9e4, timeout - (Date.now() - startTime));
|
|
84
|
+
let data = await runsyncOnce(baseUrl, apiKey, endpointId, payload, timeout);
|
|
85
|
+
const { id } = data;
|
|
86
|
+
const pollStart = Date.now();
|
|
87
|
+
while (!isCompleted(data.status)) {
|
|
88
|
+
if (Date.now() - pollStart > timeout) {
|
|
89
|
+
return { ...data, started: true, completed: false };
|
|
90
|
+
}
|
|
91
|
+
data = await statusSync(baseUrl, apiKey, endpointId, id, remaining());
|
|
92
|
+
}
|
|
93
|
+
return { ...data, started: true, completed: true, succeeded: data.status === "COMPLETED" };
|
|
94
|
+
}
|
|
95
|
+
async function* stream(baseUrl, apiKey, endpointId, requestId, timeout = 0) {
|
|
96
|
+
const start = Date.now();
|
|
97
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/stream/${requestId}`;
|
|
98
|
+
let completed = false;
|
|
99
|
+
while (!completed) {
|
|
100
|
+
const data = await readJson(await request("GET", url, apiKey, void 0, 0));
|
|
101
|
+
if (timeout !== 0 && Date.now() - start > timeout) {
|
|
102
|
+
completed = true;
|
|
103
|
+
}
|
|
104
|
+
if (isCompleted(data.status)) {
|
|
105
|
+
completed = true;
|
|
106
|
+
}
|
|
107
|
+
for (const output of data?.stream ?? []) {
|
|
108
|
+
yield output;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function cancel(baseUrl, apiKey, endpointId, requestId, timeout = 3e3) {
|
|
113
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/cancel/${requestId}`;
|
|
114
|
+
return readJson(await request("POST", url, apiKey, {}, timeout));
|
|
115
|
+
}
|
|
116
|
+
async function health(baseUrl, apiKey, endpointId, timeout = 3e3) {
|
|
117
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/health`;
|
|
118
|
+
return readJson(await request("GET", url, apiKey, void 0, timeout));
|
|
119
|
+
}
|
|
120
|
+
async function purgeQueue(baseUrl, apiKey, endpointId, timeout = 3e3) {
|
|
121
|
+
const url = `${endpointUrl(baseUrl, endpointId)}/purge-queue`;
|
|
122
|
+
return readJson(await request("POST", url, apiKey, {}, timeout));
|
|
123
|
+
}
|
|
124
|
+
var Endpoint = class {
|
|
125
|
+
endpointId;
|
|
126
|
+
baseUrl;
|
|
127
|
+
apiKey;
|
|
128
|
+
constructor(baseUrl, apiKey, endpointId) {
|
|
129
|
+
this.baseUrl = baseUrl;
|
|
130
|
+
this.apiKey = apiKey;
|
|
131
|
+
this.endpointId = endpointId;
|
|
132
|
+
}
|
|
133
|
+
runSync(payload, timeout = 9e4) {
|
|
134
|
+
return runSync(this.baseUrl, this.apiKey, this.endpointId, payload, timeout);
|
|
135
|
+
}
|
|
136
|
+
run(payload, timeout = 3e3) {
|
|
137
|
+
return run(this.baseUrl, this.apiKey, this.endpointId, payload, timeout);
|
|
138
|
+
}
|
|
139
|
+
status(requestId, timeout = 3e3) {
|
|
140
|
+
return status(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
|
|
141
|
+
}
|
|
142
|
+
statusSync(requestId, timeout = 9e4) {
|
|
143
|
+
return statusSync(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
|
|
144
|
+
}
|
|
145
|
+
/** No timeout by default. */
|
|
146
|
+
stream(requestId, timeout = 0) {
|
|
147
|
+
return stream(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
|
|
148
|
+
}
|
|
149
|
+
cancel(requestId, timeout = 3e3) {
|
|
150
|
+
return cancel(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
|
|
151
|
+
}
|
|
152
|
+
health(timeout = 3e3) {
|
|
153
|
+
return health(this.baseUrl, this.apiKey, this.endpointId, timeout);
|
|
154
|
+
}
|
|
155
|
+
purgeQueue(timeout = 3e3) {
|
|
156
|
+
return purgeQueue(this.baseUrl, this.apiKey, this.endpointId, timeout);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// src/index.ts
|
|
161
|
+
export * from "@runpod/typescript-api-sdk";
|
|
162
|
+
var RunpodSdk = class {
|
|
163
|
+
baseUrl = runpodServerlessBaseUrlProd;
|
|
164
|
+
apiKey = "";
|
|
165
|
+
apiBaseUrl;
|
|
166
|
+
restClient;
|
|
167
|
+
constructor(apiKey, options = {}) {
|
|
168
|
+
this.baseUrl = options.baseUrl ?? this.baseUrl;
|
|
169
|
+
this.apiBaseUrl = options.apiBaseUrl;
|
|
170
|
+
if (apiKey == null) {
|
|
171
|
+
console.log("Api key not supplied");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.apiKey = apiKey;
|
|
175
|
+
}
|
|
176
|
+
/** A Serverless endpoint client for job requests. */
|
|
177
|
+
endpoint(endpointId) {
|
|
178
|
+
if (endpointId == null) {
|
|
179
|
+
console.log("Endpoint id not supplied");
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
return new Endpoint(this.baseUrl, this.apiKey, endpointId);
|
|
183
|
+
}
|
|
184
|
+
/** The typed REST v2 client, for pods, endpoints, templates, volumes, and more. */
|
|
185
|
+
get api() {
|
|
186
|
+
this.restClient ??= createRunpodClient({ apiKey: this.apiKey || void 0, baseUrl: this.apiBaseUrl });
|
|
187
|
+
return this.restClient;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
function runpodSdk(apiKey, options = {}) {
|
|
191
|
+
return new RunpodSdk(apiKey, options);
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
Endpoint,
|
|
195
|
+
RunpodSdk,
|
|
196
|
+
RunpodServerlessError,
|
|
197
|
+
cancel,
|
|
198
|
+
runpodSdk as default,
|
|
199
|
+
health,
|
|
200
|
+
purgeQueue,
|
|
201
|
+
run,
|
|
202
|
+
runSync,
|
|
203
|
+
runpodServerlessBaseUrlDev,
|
|
204
|
+
runpodServerlessBaseUrlProd,
|
|
205
|
+
status,
|
|
206
|
+
statusSync,
|
|
207
|
+
stream
|
|
208
|
+
};
|
package/package.json
CHANGED
|
@@ -1,37 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runpod-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "JavaScript SDK for Runpod",
|
|
5
|
-
"
|
|
6
|
-
"types": "dist/src/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "JavaScript and TypeScript SDK for Runpod: the REST v2 API client and the Serverless job client",
|
|
5
|
+
"license": "MIT",
|
|
8
6
|
"author": "Runpod",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20"
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./dist/index.d.cts",
|
|
22
|
+
"default": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"keywords": [
|
|
31
|
+
"runpod",
|
|
32
|
+
"gpu",
|
|
33
|
+
"serverless",
|
|
34
|
+
"sdk",
|
|
35
|
+
"typescript"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/runpod/js-sdk.git",
|
|
40
|
+
"directory": "packages/runpod-sdk"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/runpod/js-sdk/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/runpod/js-sdk#readme",
|
|
9
46
|
"dependencies": {
|
|
10
|
-
"
|
|
11
|
-
"ramda": "^0.29.0",
|
|
12
|
-
"xior": "^0.1.4"
|
|
47
|
+
"@runpod/typescript-api-sdk": "^2.0.0"
|
|
13
48
|
},
|
|
14
49
|
"devDependencies": {
|
|
15
|
-
"@
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"@types/node": "^20.0.0",
|
|
23
|
-
"@types/ramda": "^0.29.7",
|
|
24
|
-
"dotenv": "^16.3.1",
|
|
25
|
-
"graphql": "^16.11.0",
|
|
26
|
-
"typescript": "^5.2.2"
|
|
50
|
+
"@types/node": "^24.0.0",
|
|
51
|
+
"tsup": "^8.5.1",
|
|
52
|
+
"typescript": "^5.9.0",
|
|
53
|
+
"vitest": "^4.1.10"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
27
57
|
},
|
|
28
58
|
"scripts": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"dev": "npm run codegen:watch & tsc --watch",
|
|
34
|
-
"test": "echo 'No tests yet'",
|
|
35
|
-
"prepublishOnly": "npm run build"
|
|
59
|
+
"build": "tsup",
|
|
60
|
+
"typecheck": "tsc --noEmit",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"check": "pnpm run typecheck && pnpm run test && pnpm run build"
|
|
36
63
|
}
|
|
37
|
-
}
|
|
64
|
+
}
|
package/dist/package.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "runpod-sdk",
|
|
3
|
-
"version": "1.1.2",
|
|
4
|
-
"description": "JavaScript SDK for Runpod",
|
|
5
|
-
"main": "dist/src/index.js",
|
|
6
|
-
"types": "dist/src/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"author": "Runpod",
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"ramda": "^0.29.0",
|
|
11
|
-
"xior": "^0.1.4"
|
|
12
|
-
},
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@types/node": "^20.0.0",
|
|
15
|
-
"@types/ramda": "^0.29.7",
|
|
16
|
-
"dotenv": "^16.3.1",
|
|
17
|
-
"typescript": "^5.2.2",
|
|
18
|
-
"vitest": "^1.0.0"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "tsc",
|
|
22
|
-
"test": "vitest run"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { GraphQLClient } from 'graphql-request';
|
|
2
|
-
import { Variables } from 'graphql-request';
|
|
3
|
-
export interface GraphQLConfig {
|
|
4
|
-
apiKey: string;
|
|
5
|
-
baseUrl?: string;
|
|
6
|
-
timeout?: number;
|
|
7
|
-
retries?: number;
|
|
8
|
-
}
|
|
9
|
-
export declare class RunPodGraphQLClient {
|
|
10
|
-
private client;
|
|
11
|
-
private config;
|
|
12
|
-
get graphqlClient(): GraphQLClient;
|
|
13
|
-
constructor(config: GraphQLConfig);
|
|
14
|
-
request<T = any, V extends Variables = Variables>(query: string, variables?: V, options?: {
|
|
15
|
-
retries?: number;
|
|
16
|
-
}): Promise<T>;
|
|
17
|
-
private isClientError;
|
|
18
|
-
private wrapError;
|
|
19
|
-
private sleep;
|
|
20
|
-
updateApiKey(apiKey: string): void;
|
|
21
|
-
setEndpoint(url: string): void;
|
|
22
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { GraphQLClient } from 'graphql-request';
|
|
2
|
-
export class RunPodGraphQLClient {
|
|
3
|
-
// Expose client for SDK usage
|
|
4
|
-
get graphqlClient() {
|
|
5
|
-
return this.client;
|
|
6
|
-
}
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.config = {
|
|
9
|
-
baseUrl: 'https://api.runpod.io/graphql',
|
|
10
|
-
timeout: 30000,
|
|
11
|
-
retries: 3,
|
|
12
|
-
...config
|
|
13
|
-
};
|
|
14
|
-
this.client = new GraphQLClient(this.config.baseUrl, {
|
|
15
|
-
headers: {
|
|
16
|
-
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
async request(query, variables, options) {
|
|
22
|
-
const maxRetries = options?.retries ?? this.config.retries;
|
|
23
|
-
let lastError;
|
|
24
|
-
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
25
|
-
try {
|
|
26
|
-
return await this.client.request(query, variables);
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
lastError = error;
|
|
30
|
-
// Don't retry on client errors (4xx)
|
|
31
|
-
if (this.isClientError(error)) {
|
|
32
|
-
throw this.wrapError(error);
|
|
33
|
-
}
|
|
34
|
-
// Exponential backoff for retries
|
|
35
|
-
if (attempt < maxRetries - 1) {
|
|
36
|
-
await this.sleep(Math.pow(2, attempt) * 1000);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
throw this.wrapError(lastError);
|
|
41
|
-
}
|
|
42
|
-
isClientError(error) {
|
|
43
|
-
return error?.response?.status >= 400 && error?.response?.status < 500;
|
|
44
|
-
}
|
|
45
|
-
wrapError(error) {
|
|
46
|
-
if (error?.response?.errors?.[0]) {
|
|
47
|
-
const gqlError = error.response.errors[0];
|
|
48
|
-
const wrappedError = new Error(gqlError.message);
|
|
49
|
-
wrappedError.name = 'GraphQLError';
|
|
50
|
-
Object.assign(wrappedError, {
|
|
51
|
-
code: gqlError.extensions?.code,
|
|
52
|
-
originalError: error
|
|
53
|
-
});
|
|
54
|
-
return wrappedError;
|
|
55
|
-
}
|
|
56
|
-
return error;
|
|
57
|
-
}
|
|
58
|
-
sleep(ms) {
|
|
59
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
60
|
-
}
|
|
61
|
-
updateApiKey(apiKey) {
|
|
62
|
-
this.config.apiKey = apiKey;
|
|
63
|
-
this.client.setHeader('Authorization', `Bearer ${apiKey}`);
|
|
64
|
-
}
|
|
65
|
-
setEndpoint(url) {
|
|
66
|
-
this.config.baseUrl = url;
|
|
67
|
-
this.client = new GraphQLClient(url, {
|
|
68
|
-
headers: {
|
|
69
|
-
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
70
|
-
'Content-Type': 'application/json',
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/graphql/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAU/C,MAAM,OAAO,mBAAmB;IAI9B,8BAA8B;IAC9B,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,+BAA+B;YACxC,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,CAAC;YACV,GAAG,MAAM;SACV,CAAA;QAED,IA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