segmind 0.5.1 → 0.6.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/README.md +60 -0
- package/dist/chunk-74UKKBOO.cjs +115 -0
- package/dist/chunk-74UKKBOO.cjs.map +1 -0
- package/dist/chunk-HWZJ36WC.cjs +186 -0
- package/dist/chunk-HWZJ36WC.cjs.map +1 -0
- package/dist/chunk-PS5KUT7P.js +115 -0
- package/dist/chunk-PS5KUT7P.js.map +1 -0
- package/dist/chunk-USGY6G4C.js +186 -0
- package/dist/chunk-USGY6G4C.js.map +1 -0
- package/dist/errors-CcHEuSmR.d.cts +258 -0
- package/dist/errors-CcHEuSmR.d.ts +258 -0
- package/dist/index.cjs +204 -294
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -60
- package/dist/index.d.ts +39 -60
- package/dist/index.js +47 -104
- package/dist/index.js.map +1 -1
- package/dist/realtime/browser/index.cjs +307 -0
- package/dist/realtime/browser/index.cjs.map +1 -0
- package/dist/realtime/browser/index.d.cts +122 -0
- package/dist/realtime/browser/index.d.ts +122 -0
- package/dist/realtime/browser/index.js +307 -0
- package/dist/realtime/browser/index.js.map +1 -0
- package/dist/realtime/index.cjs +549 -0
- package/dist/realtime/index.cjs.map +1 -0
- package/dist/realtime/index.d.cts +114 -0
- package/dist/realtime/index.d.ts +114 -0
- package/dist/realtime/index.js +549 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/vad-B-BeifvT.d.cts +245 -0
- package/dist/vad-BcBkqh2p.d.ts +245 -0
- package/package.json +44 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { S as SessionToken, a as SessionTokenProvider } from './errors-CcHEuSmR.cjs';
|
|
2
|
+
export { A as APIConnectionError, I as InferenceFailed, b as InferenceTimeout, c as InsufficientCredits, R as RateLimited, d as SegmindError } from './errors-CcHEuSmR.cjs';
|
|
3
|
+
|
|
1
4
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
2
5
|
/** Returns the signed-in user's token, or null when there is none. Called before every request. */
|
|
3
6
|
type TokenProvider = () => string | null | undefined | Promise<string | null | undefined>;
|
|
@@ -435,6 +438,37 @@ declare class PixelflowJob {
|
|
|
435
438
|
wait(options?: PixelflowWaitOptions): Promise<PixelflowStatus>;
|
|
436
439
|
}
|
|
437
440
|
|
|
441
|
+
interface CreateSessionTokenOptions {
|
|
442
|
+
/** The session model the token opens, and the only one. */
|
|
443
|
+
slug: string;
|
|
444
|
+
/** The most the session may spend, in credits: above 0, at most 100. The gateway's default applies when omitted. */
|
|
445
|
+
creditCeiling?: number;
|
|
446
|
+
/** Seconds the token can be used to open a session, at most 120. A session outlives its token. */
|
|
447
|
+
ttl?: number;
|
|
448
|
+
/** What the session is recorded as. Default `SDK-JS`; pass `SDK-RN` for a phone app's sessions. */
|
|
449
|
+
initiator?: Initiator;
|
|
450
|
+
signal?: AbortSignal;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Session tokens for realtime models. A token is minted on a server with the
|
|
454
|
+
* API key, opens one session of one model, and caps what that session may
|
|
455
|
+
* spend, so it is safe to hand to a browser or a phone app.
|
|
456
|
+
*/
|
|
457
|
+
declare class Realtime {
|
|
458
|
+
private readonly client;
|
|
459
|
+
constructor(client: Segmind);
|
|
460
|
+
/**
|
|
461
|
+
* Mints a session token. Serve it from your backend to the app that opens
|
|
462
|
+
* the session with `connect()` from `segmind/realtime`.
|
|
463
|
+
*/
|
|
464
|
+
createToken(options: CreateSessionTokenOptions): Promise<SessionToken>;
|
|
465
|
+
/**
|
|
466
|
+
* A `tokenProvider` that mints with this client's key, for opening sessions
|
|
467
|
+
* from a server: `connect(slug, { tokenProvider: segmind.realtime.tokenProvider() })`.
|
|
468
|
+
*/
|
|
469
|
+
tokenProvider(options?: Omit<CreateSessionTokenOptions, 'slug' | 'signal'>): SessionTokenProvider;
|
|
470
|
+
}
|
|
471
|
+
|
|
438
472
|
/**
|
|
439
473
|
* What a registration subscribes to. `PIXELFLOW` covers PixelFlow runs; the
|
|
440
474
|
* others are the platform's remaining subscription types.
|
|
@@ -595,6 +629,8 @@ declare class Segmind {
|
|
|
595
629
|
readonly webhooks: Webhooks;
|
|
596
630
|
/** Run published PixelFlow workflows. */
|
|
597
631
|
readonly pixelflows: PixelFlows;
|
|
632
|
+
/** Session tokens for realtime models. The sessions themselves open from `segmind/realtime`. */
|
|
633
|
+
readonly realtime: Realtime;
|
|
598
634
|
/** @internal */
|
|
599
635
|
readonly http: HttpClient;
|
|
600
636
|
constructor(options?: ClientOptions);
|
|
@@ -757,64 +793,7 @@ declare function imageUrl(input: ImageInput, options?: {
|
|
|
757
793
|
mimeType?: string;
|
|
758
794
|
}): Promise<ImageUrlPart>;
|
|
759
795
|
|
|
760
|
-
|
|
761
|
-
status?: number;
|
|
762
|
-
detail?: string;
|
|
763
|
-
requestId?: string;
|
|
764
|
-
body?: unknown;
|
|
765
|
-
cause?: unknown;
|
|
766
|
-
}
|
|
767
|
-
/** Base class of every error the SDK throws (except an `AbortSignal`'s own reason). */
|
|
768
|
-
declare class SegmindError extends Error {
|
|
769
|
-
/** HTTP status, when the error came from a response. */
|
|
770
|
-
readonly status: number | undefined;
|
|
771
|
-
/** The server's error text (`error` in the response body), when it sent one. */
|
|
772
|
-
readonly detail: string | undefined;
|
|
773
|
-
/** The v2 request id the error belongs to, when there is one. */
|
|
774
|
-
readonly requestId: string | undefined;
|
|
775
|
-
/** The parsed response body, or its text when it was not JSON. */
|
|
776
|
-
readonly body: unknown;
|
|
777
|
-
constructor(message: string, options?: SegmindErrorOptions);
|
|
778
|
-
/** Reads the response body and builds the error. Consumes the body. */
|
|
779
|
-
static fromResponse(response: Response, requestId?: string): Promise<SegmindError>;
|
|
780
|
-
}
|
|
781
|
-
/** The request never got a response: DNS, TLS, connection reset, or the client's timeout. */
|
|
782
|
-
declare class APIConnectionError extends SegmindError {
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* The account cannot pay for the request. The gateway reports this at submit, or
|
|
786
|
-
* as a failed job when the balance is positive but below the model's cost, so
|
|
787
|
-
* this one class covers both. `detail` holds the server's message.
|
|
788
|
-
*/
|
|
789
|
-
declare class InsufficientCredits extends SegmindError {
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Too many requests, after the SDK's own retries for calls that are safe to
|
|
793
|
-
* repeat. `retryAfterMs` is set when the server sent `Retry-After` and the
|
|
794
|
-
* runtime could read it: a browser only sees the header if the server exposes it.
|
|
795
|
-
*/
|
|
796
|
-
declare class RateLimited extends SegmindError {
|
|
797
|
-
readonly retryAfterMs: number | undefined;
|
|
798
|
-
constructor(message: string, options?: SegmindErrorOptions & {
|
|
799
|
-
retryAfterMs?: number;
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
/** A v2 request reached `FAILED`. The server's error text is in `detail`. */
|
|
803
|
-
declare class InferenceFailed extends SegmindError {
|
|
804
|
-
/** The status body that reported the failure. */
|
|
805
|
-
readonly statusBody: Record<string, unknown>;
|
|
806
|
-
constructor(requestId: string, statusBody: Record<string, unknown>, detail?: string);
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* `wait()` ran past its timeout. The request may still finish on the server:
|
|
810
|
-
* `job.status()` or a new `wait()` picks it up again.
|
|
811
|
-
*/
|
|
812
|
-
declare class InferenceTimeout extends SegmindError {
|
|
813
|
-
readonly elapsedMs: number;
|
|
814
|
-
constructor(requestId: string, elapsedMs: number);
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
declare const VERSION = "0.5.1";
|
|
796
|
+
declare const VERSION = "0.6.0";
|
|
818
797
|
|
|
819
798
|
/** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
|
|
820
799
|
declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
|
|
@@ -850,5 +829,5 @@ declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'lo
|
|
|
850
829
|
/** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
|
|
851
830
|
declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
|
|
852
831
|
|
|
853
|
-
export {
|
|
854
|
-
export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
|
|
832
|
+
export { Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, Job, Models, PixelFlows, PixelflowJob, Realtime, Segmind, SessionToken, SessionTokenProvider, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, webhooks };
|
|
833
|
+
export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, CreateSessionTokenOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { S as SessionToken, a as SessionTokenProvider } from './errors-CcHEuSmR.js';
|
|
2
|
+
export { A as APIConnectionError, I as InferenceFailed, b as InferenceTimeout, c as InsufficientCredits, R as RateLimited, d as SegmindError } from './errors-CcHEuSmR.js';
|
|
3
|
+
|
|
1
4
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
2
5
|
/** Returns the signed-in user's token, or null when there is none. Called before every request. */
|
|
3
6
|
type TokenProvider = () => string | null | undefined | Promise<string | null | undefined>;
|
|
@@ -435,6 +438,37 @@ declare class PixelflowJob {
|
|
|
435
438
|
wait(options?: PixelflowWaitOptions): Promise<PixelflowStatus>;
|
|
436
439
|
}
|
|
437
440
|
|
|
441
|
+
interface CreateSessionTokenOptions {
|
|
442
|
+
/** The session model the token opens, and the only one. */
|
|
443
|
+
slug: string;
|
|
444
|
+
/** The most the session may spend, in credits: above 0, at most 100. The gateway's default applies when omitted. */
|
|
445
|
+
creditCeiling?: number;
|
|
446
|
+
/** Seconds the token can be used to open a session, at most 120. A session outlives its token. */
|
|
447
|
+
ttl?: number;
|
|
448
|
+
/** What the session is recorded as. Default `SDK-JS`; pass `SDK-RN` for a phone app's sessions. */
|
|
449
|
+
initiator?: Initiator;
|
|
450
|
+
signal?: AbortSignal;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Session tokens for realtime models. A token is minted on a server with the
|
|
454
|
+
* API key, opens one session of one model, and caps what that session may
|
|
455
|
+
* spend, so it is safe to hand to a browser or a phone app.
|
|
456
|
+
*/
|
|
457
|
+
declare class Realtime {
|
|
458
|
+
private readonly client;
|
|
459
|
+
constructor(client: Segmind);
|
|
460
|
+
/**
|
|
461
|
+
* Mints a session token. Serve it from your backend to the app that opens
|
|
462
|
+
* the session with `connect()` from `segmind/realtime`.
|
|
463
|
+
*/
|
|
464
|
+
createToken(options: CreateSessionTokenOptions): Promise<SessionToken>;
|
|
465
|
+
/**
|
|
466
|
+
* A `tokenProvider` that mints with this client's key, for opening sessions
|
|
467
|
+
* from a server: `connect(slug, { tokenProvider: segmind.realtime.tokenProvider() })`.
|
|
468
|
+
*/
|
|
469
|
+
tokenProvider(options?: Omit<CreateSessionTokenOptions, 'slug' | 'signal'>): SessionTokenProvider;
|
|
470
|
+
}
|
|
471
|
+
|
|
438
472
|
/**
|
|
439
473
|
* What a registration subscribes to. `PIXELFLOW` covers PixelFlow runs; the
|
|
440
474
|
* others are the platform's remaining subscription types.
|
|
@@ -595,6 +629,8 @@ declare class Segmind {
|
|
|
595
629
|
readonly webhooks: Webhooks;
|
|
596
630
|
/** Run published PixelFlow workflows. */
|
|
597
631
|
readonly pixelflows: PixelFlows;
|
|
632
|
+
/** Session tokens for realtime models. The sessions themselves open from `segmind/realtime`. */
|
|
633
|
+
readonly realtime: Realtime;
|
|
598
634
|
/** @internal */
|
|
599
635
|
readonly http: HttpClient;
|
|
600
636
|
constructor(options?: ClientOptions);
|
|
@@ -757,64 +793,7 @@ declare function imageUrl(input: ImageInput, options?: {
|
|
|
757
793
|
mimeType?: string;
|
|
758
794
|
}): Promise<ImageUrlPart>;
|
|
759
795
|
|
|
760
|
-
|
|
761
|
-
status?: number;
|
|
762
|
-
detail?: string;
|
|
763
|
-
requestId?: string;
|
|
764
|
-
body?: unknown;
|
|
765
|
-
cause?: unknown;
|
|
766
|
-
}
|
|
767
|
-
/** Base class of every error the SDK throws (except an `AbortSignal`'s own reason). */
|
|
768
|
-
declare class SegmindError extends Error {
|
|
769
|
-
/** HTTP status, when the error came from a response. */
|
|
770
|
-
readonly status: number | undefined;
|
|
771
|
-
/** The server's error text (`error` in the response body), when it sent one. */
|
|
772
|
-
readonly detail: string | undefined;
|
|
773
|
-
/** The v2 request id the error belongs to, when there is one. */
|
|
774
|
-
readonly requestId: string | undefined;
|
|
775
|
-
/** The parsed response body, or its text when it was not JSON. */
|
|
776
|
-
readonly body: unknown;
|
|
777
|
-
constructor(message: string, options?: SegmindErrorOptions);
|
|
778
|
-
/** Reads the response body and builds the error. Consumes the body. */
|
|
779
|
-
static fromResponse(response: Response, requestId?: string): Promise<SegmindError>;
|
|
780
|
-
}
|
|
781
|
-
/** The request never got a response: DNS, TLS, connection reset, or the client's timeout. */
|
|
782
|
-
declare class APIConnectionError extends SegmindError {
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* The account cannot pay for the request. The gateway reports this at submit, or
|
|
786
|
-
* as a failed job when the balance is positive but below the model's cost, so
|
|
787
|
-
* this one class covers both. `detail` holds the server's message.
|
|
788
|
-
*/
|
|
789
|
-
declare class InsufficientCredits extends SegmindError {
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Too many requests, after the SDK's own retries for calls that are safe to
|
|
793
|
-
* repeat. `retryAfterMs` is set when the server sent `Retry-After` and the
|
|
794
|
-
* runtime could read it: a browser only sees the header if the server exposes it.
|
|
795
|
-
*/
|
|
796
|
-
declare class RateLimited extends SegmindError {
|
|
797
|
-
readonly retryAfterMs: number | undefined;
|
|
798
|
-
constructor(message: string, options?: SegmindErrorOptions & {
|
|
799
|
-
retryAfterMs?: number;
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
/** A v2 request reached `FAILED`. The server's error text is in `detail`. */
|
|
803
|
-
declare class InferenceFailed extends SegmindError {
|
|
804
|
-
/** The status body that reported the failure. */
|
|
805
|
-
readonly statusBody: Record<string, unknown>;
|
|
806
|
-
constructor(requestId: string, statusBody: Record<string, unknown>, detail?: string);
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* `wait()` ran past its timeout. The request may still finish on the server:
|
|
810
|
-
* `job.status()` or a new `wait()` picks it up again.
|
|
811
|
-
*/
|
|
812
|
-
declare class InferenceTimeout extends SegmindError {
|
|
813
|
-
readonly elapsedMs: number;
|
|
814
|
-
constructor(requestId: string, elapsedMs: number);
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
declare const VERSION = "0.5.1";
|
|
796
|
+
declare const VERSION = "0.6.0";
|
|
818
797
|
|
|
819
798
|
/** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
|
|
820
799
|
declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
|
|
@@ -850,5 +829,5 @@ declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'lo
|
|
|
850
829
|
/** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
|
|
851
830
|
declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
|
|
852
831
|
|
|
853
|
-
export {
|
|
854
|
-
export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
|
|
832
|
+
export { Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, Job, Models, PixelFlows, PixelflowJob, Realtime, Segmind, SessionToken, SessionTokenProvider, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, webhooks };
|
|
833
|
+
export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, CreateSessionTokenOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
|
package/dist/index.js
CHANGED
|
@@ -1,106 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(message, options = {}) {
|
|
12
|
-
super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
13
|
-
this.name = new.target.name;
|
|
14
|
-
this.status = options.status;
|
|
15
|
-
this.detail = options.detail;
|
|
16
|
-
this.requestId = options.requestId;
|
|
17
|
-
this.body = options.body;
|
|
18
|
-
}
|
|
19
|
-
/** Reads the response body and builds the error. Consumes the body. */
|
|
20
|
-
static fromResponse(response, requestId) {
|
|
21
|
-
return errorFromResponse(response, requestId);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var APIConnectionError = class extends SegmindError {
|
|
25
|
-
};
|
|
26
|
-
var InsufficientCredits = class extends SegmindError {
|
|
27
|
-
};
|
|
28
|
-
var RateLimited = class extends SegmindError {
|
|
29
|
-
retryAfterMs;
|
|
30
|
-
constructor(message, options = {}) {
|
|
31
|
-
super(message, options);
|
|
32
|
-
this.retryAfterMs = options.retryAfterMs;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var InferenceFailed = class extends SegmindError {
|
|
36
|
-
/** The status body that reported the failure. */
|
|
37
|
-
statusBody;
|
|
38
|
-
constructor(requestId, statusBody, detail) {
|
|
39
|
-
detail ??= typeof statusBody.error === "string" ? statusBody.error : void 0;
|
|
40
|
-
super(detail ? `request ${requestId} failed: ${detail}` : `request ${requestId} failed`, {
|
|
41
|
-
detail,
|
|
42
|
-
requestId,
|
|
43
|
-
body: statusBody
|
|
44
|
-
});
|
|
45
|
-
this.statusBody = statusBody;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var InferenceTimeout = class extends SegmindError {
|
|
49
|
-
elapsedMs;
|
|
50
|
-
constructor(requestId, elapsedMs) {
|
|
51
|
-
super(`request ${requestId} did not finish within ${Math.round(elapsedMs)} ms`, { requestId });
|
|
52
|
-
this.elapsedMs = elapsedMs;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
async function errorFromResponse(response, requestId) {
|
|
56
|
-
const text = await response.text().catch(() => "");
|
|
57
|
-
let body = text;
|
|
58
|
-
try {
|
|
59
|
-
body = text ? JSON.parse(text) : void 0;
|
|
60
|
-
} catch {
|
|
61
|
-
}
|
|
62
|
-
const detail = errorDetail(body) ?? plainText(body);
|
|
63
|
-
const message = detail ? `${response.status} ${detail}` : `${response.status} ${response.statusText || "request failed"}`;
|
|
64
|
-
const options = { status: response.status, detail, requestId, body };
|
|
65
|
-
if (response.status === 429) {
|
|
66
|
-
return new RateLimited(message, { ...options, retryAfterMs: parseRetryAfter(response.headers.get("retry-after")) });
|
|
67
|
-
}
|
|
68
|
-
if (response.status === 402 || isOutOfCredits(detail)) return new InsufficientCredits(message, options);
|
|
69
|
-
return new SegmindError(message, options);
|
|
70
|
-
}
|
|
71
|
-
function requestFailure(requestId, statusBody, detail) {
|
|
72
|
-
detail ??= typeof statusBody.error === "string" ? statusBody.error : void 0;
|
|
73
|
-
if (isOutOfCredits(detail)) {
|
|
74
|
-
return new InsufficientCredits(`request ${requestId} failed: ${detail}`, { detail, requestId, body: statusBody });
|
|
75
|
-
}
|
|
76
|
-
return new InferenceFailed(requestId, statusBody, detail);
|
|
77
|
-
}
|
|
78
|
-
function parseRetryAfter(value, now = Date.now()) {
|
|
79
|
-
if (!value) return void 0;
|
|
80
|
-
const seconds = Number(value);
|
|
81
|
-
if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
|
|
82
|
-
const date = Date.parse(value);
|
|
83
|
-
return Number.isNaN(date) ? void 0 : Math.max(date - now, 0);
|
|
84
|
-
}
|
|
85
|
-
function isOutOfCredits(detail) {
|
|
86
|
-
return detail?.startsWith("Insufficient credits.") ?? false;
|
|
87
|
-
}
|
|
88
|
-
function plainText(body) {
|
|
89
|
-
if (typeof body !== "string" || !body || body.trimStart().startsWith("<")) return void 0;
|
|
90
|
-
return body.slice(0, 500);
|
|
91
|
-
}
|
|
92
|
-
function errorDetail(body) {
|
|
93
|
-
if (!body || typeof body !== "object") return void 0;
|
|
94
|
-
const record2 = body;
|
|
95
|
-
for (const key of ["error", "message", "detail"]) {
|
|
96
|
-
const value = record2[key];
|
|
97
|
-
if (typeof value === "string" && value) return value;
|
|
98
|
-
if (value && typeof value === "object" && typeof value.message === "string") {
|
|
99
|
-
return value.message;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return void 0;
|
|
103
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
APIConnectionError,
|
|
3
|
+
InferenceFailed,
|
|
4
|
+
InferenceTimeout,
|
|
5
|
+
InsufficientCredits,
|
|
6
|
+
RateLimited,
|
|
7
|
+
SegmindError,
|
|
8
|
+
parseRetryAfter,
|
|
9
|
+
requestFailure
|
|
10
|
+
} from "./chunk-PS5KUT7P.js";
|
|
104
11
|
|
|
105
12
|
// src/chat.ts
|
|
106
13
|
var ChatResponse = class {
|
|
@@ -818,8 +725,40 @@ function failureDetail(body) {
|
|
|
818
725
|
return void 0;
|
|
819
726
|
}
|
|
820
727
|
|
|
728
|
+
// src/realtime-tokens.ts
|
|
729
|
+
var Realtime = class {
|
|
730
|
+
constructor(client2) {
|
|
731
|
+
this.client = client2;
|
|
732
|
+
}
|
|
733
|
+
client;
|
|
734
|
+
/**
|
|
735
|
+
* Mints a session token. Serve it from your backend to the app that opens
|
|
736
|
+
* the session with `connect()` from `segmind/realtime`.
|
|
737
|
+
*/
|
|
738
|
+
async createToken(options) {
|
|
739
|
+
const body = { slug: options.slug };
|
|
740
|
+
if (options.creditCeiling !== void 0) body.credit_ceiling = options.creditCeiling;
|
|
741
|
+
if (options.ttl !== void 0) body.ttl = options.ttl;
|
|
742
|
+
return this.client.http.json({
|
|
743
|
+
method: "POST",
|
|
744
|
+
url: `${this.client.baseURL}/v1/realtime/token`,
|
|
745
|
+
body,
|
|
746
|
+
headers: options.initiator ? { "X-Initiator": options.initiator } : void 0,
|
|
747
|
+
signal: options.signal,
|
|
748
|
+
retry: true
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* A `tokenProvider` that mints with this client's key, for opening sessions
|
|
753
|
+
* from a server: `connect(slug, { tokenProvider: segmind.realtime.tokenProvider() })`.
|
|
754
|
+
*/
|
|
755
|
+
tokenProvider(options = {}) {
|
|
756
|
+
return (slug) => this.createToken({ ...options, slug });
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
|
|
821
760
|
// src/version.ts
|
|
822
|
-
var VERSION = "0.
|
|
761
|
+
var VERSION = "0.6.0";
|
|
823
762
|
|
|
824
763
|
// src/webhooks.ts
|
|
825
764
|
var Webhooks = class {
|
|
@@ -910,6 +849,8 @@ var Segmind = class {
|
|
|
910
849
|
webhooks;
|
|
911
850
|
/** Run published PixelFlow workflows. */
|
|
912
851
|
pixelflows;
|
|
852
|
+
/** Session tokens for realtime models. The sessions themselves open from `segmind/realtime`. */
|
|
853
|
+
realtime;
|
|
913
854
|
/** @internal */
|
|
914
855
|
http;
|
|
915
856
|
constructor(options = {}) {
|
|
@@ -954,6 +895,7 @@ var Segmind = class {
|
|
|
954
895
|
this.generations = new Generations(this);
|
|
955
896
|
this.webhooks = new Webhooks(this);
|
|
956
897
|
this.pixelflows = new PixelFlows(this);
|
|
898
|
+
this.realtime = new Realtime(this);
|
|
957
899
|
}
|
|
958
900
|
/**
|
|
959
901
|
* Runs a model and returns its result: submits to the v2 queue, then polls
|
|
@@ -1248,6 +1190,7 @@ export {
|
|
|
1248
1190
|
PixelFlows,
|
|
1249
1191
|
PixelflowJob,
|
|
1250
1192
|
RateLimited,
|
|
1193
|
+
Realtime,
|
|
1251
1194
|
Segmind,
|
|
1252
1195
|
SegmindError,
|
|
1253
1196
|
VERSION,
|