@decartai/sdk 0.0.6 → 0.0.11

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
@@ -10,6 +10,7 @@ import { z } from "zod";
10
10
  declare const decartClientOptionsSchema: z.ZodObject<{
11
11
  apiKey: z.ZodString;
12
12
  baseUrl: z.ZodOptional<z.ZodURL>;
13
+ integration: z.ZodOptional<z.ZodString>;
13
14
  }, z.core.$strip>;
14
15
  type DecartClientOptions = z.infer<typeof decartClientOptionsSchema>;
15
16
  declare const createDecartClient: (options: DecartClientOptions) => {
package/dist/index.js CHANGED
@@ -7,7 +7,8 @@ import { z } from "zod";
7
7
  //#region src/index.ts
8
8
  const decartClientOptionsSchema = z.object({
9
9
  apiKey: z.string().min(1),
10
- baseUrl: z.url().optional()
10
+ baseUrl: z.url().optional(),
11
+ integration: z.string().optional()
11
12
  });
12
13
  const createDecartClient = (options) => {
13
14
  const parsedOptions = decartClientOptionsSchema.safeParse(options);
@@ -17,14 +18,16 @@ const createDecartClient = (options) => {
17
18
  if (issue.path.includes("baseUrl")) throw createInvalidBaseUrlError(options.baseUrl);
18
19
  throw parsedOptions.error;
19
20
  }
20
- const { baseUrl = "https://api.decart.ai", apiKey } = parsedOptions.data;
21
+ const { baseUrl = "https://api.decart.ai", apiKey, integration } = parsedOptions.data;
21
22
  const realtime = createRealTimeClient({
22
23
  baseUrl: "wss://api3.decart.ai",
23
- apiKey
24
+ apiKey,
25
+ integration
24
26
  });
25
27
  const process = createProcessClient({
26
28
  baseUrl,
27
- apiKey
29
+ apiKey,
30
+ integration
28
31
  });
29
32
  return {
30
33
  realtime,
@@ -3,7 +3,7 @@ import { fileInputToBlob, sendRequest } from "./request.js";
3
3
 
4
4
  //#region src/process/client.ts
5
5
  const createProcessClient = (opts) => {
6
- const { apiKey, baseUrl } = opts;
6
+ const { apiKey, baseUrl, integration } = opts;
7
7
  const _process = async (options) => {
8
8
  const { model, signal,...inputs } = options;
9
9
  const parsedInputs = model.inputSchema.safeParse(inputs);
@@ -16,7 +16,8 @@ const createProcessClient = (opts) => {
16
16
  apiKey,
17
17
  model,
18
18
  inputs: processedInputs,
19
- signal
19
+ signal,
20
+ integration
20
21
  });
21
22
  };
22
23
  return _process;
@@ -1,4 +1,5 @@
1
1
  import { createInvalidInputError, createSDKError } from "../utils/errors.js";
2
+ import { buildUserAgent } from "../utils/user-agent.js";
2
3
 
3
4
  //#region src/process/request.ts
4
5
  async function fileInputToBlob(input) {
@@ -13,14 +14,17 @@ async function fileInputToBlob(input) {
13
14
  }
14
15
  throw createInvalidInputError("Invalid file input type");
15
16
  }
16
- async function sendRequest({ baseUrl, apiKey, model, inputs, signal }) {
17
+ async function sendRequest({ baseUrl, apiKey, model, inputs, signal, integration }) {
17
18
  const formData = new FormData();
18
19
  for (const [key, value] of Object.entries(inputs)) if (value !== void 0 && value !== null) if (value instanceof Blob) formData.append(key, value);
19
20
  else formData.append(key, String(value));
20
21
  const endpoint = `${baseUrl}${model.urlPath}`;
21
22
  const response = await fetch(endpoint, {
22
23
  method: "POST",
23
- headers: { "X-API-KEY": apiKey },
24
+ headers: {
25
+ "X-API-KEY": apiKey,
26
+ "User-Agent": buildUserAgent(integration)
27
+ },
24
28
  body: formData,
25
29
  signal
26
30
  });
@@ -17,7 +17,7 @@ const realTimeClientConnectOptionsSchema = z.object({
17
17
  customizeOffer: createAsyncFunctionSchema(z.function()).optional()
18
18
  });
19
19
  const createRealTimeClient = (opts) => {
20
- const { baseUrl, apiKey } = opts;
20
+ const { baseUrl, apiKey, integration } = opts;
21
21
  const connect = async (stream, options) => {
22
22
  const eventEmitter = mitt();
23
23
  const parsedOptions = realTimeClientConnectOptionsSchema.safeParse(options);
@@ -31,6 +31,7 @@ const createRealTimeClient = (opts) => {
31
31
  sessionId,
32
32
  fps: options.model.fps,
33
33
  initialState,
34
+ integration,
34
35
  onRemoteStream,
35
36
  onConnectionStateChange: (state) => {
36
37
  eventEmitter.emit("connectionChange", state);
@@ -1,3 +1,5 @@
1
+ import { buildUserAgent } from "../utils/user-agent.js";
2
+
1
3
  //#region src/realtime/webrtc-connection.ts
2
4
  const ICE_SERVERS = [{ urls: "stun:stun.l.google.com:19302" }];
3
5
  var WebRTCConnection = class {
@@ -9,13 +11,16 @@ var WebRTCConnection = class {
9
11
  constructor(callbacks = {}) {
10
12
  this.callbacks = callbacks;
11
13
  }
12
- async connect(url, localStream, timeout = 25e3) {
14
+ async connect(url, localStream, timeout = 25e3, integration) {
13
15
  const deadline = Date.now() + timeout;
14
16
  this.localStream = localStream;
17
+ const userAgent = encodeURIComponent(buildUserAgent(integration));
18
+ const separator = url.includes("?") ? "&" : "?";
19
+ const wsUrl = `${url}${separator}user_agent=${userAgent}`;
15
20
  await new Promise((resolve, reject) => {
16
21
  this.connectionReject = reject;
17
22
  const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("WebSocket timeout")), timeout);
18
- this.ws = new WebSocket(url);
23
+ this.ws = new WebSocket(wsUrl);
19
24
  this.ws.onopen = () => {
20
25
  clearTimeout(timer);
21
26
  resolve();
@@ -24,7 +24,7 @@ var WebRTCManager = class {
24
24
  }
25
25
  async connect(localStream) {
26
26
  return pRetry(async () => {
27
- await this.connection.connect(this.config.webrtcUrl, localStream);
27
+ await this.connection.connect(this.config.webrtcUrl, localStream, 25e3, this.config.integration);
28
28
  return true;
29
29
  }, {
30
30
  retries: 5,
@@ -104,7 +104,7 @@ const _models = {
104
104
  mirage_v2: {
105
105
  urlPath: "/v1/stream",
106
106
  name: "mirage_v2",
107
- fps: 12,
107
+ fps: 18,
108
108
  width: 1280,
109
109
  height: 704,
110
110
  inputSchema: z.object({})
@@ -0,0 +1,32 @@
1
+ import { VERSION } from "../version.js";
2
+
3
+ //#region src/utils/user-agent.ts
4
+ function getRuntimeEnvironment(globalThisAny = globalThis) {
5
+ if (globalThisAny.window) return "runtime/browser";
6
+ if (globalThisAny.navigator?.userAgent) return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
7
+ if (globalThisAny.process?.versions?.node) return `runtime/node.js/${globalThisAny.process.version.substring(0)}`;
8
+ if (globalThisAny.EdgeRuntime) return "runtime/vercel-edge";
9
+ return "runtime/unknown";
10
+ }
11
+ /**
12
+ * Builds the User-Agent string for the SDK.
13
+ * Format: decart-js-sdk/{version} lang/js {integration} {runtime}
14
+ *
15
+ * @param integration - Optional integration identifier (e.g., "vercel-ai-sdk/3.0.0")
16
+ * @param globalThisAny - The global object (defaults to globalThis). Can be mocked for testing.
17
+ * @returns Complete User-Agent string
18
+ * @example
19
+ * buildUserAgent() // => "decart-js-sdk/0.0.7 lang/js runtime/node.js/v18.17.0"
20
+ * buildUserAgent("vercel-ai-sdk/3.0.0") // => "decart-js-sdk/0.0.7 lang/js vercel-ai-sdk/3.0.0 runtime/node.js/v18.17.0"
21
+ */
22
+ function buildUserAgent(integration, globalThisAny = globalThis) {
23
+ return [
24
+ `decart-js-sdk/${VERSION}`,
25
+ "lang/js",
26
+ ...integration ? [integration] : [],
27
+ getRuntimeEnvironment(globalThisAny)
28
+ ].join(" ");
29
+ }
30
+
31
+ //#endregion
32
+ export { buildUserAgent };
@@ -0,0 +1,10 @@
1
+ //#region src/version.ts
2
+ /**
3
+ * The current version of the Decart SDK.
4
+ * Injected at build time from package.json.
5
+ * Falls back to '0.0.0-dev' in development.
6
+ */
7
+ const VERSION = "0.0.11";
8
+
9
+ //#endregion
10
+ export { VERSION };
package/package.json CHANGED
@@ -1,61 +1,60 @@
1
1
  {
2
- "name": "@decartai/sdk",
3
- "version": "0.0.6",
4
- "description": "Decart's JavaScript SDK",
5
- "type": "module",
6
- "license": "MIT",
7
- "private": false,
8
- "homepage": "https://github.com/decartai/sdk#readme",
9
- "bugs": {
10
- "url": "https://github.com/decartai/sdk/issues"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/decartai/sdk.git"
15
- },
16
- "author": "Adir Amsalem <adir@decart.ai>",
17
- "sideEffects": false,
18
- "files": [
19
- "dist"
20
- ],
21
- "main": "./dist/index.js",
22
- "module": "./dist/index.js",
23
- "types": "./dist/index.d.ts",
24
- "exports": {
25
- ".": "./dist/index.js",
26
- "./package.json": "./package.json"
27
- },
28
- "publishConfig": {
29
- "access": "public"
30
- },
31
- "scripts": {
32
- "build": "tsdown",
33
- "dev": "tsdown --watch",
34
- "dev:example": "vite dev --port 3000",
35
- "test": "vitest unit",
36
- "test:e2e": "vitest e2e",
37
- "typecheck": "tsc --noEmit",
38
- "format": "biome format --write",
39
- "format:check": "biome check",
40
- "lint": "biome lint",
41
- "prepublishOnly": "pnpm build",
42
- "release": "bumpp && npm publish"
43
- },
44
- "devDependencies": {
45
- "@types/node": "^22.15.17",
46
- "biome": "^0.3.3",
47
- "bumpp": "^10.1.0",
48
- "msw": "^2.11.3",
49
- "pkg-pr-new": "^0.0.56",
50
- "tsdown": "^0.14.1",
51
- "typescript": "^5.8.3",
52
- "vite": "^7.1.2",
53
- "vitest": "^3.1.3"
54
- },
55
- "dependencies": {
56
- "mitt": "^3.0.1",
57
- "p-retry": "^6.2.1",
58
- "uuid": "^11.1.0",
59
- "zod": "^4.0.17"
60
- }
61
- }
2
+ "name": "@decartai/sdk",
3
+ "version": "0.0.11",
4
+ "description": "Decart's JavaScript SDK",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "homepage": "https://github.com/decartai/sdk#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/decartai/sdk/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/DecartAI/sdk"
15
+ },
16
+ "author": "Adir Amsalem <adir@decart.ai>",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "main": "./dist/index.js",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": "./dist/index.js",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^22.15.17",
33
+ "biome": "^0.3.3",
34
+ "bumpp": "^10.1.0",
35
+ "msw": "^2.11.3",
36
+ "pkg-pr-new": "^0.0.56",
37
+ "tsdown": "^0.14.1",
38
+ "typescript": "^5.8.3",
39
+ "vite": "^7.1.2",
40
+ "vitest": "^3.1.3"
41
+ },
42
+ "dependencies": {
43
+ "mitt": "^3.0.1",
44
+ "p-retry": "^6.2.1",
45
+ "uuid": "^11.1.0",
46
+ "zod": "^4.0.17"
47
+ },
48
+ "scripts": {
49
+ "build": "tsdown",
50
+ "dev": "tsdown --watch",
51
+ "dev:example": "vite dev --port 3000",
52
+ "test": "vitest unit",
53
+ "test:e2e": "vitest e2e",
54
+ "typecheck": "tsc --noEmit",
55
+ "format": "biome format --write",
56
+ "format:check": "biome check",
57
+ "lint": "biome lint",
58
+ "release": "bumpp"
59
+ }
60
+ }