@joplo-app/server 0.2.9 → 0.2.12
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/build.d.ts +1 -0
- package/dist/build.js +25 -3
- package/dist/cloud.d.ts +85 -0
- package/dist/cloud.js +110 -0
- package/dist/contract.d.ts +28 -1
- package/dist/dev.d.ts +7 -1
- package/dist/dev.js +79 -5
- package/dist/index.d.ts +1 -1
- package/dist/local-review.d.ts +18 -0
- package/dist/local-review.js +133 -0
- package/dist/render.js +6 -3
- package/dist/voice-http.d.ts +71 -0
- package/dist/voice-http.js +245 -0
- package/dist/voice.d.ts +253 -0
- package/dist/voice.js +637 -0
- package/package.json +4 -4
package/dist/build.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare const jsonForHtml: (v: unknown) => string;
|
|
|
12
12
|
export declare function finalizeHtml(html: string, readAsset: (rel: string) => string, inline: {
|
|
13
13
|
project: unknown;
|
|
14
14
|
home: string | null;
|
|
15
|
+
scoped?: true;
|
|
15
16
|
}): {
|
|
16
17
|
html: string;
|
|
17
18
|
inlined: string[];
|
package/dist/build.js
CHANGED
|
@@ -19,13 +19,16 @@ import os from 'node:os';
|
|
|
19
19
|
import path from 'node:path';
|
|
20
20
|
import tailwindcss from '@tailwindcss/vite';
|
|
21
21
|
import { build as viteBuild, createServer } from 'vite';
|
|
22
|
-
import { JoploError, orderedFeatures } from '@joplo-app/core';
|
|
22
|
+
import { hasScope, JoploError, orderedFeatures, resolveScope, scopeProject } from '@joplo-app/core';
|
|
23
23
|
import { compileProject } from "./project.js";
|
|
24
24
|
import { joploProjectPlugin, kitAliases, locateWebAssets, realProjectDir } from "./vite-shared.js";
|
|
25
25
|
import { subsetSiteFonts } from "./site-fonts.js";
|
|
26
|
+
import { joploHome } from "./home.js";
|
|
27
|
+
import { ProfileStore, bundleVoice } from "./voice.js";
|
|
26
28
|
/** 发布站只需要的 IR:去掉创作侧字段(publish 模式下它们本来就为空)。层级、镜头、角色(说话人、过渡卡、层级的 role)与 featureIds 顺序属于演示,保留(D43 / D56 / D61)。 */
|
|
27
29
|
export function publishPayload(project, home) {
|
|
28
|
-
|
|
30
|
+
// voiceConfig(D74):profile 名与音色属于作者本机的设置,发布站只需要 build 写进的 voiceIndex
|
|
31
|
+
const { rules: _r, cases: _c, issues: _i, voiceConfig: _v, ...rest } = project;
|
|
29
32
|
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 }]));
|
|
30
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 ?? {} }]));
|
|
31
34
|
const scenarios = Object.fromEntries(Object.entries(project.scenarios).map(([id, s]) => {
|
|
@@ -117,10 +120,21 @@ export async function buildSite(opts) {
|
|
|
117
120
|
const errs = compiled.diagnostics.filter((d) => d.severity === 'error');
|
|
118
121
|
throw new JoploError('EXPORT_FAILED', `Project compilation failed; no published site was generated: \n${errs.map((d) => `${d.at ?? ''} ${d.message}`).join('\n')}`, { diagnostics: compiled.diagnostics });
|
|
119
122
|
}
|
|
120
|
-
|
|
123
|
+
// 按场景保密分享(D75):先裁剪 IR,再生成产物;写错范围在写任何文件之前报错
|
|
124
|
+
let project = compiled.project;
|
|
125
|
+
let scope;
|
|
126
|
+
if (hasScope(opts.scope)) {
|
|
127
|
+
const mode = opts.review === true ? 'review' : 'publish';
|
|
128
|
+
const r = scopeProject(project, resolveScope(project, opts.scope, mode), mode);
|
|
129
|
+
project = r.project;
|
|
130
|
+
scope = r.info;
|
|
131
|
+
}
|
|
121
132
|
const inline = publishPayload(project, compiled.home);
|
|
133
|
+
if (scope)
|
|
134
|
+
inline.scoped = true;
|
|
122
135
|
// 2. vite build 到临时目录
|
|
123
136
|
const staging = fs.mkdtempSync(path.join(os.tmpdir(), 'joplo-build-'));
|
|
137
|
+
let voiceReport;
|
|
124
138
|
// React 与 plugin-react 依据 NODE_ENV 判断生产构建(测试运行器会把它设为 test);构建期间强制 production。
|
|
125
139
|
const prevEnv = process.env.NODE_ENV;
|
|
126
140
|
process.env.NODE_ENV = 'production';
|
|
@@ -129,6 +143,12 @@ export async function buildSite(opts) {
|
|
|
129
143
|
await stageDistSite(web, projectDir, staging);
|
|
130
144
|
else
|
|
131
145
|
await buildSourceSite(web, projectDir, staging);
|
|
146
|
+
// 朗读(D74):当前声音已生成的音频拷进 voice/,IR 带上 voiceIndex;Key 不进产物
|
|
147
|
+
const voice = bundleVoice(projectDir, project, staging, new ProfileStore(opts.home ?? joploHome()));
|
|
148
|
+
// 朗读角色只留范围内功能的(scopeProject 对 voiceIndex 的同一规则;bundleVoice 按声音配置生成全部角色)
|
|
149
|
+
if (voice.index)
|
|
150
|
+
inline.project.voiceIndex = scope ? scopeProject({ ...project, voiceIndex: voice.index }, scope.scenarios).project.voiceIndex : voice.index;
|
|
151
|
+
voiceReport = voice.report;
|
|
132
152
|
// 3. 后处理
|
|
133
153
|
const siteHtml = path.join(staging, 'site.html');
|
|
134
154
|
const { html, inlined } = finalizeHtml(fs.readFileSync(siteHtml, 'utf8'), (rel) => fs.readFileSync(path.join(staging, rel), 'utf8'), inline);
|
|
@@ -157,6 +177,8 @@ export async function buildSite(opts) {
|
|
|
157
177
|
routes: Object.keys(project.routes).sort(),
|
|
158
178
|
scenarios: Object.keys(project.scenarios),
|
|
159
179
|
diagnostics: compiled.diagnostics,
|
|
180
|
+
...(voiceReport && (voiceReport.clips || voiceReport.profile) ? { voice: voiceReport } : {}),
|
|
181
|
+
...(scope ? { scope } : {}),
|
|
160
182
|
};
|
|
161
183
|
}
|
|
162
184
|
/** 仓库里:直接编译 packages/web 的发布站入口。 */
|
package/dist/cloud.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 看板直接发布到云端(D76)。云端能力(登录、构建、上传)在 CLI 里,由 `joplo dev` 启动看板时注入(CloudBridge);
|
|
3
|
+
* 看板只转发请求、记录发布任务、把进度推给页面。令牌只在本机进程里,页面只拿到账号邮箱和套餐。
|
|
4
|
+
*
|
|
5
|
+
* 数据流:
|
|
6
|
+
* - 账号:`GET /__joplo/cloud/account`(本机令牌)→ bridge.account() → 浮层的“已登录 / 需要登录(可复制的登录命令)”。
|
|
7
|
+
* - 发布:`POST /__joplo/p/<id>/cloud/publish`(令牌 + Origin + JSON,body = 范围)→ bridge.publish()(即 CLI 的 share())
|
|
8
|
+
* → 任务状态(running → done / failed)存在 CloudHub,变化时推 `joplo:cloud`;`GET …/cloud/publish` 读当前任务。
|
|
9
|
+
* - 同一项目同时只有一个发布任务:再次 POST 返回正在进行的那个,不另起。
|
|
10
|
+
* - 旧版 CLI 启动的看板没有 bridge:account 返回 available: false,页面禁用这一项并提示重启 joplo dev。
|
|
11
|
+
*/
|
|
12
|
+
import type http from 'node:http';
|
|
13
|
+
import type { ScopeInfo } from '@joplo-app/core';
|
|
14
|
+
export declare const CLOUD_EVENT = "joplo:cloud";
|
|
15
|
+
export type CloudAccount = {
|
|
16
|
+
signedIn: true;
|
|
17
|
+
server: string;
|
|
18
|
+
email: string;
|
|
19
|
+
plan: 'free' | 'pro' | null;
|
|
20
|
+
} | {
|
|
21
|
+
signedIn: false;
|
|
22
|
+
server: string;
|
|
23
|
+
loginCommand: string;
|
|
24
|
+
message?: string;
|
|
25
|
+
};
|
|
26
|
+
/** 范围:都为空 = 整个项目(D75)。 */
|
|
27
|
+
export type CloudPublishRequest = {
|
|
28
|
+
scenarios?: string[];
|
|
29
|
+
features?: string[];
|
|
30
|
+
};
|
|
31
|
+
export type CloudPublishResult = {
|
|
32
|
+
shareId: string;
|
|
33
|
+
url: string;
|
|
34
|
+
expiresAt: string | null;
|
|
35
|
+
version: number;
|
|
36
|
+
plan: 'free' | 'pro';
|
|
37
|
+
scope?: ScopeInfo;
|
|
38
|
+
};
|
|
39
|
+
/** CLI 实现:account 只读本机登录(必要时问一次云端套餐);publish 就是 share(),progress 是它写给终端的每一行。 */
|
|
40
|
+
export type CloudBridge = {
|
|
41
|
+
account(): Promise<CloudAccount>;
|
|
42
|
+
publish(projectDir: string, request: CloudPublishRequest, progress: (line: string) => void): Promise<CloudPublishResult>;
|
|
43
|
+
};
|
|
44
|
+
/** 发布失败:code 来自 CLI(AUTH_REQUIRED、NOT_FOUND、NETWORK…);需要登录时带 loginCommand。 */
|
|
45
|
+
export type CloudJobError = {
|
|
46
|
+
code: string;
|
|
47
|
+
message: string;
|
|
48
|
+
loginCommand?: string;
|
|
49
|
+
};
|
|
50
|
+
export type CloudJob = {
|
|
51
|
+
id: string;
|
|
52
|
+
state: 'running' | 'done' | 'failed';
|
|
53
|
+
request: CloudPublishRequest;
|
|
54
|
+
startedAt: number;
|
|
55
|
+
/** 进度:CLI 写给终端的行(英文,页面按开头识别阶段)。 */
|
|
56
|
+
lines: string[];
|
|
57
|
+
result?: CloudPublishResult;
|
|
58
|
+
error?: CloudJobError;
|
|
59
|
+
};
|
|
60
|
+
type Ctx = {
|
|
61
|
+
guardWrite: (needJson?: boolean) => boolean;
|
|
62
|
+
jsonBody: () => Promise<{
|
|
63
|
+
ok: true;
|
|
64
|
+
body: unknown;
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
}>;
|
|
68
|
+
send: (status: number, body: unknown) => void;
|
|
69
|
+
};
|
|
70
|
+
export declare class CloudHub {
|
|
71
|
+
private readonly bridge;
|
|
72
|
+
private readonly emit;
|
|
73
|
+
private jobs;
|
|
74
|
+
private seq;
|
|
75
|
+
constructor(bridge: CloudBridge | undefined, emit: (projectId: string, job: CloudJob) => void);
|
|
76
|
+
get available(): boolean;
|
|
77
|
+
/** `/__joplo/cloud/<sub>`:sub = 'account'。 */
|
|
78
|
+
handleGlobal(sub: string, req: http.IncomingMessage, ctx: Ctx): Promise<boolean>;
|
|
79
|
+
/** `/__joplo/p/<id>/cloud/<sub>`:sub = 'publish'(GET 读任务,POST 开始发布)。 */
|
|
80
|
+
handleProject(projectId: string, dir: string, sub: string, req: http.IncomingMessage, ctx: Ctx): Promise<boolean>;
|
|
81
|
+
private start;
|
|
82
|
+
/** 测试:等当前任务结束。 */
|
|
83
|
+
settled(projectId: string): Promise<CloudJob | null>;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
package/dist/cloud.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export const CLOUD_EVENT = 'joplo:cloud';
|
|
2
|
+
const MAX_LINES = 40;
|
|
3
|
+
const strings = (v, name) => {
|
|
4
|
+
if (v === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
if (!Array.isArray(v) || v.length > 200 || v.some((x) => typeof x !== 'string' || !x || x.length > 512))
|
|
7
|
+
throw new Error(`${name} must be an array of non-empty strings`);
|
|
8
|
+
return v;
|
|
9
|
+
};
|
|
10
|
+
export class CloudHub {
|
|
11
|
+
bridge;
|
|
12
|
+
emit;
|
|
13
|
+
jobs = new Map();
|
|
14
|
+
seq = 0;
|
|
15
|
+
constructor(bridge, emit) {
|
|
16
|
+
this.bridge = bridge;
|
|
17
|
+
this.emit = emit;
|
|
18
|
+
}
|
|
19
|
+
get available() {
|
|
20
|
+
return !!this.bridge;
|
|
21
|
+
}
|
|
22
|
+
/** `/__joplo/cloud/<sub>`:sub = 'account'。 */
|
|
23
|
+
async handleGlobal(sub, req, ctx) {
|
|
24
|
+
if (sub !== 'account' || (req.method ?? 'GET') !== 'GET')
|
|
25
|
+
return false;
|
|
26
|
+
if (!ctx.guardWrite(false))
|
|
27
|
+
return true;
|
|
28
|
+
if (!this.bridge)
|
|
29
|
+
return ctx.send(200, { available: false }), true;
|
|
30
|
+
try {
|
|
31
|
+
ctx.send(200, { available: true, account: await this.bridge.account() });
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
ctx.send(500, { error: { code: 'INTERNAL', message: e instanceof Error ? e.message : String(e) } });
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
/** `/__joplo/p/<id>/cloud/<sub>`:sub = 'publish'(GET 读任务,POST 开始发布)。 */
|
|
39
|
+
async handleProject(projectId, dir, sub, req, ctx) {
|
|
40
|
+
if (sub !== 'publish')
|
|
41
|
+
return false;
|
|
42
|
+
const method = req.method ?? 'GET';
|
|
43
|
+
if (method === 'GET') {
|
|
44
|
+
if (!ctx.guardWrite(false))
|
|
45
|
+
return true;
|
|
46
|
+
ctx.send(200, { available: this.available, job: this.jobs.get(projectId) ?? null });
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (method !== 'POST')
|
|
50
|
+
return false;
|
|
51
|
+
if (!ctx.guardWrite())
|
|
52
|
+
return true;
|
|
53
|
+
if (!this.bridge)
|
|
54
|
+
return ctx.send(409, { error: { code: 'UNSUPPORTED_ACTION', message: 'This board process cannot publish to the cloud. Stop it and run joplo dev again' } }), true;
|
|
55
|
+
const b = await ctx.jsonBody();
|
|
56
|
+
if (!b.ok)
|
|
57
|
+
return true;
|
|
58
|
+
let request;
|
|
59
|
+
try {
|
|
60
|
+
const body = (b.body ?? {});
|
|
61
|
+
const scenarios = strings(body.scenarios, 'scenarios');
|
|
62
|
+
const features = strings(body.features, 'features');
|
|
63
|
+
request = { ...(scenarios?.length ? { scenarios } : {}), ...(features?.length ? { features } : {}) };
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
return ctx.send(400, { error: { code: 'USAGE', message: e instanceof Error ? e.message : String(e) } }), true;
|
|
67
|
+
}
|
|
68
|
+
const running = this.jobs.get(projectId);
|
|
69
|
+
if (running?.state === 'running')
|
|
70
|
+
return ctx.send(200, { job: running }), true;
|
|
71
|
+
ctx.send(202, { job: this.start(projectId, dir, request) });
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
start(projectId, dir, request) {
|
|
75
|
+
const job = { id: `c${++this.seq}`, state: 'running', request, startedAt: Date.now(), lines: [] };
|
|
76
|
+
this.jobs.set(projectId, job);
|
|
77
|
+
const push = () => this.emit(projectId, job);
|
|
78
|
+
push();
|
|
79
|
+
void this.bridge
|
|
80
|
+
.publish(dir, request, (line) => {
|
|
81
|
+
job.lines = [...job.lines, line].slice(-MAX_LINES);
|
|
82
|
+
push();
|
|
83
|
+
})
|
|
84
|
+
.then((result) => {
|
|
85
|
+
job.state = 'done';
|
|
86
|
+
job.result = result;
|
|
87
|
+
})
|
|
88
|
+
.catch((e) => {
|
|
89
|
+
const err = e;
|
|
90
|
+
job.state = 'failed';
|
|
91
|
+
job.error = {
|
|
92
|
+
code: typeof err.code === 'string' ? err.code : 'INTERNAL',
|
|
93
|
+
message: typeof err.message === 'string' ? err.message : String(e),
|
|
94
|
+
...(typeof err.loginCommand === 'string' ? { loginCommand: err.loginCommand } : {}),
|
|
95
|
+
};
|
|
96
|
+
})
|
|
97
|
+
.finally(push);
|
|
98
|
+
return job;
|
|
99
|
+
}
|
|
100
|
+
/** 测试:等当前任务结束。 */
|
|
101
|
+
async settled(projectId) {
|
|
102
|
+
for (let i = 0; i < 2000; i++) {
|
|
103
|
+
const j = this.jobs.get(projectId);
|
|
104
|
+
if (!j || j.state !== 'running')
|
|
105
|
+
return j ?? null;
|
|
106
|
+
await new Promise((r) => setTimeout(r, 5));
|
|
107
|
+
}
|
|
108
|
+
return this.jobs.get(projectId) ?? null;
|
|
109
|
+
}
|
|
110
|
+
}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* v2 接口(ADR-0002):CLI 只依赖这里导出的三个函数。由 T-board 实现,届时 index.ts 改为导出它们。
|
|
3
3
|
*/
|
|
4
|
-
import type { AppearanceFont, AppearanceStroke, Diagnostic } from '@joplo-app/core';
|
|
4
|
+
import type { AppearanceFont, AppearanceStroke, Diagnostic, ScopeInfo, ScopeRequest } from '@joplo-app/core';
|
|
5
|
+
import type { CloudBridge } from './cloud.js';
|
|
6
|
+
export type { CloudAccount, CloudBridge, CloudJob, CloudJobError, CloudPublishRequest, CloudPublishResult } from './cloud.js';
|
|
5
7
|
export type DevOptions = {
|
|
6
8
|
projectDir: string;
|
|
7
9
|
/** 缺省 4790;被占用时报错,不静默换端口。 */
|
|
8
10
|
port?: number;
|
|
9
11
|
open?: boolean;
|
|
10
12
|
log?: (line: string) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 直接发布到云端(D76):CLI 注入登录与 share();看板「导出 ▾」里的「发布到 Joplo Cloud」用它。
|
|
15
|
+
* 只在本进程启动看板时生效(加入已有看板时,那个进程用它自己的)。
|
|
16
|
+
*/
|
|
17
|
+
cloud?: CloudBridge;
|
|
11
18
|
};
|
|
12
19
|
/** 单进程:同一个 JOPLO_HOME 下只有一个看板进程,同时服务多个项目(编译、热更新、选中、导出)。 */
|
|
13
20
|
/**
|
|
@@ -30,14 +37,32 @@ export type BuildOptions = {
|
|
|
30
37
|
* 缺省 false:只含选定方案,与原来完全一致。
|
|
31
38
|
*/
|
|
32
39
|
review?: boolean;
|
|
40
|
+
/** 本机目录(缺省 JOPLO_HOME 或 ~/.joplo):读声音供应商 profile(D74);测试指向临时目录。 */
|
|
41
|
+
home?: string;
|
|
42
|
+
/**
|
|
43
|
+
* 按场景保密分享(D75,`--scenario` / `--feature`):构建时把 IR 裁剪到这些场景,产物里不出现范围外的功能、方案、场景。
|
|
44
|
+
* 缺省(或两个数组都为空)时与原来完全一致。写错场景 / 功能时报错,不写任何文件。
|
|
45
|
+
*/
|
|
46
|
+
scope?: ScopeRequest;
|
|
33
47
|
};
|
|
34
48
|
/** 静态发布站:只含选定方案(compile 的 publish 模式),离线可打开,可直接 `wrangler deploy`。 */
|
|
49
|
+
/**
|
|
50
|
+
* voice(D74):带上的朗读音频。clips = 片段数;bytes = 新写入的字节;missing = 当前声音下还没有音频的步骤数(观众端这些步骤用浏览器朗读);
|
|
51
|
+
* profile = 选用的声音供应商名。没有选用供应商、也没有音频时省略。
|
|
52
|
+
*/
|
|
35
53
|
export type BuildResult = {
|
|
36
54
|
outDir: string;
|
|
37
55
|
files: string[];
|
|
38
56
|
routes: string[];
|
|
39
57
|
scenarios: string[];
|
|
40
58
|
diagnostics: Diagnostic[];
|
|
59
|
+
voice?: {
|
|
60
|
+
clips: number;
|
|
61
|
+
bytes: number;
|
|
62
|
+
missing: number;
|
|
63
|
+
profile: string | null;
|
|
64
|
+
}; /** 有 scope 时:范围与借用了哪些别的功能的内容(D75)。 */
|
|
65
|
+
scope?: ScopeInfo;
|
|
41
66
|
};
|
|
42
67
|
export declare function buildSite(opts: BuildOptions): Promise<BuildResult>;
|
|
43
68
|
export type RenderOptions = {
|
|
@@ -61,6 +86,8 @@ export type RenderOptions = {
|
|
|
61
86
|
height: number;
|
|
62
87
|
};
|
|
63
88
|
scale?: number;
|
|
89
|
+
/** 按场景保密分享(D75):只用这些场景裁剪后的 IR 渲染(share 的预览图),画面上不出现范围外功能堆进来的元素。 */
|
|
90
|
+
scope?: string[];
|
|
64
91
|
};
|
|
65
92
|
export type RenderedElement = {
|
|
66
93
|
id: string;
|
package/dist/dev.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ViteDevServer } from 'vite';
|
|
|
3
3
|
import { type Diagnostic, type Project } from '@joplo-app/core';
|
|
4
4
|
import type { DevHandle, DevOptions } from './contract.js';
|
|
5
5
|
import { type ExportDeps } from './export.js';
|
|
6
|
+
import { CLOUD_EVENT, type CloudBridge } from './cloud.js';
|
|
6
7
|
import type { DistWeb } from './web-assets.js';
|
|
7
8
|
/** 推给看板的编译结果。`project` 始终是最近一次成功的 IR;`ok=false` 时看板显示错误列表、保留画面。 */
|
|
8
9
|
export type DevPayload = {
|
|
@@ -24,6 +25,9 @@ export type ProjectSummary = {
|
|
|
24
25
|
};
|
|
25
26
|
export declare const IR_EVENT = "joplo:ir";
|
|
26
27
|
export declare const PROJECTS_EVENT = "joplo:projects";
|
|
28
|
+
/** 朗读状态变化(D74):{ projectId, state }。 */
|
|
29
|
+
export declare const VOICE_EVENT = "joplo:voice";
|
|
30
|
+
export { CLOUD_EVENT };
|
|
27
31
|
export declare function sendJson(res: http.ServerResponse, status: number, body: unknown): void;
|
|
28
32
|
/** Content-Type 必须是 application/json,只允许附带 charset=utf-8 参数。 */
|
|
29
33
|
export declare function isJsonContentType(ct: string | undefined): boolean;
|
|
@@ -54,6 +58,8 @@ export type HubOptions = {
|
|
|
54
58
|
exportDeps?: Partial<ExportDeps>;
|
|
55
59
|
/** 启动这个看板的项目目录(写进 server.json,后来加入的 joplo dev 会说明)。 */
|
|
56
60
|
startedIn?: string;
|
|
61
|
+
/** 直接发布到云端(D76):由 CLI 注入;没有时看板禁用「发布到 Joplo Cloud」。 */
|
|
62
|
+
cloud?: CloudBridge;
|
|
57
63
|
};
|
|
58
64
|
export declare function serverVersion(): string;
|
|
59
65
|
export type Hub = {
|
|
@@ -75,7 +81,7 @@ export type Hub = {
|
|
|
75
81
|
close(): Promise<void>;
|
|
76
82
|
};
|
|
77
83
|
export declare function createHub(opts?: HubOptions): Promise<Hub>;
|
|
78
|
-
export type InternalDevOptions = DevOptions & Pick<HubOptions, 'watch' | 'home' | 'exportDeps'>;
|
|
84
|
+
export type InternalDevOptions = DevOptions & Pick<HubOptions, 'watch' | 'home' | 'exportDeps' | 'cloud'>;
|
|
79
85
|
export type InternalDevHandle = DevHandle & {
|
|
80
86
|
token: string;
|
|
81
87
|
port: number;
|
package/dist/dev.js
CHANGED
|
@@ -18,14 +18,20 @@ import fs from 'node:fs';
|
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
import tailwindcss from '@tailwindcss/vite';
|
|
20
20
|
import { createLogger, createServer } from 'vite';
|
|
21
|
-
import { JoploError } from '@joplo-app/core';
|
|
21
|
+
import { JoploError, LocalReviewWrite } from '@joplo-app/core';
|
|
22
|
+
import { LocalReviewHub } from "./local-review.js";
|
|
22
23
|
import { ExportHub } from "./export.js";
|
|
24
|
+
import { VoiceHub } from "./voice-http.js";
|
|
25
|
+
import { CLOUD_EVENT, CloudHub } from "./cloud.js";
|
|
23
26
|
import { Registry, clearServerInfo, joploHome, normalizeSettings, pidAlive, projectIdOf, readServerInfo, readSettings, writeServerInfo, writeSettings } from "./home.js";
|
|
24
27
|
import { compileProject, invalidateProjectModules } from "./project.js";
|
|
25
28
|
import { SelectionBody, readSelection, resolveSelection, writeSelection } from "./selection.js";
|
|
26
29
|
import { IGNORED_DIRS, cssSourcePlugin, isProjectSource, joploProjectPlugin, kitAliases, locateWebAssets, realProjectDir } from "./vite-shared.js";
|
|
27
30
|
export const IR_EVENT = 'joplo:ir';
|
|
28
31
|
export const PROJECTS_EVENT = 'joplo:projects';
|
|
32
|
+
/** 朗读状态变化(D74):{ projectId, state }。 */
|
|
33
|
+
export const VOICE_EVENT = 'joplo:voice';
|
|
34
|
+
export { CLOUD_EVENT };
|
|
29
35
|
const MAX_BODY = 64 * 1024;
|
|
30
36
|
const SECURITY_HEADERS = {
|
|
31
37
|
'x-content-type-options': 'nosniff',
|
|
@@ -171,6 +177,7 @@ export async function createHub(opts = {}) {
|
|
|
171
177
|
const allowedHosts = () => new Set([`127.0.0.1:${actualPort}`, `localhost:${actualPort}`]);
|
|
172
178
|
const allowedOrigins = () => new Set([`http://127.0.0.1:${actualPort}`, `http://localhost:${actualPort}`]);
|
|
173
179
|
const baseUrl = () => `http://127.0.0.1:${actualPort}/`;
|
|
180
|
+
const reviewHub = new LocalReviewHub(baseUrl);
|
|
174
181
|
const activeDirs = () => [...slots.values()].filter((s) => !s.closed).map((s) => s.dir);
|
|
175
182
|
const slotOfFile = (file) => [...slots.values()].find((s) => !s.closed && isProjectSource(s.dir, file)) ?? null;
|
|
176
183
|
const recordOf = (id) => registry.list().find((r) => projectIdOf(r.dir) === id) ?? null;
|
|
@@ -213,6 +220,10 @@ export async function createHub(opts = {}) {
|
|
|
213
220
|
log(`[joplo] ${path.basename(slot.dir)} compilation failed (${errors.length}): ${errors.map((d) => `${d.at ?? ''} ${d.message}`).join('; ').slice(0, 400)}`);
|
|
214
221
|
if (out.project && out.project.name)
|
|
215
222
|
registry.rename(slot.dir, out.project.name);
|
|
223
|
+
if (out.project && !errors.length)
|
|
224
|
+
reviewHub.sync(slot.dir, slot.id, out.project);
|
|
225
|
+
else
|
|
226
|
+
reviewHub.invalidate(slot.dir, 'compile_error');
|
|
216
227
|
if (!closed)
|
|
217
228
|
server?.ws.send({ type: 'custom', event: IR_EVENT, data: { projectId: slot.id, ...slot.payload } });
|
|
218
229
|
broadcastProjects();
|
|
@@ -233,6 +244,7 @@ export async function createHub(opts = {}) {
|
|
|
233
244
|
await recompile(slot);
|
|
234
245
|
}
|
|
235
246
|
catch (e) {
|
|
247
|
+
reviewHub.invalidate(slot.dir, 'compile_error');
|
|
236
248
|
log(`[joplo] Compilation exception: ${e instanceof Error ? e.message : String(e)}`);
|
|
237
249
|
}
|
|
238
250
|
} while (slot.dirty && !slot.closed);
|
|
@@ -274,6 +286,7 @@ export async function createHub(opts = {}) {
|
|
|
274
286
|
if (slot.timer)
|
|
275
287
|
clearTimeout(slot.timer);
|
|
276
288
|
await slot.running?.catch(() => undefined);
|
|
289
|
+
reviewHub.invalidate(slot.dir, 'server_stopped');
|
|
277
290
|
await slot.loader?.close().catch(() => undefined);
|
|
278
291
|
if (watch && server)
|
|
279
292
|
server.watcher.unwatch(slot.dir);
|
|
@@ -322,6 +335,23 @@ export async function createHub(opts = {}) {
|
|
|
322
335
|
deps: opts.exportDeps,
|
|
323
336
|
onEvent: () => undefined,
|
|
324
337
|
});
|
|
338
|
+
// 朗读(D74):声音供应商 profile(本机)与项目音频缓存;状态变化推 joplo:voice
|
|
339
|
+
const voiceHub = new VoiceHub(opts.home ?? joploHome(), {
|
|
340
|
+
emit: (projectId, state) => {
|
|
341
|
+
if (!closed)
|
|
342
|
+
server?.ws.send({ type: 'custom', event: VOICE_EVENT, data: { projectId, state } });
|
|
343
|
+
},
|
|
344
|
+
// profile 是本机共用的:改了就通知所有看板,各自重新取自己项目的声音状态
|
|
345
|
+
profilesChanged: () => {
|
|
346
|
+
if (!closed)
|
|
347
|
+
server?.ws.send({ type: 'custom', event: VOICE_EVENT, data: { profilesChanged: true } });
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
// 直接发布到云端(D76):发布任务变化推 joplo:cloud
|
|
351
|
+
const cloudHub = new CloudHub(opts.cloud, (projectId, job) => {
|
|
352
|
+
if (!closed)
|
|
353
|
+
server?.ws.send({ type: 'custom', event: CLOUD_EVENT, data: { projectId, job } });
|
|
354
|
+
});
|
|
325
355
|
// ---------- HTTP ----------
|
|
326
356
|
const deny = (res, status, message) => sendJson(res, status, { error: { code: 'PERMISSION_DENIED', message } });
|
|
327
357
|
/** 写接口:Origin(有则必须是看板自己)、令牌、Content-Type。返回 false 表示已拒绝。 */
|
|
@@ -349,11 +379,31 @@ export async function createHub(opts = {}) {
|
|
|
349
379
|
};
|
|
350
380
|
const fail = (res, e) => {
|
|
351
381
|
const code = e instanceof JoploError ? e.code : 'INTERNAL';
|
|
352
|
-
const status = code === 'NOT_FOUND' ? 404 : code === 'USAGE' ? 400 : code === 'RENDER_FAILED' || code === 'EXPORT_COMPONENT_MISSING' ? 503 : 500;
|
|
382
|
+
const status = code === 'NOT_FOUND' ? 404 : code === 'USAGE' || code === 'INVALID_REFERENCE' ? 400 : code === 'REVISION_CONFLICT' || code === 'IDEMPOTENCY_MISMATCH' ? 409 : code === 'RENDER_FAILED' || code === 'EXPORT_COMPONENT_MISSING' ? 503 : 500;
|
|
353
383
|
sendJson(res, status, { error: { code, message: e instanceof Error ? e.message : String(e) } });
|
|
354
384
|
};
|
|
355
385
|
async function handleProject(id, rest, req, res) {
|
|
356
386
|
const method = req.method ?? 'GET';
|
|
387
|
+
if (rest === 'review' && (method === 'GET' || method === 'POST')) {
|
|
388
|
+
if (!guardWrite(req, res, 403, method === 'POST'))
|
|
389
|
+
return;
|
|
390
|
+
const slot = await ensure(id);
|
|
391
|
+
if (slot.compiling || slot.dirty || slot.timer || !slot.payload.ok || !slot.payload.project || slot.payload.diagnostics.some(d => d.severity === 'error'))
|
|
392
|
+
throw new JoploError('REVISION_CONFLICT', 'Wait for the project to compile successfully before reviewing');
|
|
393
|
+
if (method === 'GET') {
|
|
394
|
+
const optionId = new URL(req.url, baseUrl()).searchParams.get('option');
|
|
395
|
+
if (!optionId)
|
|
396
|
+
throw new JoploError('USAGE', 'option is required');
|
|
397
|
+
return sendJson(res, 200, reviewHub.state(slot.dir, optionId));
|
|
398
|
+
}
|
|
399
|
+
const body = await jsonBody(req, res);
|
|
400
|
+
if (!body.ok)
|
|
401
|
+
return;
|
|
402
|
+
const input = LocalReviewWrite.safeParse(body.body);
|
|
403
|
+
if (!input.success)
|
|
404
|
+
throw new JoploError('USAGE', 'Invalid review request: include a sessionId, requestId, type, and page context for feedback (1–10000 characters)');
|
|
405
|
+
return sendJson(res, 200, reviewHub.write(slot.dir, slot.payload.project, input.data));
|
|
406
|
+
}
|
|
357
407
|
if (rest === 'ir' && method === 'GET') {
|
|
358
408
|
const slot = await ensure(id);
|
|
359
409
|
return sendJson(res, 200, { projectId: id, ...slot.payload });
|
|
@@ -406,6 +456,18 @@ export async function createHub(opts = {}) {
|
|
|
406
456
|
req.method = 'GET';
|
|
407
457
|
return 'next';
|
|
408
458
|
}
|
|
459
|
+
if (rest === 'voice' || rest.startsWith('voice/')) {
|
|
460
|
+
const slot = await ensure(id);
|
|
461
|
+
const ctx = { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), send: (status, body) => sendJson(res, status, body) };
|
|
462
|
+
if (await voiceHub.handleProject(id, slot.dir, slot.payload.project, rest === 'voice' ? '' : rest.slice('voice/'.length), req, res, ctx))
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (rest.startsWith('cloud/')) {
|
|
466
|
+
const slot = await ensure(id);
|
|
467
|
+
const ctx = { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), send: (status, body) => sendJson(res, status, body) };
|
|
468
|
+
if (await cloudHub.handleProject(id, slot.dir, rest.slice('cloud/'.length), req, ctx))
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
409
471
|
if (rest.startsWith('export/')) {
|
|
410
472
|
const slot = await ensure(id);
|
|
411
473
|
return exportsHub.handle(rest.slice('export/'.length), req, res, { projectId: id, dir: slot.dir, project: slot.payload.project, guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), fail: (e) => fail(res, e) });
|
|
@@ -474,6 +536,16 @@ export async function createHub(opts = {}) {
|
|
|
474
536
|
return sendJson(res, 200, { ok: true });
|
|
475
537
|
}
|
|
476
538
|
// 导出组件的安装(D66):只接受本机看板带令牌的请求(handleRuntime 内校验)
|
|
539
|
+
if (url.pathname.startsWith('/__joplo/voice/')) {
|
|
540
|
+
const ctx = { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), send: (status, body) => sendJson(res, status, body) };
|
|
541
|
+
if (await voiceHub.handleGlobal(url.pathname.slice('/__joplo/voice/'.length), req, ctx))
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (url.pathname.startsWith('/__joplo/cloud/')) {
|
|
545
|
+
const ctx = { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), send: (status, body) => sendJson(res, status, body) };
|
|
546
|
+
if (await cloudHub.handleGlobal(url.pathname.slice('/__joplo/cloud/'.length), req, ctx))
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
477
549
|
if (url.pathname.startsWith('/__joplo/export-runtime/'))
|
|
478
550
|
return exportsHub.handleRuntime(url.pathname.slice('/__joplo/export-runtime/'.length), req, res, { guardWrite: (needJson = true) => guardWrite(req, res, 403, needJson), jsonBody: () => jsonBody(req, res), fail: (e) => fail(res, e) });
|
|
479
551
|
const pm = /^\/__joplo\/p\/([^/]+)\/(.+)$/.exec(url.pathname);
|
|
@@ -552,9 +624,10 @@ export async function createHub(opts = {}) {
|
|
|
552
624
|
const slot = slotOfFile(path.resolve(file));
|
|
553
625
|
if (!slot)
|
|
554
626
|
return;
|
|
627
|
+
reviewHub.invalidate(slot.dir, 'source_changed');
|
|
555
628
|
if (slot.timer)
|
|
556
629
|
clearTimeout(slot.timer);
|
|
557
|
-
slot.timer = setTimeout(() => void run(slot), 60);
|
|
630
|
+
slot.timer = setTimeout(() => { slot.timer = null; void run(slot); }, 60);
|
|
558
631
|
});
|
|
559
632
|
}
|
|
560
633
|
return {
|
|
@@ -571,6 +644,7 @@ export async function createHub(opts = {}) {
|
|
|
571
644
|
projects: summaries,
|
|
572
645
|
close: async () => {
|
|
573
646
|
closed = true;
|
|
647
|
+
voiceHub.close();
|
|
574
648
|
await exportsHub.close();
|
|
575
649
|
for (const s of [...slots.values()])
|
|
576
650
|
await deactivate(s);
|
|
@@ -582,7 +656,7 @@ export async function createHub(opts = {}) {
|
|
|
582
656
|
}
|
|
583
657
|
/** 启动一个看板进程并打开一个项目(等首次编译完成)。缺省不持久化。 */
|
|
584
658
|
export async function createDev(opts) {
|
|
585
|
-
const hub = await createHub({ port: opts.port, log: opts.log, watch: opts.watch, home: opts.home ?? null, exportDeps: opts.exportDeps });
|
|
659
|
+
const hub = await createHub({ port: opts.port, log: opts.log, watch: opts.watch, home: opts.home ?? null, exportDeps: opts.exportDeps, cloud: opts.cloud });
|
|
586
660
|
try {
|
|
587
661
|
const { id, url, slot } = hub.addProject(opts.projectDir);
|
|
588
662
|
await slot.ready;
|
|
@@ -665,7 +739,7 @@ export async function startDev(opts) {
|
|
|
665
739
|
return existing;
|
|
666
740
|
let hub;
|
|
667
741
|
try {
|
|
668
|
-
hub = await createHub({ port: opts.port, log, home, exportDeps: opts.exportDeps, startedIn: projectDir });
|
|
742
|
+
hub = await createHub({ port: opts.port, log, home, exportDeps: opts.exportDeps, startedIn: projectDir, cloud: opts.cloud });
|
|
669
743
|
}
|
|
670
744
|
catch (e) {
|
|
671
745
|
// 另一个 joplo dev 恰好同时启动:端口被它占了,改为加入它
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - renderStep:某个场景某一步之后的截图、元素索引(带 at)与渲染告警。
|
|
7
7
|
* - exportRuntimeStatus / installExportRuntime / uninstallExportRuntime:Joplo 托管的导出组件(D66,`joplo setup export`)。
|
|
8
8
|
*/
|
|
9
|
-
export type { BuildOptions, BuildResult, DevHandle, DevOptions, RenderOptions, RenderResult, RenderedElement } from './contract.js';
|
|
9
|
+
export type { BuildOptions, BuildResult, CloudAccount, CloudBridge, CloudJob, CloudJobError, CloudPublishRequest, CloudPublishResult, DevHandle, DevOptions, RenderOptions, RenderResult, RenderedElement } from './contract.js';
|
|
10
10
|
export { startDev } from './dev.js';
|
|
11
11
|
export { buildSite } from './build.js';
|
|
12
12
|
export { renderStep } from './render.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type LocalReviewContext, type LocalReviewLocation, type LocalReviewState, type LocalReviewWrite, type Project } from '@joplo-app/core';
|
|
2
|
+
export declare function localReviewRevision(project: Project, optionId: string): string;
|
|
3
|
+
export declare function localReviewContext(project: Project, optionId: string, input: LocalReviewLocation): LocalReviewContext;
|
|
4
|
+
/** 一个 Hub 是一个不可复用的实例身份;不同 Hub 即使打开同一项目,也写不同的会话文件。 */
|
|
5
|
+
export declare class LocalReviewHub {
|
|
6
|
+
private baseUrl;
|
|
7
|
+
readonly instanceId: `${string}-${string}-${string}-${string}-${string}`;
|
|
8
|
+
private current;
|
|
9
|
+
private sessions;
|
|
10
|
+
constructor(baseUrl: () => string);
|
|
11
|
+
private key;
|
|
12
|
+
private persist;
|
|
13
|
+
private closeSession;
|
|
14
|
+
sync(dir: string, projectId: string, project: Project): void;
|
|
15
|
+
invalidate(dir: string, reason: 'source_changed' | 'compile_error' | 'server_stopped'): void;
|
|
16
|
+
state(dir: string, optionId: string): LocalReviewState;
|
|
17
|
+
write(dir: string, project: Project, input: LocalReviewWrite): LocalReviewState;
|
|
18
|
+
}
|