@playdrop/playdrop-cli 0.7.15 → 0.7.17

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.
Files changed (70) hide show
  1. package/config/client-meta.json +1 -1
  2. package/node_modules/@playdrop/ai-client/dist/index.js +461 -444
  3. package/node_modules/@playdrop/ai-client/package.json +1 -1
  4. package/node_modules/@playdrop/api-client/dist/client.js +903 -882
  5. package/node_modules/@playdrop/api-client/dist/core/errors.js +69 -45
  6. package/node_modules/@playdrop/api-client/dist/core/request.js +188 -159
  7. package/node_modules/@playdrop/api-client/dist/domains/admin.js +516 -491
  8. package/node_modules/@playdrop/api-client/dist/domains/ai.js +40 -14
  9. package/node_modules/@playdrop/api-client/dist/domains/apps.js +480 -462
  10. package/node_modules/@playdrop/api-client/dist/domains/asset-packs.js +439 -419
  11. package/node_modules/@playdrop/api-client/dist/domains/assets.js +696 -676
  12. package/node_modules/@playdrop/api-client/dist/domains/auth.js +346 -320
  13. package/node_modules/@playdrop/api-client/dist/domains/comments.js +124 -98
  14. package/node_modules/@playdrop/api-client/dist/domains/free-credits.js +91 -65
  15. package/node_modules/@playdrop/api-client/dist/domains/me.js +71 -45
  16. package/node_modules/@playdrop/api-client/dist/domains/payments.js +407 -386
  17. package/node_modules/@playdrop/api-client/dist/domains/player-meta.js +144 -118
  18. package/node_modules/@playdrop/api-client/dist/domains/search.js +117 -104
  19. package/node_modules/@playdrop/api-client/dist/domains/tags.js +188 -162
  20. package/node_modules/@playdrop/api-client/dist/index.js +993 -552
  21. package/node_modules/@playdrop/api-client/package.json +1 -1
  22. package/node_modules/@playdrop/boxel-three/dist/src/animations.js +84 -62
  23. package/node_modules/@playdrop/boxel-three/dist/src/builders.js +341 -308
  24. package/node_modules/@playdrop/boxel-three/dist/src/context.js +55 -29
  25. package/node_modules/@playdrop/boxel-three/dist/src/exporters/glb.js +856 -858
  26. package/node_modules/@playdrop/boxel-three/dist/src/exporters/image.js +267 -261
  27. package/node_modules/@playdrop/boxel-three/dist/src/index.js +64 -15
  28. package/node_modules/@playdrop/boxel-three/dist/src/instantiate.js +89 -63
  29. package/node_modules/@playdrop/boxel-three/dist/src/nodes.js +81 -56
  30. package/node_modules/@playdrop/boxel-three/dist/src/overlays.js +112 -86
  31. package/node_modules/@playdrop/boxel-three/dist/src/primitives.js +45 -17
  32. package/node_modules/@playdrop/boxel-three/dist/src/scene.js +160 -136
  33. package/node_modules/@playdrop/boxel-three/dist/src/skinned-mesh.js +582 -584
  34. package/node_modules/@playdrop/boxel-three/dist/src/texture-atlas.js +123 -97
  35. package/node_modules/@playdrop/boxel-three/dist/src/textures.js +207 -182
  36. package/node_modules/@playdrop/boxel-three/dist/src/types.js +15 -1
  37. package/node_modules/@playdrop/boxel-three/dist/src/voxels/faces.js +451 -425
  38. package/node_modules/@playdrop/boxel-three/dist/src/voxels/mesher.js +109 -84
  39. package/node_modules/@playdrop/boxel-three/dist/test/export-image.playwright.test.js +127 -106
  40. package/node_modules/@playdrop/boxel-three/dist/test/fixtures/render-worker.js +73 -51
  41. package/node_modules/@playdrop/boxel-three/dist/test/glb-skinned.test.js +97 -79
  42. package/node_modules/@playdrop/boxel-three/dist/test/index.test.js +29 -7
  43. package/node_modules/@playdrop/boxel-three/dist/test/instantiate.test.js +80 -60
  44. package/node_modules/@playdrop/boxel-three/dist/test/overlays.test.js +41 -19
  45. package/node_modules/@playdrop/boxel-three/dist/test/scene-filter.test.js +72 -50
  46. package/node_modules/@playdrop/boxel-three/dist/test/scene-smoke.test.js +84 -62
  47. package/node_modules/@playdrop/boxel-three/dist/test/skinned-mesh.test.js +69 -47
  48. package/node_modules/@playdrop/boxel-three/dist/test/textured-overlay.test.js +129 -109
  49. package/node_modules/@playdrop/boxel-three/dist/test/voxels.test.js +40 -18
  50. package/node_modules/@playdrop/boxel-three/package.json +1 -1
  51. package/node_modules/@playdrop/config/client-meta.json +1 -1
  52. package/node_modules/@playdrop/types/dist/api.js +289 -203
  53. package/node_modules/@playdrop/types/dist/app-capability-filters.js +112 -62
  54. package/node_modules/@playdrop/types/dist/app.js +91 -45
  55. package/node_modules/@playdrop/types/dist/asset-pack.js +37 -5
  56. package/node_modules/@playdrop/types/dist/asset-spec.js +170 -90
  57. package/node_modules/@playdrop/types/dist/asset.js +186 -108
  58. package/node_modules/@playdrop/types/dist/content-license.js +49 -15
  59. package/node_modules/@playdrop/types/dist/creator-public-image.js +60 -32
  60. package/node_modules/@playdrop/types/dist/ecs.js +102 -82
  61. package/node_modules/@playdrop/types/dist/engine-builtins.js +603 -573
  62. package/node_modules/@playdrop/types/dist/entity.js +63 -53
  63. package/node_modules/@playdrop/types/dist/graph.js +116 -80
  64. package/node_modules/@playdrop/types/dist/index.js +47 -20
  65. package/node_modules/@playdrop/types/dist/owned-assets.js +55 -33
  66. package/node_modules/@playdrop/types/dist/player-meta.js +151 -100
  67. package/node_modules/@playdrop/types/dist/realtime.js +27 -7
  68. package/node_modules/@playdrop/types/dist/version.js +182 -124
  69. package/node_modules/@playdrop/types/package.json +1 -1
  70. package/package.json +1 -1
@@ -1,481 +1,498 @@
1
- export const GENERATION_JOB_ETA_BASELINE_SECONDS = {
2
- IMAGE: 20,
3
- MUSIC: 40,
4
- SFX: 15,
5
- SPEECH: 15,
6
- VIDEO: 90,
7
- MODEL_3D: 420,
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
8
  };
9
- const DEFAULT_LOCAL_BASE = 'http://localhost:8083';
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var dist_exports = {};
19
+ __export(dist_exports, {
20
+ GENERATION_JOB_ETA_BASELINE_SECONDS: () => GENERATION_JOB_ETA_BASELINE_SECONDS,
21
+ createAiClient: () => createAiClient
22
+ });
23
+ module.exports = __toCommonJS(dist_exports);
24
+ const GENERATION_JOB_ETA_BASELINE_SECONDS = {
25
+ IMAGE: 20,
26
+ MUSIC: 40,
27
+ SFX: 15,
28
+ SPEECH: 15,
29
+ VIDEO: 90,
30
+ MODEL_3D: 420
31
+ };
32
+ const DEFAULT_LOCAL_BASE = "http://localhost:8083";
10
33
  const CLIENT_HEADER_NAMES = {
11
- client: 'x-playdrop-client',
12
- clientVersion: 'x-playdrop-client-version',
13
- clientBuild: 'x-playdrop-client-build',
14
- platform: 'x-playdrop-platform',
15
- platformVersion: 'x-playdrop-platform-version',
34
+ client: "x-playdrop-client",
35
+ clientVersion: "x-playdrop-client-version",
36
+ clientBuild: "x-playdrop-client-build",
37
+ platform: "x-playdrop-platform",
38
+ platformVersion: "x-playdrop-platform-version"
16
39
  };
17
40
  function stripTrailingSlash(value) {
18
- return value.endsWith('/') ? value.slice(0, -1) : value;
41
+ return value.endsWith("/") ? value.slice(0, -1) : value;
19
42
  }
20
43
  function normalizeProtocol(protocol) {
21
- if (!protocol) {
22
- return 'http';
23
- }
24
- return protocol.replace(/:$/, '') || 'http';
44
+ if (!protocol) {
45
+ return "http";
46
+ }
47
+ return protocol.replace(/:$/, "") || "http";
25
48
  }
26
49
  function isIpv4Hostname(hostname) {
27
- return /^\d{1,3}(?:\.\d{1,3}){3}$/.test(hostname);
50
+ return /^\d{1,3}(?:\.\d{1,3}){3}$/.test(hostname);
28
51
  }
29
52
  function isLocalHostname(hostname) {
30
- if (!hostname) {
31
- return true;
32
- }
33
- const normalizedHostname = hostname.trim().toLowerCase();
34
- if (!normalizedHostname) {
35
- return true;
36
- }
37
- if (normalizedHostname === 'localhost' || normalizedHostname === '0.0.0.0') {
38
- return true;
39
- }
40
- if (isIpv4Hostname(normalizedHostname)) {
41
- return true;
42
- }
43
- return normalizedHostname.includes(':');
53
+ if (!hostname) {
54
+ return true;
55
+ }
56
+ const normalizedHostname = hostname.trim().toLowerCase();
57
+ if (!normalizedHostname) {
58
+ return true;
59
+ }
60
+ if (normalizedHostname === "localhost" || normalizedHostname === "0.0.0.0") {
61
+ return true;
62
+ }
63
+ if (isIpv4Hostname(normalizedHostname)) {
64
+ return true;
65
+ }
66
+ return normalizedHostname.includes(":");
44
67
  }
45
68
  function formatHostnameForUrl(hostname) {
46
- const normalizedHostname = hostname.trim();
47
- if (!normalizedHostname) {
48
- return 'localhost';
49
- }
50
- if (normalizedHostname.includes(':') && !normalizedHostname.startsWith('[')) {
51
- return `[${normalizedHostname}]`;
52
- }
53
- return normalizedHostname;
69
+ const normalizedHostname = hostname.trim();
70
+ if (!normalizedHostname) {
71
+ return "localhost";
72
+ }
73
+ if (normalizedHostname.includes(":") && !normalizedHostname.startsWith("[")) {
74
+ return `[${normalizedHostname}]`;
75
+ }
76
+ return normalizedHostname;
54
77
  }
55
78
  function inferBaseFromHostname(hostname, protocol) {
56
- if (isLocalHostname(hostname)) {
57
- return `${protocol}://${formatHostnameForUrl(hostname)}:8083`;
58
- }
59
- if (hostname.includes('.')) {
60
- const domain = hostname
61
- .replace(/^www\./, '')
62
- .replace(/^api\./, '')
63
- .replace(/^play\./, '')
64
- .replace(/^admin\./, '')
65
- .replace(/^ai\./, '')
66
- .replace(/^assets\./, '');
67
- return `${protocol}://ai.${domain}`;
68
- }
69
- const host = formatHostnameForUrl(hostname || 'localhost');
70
- return `${protocol}://${host}:8083`;
79
+ if (isLocalHostname(hostname)) {
80
+ return `${protocol}://${formatHostnameForUrl(hostname)}:8083`;
81
+ }
82
+ if (hostname.includes(".")) {
83
+ const domain = hostname.replace(/^www\./, "").replace(/^api\./, "").replace(/^play\./, "").replace(/^admin\./, "").replace(/^ai\./, "").replace(/^assets\./, "");
84
+ return `${protocol}://ai.${domain}`;
85
+ }
86
+ const host = formatHostnameForUrl(hostname || "localhost");
87
+ return `${protocol}://${host}:8083`;
71
88
  }
72
89
  function inferBaseUrl() {
73
- if (typeof process !== 'undefined' && process.env.NEXT_PUBLIC_AI_BASE) {
74
- return process.env.NEXT_PUBLIC_AI_BASE;
75
- }
76
- if (typeof window !== 'undefined' && window.location) {
77
- const { hostname, protocol } = window.location;
78
- return inferBaseFromHostname(hostname, normalizeProtocol(protocol));
79
- }
80
- return DEFAULT_LOCAL_BASE;
90
+ if (typeof process !== "undefined" && process.env.NEXT_PUBLIC_AI_BASE) {
91
+ return process.env.NEXT_PUBLIC_AI_BASE;
92
+ }
93
+ if (typeof window !== "undefined" && window.location) {
94
+ const { hostname, protocol } = window.location;
95
+ return inferBaseFromHostname(hostname, normalizeProtocol(protocol));
96
+ }
97
+ return DEFAULT_LOCAL_BASE;
81
98
  }
82
99
  function resolveBrowserRequestCredentials() {
83
- if (typeof window === 'undefined') {
84
- return undefined;
85
- }
86
- return 'include';
100
+ if (typeof window === "undefined") {
101
+ return void 0;
102
+ }
103
+ return "include";
87
104
  }
88
105
  function readBrowserRuntimeClientMeta() {
89
- if (typeof window === 'undefined') {
90
- return null;
91
- }
92
- const raw = globalThis.__PLAYDROP_CLIENT_META;
93
- const version = typeof raw?.version === 'string' ? raw.version.trim() : '';
94
- const build = typeof raw?.build === 'string' ? raw.build.trim() : '';
95
- if (!version || !build) {
96
- return null;
97
- }
98
- return { version, build };
106
+ if (typeof window === "undefined") {
107
+ return null;
108
+ }
109
+ const raw = globalThis.__PLAYDROP_CLIENT_META;
110
+ const version = typeof raw?.version === "string" ? raw.version.trim() : "";
111
+ const build = typeof raw?.build === "string" ? raw.build.trim() : "";
112
+ if (!version || !build) {
113
+ return null;
114
+ }
115
+ return { version, build };
99
116
  }
100
117
  function normalizeBrowserPlatformName(raw) {
101
- const value = raw.trim().toLowerCase();
102
- if (value.includes('mac'))
103
- return 'macos';
104
- if (value.includes('win'))
105
- return 'windows';
106
- if (value.includes('linux'))
107
- return 'linux';
108
- if (value.includes('ios') || value.includes('iphone') || value.includes('ipad'))
109
- return 'ios';
110
- if (value.includes('android'))
111
- return 'android';
112
- return value || 'browser';
118
+ const value = raw.trim().toLowerCase();
119
+ if (value.includes("mac"))
120
+ return "macos";
121
+ if (value.includes("win"))
122
+ return "windows";
123
+ if (value.includes("linux"))
124
+ return "linux";
125
+ if (value.includes("ios") || value.includes("iphone") || value.includes("ipad"))
126
+ return "ios";
127
+ if (value.includes("android"))
128
+ return "android";
129
+ return value || "browser";
113
130
  }
114
- // eslint-disable-next-line complexity
115
131
  function resolveBrowserPlatform() {
116
- if (typeof window === 'undefined') {
117
- return { name: 'browser', version: '0.0.0' };
118
- }
119
- const envPlatform = (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_PLAYDROP_PLATFORM : '')?.trim() ?? '';
120
- const envPlatformVersion = (typeof process !== 'undefined' ? process.env.NEXT_PUBLIC_PLAYDROP_PLATFORM_VERSION : '')?.trim() ?? '';
121
- if (envPlatform && envPlatformVersion) {
122
- return { name: envPlatform.toLowerCase(), version: envPlatformVersion };
123
- }
124
- const nav = window.navigator;
125
- const userAgent = nav.userAgent || '';
126
- const data = nav.userAgentData;
127
- if (data?.platform) {
128
- const platformName = normalizeBrowserPlatformName(data.platform);
129
- const version = (data.platformVersion || '').replace(/_/g, '.').trim();
130
- if (version) {
131
- return { name: platformName, version };
132
- }
133
- }
134
- const macMatch = /Mac OS X ([0-9_]+(?:_[0-9_]+)*)/i.exec(userAgent);
135
- if (macMatch?.[1]) {
136
- return { name: 'macos', version: macMatch[1].replace(/_/g, '.') };
137
- }
138
- const iosMatch = /(iPhone|iPad|iPod).*OS ([0-9_]+)/i.exec(userAgent);
139
- if (iosMatch?.[2]) {
140
- return { name: 'ios', version: iosMatch[2].replace(/_/g, '.') };
141
- }
142
- const winMatch = /Windows NT ([0-9.]+)/i.exec(userAgent);
143
- if (winMatch?.[1]) {
144
- return { name: 'windows', version: winMatch[1] };
145
- }
146
- const androidMatch = /Android ([0-9.]+)/i.exec(userAgent);
147
- if (androidMatch?.[1]) {
148
- return { name: 'android', version: androidMatch[1] };
149
- }
150
- if (/Linux/i.test(userAgent)) {
151
- return { name: 'linux', version: '0.0.0' };
152
- }
153
- return { name: 'browser', version: '0.0.0' };
132
+ if (typeof window === "undefined") {
133
+ return { name: "browser", version: "0.0.0" };
134
+ }
135
+ const envPlatform = (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_PLAYDROP_PLATFORM : "")?.trim() ?? "";
136
+ const envPlatformVersion = (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_PLAYDROP_PLATFORM_VERSION : "")?.trim() ?? "";
137
+ if (envPlatform && envPlatformVersion) {
138
+ return { name: envPlatform.toLowerCase(), version: envPlatformVersion };
139
+ }
140
+ const nav = window.navigator;
141
+ const userAgent = nav.userAgent || "";
142
+ const data = nav.userAgentData;
143
+ if (data?.platform) {
144
+ const platformName = normalizeBrowserPlatformName(data.platform);
145
+ const version = (data.platformVersion || "").replace(/_/g, ".").trim();
146
+ if (version) {
147
+ return { name: platformName, version };
148
+ }
149
+ }
150
+ const macMatch = /Mac OS X ([0-9_]+(?:_[0-9_]+)*)/i.exec(userAgent);
151
+ if (macMatch?.[1]) {
152
+ return { name: "macos", version: macMatch[1].replace(/_/g, ".") };
153
+ }
154
+ const iosMatch = /(iPhone|iPad|iPod).*OS ([0-9_]+)/i.exec(userAgent);
155
+ if (iosMatch?.[2]) {
156
+ return { name: "ios", version: iosMatch[2].replace(/_/g, ".") };
157
+ }
158
+ const winMatch = /Windows NT ([0-9.]+)/i.exec(userAgent);
159
+ if (winMatch?.[1]) {
160
+ return { name: "windows", version: winMatch[1] };
161
+ }
162
+ const androidMatch = /Android ([0-9.]+)/i.exec(userAgent);
163
+ if (androidMatch?.[1]) {
164
+ return { name: "android", version: androidMatch[1] };
165
+ }
166
+ if (/Linux/i.test(userAgent)) {
167
+ return { name: "linux", version: "0.0.0" };
168
+ }
169
+ return { name: "browser", version: "0.0.0" };
154
170
  }
155
171
  function resolveBrowserDefaultClientHeaders() {
156
- const clientMeta = readBrowserRuntimeClientMeta();
157
- if (!clientMeta) {
158
- return {};
159
- }
160
- const platform = resolveBrowserPlatform();
161
- return {
162
- [CLIENT_HEADER_NAMES.client]: 'web',
163
- [CLIENT_HEADER_NAMES.clientVersion]: clientMeta.version,
164
- [CLIENT_HEADER_NAMES.clientBuild]: clientMeta.build,
165
- [CLIENT_HEADER_NAMES.platform]: platform.name,
166
- [CLIENT_HEADER_NAMES.platformVersion]: platform.version,
167
- };
172
+ const clientMeta = readBrowserRuntimeClientMeta();
173
+ if (!clientMeta) {
174
+ return {};
175
+ }
176
+ const platform = resolveBrowserPlatform();
177
+ return {
178
+ [CLIENT_HEADER_NAMES.client]: "web",
179
+ [CLIENT_HEADER_NAMES.clientVersion]: clientMeta.version,
180
+ [CLIENT_HEADER_NAMES.clientBuild]: clientMeta.build,
181
+ [CLIENT_HEADER_NAMES.platform]: platform.name,
182
+ [CLIENT_HEADER_NAMES.platformVersion]: platform.version
183
+ };
168
184
  }
169
185
  function fillMissingClientHeaders(headers) {
170
- if (typeof window === 'undefined') {
171
- return headers;
172
- }
173
- const inferredHeaders = resolveBrowserDefaultClientHeaders();
174
- if (!Object.keys(inferredHeaders).length) {
175
- return headers;
176
- }
177
- return {
178
- ...inferredHeaders,
179
- ...headers,
180
- };
186
+ if (typeof window === "undefined") {
187
+ return headers;
188
+ }
189
+ const inferredHeaders = resolveBrowserDefaultClientHeaders();
190
+ if (!Object.keys(inferredHeaders).length) {
191
+ return headers;
192
+ }
193
+ return {
194
+ ...inferredHeaders,
195
+ ...headers
196
+ };
181
197
  }
182
198
  async function resolveAiClientToken(config) {
183
- if (config.tokenProvider) {
184
- const token = await config.tokenProvider();
185
- return token ?? null;
186
- }
187
- return null;
199
+ if (config.tokenProvider) {
200
+ const token = await config.tokenProvider();
201
+ return token ?? null;
202
+ }
203
+ return null;
188
204
  }
189
205
  async function resolveAiClientHeaders(config) {
190
- if (config.clientHeaders) {
191
- try {
192
- const headers = await config.clientHeaders();
193
- return headers && typeof headers === 'object' ? { ...headers } : {};
194
- }
195
- catch {
196
- return {};
197
- }
198
- }
199
- return {};
206
+ if (config.clientHeaders) {
207
+ try {
208
+ const headers = await config.clientHeaders();
209
+ return headers && typeof headers === "object" ? { ...headers } : {};
210
+ } catch {
211
+ return {};
212
+ }
213
+ }
214
+ return {};
200
215
  }
201
- export function createAiClient(config = {}) {
202
- const fetchImpl = config.fetchImpl ?? globalThis.fetch?.bind(globalThis);
203
- if (!fetchImpl) {
204
- throw new Error('ai_client_missing_fetch');
205
- }
206
- const baseUrl = stripTrailingSlash(config.baseUrl ?? inferBaseUrl());
207
- async function buildHeaders() {
208
- const headers = fillMissingClientHeaders({
209
- ...(await resolveAiClientHeaders(config)),
210
- });
211
- const token = await resolveAiClientToken(config);
212
- if (token && !headers.Authorization) {
213
- headers.Authorization = `Bearer ${token}`;
214
- }
215
- return headers;
216
- }
217
- async function buildRequestInit(payload, signal) {
218
- const headers = await buildHeaders();
219
- headers['Content-Type'] = 'application/json';
220
- return {
221
- method: 'POST',
222
- headers,
223
- body: JSON.stringify(payload),
224
- credentials: resolveBrowserRequestCredentials(),
225
- signal,
226
- };
227
- }
228
- async function throwHttpError(response) {
229
- let payload = null;
216
+ function createAiClient(config = {}) {
217
+ const fetchImpl = config.fetchImpl ?? globalThis.fetch?.bind(globalThis);
218
+ if (!fetchImpl) {
219
+ throw new Error("ai_client_missing_fetch");
220
+ }
221
+ const baseUrl = stripTrailingSlash(config.baseUrl ?? inferBaseUrl());
222
+ async function buildHeaders() {
223
+ const headers = fillMissingClientHeaders({
224
+ ...await resolveAiClientHeaders(config)
225
+ });
226
+ const token = await resolveAiClientToken(config);
227
+ if (token && !headers.Authorization) {
228
+ headers.Authorization = `Bearer ${token}`;
229
+ }
230
+ return headers;
231
+ }
232
+ async function buildRequestInit(payload, signal) {
233
+ const headers = await buildHeaders();
234
+ headers["Content-Type"] = "application/json";
235
+ return {
236
+ method: "POST",
237
+ headers,
238
+ body: JSON.stringify(payload),
239
+ credentials: resolveBrowserRequestCredentials(),
240
+ signal
241
+ };
242
+ }
243
+ async function throwHttpError(response) {
244
+ let payload = null;
245
+ try {
246
+ const text = await response.text();
247
+ if (text) {
230
248
  try {
231
- const text = await response.text();
232
- if (text) {
233
- try {
234
- payload = JSON.parse(text);
235
- }
236
- catch {
237
- payload = { message: text };
238
- }
239
- }
240
- }
241
- catch {
242
- payload = null;
243
- }
244
- const code = payload?.error ?? `http_${response.status}`;
245
- const message = payload?.message ?? response.statusText ?? 'Request failed';
246
- const error = new Error(`${code}: ${message}`);
247
- error.status = response.status;
248
- error.code = code;
249
- error.details = payload;
250
- throw error;
251
- }
252
- async function ensureOk(response) {
253
- if (!response.ok) {
254
- await throwHttpError(response);
255
- }
256
- }
257
- async function generateText(input, options) {
258
- const normalizedInput = input?.trim();
259
- if (!normalizedInput) {
260
- throw new Error('ai_client_missing_input');
261
- }
262
- const size = options?.size ?? 'small';
263
- const mode = options?.mode ?? 'text';
264
- const rawSystem = options?.system?.trim();
265
- const system = rawSystem && rawSystem.length ? rawSystem : undefined;
266
- const response = await fetchImpl(`${baseUrl}/text/generate`, await buildRequestInit({
267
- input: normalizedInput,
268
- size,
269
- mode,
270
- system,
271
- }, options?.signal));
272
- await ensureOk(response);
273
- const data = (await response.json());
274
- return data;
275
- }
276
- function applyMediaGenerationPayload(payload, request) {
277
- if (request.modality === 'IMAGE') {
278
- payload.mode = 'image';
279
- payload.image1 = request.image1 ?? undefined;
280
- payload.image2 = request.image2 ?? undefined;
281
- payload.aspectRatio = request.aspectRatio;
282
- payload.imageSize = request.imageSize;
283
- return true;
284
- }
285
- if (request.modality === 'VIDEO') {
286
- payload.durationSeconds = typeof request.durationSeconds === 'number' ? request.durationSeconds : undefined;
287
- payload.aspectRatio = request.aspectRatio;
288
- payload.resolution = '720p';
289
- payload.image1 = request.image1 ?? undefined;
290
- payload.image2 = request.image2 ?? undefined;
291
- return true;
292
- }
293
- return false;
294
- }
295
- function applyAudioGenerationPayload(payload, request) {
296
- if (request.modality === 'MUSIC') {
297
- payload.durationMs = typeof request.durationMs === 'number' ? request.durationMs : undefined;
298
- payload.forceInstrumental = typeof request.forceInstrumental === 'boolean' ? request.forceInstrumental : undefined;
299
- payload.coverPrompt = typeof request.coverPrompt === 'string' ? request.coverPrompt : undefined;
300
- return true;
301
- }
302
- if (request.modality === 'SFX') {
303
- payload.durationSeconds = typeof request.durationSeconds === 'number' ? request.durationSeconds : undefined;
304
- payload.loop = typeof request.loop === 'boolean' ? request.loop : undefined;
305
- payload.coverPrompt = typeof request.coverPrompt === 'string' ? request.coverPrompt : undefined;
306
- return true;
307
- }
308
- if (request.modality === 'SPEECH') {
309
- payload.speechVoice = typeof request.speechVoice === 'string' ? request.speechVoice : undefined;
310
- payload.speechProviderVoiceId =
311
- typeof request.speechProviderVoiceId === 'string' ? request.speechProviderVoiceId : undefined;
312
- return true;
313
- }
314
- return false;
315
- }
316
- function applyGenerateAssetPayloadByModality(payload, request) {
317
- if (applyMediaGenerationPayload(payload, request) || applyAudioGenerationPayload(payload, request)) {
318
- return;
319
- }
320
- if (request.modality === 'MODEL_3D') {
321
- payload.sourceMode = request.sourceMode;
322
- payload.image1 = request.image1 ?? undefined;
323
- payload.image2 = request.image2 ?? undefined;
324
- payload.topology = request.topology;
325
- payload.targetPolycount = typeof request.targetPolycount === 'number' ? request.targetPolycount : undefined;
326
- payload.shouldRemesh = typeof request.shouldRemesh === 'boolean' ? request.shouldRemesh : undefined;
327
- payload.shouldTexture = typeof request.shouldTexture === 'boolean' ? request.shouldTexture : undefined;
328
- }
329
- }
330
- function buildGenerateAssetPayload(request) {
331
- const normalizedInput = request.input?.trim();
332
- if (!normalizedInput) {
333
- throw new Error('ai_client_missing_input');
334
- }
335
- const payload = {
336
- modality: request.modality,
337
- input: normalizedInput,
338
- assetName: request.assetName,
339
- assetDisplayName: request.assetDisplayName,
340
- assetDescription: request.assetDescription,
341
- assetVisibility: request.assetVisibility,
342
- attachAppVersionId: request.attachAppVersionId,
343
- remixAssetVersionRef: request.remixAssetVersionRef,
344
- };
345
- if (request.modality !== 'SPEECH') {
346
- payload.assetSubcategory = request.assetSubcategory;
249
+ payload = JSON.parse(text);
250
+ } catch {
251
+ payload = { message: text };
347
252
  }
348
- applyGenerateAssetPayloadByModality(payload, request);
349
- return payload;
350
- }
351
- async function createGenerationJob(request) {
352
- const payload = buildGenerateAssetPayload(request);
353
- const response = await fetchImpl(`${baseUrl}/ai/assets/jobs`, await buildRequestInit(payload, request.signal));
354
- await ensureOk(response);
355
- return (await response.json());
356
- }
357
- async function getGenerationJob(id, options = {}) {
358
- const normalizedId = id?.trim();
359
- if (!normalizedId) {
360
- throw new Error('ai_client_missing_job_id');
361
- }
362
- const response = await fetchImpl(`${baseUrl}/ai/assets/jobs/${encodeURIComponent(normalizedId)}`, {
363
- method: 'GET',
364
- headers: await buildHeaders(),
365
- credentials: resolveBrowserRequestCredentials(),
366
- signal: options.signal,
367
- });
368
- await ensureOk(response);
369
- return (await response.json());
370
- }
371
- async function listGenerationJobs(options = {}) {
372
- const params = new URLSearchParams();
373
- if (options.modality) {
374
- params.set('modality', options.modality);
375
- }
376
- if (options.status) {
377
- params.set('status', options.status);
378
- }
379
- if (typeof options.limit === 'number' && Number.isFinite(options.limit)) {
380
- params.set('limit', String(options.limit));
381
- }
382
- if (typeof options.offset === 'number' && Number.isFinite(options.offset)) {
383
- params.set('offset', String(options.offset));
384
- }
385
- const queryString = params.toString();
386
- const query = queryString ? `?${queryString}` : '';
387
- const response = await fetchImpl(`${baseUrl}/ai/assets/jobs${query}`, {
388
- method: 'GET',
389
- headers: await buildHeaders(),
390
- credentials: resolveBrowserRequestCredentials(),
391
- signal: options.signal,
392
- });
393
- await ensureOk(response);
394
- return (await response.json());
395
- }
396
- async function deleteGenerationJob(id, options = {}) {
397
- const normalizedId = id?.trim();
398
- if (!normalizedId) {
399
- throw new Error('ai_client_missing_job_id');
400
- }
401
- const response = await fetchImpl(`${baseUrl}/ai/assets/jobs/${encodeURIComponent(normalizedId)}`, {
402
- method: 'DELETE',
403
- headers: await buildHeaders(),
404
- credentials: resolveBrowserRequestCredentials(),
405
- signal: options.signal,
406
- });
407
- await ensureOk(response);
408
- }
409
- async function generateJson(input, options) {
410
- const normalizedInput = input?.trim();
411
- if (!normalizedInput) {
412
- throw new Error('ai_client_missing_input');
413
- }
414
- const normalizedSystem = options?.system?.trim();
415
- const response = await fetchImpl(`${baseUrl}/json/generate`, await buildRequestInit({
416
- input: normalizedInput,
417
- size: options?.size ?? 'small',
418
- system: normalizedSystem && normalizedSystem.length ? normalizedSystem : undefined,
419
- responseJsonSchema: options?.responseJsonSchema,
420
- }, options?.signal));
421
- await ensureOk(response);
422
- const data = (await response.json());
423
- return data;
424
- }
425
- async function listGenerations(options = {}) {
426
- const params = new URLSearchParams();
427
- if (options.type) {
428
- params.set('type', options.type);
429
- }
430
- if (typeof options.limit === 'number' && Number.isFinite(options.limit)) {
431
- params.set('limit', String(options.limit));
432
- }
433
- if (typeof options.offset === 'number' && Number.isFinite(options.offset)) {
434
- params.set('offset', String(options.offset));
435
- }
436
- const queryString = params.toString();
437
- const query = queryString ? `?${queryString}` : '';
438
- const response = await fetchImpl(`${baseUrl}/generations${query}`, {
439
- method: 'GET',
440
- headers: await buildHeaders(),
441
- credentials: resolveBrowserRequestCredentials(),
442
- signal: options.signal,
443
- });
444
- await ensureOk(response);
445
- const data = (await response.json());
446
- return data;
447
- }
448
- async function listDiscoverGenerations(options = {}) {
449
- const params = new URLSearchParams();
450
- if (options.type) {
451
- params.set('type', options.type);
452
- }
453
- if (typeof options.limit === 'number' && Number.isFinite(options.limit)) {
454
- params.set('limit', String(options.limit));
455
- }
456
- if (typeof options.offset === 'number' && Number.isFinite(options.offset)) {
457
- params.set('offset', String(options.offset));
458
- }
459
- const queryString = params.toString();
460
- const query = queryString ? `?${queryString}` : '';
461
- const response = await fetchImpl(`${baseUrl}/generations/discover${query}`, {
462
- method: 'GET',
463
- headers: await buildHeaders(),
464
- credentials: resolveBrowserRequestCredentials(),
465
- signal: options.signal,
466
- });
467
- await ensureOk(response);
468
- const data = (await response.json());
469
- return data;
470
- }
471
- return {
472
- generateText,
473
- createGenerationJob,
474
- getGenerationJob,
475
- listGenerationJobs,
476
- deleteGenerationJob,
477
- generateJson,
478
- listGenerations,
479
- listDiscoverGenerations,
253
+ }
254
+ } catch {
255
+ payload = null;
256
+ }
257
+ const code = payload?.error ?? `http_${response.status}`;
258
+ const message = payload?.message ?? response.statusText ?? "Request failed";
259
+ const error = new Error(`${code}: ${message}`);
260
+ error.status = response.status;
261
+ error.code = code;
262
+ error.details = payload;
263
+ throw error;
264
+ }
265
+ async function ensureOk(response) {
266
+ if (!response.ok) {
267
+ await throwHttpError(response);
268
+ }
269
+ }
270
+ async function generateText(input, options) {
271
+ const normalizedInput = input?.trim();
272
+ if (!normalizedInput) {
273
+ throw new Error("ai_client_missing_input");
274
+ }
275
+ const size = options?.size ?? "small";
276
+ const mode = options?.mode ?? "text";
277
+ const rawSystem = options?.system?.trim();
278
+ const system = rawSystem && rawSystem.length ? rawSystem : void 0;
279
+ const response = await fetchImpl(`${baseUrl}/text/generate`, await buildRequestInit({
280
+ input: normalizedInput,
281
+ size,
282
+ mode,
283
+ system
284
+ }, options?.signal));
285
+ await ensureOk(response);
286
+ const data = await response.json();
287
+ return data;
288
+ }
289
+ function applyMediaGenerationPayload(payload, request) {
290
+ if (request.modality === "IMAGE") {
291
+ payload.mode = "image";
292
+ payload.image1 = request.image1 ?? void 0;
293
+ payload.image2 = request.image2 ?? void 0;
294
+ payload.aspectRatio = request.aspectRatio;
295
+ payload.imageSize = request.imageSize;
296
+ return true;
297
+ }
298
+ if (request.modality === "VIDEO") {
299
+ payload.durationSeconds = typeof request.durationSeconds === "number" ? request.durationSeconds : void 0;
300
+ payload.aspectRatio = request.aspectRatio;
301
+ payload.resolution = "720p";
302
+ payload.image1 = request.image1 ?? void 0;
303
+ payload.image2 = request.image2 ?? void 0;
304
+ return true;
305
+ }
306
+ return false;
307
+ }
308
+ function applyAudioGenerationPayload(payload, request) {
309
+ if (request.modality === "MUSIC") {
310
+ payload.durationMs = typeof request.durationMs === "number" ? request.durationMs : void 0;
311
+ payload.forceInstrumental = typeof request.forceInstrumental === "boolean" ? request.forceInstrumental : void 0;
312
+ payload.coverPrompt = typeof request.coverPrompt === "string" ? request.coverPrompt : void 0;
313
+ return true;
314
+ }
315
+ if (request.modality === "SFX") {
316
+ payload.durationSeconds = typeof request.durationSeconds === "number" ? request.durationSeconds : void 0;
317
+ payload.loop = typeof request.loop === "boolean" ? request.loop : void 0;
318
+ payload.coverPrompt = typeof request.coverPrompt === "string" ? request.coverPrompt : void 0;
319
+ return true;
320
+ }
321
+ if (request.modality === "SPEECH") {
322
+ payload.speechVoice = typeof request.speechVoice === "string" ? request.speechVoice : void 0;
323
+ payload.speechProviderVoiceId = typeof request.speechProviderVoiceId === "string" ? request.speechProviderVoiceId : void 0;
324
+ return true;
325
+ }
326
+ return false;
327
+ }
328
+ function applyGenerateAssetPayloadByModality(payload, request) {
329
+ if (applyMediaGenerationPayload(payload, request) || applyAudioGenerationPayload(payload, request)) {
330
+ return;
331
+ }
332
+ if (request.modality === "MODEL_3D") {
333
+ payload.sourceMode = request.sourceMode;
334
+ payload.image1 = request.image1 ?? void 0;
335
+ payload.image2 = request.image2 ?? void 0;
336
+ payload.topology = request.topology;
337
+ payload.targetPolycount = typeof request.targetPolycount === "number" ? request.targetPolycount : void 0;
338
+ payload.shouldRemesh = typeof request.shouldRemesh === "boolean" ? request.shouldRemesh : void 0;
339
+ payload.shouldTexture = typeof request.shouldTexture === "boolean" ? request.shouldTexture : void 0;
340
+ }
341
+ }
342
+ function buildGenerateAssetPayload(request) {
343
+ const normalizedInput = request.input?.trim();
344
+ if (!normalizedInput) {
345
+ throw new Error("ai_client_missing_input");
346
+ }
347
+ const payload = {
348
+ modality: request.modality,
349
+ input: normalizedInput,
350
+ assetName: request.assetName,
351
+ assetDisplayName: request.assetDisplayName,
352
+ assetDescription: request.assetDescription,
353
+ assetVisibility: request.assetVisibility,
354
+ attachAppVersionId: request.attachAppVersionId,
355
+ remixAssetVersionRef: request.remixAssetVersionRef
480
356
  };
357
+ if (request.modality !== "SPEECH") {
358
+ payload.assetSubcategory = request.assetSubcategory;
359
+ }
360
+ applyGenerateAssetPayloadByModality(payload, request);
361
+ return payload;
362
+ }
363
+ async function createGenerationJob(request) {
364
+ const payload = buildGenerateAssetPayload(request);
365
+ const response = await fetchImpl(`${baseUrl}/ai/assets/jobs`, await buildRequestInit(payload, request.signal));
366
+ await ensureOk(response);
367
+ return await response.json();
368
+ }
369
+ async function getGenerationJob(id, options = {}) {
370
+ const normalizedId = id?.trim();
371
+ if (!normalizedId) {
372
+ throw new Error("ai_client_missing_job_id");
373
+ }
374
+ const response = await fetchImpl(`${baseUrl}/ai/assets/jobs/${encodeURIComponent(normalizedId)}`, {
375
+ method: "GET",
376
+ headers: await buildHeaders(),
377
+ credentials: resolveBrowserRequestCredentials(),
378
+ signal: options.signal
379
+ });
380
+ await ensureOk(response);
381
+ return await response.json();
382
+ }
383
+ async function listGenerationJobs(options = {}) {
384
+ const params = new URLSearchParams();
385
+ if (options.modality) {
386
+ params.set("modality", options.modality);
387
+ }
388
+ if (options.status) {
389
+ params.set("status", options.status);
390
+ }
391
+ if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
392
+ params.set("limit", String(options.limit));
393
+ }
394
+ if (typeof options.offset === "number" && Number.isFinite(options.offset)) {
395
+ params.set("offset", String(options.offset));
396
+ }
397
+ const queryString = params.toString();
398
+ const query = queryString ? `?${queryString}` : "";
399
+ const response = await fetchImpl(`${baseUrl}/ai/assets/jobs${query}`, {
400
+ method: "GET",
401
+ headers: await buildHeaders(),
402
+ credentials: resolveBrowserRequestCredentials(),
403
+ signal: options.signal
404
+ });
405
+ await ensureOk(response);
406
+ return await response.json();
407
+ }
408
+ async function deleteGenerationJob(id, options = {}) {
409
+ const normalizedId = id?.trim();
410
+ if (!normalizedId) {
411
+ throw new Error("ai_client_missing_job_id");
412
+ }
413
+ const response = await fetchImpl(`${baseUrl}/ai/assets/jobs/${encodeURIComponent(normalizedId)}`, {
414
+ method: "DELETE",
415
+ headers: await buildHeaders(),
416
+ credentials: resolveBrowserRequestCredentials(),
417
+ signal: options.signal
418
+ });
419
+ await ensureOk(response);
420
+ }
421
+ async function generateJson(input, options) {
422
+ const normalizedInput = input?.trim();
423
+ if (!normalizedInput) {
424
+ throw new Error("ai_client_missing_input");
425
+ }
426
+ const normalizedSystem = options?.system?.trim();
427
+ const response = await fetchImpl(`${baseUrl}/json/generate`, await buildRequestInit({
428
+ input: normalizedInput,
429
+ size: options?.size ?? "small",
430
+ system: normalizedSystem && normalizedSystem.length ? normalizedSystem : void 0,
431
+ responseJsonSchema: options?.responseJsonSchema
432
+ }, options?.signal));
433
+ await ensureOk(response);
434
+ const data = await response.json();
435
+ return data;
436
+ }
437
+ async function listGenerations(options = {}) {
438
+ const params = new URLSearchParams();
439
+ if (options.type) {
440
+ params.set("type", options.type);
441
+ }
442
+ if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
443
+ params.set("limit", String(options.limit));
444
+ }
445
+ if (typeof options.offset === "number" && Number.isFinite(options.offset)) {
446
+ params.set("offset", String(options.offset));
447
+ }
448
+ const queryString = params.toString();
449
+ const query = queryString ? `?${queryString}` : "";
450
+ const response = await fetchImpl(`${baseUrl}/generations${query}`, {
451
+ method: "GET",
452
+ headers: await buildHeaders(),
453
+ credentials: resolveBrowserRequestCredentials(),
454
+ signal: options.signal
455
+ });
456
+ await ensureOk(response);
457
+ const data = await response.json();
458
+ return data;
459
+ }
460
+ async function listDiscoverGenerations(options = {}) {
461
+ const params = new URLSearchParams();
462
+ if (options.type) {
463
+ params.set("type", options.type);
464
+ }
465
+ if (typeof options.limit === "number" && Number.isFinite(options.limit)) {
466
+ params.set("limit", String(options.limit));
467
+ }
468
+ if (typeof options.offset === "number" && Number.isFinite(options.offset)) {
469
+ params.set("offset", String(options.offset));
470
+ }
471
+ const queryString = params.toString();
472
+ const query = queryString ? `?${queryString}` : "";
473
+ const response = await fetchImpl(`${baseUrl}/generations/discover${query}`, {
474
+ method: "GET",
475
+ headers: await buildHeaders(),
476
+ credentials: resolveBrowserRequestCredentials(),
477
+ signal: options.signal
478
+ });
479
+ await ensureOk(response);
480
+ const data = await response.json();
481
+ return data;
482
+ }
483
+ return {
484
+ generateText,
485
+ createGenerationJob,
486
+ getGenerationJob,
487
+ listGenerationJobs,
488
+ deleteGenerationJob,
489
+ generateJson,
490
+ listGenerations,
491
+ listDiscoverGenerations
492
+ };
481
493
  }
494
+ // Annotate the CommonJS export names for ESM import in node:
495
+ 0 && (module.exports = {
496
+ GENERATION_JOB_ETA_BASELINE_SECONDS,
497
+ createAiClient
498
+ });