@craft_eco/craft-mcp 0.1.21 → 0.1.25
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 +8 -8
- package/bin/craft-mcp.mjs +6 -0
- package/dist-server/game-workflow/draft-uploads.mjs +26 -8
- package/dist-server/game-workflow/publication-materials.mjs +48 -21
- package/dist-server/game-workflow/publications.mjs +35 -17
- package/dist-server/game-workflow/publish-capture.mjs +57 -21
- package/dist-server/mcp/publication-page.html +4 -3
- package/dist-server/mcp/publication-page.mjs +85 -24
- package/dist-server/mcp/publish-panel.mjs +54 -33
- package/dist-server/mcp/server.mjs +5 -4
- package/dist-server/upstream/craft-aigc.mjs +1 -1
- package/dist-server/upstream/publication-transport.mjs +37 -17
- package/package.json +3 -2
- package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.js +69 -5
- package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.js.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/process-artifacts.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/process-artifacts.js +5 -0
- package/vendor/agent-cli/dist/src/artifacts/process-artifacts.js.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/restore.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/restore.js +3 -2
- package/vendor/agent-cli/dist/src/artifacts/restore.js.map +1 -1
- package/vendor/agent-cli/dist/src/artifacts/scene-asset-delivery.d.ts +7 -0
- package/vendor/agent-cli/dist/src/artifacts/scene-asset-delivery.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/scene-asset-delivery.js +145 -0
- package/vendor/agent-cli/dist/src/artifacts/scene-asset-delivery.js.map +1 -0
- package/vendor/agent-cli/dist/src/context/template-cache.d.ts +5 -1
- package/vendor/agent-cli/dist/src/context/template-cache.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/template-cache.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/template-refresh.d.ts +6 -0
- package/vendor/agent-cli/dist/src/context/template-refresh.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/context/template-refresh.js +45 -0
- package/vendor/agent-cli/dist/src/context/template-refresh.js.map +1 -0
- package/vendor/agent-cli/dist/src/context/template-seed.d.ts +13 -3
- package/vendor/agent-cli/dist/src/context/template-seed.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/context/template-seed.js +22 -4
- package/vendor/agent-cli/dist/src/context/template-seed.js.map +1 -1
- package/vendor/agent-cli/dist/src/context/template-sync.d.ts +11 -0
- package/vendor/agent-cli/dist/src/context/template-sync.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/context/template-sync.js +167 -0
- package/vendor/agent-cli/dist/src/context/template-sync.js.map +1 -0
- package/vendor/agent-cli/dist/src/index.d.ts +1 -0
- package/vendor/agent-cli/dist/src/index.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/index.js +1 -0
- package/vendor/agent-cli/dist/src/index.js.map +1 -1
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.d.ts +2 -0
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.js +1 -0
- package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/client.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/client.js +3 -1
- package/vendor/agent-cli/dist/src/session/client.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/link-session.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/link-session.js +4 -1
- package/vendor/agent-cli/dist/src/session/link-session.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-environment.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-environment.js +11 -0
- package/vendor/agent-cli/dist/src/session/process-environment.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-lifecycle.js +1 -1
- package/vendor/agent-cli/dist/src/session/process-lifecycle.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-request.d.ts +1 -0
- package/vendor/agent-cli/dist/src/session/process-request.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-request.js +12 -28
- package/vendor/agent-cli/dist/src/session/process-request.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/process-summary-output.d.ts +15 -0
- package/vendor/agent-cli/dist/src/session/process-summary-output.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/process-summary-output.js +46 -0
- package/vendor/agent-cli/dist/src/session/process-summary-output.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/run-setup.d.ts +2 -0
- package/vendor/agent-cli/dist/src/session/run-setup.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/run-setup.js +2 -0
- package/vendor/agent-cli/dist/src/session/run-setup.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/run-start-body.d.ts +1 -0
- package/vendor/agent-cli/dist/src/session/run-start-body.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/run-start-body.js +1 -0
- package/vendor/agent-cli/dist/src/session/run-start-body.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/tool-scheduler.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/tool-scheduler.js +2 -1
- package/vendor/agent-cli/dist/src/session/tool-scheduler.js.map +1 -1
- package/vendor/agent-cli/dist/src/session/user-choice-policy.d.ts +25 -0
- package/vendor/agent-cli/dist/src/session/user-choice-policy.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/session/user-choice-policy.js +70 -0
- package/vendor/agent-cli/dist/src/session/user-choice-policy.js.map +1 -0
- package/vendor/agent-cli/dist/src/session/user-choice.d.ts +3 -2
- package/vendor/agent-cli/dist/src/session/user-choice.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/session/user-choice.js +30 -9
- package/vendor/agent-cli/dist/src/session/user-choice.js.map +1 -1
- package/vendor/agent-cli/dist/src/shared/replace-file.d.ts +3 -0
- package/vendor/agent-cli/dist/src/shared/replace-file.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/shared/replace-file.js +34 -0
- package/vendor/agent-cli/dist/src/shared/replace-file.js.map +1 -0
- package/vendor/agent-cli/dist/src/shared/types.d.ts +9 -1
- package/vendor/agent-cli/dist/src/shared/types.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/shared/user-choice.d.ts +21 -2
- package/vendor/agent-cli/dist/src/shared/user-choice.d.ts.map +1 -1
|
@@ -6,23 +6,43 @@ const pageAbort = new AbortController();
|
|
|
6
6
|
const hashPattern = /^[a-f0-9]{64}$/;
|
|
7
7
|
const idPattern = /^[A-Za-z0-9_-]{1,128}$/;
|
|
8
8
|
const imageLimit = 2 * 1024 * 1024;
|
|
9
|
+
const publishedTargetHelp = '当前版本已发布。请回到 WorkBuddy 重新验收同一个游戏,再用新的验收结果打开发布页。';
|
|
9
10
|
let context, publication, reviewedRevision, busy = false, dirty = false, needsSync = false;
|
|
10
11
|
let disposed = false, formInitialized = false, reviewGeneration = 0, statusTimer;
|
|
12
|
+
let targetVersionPublished = false;
|
|
11
13
|
let coverData, coverId, coverURL, coverGeneration = 0, coverLoading = false, imagesReady = false;
|
|
12
14
|
const stateNames = { awaiting_confirmation:'等待审阅确认', submitting:'正在提交', submitted:'已提交,等待审核', sharing:'审核中',
|
|
13
15
|
share_repacking:'发布处理中', share_completed:'审核通过', share_failed:'发布未完成', share_delisted:'审核未通过或已下架',
|
|
14
16
|
different_publication:'目标版本存在另一条发布记录', not_submitted:'尚未提交', external_draft:'私有草稿' };
|
|
15
17
|
|
|
16
18
|
function message(text) { byId('message').textContent = text; }
|
|
19
|
+
function localizedText(value, fallback) {
|
|
20
|
+
return typeof value === 'string' && /\p{Script=Han}/u.test(value) && !/\n\s+at |file:\/\/\/|[A-Za-z]:\\|\b(?:ENOENT|EACCES|EPERM)\b/.test(value) ? value : fallback;
|
|
21
|
+
}
|
|
17
22
|
function showError(error) {
|
|
18
|
-
byId('error').textContent = error instanceof Error ? error.message : String(error);
|
|
23
|
+
byId('error').textContent = localizedText(error instanceof Error ? error.message : String(error),'发布操作未完成,请刷新进度后查看。');
|
|
19
24
|
byId('error').hidden = false;
|
|
20
25
|
}
|
|
21
26
|
function clearError() { byId('error').textContent = ''; byId('error').hidden = true; }
|
|
22
|
-
function errorText(data) {
|
|
27
|
+
function errorText(data, fallback) {
|
|
23
28
|
const detail = data && typeof data === 'object' ? data : {};
|
|
24
|
-
return [detail.error || detail.message
|
|
25
|
-
detail.request_id ? '请求 ID:' + detail.request_id : ''].filter(Boolean).join('\n');
|
|
29
|
+
return [localizedText(detail.error || detail.message,fallback),
|
|
30
|
+
idPattern.test(detail.request_id || '') ? '请求 ID:' + detail.request_id : ''].filter(Boolean).join('\n');
|
|
31
|
+
}
|
|
32
|
+
function isPublishedTaskFailure(task) {
|
|
33
|
+
const { reason,message:rawMessage } = task.error || {};
|
|
34
|
+
return task.kind === 'publish_prepare' && task.status === 'failed' && (reason === 'publication_version_already_published' ||
|
|
35
|
+
typeof rawMessage === 'string' && rawMessage.startsWith('This version is already published.'));
|
|
36
|
+
}
|
|
37
|
+
function taskError(task, fallback) {
|
|
38
|
+
if (task?.kind === 'publish_prepare' && task.status === 'failed') {
|
|
39
|
+
if (isPublishedTaskFailure(task)) {
|
|
40
|
+
return Object.assign(new Error(publishedTargetHelp),{ targetVersionPublished:true });
|
|
41
|
+
}
|
|
42
|
+
if (task.error?.reason === 'publication_review_in_progress') return new Error(errorText(task.error,'当前版本正在审核,请回到 WorkBuddy 查看原发布记录。'));
|
|
43
|
+
return new Error(['发布材料准备失败。请重新点击「准备发布材料」重试。',errorText(task.error,'')].filter(Boolean).join('\n\n'));
|
|
44
|
+
}
|
|
45
|
+
return new Error(errorText(task?.error,task?.status === 'failed' && task.kind === 'publish_submit' ? '提交审核未完成,请刷新进度并查看原发布记录。' : fallback));
|
|
26
46
|
}
|
|
27
47
|
async function request(route, body, query) {
|
|
28
48
|
const url = new URL(apiBase + '/' + route, location.origin);
|
|
@@ -42,7 +62,7 @@ async function request(route, body, query) {
|
|
|
42
62
|
}
|
|
43
63
|
const data = await response.json().catch(() => null);
|
|
44
64
|
if (!response.ok || !data || typeof data !== 'object') {
|
|
45
|
-
const error = new Error(errorText(data)); error.httpStatus = response.status;
|
|
65
|
+
const error = new Error(errorText(data,body === undefined ? '暂时无法读取发布信息,请刷新进度后重试。' : '发布操作未完成,请先刷新进度。')); error.httpStatus = response.status;
|
|
46
66
|
error.needsSync = body !== undefined && (!data || typeof data !== 'object' || response.status >= 500); throw error;
|
|
47
67
|
}
|
|
48
68
|
return data;
|
|
@@ -60,17 +80,25 @@ function changeStep(current) {
|
|
|
60
80
|
if (index === current) item.setAttribute('aria-current','step'); else item.removeAttribute('aria-current');
|
|
61
81
|
});
|
|
62
82
|
}
|
|
83
|
+
function showPublishedTarget() {
|
|
84
|
+
targetVersionPublished = true;
|
|
85
|
+
if (!publication?.published) changeStep(0);
|
|
86
|
+
byId('status').textContent = '当前版本已发布';
|
|
87
|
+
byId('status').dataset.state = 'share_completed';
|
|
88
|
+
message(publishedTargetHelp);
|
|
89
|
+
}
|
|
63
90
|
function isInProgress() { return ['submitting','submitted','sharing','share_repacking'].includes(publication?.state); }
|
|
64
|
-
function isLocked() { return publication?.published === true || isInProgress() || publication?.state === 'different_publication'; }
|
|
91
|
+
function isLocked() { return targetVersionPublished || publication?.published === true || isInProgress() || publication?.state === 'different_publication'; }
|
|
65
92
|
function canConfirm() {
|
|
66
|
-
return Boolean(publication && reviewedRevision === publication.revision && imagesReady && !dirty && !needsSync &&
|
|
93
|
+
return Boolean(!targetVersionPublished && publication && reviewedRevision === publication.revision && imagesReady && !dirty && !needsSync &&
|
|
67
94
|
publication.materials?.open_to_recreate === false &&
|
|
68
95
|
(publication.state === 'awaiting_confirmation' || publication.finalization_retry_required === true));
|
|
69
96
|
}
|
|
70
97
|
function updateControls() {
|
|
71
98
|
byId('refresh').disabled = busy;
|
|
72
99
|
byId('materials-fields').disabled = busy || coverLoading || !context || needsSync || isLocked();
|
|
73
|
-
byId('
|
|
100
|
+
byId('previous-cover').hidden = context?.previous_publication?.cover_available !== true || Boolean(coverData);
|
|
101
|
+
byId('review').hidden = targetVersionPublished || !publication || dirty || !['awaiting_confirmation'].includes(publication.state) && !publication.finalization_retry_required;
|
|
74
102
|
byId('review').disabled = busy || needsSync;
|
|
75
103
|
byId('confirm').disabled = busy || !canConfirm();
|
|
76
104
|
byId('submit').disabled = busy || !canConfirm() || !byId('confirm').checked;
|
|
@@ -94,8 +122,9 @@ function renderContext() {
|
|
|
94
122
|
}
|
|
95
123
|
function renderTags(id,values,selected = []) {
|
|
96
124
|
const root = byId(id); root.replaceChildren();
|
|
97
|
-
|
|
98
|
-
|
|
125
|
+
const choices = [...new Set([...values,...selected])];
|
|
126
|
+
if (!choices.length) { const empty = document.createElement('span'); empty.className = 'empty'; empty.textContent = '暂无可选项'; root.append(empty); }
|
|
127
|
+
for (const value of choices) {
|
|
99
128
|
const label = document.createElement('label'), input = document.createElement('input'), text = document.createElement('span');
|
|
100
129
|
label.className = 'tag'; input.type = 'checkbox'; input.value = value; input.checked = selected.includes(value);
|
|
101
130
|
text.textContent = value; label.append(input,text); root.append(label);
|
|
@@ -106,9 +135,12 @@ function fillForm(materials) {
|
|
|
106
135
|
byId('game-name').value = input.game_name || Array.from(context.name || '').slice(0,40).join('');
|
|
107
136
|
byId('instructions').value = input.instructions || '';
|
|
108
137
|
const options = context.options || {}, select = byId('game-type');
|
|
138
|
+
const gameTypes = options.game_types || [];
|
|
109
139
|
select.replaceChildren(new Option('请选择分类',''));
|
|
110
|
-
for (const value of
|
|
111
|
-
if (input.game_type && !
|
|
140
|
+
for (const value of gameTypes) select.add(new Option(value,value));
|
|
141
|
+
if (input.game_type && !gameTypes.includes(input.game_type)) {
|
|
142
|
+
select.add(new Option(gameTypes.length ? input.game_type + '(已停用,请重新选择)' : input.game_type,input.game_type));
|
|
143
|
+
}
|
|
112
144
|
select.value = input.game_type || '';
|
|
113
145
|
renderTags('art-styles',options.art_styles || [],input.art_styles || []);
|
|
114
146
|
renderTags('play-tags',options.play_tags || [],input.play_tags || []);
|
|
@@ -118,8 +150,10 @@ function materialInput() {
|
|
|
118
150
|
const selected = id => Array.from(byId(id).querySelectorAll('input:checked'),input => input.value);
|
|
119
151
|
const art = selected('art-styles'), tags = selected('play-tags');
|
|
120
152
|
if (art.length > 12 || tags.length > 12) throw new Error('美术风格和玩法标签各最多选择 12 项。');
|
|
153
|
+
const gameType = byId('game-type').value, gameTypes = context.options?.game_types;
|
|
154
|
+
if (gameTypes?.length && !gameTypes.includes(gameType)) throw new Error('上次使用的游戏分类已停用,请选择当前分类后准备材料。');
|
|
121
155
|
return { game_name:byId('game-name').value.trim(), instructions:byId('instructions').value.trim(),
|
|
122
|
-
game_type:
|
|
156
|
+
game_type:gameType, art_styles:art, play_tags:tags, open_to_recreate:false, cover_image_source:2 };
|
|
123
157
|
}
|
|
124
158
|
function renderPublicLink() {
|
|
125
159
|
const link = byId('public-url'); link.hidden = true; link.removeAttribute('href');
|
|
@@ -136,11 +170,12 @@ function setPublication(value) {
|
|
|
136
170
|
value.name !== context.name || value.check_task_id !== context.check_task_id) throw new Error('发布回执与当前检查不一致,请返回 AI IDE 重新打开发布页面。');
|
|
137
171
|
if (reviewedRevision !== value.revision) { reviewedRevision = undefined; imagesReady = false; byId('confirm').checked = false; }
|
|
138
172
|
publication = value;
|
|
139
|
-
byId('status').textContent = stateNames
|
|
173
|
+
byId('status').textContent = Object.hasOwn(stateNames,value.state) ? stateNames[value.state] : '状态待确认';
|
|
140
174
|
byId('status').dataset.state = value.state;
|
|
141
|
-
byId('publication-progress').textContent = value.status_reason
|
|
175
|
+
byId('publication-progress').textContent = localizedText(value.status_reason,value.published ? '当前目标版本已通过审核。' :
|
|
142
176
|
value.finalization_retry_required ? '审核后的发布收尾尚未完成,可重试同一份已确认材料。' :
|
|
143
|
-
isInProgress() ? '材料已受理,正在查询同一发布记录的审核进度。请保留此页面,不要重复提交。' :
|
|
177
|
+
isInProgress() ? '材料已受理,正在查询同一发布记录的审核进度。请保留此页面,不要重复提交。' :
|
|
178
|
+
value.status_reason ? '请在 Craft 平台查看此版本的审核详情。' : '');
|
|
144
179
|
if (value.published) { changeStep(3); message('当前目标版本已通过审核,可以打开已发布游戏。'); }
|
|
145
180
|
else if (isInProgress()) { changeStep(3); message('已提交审核,正在等待当前版本的结果。'); }
|
|
146
181
|
else if (!dirty) changeStep(2);
|
|
@@ -224,7 +259,7 @@ async function waitForTask(task) {
|
|
|
224
259
|
try { task = await request('task',undefined,{ task_id:task.task_id }); }
|
|
225
260
|
catch (error) { error.needsSync = true; throw error; }
|
|
226
261
|
}
|
|
227
|
-
if (task?.status !== 'completed' || !task.result) throw
|
|
262
|
+
if (task?.status !== 'completed' || !task.result) throw taskError(task,'任务已中断,请刷新查看原记录。');
|
|
228
263
|
return task.result;
|
|
229
264
|
}
|
|
230
265
|
function configureRuntime(value) {
|
|
@@ -240,8 +275,20 @@ async function loadState() {
|
|
|
240
275
|
const state = await request('state');
|
|
241
276
|
if (!state.name || !idPattern.test(state.check_task_id || '') || !state.account?.user_id) throw new Error('本地发布会话无效,请从 AI IDE 重新打开。');
|
|
242
277
|
context = state; needsSync = false; renderContext(); configureRuntime(state.runtime_url);
|
|
243
|
-
|
|
278
|
+
const previous = state.previous_publication;
|
|
279
|
+
document.title = previous ? '更新 Craft 游戏' : '发布到 Craft';
|
|
280
|
+
byId('page-title').textContent = document.title;
|
|
281
|
+
byId('form-title').textContent = previous ? '更新资料' : '发布资料';
|
|
282
|
+
byId('form-intro').textContent = previous ? '可修改发布资料。准备材料时会重新采集当前版本的截图。' :
|
|
283
|
+
'修改文案或封面后,需要重新准备并确认材料。关闭页面不会自动提交。';
|
|
284
|
+
const coverHelp = 'PNG / JPEG,最大 2 MiB。选图只在本机预览。';
|
|
285
|
+
const coverFallback = previous ? '上次封面不可用,留空使用本次试玩截图。' : '留空使用本次试玩截图。';
|
|
286
|
+
byId('cover-help').textContent = previous?.cover_available === true ? coverHelp : coverHelp + coverFallback;
|
|
287
|
+
if (!formInitialized) fillForm(state.publication?.materials ?? previous?.materials);
|
|
244
288
|
if (state.publication) setPublication(state.publication);
|
|
289
|
+
if (targetVersionPublished || state.target_version_published || state.publication?.state === 'share_completed') {
|
|
290
|
+
showPublishedTarget(); return;
|
|
291
|
+
}
|
|
245
292
|
if (state.task_id) {
|
|
246
293
|
const task = await request('task',undefined,{ task_id:state.task_id });
|
|
247
294
|
if (task.status === 'running') { changeStep(1); message('正在恢复原发布任务…'); }
|
|
@@ -249,16 +296,22 @@ async function loadState() {
|
|
|
249
296
|
const result = await waitForTask(task);
|
|
250
297
|
setPublication(await request('status',undefined,{ publication_id:result.publication_id }));
|
|
251
298
|
if (!dirty) fillForm(publication.materials);
|
|
252
|
-
} else if (task.status !== 'completed' && !state.publication
|
|
299
|
+
} else if (task.status !== 'completed' && (!state.publication || isPublishedTaskFailure(task))) {
|
|
300
|
+
throw taskError(task,'原任务已中断,请回 WorkBuddy 查看。');
|
|
301
|
+
}
|
|
253
302
|
}
|
|
254
303
|
if (publication && !dirty && (publication.state === 'awaiting_confirmation' || publication.finalization_retry_required)) {
|
|
255
304
|
await reviewPublication(publication); message('材料已准备。请核对文案、封面和全部展示截图,再确认公开提交。');
|
|
256
|
-
} else if (!publication) {
|
|
305
|
+
} else if (!publication) {
|
|
306
|
+
changeStep(0);
|
|
307
|
+
message(previous?.materials ? '已带入上次发布的资料。请核对后点击「准备发布材料」。' :
|
|
308
|
+
'填写资料后准备材料。封面和采集结果会先保存在本机。');
|
|
309
|
+
}
|
|
257
310
|
scheduleStatus(); updateControls();
|
|
258
311
|
}
|
|
259
312
|
function scheduleStatus() {
|
|
260
313
|
clearTimeout(statusTimer);
|
|
261
|
-
if (disposed || !publication || !isInProgress()) return;
|
|
314
|
+
if (disposed || targetVersionPublished || !publication || !isInProgress()) return;
|
|
262
315
|
statusTimer = setTimeout(async () => {
|
|
263
316
|
if (busy) { scheduleStatus(); return; }
|
|
264
317
|
try {
|
|
@@ -278,7 +331,13 @@ async function perform(action) {
|
|
|
278
331
|
if (busy || disposed) return;
|
|
279
332
|
busy = true; clearTimeout(statusTimer); clearError(); updateControls();
|
|
280
333
|
try { await action(); }
|
|
281
|
-
catch (error) {
|
|
334
|
+
catch (error) {
|
|
335
|
+
if (!disposed) {
|
|
336
|
+
if (error.needsSync) needsSync = true;
|
|
337
|
+
if (error.targetVersionPublished) showPublishedTarget();
|
|
338
|
+
else showError(error);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
282
341
|
finally { busy = false; updateControls(); scheduleStatus(); }
|
|
283
342
|
}
|
|
284
343
|
function clearCover(resetInput = true) {
|
|
@@ -308,14 +367,16 @@ byId('cover-file').addEventListener('change',async () => {
|
|
|
308
367
|
byId('clear-cover').onclick = () => { clearCover(); invalidateReview(); };
|
|
309
368
|
byId('materials-form').onsubmit = event => {
|
|
310
369
|
event.preventDefault();
|
|
311
|
-
if (coverLoading || !byId('materials-form').reportValidity()) return;
|
|
370
|
+
if (coverLoading || needsSync || isLocked() || !byId('materials-form').reportValidity()) return;
|
|
312
371
|
void perform(async () => {
|
|
313
372
|
const materials = materialInput();
|
|
314
373
|
reviewedRevision = undefined; imagesReady = false; byId('confirm').checked = false;
|
|
315
374
|
changeStep(1); message('正在准备本地材料与真实试玩采集,尚未公开上传图片。');
|
|
316
375
|
if (coverData && !coverId) coverId = (await request('cover',{ data:coverData })).cover_id;
|
|
317
376
|
if (coverData && !idPattern.test(coverId || '')) throw new Error('封面暂存回执无效。');
|
|
318
|
-
const
|
|
377
|
+
const skipPreviousCover = context.previous_publication?.cover_available === true && !byId('reuse-previous-cover').checked;
|
|
378
|
+
const task = await request('prepare',{ materials,...(coverId ? { cover_id:coverId } : {}),
|
|
379
|
+
...(skipPreviousCover && !coverId ? { reuse_previous_cover:false } : {}) });
|
|
319
380
|
const result = await waitForTask(task); dirty = false; setPublication(result);
|
|
320
381
|
await reviewPublication(result); message('材料已准备。请逐项审阅,并确认将图片公开上传后提交审核。');
|
|
321
382
|
});
|
|
@@ -7,12 +7,16 @@ import { publicationMaterials } from '../game-workflow/publication-materials.mjs
|
|
|
7
7
|
|
|
8
8
|
const identifier = /^[a-zA-Z0-9_-]{1,128}$/;
|
|
9
9
|
const failure = (message,status=400)=>Object.assign(new Error(message),{ status });
|
|
10
|
+
const pageChanged = 'Craft 账号已变更或发布页已失效。请回到 AI IDE 重新打开发布页。';
|
|
11
|
+
const publicationCheckMismatch = '发布记录与当前验收结果不匹配。请回到 AI IDE 打开对应的发布页。';
|
|
12
|
+
const previewUnavailable = '本地游戏预览暂不可用。请重新加载页面后再试,已保存的发布进度仍可查看。';
|
|
13
|
+
const coverRequirements = '请选择不超过 2 MiB 的 PNG 或 JPEG 封面图片。';
|
|
10
14
|
function bodyFields(body,keys,required=keys) {
|
|
11
15
|
if (!body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).some(key=>!keys.includes(key)) ||
|
|
12
|
-
required.some(key=>!Object.hasOwn(body,key))) throw failure('
|
|
16
|
+
required.some(key=>!Object.hasOwn(body,key))) throw failure('发布请求缺少必要资料或包含无效字段。');
|
|
13
17
|
}
|
|
14
18
|
function selectedId(value) {
|
|
15
|
-
if (typeof value !== 'string' || !identifier.test(value)) throw failure('
|
|
19
|
+
if (typeof value !== 'string' || !identifier.test(value)) throw failure('发布记录或任务标识无效。请回到 AI IDE 重新打开发布页。');
|
|
16
20
|
return value;
|
|
17
21
|
}
|
|
18
22
|
|
|
@@ -32,20 +36,20 @@ export function createPublishPanel({ platform,projects,tasks,drafts,publications
|
|
|
32
36
|
}
|
|
33
37
|
async function scopeFor(cap) {
|
|
34
38
|
const scope = scopes.get(cap);
|
|
35
|
-
if (!scope) throw failure('
|
|
39
|
+
if (!scope) throw failure('本地发布页已失效。请回到 AI IDE 重新打开发布页。',404);
|
|
36
40
|
if (!current(scope)) {
|
|
37
41
|
await retire(cap,scope);
|
|
38
|
-
throw failure(
|
|
42
|
+
throw failure(pageChanged,403);
|
|
39
43
|
}
|
|
40
44
|
return scope;
|
|
41
45
|
}
|
|
42
46
|
function requireCurrent(scope) {
|
|
43
|
-
if (!current(scope)) throw failure(
|
|
47
|
+
if (!current(scope)) throw failure(pageChanged,403);
|
|
44
48
|
}
|
|
45
49
|
async function publication(scope,id) {
|
|
46
|
-
if (selectedId(id) !== scope.publication_id) throw failure('
|
|
50
|
+
if (selectedId(id) !== scope.publication_id) throw failure('发布记录不属于当前页面。请回到 AI IDE 打开对应的发布页。',403);
|
|
47
51
|
const result = await publications.status(scope.name,id,scope.owner);
|
|
48
|
-
if (result.check_task_id !== scope.check_task_id) throw failure(
|
|
52
|
+
if (result.check_task_id !== scope.check_task_id) throw failure(publicationCheckMismatch,403);
|
|
49
53
|
requireCurrent(scope); return result;
|
|
50
54
|
}
|
|
51
55
|
async function preview(scope) {
|
|
@@ -57,7 +61,7 @@ export function createPublishPanel({ platform,projects,tasks,drafts,publications
|
|
|
57
61
|
handle=await pending;
|
|
58
62
|
url=new URL(handle.url);
|
|
59
63
|
if (url.protocol !== 'http:' || url.hostname !== '127.0.0.1' || url.origin === origin || url.username || url.password || url.hash) {
|
|
60
|
-
throw failure('
|
|
64
|
+
throw failure('发布预览需要独立的本机回环地址。');
|
|
61
65
|
}
|
|
62
66
|
} catch {
|
|
63
67
|
if (scope.preview === pending) delete scope.preview;
|
|
@@ -75,18 +79,18 @@ export function createPublishPanel({ platform,projects,tasks,drafts,publications
|
|
|
75
79
|
return {
|
|
76
80
|
bindOrigin(value) { origin=value; },
|
|
77
81
|
async open(name,checkId,publicationId) {
|
|
78
|
-
if (closed || !origin) throw failure('
|
|
82
|
+
if (closed || !origin) throw failure('本地发布页暂不可用。请重新连接 Craft MCP 后再试。');
|
|
79
83
|
projects.file(name); selectedId(checkId);
|
|
80
84
|
const account=platform.account(),session=platform.store.getSession();
|
|
81
85
|
const resume=Boolean(publicationId) || await drafts.hasRequest(name,checkId,account.user_id);
|
|
82
86
|
const context=await checkedTask(checkId,name,resume);
|
|
83
87
|
for (const [cap,existing] of scopes) if (!current(existing)) await retire(cap,existing);
|
|
84
|
-
if (scopes.size >= 32) throw failure('
|
|
88
|
+
if (scopes.size >= 32) throw failure('已打开的发布页过多。请关闭并重新连接 Craft MCP,再打开发布页。');
|
|
85
89
|
const scope={ name,check_task_id:checkId,check:context.task,project:context.project,owner:account.user_id,
|
|
86
90
|
platform:platform.base,token:session.token,created:now(),tasks:new Set() };
|
|
87
91
|
if (publicationId) {
|
|
88
92
|
const existing=await publications.status(name,selectedId(publicationId),account.user_id);
|
|
89
|
-
if (existing.check_task_id !== checkId) throw failure(
|
|
93
|
+
if (existing.check_task_id !== checkId) throw failure(publicationCheckMismatch,403);
|
|
90
94
|
scope.publication_id=publicationId;
|
|
91
95
|
}
|
|
92
96
|
requireCurrent(scope);
|
|
@@ -99,49 +103,57 @@ export function createPublishPanel({ platform,projects,tasks,drafts,publications
|
|
|
99
103
|
async document(cap) {
|
|
100
104
|
const scope=await scopeFor(cap),runtime_url=await preview(scope);
|
|
101
105
|
scope.document_loaded=true;scope.document_preview_origin=runtime_url ? new URL(runtime_url).origin : undefined;
|
|
102
|
-
return { runtime_url,...(scope.preview_unavailable ? { preview_error:
|
|
106
|
+
return { runtime_url,...(scope.preview_unavailable ? { preview_error:previewUnavailable } : {}) };
|
|
103
107
|
},
|
|
104
108
|
async handle(cap,action,method,query,body) {
|
|
105
109
|
const scope=await scopeFor(cap);
|
|
106
110
|
const writing=['cover','prepare','review','submit'].includes(action);
|
|
107
|
-
if (method !== (writing ? 'POST' : 'GET')) throw failure('
|
|
111
|
+
if (method !== (writing ? 'POST' : 'GET')) throw failure('发布页不支持此请求方式。请从页面上的按钮发起操作。',405);
|
|
108
112
|
const allowedQuery=action === 'task' ? ['task_id'] : action === 'status' ? ['publication_id'] : [];
|
|
109
|
-
if ([...query.keys()].some(key=>!allowedQuery.includes(key)) || allowedQuery.some(key=>query.getAll(key).length !== 1)) throw failure('
|
|
113
|
+
if ([...query.keys()].some(key=>!allowedQuery.includes(key)) || allowedQuery.some(key=>query.getAll(key).length !== 1)) throw failure('发布查询参数无效。请刷新页面后再试。');
|
|
110
114
|
if (action === 'state') {
|
|
111
|
-
const options=await
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
const [options,draft,saved,previous]=await Promise.all([
|
|
116
|
+
platform.publicationSession(scope.owner)('options'),
|
|
117
|
+
drafts.status(scope.name,scope.check_task_id,scope.owner),
|
|
118
|
+
scope.publication_id ? publication(scope,scope.publication_id) : undefined,
|
|
119
|
+
publications.previous(scope.check,scope.owner),
|
|
120
|
+
]);
|
|
114
121
|
// The document CSP pins its optional frame origin; a failed preview is retried on reload.
|
|
115
122
|
const runtime_url=scope.document_loaded && !scope.document_preview_origin ? undefined : await preview(scope); requireCurrent(scope);
|
|
116
123
|
const account=platform.account();
|
|
124
|
+
scope.previous=previous;
|
|
125
|
+
const target_version_published=draft.state === 'draft_ready' && previous?.published === true && previous.conversation_id === draft.conversation_id &&
|
|
126
|
+
previous.version_id === draft.version_id;
|
|
117
127
|
return { name:scope.name,check_task_id:scope.check_task_id,engine:scope.check.result.engine,platform:scope.platform,
|
|
118
|
-
account:{ user_id:account.user_id,nickname:account.nickname },draft,options,publication:saved,
|
|
128
|
+
account:{ user_id:account.user_id,nickname:account.nickname },draft,options,publication:saved,target_version_published,
|
|
129
|
+
...(previous ? { previous_publication:{ materials:previous.materials,cover_available:Boolean(previous.cover_url) } } : {}),
|
|
119
130
|
task_id:scope.task_id,runtime_url,preview_unavailable:scope.preview_unavailable === true,
|
|
120
|
-
...(scope.preview_unavailable ? { preview_error:
|
|
131
|
+
...(scope.preview_unavailable ? { preview_error:previewUnavailable } : {}) };
|
|
121
132
|
}
|
|
122
133
|
if (action === 'task') {
|
|
123
134
|
const id=selectedId(query.get('task_id'));
|
|
124
|
-
if (!scope.tasks.has(id)) throw failure('
|
|
135
|
+
if (!scope.tasks.has(id)) throw failure('任务不属于当前发布页。请回到 AI IDE 打开对应的发布页。',403);
|
|
125
136
|
const result=viewTask(await tasks.get(id)); requireCurrent(scope); return result;
|
|
126
137
|
}
|
|
127
138
|
if (action === 'status') return publication(scope,query.get('publication_id'));
|
|
128
|
-
if (!writing) throw failure('
|
|
139
|
+
if (!writing) throw failure('发布页不支持此操作。',404);
|
|
129
140
|
return mutate(scope.name,async()=>{
|
|
130
141
|
requireCurrent(scope);
|
|
131
142
|
if (action === 'cover') {
|
|
132
143
|
bodyFields(body,['data']);
|
|
133
144
|
if (typeof body.data !== 'string' || body.data.length > Math.ceil(2*1024*1024/3)*4 ||
|
|
134
|
-
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(body.data)) throw failure(
|
|
145
|
+
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(body.data)) throw failure(coverRequirements);
|
|
135
146
|
const data=Buffer.from(body.data,'base64');
|
|
136
|
-
if (!data.length || data.length > 2*1024*1024) throw failure(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!
|
|
147
|
+
if (!data.length || data.length > 2*1024*1024) throw failure(coverRequirements);
|
|
148
|
+
let extension;
|
|
149
|
+
try { extension=imageExtension(data); } catch { throw failure(coverRequirements); }
|
|
150
|
+
if (!['png','jpg'].includes(extension)) throw failure(coverRequirements);
|
|
151
|
+
if (!coverDirectory) throw failure('本地封面暂存不可用。请重新连接 Craft MCP 后再试。');
|
|
140
152
|
coverRoot ??= privateDirectory(coverDirectory,projects.root);
|
|
141
153
|
const root=await coverRoot;
|
|
142
154
|
const directory=scope.cover_directory ?? path.join(root,cap);
|
|
143
155
|
await mkdir(directory,{ recursive:true,mode:0o700 });
|
|
144
|
-
if ((await lstat(directory)).isSymbolicLink() || await realpath(directory) !== directory) throw failure('
|
|
156
|
+
if ((await lstat(directory)).isSymbolicLink() || await realpath(directory) !== directory) throw failure('本地封面暂存目录无效。请重新连接 Craft MCP 后再试。');
|
|
145
157
|
scope.cover_directory=directory;
|
|
146
158
|
const id=randomUUID(),file=id+'.'+extension;
|
|
147
159
|
await writeFile(path.join(directory,file),data,{ flag:'wx',mode:0o600 });
|
|
@@ -152,18 +164,27 @@ export function createPublishPanel({ platform,projects,tasks,drafts,publications
|
|
|
152
164
|
return { cover_id:id };
|
|
153
165
|
}
|
|
154
166
|
if (action === 'prepare') {
|
|
155
|
-
bodyFields(body,['materials','cover_id'],['materials']); publicationMaterials(body.materials);
|
|
156
|
-
if (body.materials.cover_path !== undefined) throw failure('
|
|
157
|
-
if (body.cover_id !== undefined && (typeof body.cover_id !== 'string' || body.cover_id !== scope.cover?.id)) throw failure('
|
|
167
|
+
bodyFields(body,['materials','cover_id','reuse_previous_cover'],['materials']); publicationMaterials(body.materials);
|
|
168
|
+
if (body.materials.cover_path !== undefined) throw failure('请在当前发布页选择封面图片。');
|
|
169
|
+
if (body.cover_id !== undefined && (typeof body.cover_id !== 'string' || body.cover_id !== scope.cover?.id)) throw failure('封面不属于当前发布页。请重新选择封面图片。',403);
|
|
170
|
+
if (body.reuse_previous_cover !== undefined && typeof body.reuse_previous_cover !== 'boolean') throw failure('请选择是否沿用上次的封面。');
|
|
158
171
|
const stagedCover=body.cover_id ? scope.cover : undefined;
|
|
159
172
|
const resume=await drafts.hasRequest(scope.name,scope.check_task_id,scope.owner);
|
|
160
173
|
const context=await checkedTask(scope.check_task_id,scope.name,resume);
|
|
161
174
|
requireCurrent(scope);
|
|
162
175
|
const task=await tasks.start(scope.name,'publish_prepare',async signal=>{
|
|
163
176
|
requireCurrent(scope);
|
|
164
|
-
|
|
177
|
+
const reusePreviousCover=!stagedCover && body.reuse_previous_cover !== false;
|
|
178
|
+
let previous=scope.previous;
|
|
179
|
+
if (reusePreviousCover && !Object.hasOwn(scope,'previous')) {
|
|
180
|
+
previous=await publications.previous(context.task,scope.owner,signal);
|
|
181
|
+
requireCurrent(scope);
|
|
182
|
+
}
|
|
183
|
+
const source=await drafts.upload(context.task,scope.owner,signal);
|
|
165
184
|
requireCurrent(scope);
|
|
166
|
-
|
|
185
|
+
if (previous && source.conversation_id !== previous.conversation_id) throw new Error('发布资料所属项目已变化,请刷新进度并核对资料后重试。');
|
|
186
|
+
const previousCover=reusePreviousCover && previous?.cover_url ? previous : undefined;
|
|
187
|
+
const result=await publications.prepare(context.task,context.project,body.materials,scope.owner,signal,stagedCover,previousCover);
|
|
167
188
|
requireCurrent(scope); scope.publication_id=result.publication_id; return result;
|
|
168
189
|
},{ owner:scope.owner,platform:scope.platform,check_task_id:scope.check_task_id });
|
|
169
190
|
scope.tasks.add(task.task_id); scope.task_id=task.task_id; return viewTask(task);
|
|
@@ -174,7 +195,7 @@ export function createPublishPanel({ platform,projects,tasks,drafts,publications
|
|
|
174
195
|
requireCurrent(scope); return result;
|
|
175
196
|
}
|
|
176
197
|
bodyFields(body,['publication_id','revision','confirmed']);
|
|
177
|
-
if (typeof body.revision !== 'string' || !/^[0-9a-f]{64}$/.test(body.revision) || body.confirmed !== true) throw failure('
|
|
198
|
+
if (typeof body.revision !== 'string' || !/^[0-9a-f]{64}$/.test(body.revision) || body.confirmed !== true) throw failure('请先审阅并确认当前版本的发布材料,再提交审核。');
|
|
178
199
|
await publication(scope,body.publication_id); requireCurrent(scope);
|
|
179
200
|
const task=await tasks.start(scope.name,'publish_submit',signal=>{
|
|
180
201
|
requireCurrent(scope);
|
|
@@ -122,12 +122,13 @@ function viewTask(task) {
|
|
|
122
122
|
}
|
|
123
123
|
async function checkedTask(id, name, resumeUpload = false) {
|
|
124
124
|
const task = await tasks.get(id);
|
|
125
|
-
if (task.kind !== 'check' || task.status !== 'completed' || !task.result?.gate?.passed) throw new Error('
|
|
126
|
-
if (name !== undefined && task.name !== name) throw new Error('
|
|
125
|
+
if (task.kind !== 'check' || task.status !== 'completed' || !task.result?.gate?.passed) throw new Error('请先完成游戏验收并使用通过的验收结果。');
|
|
126
|
+
if (name !== undefined && task.name !== name) throw new Error('该验收结果属于其他游戏,请使用当前游戏的验收结果。');
|
|
127
127
|
const { project,engine } = await projects.describe(task.name);
|
|
128
128
|
await leases.acquire(task.name);
|
|
129
|
-
if (task.result.engine && task.result.engine !== engine) throw new Error('
|
|
130
|
-
if (tasks.busy(task.name)
|
|
129
|
+
if (task.result.engine && task.result.engine !== engine) throw new Error('验收后游戏引擎已变更,请重新验收当前游戏。');
|
|
130
|
+
if (tasks.busy(task.name)) throw new Error('当前游戏还有任务在运行,请等待任务完成后继续。');
|
|
131
|
+
if (!resumeUpload && task.result.source !== await fingerprint(project)) throw new Error('验收后游戏文件已变更,请重新验收当前游戏。');
|
|
131
132
|
return { task, project };
|
|
132
133
|
}
|
|
133
134
|
server.setRequestHandler(CallToolRequestSchema,async request=>{
|
|
@@ -118,7 +118,7 @@ export class CraftAigc {
|
|
|
118
118
|
publicationSession(owner) {
|
|
119
119
|
const session = this.store.getSession(), token = session.token;
|
|
120
120
|
if (!session.loggedIn || owner !== Number(session.identity?.userId) || !token) throw new Error('Craft account changed');
|
|
121
|
-
return publicationSession({ base:this.base,token,
|
|
121
|
+
return publicationSession({ base:this.base,token,owner,
|
|
122
122
|
current:()=>{ const value = this.store.getSession(); return value.loggedIn && value.token === token && Number(value.identity?.userId) === owner; },
|
|
123
123
|
http:(endpoint,method,body,signal,options)=>this.#http(endpoint,method,body,token,signal,options?.bare === true,options) });
|
|
124
124
|
}
|
|
@@ -2,31 +2,49 @@ const idPattern = /^[a-zA-Z0-9_-]{1,128}$/;
|
|
|
2
2
|
const hashPattern = /^[0-9a-f]{64}$/;
|
|
3
3
|
|
|
4
4
|
function identifier(value) {
|
|
5
|
-
if (typeof value !== 'string' || !idPattern.test(value)) throw new Error('
|
|
5
|
+
if (typeof value !== 'string' || !idPattern.test(value)) throw new Error('发布记录标识无效。请重新打开发布页。');
|
|
6
6
|
return value;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
function imageURL(value, token, base) {
|
|
10
|
-
if (typeof value !== 'string' || value.includes(token)) throw new Error('
|
|
10
|
+
if (typeof value !== 'string' || value.includes(token)) throw new Error('平台返回的发布图片地址无效。');
|
|
11
11
|
const url = new URL(value);
|
|
12
12
|
if (url.username || url.password || url.hash || url.search ||
|
|
13
13
|
(url.protocol !== 'https:' && !(url.protocol === 'http:' && new URL(base).hostname === '127.0.0.1' && url.hostname === '127.0.0.1'))) {
|
|
14
|
-
throw new Error('
|
|
14
|
+
throw new Error('平台返回的发布图片地址无效。');
|
|
15
15
|
}
|
|
16
16
|
return url.href;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
if (
|
|
19
|
+
function previousPublication(data, conversationId, owner, token, base) {
|
|
20
|
+
if (!data || typeof data !== 'object' || !Object.hasOwn(data,'share_info')) throw new Error('无法读取上次发布资料。请刷新进度后重试。');
|
|
21
|
+
const previous = data.share_info;
|
|
22
|
+
if (previous === null) return;
|
|
23
|
+
if (previous?.conversation_id !== conversationId || previous.user_id !== owner) throw new Error('上次发布资料与当前项目或账号不一致。请重新打开对应的发布页。');
|
|
24
|
+
if (!['share_completed','share_delisted'].includes(previous.status)) return;
|
|
25
|
+
|
|
26
|
+
const text = value => typeof value === 'string' && !value.includes(token) ? value : '';
|
|
27
|
+
const list = values => Array.isArray(values) ? values.map(text).filter(Boolean) : [];
|
|
28
|
+
let tags, cover;
|
|
29
|
+
try { tags = JSON.parse(previous.game_tags); } catch { /* Old releases may have no category metadata. */ }
|
|
30
|
+
try { cover = imageURL(previous.cover_image_cos,token,base); } catch { /* Legacy covers may be unavailable. */ }
|
|
31
|
+
return { conversation_id:conversationId,version_id:identifier(previous.version_id),published:previous.status === 'share_completed',
|
|
32
|
+
materials:{ game_name:text(previous.game_name),instructions:text(previous.instructions),game_type:text(tags?.game_type),
|
|
33
|
+
art_styles:list(tags?.art_styles),play_tags:list(Array.isArray(tags) ? tags : tags?.play_tags) },
|
|
34
|
+
...(cover ? { cover_url:cover } : {}),cover_image_source:previous.cover_image_source === 1 ? 1 : 2 };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function publicationSession({ base, token, owner, current, http }) {
|
|
38
|
+
if (new URL(base).pathname !== '/') throw new Error('Craft 平台地址格式无效,请检查 MCP 的平台配置。');
|
|
21
39
|
return async (kind, options = {}, signal) => {
|
|
22
|
-
if (!current()) throw new Error('Craft
|
|
40
|
+
if (!current()) throw new Error('Craft 登录账号已变更,请重新打开发布页。');
|
|
23
41
|
let endpoint, method = 'GET', body, form;
|
|
24
42
|
if (kind === 'options') endpoint = '/api/ms/gamemeta/game-style';
|
|
25
43
|
else if (kind === 'image') {
|
|
26
44
|
const { image, conversation_id, version_id, external_manifest_sha256, purpose } = options;
|
|
27
45
|
if (!['cover','screenshot','audit-shot'].includes(purpose) || !hashPattern.test(external_manifest_sha256) ||
|
|
28
46
|
!Buffer.isBuffer(image?.data) || !image.data.length || image.data.length > 2 * 1024 * 1024 ||
|
|
29
|
-
!['png','jpg'].includes(image.extension)) throw new Error('
|
|
47
|
+
!['png','jpg'].includes(image.extension)) throw new Error('发布图片格式无效或超过 2 MiB,请重新选择图片或采集截图。');
|
|
30
48
|
endpoint = '/api/ms/versions/share-cover'; method = 'POST';
|
|
31
49
|
form = new FormData();
|
|
32
50
|
for (const [key,value] of Object.entries({ conversation_id:identifier(conversation_id), version_id:identifier(version_id), external_manifest_sha256, purpose })) form.set(key,value);
|
|
@@ -34,32 +52,34 @@ export function publicationSession({ base, token, current, http }) {
|
|
|
34
52
|
} else if (kind === 'submit') {
|
|
35
53
|
endpoint = '/api/ms/versions/share'; method = 'POST'; body = options.input;
|
|
36
54
|
identifier(body?.client_request_id); identifier(body?.conversation_id); identifier(body?.version_id);
|
|
37
|
-
if (!hashPattern.test(body.external_manifest_sha256)) throw new Error('
|
|
55
|
+
if (!hashPattern.test(body.external_manifest_sha256)) throw new Error('发布版本缺少有效的构建校验值。请回到 WorkBuddy 核对验收结果。');
|
|
38
56
|
} else if (kind === 'status') endpoint = `/api/ms/versions/${identifier(options.version_id)}/detail`;
|
|
39
|
-
else
|
|
57
|
+
else if (kind === 'previous') endpoint = `/api/ms/conversations/${identifier(options.conversation_id)}/publish-context`;
|
|
58
|
+
else throw new Error('无法识别此发布操作。请刷新页面后重试。');
|
|
40
59
|
const data = await http(endpoint,method,body,signal,{ form,draft:true,businessErrors:true,bare:kind === 'options' });
|
|
41
|
-
if (!current()) throw new Error('Craft
|
|
60
|
+
if (!current()) throw new Error('发布期间 Craft 登录账号已变更,请重新打开发布页。');
|
|
42
61
|
if (kind === 'options') {
|
|
43
|
-
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('
|
|
62
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('无法读取游戏分类,请刷新进度后重试。');
|
|
44
63
|
const result = {};
|
|
45
64
|
for (const key of ['game_types','art_styles','play_tags']) {
|
|
46
|
-
if (!data || !Object.hasOwn(data,key)) throw new Error('
|
|
65
|
+
if (!data || !Object.hasOwn(data,key)) throw new Error('无法读取游戏分类,请刷新进度后重试。');
|
|
47
66
|
const values = data[key] ?? [];
|
|
48
|
-
if (!Array.isArray(values) || values.length > 200 || values.some(item=>typeof item !== 'string' || item.length > 100 || item.includes(token))) throw new Error('
|
|
67
|
+
if (!Array.isArray(values) || values.length > 200 || values.some(item=>typeof item !== 'string' || item.length > 100 || item.includes(token))) throw new Error('无法读取游戏分类,请刷新进度后重试。');
|
|
49
68
|
result[key] = values;
|
|
50
69
|
}
|
|
51
70
|
return result;
|
|
52
71
|
}
|
|
53
72
|
if (kind === 'image') {
|
|
54
|
-
if (!hashPattern.test(data?.sha256) || data.bytes !== options.image.data.length) throw new Error('
|
|
73
|
+
if (!hashPattern.test(data?.sha256) || data.bytes !== options.image.data.length) throw new Error('平台返回的图片上传回执不完整。请先刷新进度。');
|
|
55
74
|
return { cover_url:imageURL(data.cover_url,token,base),material_id:identifier(data.material_id),sha256:data.sha256,bytes:data.bytes };
|
|
56
75
|
}
|
|
57
76
|
if (kind === 'submit') return { accepted:true };
|
|
77
|
+
if (kind === 'previous') return previousPublication(data,options.conversation_id,owner,token,base);
|
|
58
78
|
const publication = data?.external_publication;
|
|
59
79
|
if (!publication) return { state:'not_submitted', version_id:options.version_id };
|
|
60
80
|
if (publication.version_id !== options.version_id || !hashPattern.test(publication.external_manifest_sha256) ||
|
|
61
81
|
!hashPattern.test(publication.request_sha256) || typeof publication.status !== 'string' || !/^[a-z_]{1,48}$/.test(publication.status)) {
|
|
62
|
-
throw new Error('
|
|
82
|
+
throw new Error('平台返回的发布状态无效。请刷新进度后重试。');
|
|
63
83
|
}
|
|
64
84
|
const result = { client_request_id:identifier(publication.client_request_id),request_sha256:publication.request_sha256,
|
|
65
85
|
external_manifest_sha256:publication.external_manifest_sha256,version_id:publication.version_id,
|
|
@@ -67,13 +87,13 @@ export function publicationSession({ base, token, current, http }) {
|
|
|
67
87
|
status_reason:typeof publication.status_reason === 'string' ? publication.status_reason.split(token).join('[REDACTED]').slice(0,1000) : '' };
|
|
68
88
|
if (publication.finalization_retry_required !== undefined) {
|
|
69
89
|
if (typeof publication.finalization_retry_required !== 'boolean' ||
|
|
70
|
-
(publication.finalization_retry_required && result.state !== 'sharing')) throw new Error('
|
|
90
|
+
(publication.finalization_retry_required && result.state !== 'sharing')) throw new Error('平台返回的发布收尾状态无效。请刷新进度后重试。');
|
|
71
91
|
result.finalization_retry_required = publication.finalization_retry_required;
|
|
72
92
|
}
|
|
73
93
|
if (publication.public_url !== undefined && publication.public_url !== '') {
|
|
74
94
|
const url = new URL(publication.public_url);
|
|
75
95
|
if (result.state !== 'share_completed' || publication.published_version_id !== options.version_id ||
|
|
76
|
-
url.origin !== new URL(base).origin || url.username || url.password || publication.public_url.includes(token)) throw new Error('
|
|
96
|
+
url.origin !== new URL(base).origin || url.username || url.password || publication.public_url.includes(token)) throw new Error('公开链接与已发布版本不一致。请在 Craft 平台查看该版本。');
|
|
77
97
|
result.public_url = url.href;
|
|
78
98
|
}
|
|
79
99
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@craft_eco/craft-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.12.0"
|
|
@@ -31,5 +31,6 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"registry": "https://registry.npmjs.org/",
|
|
33
33
|
"access": "public"
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"craftDefaultPlatform": "https://pre.craft.qq.com"
|
|
35
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preinstalled-dependencies.d.ts","sourceRoot":"","sources":["../../../src/artifacts/preinstalled-dependencies.ts"],"names":[],"mappings":"AAMA,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;IACjD,MAAM,EAAE,uBAAuB,GAAG,kBAAkB,GAAG,0BAA0B,GAAG,uBAAuB,GAAG,sBAAsB,CAAC;CACtI;AACD,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAIpE,wBAAgB,2BAA2B,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpE;
|
|
1
|
+
{"version":3,"file":"preinstalled-dependencies.d.ts","sourceRoot":"","sources":["../../../src/artifacts/preinstalled-dependencies.ts"],"names":[],"mappings":"AAMA,KAAK,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAExC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;IACjD,MAAM,EAAE,uBAAuB,GAAG,kBAAkB,GAAG,0BAA0B,GAAG,uBAAuB,GAAG,sBAAsB,CAAC;CACtI;AACD,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;AAIpE,wBAAgB,2BAA2B,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpE;AAuJD,+GAA+G;AAC/G,wBAAsB,+BAA+B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAUnF;AAqED,sHAAsH;AACtH,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,kBAAkB,GACnG,OAAO,CAAC,OAAO,CAAC,CA0ClB"}
|