@decartai/sdk 0.0.50 → 0.0.52
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.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LogLevel, Logger, createConsoleLogger, noopLogger } from "./utils/logger.js";
|
|
2
|
-
import { ImageModelDefinition, ImageModels, Model, ModelDefinition, RealTimeModels, VideoModelDefinition, VideoModels, isImageModel, isRealtimeModel, isVideoModel, models } from "./shared/model.js";
|
|
2
|
+
import { CustomModelDefinition, ImageModelDefinition, ImageModels, Model, ModelDefinition, RealTimeModels, VideoModelDefinition, VideoModels, isImageModel, isRealtimeModel, isVideoModel, models } from "./shared/model.js";
|
|
3
3
|
import { FileInput, ProcessOptions, ReactNativeFile } from "./process/types.js";
|
|
4
4
|
import { ProcessClient } from "./process/client.js";
|
|
5
5
|
import { JobStatus, JobStatusResponse, JobSubmitResponse, QueueJobResult, QueueSubmitAndPollOptions, QueueSubmitOptions } from "./queue/types.js";
|
|
@@ -19,6 +19,7 @@ type DecartClientOptions = {
|
|
|
19
19
|
proxy: string;
|
|
20
20
|
apiKey?: never;
|
|
21
21
|
baseUrl?: string;
|
|
22
|
+
realtimeBaseUrl?: string;
|
|
22
23
|
integration?: string;
|
|
23
24
|
logger?: Logger;
|
|
24
25
|
telemetry?: boolean;
|
|
@@ -26,6 +27,7 @@ type DecartClientOptions = {
|
|
|
26
27
|
proxy?: never;
|
|
27
28
|
apiKey?: string;
|
|
28
29
|
baseUrl?: string;
|
|
30
|
+
realtimeBaseUrl?: string;
|
|
29
31
|
integration?: string;
|
|
30
32
|
logger?: Logger;
|
|
31
33
|
telemetry?: boolean;
|
|
@@ -37,6 +39,7 @@ type DecartClientOptions = {
|
|
|
37
39
|
* @param options.proxy - URL of the proxy server. When set, the client will use the proxy instead of direct API access and apiKey is not required.
|
|
38
40
|
* @param options.apiKey - API key for authentication.
|
|
39
41
|
* @param options.baseUrl - Override the default API base URL.
|
|
42
|
+
* @param options.realtimeBaseUrl - Override the default WebSocket base URL for realtime connections.
|
|
40
43
|
* @param options.integration - Optional integration identifier.
|
|
41
44
|
*
|
|
42
45
|
* @example
|
|
@@ -128,4 +131,4 @@ declare const createDecartClient: (options?: DecartClientOptions) => {
|
|
|
128
131
|
tokens: TokensClient;
|
|
129
132
|
};
|
|
130
133
|
//#endregion
|
|
131
|
-
export { type ConnectionPhase, type ConnectionState, type CreateTokenOptions, type CreateTokenResponse, DecartClientOptions, type DecartSDKError, type DiagnosticEvent, type DiagnosticEventName, type DiagnosticEvents, ERROR_CODES, type FileInput, type IceCandidateEvent, type IceStateEvent, type ImageModelDefinition, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type LogLevel, type Logger, type Model, type ModelDefinition, type ModelState, type PeerConnectionStateEvent, type PhaseTimingEvent, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type ReactNativeFile, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type Events as RealTimeEvents, type RealTimeModels, type RealTimeSubscribeClient, type ReconnectEvent, type SelectedCandidatePairEvent, type SetInput, type SignalingStateEvent, type SubscribeEvents, type SubscribeOptions, type TokensClient, type VideoModelDefinition, type VideoModels, type VideoStallEvent, type WebRTCStats, createConsoleLogger, createDecartClient, isImageModel, isRealtimeModel, isVideoModel, models, noopLogger };
|
|
134
|
+
export { type ConnectionPhase, type ConnectionState, type CreateTokenOptions, type CreateTokenResponse, type CustomModelDefinition, DecartClientOptions, type DecartSDKError, type DiagnosticEvent, type DiagnosticEventName, type DiagnosticEvents, ERROR_CODES, type FileInput, type IceCandidateEvent, type IceStateEvent, type ImageModelDefinition, type ImageModels, type JobStatus, type JobStatusResponse, type JobSubmitResponse, type LogLevel, type Logger, type Model, type ModelDefinition, type ModelState, type PeerConnectionStateEvent, type PhaseTimingEvent, type ProcessClient, type ProcessOptions, type QueueClient, type QueueJobResult, type QueueSubmitAndPollOptions, type QueueSubmitOptions, type ReactNativeFile, type RealTimeClient, type RealTimeClientConnectOptions, type RealTimeClientInitialState, type Events as RealTimeEvents, type RealTimeModels, type RealTimeSubscribeClient, type ReconnectEvent, type SelectedCandidatePairEvent, type SetInput, type SignalingStateEvent, type SubscribeEvents, type SubscribeOptions, type TokensClient, type VideoModelDefinition, type VideoModels, type VideoStallEvent, type WebRTCStats, createConsoleLogger, createDecartClient, isImageModel, isRealtimeModel, isVideoModel, models, noopLogger };
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,8 @@ const decartClientOptionsSchema = z.object({
|
|
|
14
14
|
apiKey: z.string().min(1).optional(),
|
|
15
15
|
baseUrl: z.url().optional(),
|
|
16
16
|
proxy: proxySchema.optional(),
|
|
17
|
-
integration: z.string().optional()
|
|
17
|
+
integration: z.string().optional(),
|
|
18
|
+
realtimeBaseUrl: z.url().optional()
|
|
18
19
|
}).refine((data) => {
|
|
19
20
|
const hasProxy = !!data.proxy;
|
|
20
21
|
const hasApiKey = !!data.apiKey;
|
|
@@ -27,6 +28,7 @@ const decartClientOptionsSchema = z.object({
|
|
|
27
28
|
* @param options.proxy - URL of the proxy server. When set, the client will use the proxy instead of direct API access and apiKey is not required.
|
|
28
29
|
* @param options.apiKey - API key for authentication.
|
|
29
30
|
* @param options.baseUrl - Override the default API base URL.
|
|
31
|
+
* @param options.realtimeBaseUrl - Override the default WebSocket base URL for realtime connections.
|
|
30
32
|
* @param options.integration - Optional integration identifier.
|
|
31
33
|
*
|
|
32
34
|
* @example
|
|
@@ -46,7 +48,7 @@ const createDecartClient = (options = {}) => {
|
|
|
46
48
|
if (!parsedOptions.success) {
|
|
47
49
|
const issue = parsedOptions.error.issues[0];
|
|
48
50
|
if (issue.path.includes("apiKey")) throw createInvalidApiKeyError();
|
|
49
|
-
if (issue.path.includes("baseUrl")) throw createInvalidBaseUrlError(issue.path.includes("
|
|
51
|
+
if (issue.path.includes("baseUrl") || issue.path.includes("realtimeBaseUrl")) throw createInvalidBaseUrlError(options[issue.path.includes("realtimeBaseUrl") ? "realtimeBaseUrl" : "baseUrl"]);
|
|
50
52
|
if (issue.path.includes("proxy")) throw createInvalidBaseUrlError(issue.path.includes("proxy") ? options.proxy : void 0);
|
|
51
53
|
throw parsedOptions.error;
|
|
52
54
|
}
|
|
@@ -61,7 +63,7 @@ const createDecartClient = (options = {}) => {
|
|
|
61
63
|
const telemetryEnabled = "telemetry" in options && options.telemetry === false ? false : true;
|
|
62
64
|
return {
|
|
63
65
|
realtime: createRealTimeClient({
|
|
64
|
-
baseUrl: "wss://api3.decart.ai",
|
|
66
|
+
baseUrl: parsedOptions.data.realtimeBaseUrl || "wss://api3.decart.ai",
|
|
65
67
|
apiKey: apiKey || "",
|
|
66
68
|
integration,
|
|
67
69
|
logger,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CustomModelDefinition, ModelDefinition } from "../shared/model.js";
|
|
1
2
|
import { DecartSDKError } from "../utils/errors.js";
|
|
2
3
|
import { DiagnosticEvent } from "./diagnostics.js";
|
|
3
4
|
import { ConnectionState } from "./types.js";
|
|
@@ -18,7 +19,7 @@ type OnRemoteStreamFn = (stream: MediaStream) => void;
|
|
|
18
19
|
type RealTimeClientInitialState = z.infer<typeof realTimeClientInitialStateSchema>;
|
|
19
20
|
declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
|
|
20
21
|
model: z.ZodObject<{
|
|
21
|
-
name: z.
|
|
22
|
+
name: z.ZodString;
|
|
22
23
|
urlPath: z.ZodString;
|
|
23
24
|
queueUrlPath: z.ZodOptional<z.ZodString>;
|
|
24
25
|
fps: z.ZodNumber;
|
|
@@ -36,7 +37,9 @@ declare const realTimeClientConnectOptionsSchema: z.ZodObject<{
|
|
|
36
37
|
}, z.core.$strip>>;
|
|
37
38
|
customizeOffer: z.ZodOptional<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>, z.core.$InferInnerFunctionTypeAsync<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>>>;
|
|
38
39
|
}, z.core.$strip>;
|
|
39
|
-
type RealTimeClientConnectOptions = z.infer<typeof realTimeClientConnectOptionsSchema
|
|
40
|
+
type RealTimeClientConnectOptions = Omit<z.infer<typeof realTimeClientConnectOptionsSchema>, "model"> & {
|
|
41
|
+
model: ModelDefinition | CustomModelDefinition;
|
|
42
|
+
};
|
|
40
43
|
type Events = {
|
|
41
44
|
connectionChange: ConnectionState;
|
|
42
45
|
error: DecartSDKError;
|
|
@@ -98,6 +98,14 @@ var WebRTCConnection = class {
|
|
|
98
98
|
durationMs: performance.now() - promptStart,
|
|
99
99
|
success: true
|
|
100
100
|
});
|
|
101
|
+
} else if (localStream) {
|
|
102
|
+
const nullStart = performance.now();
|
|
103
|
+
await Promise.race([this.setImageBase64(null, { prompt: null }), connectAbort]);
|
|
104
|
+
this.emitDiagnostic("phaseTiming", {
|
|
105
|
+
phase: "initial-prompt",
|
|
106
|
+
durationMs: performance.now() - nullStart,
|
|
107
|
+
success: true
|
|
108
|
+
});
|
|
101
109
|
}
|
|
102
110
|
const handshakeStart = performance.now();
|
|
103
111
|
await this.setupNewPeerConnection();
|
package/dist/shared/model.d.ts
CHANGED
|
@@ -154,6 +154,14 @@ type ModelDefinition<T extends Model = Model> = {
|
|
|
154
154
|
height: number;
|
|
155
155
|
inputSchema: T extends keyof ModelInputSchemas ? ModelInputSchemas[T] : z.ZodTypeAny;
|
|
156
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* A model definition with an arbitrary (non-registry) model name.
|
|
159
|
+
* Use this when providing your own model configuration.
|
|
160
|
+
*/
|
|
161
|
+
type CustomModelDefinition = Omit<ModelDefinition, "name" | "inputSchema"> & {
|
|
162
|
+
name: string;
|
|
163
|
+
inputSchema?: z.ZodTypeAny;
|
|
164
|
+
};
|
|
157
165
|
/**
|
|
158
166
|
* Type alias for model definitions that support synchronous processing.
|
|
159
167
|
* Only image models support the sync/process API.
|
|
@@ -189,4 +197,4 @@ declare const models: {
|
|
|
189
197
|
image: <T extends ImageModels>(model: T) => ModelDefinition<T>;
|
|
190
198
|
};
|
|
191
199
|
//#endregion
|
|
192
|
-
export { ImageModelDefinition, ImageModels, Model, ModelDefinition, ModelInputSchemas, RealTimeModels, VideoModelDefinition, VideoModels, isImageModel, isRealtimeModel, isVideoModel, models };
|
|
200
|
+
export { CustomModelDefinition, ImageModelDefinition, ImageModels, Model, ModelDefinition, ModelInputSchemas, RealTimeModels, VideoModelDefinition, VideoModels, isImageModel, isRealtimeModel, isVideoModel, models };
|
package/dist/shared/model.js
CHANGED
|
@@ -139,7 +139,7 @@ const modelInputSchemas = {
|
|
|
139
139
|
}).refine((data) => data.prompt !== void 0 !== (data.reference_image !== void 0), { message: "Must provide either 'prompt' or 'reference_image', but not both" }).refine((data) => !(data.reference_image !== void 0 && data.enhance_prompt !== void 0), { message: "'enhance_prompt' is only valid when using 'prompt', not 'reference_image'" })
|
|
140
140
|
};
|
|
141
141
|
const modelDefinitionSchema = z.object({
|
|
142
|
-
name:
|
|
142
|
+
name: z.string(),
|
|
143
143
|
urlPath: z.string(),
|
|
144
144
|
queueUrlPath: z.string().optional(),
|
|
145
145
|
fps: z.number().min(1),
|