@singularity-layer/grid 0.1.0 → 0.2.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/dist/index.d.mts +111 -2
- package/dist/index.d.ts +111 -2
- package/dist/index.js +148 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.d.mts
CHANGED
|
@@ -98,8 +98,96 @@ interface ChatCompletionResponse {
|
|
|
98
98
|
total_tokens: number;
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
+
interface DeployProcessorOptions {
|
|
102
|
+
name: string;
|
|
103
|
+
code: string;
|
|
104
|
+
runtime?: "deno" | "wasm";
|
|
105
|
+
memory_mb?: number;
|
|
106
|
+
timeout_seconds?: number;
|
|
107
|
+
tee_type_required?: string;
|
|
108
|
+
metadata?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
interface ProcessorInfo {
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
owner_wallet: string;
|
|
114
|
+
owner_chain: string;
|
|
115
|
+
runtime: string;
|
|
116
|
+
memory_mb: number;
|
|
117
|
+
timeout_seconds: number;
|
|
118
|
+
tee_type_required?: string;
|
|
119
|
+
invocation_count: number;
|
|
120
|
+
last_invoked_at?: string;
|
|
121
|
+
status: string;
|
|
122
|
+
code_hash?: string;
|
|
123
|
+
deployment_stake_sgl: number;
|
|
124
|
+
invoke_url: string;
|
|
125
|
+
created_at: string;
|
|
126
|
+
updated_at?: string;
|
|
127
|
+
metadata?: Record<string, unknown>;
|
|
128
|
+
}
|
|
129
|
+
interface ProcessorDeployResult {
|
|
130
|
+
id: string;
|
|
131
|
+
name: string;
|
|
132
|
+
runtime: string;
|
|
133
|
+
memory_mb: number;
|
|
134
|
+
timeout_seconds: number;
|
|
135
|
+
status: string;
|
|
136
|
+
code_hash: string;
|
|
137
|
+
invoke_url: string;
|
|
138
|
+
tier: string;
|
|
139
|
+
sgl_staked: number;
|
|
140
|
+
created_at: string;
|
|
141
|
+
}
|
|
142
|
+
interface ProcessorInvokeResult {
|
|
143
|
+
job_id: string;
|
|
144
|
+
processor: string;
|
|
145
|
+
status: string;
|
|
146
|
+
output?: unknown;
|
|
147
|
+
duration_ms?: number;
|
|
148
|
+
payment?: {
|
|
149
|
+
amount_usd: string;
|
|
150
|
+
token: string;
|
|
151
|
+
discount_pct: number;
|
|
152
|
+
};
|
|
153
|
+
tee?: {
|
|
154
|
+
node_id: string;
|
|
155
|
+
tee_type: string;
|
|
156
|
+
attestation_verified: boolean;
|
|
157
|
+
};
|
|
158
|
+
message?: string;
|
|
159
|
+
}
|
|
160
|
+
interface ProcessorListResponse {
|
|
161
|
+
processors: ProcessorInfo[];
|
|
162
|
+
total: number;
|
|
163
|
+
page: number;
|
|
164
|
+
limit: number;
|
|
165
|
+
}
|
|
166
|
+
interface ProcessorLogEntry {
|
|
167
|
+
id: string;
|
|
168
|
+
processor_id: string;
|
|
169
|
+
job_id: string;
|
|
170
|
+
node_id: string;
|
|
171
|
+
duration_ms?: number;
|
|
172
|
+
status: string;
|
|
173
|
+
error_message?: string;
|
|
174
|
+
created_at: string;
|
|
175
|
+
}
|
|
176
|
+
interface ProcessorLogsResponse {
|
|
177
|
+
logs: ProcessorLogEntry[];
|
|
178
|
+
total: number;
|
|
179
|
+
page: number;
|
|
180
|
+
limit: number;
|
|
181
|
+
}
|
|
182
|
+
interface WalletAuth {
|
|
183
|
+
address: string;
|
|
184
|
+
chain?: string;
|
|
185
|
+
signature: string;
|
|
186
|
+
timestamp: string;
|
|
187
|
+
nonce: string;
|
|
188
|
+
}
|
|
101
189
|
|
|
102
|
-
declare const DEFAULT_BASE_URL = "https://
|
|
190
|
+
declare const DEFAULT_BASE_URL = "https://grid.x402compute.cc";
|
|
103
191
|
declare class GridClient {
|
|
104
192
|
private readonly baseUrl;
|
|
105
193
|
private readonly headers;
|
|
@@ -116,6 +204,27 @@ declare class GridClient {
|
|
|
116
204
|
getJob(jobId: string): Promise<JobResult>;
|
|
117
205
|
getAttestation(jobId: string): Promise<AttestationProof>;
|
|
118
206
|
chatCompletions(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
207
|
+
private requestWithWalletAuth;
|
|
208
|
+
private requestWithPayment;
|
|
209
|
+
deployProcessor(wallet: WalletAuth, options: DeployProcessorOptions): Promise<ProcessorDeployResult>;
|
|
210
|
+
invokeProcessor(processorName: string, input: Record<string, unknown>, options?: {
|
|
211
|
+
paymentHeader?: string;
|
|
212
|
+
paymentToken?: "USDC" | "SGL";
|
|
213
|
+
}): Promise<ProcessorInvokeResult>;
|
|
214
|
+
listProcessors(options?: {
|
|
215
|
+
owner?: string;
|
|
216
|
+
page?: number;
|
|
217
|
+
limit?: number;
|
|
218
|
+
}): Promise<ProcessorListResponse>;
|
|
219
|
+
getProcessor(processorId: string): Promise<ProcessorInfo>;
|
|
220
|
+
deleteProcessor(processorId: string, wallet: WalletAuth): Promise<{
|
|
221
|
+
deleted: boolean;
|
|
222
|
+
id: string;
|
|
223
|
+
}>;
|
|
224
|
+
getProcessorLogs(processorId: string, wallet: WalletAuth, options?: {
|
|
225
|
+
page?: number;
|
|
226
|
+
limit?: number;
|
|
227
|
+
}): Promise<ProcessorLogsResponse>;
|
|
119
228
|
}
|
|
120
229
|
|
|
121
230
|
declare class SGLError extends Error {
|
|
@@ -136,4 +245,4 @@ declare class SGLConnectionError extends SGLError {
|
|
|
136
245
|
constructor(message: string);
|
|
137
246
|
}
|
|
138
247
|
|
|
139
|
-
export { type AttestationProof, type CapacityResponse, type ChatChoice, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, DEFAULT_BASE_URL, GridClient, type GridClientOptions, type JobResponse, type JobResult, type JobSubmission, type ModelInfo, type ModelPricing, type PricingInfo, SGLAPIError, SGLAuthError, SGLConnectionError, SGLError, SGLNotFoundError, type TeeCapacity };
|
|
248
|
+
export { type AttestationProof, type CapacityResponse, type ChatChoice, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, DEFAULT_BASE_URL, type DeployProcessorOptions, GridClient, type GridClientOptions, type JobResponse, type JobResult, type JobSubmission, type ModelInfo, type ModelPricing, type PricingInfo, type ProcessorDeployResult, type ProcessorInfo, type ProcessorInvokeResult, type ProcessorListResponse, type ProcessorLogEntry, type ProcessorLogsResponse, SGLAPIError, SGLAuthError, SGLConnectionError, SGLError, SGLNotFoundError, type TeeCapacity, type WalletAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -98,8 +98,96 @@ interface ChatCompletionResponse {
|
|
|
98
98
|
total_tokens: number;
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
+
interface DeployProcessorOptions {
|
|
102
|
+
name: string;
|
|
103
|
+
code: string;
|
|
104
|
+
runtime?: "deno" | "wasm";
|
|
105
|
+
memory_mb?: number;
|
|
106
|
+
timeout_seconds?: number;
|
|
107
|
+
tee_type_required?: string;
|
|
108
|
+
metadata?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
interface ProcessorInfo {
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
owner_wallet: string;
|
|
114
|
+
owner_chain: string;
|
|
115
|
+
runtime: string;
|
|
116
|
+
memory_mb: number;
|
|
117
|
+
timeout_seconds: number;
|
|
118
|
+
tee_type_required?: string;
|
|
119
|
+
invocation_count: number;
|
|
120
|
+
last_invoked_at?: string;
|
|
121
|
+
status: string;
|
|
122
|
+
code_hash?: string;
|
|
123
|
+
deployment_stake_sgl: number;
|
|
124
|
+
invoke_url: string;
|
|
125
|
+
created_at: string;
|
|
126
|
+
updated_at?: string;
|
|
127
|
+
metadata?: Record<string, unknown>;
|
|
128
|
+
}
|
|
129
|
+
interface ProcessorDeployResult {
|
|
130
|
+
id: string;
|
|
131
|
+
name: string;
|
|
132
|
+
runtime: string;
|
|
133
|
+
memory_mb: number;
|
|
134
|
+
timeout_seconds: number;
|
|
135
|
+
status: string;
|
|
136
|
+
code_hash: string;
|
|
137
|
+
invoke_url: string;
|
|
138
|
+
tier: string;
|
|
139
|
+
sgl_staked: number;
|
|
140
|
+
created_at: string;
|
|
141
|
+
}
|
|
142
|
+
interface ProcessorInvokeResult {
|
|
143
|
+
job_id: string;
|
|
144
|
+
processor: string;
|
|
145
|
+
status: string;
|
|
146
|
+
output?: unknown;
|
|
147
|
+
duration_ms?: number;
|
|
148
|
+
payment?: {
|
|
149
|
+
amount_usd: string;
|
|
150
|
+
token: string;
|
|
151
|
+
discount_pct: number;
|
|
152
|
+
};
|
|
153
|
+
tee?: {
|
|
154
|
+
node_id: string;
|
|
155
|
+
tee_type: string;
|
|
156
|
+
attestation_verified: boolean;
|
|
157
|
+
};
|
|
158
|
+
message?: string;
|
|
159
|
+
}
|
|
160
|
+
interface ProcessorListResponse {
|
|
161
|
+
processors: ProcessorInfo[];
|
|
162
|
+
total: number;
|
|
163
|
+
page: number;
|
|
164
|
+
limit: number;
|
|
165
|
+
}
|
|
166
|
+
interface ProcessorLogEntry {
|
|
167
|
+
id: string;
|
|
168
|
+
processor_id: string;
|
|
169
|
+
job_id: string;
|
|
170
|
+
node_id: string;
|
|
171
|
+
duration_ms?: number;
|
|
172
|
+
status: string;
|
|
173
|
+
error_message?: string;
|
|
174
|
+
created_at: string;
|
|
175
|
+
}
|
|
176
|
+
interface ProcessorLogsResponse {
|
|
177
|
+
logs: ProcessorLogEntry[];
|
|
178
|
+
total: number;
|
|
179
|
+
page: number;
|
|
180
|
+
limit: number;
|
|
181
|
+
}
|
|
182
|
+
interface WalletAuth {
|
|
183
|
+
address: string;
|
|
184
|
+
chain?: string;
|
|
185
|
+
signature: string;
|
|
186
|
+
timestamp: string;
|
|
187
|
+
nonce: string;
|
|
188
|
+
}
|
|
101
189
|
|
|
102
|
-
declare const DEFAULT_BASE_URL = "https://
|
|
190
|
+
declare const DEFAULT_BASE_URL = "https://grid.x402compute.cc";
|
|
103
191
|
declare class GridClient {
|
|
104
192
|
private readonly baseUrl;
|
|
105
193
|
private readonly headers;
|
|
@@ -116,6 +204,27 @@ declare class GridClient {
|
|
|
116
204
|
getJob(jobId: string): Promise<JobResult>;
|
|
117
205
|
getAttestation(jobId: string): Promise<AttestationProof>;
|
|
118
206
|
chatCompletions(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
207
|
+
private requestWithWalletAuth;
|
|
208
|
+
private requestWithPayment;
|
|
209
|
+
deployProcessor(wallet: WalletAuth, options: DeployProcessorOptions): Promise<ProcessorDeployResult>;
|
|
210
|
+
invokeProcessor(processorName: string, input: Record<string, unknown>, options?: {
|
|
211
|
+
paymentHeader?: string;
|
|
212
|
+
paymentToken?: "USDC" | "SGL";
|
|
213
|
+
}): Promise<ProcessorInvokeResult>;
|
|
214
|
+
listProcessors(options?: {
|
|
215
|
+
owner?: string;
|
|
216
|
+
page?: number;
|
|
217
|
+
limit?: number;
|
|
218
|
+
}): Promise<ProcessorListResponse>;
|
|
219
|
+
getProcessor(processorId: string): Promise<ProcessorInfo>;
|
|
220
|
+
deleteProcessor(processorId: string, wallet: WalletAuth): Promise<{
|
|
221
|
+
deleted: boolean;
|
|
222
|
+
id: string;
|
|
223
|
+
}>;
|
|
224
|
+
getProcessorLogs(processorId: string, wallet: WalletAuth, options?: {
|
|
225
|
+
page?: number;
|
|
226
|
+
limit?: number;
|
|
227
|
+
}): Promise<ProcessorLogsResponse>;
|
|
119
228
|
}
|
|
120
229
|
|
|
121
230
|
declare class SGLError extends Error {
|
|
@@ -136,4 +245,4 @@ declare class SGLConnectionError extends SGLError {
|
|
|
136
245
|
constructor(message: string);
|
|
137
246
|
}
|
|
138
247
|
|
|
139
|
-
export { type AttestationProof, type CapacityResponse, type ChatChoice, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, DEFAULT_BASE_URL, GridClient, type GridClientOptions, type JobResponse, type JobResult, type JobSubmission, type ModelInfo, type ModelPricing, type PricingInfo, SGLAPIError, SGLAuthError, SGLConnectionError, SGLError, SGLNotFoundError, type TeeCapacity };
|
|
248
|
+
export { type AttestationProof, type CapacityResponse, type ChatChoice, type ChatCompletionRequest, type ChatCompletionResponse, type ChatMessage, DEFAULT_BASE_URL, type DeployProcessorOptions, GridClient, type GridClientOptions, type JobResponse, type JobResult, type JobSubmission, type ModelInfo, type ModelPricing, type PricingInfo, type ProcessorDeployResult, type ProcessorInfo, type ProcessorInvokeResult, type ProcessorListResponse, type ProcessorLogEntry, type ProcessorLogsResponse, SGLAPIError, SGLAuthError, SGLConnectionError, SGLError, SGLNotFoundError, type TeeCapacity, type WalletAuth };
|
package/dist/index.js
CHANGED
|
@@ -65,7 +65,7 @@ var SGLConnectionError = class extends SGLError {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
// src/client.ts
|
|
68
|
-
var DEFAULT_BASE_URL = "https://
|
|
68
|
+
var DEFAULT_BASE_URL = "https://grid.x402compute.cc";
|
|
69
69
|
var DEFAULT_TIMEOUT = 6e4;
|
|
70
70
|
var GridClient = class {
|
|
71
71
|
constructor(options = {}) {
|
|
@@ -153,6 +153,153 @@ var GridClient = class {
|
|
|
153
153
|
request
|
|
154
154
|
);
|
|
155
155
|
}
|
|
156
|
+
// -- Processor helpers ----------------------------------------------------
|
|
157
|
+
async requestWithWalletAuth(method, path, wallet, body) {
|
|
158
|
+
const url = `${this.baseUrl}${path}`;
|
|
159
|
+
const controller = new AbortController();
|
|
160
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
161
|
+
const reqHeaders = {
|
|
162
|
+
...this.headers,
|
|
163
|
+
"X-Auth-Address": wallet.address,
|
|
164
|
+
"X-Auth-Chain": wallet.chain ?? "solana",
|
|
165
|
+
"X-Auth-Signature": wallet.signature,
|
|
166
|
+
"X-Auth-Timestamp": wallet.timestamp,
|
|
167
|
+
"X-Auth-Nonce": wallet.nonce
|
|
168
|
+
};
|
|
169
|
+
let response;
|
|
170
|
+
try {
|
|
171
|
+
response = await fetch(url, {
|
|
172
|
+
method,
|
|
173
|
+
headers: reqHeaders,
|
|
174
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
175
|
+
signal: controller.signal
|
|
176
|
+
});
|
|
177
|
+
} catch (err) {
|
|
178
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
179
|
+
throw new SGLConnectionError(`Request to ${url} timed out`);
|
|
180
|
+
}
|
|
181
|
+
throw new SGLConnectionError(
|
|
182
|
+
`Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`
|
|
183
|
+
);
|
|
184
|
+
} finally {
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
}
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
let errorBody;
|
|
189
|
+
let message = response.statusText;
|
|
190
|
+
try {
|
|
191
|
+
errorBody = await response.json();
|
|
192
|
+
const err = errorBody?.error;
|
|
193
|
+
if (typeof err === "string") message = err;
|
|
194
|
+
else if (err && typeof err === "object" && "message" in err)
|
|
195
|
+
message = String(err.message);
|
|
196
|
+
} catch {
|
|
197
|
+
}
|
|
198
|
+
if (response.status === 401 || response.status === 403) {
|
|
199
|
+
throw new SGLAuthError(response.status, message, errorBody);
|
|
200
|
+
}
|
|
201
|
+
if (response.status === 404) {
|
|
202
|
+
throw new SGLNotFoundError(message, errorBody);
|
|
203
|
+
}
|
|
204
|
+
throw new SGLAPIError(response.status, message, errorBody);
|
|
205
|
+
}
|
|
206
|
+
if (response.status === 204) return {};
|
|
207
|
+
return await response.json();
|
|
208
|
+
}
|
|
209
|
+
async requestWithPayment(method, path, body, paymentHeader) {
|
|
210
|
+
const url = `${this.baseUrl}${path}`;
|
|
211
|
+
const controller = new AbortController();
|
|
212
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
213
|
+
const reqHeaders = { ...this.headers };
|
|
214
|
+
if (paymentHeader) {
|
|
215
|
+
reqHeaders["X-Payment"] = paymentHeader;
|
|
216
|
+
}
|
|
217
|
+
let response;
|
|
218
|
+
try {
|
|
219
|
+
response = await fetch(url, {
|
|
220
|
+
method,
|
|
221
|
+
headers: reqHeaders,
|
|
222
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
223
|
+
signal: controller.signal
|
|
224
|
+
});
|
|
225
|
+
} catch (err) {
|
|
226
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
227
|
+
throw new SGLConnectionError(`Request to ${url} timed out`);
|
|
228
|
+
}
|
|
229
|
+
throw new SGLConnectionError(
|
|
230
|
+
`Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`
|
|
231
|
+
);
|
|
232
|
+
} finally {
|
|
233
|
+
clearTimeout(timer);
|
|
234
|
+
}
|
|
235
|
+
if (response.status === 402) {
|
|
236
|
+
const requirements = await response.json();
|
|
237
|
+
throw new SGLAPIError(402, "Payment required", requirements);
|
|
238
|
+
}
|
|
239
|
+
if (!response.ok) {
|
|
240
|
+
let errorBody;
|
|
241
|
+
let message = response.statusText;
|
|
242
|
+
try {
|
|
243
|
+
errorBody = await response.json();
|
|
244
|
+
const err = errorBody?.error;
|
|
245
|
+
if (typeof err === "string") message = err;
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
throw new SGLAPIError(response.status, message, errorBody);
|
|
249
|
+
}
|
|
250
|
+
return await response.json();
|
|
251
|
+
}
|
|
252
|
+
// -- Processors -----------------------------------------------------------
|
|
253
|
+
async deployProcessor(wallet, options) {
|
|
254
|
+
return this.requestWithWalletAuth(
|
|
255
|
+
"POST",
|
|
256
|
+
"/grid/processors",
|
|
257
|
+
wallet,
|
|
258
|
+
options
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
async invokeProcessor(processorName, input, options) {
|
|
262
|
+
const body = { input };
|
|
263
|
+
if (options?.paymentToken) body.payment_token = options.paymentToken;
|
|
264
|
+
return this.requestWithPayment(
|
|
265
|
+
"POST",
|
|
266
|
+
`/grid/processors/${encodeURIComponent(processorName)}/invoke`,
|
|
267
|
+
body,
|
|
268
|
+
options?.paymentHeader
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
async listProcessors(options) {
|
|
272
|
+
const params = new URLSearchParams();
|
|
273
|
+
if (options?.owner) params.set("owner", options.owner);
|
|
274
|
+
if (options?.page != null) params.set("page", String(options.page));
|
|
275
|
+
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
276
|
+
const qs = params.toString();
|
|
277
|
+
return this.request(
|
|
278
|
+
"GET",
|
|
279
|
+
`/grid/processors${qs ? `?${qs}` : ""}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
async getProcessor(processorId) {
|
|
283
|
+
return this.request("GET", `/grid/processors/${processorId}`);
|
|
284
|
+
}
|
|
285
|
+
async deleteProcessor(processorId, wallet) {
|
|
286
|
+
return this.requestWithWalletAuth(
|
|
287
|
+
"DELETE",
|
|
288
|
+
`/grid/processors/${processorId}`,
|
|
289
|
+
wallet
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
async getProcessorLogs(processorId, wallet, options) {
|
|
293
|
+
const params = new URLSearchParams();
|
|
294
|
+
if (options?.page != null) params.set("page", String(options.page));
|
|
295
|
+
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
296
|
+
const qs = params.toString();
|
|
297
|
+
return this.requestWithWalletAuth(
|
|
298
|
+
"GET",
|
|
299
|
+
`/grid/processors/${processorId}/logs${qs ? `?${qs}` : ""}`,
|
|
300
|
+
wallet
|
|
301
|
+
);
|
|
302
|
+
}
|
|
156
303
|
};
|
|
157
304
|
// Annotate the CommonJS export names for ESM import in node:
|
|
158
305
|
0 && (module.exports = {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { GridClient, DEFAULT_BASE_URL } from \"./client.js\";\nexport {\n SGLError,\n SGLAPIError,\n SGLAuthError,\n SGLNotFoundError,\n SGLConnectionError,\n} from \"./errors.js\";\nexport type {\n AttestationProof,\n CapacityResponse,\n ChatChoice,\n ChatCompletionRequest,\n ChatCompletionResponse,\n ChatMessage,\n GridClientOptions,\n JobResponse,\n JobResult,\n JobSubmission,\n ModelInfo,\n ModelPricing,\n PricingInfo,\n TeeCapacity,\n} from \"./types.js\";\n","export class SGLError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SGLError\";\n }\n}\n\nexport class SGLAPIError extends SGLError {\n readonly statusCode: number;\n readonly body?: Record<string, unknown>;\n\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(`HTTP ${statusCode}: ${message}`);\n this.name = \"SGLAPIError\";\n this.statusCode = statusCode;\n this.body = body;\n }\n}\n\nexport class SGLAuthError extends SGLAPIError {\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(statusCode, message, body);\n this.name = \"SGLAuthError\";\n }\n}\n\nexport class SGLNotFoundError extends SGLAPIError {\n constructor(message: string, body?: Record<string, unknown>) {\n super(404, message, body);\n this.name = \"SGLNotFoundError\";\n }\n}\n\nexport class SGLConnectionError extends SGLError {\n constructor(message: string) {\n super(message);\n this.name = \"SGLConnectionError\";\n }\n}\n","import { SGLAPIError, SGLAuthError, SGLConnectionError, SGLNotFoundError } from \"./errors.js\";\nimport type {\n AttestationProof,\n CapacityResponse,\n ChatCompletionRequest,\n ChatCompletionResponse,\n GridClientOptions,\n JobResponse,\n JobResult,\n ModelInfo,\n PricingInfo,\n} from \"./types.js\";\n\nexport const DEFAULT_BASE_URL =\n \"https://sgl-network-orchestrator.ivaavimusicproductions.workers.dev\";\n\nconst DEFAULT_TIMEOUT = 60_000;\n\nexport class GridClient {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly timeout: number;\n\n constructor(options: GridClientOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this.headers = { Accept: \"application/json\", \"Content-Type\": \"application/json\" };\n if (options.apiKey) {\n this.headers[\"Authorization\"] = `Bearer ${options.apiKey}`;\n }\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: this.headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n else if (err && typeof err === \"object\" && \"message\" in err)\n message = String((err as { message: unknown }).message);\n } catch {\n /* body not JSON */\n }\n\n if (response.status === 401 || response.status === 403) {\n throw new SGLAuthError(response.status, message, errorBody);\n }\n if (response.status === 404) {\n throw new SGLNotFoundError(message, errorBody);\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n if (response.status === 204) return {} as T;\n return (await response.json()) as T;\n }\n\n // -- Public endpoints (no auth) ------------------------------------------\n\n async capacity(): Promise<CapacityResponse> {\n return this.request<CapacityResponse>(\"GET\", \"/grid/capacity\");\n }\n\n async models(): Promise<ModelInfo[]> {\n const data = await this.request<{ models: ModelInfo[] }>(\"GET\", \"/grid/models\");\n return data.models ?? [];\n }\n\n async pricing(): Promise<PricingInfo[]> {\n const data = await this.request<{ pricing: PricingInfo[] }>(\"GET\", \"/grid/pricing\");\n return data.pricing ?? [];\n }\n\n // -- Authenticated endpoints ---------------------------------------------\n\n async submitJob(\n model: string,\n input: Record<string, unknown>,\n options?: { submitterWallet?: string; submitterChain?: string },\n ): Promise<JobResponse> {\n const body: Record<string, unknown> = { model, input };\n if (options?.submitterWallet) body.submitter_wallet = options.submitterWallet;\n if (options?.submitterChain) body.submitter_chain = options.submitterChain;\n return this.request<JobResponse>(\"POST\", \"/grid/jobs\", body);\n }\n\n async getJob(jobId: string): Promise<JobResult> {\n return this.request<JobResult>(\"GET\", `/grid/jobs/${jobId}`);\n }\n\n async getAttestation(jobId: string): Promise<AttestationProof> {\n return this.request<AttestationProof>(\"GET\", `/grid/jobs/${jobId}/attestation`);\n }\n\n // -- OpenAI-compatible ---------------------------------------------------\n\n async chatCompletions(\n request: ChatCompletionRequest,\n ): Promise<ChatCompletionResponse> {\n return this.request<ChatCompletionResponse>(\n \"POST\",\n \"/v1/chat/completions\",\n request,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,SAAS;AAAA,EAIxC,YACE,YACA,SACA,MACA;AACA,UAAM,QAAQ,UAAU,KAAK,OAAO,EAAE;AACtC,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,eAAN,cAA2B,YAAY;AAAA,EAC5C,YACE,YACA,SACA,MACA;AACA,UAAM,YAAY,SAAS,IAAI;AAC/B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,YAAY;AAAA,EAChD,YAAY,SAAiB,MAAgC;AAC3D,UAAM,KAAK,SAAS,IAAI;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,qBAAN,cAAiC,SAAS;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACjCO,IAAM,mBACX;AAEF,IAAM,kBAAkB;AAEj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"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["export { GridClient, DEFAULT_BASE_URL } from \"./client.js\";\nexport {\n SGLError,\n SGLAPIError,\n SGLAuthError,\n SGLNotFoundError,\n SGLConnectionError,\n} from \"./errors.js\";\nexport type {\n AttestationProof,\n CapacityResponse,\n ChatChoice,\n ChatCompletionRequest,\n ChatCompletionResponse,\n ChatMessage,\n DeployProcessorOptions,\n GridClientOptions,\n JobResponse,\n JobResult,\n JobSubmission,\n ModelInfo,\n ModelPricing,\n PricingInfo,\n ProcessorDeployResult,\n ProcessorInfo,\n ProcessorInvokeResult,\n ProcessorListResponse,\n ProcessorLogEntry,\n ProcessorLogsResponse,\n TeeCapacity,\n WalletAuth,\n} from \"./types.js\";\n","export class SGLError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SGLError\";\n }\n}\n\nexport class SGLAPIError extends SGLError {\n readonly statusCode: number;\n readonly body?: Record<string, unknown>;\n\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(`HTTP ${statusCode}: ${message}`);\n this.name = \"SGLAPIError\";\n this.statusCode = statusCode;\n this.body = body;\n }\n}\n\nexport class SGLAuthError extends SGLAPIError {\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(statusCode, message, body);\n this.name = \"SGLAuthError\";\n }\n}\n\nexport class SGLNotFoundError extends SGLAPIError {\n constructor(message: string, body?: Record<string, unknown>) {\n super(404, message, body);\n this.name = \"SGLNotFoundError\";\n }\n}\n\nexport class SGLConnectionError extends SGLError {\n constructor(message: string) {\n super(message);\n this.name = \"SGLConnectionError\";\n }\n}\n","import { SGLAPIError, SGLAuthError, SGLConnectionError, SGLNotFoundError } from \"./errors.js\";\nimport type {\n AttestationProof,\n CapacityResponse,\n ChatCompletionRequest,\n ChatCompletionResponse,\n DeployProcessorOptions,\n GridClientOptions,\n JobResponse,\n JobResult,\n ModelInfo,\n PricingInfo,\n ProcessorDeployResult,\n ProcessorInfo,\n ProcessorInvokeResult,\n ProcessorListResponse,\n ProcessorLogEntry,\n ProcessorLogsResponse,\n WalletAuth,\n} from \"./types.js\";\n\nexport const DEFAULT_BASE_URL = \"https://grid.x402compute.cc\";\n\nconst DEFAULT_TIMEOUT = 60_000;\n\nexport class GridClient {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly timeout: number;\n\n constructor(options: GridClientOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this.headers = { Accept: \"application/json\", \"Content-Type\": \"application/json\" };\n if (options.apiKey) {\n this.headers[\"Authorization\"] = `Bearer ${options.apiKey}`;\n }\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: this.headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n else if (err && typeof err === \"object\" && \"message\" in err)\n message = String((err as { message: unknown }).message);\n } catch {\n /* body not JSON */\n }\n\n if (response.status === 401 || response.status === 403) {\n throw new SGLAuthError(response.status, message, errorBody);\n }\n if (response.status === 404) {\n throw new SGLNotFoundError(message, errorBody);\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n if (response.status === 204) return {} as T;\n return (await response.json()) as T;\n }\n\n // -- Public endpoints (no auth) ------------------------------------------\n\n async capacity(): Promise<CapacityResponse> {\n return this.request<CapacityResponse>(\"GET\", \"/grid/capacity\");\n }\n\n async models(): Promise<ModelInfo[]> {\n const data = await this.request<{ models: ModelInfo[] }>(\"GET\", \"/grid/models\");\n return data.models ?? [];\n }\n\n async pricing(): Promise<PricingInfo[]> {\n const data = await this.request<{ pricing: PricingInfo[] }>(\"GET\", \"/grid/pricing\");\n return data.pricing ?? [];\n }\n\n // -- Authenticated endpoints ---------------------------------------------\n\n async submitJob(\n model: string,\n input: Record<string, unknown>,\n options?: { submitterWallet?: string; submitterChain?: string },\n ): Promise<JobResponse> {\n const body: Record<string, unknown> = { model, input };\n if (options?.submitterWallet) body.submitter_wallet = options.submitterWallet;\n if (options?.submitterChain) body.submitter_chain = options.submitterChain;\n return this.request<JobResponse>(\"POST\", \"/grid/jobs\", body);\n }\n\n async getJob(jobId: string): Promise<JobResult> {\n return this.request<JobResult>(\"GET\", `/grid/jobs/${jobId}`);\n }\n\n async getAttestation(jobId: string): Promise<AttestationProof> {\n return this.request<AttestationProof>(\"GET\", `/grid/jobs/${jobId}/attestation`);\n }\n\n // -- OpenAI-compatible ---------------------------------------------------\n\n async chatCompletions(\n request: ChatCompletionRequest,\n ): Promise<ChatCompletionResponse> {\n return this.request<ChatCompletionResponse>(\n \"POST\",\n \"/v1/chat/completions\",\n request,\n );\n }\n\n // -- Processor helpers ----------------------------------------------------\n\n private async requestWithWalletAuth<T>(\n method: string,\n path: string,\n wallet: WalletAuth,\n body?: unknown,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n const reqHeaders: Record<string, string> = {\n ...this.headers,\n \"X-Auth-Address\": wallet.address,\n \"X-Auth-Chain\": wallet.chain ?? \"solana\",\n \"X-Auth-Signature\": wallet.signature,\n \"X-Auth-Timestamp\": wallet.timestamp,\n \"X-Auth-Nonce\": wallet.nonce,\n };\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: reqHeaders,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n else if (err && typeof err === \"object\" && \"message\" in err)\n message = String((err as { message: unknown }).message);\n } catch {\n /* body not JSON */\n }\n\n if (response.status === 401 || response.status === 403) {\n throw new SGLAuthError(response.status, message, errorBody);\n }\n if (response.status === 404) {\n throw new SGLNotFoundError(message, errorBody);\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n if (response.status === 204) return {} as T;\n return (await response.json()) as T;\n }\n\n private async requestWithPayment<T>(\n method: string,\n path: string,\n body?: unknown,\n paymentHeader?: string,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n const reqHeaders: Record<string, string> = { ...this.headers };\n if (paymentHeader) {\n reqHeaders[\"X-Payment\"] = paymentHeader;\n }\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: reqHeaders,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (response.status === 402) {\n const requirements = (await response.json()) as Record<string, unknown>;\n throw new SGLAPIError(402, \"Payment required\", requirements);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n } catch {\n /* body not JSON */\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n return (await response.json()) as T;\n }\n\n // -- Processors -----------------------------------------------------------\n\n async deployProcessor(\n wallet: WalletAuth,\n options: DeployProcessorOptions,\n ): Promise<ProcessorDeployResult> {\n return this.requestWithWalletAuth<ProcessorDeployResult>(\n \"POST\",\n \"/grid/processors\",\n wallet,\n options,\n );\n }\n\n async invokeProcessor(\n processorName: string,\n input: Record<string, unknown>,\n options?: { paymentHeader?: string; paymentToken?: \"USDC\" | \"SGL\" },\n ): Promise<ProcessorInvokeResult> {\n const body: Record<string, unknown> = { input };\n if (options?.paymentToken) body.payment_token = options.paymentToken;\n return this.requestWithPayment<ProcessorInvokeResult>(\n \"POST\",\n `/grid/processors/${encodeURIComponent(processorName)}/invoke`,\n body,\n options?.paymentHeader,\n );\n }\n\n async listProcessors(options?: {\n owner?: string;\n page?: number;\n limit?: number;\n }): Promise<ProcessorListResponse> {\n const params = new URLSearchParams();\n if (options?.owner) params.set(\"owner\", options.owner);\n if (options?.page != null) params.set(\"page\", String(options.page));\n if (options?.limit != null) params.set(\"limit\", String(options.limit));\n const qs = params.toString();\n return this.request<ProcessorListResponse>(\n \"GET\",\n `/grid/processors${qs ? `?${qs}` : \"\"}`,\n );\n }\n\n async getProcessor(processorId: string): Promise<ProcessorInfo> {\n return this.request<ProcessorInfo>(\"GET\", `/grid/processors/${processorId}`);\n }\n\n async deleteProcessor(\n processorId: string,\n wallet: WalletAuth,\n ): Promise<{ deleted: boolean; id: string }> {\n return this.requestWithWalletAuth<{ deleted: boolean; id: string }>(\n \"DELETE\",\n `/grid/processors/${processorId}`,\n wallet,\n );\n }\n\n async getProcessorLogs(\n processorId: string,\n wallet: WalletAuth,\n options?: { page?: number; limit?: number },\n ): Promise<ProcessorLogsResponse> {\n const params = new URLSearchParams();\n if (options?.page != null) params.set(\"page\", String(options.page));\n if (options?.limit != null) params.set(\"limit\", String(options.limit));\n const qs = params.toString();\n return this.requestWithWalletAuth<ProcessorLogsResponse>(\n \"GET\",\n `/grid/processors/${processorId}/logs${qs ? `?${qs}` : \"\"}`,\n wallet,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,SAAS;AAAA,EAIxC,YACE,YACA,SACA,MACA;AACA,UAAM,QAAQ,UAAU,KAAK,OAAO,EAAE;AACtC,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,eAAN,cAA2B,YAAY;AAAA,EAC5C,YACE,YACA,SACA,MACA;AACA,UAAM,YAAY,SAAS,IAAI;AAC/B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,YAAY;AAAA,EAChD,YAAY,SAAiB,MAAgC;AAC3D,UAAM,KAAK,SAAS,IAAI;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,qBAAN,cAAiC,SAAS;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACzBO,IAAM,mBAAmB;AAEhC,IAAM,kBAAkB;AAEjB,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAAY,UAA6B,CAAC,GAAG;AAC3C,SAAK,WAAW,QAAQ,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AACvE,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,UAAU,EAAE,QAAQ,oBAAoB,gBAAgB,mB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WAAW,QAAQ,KAAK,IAAI,EAAE,KAAK,EAAE;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,7 @@ var SGLConnectionError = class extends SGLError {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
// src/client.ts
|
|
36
|
-
var DEFAULT_BASE_URL = "https://
|
|
36
|
+
var DEFAULT_BASE_URL = "https://grid.x402compute.cc";
|
|
37
37
|
var DEFAULT_TIMEOUT = 6e4;
|
|
38
38
|
var GridClient = class {
|
|
39
39
|
constructor(options = {}) {
|
|
@@ -121,6 +121,153 @@ var GridClient = class {
|
|
|
121
121
|
request
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
|
+
// -- Processor helpers ----------------------------------------------------
|
|
125
|
+
async requestWithWalletAuth(method, path, wallet, body) {
|
|
126
|
+
const url = `${this.baseUrl}${path}`;
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
129
|
+
const reqHeaders = {
|
|
130
|
+
...this.headers,
|
|
131
|
+
"X-Auth-Address": wallet.address,
|
|
132
|
+
"X-Auth-Chain": wallet.chain ?? "solana",
|
|
133
|
+
"X-Auth-Signature": wallet.signature,
|
|
134
|
+
"X-Auth-Timestamp": wallet.timestamp,
|
|
135
|
+
"X-Auth-Nonce": wallet.nonce
|
|
136
|
+
};
|
|
137
|
+
let response;
|
|
138
|
+
try {
|
|
139
|
+
response = await fetch(url, {
|
|
140
|
+
method,
|
|
141
|
+
headers: reqHeaders,
|
|
142
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
143
|
+
signal: controller.signal
|
|
144
|
+
});
|
|
145
|
+
} catch (err) {
|
|
146
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
147
|
+
throw new SGLConnectionError(`Request to ${url} timed out`);
|
|
148
|
+
}
|
|
149
|
+
throw new SGLConnectionError(
|
|
150
|
+
`Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`
|
|
151
|
+
);
|
|
152
|
+
} finally {
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
}
|
|
155
|
+
if (!response.ok) {
|
|
156
|
+
let errorBody;
|
|
157
|
+
let message = response.statusText;
|
|
158
|
+
try {
|
|
159
|
+
errorBody = await response.json();
|
|
160
|
+
const err = errorBody?.error;
|
|
161
|
+
if (typeof err === "string") message = err;
|
|
162
|
+
else if (err && typeof err === "object" && "message" in err)
|
|
163
|
+
message = String(err.message);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
if (response.status === 401 || response.status === 403) {
|
|
167
|
+
throw new SGLAuthError(response.status, message, errorBody);
|
|
168
|
+
}
|
|
169
|
+
if (response.status === 404) {
|
|
170
|
+
throw new SGLNotFoundError(message, errorBody);
|
|
171
|
+
}
|
|
172
|
+
throw new SGLAPIError(response.status, message, errorBody);
|
|
173
|
+
}
|
|
174
|
+
if (response.status === 204) return {};
|
|
175
|
+
return await response.json();
|
|
176
|
+
}
|
|
177
|
+
async requestWithPayment(method, path, body, paymentHeader) {
|
|
178
|
+
const url = `${this.baseUrl}${path}`;
|
|
179
|
+
const controller = new AbortController();
|
|
180
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
181
|
+
const reqHeaders = { ...this.headers };
|
|
182
|
+
if (paymentHeader) {
|
|
183
|
+
reqHeaders["X-Payment"] = paymentHeader;
|
|
184
|
+
}
|
|
185
|
+
let response;
|
|
186
|
+
try {
|
|
187
|
+
response = await fetch(url, {
|
|
188
|
+
method,
|
|
189
|
+
headers: reqHeaders,
|
|
190
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
191
|
+
signal: controller.signal
|
|
192
|
+
});
|
|
193
|
+
} catch (err) {
|
|
194
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
195
|
+
throw new SGLConnectionError(`Request to ${url} timed out`);
|
|
196
|
+
}
|
|
197
|
+
throw new SGLConnectionError(
|
|
198
|
+
`Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`
|
|
199
|
+
);
|
|
200
|
+
} finally {
|
|
201
|
+
clearTimeout(timer);
|
|
202
|
+
}
|
|
203
|
+
if (response.status === 402) {
|
|
204
|
+
const requirements = await response.json();
|
|
205
|
+
throw new SGLAPIError(402, "Payment required", requirements);
|
|
206
|
+
}
|
|
207
|
+
if (!response.ok) {
|
|
208
|
+
let errorBody;
|
|
209
|
+
let message = response.statusText;
|
|
210
|
+
try {
|
|
211
|
+
errorBody = await response.json();
|
|
212
|
+
const err = errorBody?.error;
|
|
213
|
+
if (typeof err === "string") message = err;
|
|
214
|
+
} catch {
|
|
215
|
+
}
|
|
216
|
+
throw new SGLAPIError(response.status, message, errorBody);
|
|
217
|
+
}
|
|
218
|
+
return await response.json();
|
|
219
|
+
}
|
|
220
|
+
// -- Processors -----------------------------------------------------------
|
|
221
|
+
async deployProcessor(wallet, options) {
|
|
222
|
+
return this.requestWithWalletAuth(
|
|
223
|
+
"POST",
|
|
224
|
+
"/grid/processors",
|
|
225
|
+
wallet,
|
|
226
|
+
options
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
async invokeProcessor(processorName, input, options) {
|
|
230
|
+
const body = { input };
|
|
231
|
+
if (options?.paymentToken) body.payment_token = options.paymentToken;
|
|
232
|
+
return this.requestWithPayment(
|
|
233
|
+
"POST",
|
|
234
|
+
`/grid/processors/${encodeURIComponent(processorName)}/invoke`,
|
|
235
|
+
body,
|
|
236
|
+
options?.paymentHeader
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
async listProcessors(options) {
|
|
240
|
+
const params = new URLSearchParams();
|
|
241
|
+
if (options?.owner) params.set("owner", options.owner);
|
|
242
|
+
if (options?.page != null) params.set("page", String(options.page));
|
|
243
|
+
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
244
|
+
const qs = params.toString();
|
|
245
|
+
return this.request(
|
|
246
|
+
"GET",
|
|
247
|
+
`/grid/processors${qs ? `?${qs}` : ""}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
async getProcessor(processorId) {
|
|
251
|
+
return this.request("GET", `/grid/processors/${processorId}`);
|
|
252
|
+
}
|
|
253
|
+
async deleteProcessor(processorId, wallet) {
|
|
254
|
+
return this.requestWithWalletAuth(
|
|
255
|
+
"DELETE",
|
|
256
|
+
`/grid/processors/${processorId}`,
|
|
257
|
+
wallet
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
async getProcessorLogs(processorId, wallet, options) {
|
|
261
|
+
const params = new URLSearchParams();
|
|
262
|
+
if (options?.page != null) params.set("page", String(options.page));
|
|
263
|
+
if (options?.limit != null) params.set("limit", String(options.limit));
|
|
264
|
+
const qs = params.toString();
|
|
265
|
+
return this.requestWithWalletAuth(
|
|
266
|
+
"GET",
|
|
267
|
+
`/grid/processors/${processorId}/logs${qs ? `?${qs}` : ""}`,
|
|
268
|
+
wallet
|
|
269
|
+
);
|
|
270
|
+
}
|
|
124
271
|
};
|
|
125
272
|
export {
|
|
126
273
|
DEFAULT_BASE_URL,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["export class SGLError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SGLError\";\n }\n}\n\nexport class SGLAPIError extends SGLError {\n readonly statusCode: number;\n readonly body?: Record<string, unknown>;\n\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(`HTTP ${statusCode}: ${message}`);\n this.name = \"SGLAPIError\";\n this.statusCode = statusCode;\n this.body = body;\n }\n}\n\nexport class SGLAuthError extends SGLAPIError {\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(statusCode, message, body);\n this.name = \"SGLAuthError\";\n }\n}\n\nexport class SGLNotFoundError extends SGLAPIError {\n constructor(message: string, body?: Record<string, unknown>) {\n super(404, message, body);\n this.name = \"SGLNotFoundError\";\n }\n}\n\nexport class SGLConnectionError extends SGLError {\n constructor(message: string) {\n super(message);\n this.name = \"SGLConnectionError\";\n }\n}\n","import { SGLAPIError, SGLAuthError, SGLConnectionError, SGLNotFoundError } from \"./errors.js\";\nimport type {\n AttestationProof,\n CapacityResponse,\n ChatCompletionRequest,\n ChatCompletionResponse,\n GridClientOptions,\n JobResponse,\n JobResult,\n ModelInfo,\n PricingInfo,\n} from \"./types.js\";\n\nexport const DEFAULT_BASE_URL =\n \"https://sgl-network-orchestrator.ivaavimusicproductions.workers.dev\";\n\nconst DEFAULT_TIMEOUT = 60_000;\n\nexport class GridClient {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly timeout: number;\n\n constructor(options: GridClientOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this.headers = { Accept: \"application/json\", \"Content-Type\": \"application/json\" };\n if (options.apiKey) {\n this.headers[\"Authorization\"] = `Bearer ${options.apiKey}`;\n }\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: this.headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n else if (err && typeof err === \"object\" && \"message\" in err)\n message = String((err as { message: unknown }).message);\n } catch {\n /* body not JSON */\n }\n\n if (response.status === 401 || response.status === 403) {\n throw new SGLAuthError(response.status, message, errorBody);\n }\n if (response.status === 404) {\n throw new SGLNotFoundError(message, errorBody);\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n if (response.status === 204) return {} as T;\n return (await response.json()) as T;\n }\n\n // -- Public endpoints (no auth) ------------------------------------------\n\n async capacity(): Promise<CapacityResponse> {\n return this.request<CapacityResponse>(\"GET\", \"/grid/capacity\");\n }\n\n async models(): Promise<ModelInfo[]> {\n const data = await this.request<{ models: ModelInfo[] }>(\"GET\", \"/grid/models\");\n return data.models ?? [];\n }\n\n async pricing(): Promise<PricingInfo[]> {\n const data = await this.request<{ pricing: PricingInfo[] }>(\"GET\", \"/grid/pricing\");\n return data.pricing ?? [];\n }\n\n // -- Authenticated endpoints ---------------------------------------------\n\n async submitJob(\n model: string,\n input: Record<string, unknown>,\n options?: { submitterWallet?: string; submitterChain?: string },\n ): Promise<JobResponse> {\n const body: Record<string, unknown> = { model, input };\n if (options?.submitterWallet) body.submitter_wallet = options.submitterWallet;\n if (options?.submitterChain) body.submitter_chain = options.submitterChain;\n return this.request<JobResponse>(\"POST\", \"/grid/jobs\", body);\n }\n\n async getJob(jobId: string): Promise<JobResult> {\n return this.request<JobResult>(\"GET\", `/grid/jobs/${jobId}`);\n }\n\n async getAttestation(jobId: string): Promise<AttestationProof> {\n return this.request<AttestationProof>(\"GET\", `/grid/jobs/${jobId}/attestation`);\n }\n\n // -- OpenAI-compatible ---------------------------------------------------\n\n async chatCompletions(\n request: ChatCompletionRequest,\n ): Promise<ChatCompletionResponse> {\n return this.request<ChatCompletionResponse>(\n \"POST\",\n \"/v1/chat/completions\",\n request,\n );\n }\n}\n"],"mappings":";AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,SAAS;AA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EAIA,MAAM,UACJ,OACA,OACA,SACsB;AACtB,UAAM,OAAgC,EAAE,OAAO,MAAM;AACrD,QAAI,SAAS,gBAAiB,MAAK,mBAAmB,QAAQ;AAC9D,QAAI,SAAS,eAAgB,MAAK,kBAAkB,QAAQ;AAC5D,WAAO,KAAK,QAAqB,QAAQ,cAAc,IAAI;AAAA,EAC7D;AAAA,EAEA,MAAM,OAAO,OAAmC;AAC9C,WAAO,KAAK,QAAmB,OAAO,cAAc,KAAK,EAAE;AAAA,EAC7D;AAAA,EAEA,MAAM,eAAe,OAA0C;AAC7D,WAAO,KAAK,QAA0B,OAAO,cAAc,KAAK,cAAc;AAAA,EAChF;AAAA;AAAA,EAIA,MAAM,gBACJ,SACiC;AACjC,WAAO,KAAK;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["export class SGLError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"SGLError\";\n }\n}\n\nexport class SGLAPIError extends SGLError {\n readonly statusCode: number;\n readonly body?: Record<string, unknown>;\n\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(`HTTP ${statusCode}: ${message}`);\n this.name = \"SGLAPIError\";\n this.statusCode = statusCode;\n this.body = body;\n }\n}\n\nexport class SGLAuthError extends SGLAPIError {\n constructor(\n statusCode: number,\n message: string,\n body?: Record<string, unknown>,\n ) {\n super(statusCode, message, body);\n this.name = \"SGLAuthError\";\n }\n}\n\nexport class SGLNotFoundError extends SGLAPIError {\n constructor(message: string, body?: Record<string, unknown>) {\n super(404, message, body);\n this.name = \"SGLNotFoundError\";\n }\n}\n\nexport class SGLConnectionError extends SGLError {\n constructor(message: string) {\n super(message);\n this.name = \"SGLConnectionError\";\n }\n}\n","import { SGLAPIError, SGLAuthError, SGLConnectionError, SGLNotFoundError } from \"./errors.js\";\nimport type {\n AttestationProof,\n CapacityResponse,\n ChatCompletionRequest,\n ChatCompletionResponse,\n DeployProcessorOptions,\n GridClientOptions,\n JobResponse,\n JobResult,\n ModelInfo,\n PricingInfo,\n ProcessorDeployResult,\n ProcessorInfo,\n ProcessorInvokeResult,\n ProcessorListResponse,\n ProcessorLogEntry,\n ProcessorLogsResponse,\n WalletAuth,\n} from \"./types.js\";\n\nexport const DEFAULT_BASE_URL = \"https://grid.x402compute.cc\";\n\nconst DEFAULT_TIMEOUT = 60_000;\n\nexport class GridClient {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n private readonly timeout: number;\n\n constructor(options: GridClientOptions = {}) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n this.headers = { Accept: \"application/json\", \"Content-Type\": \"application/json\" };\n if (options.apiKey) {\n this.headers[\"Authorization\"] = `Bearer ${options.apiKey}`;\n }\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: this.headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n else if (err && typeof err === \"object\" && \"message\" in err)\n message = String((err as { message: unknown }).message);\n } catch {\n /* body not JSON */\n }\n\n if (response.status === 401 || response.status === 403) {\n throw new SGLAuthError(response.status, message, errorBody);\n }\n if (response.status === 404) {\n throw new SGLNotFoundError(message, errorBody);\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n if (response.status === 204) return {} as T;\n return (await response.json()) as T;\n }\n\n // -- Public endpoints (no auth) ------------------------------------------\n\n async capacity(): Promise<CapacityResponse> {\n return this.request<CapacityResponse>(\"GET\", \"/grid/capacity\");\n }\n\n async models(): Promise<ModelInfo[]> {\n const data = await this.request<{ models: ModelInfo[] }>(\"GET\", \"/grid/models\");\n return data.models ?? [];\n }\n\n async pricing(): Promise<PricingInfo[]> {\n const data = await this.request<{ pricing: PricingInfo[] }>(\"GET\", \"/grid/pricing\");\n return data.pricing ?? [];\n }\n\n // -- Authenticated endpoints ---------------------------------------------\n\n async submitJob(\n model: string,\n input: Record<string, unknown>,\n options?: { submitterWallet?: string; submitterChain?: string },\n ): Promise<JobResponse> {\n const body: Record<string, unknown> = { model, input };\n if (options?.submitterWallet) body.submitter_wallet = options.submitterWallet;\n if (options?.submitterChain) body.submitter_chain = options.submitterChain;\n return this.request<JobResponse>(\"POST\", \"/grid/jobs\", body);\n }\n\n async getJob(jobId: string): Promise<JobResult> {\n return this.request<JobResult>(\"GET\", `/grid/jobs/${jobId}`);\n }\n\n async getAttestation(jobId: string): Promise<AttestationProof> {\n return this.request<AttestationProof>(\"GET\", `/grid/jobs/${jobId}/attestation`);\n }\n\n // -- OpenAI-compatible ---------------------------------------------------\n\n async chatCompletions(\n request: ChatCompletionRequest,\n ): Promise<ChatCompletionResponse> {\n return this.request<ChatCompletionResponse>(\n \"POST\",\n \"/v1/chat/completions\",\n request,\n );\n }\n\n // -- Processor helpers ----------------------------------------------------\n\n private async requestWithWalletAuth<T>(\n method: string,\n path: string,\n wallet: WalletAuth,\n body?: unknown,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n const reqHeaders: Record<string, string> = {\n ...this.headers,\n \"X-Auth-Address\": wallet.address,\n \"X-Auth-Chain\": wallet.chain ?? \"solana\",\n \"X-Auth-Signature\": wallet.signature,\n \"X-Auth-Timestamp\": wallet.timestamp,\n \"X-Auth-Nonce\": wallet.nonce,\n };\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: reqHeaders,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n else if (err && typeof err === \"object\" && \"message\" in err)\n message = String((err as { message: unknown }).message);\n } catch {\n /* body not JSON */\n }\n\n if (response.status === 401 || response.status === 403) {\n throw new SGLAuthError(response.status, message, errorBody);\n }\n if (response.status === 404) {\n throw new SGLNotFoundError(message, errorBody);\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n if (response.status === 204) return {} as T;\n return (await response.json()) as T;\n }\n\n private async requestWithPayment<T>(\n method: string,\n path: string,\n body?: unknown,\n paymentHeader?: string,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n const reqHeaders: Record<string, string> = { ...this.headers };\n if (paymentHeader) {\n reqHeaders[\"X-Payment\"] = paymentHeader;\n }\n\n let response: Response;\n try {\n response = await fetch(url, {\n method,\n headers: reqHeaders,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n if (err instanceof Error && err.name === \"AbortError\") {\n throw new SGLConnectionError(`Request to ${url} timed out`);\n }\n throw new SGLConnectionError(\n `Could not connect to ${this.baseUrl}: ${err instanceof Error ? err.message : String(err)}`,\n );\n } finally {\n clearTimeout(timer);\n }\n\n if (response.status === 402) {\n const requirements = (await response.json()) as Record<string, unknown>;\n throw new SGLAPIError(402, \"Payment required\", requirements);\n }\n\n if (!response.ok) {\n let errorBody: Record<string, unknown> | undefined;\n let message = response.statusText;\n try {\n errorBody = (await response.json()) as Record<string, unknown>;\n const err = errorBody?.error;\n if (typeof err === \"string\") message = err;\n } catch {\n /* body not JSON */\n }\n throw new SGLAPIError(response.status, message, errorBody);\n }\n\n return (await response.json()) as T;\n }\n\n // -- Processors -----------------------------------------------------------\n\n async deployProcessor(\n wallet: WalletAuth,\n options: DeployProcessorOptions,\n ): Promise<ProcessorDeployResult> {\n return this.requestWithWalletAuth<ProcessorDeployResult>(\n \"POST\",\n \"/grid/processors\",\n wallet,\n options,\n );\n }\n\n async invokeProcessor(\n processorName: string,\n input: Record<string, unknown>,\n options?: { paymentHeader?: string; paymentToken?: \"USDC\" | \"SGL\" },\n ): Promise<ProcessorInvokeResult> {\n const body: Record<string, unknown> = { input };\n if (options?.paymentToken) body.payment_token = options.paymentToken;\n return this.requestWithPayment<ProcessorInvokeResult>(\n \"POST\",\n `/grid/processors/${encodeURIComponent(processorName)}/invoke`,\n body,\n options?.paymentHeader,\n );\n }\n\n async listProcessors(options?: {\n owner?: string;\n page?: number;\n limit?: number;\n }): Promise<ProcessorListResponse> {\n const params = new URLSearchParams();\n if (options?.owner) params.set(\"owner\", options.owner);\n if (options?.page != null) params.set(\"page\", String(options.page));\n if (options?.limit != null) params.set(\"limit\", String(options.limit));\n const qs = params.toString();\n return this.request<ProcessorListResponse>(\n \"GET\",\n `/grid/processors${qs ? `?${qs}` : \"\"}`,\n );\n }\n\n async getProcessor(processorId: string): Promise<ProcessorInfo> {\n return this.request<ProcessorInfo>(\"GET\", `/grid/processors/${processorId}`);\n }\n\n async deleteProcessor(\n processorId: string,\n wallet: WalletAuth,\n ): Promise<{ deleted: boolean; id: string }> {\n return this.requestWithWalletAuth<{ deleted: boolean; id: string }>(\n \"DELETE\",\n `/grid/processors/${processorId}`,\n wallet,\n );\n }\n\n async getProcessorLogs(\n processorId: string,\n wallet: WalletAuth,\n options?: { page?: number; limit?: number },\n ): Promise<ProcessorLogsResponse> {\n const params = new URLSearchParams();\n if (options?.page != null) params.set(\"page\", String(options.page));\n if (options?.limit != null) params.set(\"limit\", String(options.limit));\n const qs = params.toString();\n return this.requestWithWalletAuth<ProcessorLogsResponse>(\n \"GET\",\n `/grid/processors/${processorId}/logs${qs ? `?${qs}` : \"\"}`,\n wallet,\n );\n }\n}\n"],"mappings":";AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,SAAS;AAAA,EAIxC,YACE,YACA,SACA,MACA;AACA,UAAM,QAAQ,UAAU,KAAK,OAAO,EAAE;AACtC,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,eAAN,cAA2B,YAAY;AAAA,EAC5C,YACE,YACA,SACA,MACA;AACA,UAAM,YAAY,SAAS,IAAI;AAC/B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,YAAY;AAAA,EAChD,YAAY,SAAiB,MAAgC;AAC3D,UAAM,KAAK,SAAS,IAAI;AACxB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,qBAAN,cAAiC,SAAS;AAAA,EAC/C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;;;ACzBO,IAAM,mBAAmB;AAEhC,IAAM,kBAAkB;AAEjB,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAAY,UAA6B,CAAC,GAAG;AAC3C,SAAK,WAAW,QAAQ,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AACvE,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,UAAU,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K;AAAA,MACV;AAAA,MACA,oBAAoB,WAAW,QAAQ,KAAK,IAAI,EAAE,KAAK,EAAE;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@singularity-layer/grid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript SDK for the SGL Network confidential compute grid",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"confidential-computing",
|
|
31
31
|
"inference",
|
|
32
32
|
"ai",
|
|
33
|
-
"openai"
|
|
33
|
+
"openai",
|
|
34
|
+
"serverless",
|
|
35
|
+
"processors",
|
|
36
|
+
"x402"
|
|
34
37
|
],
|
|
35
38
|
"author": "Singularity Layer <dev@singularitylayer.xyz>",
|
|
36
39
|
"license": "MIT",
|