cortico-world-extra-actions 0.3.21 → 0.3.23
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/webui.js +16 -3
- package/package.json +1 -1
- package/src/online.js +20 -12
- package/src/world.js +12 -0
- package/tools/test_api_contract.mjs +61 -0
package/dist/webui.js
CHANGED
|
@@ -505,7 +505,10 @@ const panel = {
|
|
|
505
505
|
if (!state.library.ok) {
|
|
506
506
|
noteEl.hidden = false;
|
|
507
507
|
noteEl.className = 'ea-note bad';
|
|
508
|
-
|
|
508
|
+
// 后台有没有 download-library:没有就说明版本对不上,先别显示按钮
|
|
509
|
+
const api = Array.isArray(state.api) ? state.api : null;
|
|
510
|
+
const canDownload = !api || api.includes('download-library');
|
|
511
|
+
const smallLib = state.library.ok && (state.library.present ?? state.library.count) < 20 && canDownload
|
|
509
512
|
? `<b>当前动作库只有 ${state.library.present ?? state.library.count} 段</b>(插件自带的示例)。想要全部 105 段:
|
|
510
513
|
<button class="ea-btn pri" type="button" data-act="download-library" style="margin-left:6px">一键下载并安装</button>
|
|
511
514
|
<span class="ea-dim">(插件自己下、自己解压,不用你选文件夹)</span><br>`
|
|
@@ -581,6 +584,16 @@ const panel = {
|
|
|
581
584
|
};
|
|
582
585
|
qInp.oninput = () => { query = qInp.value.trim(); renderList(); };
|
|
583
586
|
|
|
587
|
+
/** 把后台的报错翻译成用户能照做的动作。 */
|
|
588
|
+
function explainErr(err) {
|
|
589
|
+
const raw = String(err?.message ?? err ?? '');
|
|
590
|
+
if (/unknown method/i.test(raw)) {
|
|
591
|
+
return '扩展刚更新过,但 Coopanion 还在用旧的后台。请完全退出 Coopanion 再打开,这个按钮就能用了。';
|
|
592
|
+
}
|
|
593
|
+
if (/内置形象包不给写/.test(raw)) return '这是内置形象包,不能写。先「建立空的角色包」再保存。';
|
|
594
|
+
return raw || '操作失败';
|
|
595
|
+
}
|
|
596
|
+
|
|
584
597
|
async function doDownloadLibrary() {
|
|
585
598
|
busy(true);
|
|
586
599
|
say('正在下载完整动作库…(约 370 MB,视网速几分钟,别关这个页面)');
|
|
@@ -589,7 +602,7 @@ const panel = {
|
|
|
589
602
|
say(`动作库已装好:${r.modules} 段 → ${r.path}`);
|
|
590
603
|
await loadAll();
|
|
591
604
|
} catch (err) {
|
|
592
|
-
say('下载没成功:' +
|
|
605
|
+
say('下载没成功:' + explainErr(err), true);
|
|
593
606
|
} finally {
|
|
594
607
|
busy(false);
|
|
595
608
|
}
|
|
@@ -748,7 +761,7 @@ const panel = {
|
|
|
748
761
|
say(r.note ? `${r.note}(${r.libraryDir})` : `动作库已更新(${r.libraryDir})`);
|
|
749
762
|
}
|
|
750
763
|
} catch (err) {
|
|
751
|
-
say(
|
|
764
|
+
say(explainErr(err), true);
|
|
752
765
|
} finally {
|
|
753
766
|
busy(false);
|
|
754
767
|
}
|
package/package.json
CHANGED
package/src/online.js
CHANGED
|
@@ -18,23 +18,31 @@ import { extractTarGz } from './tar.js';
|
|
|
18
18
|
/** 维护者把 Gitee 仓库的 raw/下载前缀填这里(末尾不要带斜杠)。 */
|
|
19
19
|
export const DEFAULT_REMOTE = '';
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/** 动作库分片:主源 Gitee(国内直连快),sha256 用于完整性校验。 */
|
|
22
22
|
export const LIB_PARTS = [
|
|
23
|
-
{ name: 'cortico-world-shenshen-lib-1', version: '1.0.0', modules: 15, bytes: 51758812, sha256: 'db10bf40ae3078d087966b048fd1ab9704b16ffd99179e80799e75ddf2efc1ca'
|
|
24
|
-
|
|
25
|
-
{ name: 'cortico-world-shenshen-lib-
|
|
26
|
-
|
|
27
|
-
{ name: 'cortico-world-shenshen-lib-
|
|
28
|
-
|
|
29
|
-
{ name: 'cortico-world-shenshen-lib-
|
|
30
|
-
|
|
23
|
+
{ name: 'cortico-world-shenshen-lib-1', version: '1.0.0', modules: 15, bytes: 51758812, sha256: 'db10bf40ae3078d087966b048fd1ab9704b16ffd99179e80799e75ddf2efc1ca',
|
|
24
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-1.tgz' },
|
|
25
|
+
{ name: 'cortico-world-shenshen-lib-2', version: '1.0.0', modules: 15, bytes: 53693012, sha256: '541bb2ce6ee0ccc53aa9437213ec15e7b981ee0edb04b33037d941c235b6fcff',
|
|
26
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-2.tgz' },
|
|
27
|
+
{ name: 'cortico-world-shenshen-lib-3', version: '1.0.0', modules: 15, bytes: 53643090, sha256: 'b4a908bf0c4fb778829e13ca230801d3110935104d6b5b2e692131372e946182',
|
|
28
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-3.tgz' },
|
|
29
|
+
{ name: 'cortico-world-shenshen-lib-4', version: '1.0.0', modules: 13, bytes: 53889958, sha256: 'c528c70954cb20afb57568c85ada3b6af8ca274a059bde9c2cba8774e37f65fe',
|
|
30
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-4.tgz' },
|
|
31
|
+
{ name: 'cortico-world-shenshen-lib-5', version: '1.0.0', modules: 13, bytes: 52249938, sha256: '575b60e97fe87198dc9794f3848b6cfd422238df081810ac7169c804cfa80212',
|
|
32
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-5.tgz' },
|
|
33
|
+
{ name: 'cortico-world-shenshen-lib-6', version: '1.0.0', modules: 14, bytes: 51269171, sha256: '19b06067b724555e36633ba63f0696631287278447e78d4a0606509de4b03f64',
|
|
34
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-6.tgz' },
|
|
35
|
+
{ name: 'cortico-world-shenshen-lib-7', version: '1.0.0', modules: 14, bytes: 51556774, sha256: 'a533d38e5504156539bbbdcf4bf231d6162f9033a83ab82317cd5c72be934a6e',
|
|
36
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-7.tgz' },
|
|
37
|
+
{ name: 'cortico-world-shenshen-lib-8', version: '1.0.0', modules: 6, bytes: 20030747, sha256: 'ac8fdf8c0927369226ca09f646f2a8a40c167a954260670463c64727713d0a81',
|
|
38
|
+
url: 'https://gitee.com/Daniele-WOLF-Holo/shenshen-actions/releases/download/library/lib-8.tgz' },
|
|
31
39
|
];
|
|
32
40
|
|
|
33
|
-
/**
|
|
41
|
+
/** 每片的候选地址:Gitee 优先,官方 npm 兜底(npm 分片可能会被撤,404 会立刻跳过)。 */
|
|
34
42
|
export const partTarballs = (p) => [
|
|
35
|
-
|
|
43
|
+
p.url,
|
|
36
44
|
`https://registry.npmjs.org/${p.name}/-/${p.name}-${p.version}.tgz`,
|
|
37
|
-
];
|
|
45
|
+
].filter(Boolean);
|
|
38
46
|
|
|
39
47
|
const MAX_LIBRARY_BYTES = 800 * 1024 * 1024; // 完整库上限
|
|
40
48
|
const MAX_ACTION_BYTES = 32 * 1024 * 1024; // 单个动作上限
|
package/src/world.js
CHANGED
|
@@ -17,6 +17,13 @@ import { ensureStarter, installStarterLibrary, libraryHealth, restorePack, safeP
|
|
|
17
17
|
import { FALLBACK_ACTION_BASE, FALLBACK_LIBRARY, LIB_PARTS, actionUrl, flatActionUrl, installAction, installLibrary, installLibraryParts, libraryUrl } from './online.js';
|
|
18
18
|
import { petFigures, petState } from './pet.js';
|
|
19
19
|
|
|
20
|
+
/** 面板能调的方法清单 —— 写进 state.api,让面板发现自己和后台不是同一版本。 */
|
|
21
|
+
const METHODS = [
|
|
22
|
+
'state', 'catalog', 'dirs', 'save', 'remove', 'clear', 'prune', 'add',
|
|
23
|
+
'reindex', 'find-libraries', 'set-library', 'use-starter-library', 'restore-pack',
|
|
24
|
+
'download-library', 'download-action', 'reload',
|
|
25
|
+
];
|
|
26
|
+
|
|
20
27
|
const ID = 'extra-actions';
|
|
21
28
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
22
29
|
const CATALOG_FILE = join(HERE, '..', 'assets', 'catalog.json');
|
|
@@ -370,6 +377,9 @@ export class ExtraActionsWorld {
|
|
|
370
377
|
return this.downloadLibrary();
|
|
371
378
|
case 'download-action':
|
|
372
379
|
return this.downloadAction(String(a[0] ?? ''), String(a[1] ?? ''));
|
|
380
|
+
// 老版本面板会调 reload:当作「重新读一遍状态」,别再报 unknown method
|
|
381
|
+
case 'reload':
|
|
382
|
+
return this.state();
|
|
373
383
|
default:
|
|
374
384
|
throw new Error(`unknown method: ${method}`);
|
|
375
385
|
}
|
|
@@ -390,6 +400,8 @@ export class ExtraActionsWorld {
|
|
|
390
400
|
const figs = await this.figures();
|
|
391
401
|
const pick = figs.find((f) => f.supported && !f.builtin) ?? figs.find((f) => f.supported) ?? null;
|
|
392
402
|
return {
|
|
403
|
+
// 面板据此判断自己调的方法后台到底有没有(扩展更新后没重启就会出现差异)
|
|
404
|
+
api: METHODS,
|
|
393
405
|
figures: figs,
|
|
394
406
|
current: figs.find((f) => f.current)?.id ?? null,
|
|
395
407
|
pick: pick?.id ?? null,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 面板 ↔ 后台 的接口契约测试。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要:面板(webui.js)是每次打开都从磁盘读的,而后台的 world 模块只在
|
|
5
|
+
* Coopanion 启动时 import 一次。扩展更新后没重启,就会出现「面板调了新方法、
|
|
6
|
+
* 后台还没有」→ 用户看到一句"接口异常"(日志里是 unknown method),很难自己想到要重启。
|
|
7
|
+
*
|
|
8
|
+
* 这里静态比对:面板 invoke 的方法名,必须都在 world 的 METHODS 清单里;
|
|
9
|
+
* 并且 world 的 switch 必须真的实现了 METHODS 里的每一个。
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const panel = readFileSync(join(here, '..', 'dist', 'webui.js'), 'utf8');
|
|
17
|
+
const world = readFileSync(join(here, '..', 'src', 'world.js'), 'utf8');
|
|
18
|
+
|
|
19
|
+
const fails = [];
|
|
20
|
+
const check = (fn, msg) => { try { fn(); console.log('ok ' + msg); } catch (e) { fails.push(`${msg} → ${e.message}`); console.log('FAIL ' + msg); } };
|
|
21
|
+
|
|
22
|
+
const panelMethods = [...new Set([...panel.matchAll(/invoke\('([a-z-]+)'/g)].map((m) => m[1]))].sort();
|
|
23
|
+
const methodsBlock = world.match(/const METHODS = \[([\s\S]*?)\];/);
|
|
24
|
+
const declared = methodsBlock ? [...new Set([...methodsBlock[1].matchAll(/'([a-z-]+)'/g)].map((m) => m[1]))].sort() : [];
|
|
25
|
+
const cases = [...new Set([...world.matchAll(/case '([a-z-]+)':/g)].map((m) => m[1]))].sort();
|
|
26
|
+
|
|
27
|
+
console.log(`面板调用 ${panelMethods.length} 个方法:${panelMethods.join(', ')}`);
|
|
28
|
+
console.log(`world 声明 ${declared.length} 个,实现 ${cases.length} 个`);
|
|
29
|
+
|
|
30
|
+
check(() => {
|
|
31
|
+
if (!methodsBlock) throw new Error('world 里找不到 METHODS 清单');
|
|
32
|
+
}, 'world 有 METHODS 清单');
|
|
33
|
+
|
|
34
|
+
check(() => {
|
|
35
|
+
const missing = panelMethods.filter((m) => !declared.includes(m));
|
|
36
|
+
if (missing.length) throw new Error('面板调了但 METHODS 没声明:' + missing.join(', '));
|
|
37
|
+
}, '面板调用的方法都在 METHODS 里');
|
|
38
|
+
|
|
39
|
+
check(() => {
|
|
40
|
+
const unimplemented = declared.filter((m) => !cases.includes(m));
|
|
41
|
+
if (unimplemented.length) throw new Error('METHODS 声明了但 switch 没实现:' + unimplemented.join(', '));
|
|
42
|
+
}, 'METHODS 里的每个方法都真的实现了');
|
|
43
|
+
|
|
44
|
+
check(() => {
|
|
45
|
+
if (!world.includes('api: METHODS')) throw new Error('state 里没带出 api 字段');
|
|
46
|
+
}, 'state 会带出 api 清单(面板据此判断版本是否一致');
|
|
47
|
+
|
|
48
|
+
check(() => {
|
|
49
|
+
if (!panel.includes("includes('download-library')")) throw new Error('面板没有检查 api 里有没有 download-library');
|
|
50
|
+
}, '面板会先检查后台支不支持下载再显示按钮');
|
|
51
|
+
|
|
52
|
+
check(() => {
|
|
53
|
+
if (!panel.includes('unknown method')) throw new Error('面板没有针对 unknown method 的友好提示');
|
|
54
|
+
}, '面板把 unknown method 翻译成「重启 Coopanion」的提示');
|
|
55
|
+
|
|
56
|
+
check(() => {
|
|
57
|
+
if (!cases.includes('reload')) throw new Error('world 没有 reload 别名');
|
|
58
|
+
}, 'world 保留了 reload 别名(兼容老面板)');
|
|
59
|
+
|
|
60
|
+
console.log(fails.length ? `\nFAIL (${fails.length})\n- ${fails.join('\n- ')}` : '\nall checks passed');
|
|
61
|
+
process.exit(fails.length ? 1 : 0);
|