segmind 0.5.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/dist/index.cjs +29 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +29 -16
- 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
|
|
|
@@ -811,7 +814,7 @@ declare class InferenceTimeout extends SegmindError {
|
|
|
811
814
|
constructor(requestId: string, elapsedMs: number);
|
|
812
815
|
}
|
|
813
816
|
|
|
814
|
-
declare const VERSION = "0.5.
|
|
817
|
+
declare const VERSION = "0.5.1";
|
|
815
818
|
|
|
816
819
|
/** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
|
|
817
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
|
|
|
@@ -806,7 +819,7 @@ function failureDetail(body) {
|
|
|
806
819
|
}
|
|
807
820
|
|
|
808
821
|
// src/version.ts
|
|
809
|
-
var VERSION = "0.5.
|
|
822
|
+
var VERSION = "0.5.1";
|
|
810
823
|
|
|
811
824
|
// src/webhooks.ts
|
|
812
825
|
var Webhooks = class {
|