@warlok-net/sdk 0.1.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.
@@ -0,0 +1,89 @@
1
+ import { AssetType, GenerationEntityType, GenerationV2, GenerationStage } from '@warlok-net/core';
2
+ export { AssetType, GenerationEntityType, GenerationStage, GenerationV2 } from '@warlok-net/core';
3
+
4
+ /**
5
+ * Warlok SDK - Node.js client for the Warlok generation API.
6
+ */
7
+
8
+ type LegacyGenerationType = AssetType | GenerationEntityType;
9
+ type Generation = GenerationV2;
10
+ type Asset = Generation;
11
+ interface GenerateParams {
12
+ name?: string;
13
+ entityType?: GenerationEntityType;
14
+ type?: LegacyGenerationType;
15
+ prompt?: string;
16
+ imageUrl?: string;
17
+ imageBase64?: string;
18
+ options?: {
19
+ rigForMixamo?: boolean;
20
+ includeTpose?: boolean;
21
+ optimize?: boolean;
22
+ autoRig?: boolean;
23
+ };
24
+ }
25
+ interface ListGenerationsOptions {
26
+ limit?: number;
27
+ status?: GenerationStage;
28
+ entityType?: GenerationEntityType;
29
+ type?: LegacyGenerationType;
30
+ }
31
+ interface WarlokClientOptions {
32
+ apiKey: string;
33
+ baseUrl?: string;
34
+ }
35
+ /**
36
+ * Warlok API client for generation workflows.
37
+ */
38
+ declare class WarlokClient {
39
+ private apiKey;
40
+ private baseUrl;
41
+ constructor(options: WarlokClientOptions);
42
+ private request;
43
+ /**
44
+ * Create a generation job.
45
+ */
46
+ generate(params: GenerateParams): Promise<Generation>;
47
+ /**
48
+ * Get a generation by ID.
49
+ */
50
+ getGeneration(id: string): Promise<Generation>;
51
+ /**
52
+ * List generations for the current account.
53
+ */
54
+ listGenerations(options?: ListGenerationsOptions): Promise<Generation[]>;
55
+ /**
56
+ * Download a generated model file.
57
+ */
58
+ downloadGeneration(id: string, format?: "model" | "rigged"): Promise<Blob>;
59
+ /**
60
+ * Wait for terminal generation status.
61
+ */
62
+ waitForCompletion(id: string, options?: {
63
+ pollingInterval?: number;
64
+ timeout?: number;
65
+ onProgress?: (generation: Generation) => void;
66
+ }): Promise<Generation>;
67
+ /**
68
+ * Delete a generation.
69
+ */
70
+ deleteGeneration(id: string): Promise<void>;
71
+ getAsset(id: string): Promise<Asset>;
72
+ listAssets(options?: {
73
+ limit?: number;
74
+ offset?: number;
75
+ status?: GenerationStage;
76
+ type?: LegacyGenerationType;
77
+ }): Promise<Asset[]>;
78
+ downloadAsset(id: string, format?: "model" | "rigged"): Promise<Blob>;
79
+ deleteAsset(id: string): Promise<void>;
80
+ }
81
+ /**
82
+ * Custom error class for Warlok API errors.
83
+ */
84
+ declare class WarlokError extends Error {
85
+ code: string;
86
+ constructor(message: string, code: string);
87
+ }
88
+
89
+ export { type Asset, type GenerateParams, type Generation, type LegacyGenerationType, type ListGenerationsOptions, WarlokClient, type WarlokClientOptions, WarlokError };
@@ -0,0 +1,89 @@
1
+ import { AssetType, GenerationEntityType, GenerationV2, GenerationStage } from '@warlok-net/core';
2
+ export { AssetType, GenerationEntityType, GenerationStage, GenerationV2 } from '@warlok-net/core';
3
+
4
+ /**
5
+ * Warlok SDK - Node.js client for the Warlok generation API.
6
+ */
7
+
8
+ type LegacyGenerationType = AssetType | GenerationEntityType;
9
+ type Generation = GenerationV2;
10
+ type Asset = Generation;
11
+ interface GenerateParams {
12
+ name?: string;
13
+ entityType?: GenerationEntityType;
14
+ type?: LegacyGenerationType;
15
+ prompt?: string;
16
+ imageUrl?: string;
17
+ imageBase64?: string;
18
+ options?: {
19
+ rigForMixamo?: boolean;
20
+ includeTpose?: boolean;
21
+ optimize?: boolean;
22
+ autoRig?: boolean;
23
+ };
24
+ }
25
+ interface ListGenerationsOptions {
26
+ limit?: number;
27
+ status?: GenerationStage;
28
+ entityType?: GenerationEntityType;
29
+ type?: LegacyGenerationType;
30
+ }
31
+ interface WarlokClientOptions {
32
+ apiKey: string;
33
+ baseUrl?: string;
34
+ }
35
+ /**
36
+ * Warlok API client for generation workflows.
37
+ */
38
+ declare class WarlokClient {
39
+ private apiKey;
40
+ private baseUrl;
41
+ constructor(options: WarlokClientOptions);
42
+ private request;
43
+ /**
44
+ * Create a generation job.
45
+ */
46
+ generate(params: GenerateParams): Promise<Generation>;
47
+ /**
48
+ * Get a generation by ID.
49
+ */
50
+ getGeneration(id: string): Promise<Generation>;
51
+ /**
52
+ * List generations for the current account.
53
+ */
54
+ listGenerations(options?: ListGenerationsOptions): Promise<Generation[]>;
55
+ /**
56
+ * Download a generated model file.
57
+ */
58
+ downloadGeneration(id: string, format?: "model" | "rigged"): Promise<Blob>;
59
+ /**
60
+ * Wait for terminal generation status.
61
+ */
62
+ waitForCompletion(id: string, options?: {
63
+ pollingInterval?: number;
64
+ timeout?: number;
65
+ onProgress?: (generation: Generation) => void;
66
+ }): Promise<Generation>;
67
+ /**
68
+ * Delete a generation.
69
+ */
70
+ deleteGeneration(id: string): Promise<void>;
71
+ getAsset(id: string): Promise<Asset>;
72
+ listAssets(options?: {
73
+ limit?: number;
74
+ offset?: number;
75
+ status?: GenerationStage;
76
+ type?: LegacyGenerationType;
77
+ }): Promise<Asset[]>;
78
+ downloadAsset(id: string, format?: "model" | "rigged"): Promise<Blob>;
79
+ deleteAsset(id: string): Promise<void>;
80
+ }
81
+ /**
82
+ * Custom error class for Warlok API errors.
83
+ */
84
+ declare class WarlokError extends Error {
85
+ code: string;
86
+ constructor(message: string, code: string);
87
+ }
88
+
89
+ export { type Asset, type GenerateParams, type Generation, type LegacyGenerationType, type ListGenerationsOptions, WarlokClient, type WarlokClientOptions, WarlokError };
package/dist/index.js ADDED
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ WarlokClient: () => WarlokClient,
24
+ WarlokError: () => WarlokError
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ function mapToEntityType(type) {
28
+ const normalized = String(type).toLowerCase();
29
+ if (normalized === "person" || normalized === "character" || normalized === "creature") {
30
+ return "person";
31
+ }
32
+ if (normalized === "place" || normalized === "environment") {
33
+ return "place";
34
+ }
35
+ if (normalized === "noun") {
36
+ return "noun";
37
+ }
38
+ return "thing";
39
+ }
40
+ function resolveEntityType(params) {
41
+ if (params.entityType) {
42
+ return params.entityType;
43
+ }
44
+ if (params.type) {
45
+ return mapToEntityType(params.type);
46
+ }
47
+ return "thing";
48
+ }
49
+ var WarlokClient = class {
50
+ constructor(options) {
51
+ this.apiKey = options.apiKey;
52
+ this.baseUrl = options.baseUrl || "https://api.warlok.net";
53
+ }
54
+ async request(method, path, body) {
55
+ const headers = {
56
+ Authorization: `Bearer ${this.apiKey}`
57
+ };
58
+ const init = {
59
+ method,
60
+ headers
61
+ };
62
+ if (body !== void 0) {
63
+ headers["Content-Type"] = "application/json";
64
+ init.body = JSON.stringify(body);
65
+ }
66
+ const response = await fetch(`${this.baseUrl}${path}`, init);
67
+ const contentType = response.headers.get("content-type") || "";
68
+ const payload = contentType.includes("application/json") ? await response.json().catch(() => void 0) : void 0;
69
+ if (!response.ok) {
70
+ const errorPayload = payload || {};
71
+ throw new WarlokError(
72
+ errorPayload.error?.message || `Request failed: ${response.status}`,
73
+ errorPayload.error?.code || "REQUEST_FAILED"
74
+ );
75
+ }
76
+ return payload;
77
+ }
78
+ /**
79
+ * Create a generation job.
80
+ */
81
+ async generate(params) {
82
+ const entityType = resolveEntityType(params);
83
+ const isPerson = entityType === "person";
84
+ const rigForMixamo = isPerson ? params.options?.rigForMixamo ?? params.options?.autoRig ?? true : false;
85
+ const includeTpose = isPerson ? params.options?.includeTpose ?? true : false;
86
+ const optimize = params.options?.optimize ?? true;
87
+ const response = await this.request(
88
+ "POST",
89
+ "/api/v1/generations",
90
+ {
91
+ name: params.name,
92
+ entityType,
93
+ input: {
94
+ prompt: params.prompt,
95
+ imageUrl: params.imageUrl,
96
+ imageBase64: params.imageBase64
97
+ },
98
+ options: {
99
+ rigForMixamo,
100
+ includeTpose,
101
+ optimize
102
+ }
103
+ }
104
+ );
105
+ if (!response.success || !response.data) {
106
+ throw new WarlokError(
107
+ response.error?.message || "Generation failed",
108
+ response.error?.code || "GENERATION_FAILED"
109
+ );
110
+ }
111
+ return response.data;
112
+ }
113
+ /**
114
+ * Get a generation by ID.
115
+ */
116
+ async getGeneration(id) {
117
+ const response = await this.request(
118
+ "GET",
119
+ `/api/v1/generations/${id}`
120
+ );
121
+ if (!response.success || !response.data) {
122
+ throw new WarlokError(
123
+ response.error?.message || "Generation not found",
124
+ response.error?.code || "NOT_FOUND"
125
+ );
126
+ }
127
+ return response.data;
128
+ }
129
+ /**
130
+ * List generations for the current account.
131
+ */
132
+ async listGenerations(options) {
133
+ const response = await this.request(
134
+ "GET",
135
+ "/api/v1/generations"
136
+ );
137
+ let items = response.data || [];
138
+ if (options?.status) {
139
+ items = items.filter((item) => item.status === options.status);
140
+ }
141
+ const filteredEntityType = options?.entityType || (options?.type ? mapToEntityType(options.type) : void 0);
142
+ if (filteredEntityType) {
143
+ items = items.filter((item) => item.entityType === filteredEntityType);
144
+ }
145
+ if (options?.limit && options.limit > 0) {
146
+ items = items.slice(0, options.limit);
147
+ }
148
+ return items;
149
+ }
150
+ /**
151
+ * Download a generated model file.
152
+ */
153
+ async downloadGeneration(id, format) {
154
+ const generation = await this.getGeneration(id);
155
+ let url;
156
+ if (format === "rigged") {
157
+ url = generation.outputs.riggedModelUrl;
158
+ } else if (format === "model") {
159
+ url = generation.outputs.modelUrl;
160
+ } else {
161
+ url = generation.outputs.riggedModelUrl || generation.outputs.modelUrl;
162
+ }
163
+ if (!url) {
164
+ throw new WarlokError("No model URL available", "NO_MODEL");
165
+ }
166
+ const response = await fetch(url, {
167
+ headers: {
168
+ Authorization: `Bearer ${this.apiKey}`
169
+ }
170
+ });
171
+ if (!response.ok) {
172
+ throw new WarlokError("Download failed", "DOWNLOAD_FAILED");
173
+ }
174
+ return response.blob();
175
+ }
176
+ /**
177
+ * Wait for terminal generation status.
178
+ */
179
+ async waitForCompletion(id, options) {
180
+ const interval = options?.pollingInterval || 2e3;
181
+ const timeout = options?.timeout || 3e5;
182
+ const startTime = Date.now();
183
+ while (true) {
184
+ const generation = await this.getGeneration(id);
185
+ if (options?.onProgress) {
186
+ options.onProgress(generation);
187
+ }
188
+ if (generation.status === "complete") {
189
+ return generation;
190
+ }
191
+ if (generation.status === "failed") {
192
+ throw new WarlokError(
193
+ generation.error || "Generation failed",
194
+ "GENERATION_FAILED"
195
+ );
196
+ }
197
+ if (Date.now() - startTime > timeout) {
198
+ throw new WarlokError("Timeout waiting for completion", "TIMEOUT");
199
+ }
200
+ await sleep(interval);
201
+ }
202
+ }
203
+ /**
204
+ * Delete a generation.
205
+ */
206
+ async deleteGeneration(id) {
207
+ await this.request(
208
+ "DELETE",
209
+ `/api/v1/generations/${id}`
210
+ );
211
+ }
212
+ // Compatibility aliases for previous SDK method names.
213
+ async getAsset(id) {
214
+ return this.getGeneration(id);
215
+ }
216
+ async listAssets(options) {
217
+ const items = await this.listGenerations({
218
+ limit: options?.limit,
219
+ status: options?.status,
220
+ type: options?.type
221
+ });
222
+ if (!options?.offset || options.offset <= 0) {
223
+ return items;
224
+ }
225
+ return items.slice(options.offset);
226
+ }
227
+ async downloadAsset(id, format) {
228
+ return this.downloadGeneration(id, format);
229
+ }
230
+ async deleteAsset(id) {
231
+ return this.deleteGeneration(id);
232
+ }
233
+ };
234
+ var WarlokError = class extends Error {
235
+ constructor(message, code) {
236
+ super(message);
237
+ this.name = "WarlokError";
238
+ this.code = code;
239
+ }
240
+ };
241
+ function sleep(ms) {
242
+ return new Promise((resolve) => setTimeout(resolve, ms));
243
+ }
244
+ // Annotate the CommonJS export names for ESM import in node:
245
+ 0 && (module.exports = {
246
+ WarlokClient,
247
+ WarlokError
248
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,222 @@
1
+ // src/index.ts
2
+ function mapToEntityType(type) {
3
+ const normalized = String(type).toLowerCase();
4
+ if (normalized === "person" || normalized === "character" || normalized === "creature") {
5
+ return "person";
6
+ }
7
+ if (normalized === "place" || normalized === "environment") {
8
+ return "place";
9
+ }
10
+ if (normalized === "noun") {
11
+ return "noun";
12
+ }
13
+ return "thing";
14
+ }
15
+ function resolveEntityType(params) {
16
+ if (params.entityType) {
17
+ return params.entityType;
18
+ }
19
+ if (params.type) {
20
+ return mapToEntityType(params.type);
21
+ }
22
+ return "thing";
23
+ }
24
+ var WarlokClient = class {
25
+ constructor(options) {
26
+ this.apiKey = options.apiKey;
27
+ this.baseUrl = options.baseUrl || "https://api.warlok.net";
28
+ }
29
+ async request(method, path, body) {
30
+ const headers = {
31
+ Authorization: `Bearer ${this.apiKey}`
32
+ };
33
+ const init = {
34
+ method,
35
+ headers
36
+ };
37
+ if (body !== void 0) {
38
+ headers["Content-Type"] = "application/json";
39
+ init.body = JSON.stringify(body);
40
+ }
41
+ const response = await fetch(`${this.baseUrl}${path}`, init);
42
+ const contentType = response.headers.get("content-type") || "";
43
+ const payload = contentType.includes("application/json") ? await response.json().catch(() => void 0) : void 0;
44
+ if (!response.ok) {
45
+ const errorPayload = payload || {};
46
+ throw new WarlokError(
47
+ errorPayload.error?.message || `Request failed: ${response.status}`,
48
+ errorPayload.error?.code || "REQUEST_FAILED"
49
+ );
50
+ }
51
+ return payload;
52
+ }
53
+ /**
54
+ * Create a generation job.
55
+ */
56
+ async generate(params) {
57
+ const entityType = resolveEntityType(params);
58
+ const isPerson = entityType === "person";
59
+ const rigForMixamo = isPerson ? params.options?.rigForMixamo ?? params.options?.autoRig ?? true : false;
60
+ const includeTpose = isPerson ? params.options?.includeTpose ?? true : false;
61
+ const optimize = params.options?.optimize ?? true;
62
+ const response = await this.request(
63
+ "POST",
64
+ "/api/v1/generations",
65
+ {
66
+ name: params.name,
67
+ entityType,
68
+ input: {
69
+ prompt: params.prompt,
70
+ imageUrl: params.imageUrl,
71
+ imageBase64: params.imageBase64
72
+ },
73
+ options: {
74
+ rigForMixamo,
75
+ includeTpose,
76
+ optimize
77
+ }
78
+ }
79
+ );
80
+ if (!response.success || !response.data) {
81
+ throw new WarlokError(
82
+ response.error?.message || "Generation failed",
83
+ response.error?.code || "GENERATION_FAILED"
84
+ );
85
+ }
86
+ return response.data;
87
+ }
88
+ /**
89
+ * Get a generation by ID.
90
+ */
91
+ async getGeneration(id) {
92
+ const response = await this.request(
93
+ "GET",
94
+ `/api/v1/generations/${id}`
95
+ );
96
+ if (!response.success || !response.data) {
97
+ throw new WarlokError(
98
+ response.error?.message || "Generation not found",
99
+ response.error?.code || "NOT_FOUND"
100
+ );
101
+ }
102
+ return response.data;
103
+ }
104
+ /**
105
+ * List generations for the current account.
106
+ */
107
+ async listGenerations(options) {
108
+ const response = await this.request(
109
+ "GET",
110
+ "/api/v1/generations"
111
+ );
112
+ let items = response.data || [];
113
+ if (options?.status) {
114
+ items = items.filter((item) => item.status === options.status);
115
+ }
116
+ const filteredEntityType = options?.entityType || (options?.type ? mapToEntityType(options.type) : void 0);
117
+ if (filteredEntityType) {
118
+ items = items.filter((item) => item.entityType === filteredEntityType);
119
+ }
120
+ if (options?.limit && options.limit > 0) {
121
+ items = items.slice(0, options.limit);
122
+ }
123
+ return items;
124
+ }
125
+ /**
126
+ * Download a generated model file.
127
+ */
128
+ async downloadGeneration(id, format) {
129
+ const generation = await this.getGeneration(id);
130
+ let url;
131
+ if (format === "rigged") {
132
+ url = generation.outputs.riggedModelUrl;
133
+ } else if (format === "model") {
134
+ url = generation.outputs.modelUrl;
135
+ } else {
136
+ url = generation.outputs.riggedModelUrl || generation.outputs.modelUrl;
137
+ }
138
+ if (!url) {
139
+ throw new WarlokError("No model URL available", "NO_MODEL");
140
+ }
141
+ const response = await fetch(url, {
142
+ headers: {
143
+ Authorization: `Bearer ${this.apiKey}`
144
+ }
145
+ });
146
+ if (!response.ok) {
147
+ throw new WarlokError("Download failed", "DOWNLOAD_FAILED");
148
+ }
149
+ return response.blob();
150
+ }
151
+ /**
152
+ * Wait for terminal generation status.
153
+ */
154
+ async waitForCompletion(id, options) {
155
+ const interval = options?.pollingInterval || 2e3;
156
+ const timeout = options?.timeout || 3e5;
157
+ const startTime = Date.now();
158
+ while (true) {
159
+ const generation = await this.getGeneration(id);
160
+ if (options?.onProgress) {
161
+ options.onProgress(generation);
162
+ }
163
+ if (generation.status === "complete") {
164
+ return generation;
165
+ }
166
+ if (generation.status === "failed") {
167
+ throw new WarlokError(
168
+ generation.error || "Generation failed",
169
+ "GENERATION_FAILED"
170
+ );
171
+ }
172
+ if (Date.now() - startTime > timeout) {
173
+ throw new WarlokError("Timeout waiting for completion", "TIMEOUT");
174
+ }
175
+ await sleep(interval);
176
+ }
177
+ }
178
+ /**
179
+ * Delete a generation.
180
+ */
181
+ async deleteGeneration(id) {
182
+ await this.request(
183
+ "DELETE",
184
+ `/api/v1/generations/${id}`
185
+ );
186
+ }
187
+ // Compatibility aliases for previous SDK method names.
188
+ async getAsset(id) {
189
+ return this.getGeneration(id);
190
+ }
191
+ async listAssets(options) {
192
+ const items = await this.listGenerations({
193
+ limit: options?.limit,
194
+ status: options?.status,
195
+ type: options?.type
196
+ });
197
+ if (!options?.offset || options.offset <= 0) {
198
+ return items;
199
+ }
200
+ return items.slice(options.offset);
201
+ }
202
+ async downloadAsset(id, format) {
203
+ return this.downloadGeneration(id, format);
204
+ }
205
+ async deleteAsset(id) {
206
+ return this.deleteGeneration(id);
207
+ }
208
+ };
209
+ var WarlokError = class extends Error {
210
+ constructor(message, code) {
211
+ super(message);
212
+ this.name = "WarlokError";
213
+ this.code = code;
214
+ }
215
+ };
216
+ function sleep(ms) {
217
+ return new Promise((resolve) => setTimeout(resolve, ms));
218
+ }
219
+ export {
220
+ WarlokClient,
221
+ WarlokError
222
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@warlok-net/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Node.js SDK for the Warlok 3D asset generation API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@warlok-net/core": "0.1.0"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/crispcode-io/Warlok.git",
27
+ "directory": "packages/warlok-sdk"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.0.0",
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.3.0"
33
+ },
34
+ "peerDependencies": {
35
+ "typescript": ">=5.0.0"
36
+ },
37
+ "peerDependenciesMeta": {
38
+ "typescript": {
39
+ "optional": true
40
+ }
41
+ },
42
+ "keywords": [
43
+ "warlok",
44
+ "3d",
45
+ "game-assets",
46
+ "ai",
47
+ "sdk"
48
+ ],
49
+ "license": "MIT",
50
+ "scripts": {
51
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
52
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
53
+ "lint": "tsc --noEmit",
54
+ "type-check": "tsc --noEmit"
55
+ }
56
+ }