@craft_eco/craft-mcp 0.1.29 → 0.1.30
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 +10 -55
- package/bin/craft-mcp.mjs +4 -1
- package/dist-server/game-workflow/check.mjs +3 -2
- package/dist-server/game-workflow/context-state.mjs +67 -67
- package/dist-server/game-workflow/draft-archive.mjs +147 -2
- package/dist-server/game-workflow/draft-upload-identity.mjs +11 -0
- package/dist-server/game-workflow/draft-uploads.mjs +105 -60
- package/dist-server/game-workflow/local-context.mjs +62 -62
- package/dist-server/game-workflow/native-context.mjs +289 -289
- package/dist-server/game-workflow/project-bundles.mjs +246 -246
- package/dist-server/game-workflow/project-context.mjs +8 -8
- package/dist-server/game-workflow/projects.mjs +6 -4
- package/dist-server/game-workflow/tasks.mjs +1 -1
- package/dist-server/game-workflow/work-scope.mjs +7 -7
- package/dist-server/integrations/config.mjs +145 -145
- package/dist-server/integrations/connect.mjs +36 -0
- package/dist-server/integrations/connection-handoff.mjs +36 -42
- package/dist-server/integrations/dsh-config.mjs +182 -182
- package/dist-server/integrations/files.mjs +54 -54
- package/dist-server/integrations/fixed-launcher.mjs +31 -0
- package/dist-server/integrations/host-reload.mjs +19 -0
- package/dist-server/integrations/hosts.mjs +55 -55
- package/dist-server/integrations/install.mjs +223 -205
- package/dist-server/integrations/installation-state.mjs +84 -84
- package/dist-server/integrations/launcher-start.mjs +52 -0
- package/dist-server/integrations/npm-diagnostics.mjs +32 -0
- package/dist-server/integrations/runtime-gc.mjs +191 -188
- package/dist-server/integrations/runtime-identity.mjs +22 -0
- package/dist-server/integrations/runtime.mjs +111 -126
- package/dist-server/integrations/updates.mjs +258 -225
- package/dist-server/integrations/version-policy.mjs +32 -32
- package/dist-server/launcher.mjs +1845 -0
- package/dist-server/mcp/control-panel.mjs +8 -23
- package/dist-server/mcp/server.mjs +31 -80
- package/dist-server/mcp/update-session.mjs +107 -92
- package/dist-server/upstream/craft-aigc.mjs +43 -16
- package/dist-server/upstream/draft-source.mjs +29 -0
- package/package.json +3 -2
- package/resources/context-filter-report.json +1 -1
- package/resources/craft-create/SKILL.md +19 -19
- package/resources/craft-update/SKILL.md +9 -11
- package/resources/targets/claude/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/claude/js/context-filter-report.json +1 -1
- package/resources/targets/claude/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/claude/js/js/bundle.json +7 -7
- package/resources/targets/claude/js/recovery.md +5 -1
- package/resources/targets/claude/js/target.json +1 -1
- package/resources/targets/claude/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/claude/js3d/context-filter-report.json +1 -1
- package/resources/targets/claude/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/claude/js3d/js3d/bundle.json +7 -7
- package/resources/targets/claude/js3d/recovery.md +5 -1
- package/resources/targets/claude/js3d/target.json +1 -1
- package/resources/targets/codebuddy/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/codebuddy/js/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codebuddy/js/js/bundle.json +7 -7
- package/resources/targets/codebuddy/js/recovery.md +5 -1
- package/resources/targets/codebuddy/js/target.json +1 -1
- package/resources/targets/codebuddy/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/codebuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/codebuddy/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codebuddy/js3d/js3d/bundle.json +7 -7
- package/resources/targets/codebuddy/js3d/recovery.md +5 -1
- package/resources/targets/codebuddy/js3d/target.json +1 -1
- package/resources/targets/codex/js/bootstrap/SKILL.md +2 -4
- package/resources/targets/codex/js/context-filter-report.json +1 -1
- package/resources/targets/codex/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codex/js/js/bundle.json +7 -7
- package/resources/targets/codex/js/recovery.md +3 -3
- package/resources/targets/codex/js/target.json +1 -1
- package/resources/targets/codex/js3d/bootstrap/SKILL.md +2 -4
- package/resources/targets/codex/js3d/context-filter-report.json +1 -1
- package/resources/targets/codex/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/codex/js3d/js3d/bundle.json +7 -7
- package/resources/targets/codex/js3d/recovery.md +3 -3
- package/resources/targets/codex/js3d/target.json +1 -1
- package/resources/targets/cursor/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/cursor/js/context-filter-report.json +1 -1
- package/resources/targets/cursor/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/cursor/js/js/bundle.json +7 -7
- package/resources/targets/cursor/js/recovery.md +5 -1
- package/resources/targets/cursor/js/target.json +1 -1
- package/resources/targets/cursor/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/cursor/js3d/context-filter-report.json +1 -1
- package/resources/targets/cursor/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/cursor/js3d/js3d/bundle.json +7 -7
- package/resources/targets/cursor/js3d/recovery.md +5 -1
- package/resources/targets/cursor/js3d/target.json +1 -1
- package/resources/targets/dsh/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/dsh/js/context-filter-report.json +1 -1
- package/resources/targets/dsh/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/dsh/js/js/bundle.json +7 -7
- package/resources/targets/dsh/js/recovery.md +5 -1
- package/resources/targets/dsh/js/target.json +1 -1
- package/resources/targets/dsh/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/dsh/js3d/context-filter-report.json +1 -1
- package/resources/targets/dsh/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/dsh/js3d/js3d/bundle.json +7 -7
- package/resources/targets/dsh/js3d/recovery.md +5 -1
- package/resources/targets/dsh/js3d/target.json +1 -1
- package/resources/targets/index.json +32 -32
- package/resources/targets/kimi/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/kimi/js/context-filter-report.json +1 -1
- package/resources/targets/kimi/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/kimi/js/js/bundle.json +7 -7
- package/resources/targets/kimi/js/recovery.md +5 -1
- package/resources/targets/kimi/js/target.json +1 -1
- package/resources/targets/kimi/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/kimi/js3d/context-filter-report.json +1 -1
- package/resources/targets/kimi/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/kimi/js3d/js3d/bundle.json +7 -7
- package/resources/targets/kimi/js3d/recovery.md +5 -1
- package/resources/targets/kimi/js3d/target.json +1 -1
- package/resources/targets/workbuddy/js/bootstrap/SKILL.md +22 -24
- package/resources/targets/workbuddy/js/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/workbuddy/js/js/bundle.json +8 -8
- package/resources/targets/workbuddy/js/js/context/AGENTS.md +29 -29
- package/resources/targets/workbuddy/js/recovery.md +19 -19
- package/resources/targets/workbuddy/js/target.json +1 -1
- package/resources/targets/workbuddy/js3d/bootstrap/SKILL.md +22 -24
- package/resources/targets/workbuddy/js3d/context-filter-report.json +1 -1
- package/resources/targets/workbuddy/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/workbuddy/js3d/js3d/bundle.json +8 -8
- package/resources/targets/workbuddy/js3d/js3d/context/AGENTS.md +30 -30
- package/resources/targets/workbuddy/js3d/recovery.md +19 -19
- package/resources/targets/workbuddy/js3d/target.json +1 -1
- package/resources/targets/zcode/js/bootstrap/SKILL.md +3 -1
- package/resources/targets/zcode/js/context-filter-report.json +1 -1
- package/resources/targets/zcode/js/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/zcode/js/js/bundle.json +7 -7
- package/resources/targets/zcode/js/recovery.md +5 -1
- package/resources/targets/zcode/js/target.json +1 -1
- package/resources/targets/zcode/js3d/bootstrap/SKILL.md +3 -1
- package/resources/targets/zcode/js3d/context-filter-report.json +1 -1
- package/resources/targets/zcode/js3d/craft-game-maker/SKILL.md +11 -15
- package/resources/targets/zcode/js3d/js3d/bundle.json +7 -7
- package/resources/targets/zcode/js3d/recovery.md +5 -1
- package/resources/targets/zcode/js3d/target.json +1 -1
- package/vendor/craft-runtime/SOURCE.json +4 -4
- package/vendor/craft-runtime/package.json +1 -1
- package/dist-server/game-workflow/publication-materials.mjs +0 -92
- package/dist-server/game-workflow/publications.mjs +0 -168
- package/dist-server/game-workflow/publish-capture-worker.mjs +0 -57
- package/dist-server/game-workflow/publish-capture.mjs +0 -75
- package/dist-server/mcp/publication-page.html +0 -86
- package/dist-server/mcp/publication-page.mjs +0 -375
- package/dist-server/mcp/publication-preview.mjs +0 -63
- package/dist-server/mcp/publication-tools.mjs +0 -22
- package/dist-server/mcp/publish-panel.mjs +0 -210
- package/dist-server/upstream/publication-transport.mjs +0 -101
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { randomBytes, randomUUID, createHash } from 'node:crypto';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { currentWork } from '../game-workflow/work-scope.mjs';
|
|
4
|
-
import { mkdir,writeFile,rm,lstat,realpath } from 'node:fs/promises';
|
|
5
|
-
import { privateDirectory } from '../game-workflow/request-store.mjs';
|
|
6
|
-
import { imageExtension } from '../game-workflow/asset-formats.mjs';
|
|
7
|
-
import { publicationMaterials } from '../game-workflow/publication-materials.mjs';
|
|
8
|
-
|
|
9
|
-
const identifier = /^[a-zA-Z0-9_-]{1,128}$/;
|
|
10
|
-
const failure = (message,status=400)=>Object.assign(new Error(message),{ status });
|
|
11
|
-
function bodyFields(body,keys,required=keys) {
|
|
12
|
-
if (!body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).some(key=>!keys.includes(key)) ||
|
|
13
|
-
required.some(key=>!Object.hasOwn(body,key))) throw failure('Invalid publication request');
|
|
14
|
-
}
|
|
15
|
-
function selectedId(value) {
|
|
16
|
-
if (typeof value !== 'string' || !identifier.test(value)) throw failure('Invalid publication identity');
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Both the MCP tools and this local page use the host's original workflow and project locks.
|
|
21
|
-
export function createPublishPanel({ platform,projects,tasks,drafts,publications,checkedTask,mutate,viewTask,
|
|
22
|
-
preview:openPreview,coverDirectory,now=Date.now }) {
|
|
23
|
-
const scopes = new Map(); let origin,closed=false,coverRoot;
|
|
24
|
-
const current = scope=>{
|
|
25
|
-
const session = platform.store.getSession();
|
|
26
|
-
return !closed && now()-scope.created < 60*60*1000 && platform.base === scope.platform && session.loggedIn &&
|
|
27
|
-
session.token === scope.token && Number(session.identity?.userId) === scope.owner;
|
|
28
|
-
};
|
|
29
|
-
async function retire(cap,scope) {
|
|
30
|
-
scopes.delete(cap); clearTimeout(scope.expiry);
|
|
31
|
-
if (scope.cover_directory) { try { await rm(scope.cover_directory,{ recursive:true,force:true }); } catch { /* The private stage can be retried by host cleanup. */ } }
|
|
32
|
-
try { await (await scope.preview)?.close(); } catch { /* A stopped local preview is already unavailable. */ }
|
|
33
|
-
}
|
|
34
|
-
async function scopeFor(cap) {
|
|
35
|
-
const scope = scopes.get(cap);
|
|
36
|
-
if (!scope) throw failure('This local publication page is unavailable. Reopen it from Craft.',404);
|
|
37
|
-
if (!current(scope)) {
|
|
38
|
-
await retire(cap,scope);
|
|
39
|
-
throw failure('Craft account or publication page changed. Reopen the page.',403);
|
|
40
|
-
}
|
|
41
|
-
return scope;
|
|
42
|
-
}
|
|
43
|
-
function requireCurrent(scope) {
|
|
44
|
-
if (!current(scope)) throw failure('Craft account or publication page changed. Reopen the page.',403);
|
|
45
|
-
}
|
|
46
|
-
async function publication(scope,id) {
|
|
47
|
-
if (selectedId(id) !== scope.publication_id) throw failure('Publication does not belong to this page',403);
|
|
48
|
-
const result = await publications.status(scope.name,id,scope.owner);
|
|
49
|
-
if (result.check_task_id !== scope.check_task_id) throw failure('Publication does not match this checked build',403);
|
|
50
|
-
requireCurrent(scope); return result;
|
|
51
|
-
}
|
|
52
|
-
async function preview(scope) {
|
|
53
|
-
if (!openPreview) return;
|
|
54
|
-
const pending=scope.preview ??= Promise.resolve().then(()=>openPreview(scope.check));
|
|
55
|
-
let handle;
|
|
56
|
-
let url;
|
|
57
|
-
try {
|
|
58
|
-
handle=await pending;
|
|
59
|
-
url=new URL(handle.url);
|
|
60
|
-
if (url.protocol !== 'http:' || url.hostname !== '127.0.0.1' || url.origin === origin || url.username || url.password || url.hash) {
|
|
61
|
-
throw failure('Publication preview must use an isolated loopback origin');
|
|
62
|
-
}
|
|
63
|
-
} catch {
|
|
64
|
-
if (scope.preview === pending) delete scope.preview;
|
|
65
|
-
try { await handle?.close(); } catch { /* No usable optional preview remains. */ }
|
|
66
|
-
requireCurrent(scope); scope.preview_unavailable=true;
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
// Authorization failures remain errors; retirement owns the valid preview handle.
|
|
70
|
-
requireCurrent(scope); scope.preview_unavailable=false;
|
|
71
|
-
return url.href;
|
|
72
|
-
}
|
|
73
|
-
const unsubscribe = platform.store.onChange?.(()=>{
|
|
74
|
-
for (const [cap,scope] of scopes) if (!current(scope)) void retire(cap,scope);
|
|
75
|
-
});
|
|
76
|
-
return {
|
|
77
|
-
get activeCount() { return scopes.size; },
|
|
78
|
-
async releaseWork(workId) {
|
|
79
|
-
for (const [cap,scope] of scopes) if (scope.work?.work_id===workId) await retire(cap,scope);
|
|
80
|
-
},
|
|
81
|
-
bindOrigin(value) { origin=value; },
|
|
82
|
-
async open(name,checkId,publicationId) {
|
|
83
|
-
if (closed || !origin) throw failure('Local publication panel is unavailable');
|
|
84
|
-
projects.file(name); selectedId(checkId);
|
|
85
|
-
const account=platform.account(),session=platform.store.getSession();
|
|
86
|
-
const resume=Boolean(publicationId) || await drafts.hasRequest(name,checkId,account.user_id);
|
|
87
|
-
const context=await checkedTask(checkId,name,resume);
|
|
88
|
-
for (const [cap,existing] of scopes) if (!current(existing)) await retire(cap,existing);
|
|
89
|
-
if (scopes.size >= 32) throw failure('Close and reconnect Craft to reopen the local publication panel');
|
|
90
|
-
const scope={ name,work:currentWork(),check_task_id:checkId,check:context.task,project:context.project,owner:account.user_id,
|
|
91
|
-
platform:platform.base,token:session.token,created:now(),tasks:new Set() };
|
|
92
|
-
if (publicationId) {
|
|
93
|
-
const existing=await publications.status(name,selectedId(publicationId),account.user_id);
|
|
94
|
-
if (existing.check_task_id !== checkId) throw failure('Publication does not match this checked build',403);
|
|
95
|
-
scope.publication_id=publicationId;
|
|
96
|
-
}
|
|
97
|
-
requireCurrent(scope);
|
|
98
|
-
const cap=randomBytes(32).toString('base64url'); scopes.set(cap,scope);
|
|
99
|
-
scope.expiry=setTimeout(()=>{void retire(cap,scope);},60*60*1000);scope.expiry.unref();
|
|
100
|
-
return { status:'ready',url:origin+'/publish/'+cap,name,check_task_id:checkId,
|
|
101
|
-
...(publicationId ? { publication_id:publicationId } : {}),
|
|
102
|
-
next:'Open this local page to review the frozen game, prepare materials and confirm the exact publication revision. Opening the page does not submit review.' };
|
|
103
|
-
},
|
|
104
|
-
async document(cap) {
|
|
105
|
-
const scope=await scopeFor(cap),runtime_url=await preview(scope);
|
|
106
|
-
scope.document_loaded=true;scope.document_preview_origin=runtime_url ? new URL(runtime_url).origin : undefined;
|
|
107
|
-
return { runtime_url,...(scope.preview_unavailable ? { preview_error:'Local frozen preview is unavailable. Reload this page to retry; saved publication status remains available.' } : {}) };
|
|
108
|
-
},
|
|
109
|
-
async handle(cap,action,method,query,body) {
|
|
110
|
-
const scope=await scopeFor(cap);
|
|
111
|
-
const writing=['cover','prepare','review','submit'].includes(action);
|
|
112
|
-
if (method !== (writing ? 'POST' : 'GET')) throw failure('Publication method is not allowed',405);
|
|
113
|
-
const allowedQuery=action === 'task' ? ['task_id'] : action === 'status' ? ['publication_id'] : [];
|
|
114
|
-
if ([...query.keys()].some(key=>!allowedQuery.includes(key)) || allowedQuery.some(key=>query.getAll(key).length !== 1)) throw failure('Invalid publication query');
|
|
115
|
-
if (action === 'state') {
|
|
116
|
-
const [options,draft,saved,previous]=await Promise.all([
|
|
117
|
-
platform.publicationSession(scope.owner)('options'),
|
|
118
|
-
drafts.status(scope.name,scope.check_task_id,scope.owner),
|
|
119
|
-
scope.publication_id ? publication(scope,scope.publication_id) : undefined,
|
|
120
|
-
publications.previous(scope.check,scope.owner),
|
|
121
|
-
]);
|
|
122
|
-
// The document CSP pins its optional frame origin; a failed preview is retried on reload.
|
|
123
|
-
const runtime_url=scope.document_loaded && !scope.document_preview_origin ? undefined : await preview(scope); requireCurrent(scope);
|
|
124
|
-
const account=platform.account();
|
|
125
|
-
scope.previous=previous;
|
|
126
|
-
return { name:scope.name,check_task_id:scope.check_task_id,engine:scope.check.result.engine,platform:scope.platform,
|
|
127
|
-
account:{ user_id:account.user_id,nickname:account.nickname },draft,options,publication:saved,
|
|
128
|
-
...(previous ? { previous_publication:{ materials:previous.materials,cover_available:Boolean(previous.cover_url) } } : {}),
|
|
129
|
-
task_id:scope.task_id,runtime_url,preview_unavailable:scope.preview_unavailable === true,
|
|
130
|
-
...(scope.preview_unavailable ? { preview_error:'Local frozen preview is unavailable. Reload this page to retry; saved publication status remains available.' } : {}) };
|
|
131
|
-
}
|
|
132
|
-
if (action === 'task') {
|
|
133
|
-
const id=selectedId(query.get('task_id'));
|
|
134
|
-
if (!scope.tasks.has(id)) throw failure('Task does not belong to this page',403);
|
|
135
|
-
const result=viewTask(await tasks.get(id)); requireCurrent(scope); return result;
|
|
136
|
-
}
|
|
137
|
-
if (action === 'status') return publication(scope,query.get('publication_id'));
|
|
138
|
-
if (!writing) throw failure('Unknown publication action',404);
|
|
139
|
-
return mutate(scope.name,async()=>{
|
|
140
|
-
requireCurrent(scope);
|
|
141
|
-
if (action === 'cover') {
|
|
142
|
-
bodyFields(body,['data']);
|
|
143
|
-
if (typeof body.data !== 'string' || body.data.length > Math.ceil(2*1024*1024/3)*4 ||
|
|
144
|
-
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(body.data)) throw failure('Cover must be a PNG/JPEG image of at most 2 MiB');
|
|
145
|
-
const data=Buffer.from(body.data,'base64');
|
|
146
|
-
if (!data.length || data.length > 2*1024*1024) throw failure('Cover must be a PNG/JPEG image of at most 2 MiB');
|
|
147
|
-
const extension=imageExtension(data);
|
|
148
|
-
if (!['png','jpg'].includes(extension)) throw failure('Cover must be a PNG or JPEG image');
|
|
149
|
-
if (!coverDirectory) throw failure('Local cover staging is unavailable');
|
|
150
|
-
coverRoot ??= privateDirectory(coverDirectory,projects.root);
|
|
151
|
-
const root=await coverRoot;
|
|
152
|
-
const directory=scope.cover_directory ?? path.join(root,cap);
|
|
153
|
-
await mkdir(directory,{ recursive:true,mode:0o700 });
|
|
154
|
-
if ((await lstat(directory)).isSymbolicLink() || await realpath(directory) !== directory) throw failure('Invalid private cover directory');
|
|
155
|
-
scope.cover_directory=directory;
|
|
156
|
-
const id=randomUUID(),file=id+'.'+extension;
|
|
157
|
-
await writeFile(path.join(directory,file),data,{ flag:'wx',mode:0o600 });
|
|
158
|
-
requireCurrent(scope);
|
|
159
|
-
const old=scope.cover;
|
|
160
|
-
scope.cover={ id,directory,file,sha256:createHash('sha256').update(data).digest('hex'),bytes:data.length,extension };
|
|
161
|
-
if (old) await rm(path.join(old.directory,old.file),{ force:true });
|
|
162
|
-
return { cover_id:id };
|
|
163
|
-
}
|
|
164
|
-
if (action === 'prepare') {
|
|
165
|
-
bodyFields(body,['materials','cover_id','reuse_previous_cover'],['materials']); publicationMaterials(body.materials);
|
|
166
|
-
if (body.materials.cover_path !== undefined) throw failure('Choose a cover image on this local page');
|
|
167
|
-
if (body.cover_id !== undefined && (typeof body.cover_id !== 'string' || body.cover_id !== scope.cover?.id)) throw failure('Cover does not belong to this page',403);
|
|
168
|
-
if (body.reuse_previous_cover !== undefined && typeof body.reuse_previous_cover !== 'boolean') throw failure('Choose whether to reuse the previous cover');
|
|
169
|
-
const stagedCover=body.cover_id ? scope.cover : undefined;
|
|
170
|
-
const resume=await drafts.hasRequest(scope.name,scope.check_task_id,scope.owner);
|
|
171
|
-
const context=await checkedTask(scope.check_task_id,scope.name,resume);
|
|
172
|
-
requireCurrent(scope);
|
|
173
|
-
const task=await tasks.start(scope.name,'publish_prepare',async signal=>{
|
|
174
|
-
requireCurrent(scope);
|
|
175
|
-
const reusePreviousCover=!stagedCover && body.reuse_previous_cover !== false;
|
|
176
|
-
let previous=scope.previous;
|
|
177
|
-
if (reusePreviousCover && !Object.hasOwn(scope,'previous')) {
|
|
178
|
-
previous=await publications.previous(context.task,scope.owner,signal);
|
|
179
|
-
requireCurrent(scope);
|
|
180
|
-
}
|
|
181
|
-
const source=await drafts.upload(context.task,scope.owner,signal);
|
|
182
|
-
requireCurrent(scope);
|
|
183
|
-
if (previous && source.conversation_id !== previous.conversation_id) throw new Error('发布资料所属项目已变化,请刷新进度并核对资料后重试。');
|
|
184
|
-
const previousCover=reusePreviousCover && previous?.cover_url ? previous : undefined;
|
|
185
|
-
const result=await publications.prepare(context.task,context.project,body.materials,scope.owner,signal,stagedCover,previousCover);
|
|
186
|
-
requireCurrent(scope); scope.publication_id=result.publication_id; return result;
|
|
187
|
-
},{ owner:scope.owner,platform:scope.platform,check_task_id:scope.check_task_id });
|
|
188
|
-
scope.tasks.add(task.task_id); scope.task_id=task.task_id; return viewTask(task);
|
|
189
|
-
}
|
|
190
|
-
if (action === 'review') {
|
|
191
|
-
bodyFields(body,['publication_id']); await publication(scope,body.publication_id);
|
|
192
|
-
const result=await publications.review(scope.name,body.publication_id,scope.owner);
|
|
193
|
-
requireCurrent(scope); return result;
|
|
194
|
-
}
|
|
195
|
-
bodyFields(body,['publication_id','revision','confirmed']);
|
|
196
|
-
if (typeof body.revision !== 'string' || !/^[0-9a-f]{64}$/.test(body.revision) || body.confirmed !== true) throw failure('Confirm the exact reviewed publication revision');
|
|
197
|
-
await publication(scope,body.publication_id); requireCurrent(scope);
|
|
198
|
-
const task=await tasks.start(scope.name,'publish_submit',signal=>{
|
|
199
|
-
requireCurrent(scope);
|
|
200
|
-
return publications.submit(scope.name,body.publication_id,body.revision,true,scope.owner,signal);
|
|
201
|
-
},{ owner:scope.owner,platform:scope.platform,publication_id:body.publication_id });
|
|
202
|
-
scope.tasks.add(task.task_id); scope.task_id=task.task_id; return viewTask(task);
|
|
203
|
-
},scope.work);
|
|
204
|
-
},
|
|
205
|
-
async close() {
|
|
206
|
-
closed=true; unsubscribe?.();
|
|
207
|
-
await Promise.allSettled([...scopes].map(([cap,scope])=>retire(cap,scope)));
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const idPattern = /^[a-zA-Z0-9_-]{1,128}$/;
|
|
2
|
-
const hashPattern = /^[0-9a-f]{64}$/;
|
|
3
|
-
|
|
4
|
-
function identifier(value) {
|
|
5
|
-
if (typeof value !== 'string' || !idPattern.test(value)) throw new Error('Invalid publication identifier');
|
|
6
|
-
return value;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function imageURL(value, token, base) {
|
|
10
|
-
if (typeof value !== 'string' || value.includes(token)) throw new Error('Invalid publication image URL');
|
|
11
|
-
const url = new URL(value);
|
|
12
|
-
if (url.username || url.password || url.hash || url.search ||
|
|
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('Invalid publication image URL');
|
|
15
|
-
}
|
|
16
|
-
return url.href;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function previousPublication(data, conversationId, owner, token, base) {
|
|
20
|
-
if (!data || typeof data !== 'object' || !Object.hasOwn(data,'share_info')) throw new Error('Invalid publication history response');
|
|
21
|
-
const previous = data.share_info;
|
|
22
|
-
if (previous === null) return;
|
|
23
|
-
if (previous?.conversation_id !== conversationId || previous.user_id !== owner) throw new Error('Publication history belongs to a different project or account');
|
|
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),
|
|
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('Publication requires a Craft platform origin');
|
|
39
|
-
return async (kind, options = {}, signal) => {
|
|
40
|
-
if (!current()) throw new Error('Craft account changed');
|
|
41
|
-
let endpoint, method = 'GET', body, form;
|
|
42
|
-
if (kind === 'options') endpoint = '/api/ms/gamemeta/game-style';
|
|
43
|
-
else if (kind === 'image') {
|
|
44
|
-
const { image, conversation_id, version_id, external_manifest_sha256, purpose } = options;
|
|
45
|
-
if (!['cover','screenshot','audit-shot'].includes(purpose) || !hashPattern.test(external_manifest_sha256) ||
|
|
46
|
-
!Buffer.isBuffer(image?.data) || !image.data.length || image.data.length > 2 * 1024 * 1024 ||
|
|
47
|
-
!['png','jpg'].includes(image.extension)) throw new Error('Invalid publication image');
|
|
48
|
-
endpoint = '/api/ms/versions/share-cover'; method = 'POST';
|
|
49
|
-
form = new FormData();
|
|
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);
|
|
51
|
-
form.set('cover',new Blob([image.data],{ type:image.extension === 'png' ? 'image/png' : 'image/jpeg' }),`material.${image.extension}`);
|
|
52
|
-
} else if (kind === 'submit') {
|
|
53
|
-
endpoint = '/api/ms/versions/share'; method = 'POST'; body = options.input;
|
|
54
|
-
identifier(body?.client_request_id); identifier(body?.conversation_id); identifier(body?.version_id);
|
|
55
|
-
if (!hashPattern.test(body.external_manifest_sha256)) throw new Error('Invalid publication manifest');
|
|
56
|
-
} else if (kind === 'status') endpoint = `/api/ms/versions/${identifier(options.version_id)}/detail`;
|
|
57
|
-
else if (kind === 'previous') endpoint = `/api/ms/conversations/${identifier(options.conversation_id)}/publish-context`;
|
|
58
|
-
else throw new Error('Unknown publication operation');
|
|
59
|
-
const data = await http(endpoint,method,body,signal,{ form,draft:true,businessErrors:true,bare:kind === 'options' });
|
|
60
|
-
if (!current()) throw new Error('Craft account changed during publication');
|
|
61
|
-
if (kind === 'options') {
|
|
62
|
-
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('Invalid publication category response');
|
|
63
|
-
const result = {};
|
|
64
|
-
for (const key of ['game_types','art_styles','play_tags']) {
|
|
65
|
-
if (!data || !Object.hasOwn(data,key)) throw new Error('Invalid publication category response');
|
|
66
|
-
const values = data[key] ?? [];
|
|
67
|
-
if (!Array.isArray(values) || values.length > 200 || values.some(item=>typeof item !== 'string' || item.length > 100 || item.includes(token))) throw new Error('Invalid publication category response');
|
|
68
|
-
result[key] = values;
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
if (kind === 'image') {
|
|
73
|
-
if (!hashPattern.test(data?.sha256) || data.bytes !== options.image.data.length) throw new Error('Invalid publication material receipt');
|
|
74
|
-
return { cover_url:imageURL(data.cover_url,token,base),material_id:identifier(data.material_id),sha256:data.sha256,bytes:data.bytes };
|
|
75
|
-
}
|
|
76
|
-
if (kind === 'submit') return { accepted:true };
|
|
77
|
-
if (kind === 'previous') return previousPublication(data,options.conversation_id,owner,token,base);
|
|
78
|
-
const publication = data?.external_publication;
|
|
79
|
-
if (!publication) return { state:'not_submitted', version_id:options.version_id };
|
|
80
|
-
if (publication.version_id !== options.version_id || !hashPattern.test(publication.external_manifest_sha256) ||
|
|
81
|
-
!hashPattern.test(publication.request_sha256) || typeof publication.status !== 'string' || !/^[a-z_]{1,48}$/.test(publication.status)) {
|
|
82
|
-
throw new Error('Invalid publication status response');
|
|
83
|
-
}
|
|
84
|
-
const result = { client_request_id:identifier(publication.client_request_id),request_sha256:publication.request_sha256,
|
|
85
|
-
external_manifest_sha256:publication.external_manifest_sha256,version_id:publication.version_id,
|
|
86
|
-
conversation_id:identifier(publication.conversation_id),state:publication.status,
|
|
87
|
-
status_reason:typeof publication.status_reason === 'string' ? publication.status_reason.split(token).join('[REDACTED]').slice(0,1000) : '' };
|
|
88
|
-
if (publication.finalization_retry_required !== undefined) {
|
|
89
|
-
if (typeof publication.finalization_retry_required !== 'boolean' ||
|
|
90
|
-
(publication.finalization_retry_required && result.state !== 'sharing')) throw new Error('Invalid publication finalization state');
|
|
91
|
-
result.finalization_retry_required = publication.finalization_retry_required;
|
|
92
|
-
}
|
|
93
|
-
if (publication.public_url !== undefined && publication.public_url !== '') {
|
|
94
|
-
const url = new URL(publication.public_url);
|
|
95
|
-
if (result.state !== 'share_completed' || publication.published_version_id !== options.version_id ||
|
|
96
|
-
url.origin !== new URL(base).origin || url.username || url.password || publication.public_url.includes(token)) throw new Error('Publication URL does not match the completed version');
|
|
97
|
-
result.public_url = url.href;
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
}
|