@joplo-app/server 0.2.17 → 0.3.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/dist/binary-assets.d.ts +6 -0
- package/dist/binary-assets.js +25 -0
- package/dist/build.d.ts +8 -1
- package/dist/build.js +90 -5
- package/dist/cloud.d.ts +129 -2
- package/dist/cloud.js +29 -6
- package/dist/contract.d.ts +73 -0
- package/dist/dev.d.ts +3 -0
- package/dist/dev.js +140 -5
- package/dist/export.d.ts +2 -1
- package/dist/export.js +22 -3
- package/dist/film.d.ts +27 -0
- package/dist/film.js +263 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +6 -1
- package/dist/local-resources.d.ts +47 -0
- package/dist/local-resources.js +368 -0
- package/dist/local-review.js +2 -1
- package/dist/media-calibration.d.ts +8 -0
- package/dist/media-calibration.js +67 -0
- package/dist/media-check.d.ts +9 -0
- package/dist/media-check.js +56 -0
- package/dist/media-mux.d.ts +9 -0
- package/dist/media-mux.js +68 -0
- package/dist/page-report.js +9 -0
- package/dist/plugin-assets.d.ts +5 -0
- package/dist/plugin-assets.js +35 -0
- package/dist/plugin-keys.d.ts +35 -0
- package/dist/plugin-keys.js +66 -0
- package/dist/project.d.ts +10 -0
- package/dist/project.js +33 -6
- package/dist/render.d.ts +7 -1
- package/dist/render.js +80 -0
- package/dist/resources-run.d.ts +31 -0
- package/dist/resources-run.js +43 -0
- package/dist/voice-http.d.ts +53 -4
- package/dist/voice-http.js +167 -39
- package/dist/voice-run.d.ts +71 -0
- package/dist/voice-run.js +98 -0
- package/dist/voice.d.ts +188 -62
- package/dist/voice.js +492 -274
- package/dist/web-assets.js +3 -3
- package/package.json +5 -5
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Dev serves binary bytes by content hash; static builds keep data URIs for file://. */
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
export function binaryAssets(value, opts, seen = new Set()) {
|
|
6
|
+
if (typeof value === 'string' && /^data:(model\/gltf-binary|audio\/[a-z0-9.+-]+);base64,/.test(value)) {
|
|
7
|
+
const comma = value.indexOf(','), mime = value.slice(5, comma - 7), bytes = Buffer.from(value.slice(comma + 1), 'base64'), hash = crypto.createHash('sha256').update(bytes).digest('hex');
|
|
8
|
+
if (!seen.has(hash) && mime === 'model/gltf-binary' && bytes.length > 5 * 1024 * 1024)
|
|
9
|
+
opts.diagnostics?.push({ severity: 'warning', source: 'structure', code: 'MODEL_SIZE', message: `GLB model is ${(bytes.length / 1024 / 1024).toFixed(1)} MB; reduce face_limit/textures before publishing (recommended below 5 MB).` });
|
|
10
|
+
seen.add(hash);
|
|
11
|
+
if (opts.directory && opts.prefix) {
|
|
12
|
+
const file = path.join(opts.directory, hash);
|
|
13
|
+
fs.mkdirSync(opts.directory, { recursive: true });
|
|
14
|
+
if (!fs.existsSync(file))
|
|
15
|
+
fs.writeFileSync(file, bytes);
|
|
16
|
+
return `${opts.prefix}${hash}${mime === 'model/gltf-binary' ? '.glb' : '.audio'}`;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(value))
|
|
21
|
+
return value.map(v => binaryAssets(v, opts, seen));
|
|
22
|
+
if (value && typeof value === 'object')
|
|
23
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, binaryAssets(v, opts, seen)]));
|
|
24
|
+
return value;
|
|
25
|
+
}
|
package/dist/build.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type StepIdentity, type Project } from '@joplo-app/core';
|
|
2
2
|
import type { BuildOptions, BuildResult } from './contract.js';
|
|
3
|
-
import type { DistWeb } from './web-assets.js';
|
|
3
|
+
import type { DistWeb, WebAssets } from './web-assets.js';
|
|
4
4
|
/** 发布站只需要的 IR:去掉创作侧字段(publish 模式下它们本来就为空)。层级、镜头、角色(说话人、过渡卡、层级的 role)与 featureIds 顺序属于演示,保留(D43 / D56 / D61)。 */
|
|
5
5
|
export declare function publishPayload(project: Project, home: string | null): {
|
|
6
6
|
project: Record<string, unknown>;
|
|
@@ -20,3 +20,10 @@ export declare function finalizeHtml(html: string, readAsset: (rel: string) => s
|
|
|
20
20
|
export declare function buildSite(opts: BuildOptions): Promise<BuildResult>;
|
|
21
21
|
/** 从 npm 安装时:复制预构建的发布站,单独编译作者 className 的 CSS 并在 site.html 里引用。 */
|
|
22
22
|
export declare function stageDistSite(web: DistWeb, projectDir: string, staging: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* 把每个插件运行时打成一个自包含的 ES 模块(依赖一起打进去),执行时注册到 globalThis.__JOPLO_PLUGINS__
|
|
25
|
+
* (web 的 renderer/plugins.ts 取走)。按插件 id 排序,产物稳定。
|
|
26
|
+
*/
|
|
27
|
+
export declare function bundlePluginRuntimes(runtimes: Record<string, string>, projectDir: string, web: WebAssets, mode?: 'factory' | 'module'): Promise<string[]>;
|
|
28
|
+
/** 插件脚本放在第一个模块脚本(入口)之前:模块脚本按文档顺序执行,注册表载入时插件已经就位。 */
|
|
29
|
+
export declare function injectPluginScripts(html: string, codes: string[]): string;
|
package/dist/build.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { binaryAssets } from "./binary-assets.js";
|
|
2
|
+
import { inlineResources } from "./local-resources.js";
|
|
3
|
+
import { inlinePluginAssets, PLUGIN_ASSET_BASE } from "./plugin-assets.js";
|
|
4
|
+
import sharedModules from '@joplo-app/web/shared-modules.json' with { type: 'json' };
|
|
1
5
|
/**
|
|
2
6
|
* `joplo build`:静态发布站。
|
|
3
7
|
*
|
|
@@ -30,7 +34,7 @@ export function publishPayload(project, home) {
|
|
|
30
34
|
// voiceConfig(D74):profile 名与音色属于作者本机的设置,发布站只需要 build 写进的 voiceIndex
|
|
31
35
|
const { rules: _r, cases: _c, issues: _i, voiceConfig: _v, ...rest } = project;
|
|
32
36
|
const features = Object.fromEntries(orderedFeatures(project).map(f => [f.id, { id: f.id, name: f.name, goal: f.goal, roles: f.roles, optionIds: f.optionIds, pick: f.pick }]));
|
|
33
|
-
const options = Object.fromEntries(Object.entries(project.options).map(([id, o]) => [id, { id: o.id, featureId: o.featureId, key: o.key, name: o.name, idea: o.idea, routes: o.routes, coverage: {}, layers: o.layers ?? {} }]));
|
|
37
|
+
const options = Object.fromEntries(Object.entries(project.options).map(([id, o]) => [id, { id: o.id, featureId: o.featureId, key: o.key, name: o.name, idea: o.idea, routes: o.routes, coverage: {}, layers: o.layers ?? {}, ...(o.free ? { free: o.free } : {}) }]));
|
|
34
38
|
const scenarios = Object.fromEntries(Object.entries(project.scenarios).map(([id, s]) => {
|
|
35
39
|
const { caseIds: _ci, ...sr } = s;
|
|
36
40
|
return [id, { ...sr, caseIds: [], steps: s.steps.map(({ ruleIds: _ri, key: _key, ...st }) => ({ ...st, ruleIds: [] })) }];
|
|
@@ -45,6 +49,8 @@ export const jsonForHtml = (v) => JSON.stringify(v).replace(/</g, '\\u003c').rep
|
|
|
45
49
|
export function finalizeHtml(html, readAsset, inline, identity) {
|
|
46
50
|
const inlined = [];
|
|
47
51
|
let out = html.replace(/\s+crossorigin(?:="[^"]*")?/g, '');
|
|
52
|
+
// 作者标记只由 Cloud 注入,不能随本地构建或导出传播。
|
|
53
|
+
out = out.replace(/<meta\b[^>]*\bname\s*=\s*["']joplo-author["'][^>]*>/gi, '');
|
|
48
54
|
out = out.replace(/<link rel="modulepreload"[^>]*>\s*/g, '');
|
|
49
55
|
out = out.replace(/<script type="module" src="\.\/([^"]+)"><\/script>/g, (_m, rel) => {
|
|
50
56
|
inlined.push(rel);
|
|
@@ -131,6 +137,18 @@ export async function buildSite(opts) {
|
|
|
131
137
|
project = r.project;
|
|
132
138
|
scope = r.info;
|
|
133
139
|
}
|
|
140
|
+
let mediaCredits = [], mediaLicenses = [];
|
|
141
|
+
if (compiled.resources) {
|
|
142
|
+
const resources = await inlineResources(project, compiled.resources.requests, compiled.resources.host);
|
|
143
|
+
if (Object.keys(resources.assets).length)
|
|
144
|
+
project = { ...project, mediaAssets: resources.assets, mediaInfo: resources.audioInfo };
|
|
145
|
+
compiled.diagnostics.push(...resources.diagnostics);
|
|
146
|
+
mediaCredits = resources.credits;
|
|
147
|
+
mediaLicenses = resources.licenses;
|
|
148
|
+
if (resources.diagnostics.some(d => d.severity === 'error'))
|
|
149
|
+
throw new JoploError('EXPORT_FAILED', 'Audio attribution is incomplete; no site was published', { diagnostics: resources.diagnostics });
|
|
150
|
+
}
|
|
151
|
+
binaryAssets(project, { diagnostics: compiled.diagnostics });
|
|
134
152
|
const inline = publishPayload(project, compiled.home);
|
|
135
153
|
if (scope)
|
|
136
154
|
inline.scoped = true;
|
|
@@ -148,8 +166,8 @@ export async function buildSite(opts) {
|
|
|
148
166
|
// 朗读(D74):当前声音已生成的音频拷进 voice/,IR 带上 voiceIndex;Key 不进产物
|
|
149
167
|
const store = new ProfileStore(opts.home ?? joploHome());
|
|
150
168
|
// 重新发布(D84):先从上一次的分享沿用本机没有的音频(同样的文字与声音),不重新生成
|
|
151
|
-
const reused = opts.sharedVoice ? await reuseSharedVoice(projectDir, project, opts.sharedVoice, store) : 0;
|
|
152
|
-
const voice = bundleVoice(projectDir, project, staging, store, undefined, opts.sharedVoice?.index);
|
|
169
|
+
const reused = opts.sharedVoice ? await reuseSharedVoice(projectDir, project, opts.sharedVoice, store, undefined, opts.voiceDefault) : 0;
|
|
170
|
+
const voice = bundleVoice(projectDir, project, staging, store, undefined, opts.sharedVoice?.index, opts.voiceDefault);
|
|
153
171
|
if (reused)
|
|
154
172
|
voice.report.reused = reused;
|
|
155
173
|
// 朗读角色只留范围内功能的(scopeProject 对 voiceIndex 的同一规则;bundleVoice 按声音配置生成全部角色)
|
|
@@ -162,9 +180,23 @@ export async function buildSite(opts) {
|
|
|
162
180
|
fs.rmSync(siteHtml);
|
|
163
181
|
for (const rel of inlined)
|
|
164
182
|
fs.rmSync(path.join(staging, rel));
|
|
165
|
-
|
|
183
|
+
// 插件运行时(D86):每个打成一个文件,内联在入口脚本之前(file:// 也能打开);只打包 IR 里用到的插件
|
|
184
|
+
const used = Object.fromEntries(Object.entries(compiled.pluginRuntimes).filter(([id]) => project.plugins?.[id]));
|
|
185
|
+
const pluginCode = await bundlePluginRuntimes(used, projectDir, web);
|
|
186
|
+
let withPlugins = injectPluginScripts(html, pluginCode);
|
|
187
|
+
if (mediaCredits.length) {
|
|
188
|
+
if (mediaLicenses.length)
|
|
189
|
+
fs.writeFileSync(path.join(staging, 'music-LICENSE.txt'), mediaLicenses.join('\n\n'));
|
|
190
|
+
fs.writeFileSync(path.join(staging, 'credits.txt'), `Music sound libraries\n\n${mediaCredits.join('\n\n')}\n`);
|
|
191
|
+
withPlugins = withPlugins.replace('</head>', '<link rel="license" href="./credits.txt" title="Music credits"></head>');
|
|
192
|
+
}
|
|
193
|
+
fs.writeFileSync(path.join(staging, 'index.html'), withPlugins.replace(/<title>[^<]*<\/title>/i, () => `<title>${escapeHtml(project.name)} · Joplo</title>`));
|
|
166
194
|
// D59: scan every staged text artifact, then retain only font subsets its content needs.
|
|
167
195
|
subsetSiteFonts(staging, web);
|
|
196
|
+
const siteBytes = listFiles(staging).reduce((n, f) => n + fs.statSync(path.join(staging, f)).size, 0);
|
|
197
|
+
compiled.diagnostics.push({ severity: 'info', source: 'structure', code: 'SITE_BUDGET', message: `Complete site: ${siteBytes} bytes (including embedded audio, fonts, models and narration)` });
|
|
198
|
+
if (siteBytes >= 18 * 1024 * 1024)
|
|
199
|
+
compiled.diagnostics.push({ severity: 'warning', source: 'structure', code: 'SITE_BUDGET_LARGE', message: 'Site approaches the documented Free 20 MiB single-upload budget (18 MiB warning); actual account limits come from the service' });
|
|
168
200
|
// 4. 写入目标目录
|
|
169
201
|
if (fs.existsSync(outDir))
|
|
170
202
|
fs.rmSync(outDir, { recursive: true, force: true });
|
|
@@ -198,7 +230,7 @@ async function buildSourceSite(web, projectDir, staging) {
|
|
|
198
230
|
base: './',
|
|
199
231
|
mode: 'production',
|
|
200
232
|
logLevel: 'error',
|
|
201
|
-
resolve: { alias: [{ find: /^@joplo-app\/core
|
|
233
|
+
resolve: { alias: [{ find: /^@joplo-app\/core(?:\/runtime)?$/, replacement: path.join(web.webDir, 'src/site/core-lite.ts') }, ...kitAliases(web, projectDir)] },
|
|
202
234
|
define: { 'process.env.NODE_ENV': '"production"' },
|
|
203
235
|
plugins: [joploProjectPlugin(projectDir, web), react(), tailwindcss()],
|
|
204
236
|
build: {
|
|
@@ -249,4 +281,57 @@ export async function stageDistSite(web, projectDir, staging) {
|
|
|
249
281
|
fs.rmSync(cssOut, { recursive: true, force: true });
|
|
250
282
|
}
|
|
251
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* 把每个插件运行时打成一个自包含的 ES 模块(依赖一起打进去),执行时注册到 globalThis.__JOPLO_PLUGINS__
|
|
286
|
+
* (web 的 renderer/plugins.ts 取走)。按插件 id 排序,产物稳定。
|
|
287
|
+
*/
|
|
288
|
+
export async function bundlePluginRuntimes(runtimes, projectDir, web, mode = 'factory') {
|
|
289
|
+
const out = [];
|
|
290
|
+
const modules = sharedModules;
|
|
291
|
+
const shared = Object.keys(modules);
|
|
292
|
+
const bridge = (name) => {
|
|
293
|
+
const keys = modules[name];
|
|
294
|
+
return `const shared = globalThis.__JOPLO_SHARED__[${JSON.stringify(name)}]; export default shared; ${keys.map(k => `export const ${k} = shared.${k};`).join(' ')}`;
|
|
295
|
+
};
|
|
296
|
+
for (const [id, file] of Object.entries(runtimes).sort(([a], [b]) => a.localeCompare(b))) {
|
|
297
|
+
const entry = '\0joplo-plugin-entry';
|
|
298
|
+
const r = (await viteBuild({
|
|
299
|
+
configFile: false,
|
|
300
|
+
envDir: false,
|
|
301
|
+
root: path.dirname(file),
|
|
302
|
+
base: PLUGIN_ASSET_BASE,
|
|
303
|
+
mode: 'production',
|
|
304
|
+
logLevel: 'error',
|
|
305
|
+
resolve: { alias: kitAliases(web, projectDir) },
|
|
306
|
+
define: { 'process.env.NODE_ENV': '"production"' },
|
|
307
|
+
oxc: { jsx: { runtime: 'automatic', importSource: 'react', development: false } },
|
|
308
|
+
plugins: [{
|
|
309
|
+
name: 'joplo:plugin-entry',
|
|
310
|
+
// Resolve shared modules before Vite finds a plugin's installed React copy.
|
|
311
|
+
enforce: 'pre',
|
|
312
|
+
resolveId: (src) => src === 'joplo-plugin-entry' ? entry : shared.includes(src) ? `\0joplo-shared:${src}` : null,
|
|
313
|
+
load: (resolved) => (resolved.startsWith('\0joplo-shared:') ? bridge(resolved.slice('\0joplo-shared:'.length)) : resolved === entry ? `import runtime from ${JSON.stringify(file)};\n${mode === 'module' ? 'export default runtime;' : '(globalThis.__JOPLO_PLUGINS__ ??= []).push(runtime);'}\n` : null),
|
|
314
|
+
}],
|
|
315
|
+
build: { write: false, assetsInlineLimit: 0, cssCodeSplit: false, minify: true, sourcemap: false, modulePreload: false, reportCompressedSize: false, emptyOutDir: false, rolldownOptions: { input: 'joplo-plugin-entry', ...(mode === 'module' ? { preserveEntrySignatures: 'strict' } : {}), output: { format: 'es', codeSplitting: false } } },
|
|
316
|
+
}));
|
|
317
|
+
const output = (Array.isArray(r) ? r : [r]).flatMap(o => o.output);
|
|
318
|
+
const chunks = output.filter((x) => x.type === 'chunk');
|
|
319
|
+
if (chunks.length !== 1)
|
|
320
|
+
throw new JoploError('EXPORT_FAILED', `Plugin ${id}: expected one bundled runtime file, got ${chunks.length}`);
|
|
321
|
+
const code = inlinePluginAssets(id, chunks[0].code, output.filter((x) => x.type === 'asset'));
|
|
322
|
+
// Defer evaluation until the host has initialized its shared React instance.
|
|
323
|
+
out.push(mode === 'module' ? code : `(globalThis.__JOPLO_PLUGIN_FACTORIES__ ??= []).push({id:${JSON.stringify(id)},load:()=>{\n${code}\n}});`);
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
/** 插件脚本放在第一个模块脚本(入口)之前:模块脚本按文档顺序执行,注册表载入时插件已经就位。 */
|
|
328
|
+
export function injectPluginScripts(html, codes) {
|
|
329
|
+
if (!codes.length)
|
|
330
|
+
return html;
|
|
331
|
+
const tags = codes.map((c) => `<script type="module" data-joplo-plugin>${c.replace(/<\/script/gi, '<\\/script')}</script>`).join('\n');
|
|
332
|
+
const i = html.indexOf('<script type="module">');
|
|
333
|
+
if (i < 0)
|
|
334
|
+
throw new JoploError('EXPORT_FAILED', 'Published site has no entry script to put plugin runtimes before');
|
|
335
|
+
return `${html.slice(0, i)}${tags}\n${html.slice(i)}`;
|
|
336
|
+
}
|
|
252
337
|
const escapeHtml = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
package/dist/cloud.d.ts
CHANGED
|
@@ -12,45 +12,172 @@
|
|
|
12
12
|
import type http from 'node:http';
|
|
13
13
|
import type { ScopeInfo } from '@joplo-app/core';
|
|
14
14
|
export declare const CLOUD_EVENT = "joplo:cloud";
|
|
15
|
+
export type CloudVisibility = 'public' | 'private';
|
|
16
|
+
export type CloudPortfolio = {
|
|
17
|
+
workUrl: string | null;
|
|
18
|
+
profileUrl: string | null;
|
|
19
|
+
needsUsername: boolean;
|
|
20
|
+
setupPath: string;
|
|
21
|
+
};
|
|
22
|
+
export type CloudLinks = {
|
|
23
|
+
main: {
|
|
24
|
+
visibility?: CloudVisibility;
|
|
25
|
+
passwordProtected?: boolean;
|
|
26
|
+
} | null;
|
|
27
|
+
scoped?: Record<string, {
|
|
28
|
+
visibility?: CloudVisibility;
|
|
29
|
+
passwordProtected?: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
15
32
|
export type CloudAccount = {
|
|
16
33
|
signedIn: true;
|
|
17
34
|
server: string;
|
|
18
35
|
email: string;
|
|
19
36
|
plan: 'free' | 'pro' | null;
|
|
37
|
+
/** 账号容量(C27);云端连不上或旧云端时没有。 */
|
|
38
|
+
storage?: CloudStorage;
|
|
39
|
+
/** 托管朗读额度(D85,`GET /api/v1/voice` 的 quota);云端连不上或旧云端(404)时没有。 */
|
|
40
|
+
voice?: VoiceQuota;
|
|
41
|
+
username?: string | null;
|
|
42
|
+
portfolioUrl?: string | null;
|
|
20
43
|
} | {
|
|
21
44
|
signedIn: false;
|
|
22
45
|
server: string;
|
|
23
46
|
loginCommand: string;
|
|
24
47
|
message?: string;
|
|
25
48
|
};
|
|
49
|
+
/** 托管朗读额度(D85,与 Cloud 契约 `GET /api/v1/voice` 的 quota 一致):免费是一次性的体验额度(trial),Pro 按月(month)。字数 = Array.from(文字).length。 */
|
|
50
|
+
export type VoiceQuota = {
|
|
51
|
+
plan: string;
|
|
52
|
+
period: 'trial' | 'month';
|
|
53
|
+
allowanceChars: number;
|
|
54
|
+
usedChars: number;
|
|
55
|
+
remainingChars: number;
|
|
56
|
+
/** 本月额度的重置时间(ISO);体验额度为 null。 */
|
|
57
|
+
resetsAt: string | null;
|
|
58
|
+
/** 加油包:各自剩余与到期时间。 */
|
|
59
|
+
packs: {
|
|
60
|
+
remainingChars: number;
|
|
61
|
+
expiresAt: string;
|
|
62
|
+
}[];
|
|
63
|
+
/** 当月(或体验)剩余 + 加油包剩余。看板与 CLI 显示的“剩 N 字”就是它。 */
|
|
64
|
+
totalRemainingChars: number;
|
|
65
|
+
};
|
|
66
|
+
/** Joplo 音色(Cloud 固定 6 个,都是多语言):labels / samples 按界面语言(10 种之一)。 */
|
|
67
|
+
export type CloudVoice = {
|
|
68
|
+
id: string;
|
|
69
|
+
gender: 'female' | 'male';
|
|
70
|
+
labels: Record<string, string>;
|
|
71
|
+
samples: Record<string, string>;
|
|
72
|
+
};
|
|
73
|
+
/** `GET /api/v1/voice` 去掉 quota 之后的部分:音色表、每种语言的推荐音色、默认音色。 */
|
|
74
|
+
export type CloudVoiceCatalog = {
|
|
75
|
+
model: string;
|
|
76
|
+
voices: CloudVoice[];
|
|
77
|
+
recommended: Record<string, string[]>;
|
|
78
|
+
defaultVoice: string;
|
|
79
|
+
};
|
|
80
|
+
export type CloudVoiceInfo = CloudVoiceCatalog & {
|
|
81
|
+
quota: VoiceQuota;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* 托管朗读的状态:没登录时给登录命令;已登录时 voice 是 `GET /api/v1/voice` 的内容,云端连不上或旧云端(404)时为 null(看板退回浏览器朗读)。
|
|
85
|
+
*/
|
|
86
|
+
export type CloudVoiceStatus = {
|
|
87
|
+
signedIn: false;
|
|
88
|
+
server: string;
|
|
89
|
+
loginCommand: string;
|
|
90
|
+
} | {
|
|
91
|
+
signedIn: true;
|
|
92
|
+
server: string;
|
|
93
|
+
voice: CloudVoiceInfo | null;
|
|
94
|
+
};
|
|
95
|
+
/** `POST /api/v1/voice/speech` 的请求:locale 是内容语言(D84,不知道时不带),project 是项目名(控制台明细用)。 */
|
|
96
|
+
export type CloudSpeechRequest = {
|
|
97
|
+
text: string;
|
|
98
|
+
voice: string;
|
|
99
|
+
locale?: string;
|
|
100
|
+
project?: string;
|
|
101
|
+
};
|
|
102
|
+
/** 合成结果:音频与响应头(X-Joplo-Chars-Charged / -Remaining、X-Joplo-Cache、X-Joplo-Audio-Sha256),头缺失或不合法时为 null。 */
|
|
103
|
+
export type CloudSpeechResult = {
|
|
104
|
+
audio: Uint8Array;
|
|
105
|
+
contentType: string;
|
|
106
|
+
charged: number | null;
|
|
107
|
+
remaining: number | null;
|
|
108
|
+
cache: 'hit' | 'miss' | null;
|
|
109
|
+
sha256: string | null;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* 托管朗读(D85)的 CLI 一侧:看板与 `joplo voice` 共用。server 包不依赖 CLI,由 CLI 注入(与 publish 一样)。
|
|
113
|
+
* speech 失败时抛 `{ code, message, data? }`:TTS_QUOTA_EXCEEDED(data: neededChars / remainingChars / usageUrl)、AUTH_REQUIRED、AUTH_EXPIRED、
|
|
114
|
+
* EMAIL_UNVERIFIED、FORBIDDEN、RATE_LIMITED、TTS_UNAVAILABLE、BAD_REQUEST、NOT_FOUND(旧云端)、NETWORK。
|
|
115
|
+
*/
|
|
116
|
+
export type CloudVoiceBridge = {
|
|
117
|
+
status(): Promise<CloudVoiceStatus>;
|
|
118
|
+
speech(req: CloudSpeechRequest): Promise<CloudSpeechResult>;
|
|
119
|
+
};
|
|
120
|
+
/** 账号容量(C27):已用 / 上限,字节。 */
|
|
121
|
+
export type CloudStorage = {
|
|
122
|
+
usedBytes: number;
|
|
123
|
+
quotaBytes: number;
|
|
124
|
+
};
|
|
125
|
+
/** 容量不足(QUOTA_EXCEEDED,kind: storage):数字可能缺;两个链接已拼好当前 server。 */
|
|
126
|
+
export type CloudStorageFull = {
|
|
127
|
+
usedBytes?: number;
|
|
128
|
+
quotaBytes?: number;
|
|
129
|
+
shareBytes?: number;
|
|
130
|
+
replacedBytes?: number;
|
|
131
|
+
manageUrl: string;
|
|
132
|
+
upgradeUrl: string;
|
|
133
|
+
};
|
|
26
134
|
/** 范围:都为空 = 整个项目(D75)。 */
|
|
27
135
|
export type CloudPublishRequest = {
|
|
136
|
+
password?: string | null;
|
|
137
|
+
visibility?: CloudVisibility;
|
|
138
|
+
review?: boolean;
|
|
28
139
|
scenarios?: string[];
|
|
29
140
|
features?: string[];
|
|
30
141
|
};
|
|
31
142
|
export type CloudPublishResult = {
|
|
143
|
+
passwordProtected?: boolean;
|
|
144
|
+
mode?: 'review';
|
|
145
|
+
visibility?: CloudVisibility;
|
|
146
|
+
portfolio?: CloudPortfolio;
|
|
147
|
+
review?: {
|
|
148
|
+
url: string;
|
|
149
|
+
shareId: string;
|
|
150
|
+
};
|
|
32
151
|
shareId: string;
|
|
33
152
|
url: string;
|
|
34
153
|
expiresAt: string | null;
|
|
35
154
|
version: number;
|
|
36
155
|
plan: 'free' | 'pro';
|
|
37
|
-
scope?: ScopeInfo;
|
|
156
|
+
scope?: ScopeInfo; /** 发布后的账号容量与这次大小(C27)。 */
|
|
157
|
+
storage?: CloudStorage & {
|
|
158
|
+
shareBytes: number;
|
|
159
|
+
};
|
|
38
160
|
};
|
|
39
161
|
/** CLI 实现:account 只读本机登录(必要时问一次云端套餐);publish 就是 share(),progress 是它写给终端的每一行。 */
|
|
40
162
|
export type CloudBridge = {
|
|
41
163
|
account(): Promise<CloudAccount>;
|
|
164
|
+
links?(projectDir: string): Promise<CloudLinks>;
|
|
42
165
|
publish(projectDir: string, request: CloudPublishRequest, progress: (line: string) => void): Promise<CloudPublishResult>;
|
|
166
|
+
/** 托管朗读(D85);旧 CLI 没有这一项时看板只用浏览器朗读与自带 Key 的供应商。 */
|
|
167
|
+
voice?: CloudVoiceBridge;
|
|
43
168
|
};
|
|
44
169
|
/** 发布失败:code 来自 CLI(AUTH_REQUIRED、NOT_FOUND、NETWORK…);需要登录时带 loginCommand。 */
|
|
45
170
|
export type CloudJobError = {
|
|
46
171
|
code: string;
|
|
47
172
|
message: string;
|
|
48
173
|
loginCommand?: string;
|
|
174
|
+
upgradeUrl?: string; /** 容量不足时的数字与链接(C27)。 */
|
|
175
|
+
storage?: CloudStorageFull;
|
|
49
176
|
};
|
|
50
177
|
export type CloudJob = {
|
|
51
178
|
id: string;
|
|
52
179
|
state: 'running' | 'done' | 'failed';
|
|
53
|
-
request: CloudPublishRequest
|
|
180
|
+
request: Omit<CloudPublishRequest, 'password'>;
|
|
54
181
|
startedAt: number;
|
|
55
182
|
/** 进度:CLI 写给终端的行(英文,页面按开头识别阶段)。 */
|
|
56
183
|
lines: string[];
|
package/dist/cloud.js
CHANGED
|
@@ -37,6 +37,12 @@ export class CloudHub {
|
|
|
37
37
|
}
|
|
38
38
|
/** `/__joplo/p/<id>/cloud/<sub>`:sub = 'publish'(GET 读任务,POST 开始发布)。 */
|
|
39
39
|
async handleProject(projectId, dir, sub, req, ctx) {
|
|
40
|
+
if (sub === 'links' && req.method === 'GET') {
|
|
41
|
+
if (!ctx.guardWrite(false))
|
|
42
|
+
return true;
|
|
43
|
+
ctx.send(200, { links: await this.bridge?.links?.(dir) ?? { main: null } });
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
40
46
|
if (sub !== 'publish')
|
|
41
47
|
return false;
|
|
42
48
|
const method = req.method ?? 'GET';
|
|
@@ -60,7 +66,19 @@ export class CloudHub {
|
|
|
60
66
|
const body = (b.body ?? {});
|
|
61
67
|
const scenarios = strings(body.scenarios, 'scenarios');
|
|
62
68
|
const features = strings(body.features, 'features');
|
|
63
|
-
|
|
69
|
+
if (body.visibility !== 'public' && body.visibility !== 'private')
|
|
70
|
+
throw new Error('Choose visibility: public / private');
|
|
71
|
+
if (typeof body.review !== 'boolean')
|
|
72
|
+
throw new Error('Choose review: true / false');
|
|
73
|
+
if (body.visibility === 'public' && (scenarios?.length || features?.length))
|
|
74
|
+
throw new Error('Scoped shares must be private');
|
|
75
|
+
if (body.password !== undefined) {
|
|
76
|
+
if (body.visibility !== 'private')
|
|
77
|
+
throw new Error('Passwords require a private share');
|
|
78
|
+
if (body.password !== null && (typeof body.password !== 'string' || Array.from(body.password).length < 8 || Array.from(body.password).length > 128))
|
|
79
|
+
throw new Error('Access password must contain 8–128 characters');
|
|
80
|
+
}
|
|
81
|
+
request = { ...(body.password !== undefined ? { password: body.password } : {}), visibility: body.visibility, review: body.review, ...(scenarios?.length ? { scenarios } : {}), ...(features?.length ? { features } : {}) };
|
|
64
82
|
}
|
|
65
83
|
catch (e) {
|
|
66
84
|
return ctx.send(400, { error: { code: 'USAGE', message: e instanceof Error ? e.message : String(e) } }), true;
|
|
@@ -72,27 +90,32 @@ export class CloudHub {
|
|
|
72
90
|
return true;
|
|
73
91
|
}
|
|
74
92
|
start(projectId, dir, request) {
|
|
75
|
-
const
|
|
93
|
+
const { password, ...safeRequest } = request;
|
|
94
|
+
const redact = (text) => typeof password === 'string' && password ? text.split(password).join('[REDACTED]') : text;
|
|
95
|
+
const safe = (value) => JSON.parse(JSON.stringify(value, (_key, v) => typeof v === 'string' ? redact(v) : v));
|
|
96
|
+
const job = { id: `c${++this.seq}`, state: 'running', request: safe(safeRequest), startedAt: Date.now(), lines: [] };
|
|
76
97
|
this.jobs.set(projectId, job);
|
|
77
98
|
const push = () => this.emit(projectId, job);
|
|
78
99
|
push();
|
|
79
100
|
void this.bridge
|
|
80
101
|
.publish(dir, request, (line) => {
|
|
81
|
-
job.lines = [...job.lines, line].slice(-MAX_LINES);
|
|
102
|
+
job.lines = [...job.lines, redact(line)].slice(-MAX_LINES);
|
|
82
103
|
push();
|
|
83
104
|
})
|
|
84
105
|
.then((result) => {
|
|
85
106
|
job.state = 'done';
|
|
86
|
-
job.result = result;
|
|
107
|
+
job.result = safe(result);
|
|
87
108
|
})
|
|
88
109
|
.catch((e) => {
|
|
89
110
|
const err = e;
|
|
90
111
|
job.state = 'failed';
|
|
91
|
-
job.error = {
|
|
112
|
+
job.error = safe({
|
|
92
113
|
code: typeof err.code === 'string' ? err.code : 'INTERNAL',
|
|
93
114
|
message: typeof err.message === 'string' ? err.message : String(e),
|
|
94
115
|
...(typeof err.loginCommand === 'string' ? { loginCommand: err.loginCommand } : {}),
|
|
95
|
-
|
|
116
|
+
...(err.storage && typeof err.storage === 'object' ? { storage: err.storage } : {}),
|
|
117
|
+
...(typeof err.upgradeUrl === 'string' ? { upgradeUrl: err.upgradeUrl } : {}),
|
|
118
|
+
});
|
|
96
119
|
})
|
|
97
120
|
.finally(push);
|
|
98
121
|
return job;
|
package/dist/contract.d.ts
CHANGED
|
@@ -52,6 +52,11 @@ export type BuildOptions = {
|
|
|
52
52
|
index: VoiceIndex;
|
|
53
53
|
fetch: (file: string) => Promise<Uint8Array | null>;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* 项目没选过声音来源、config 也没写时用哪个(D85):CLI 已登录 Joplo Cloud 时传 'cloud'(与看板同一规则),
|
|
57
|
+
* 这样看板里默认用 cloud 生成的音频也会带上。缺省 null:只用看板里选过的(与原来一致)。
|
|
58
|
+
*/
|
|
59
|
+
voiceDefault?: string | null;
|
|
55
60
|
};
|
|
56
61
|
/** 静态发布站:只含选定方案(compile 的 publish 模式),离线可打开,可直接 `wrangler deploy`。 */
|
|
57
62
|
/**
|
|
@@ -126,3 +131,71 @@ export type RenderResult = {
|
|
|
126
131
|
warnings: string[];
|
|
127
132
|
};
|
|
128
133
|
export declare function renderStep(opts: RenderOptions): Promise<RenderResult>;
|
|
134
|
+
/** 分镜(storyboard):一个场景的每一步拼成一张图,每格下面是步号、字幕与旁白。 */
|
|
135
|
+
export type SheetOptions = Omit<RenderOptions, 'stepId' | 'viewport' | 'scope'> & {
|
|
136
|
+
columns?: number; /** 每格宽度(像素),默认 480。 */
|
|
137
|
+
cellWidth?: number;
|
|
138
|
+
};
|
|
139
|
+
export type SheetResult = {
|
|
140
|
+
path: string;
|
|
141
|
+
steps: number;
|
|
142
|
+
warnings: string[];
|
|
143
|
+
};
|
|
144
|
+
export declare function renderSheet(opts: SheetOptions): Promise<SheetResult>;
|
|
145
|
+
/**
|
|
146
|
+
* 胶片条(`joplo render --film`):按引擎时间逐帧定格(Playwright 假时钟),每 sampleMs 算一次相邻帧差,每 every 取一格。
|
|
147
|
+
* 每个场景一页(多页时 out 之后加 -1、-2…);cuts = 单帧整屏突变,stills = 至少 stillMs 没有可见变化,boundaries = 每次提交一步前后的最大相邻帧差。
|
|
148
|
+
*/
|
|
149
|
+
export type FilmOptions = Omit<RenderOptions, 'stepId' | 'viewport' | 'scope' | 'scale'> & {
|
|
150
|
+
chain?: boolean;
|
|
151
|
+
every?: number;
|
|
152
|
+
sampleMs?: number;
|
|
153
|
+
stillMs?: number;
|
|
154
|
+
columns?: number;
|
|
155
|
+
cellWidth?: number; /** 把胶片格另存为 JPEG 的目录(可选)。 */
|
|
156
|
+
frames?: string;
|
|
157
|
+
};
|
|
158
|
+
export type FilmCut = {
|
|
159
|
+
atMs: number;
|
|
160
|
+
diff: number;
|
|
161
|
+
changed: number;
|
|
162
|
+
scenarioId: string | null;
|
|
163
|
+
position: number;
|
|
164
|
+
};
|
|
165
|
+
export type FilmStill = {
|
|
166
|
+
fromMs: number;
|
|
167
|
+
toMs: number;
|
|
168
|
+
scenarioId: string | null;
|
|
169
|
+
position: number;
|
|
170
|
+
};
|
|
171
|
+
export type FilmBoundary = {
|
|
172
|
+
atMs: number;
|
|
173
|
+
scenarioId: string | null;
|
|
174
|
+
position: number;
|
|
175
|
+
chapter: boolean;
|
|
176
|
+
maxDiff: number;
|
|
177
|
+
maxChanged: number;
|
|
178
|
+
};
|
|
179
|
+
export type FilmResult = {
|
|
180
|
+
path: string;
|
|
181
|
+
files: string[];
|
|
182
|
+
durationMs: number;
|
|
183
|
+
sampleMs: number;
|
|
184
|
+
every: number;
|
|
185
|
+
samples: number;
|
|
186
|
+
cuts: FilmCut[];
|
|
187
|
+
stills: FilmStill[];
|
|
188
|
+
boundaries: FilmBoundary[];
|
|
189
|
+
maxDiff: number;
|
|
190
|
+
warnings: string[];
|
|
191
|
+
};
|
|
192
|
+
export declare function renderFilm(opts: FilmOptions): Promise<FilmResult>;
|
|
193
|
+
/** 视频(`joplo render --video`):与看板导出同一个录制器(真实时间,webm)。 */
|
|
194
|
+
export type VideoOptions = Omit<RenderOptions, 'stepId' | 'viewport' | 'scope' | 'scale'> & {
|
|
195
|
+
chain?: boolean;
|
|
196
|
+
};
|
|
197
|
+
export type VideoResult = {
|
|
198
|
+
path: string;
|
|
199
|
+
durationMs: number;
|
|
200
|
+
};
|
|
201
|
+
export declare function renderVideo(opts: VideoOptions): Promise<VideoResult>;
|
package/dist/dev.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export type DevPayload = {
|
|
|
12
12
|
project: Project | null;
|
|
13
13
|
diagnostics: Diagnostic[];
|
|
14
14
|
home: string | null;
|
|
15
|
+
/** 插件(D86):插件 id → 运行时地址(本服务以 /@fs/<绝对路径> 提供,Vite 负责转译与依赖解析)。 */
|
|
16
|
+
plugins?: Record<string, string>;
|
|
15
17
|
};
|
|
16
18
|
/** 首页项目列表的一行。status:idle 未编译、compiling 首次编译中、ok、error(编译出错)、missing(目录不存在)。 */
|
|
17
19
|
export type ProjectSummary = {
|
|
@@ -40,6 +42,7 @@ export type ProjectSlot = {
|
|
|
40
42
|
loader: ViteDevServer | null;
|
|
41
43
|
ready: Promise<void>;
|
|
42
44
|
payload: DevPayload;
|
|
45
|
+
runtimeModules: Map<string, string>;
|
|
43
46
|
compiling: boolean;
|
|
44
47
|
closed: boolean;
|
|
45
48
|
running: Promise<void> | null;
|