@liforma/publisher 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.
- package/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/createPublisher.d.ts +282 -0
- package/dist/createPublisher.d.ts.map +1 -0
- package/dist/createPublisher.js +194 -0
- package/dist/createPublisher.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +64 -0
- package/dist/errors.js.map +1 -0
- package/dist/hash.d.ts +4 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +21 -0
- package/dist/hash.js.map +1 -0
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +93 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs.d.ts +15 -0
- package/dist/jobs.d.ts.map +1 -0
- package/dist/jobs.js +127 -0
- package/dist/jobs.js.map +1 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +19 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schemas.d.ts +384 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +199 -0
- package/dist/schemas.js.map +1 -0
- package/dist/upload.d.ts +18 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +67 -0
- package/dist/upload.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Liforma Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @liforma/publisher
|
|
2
|
+
|
|
3
|
+
Server SDK for Liforma programmatic authoring — upload images, create locations/places/clothes/hair/characters, and publish experiences.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @liforma/publisher
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createPublisher } from '@liforma/publisher';
|
|
11
|
+
|
|
12
|
+
const publisher = createPublisher(process.env.LIFORMA_PROJECT_ID!, {
|
|
13
|
+
apiKey: process.env.LIFORMA_API_KEY!
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const background = await publisher.uploadImage(lobbyPng, { contentType: 'image/png' });
|
|
17
|
+
const location = await publisher.createLocation({ name: 'Hotel lobby', image: background });
|
|
18
|
+
const place = await publisher.createPlace({ name: 'Hotel lobby', locationId: location.id });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Use a **live** API key on the server only. Never ship this package or the key to a browser.
|
|
22
|
+
|
|
23
|
+
Docs (alpha): https://docs.liforma.ai/_alpha/publisher-sdk
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { type WaitOptions } from './jobs.js';
|
|
2
|
+
import { type AuthoringAvatar, type AuthoringJob, type CharacterResource, type ClothesResource, type CreatePublishResponse, type ExperienceResource, type HairResource, type LocationResource, type PlaceResource } from './schemas.js';
|
|
3
|
+
import type { ImageBytes } from './hash.js';
|
|
4
|
+
import { type UploadedImage } from './upload.js';
|
|
5
|
+
export type CreatePublisherOptions = {
|
|
6
|
+
readonly apiKey?: string;
|
|
7
|
+
readonly baseUrl?: string;
|
|
8
|
+
readonly fetch?: typeof fetch;
|
|
9
|
+
};
|
|
10
|
+
export type BackgroundMode = 'remove' | 'transparent';
|
|
11
|
+
export type PollableCreateOptions = WaitOptions & {
|
|
12
|
+
readonly externalId?: string;
|
|
13
|
+
};
|
|
14
|
+
export type CreateClothesInput = PollableCreateOptions & {
|
|
15
|
+
readonly avatarId: string;
|
|
16
|
+
readonly image: UploadedImage | string;
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
readonly backgroundMode?: BackgroundMode;
|
|
19
|
+
};
|
|
20
|
+
export type CreateHairInput = CreateClothesInput;
|
|
21
|
+
export type CreateLocationInput = PollableCreateOptions & {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly image: UploadedImage | string;
|
|
24
|
+
readonly depth?: {
|
|
25
|
+
readonly image: UploadedImage | string;
|
|
26
|
+
readonly depthMapType?: 'disparity';
|
|
27
|
+
readonly metersPerDepth?: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export type CreatePlaceInput = {
|
|
31
|
+
readonly locationId: string;
|
|
32
|
+
readonly name?: string;
|
|
33
|
+
readonly externalId?: string;
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
};
|
|
36
|
+
export type CreateCharacterInput = {
|
|
37
|
+
readonly avatarId: string;
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly voice: string;
|
|
40
|
+
readonly sttLang: string;
|
|
41
|
+
readonly clothesId?: string;
|
|
42
|
+
readonly hairId?: string;
|
|
43
|
+
readonly personality?: string;
|
|
44
|
+
readonly generalInstructions?: string;
|
|
45
|
+
readonly externalId?: string;
|
|
46
|
+
readonly signal?: AbortSignal;
|
|
47
|
+
};
|
|
48
|
+
export type CreateExperienceInput = {
|
|
49
|
+
readonly title: string;
|
|
50
|
+
readonly characterId: string;
|
|
51
|
+
readonly placeId: string;
|
|
52
|
+
readonly slug?: string;
|
|
53
|
+
readonly attributes?: Record<string, string>;
|
|
54
|
+
readonly startingMessage?: string;
|
|
55
|
+
readonly systemInstructions?: string;
|
|
56
|
+
readonly introduction?: string;
|
|
57
|
+
readonly publish?: boolean;
|
|
58
|
+
readonly externalId?: string;
|
|
59
|
+
readonly signal?: AbortSignal;
|
|
60
|
+
};
|
|
61
|
+
export type UpdateExperienceInput = {
|
|
62
|
+
readonly title?: string;
|
|
63
|
+
readonly slug?: string;
|
|
64
|
+
readonly attributes?: Record<string, string>;
|
|
65
|
+
readonly signal?: AbortSignal;
|
|
66
|
+
};
|
|
67
|
+
export declare function createPublisher(projectId: string, options?: CreatePublisherOptions): {
|
|
68
|
+
projectId: string;
|
|
69
|
+
baseUrl: string;
|
|
70
|
+
uploadImage: (input: ImageBytes, uploadOptions: {
|
|
71
|
+
contentType: string;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}) => Promise<UploadedImage>;
|
|
74
|
+
uploadDepthMap: (input: ImageBytes, uploadOptions: {
|
|
75
|
+
contentType: string;
|
|
76
|
+
signal?: AbortSignal;
|
|
77
|
+
}) => Promise<UploadedImage>;
|
|
78
|
+
listAvatars: (signal?: AbortSignal) => Promise<AuthoringAvatar[]>;
|
|
79
|
+
startClothes: (input: CreateClothesInput) => Promise<CreatePublishResponse>;
|
|
80
|
+
createClothes: (input: CreateClothesInput) => Promise<ClothesResource>;
|
|
81
|
+
getClothes: (clothesId: string, signal?: AbortSignal) => Promise<{
|
|
82
|
+
kind: "clothes";
|
|
83
|
+
id: string;
|
|
84
|
+
avatarId: string;
|
|
85
|
+
name: string;
|
|
86
|
+
status: string;
|
|
87
|
+
source: string;
|
|
88
|
+
renderKind: string;
|
|
89
|
+
catalogueKey: string | null;
|
|
90
|
+
assetPath: string | null;
|
|
91
|
+
externalId: string | null;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
updatedAt: string;
|
|
94
|
+
}>;
|
|
95
|
+
startHair: (input: CreateHairInput) => Promise<CreatePublishResponse>;
|
|
96
|
+
createHair: (input: CreateHairInput) => Promise<HairResource>;
|
|
97
|
+
getHair: (hairId: string, signal?: AbortSignal) => Promise<{
|
|
98
|
+
kind: "hair";
|
|
99
|
+
id: string;
|
|
100
|
+
avatarId: string;
|
|
101
|
+
name: string;
|
|
102
|
+
status: string;
|
|
103
|
+
source: string;
|
|
104
|
+
catalogueKey: string | null;
|
|
105
|
+
assetPath: string | null;
|
|
106
|
+
externalId: string | null;
|
|
107
|
+
createdAt: string;
|
|
108
|
+
updatedAt: string;
|
|
109
|
+
}>;
|
|
110
|
+
startLocation: (input: CreateLocationInput) => Promise<CreatePublishResponse>;
|
|
111
|
+
createLocation: (input: CreateLocationInput) => Promise<LocationResource>;
|
|
112
|
+
getLocation: (locationId: string, signal?: AbortSignal) => Promise<{
|
|
113
|
+
kind: "location";
|
|
114
|
+
id: string;
|
|
115
|
+
status: string;
|
|
116
|
+
name: string;
|
|
117
|
+
depthEncoding: string | null;
|
|
118
|
+
externalId: string | null;
|
|
119
|
+
}>;
|
|
120
|
+
createPlace: (input: CreatePlaceInput) => Promise<PlaceResource>;
|
|
121
|
+
createCharacter: (input: CreateCharacterInput) => Promise<CharacterResource>;
|
|
122
|
+
createExperience: (input: CreateExperienceInput) => Promise<ExperienceResource>;
|
|
123
|
+
getExperience: (experienceId: string, signal?: AbortSignal) => Promise<ExperienceResource>;
|
|
124
|
+
updateExperience: (experienceId: string, input: UpdateExperienceInput) => Promise<ExperienceResource>;
|
|
125
|
+
publishExperience: (experienceId: string, signal?: AbortSignal) => Promise<ExperienceResource>;
|
|
126
|
+
jobs: {
|
|
127
|
+
get: (jobId: string, signal?: AbortSignal) => Promise<{
|
|
128
|
+
id: string;
|
|
129
|
+
status: "queued" | "running" | "waiting_processor" | "succeeded" | "failed";
|
|
130
|
+
kind: "location" | "clothes" | "hair";
|
|
131
|
+
pollUrl: string;
|
|
132
|
+
targetId: string;
|
|
133
|
+
requiredOk: boolean;
|
|
134
|
+
claimCount: number;
|
|
135
|
+
failureCount: number;
|
|
136
|
+
nextRunAt: string | null;
|
|
137
|
+
stage: string | null;
|
|
138
|
+
progress: {
|
|
139
|
+
requiredVerified: number;
|
|
140
|
+
requiredTotal: number;
|
|
141
|
+
};
|
|
142
|
+
error: {
|
|
143
|
+
code: string;
|
|
144
|
+
message: string;
|
|
145
|
+
} | null;
|
|
146
|
+
enrichment: {
|
|
147
|
+
status: "running" | "failed" | "pending" | "complete" | "not_applicable";
|
|
148
|
+
verified: number;
|
|
149
|
+
total: number;
|
|
150
|
+
error: {
|
|
151
|
+
code: string;
|
|
152
|
+
message: string;
|
|
153
|
+
} | null;
|
|
154
|
+
};
|
|
155
|
+
}>;
|
|
156
|
+
wait: (jobId: string, waitOptions?: WaitOptions) => Promise<{
|
|
157
|
+
id: string;
|
|
158
|
+
status: "queued" | "running" | "waiting_processor" | "succeeded" | "failed";
|
|
159
|
+
kind: "location" | "clothes" | "hair";
|
|
160
|
+
pollUrl: string;
|
|
161
|
+
targetId: string;
|
|
162
|
+
requiredOk: boolean;
|
|
163
|
+
claimCount: number;
|
|
164
|
+
failureCount: number;
|
|
165
|
+
nextRunAt: string | null;
|
|
166
|
+
stage: string | null;
|
|
167
|
+
progress: {
|
|
168
|
+
requiredVerified: number;
|
|
169
|
+
requiredTotal: number;
|
|
170
|
+
};
|
|
171
|
+
error: {
|
|
172
|
+
code: string;
|
|
173
|
+
message: string;
|
|
174
|
+
} | null;
|
|
175
|
+
enrichment: {
|
|
176
|
+
status: "running" | "failed" | "pending" | "complete" | "not_applicable";
|
|
177
|
+
verified: number;
|
|
178
|
+
total: number;
|
|
179
|
+
error: {
|
|
180
|
+
code: string;
|
|
181
|
+
message: string;
|
|
182
|
+
} | null;
|
|
183
|
+
};
|
|
184
|
+
}>;
|
|
185
|
+
watch: (jobId: string, waitOptions?: WaitOptions) => AsyncGenerator<{
|
|
186
|
+
id: string;
|
|
187
|
+
status: "queued" | "running" | "waiting_processor" | "succeeded" | "failed";
|
|
188
|
+
kind: "location" | "clothes" | "hair";
|
|
189
|
+
pollUrl: string;
|
|
190
|
+
targetId: string;
|
|
191
|
+
requiredOk: boolean;
|
|
192
|
+
claimCount: number;
|
|
193
|
+
failureCount: number;
|
|
194
|
+
nextRunAt: string | null;
|
|
195
|
+
stage: string | null;
|
|
196
|
+
progress: {
|
|
197
|
+
requiredVerified: number;
|
|
198
|
+
requiredTotal: number;
|
|
199
|
+
};
|
|
200
|
+
error: {
|
|
201
|
+
code: string;
|
|
202
|
+
message: string;
|
|
203
|
+
} | null;
|
|
204
|
+
enrichment: {
|
|
205
|
+
status: "running" | "failed" | "pending" | "complete" | "not_applicable";
|
|
206
|
+
verified: number;
|
|
207
|
+
total: number;
|
|
208
|
+
error: {
|
|
209
|
+
code: string;
|
|
210
|
+
message: string;
|
|
211
|
+
} | null;
|
|
212
|
+
};
|
|
213
|
+
}, {
|
|
214
|
+
id: string;
|
|
215
|
+
status: "queued" | "running" | "waiting_processor" | "succeeded" | "failed";
|
|
216
|
+
kind: "location" | "clothes" | "hair";
|
|
217
|
+
pollUrl: string;
|
|
218
|
+
targetId: string;
|
|
219
|
+
requiredOk: boolean;
|
|
220
|
+
claimCount: number;
|
|
221
|
+
failureCount: number;
|
|
222
|
+
nextRunAt: string | null;
|
|
223
|
+
stage: string | null;
|
|
224
|
+
progress: {
|
|
225
|
+
requiredVerified: number;
|
|
226
|
+
requiredTotal: number;
|
|
227
|
+
};
|
|
228
|
+
error: {
|
|
229
|
+
code: string;
|
|
230
|
+
message: string;
|
|
231
|
+
} | null;
|
|
232
|
+
enrichment: {
|
|
233
|
+
status: "running" | "failed" | "pending" | "complete" | "not_applicable";
|
|
234
|
+
verified: number;
|
|
235
|
+
total: number;
|
|
236
|
+
error: {
|
|
237
|
+
code: string;
|
|
238
|
+
message: string;
|
|
239
|
+
} | null;
|
|
240
|
+
};
|
|
241
|
+
}, void>;
|
|
242
|
+
retry: (jobId: string, signal?: AbortSignal) => Promise<{
|
|
243
|
+
job: {
|
|
244
|
+
id: string;
|
|
245
|
+
status: "queued" | "running" | "waiting_processor" | "succeeded" | "failed";
|
|
246
|
+
kind: "location" | "clothes" | "hair";
|
|
247
|
+
pollUrl: string;
|
|
248
|
+
targetId: string;
|
|
249
|
+
requiredOk: boolean;
|
|
250
|
+
claimCount: number;
|
|
251
|
+
failureCount: number;
|
|
252
|
+
nextRunAt: string | null;
|
|
253
|
+
stage: string | null;
|
|
254
|
+
progress: {
|
|
255
|
+
requiredVerified: number;
|
|
256
|
+
requiredTotal: number;
|
|
257
|
+
};
|
|
258
|
+
error: {
|
|
259
|
+
code: string;
|
|
260
|
+
message: string;
|
|
261
|
+
} | null;
|
|
262
|
+
enrichment: {
|
|
263
|
+
status: "running" | "failed" | "pending" | "complete" | "not_applicable";
|
|
264
|
+
verified: number;
|
|
265
|
+
total: number;
|
|
266
|
+
error: {
|
|
267
|
+
code: string;
|
|
268
|
+
message: string;
|
|
269
|
+
} | null;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
resource: {
|
|
273
|
+
kind: "location" | "clothes" | "hair";
|
|
274
|
+
id: string;
|
|
275
|
+
status: string;
|
|
276
|
+
};
|
|
277
|
+
}>;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
export type Publisher = ReturnType<typeof createPublisher>;
|
|
281
|
+
export type { AuthoringJob, UploadedImage, WaitOptions };
|
|
282
|
+
//# source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G,OAAO,CAAC,YAAY,CAAC;sBAe/C,MAAM,WAAW,WAAW;;;;;;;;;;;;;2BAEjB,mBAAmB,KAAG,OAAO,CAAC,qBAAqB,CAAC;4BAyBnD,mBAAmB,KAAG,OAAO,CAAC,gBAAgB,CAAC;8BA0BnD,MAAM,WAAW,WAAW;;;;;;;;yBAE3B,gBAAgB,KAAG,OAAO,CAAC,aAAa,CAAC;6BAkBrC,oBAAoB,KAAG,OAAO,CAAC,iBAAiB,CAAC;8BA0BhD,qBAAqB,KAAG,OAAO,CAAC,kBAAkB,CAAC;kCA2B/C,MAAM,WAAW,WAAW,KAAG,OAAO,CAAC,kBAAkB,CAAC;qCAW/E,MAAM,SACb,qBAAqB,KAC1B,OAAO,CAAC,kBAAkB,CAAC;sCAmBf,MAAM,WACX,WAAW,KAClB,OAAO,CAAC,kBAAkB,CAAC;;qBAtPjB,MAAM,WAAW,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAC3B,MAAM,gBAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAChC,MAAM,gBAAgB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBACjC,MAAM,WAAW,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+P5C;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { LiformaPublisherError } from './errors.js';
|
|
2
|
+
import { projectPath, publisherRequest } from './http.js';
|
|
3
|
+
import { getClothes, getHair, getJob, getLocation, retryJob, waitForJob, watchJob } from './jobs.js';
|
|
4
|
+
import { assertServerRuntime, resolveApiKey, resolveBaseUrl } from './runtime.js';
|
|
5
|
+
import { createCharacterResponseSchema, createPlaceResponseSchema, createPublishResponseSchema, experienceResponseSchema, listAvatarsResponseSchema } from './schemas.js';
|
|
6
|
+
import { uploadDepthMap, uploadImage, uploadIdFromImage } from './upload.js';
|
|
7
|
+
function httpFrom(projectId, options = {}) {
|
|
8
|
+
assertServerRuntime();
|
|
9
|
+
const id = projectId.trim();
|
|
10
|
+
if (!id) {
|
|
11
|
+
throw new LiformaPublisherError('projectId is required.', { code: 'INVALID_PROJECT_ID' });
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
projectId: id,
|
|
15
|
+
apiKey: resolveApiKey(options.apiKey),
|
|
16
|
+
baseUrl: resolveBaseUrl(options.baseUrl),
|
|
17
|
+
fetchImpl: options.fetch ?? globalThis.fetch.bind(globalThis)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async function startPublish(http, kind, body, signal) {
|
|
21
|
+
const path = kind === 'clothes' ? '/clothes' : kind === 'hair' ? '/hair' : '/locations';
|
|
22
|
+
const { data } = await publisherRequest(http, projectPath(http, path), createPublishResponseSchema, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
body,
|
|
25
|
+
signal
|
|
26
|
+
});
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
async function createAndWaitResource(http, kind, body, fetchReady, options) {
|
|
30
|
+
const started = await startPublish(http, kind, body, options.signal);
|
|
31
|
+
const job = await waitForJob(http, started.job.id, options);
|
|
32
|
+
return fetchReady(job.targetId, options.signal);
|
|
33
|
+
}
|
|
34
|
+
export function createPublisher(projectId, options = {}) {
|
|
35
|
+
const http = httpFrom(projectId, options);
|
|
36
|
+
const jobs = {
|
|
37
|
+
get: (jobId, signal) => getJob(http, jobId, signal),
|
|
38
|
+
wait: (jobId, waitOptions) => waitForJob(http, jobId, waitOptions),
|
|
39
|
+
watch: (jobId, waitOptions) => watchJob(http, jobId, waitOptions),
|
|
40
|
+
retry: (jobId, signal) => retryJob(http, jobId, signal)
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
projectId: http.projectId,
|
|
44
|
+
baseUrl: http.baseUrl,
|
|
45
|
+
uploadImage: (input, uploadOptions) => uploadImage(http, input, uploadOptions),
|
|
46
|
+
uploadDepthMap: (input, uploadOptions) => uploadDepthMap(http, input, uploadOptions),
|
|
47
|
+
listAvatars: async (signal) => {
|
|
48
|
+
const { data } = await publisherRequest(http, projectPath(http, '/avatars'), listAvatarsResponseSchema, { method: 'GET', signal, retry: true });
|
|
49
|
+
return data.avatars;
|
|
50
|
+
},
|
|
51
|
+
startClothes: async (input) => startPublish(http, 'clothes', {
|
|
52
|
+
avatarId: input.avatarId,
|
|
53
|
+
uploadId: uploadIdFromImage(input.image),
|
|
54
|
+
...(input.name !== undefined ? { name: input.name } : {}),
|
|
55
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {}),
|
|
56
|
+
...(input.backgroundMode !== undefined ? { backgroundMode: input.backgroundMode } : {})
|
|
57
|
+
}, input.signal),
|
|
58
|
+
createClothes: async (input) => createAndWaitResource(http, 'clothes', {
|
|
59
|
+
avatarId: input.avatarId,
|
|
60
|
+
uploadId: uploadIdFromImage(input.image),
|
|
61
|
+
...(input.name !== undefined ? { name: input.name } : {}),
|
|
62
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {}),
|
|
63
|
+
...(input.backgroundMode !== undefined ? { backgroundMode: input.backgroundMode } : {})
|
|
64
|
+
}, (id, signal) => getClothes(http, id, signal), input),
|
|
65
|
+
getClothes: (clothesId, signal) => getClothes(http, clothesId, signal),
|
|
66
|
+
startHair: async (input) => startPublish(http, 'hair', {
|
|
67
|
+
avatarId: input.avatarId,
|
|
68
|
+
uploadId: uploadIdFromImage(input.image),
|
|
69
|
+
...(input.name !== undefined ? { name: input.name } : {}),
|
|
70
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {}),
|
|
71
|
+
...(input.backgroundMode !== undefined ? { backgroundMode: input.backgroundMode } : {})
|
|
72
|
+
}, input.signal),
|
|
73
|
+
createHair: async (input) => createAndWaitResource(http, 'hair', {
|
|
74
|
+
avatarId: input.avatarId,
|
|
75
|
+
uploadId: uploadIdFromImage(input.image),
|
|
76
|
+
...(input.name !== undefined ? { name: input.name } : {}),
|
|
77
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {}),
|
|
78
|
+
...(input.backgroundMode !== undefined ? { backgroundMode: input.backgroundMode } : {})
|
|
79
|
+
}, (id, signal) => getHair(http, id, signal), input),
|
|
80
|
+
getHair: (hairId, signal) => getHair(http, hairId, signal),
|
|
81
|
+
startLocation: async (input) => startPublish(http, 'location', {
|
|
82
|
+
name: input.name,
|
|
83
|
+
uploadId: uploadIdFromImage(input.image),
|
|
84
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {}),
|
|
85
|
+
...(input.depth
|
|
86
|
+
? {
|
|
87
|
+
depth: {
|
|
88
|
+
uploadId: uploadIdFromImage(input.depth.image),
|
|
89
|
+
...(input.depth.depthMapType !== undefined
|
|
90
|
+
? { depthMapType: input.depth.depthMapType }
|
|
91
|
+
: {}),
|
|
92
|
+
...(input.depth.metersPerDepth !== undefined
|
|
93
|
+
? { metersPerDepth: input.depth.metersPerDepth }
|
|
94
|
+
: {})
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
: {})
|
|
98
|
+
}, input.signal),
|
|
99
|
+
createLocation: async (input) => createAndWaitResource(http, 'location', {
|
|
100
|
+
name: input.name,
|
|
101
|
+
uploadId: uploadIdFromImage(input.image),
|
|
102
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {}),
|
|
103
|
+
...(input.depth
|
|
104
|
+
? {
|
|
105
|
+
depth: {
|
|
106
|
+
uploadId: uploadIdFromImage(input.depth.image),
|
|
107
|
+
...(input.depth.depthMapType !== undefined
|
|
108
|
+
? { depthMapType: input.depth.depthMapType }
|
|
109
|
+
: {}),
|
|
110
|
+
...(input.depth.metersPerDepth !== undefined
|
|
111
|
+
? { metersPerDepth: input.depth.metersPerDepth }
|
|
112
|
+
: {})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
: {})
|
|
116
|
+
}, (id, signal) => getLocation(http, id, signal), input),
|
|
117
|
+
getLocation: (locationId, signal) => getLocation(http, locationId, signal),
|
|
118
|
+
createPlace: async (input) => {
|
|
119
|
+
const { data } = await publisherRequest(http, projectPath(http, '/places'), createPlaceResponseSchema, {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
body: {
|
|
122
|
+
locationId: input.locationId,
|
|
123
|
+
...(input.name !== undefined ? { name: input.name } : {}),
|
|
124
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {})
|
|
125
|
+
},
|
|
126
|
+
signal: input.signal
|
|
127
|
+
});
|
|
128
|
+
return data.place;
|
|
129
|
+
},
|
|
130
|
+
createCharacter: async (input) => {
|
|
131
|
+
const { data } = await publisherRequest(http, projectPath(http, '/characters'), createCharacterResponseSchema, {
|
|
132
|
+
method: 'POST',
|
|
133
|
+
body: {
|
|
134
|
+
avatarId: input.avatarId,
|
|
135
|
+
name: input.name,
|
|
136
|
+
voice: input.voice,
|
|
137
|
+
sttLang: input.sttLang,
|
|
138
|
+
...(input.clothesId !== undefined ? { clothesId: input.clothesId } : {}),
|
|
139
|
+
...(input.hairId !== undefined ? { hairId: input.hairId } : {}),
|
|
140
|
+
...(input.personality !== undefined ? { personality: input.personality } : {}),
|
|
141
|
+
...(input.generalInstructions !== undefined
|
|
142
|
+
? { generalInstructions: input.generalInstructions }
|
|
143
|
+
: {}),
|
|
144
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {})
|
|
145
|
+
},
|
|
146
|
+
signal: input.signal
|
|
147
|
+
});
|
|
148
|
+
return data.character;
|
|
149
|
+
},
|
|
150
|
+
createExperience: async (input) => {
|
|
151
|
+
const { data } = await publisherRequest(http, projectPath(http, '/experiences'), experienceResponseSchema, {
|
|
152
|
+
method: 'POST',
|
|
153
|
+
body: {
|
|
154
|
+
title: input.title,
|
|
155
|
+
characterId: input.characterId,
|
|
156
|
+
placeId: input.placeId,
|
|
157
|
+
...(input.slug !== undefined ? { slug: input.slug } : {}),
|
|
158
|
+
...(input.attributes !== undefined ? { attributes: input.attributes } : {}),
|
|
159
|
+
...(input.startingMessage !== undefined ? { startingMessage: input.startingMessage } : {}),
|
|
160
|
+
...(input.systemInstructions !== undefined
|
|
161
|
+
? { systemInstructions: input.systemInstructions }
|
|
162
|
+
: {}),
|
|
163
|
+
...(input.introduction !== undefined ? { introduction: input.introduction } : {}),
|
|
164
|
+
...(input.publish !== undefined ? { publish: input.publish } : {}),
|
|
165
|
+
...(input.externalId !== undefined ? { externalId: input.externalId } : {})
|
|
166
|
+
},
|
|
167
|
+
signal: input.signal
|
|
168
|
+
});
|
|
169
|
+
return data.experience;
|
|
170
|
+
},
|
|
171
|
+
getExperience: async (experienceId, signal) => {
|
|
172
|
+
const { data } = await publisherRequest(http, `/v1/experiences/${encodeURIComponent(experienceId)}`, experienceResponseSchema, { method: 'GET', signal, retry: true });
|
|
173
|
+
return data.experience;
|
|
174
|
+
},
|
|
175
|
+
updateExperience: async (experienceId, input) => {
|
|
176
|
+
const { data } = await publisherRequest(http, `/v1/experiences/${encodeURIComponent(experienceId)}`, experienceResponseSchema, {
|
|
177
|
+
method: 'PATCH',
|
|
178
|
+
body: {
|
|
179
|
+
...(input.title !== undefined ? { title: input.title } : {}),
|
|
180
|
+
...(input.slug !== undefined ? { slug: input.slug } : {}),
|
|
181
|
+
...(input.attributes !== undefined ? { attributes: input.attributes } : {})
|
|
182
|
+
},
|
|
183
|
+
signal: input.signal
|
|
184
|
+
});
|
|
185
|
+
return data.experience;
|
|
186
|
+
},
|
|
187
|
+
publishExperience: async (experienceId, signal) => {
|
|
188
|
+
const { data } = await publisherRequest(http, `/v1/experiences/${encodeURIComponent(experienceId)}/publish`, experienceResponseSchema, { method: 'POST', signal });
|
|
189
|
+
return data.experience;
|
|
190
|
+
},
|
|
191
|
+
jobs
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=createPublisher.js.map
|
|
@@ -0,0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AAM,EAAE,KAAK,CAAC,MAAM;aACpB,CACD,CAAC;YACF,OAAO,IAAI,CAAC,UAAU,CAAC;QACxB,CAAC;QAED,iBAAiB,EAAE,KAAK,EACvB,YAAoB,EACpB,MAAoB,EACU,EAAE;YAChC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,gBAAgB,CACtC,IAAI,EACJ,mBAAmB,kBAAkB,CAAC,YAAY,CAAC,UAAU,EAC7D,wBAAwB,EACxB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAC1B,CAAC;YACF,OAAO,IAAI,CAAC,UAAU,CAAC;QACxB,CAAC;QAED,IAAI;KACJ,CAAC;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class LiformaPublisherError extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
readonly status: number | undefined;
|
|
4
|
+
readonly requestId: string | undefined;
|
|
5
|
+
readonly details: Record<string, unknown> | undefined;
|
|
6
|
+
readonly retryable: boolean;
|
|
7
|
+
readonly job: Record<string, unknown> | undefined;
|
|
8
|
+
constructor(message: string, options?: {
|
|
9
|
+
readonly code?: string;
|
|
10
|
+
readonly status?: number;
|
|
11
|
+
readonly requestId?: string;
|
|
12
|
+
readonly details?: Record<string, unknown>;
|
|
13
|
+
readonly retryable?: boolean;
|
|
14
|
+
readonly job?: Record<string, unknown>;
|
|
15
|
+
readonly cause?: unknown;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export declare function isRetryableStatus(status: number | undefined): boolean;
|
|
19
|
+
export declare function isRetryableError(error: LiformaPublisherError): boolean;
|
|
20
|
+
export declare function publisherErrorFromResponse(status: number, text: string, headers?: Headers): LiformaPublisherError;
|
|
21
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,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;
|
|
4
|
+
requestId;
|
|
5
|
+
details;
|
|
6
|
+
retryable;
|
|
7
|
+
job;
|
|
8
|
+
constructor(message, options) {
|
|
9
|
+
super(message, options?.cause !== undefined ? { cause: options.cause } : undefined);
|
|
10
|
+
this.name = 'LiformaPublisherError';
|
|
11
|
+
this.code = options?.code?.trim() || 'UNKNOWN';
|
|
12
|
+
this.status = options?.status;
|
|
13
|
+
this.requestId = options?.requestId?.trim() || undefined;
|
|
14
|
+
this.details = options?.details;
|
|
15
|
+
this.retryable = Boolean(options?.retryable);
|
|
16
|
+
this.job = options?.job;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const RETRYABLE_CODES = new Set([
|
|
20
|
+
'DATABASE_UNAVAILABLE',
|
|
21
|
+
'JOB_RUNNER_UNAVAILABLE',
|
|
22
|
+
'PROCESSOR_FAILED',
|
|
23
|
+
'HTTP_ERROR'
|
|
24
|
+
]);
|
|
25
|
+
export function isRetryableStatus(status) {
|
|
26
|
+
return status === 408 || status === 429 || (typeof status === 'number' && status >= 500);
|
|
27
|
+
}
|
|
28
|
+
export function isRetryableError(error) {
|
|
29
|
+
if (error.retryable)
|
|
30
|
+
return true;
|
|
31
|
+
if (RETRYABLE_CODES.has(error.code))
|
|
32
|
+
return true;
|
|
33
|
+
return isRetryableStatus(error.status);
|
|
34
|
+
}
|
|
35
|
+
export function publisherErrorFromResponse(status, text, headers) {
|
|
36
|
+
const headerRequestId = headers?.get('Liforma-Request-Id')?.trim() || undefined;
|
|
37
|
+
let parsed = null;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(text);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
/* keep */
|
|
43
|
+
}
|
|
44
|
+
const nested = parsed?.error && typeof parsed.error === 'object' ? parsed.error : undefined;
|
|
45
|
+
const codeRaw = nested?.code ?? parsed?.code;
|
|
46
|
+
const messageRaw = nested?.message ?? parsed?.message;
|
|
47
|
+
const requestIdRaw = nested?.requestId ?? parsed?.requestId ?? headerRequestId;
|
|
48
|
+
const code = typeof codeRaw === 'string' && codeRaw.trim() ? codeRaw.trim() : 'HTTP_ERROR';
|
|
49
|
+
const message = typeof messageRaw === 'string' && messageRaw.trim()
|
|
50
|
+
? messageRaw.trim()
|
|
51
|
+
: text.trim().slice(0, 500) || `Request failed (${status})`;
|
|
52
|
+
const requestId = typeof requestIdRaw === 'string' && requestIdRaw.trim() ? requestIdRaw.trim() : headerRequestId;
|
|
53
|
+
const details = nested && typeof nested === 'object'
|
|
54
|
+
? Object.fromEntries(Object.entries(nested).filter(([key]) => !['code', 'message', 'requestId'].includes(key)))
|
|
55
|
+
: undefined;
|
|
56
|
+
return new LiformaPublisherError(message, {
|
|
57
|
+
code,
|
|
58
|
+
status,
|
|
59
|
+
requestId,
|
|
60
|
+
details: details && Object.keys(details).length > 0 ? details : undefined,
|
|
61
|
+
retryable: isRetryableStatus(status)
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IACtC,IAAI,CAAS;IACb,MAAM,CAAqB;IAC3B,SAAS,CAAqB;IAC9B,OAAO,CAAsC;IAC7C,SAAS,CAAU;IACnB,GAAG,CAAsC;IAElD,YACC,OAAe,EACf,OAQC;QAED,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACpF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MA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