@alpha2-sh/editor 0.6.1 → 0.7.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/README.md +5 -4
- package/dist/browser/bridge.js +187 -27
- package/dist/browser/extensions-worker.js +2 -1
- package/dist/browser/extract-worker-entry.d.ts +1 -0
- package/dist/browser/extract-worker-entry.js +3 -0
- package/dist/browser/extract-worker.d.ts +44 -0
- package/dist/browser/extract-worker.js +172 -0
- package/dist/browser/hash-worker.js +2 -1
- package/dist/browser/runtime/assets.d.ts +2 -2
- package/dist/browser/runtime/assets.js +11 -7
- package/dist/browser/runtime/engine.d.ts +7 -0
- package/dist/browser/runtime/engine.js +16 -0
- package/dist/browser/runtime/exporter.js +4 -2
- package/dist/browser/runtime/extension-import.js +2 -1
- package/dist/browser/runtime/fingerprint.js +3 -2
- package/dist/browser/runtime/media-reference.d.ts +6 -0
- package/dist/browser/runtime/media-reference.js +40 -0
- package/dist/browser/runtime/proxies.js +3 -2
- package/dist/browser/runtime/range-file.d.ts +37 -0
- package/dist/browser/runtime/range-file.js +123 -0
- package/dist/browser/runtime/still.js +2 -1
- package/dist/browser/types.d.ts +97 -21
- package/dist/browser/worker.js +2 -1
- package/dist/native-client/index.d.ts +12 -5
- package/dist/native-client/index.js +82 -25
- package/package.json +9 -4
|
@@ -5,10 +5,12 @@ import { type ExportFailure } from "alpha2/export-failure";
|
|
|
5
5
|
import { ExportJob } from "../browser/jobs.js";
|
|
6
6
|
import type { BrowserExportOptions } from "../browser/types.js";
|
|
7
7
|
/**
|
|
8
|
-
* A file
|
|
9
|
-
*
|
|
8
|
+
* A file a native export reads, usually from the browser bridge's `nativeAssets`: its bytes,
|
|
9
|
+
* uploaded to the service (`blob`), or a `path` on the service's machine, sent in the render
|
|
10
|
+
* request's `paths` (`{ [kind]: { [id]: path } }`) and never uploaded. The host reads media only
|
|
11
|
+
* from these, never from a path the document names.
|
|
10
12
|
*/
|
|
11
|
-
export
|
|
13
|
+
export type NativeAsset = {
|
|
12
14
|
/** The source, resource or font id the file belongs to (for `frames`, the upload's own id). */
|
|
13
15
|
readonly id: string;
|
|
14
16
|
/**
|
|
@@ -16,12 +18,17 @@ export interface NativeAsset {
|
|
|
16
18
|
* the file at `locator`.
|
|
17
19
|
*/
|
|
18
20
|
readonly kind: "assets" | "effect-assets" | "caption-fonts" | "proxies" | "frames";
|
|
19
|
-
readonly blob: Blob;
|
|
20
21
|
/** The original file name, sent to the host percent-encoded. */
|
|
21
22
|
readonly name: string;
|
|
22
23
|
readonly madeFrom?: MediaFingerprint;
|
|
23
24
|
readonly locator?: string;
|
|
24
|
-
}
|
|
25
|
+
} & ({
|
|
26
|
+
readonly blob: Blob;
|
|
27
|
+
readonly path?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly blob?: undefined;
|
|
31
|
+
});
|
|
25
32
|
/**
|
|
26
33
|
* Export settings for a native job: the browser export's options plus the MPEG-4 Part 2 codec the
|
|
27
34
|
* host can encode. An absent `container`, `videoCodec` or `audioCodec` takes the host's default, as
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compileEditorDocument, EditorError, sequenceEnd, } from "../core/document.js";
|
|
2
|
-
import { ExportFailureError } from "alpha2/export-failure";
|
|
2
|
+
import { ExportFailureError, failureClassOfHttpStatus, } from "alpha2/export-failure";
|
|
3
3
|
import { ExportJob, requireExportFrameRate } from "../browser/jobs.js";
|
|
4
4
|
/**
|
|
5
5
|
* Asks the service whether an artifact's `url` can still be downloaded, without downloading it.
|
|
@@ -46,6 +46,46 @@ function nativeFailure(state, jobId) {
|
|
|
46
46
|
};
|
|
47
47
|
return new ExportFailureError({ ...failure, message, jobId });
|
|
48
48
|
}
|
|
49
|
+
async function serviceFailure(response, context) {
|
|
50
|
+
const text = await response.text().catch(() => "");
|
|
51
|
+
let detail = {};
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(text);
|
|
54
|
+
if (typeof parsed === "object" && parsed !== null)
|
|
55
|
+
detail = parsed;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// A body that is not JSON is the message itself.
|
|
59
|
+
}
|
|
60
|
+
const { code, resource } = failureClassOfHttpStatus(response.status);
|
|
61
|
+
const retryAfterMs = Number(response.headers.get("retry-after")) * 1000;
|
|
62
|
+
return new ExportFailureError({
|
|
63
|
+
code,
|
|
64
|
+
message: `Native host: ${typeof detail.error === "string" ? detail.error : text || response.status}`,
|
|
65
|
+
origin: "browser",
|
|
66
|
+
operation: "export",
|
|
67
|
+
backend: "native",
|
|
68
|
+
phase: "prepare",
|
|
69
|
+
stage: context.stage,
|
|
70
|
+
resource,
|
|
71
|
+
jobId: context.jobId,
|
|
72
|
+
attemptId: context.attemptId,
|
|
73
|
+
...(code === "RESOURCE_BUSY" && retryAfterMs > 0 ? { retryAfterMs } : {}),
|
|
74
|
+
diagnostics: {
|
|
75
|
+
status: response.status,
|
|
76
|
+
...(typeof detail.limitBytes === "number"
|
|
77
|
+
? { limitBytes: detail.limitBytes }
|
|
78
|
+
: {}),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function pathsOf(assets) {
|
|
83
|
+
const paths = {};
|
|
84
|
+
for (const asset of assets)
|
|
85
|
+
if (asset.path !== undefined)
|
|
86
|
+
(paths[asset.kind] ??= {})[asset.id] = asset.path;
|
|
87
|
+
return paths;
|
|
88
|
+
}
|
|
49
89
|
/** Consecutive failed status requests before an attempt gives up on the job. */
|
|
50
90
|
const STATUS_ATTEMPTS = 5;
|
|
51
91
|
/** Status retry delay, doubled each time (0.25 s to 2 s). */
|
|
@@ -117,11 +157,37 @@ export function createNativeClient(options) {
|
|
|
117
157
|
uploaded = null;
|
|
118
158
|
posted = false;
|
|
119
159
|
};
|
|
120
|
-
const
|
|
160
|
+
const lostJob = (attempt, phase) => {
|
|
161
|
+
lost();
|
|
162
|
+
return new ExportFailureError({
|
|
163
|
+
code: "HOST_EXITED",
|
|
164
|
+
message: "The native export service lost this job; it may have restarted",
|
|
165
|
+
origin: "browser",
|
|
166
|
+
operation: "export",
|
|
167
|
+
backend: "native",
|
|
168
|
+
phase,
|
|
169
|
+
resource: "unknown",
|
|
170
|
+
jobId: id,
|
|
171
|
+
attemptId: attempt.id,
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
const jobRequest = async (suffix, init, attempt, stage) => {
|
|
175
|
+
const response = await request(`${base}${path}${suffix}`, init);
|
|
176
|
+
if (response.ok)
|
|
177
|
+
return response;
|
|
178
|
+
if (response.status === 404 && allocated)
|
|
179
|
+
throw lostJob(attempt, "prepare");
|
|
180
|
+
throw await serviceFailure(response, {
|
|
181
|
+
jobId: id,
|
|
182
|
+
attemptId: attempt.id,
|
|
183
|
+
stage,
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
const allocate = async (attempt) => {
|
|
121
187
|
// Allocate without the cancellation signal so a cancelled allocation is still acknowledged
|
|
122
188
|
// before DELETE and cannot leave an orphan job.
|
|
123
189
|
try {
|
|
124
|
-
await
|
|
190
|
+
await jobRequest("", { method: "PUT" }, attempt, "allocate");
|
|
125
191
|
}
|
|
126
192
|
catch (error) {
|
|
127
193
|
// The allocation's response was lost. The id is unique to this job, so a job there is it.
|
|
@@ -131,9 +197,9 @@ export function createNativeClient(options) {
|
|
|
131
197
|
}
|
|
132
198
|
allocated = true;
|
|
133
199
|
};
|
|
134
|
-
const upload = async (doc, signal) => {
|
|
200
|
+
const upload = async (doc, signal, attempt) => {
|
|
135
201
|
if (!allocated)
|
|
136
|
-
await allocate();
|
|
202
|
+
await allocate(attempt);
|
|
137
203
|
captured ??=
|
|
138
204
|
typeof capturedAssets === "function"
|
|
139
205
|
? await capturedAssets(doc, signal)
|
|
@@ -141,16 +207,16 @@ export function createNativeClient(options) {
|
|
|
141
207
|
signal.throwIfAborted();
|
|
142
208
|
for (const asset of captured) {
|
|
143
209
|
const key = `${asset.kind}/${asset.id}`;
|
|
144
|
-
if (acknowledged.has(key))
|
|
210
|
+
if (asset.blob === undefined || acknowledged.has(key))
|
|
145
211
|
continue;
|
|
146
|
-
await
|
|
212
|
+
await jobRequest(`/${asset.kind}/${encodeURIComponent(asset.id)}`, {
|
|
147
213
|
method: "PUT",
|
|
148
214
|
body: asset.blob,
|
|
149
215
|
signal,
|
|
150
216
|
headers: {
|
|
151
217
|
"x-alpha2-filename": encodeURIComponent(asset.name),
|
|
152
218
|
},
|
|
153
|
-
});
|
|
219
|
+
}, attempt, "upload");
|
|
154
220
|
acknowledged.add(key);
|
|
155
221
|
}
|
|
156
222
|
return {
|
|
@@ -171,20 +237,8 @@ export function createNativeClient(options) {
|
|
|
171
237
|
let failure;
|
|
172
238
|
try {
|
|
173
239
|
const response = await request(`${base}${path}`, { signal });
|
|
174
|
-
if (response.status === 404)
|
|
175
|
-
|
|
176
|
-
throw new ExportFailureError({
|
|
177
|
-
code: "HOST_EXITED",
|
|
178
|
-
message: "The native export service lost this job; it may have restarted",
|
|
179
|
-
origin: "browser",
|
|
180
|
-
operation: "export",
|
|
181
|
-
backend: "native",
|
|
182
|
-
phase: "render",
|
|
183
|
-
resource: "unknown",
|
|
184
|
-
jobId: id,
|
|
185
|
-
attemptId: attempt.id,
|
|
186
|
-
});
|
|
187
|
-
}
|
|
240
|
+
if (response.status === 404)
|
|
241
|
+
throw lostJob(attempt, "render");
|
|
188
242
|
if (response.ok)
|
|
189
243
|
return (await response.json());
|
|
190
244
|
failure = Error(`Native host: ${await response.text()}`);
|
|
@@ -200,7 +254,7 @@ export function createNativeClient(options) {
|
|
|
200
254
|
}
|
|
201
255
|
};
|
|
202
256
|
const render = async (doc, signal, progress, attempt) => {
|
|
203
|
-
uploaded ??= await upload(doc, signal);
|
|
257
|
+
uploaded ??= await upload(doc, signal, attempt);
|
|
204
258
|
const { assets: captured, frames } = uploaded;
|
|
205
259
|
const compiled = compileEditorDocument(doc);
|
|
206
260
|
const diagnostics = compiled.diagnostics;
|
|
@@ -216,7 +270,7 @@ export function createNativeClient(options) {
|
|
|
216
270
|
: false;
|
|
217
271
|
if (!running) {
|
|
218
272
|
posted = true;
|
|
219
|
-
await
|
|
273
|
+
await jobRequest("", {
|
|
220
274
|
method: "POST",
|
|
221
275
|
headers: { "content-type": "application/json" },
|
|
222
276
|
body: JSON.stringify({
|
|
@@ -227,6 +281,9 @@ export function createNativeClient(options) {
|
|
|
227
281
|
fonts: captured
|
|
228
282
|
.filter((a) => a.kind === "caption-fonts")
|
|
229
283
|
.map((a) => a.id),
|
|
284
|
+
...(captured.some((a) => a.path !== undefined)
|
|
285
|
+
? { paths: pathsOf(captured) }
|
|
286
|
+
: {}),
|
|
230
287
|
frames: Object.fromEntries(project.sources.flatMap((source) => source.provider?.format === "image_sequence"
|
|
231
288
|
? [
|
|
232
289
|
[
|
|
@@ -254,7 +311,7 @@ export function createNativeClient(options) {
|
|
|
254
311
|
: {}),
|
|
255
312
|
attempt: attempt.id,
|
|
256
313
|
}),
|
|
257
|
-
});
|
|
314
|
+
}, attempt, "submit");
|
|
258
315
|
}
|
|
259
316
|
let published;
|
|
260
317
|
for (;;) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpha2-sh/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Headless Project-based editing sessions and browser adapters for alpha2.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"sideEffects": [
|
|
20
20
|
"./dist/browser/worker-entry.js",
|
|
21
21
|
"./dist/browser/hash-worker-entry.js",
|
|
22
|
-
"./dist/browser/extensions-worker-entry.js"
|
|
22
|
+
"./dist/browser/extensions-worker-entry.js",
|
|
23
|
+
"./dist/browser/extract-worker-entry.js"
|
|
23
24
|
],
|
|
24
25
|
"files": [
|
|
25
26
|
"dist",
|
|
@@ -47,6 +48,10 @@
|
|
|
47
48
|
"types": "./dist/browser/extensions-worker-entry.d.ts",
|
|
48
49
|
"import": "./dist/browser/extensions-worker-entry.js"
|
|
49
50
|
},
|
|
51
|
+
"./extract-worker": {
|
|
52
|
+
"types": "./dist/browser/extract-worker-entry.d.ts",
|
|
53
|
+
"import": "./dist/browser/extract-worker-entry.js"
|
|
54
|
+
},
|
|
50
55
|
"./react": {
|
|
51
56
|
"types": "./dist/react/index.d.ts",
|
|
52
57
|
"import": "./dist/react/index.js"
|
|
@@ -60,11 +65,11 @@
|
|
|
60
65
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json"
|
|
61
66
|
},
|
|
62
67
|
"peerDependencies": {
|
|
63
|
-
"alpha2": "0.
|
|
68
|
+
"alpha2": "0.7.0",
|
|
64
69
|
"react": "^19.3.0"
|
|
65
70
|
},
|
|
66
71
|
"devDependencies": {
|
|
67
|
-
"alpha2": "0.
|
|
72
|
+
"alpha2": "0.7.0",
|
|
68
73
|
"react": "19.3.0",
|
|
69
74
|
"react-dom": "19.3.0",
|
|
70
75
|
"@types/react": "19.3.0",
|