segmind 0.4.0 → 0.5.1
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/README.md +4 -1
- package/dist/index.cjs +32 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +32 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -209,7 +209,10 @@ declare class Files {
|
|
|
209
209
|
private stage;
|
|
210
210
|
/** A file in the caller's asset library: presign, PUT, then confirm to register it. */
|
|
211
211
|
private persist;
|
|
212
|
-
/**
|
|
212
|
+
/**
|
|
213
|
+
* A PUT to the same key is idempotent, so it retries; a `Blob` body can be
|
|
214
|
+
* sent again, unlike a stream. `bare` keeps the API key off the storage host.
|
|
215
|
+
*/
|
|
213
216
|
private put;
|
|
214
217
|
}
|
|
215
218
|
|
|
@@ -262,6 +265,9 @@ interface RequestRecord {
|
|
|
262
265
|
}
|
|
263
266
|
interface GenerationsListOptions {
|
|
264
267
|
page?: number;
|
|
268
|
+
/** 1–100. Default 10. */
|
|
269
|
+
perPage?: number;
|
|
270
|
+
/** Substring match on the model slug. */
|
|
265
271
|
modelName?: string;
|
|
266
272
|
/** YYYY-MM-DD. */
|
|
267
273
|
startDate?: string;
|
|
@@ -269,6 +275,8 @@ interface GenerationsListOptions {
|
|
|
269
275
|
endDate?: string;
|
|
270
276
|
/** Inside a team, any member's user id; otherwise only your own. */
|
|
271
277
|
userId?: string;
|
|
278
|
+
/** Same as `userId`, by email. Pass one or the other. */
|
|
279
|
+
userEmail?: string;
|
|
272
280
|
signal?: AbortSignal;
|
|
273
281
|
}
|
|
274
282
|
interface HistoryOptions {
|
|
@@ -806,7 +814,7 @@ declare class InferenceTimeout extends SegmindError {
|
|
|
806
814
|
constructor(requestId: string, elapsedMs: number);
|
|
807
815
|
}
|
|
808
816
|
|
|
809
|
-
declare const VERSION = "0.
|
|
817
|
+
declare const VERSION = "0.5.1";
|
|
810
818
|
|
|
811
819
|
/** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
|
|
812
820
|
declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
|
package/dist/index.js
CHANGED
|
@@ -441,22 +441,22 @@ function mimeFromName(name) {
|
|
|
441
441
|
const extension = name.includes(".") ? name.split(".").pop().toLowerCase() : "";
|
|
442
442
|
return MIME_BY_EXTENSION[extension];
|
|
443
443
|
}
|
|
444
|
-
async function
|
|
445
|
-
let
|
|
444
|
+
async function openFileInput(input, options) {
|
|
445
|
+
let body;
|
|
446
446
|
let name = options.filename;
|
|
447
447
|
let mimeType = options.mimeType;
|
|
448
448
|
if (typeof input === "string") {
|
|
449
449
|
if (detectRuntime() !== "node") {
|
|
450
450
|
throw new SegmindError(`${options.caller}: file paths work in Node only; pass a Blob or bytes`);
|
|
451
451
|
}
|
|
452
|
-
const {
|
|
452
|
+
const { openAsBlob } = await import(
|
|
453
453
|
/* webpackIgnore: true */
|
|
454
454
|
/* turbopackIgnore: true */
|
|
455
455
|
/* @vite-ignore */
|
|
456
|
-
"node:fs
|
|
456
|
+
"node:fs"
|
|
457
457
|
);
|
|
458
458
|
try {
|
|
459
|
-
|
|
459
|
+
body = await openAsBlob(input);
|
|
460
460
|
} catch (err) {
|
|
461
461
|
throw new SegmindError(`${options.caller}: cannot read ${JSON.stringify(input)}: ${err.message}`, {
|
|
462
462
|
cause: err
|
|
@@ -464,13 +464,13 @@ async function readFileInput(input, options) {
|
|
|
464
464
|
}
|
|
465
465
|
name ??= input.split(/[\\/]/).pop();
|
|
466
466
|
} else if (typeof Blob !== "undefined" && input instanceof Blob) {
|
|
467
|
-
|
|
467
|
+
body = input;
|
|
468
468
|
name ??= input.name || void 0;
|
|
469
469
|
mimeType ??= input.type || void 0;
|
|
470
470
|
} else {
|
|
471
|
-
|
|
471
|
+
body = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
472
472
|
}
|
|
473
|
-
mimeType ??= name && mimeFromName(name) || sniff(
|
|
473
|
+
mimeType ??= name && mimeFromName(name) || sniff(await head(body));
|
|
474
474
|
if (!name || !name.includes(".")) {
|
|
475
475
|
const extension = mimeType ? EXTENSION_BY_MIME[mimeType] : void 0;
|
|
476
476
|
if (!extension) {
|
|
@@ -478,7 +478,17 @@ async function readFileInput(input, options) {
|
|
|
478
478
|
}
|
|
479
479
|
name = `${name || "upload"}.${extension}`;
|
|
480
480
|
}
|
|
481
|
-
|
|
481
|
+
const size = body instanceof Uint8Array ? body.byteLength : body.size;
|
|
482
|
+
return { body, size, filename: name, mimeType };
|
|
483
|
+
}
|
|
484
|
+
async function readFileInput(input, options) {
|
|
485
|
+
const { body, filename, mimeType } = await openFileInput(input, options);
|
|
486
|
+
const bytes = body instanceof Uint8Array ? body : new Uint8Array(await body.arrayBuffer());
|
|
487
|
+
return { bytes, filename, mimeType };
|
|
488
|
+
}
|
|
489
|
+
async function head(body) {
|
|
490
|
+
if (body instanceof Uint8Array) return body;
|
|
491
|
+
return new Uint8Array(await body.slice(0, 16).arrayBuffer());
|
|
482
492
|
}
|
|
483
493
|
function sniff(bytes) {
|
|
484
494
|
const at = (offset, signature) => signature.every((b, i) => bytes[offset + i] === b);
|
|
@@ -508,16 +518,16 @@ var Files = class {
|
|
|
508
518
|
return this.uploadOne(input, options);
|
|
509
519
|
}
|
|
510
520
|
async uploadOne(input, options) {
|
|
511
|
-
const file = await
|
|
521
|
+
const file = await openFileInput(input, { ...options, caller: "files.upload" });
|
|
512
522
|
const url = options.persist ? await this.persist(file, options.signal) : await this.stage(file, options.signal);
|
|
513
|
-
return { url, filename: file.filename, size: file.
|
|
523
|
+
return { url, filename: file.filename, size: file.size, persistent: options.persist === true };
|
|
514
524
|
}
|
|
515
525
|
/** A temporary model input on the inference API's input bucket. */
|
|
516
526
|
async stage(file, signal) {
|
|
517
527
|
const ticket = await this.client.http.json({
|
|
518
528
|
method: "POST",
|
|
519
529
|
url: `${this.client.spotURL}/inference-request/input-presign`,
|
|
520
|
-
body: { filename: file.filename, size: file.
|
|
530
|
+
body: { filename: file.filename, size: file.size },
|
|
521
531
|
signal,
|
|
522
532
|
retry: true
|
|
523
533
|
});
|
|
@@ -540,7 +550,7 @@ var Files = class {
|
|
|
540
550
|
const ticket = await http.json({
|
|
541
551
|
method: "POST",
|
|
542
552
|
url: `${assetsURL}/upload-asset/presign`,
|
|
543
|
-
body: { filename: file.filename, contentType, size: file.
|
|
553
|
+
body: { filename: file.filename, contentType, size: file.size },
|
|
544
554
|
signal,
|
|
545
555
|
retry: true
|
|
546
556
|
});
|
|
@@ -559,9 +569,12 @@ var Files = class {
|
|
|
559
569
|
});
|
|
560
570
|
return confirmed.asset?.url ?? ticket.publicUrl;
|
|
561
571
|
}
|
|
562
|
-
/**
|
|
572
|
+
/**
|
|
573
|
+
* A PUT to the same key is idempotent, so it retries; a `Blob` body can be
|
|
574
|
+
* sent again, unlike a stream. `bare` keeps the API key off the storage host.
|
|
575
|
+
*/
|
|
563
576
|
async put(url, file, headers, signal) {
|
|
564
|
-
await this.client.http.request({ method: "PUT", url, rawBody: file.
|
|
577
|
+
await this.client.http.request({ method: "PUT", url, rawBody: file.body, headers, bare: true, signal, retry: true });
|
|
565
578
|
}
|
|
566
579
|
};
|
|
567
580
|
|
|
@@ -575,10 +588,12 @@ var Generations = class {
|
|
|
575
588
|
async list(options = {}) {
|
|
576
589
|
return this.read("/inference-request/generations", options.signal, {
|
|
577
590
|
page: options.page ?? 1,
|
|
591
|
+
per_page: options.perPage,
|
|
578
592
|
model_name: options.modelName,
|
|
579
593
|
start_date: options.startDate,
|
|
580
594
|
end_date: options.endDate,
|
|
581
|
-
user_id: options.userId
|
|
595
|
+
user_id: options.userId,
|
|
596
|
+
user_email: options.userEmail
|
|
582
597
|
});
|
|
583
598
|
}
|
|
584
599
|
/** The newest generations for one model. */
|
|
@@ -804,7 +819,7 @@ function failureDetail(body) {
|
|
|
804
819
|
}
|
|
805
820
|
|
|
806
821
|
// src/version.ts
|
|
807
|
-
var VERSION = "0.
|
|
822
|
+
var VERSION = "0.5.1";
|
|
808
823
|
|
|
809
824
|
// src/webhooks.ts
|
|
810
825
|
var Webhooks = class {
|