@craft_eco/craft-mcp 0.1.14 → 0.1.18
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 +1 -1
- package/dist-server/game-workflow/draft-archive.mjs +53 -91
- package/dist-server/game-workflow/draft-uploads.mjs +207 -207
- package/dist-server/game-workflow/publications.mjs +4 -2
- package/dist-server/mcp/control-panel.mjs +59 -40
- package/dist-server/mcp/publication-page.html +86 -0
- package/dist-server/mcp/publication-page.mjs +347 -0
- package/dist-server/mcp/publication-preview.mjs +49 -0
- package/dist-server/mcp/publication-tools.mjs +4 -1
- package/dist-server/mcp/publish-panel.mjs +191 -0
- package/dist-server/mcp/server.mjs +312 -297
- package/dist-server/upstream/craft-aigc.mjs +169 -197
- package/dist-server/upstream/publication-transport.mjs +2 -1
- package/package.json +1 -1
- package/resources/craft-game-maker/SKILL.md +69 -67
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.d.ts +19 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.js +107 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-archive.js.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.d.ts +44 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.d.ts.map +1 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.js +106 -0
- package/vendor/agent-cli/dist/src/artifacts/external-game-upload.js.map +1 -0
- package/vendor/agent-cli/dist/src/index.d.ts +2 -0
- package/vendor/agent-cli/dist/src/index.d.ts.map +1 -1
- package/vendor/agent-cli/dist/src/index.js +2 -0
- package/vendor/agent-cli/dist/src/index.js.map +1 -1
|
@@ -1,197 +1,169 @@
|
|
|
1
|
-
import { AuthStore } from '../core/auth-store.mjs';
|
|
2
|
-
import { resolveLibraryUrl } from './library-url.mjs';
|
|
3
|
-
import {
|
|
4
|
-
import { publicationSession } from './publication-transport.mjs';
|
|
5
|
-
|
|
6
|
-
const API = Object.freeze({ me: '/api/auth/me', metadata: '/api/ms/gamemeta/file-hashes',
|
|
7
|
-
generate: '/api/res/generate-2-d-text-to-image', generate_image_edit:'/api/res/generate-2-d-image-text-to-image',
|
|
8
|
-
generate_static_mesh:'/api/res/generate-3-d-props-pipeline', generate_skeletal_mesh:'/api/res/generate-3-d-character-pipeline',
|
|
9
|
-
generate_music:'/api/res/generate-music', generate_video:'/api/res/generate-video',
|
|
10
|
-
generate_sprite_sheet:'/api/res/generate-sprite-sheet-pipeline', generate_animation:'/api/res/generate-mocap',
|
|
11
|
-
query: '/api/res/query-tasks', cancel: '/api/res/cancel-task',
|
|
12
|
-
search:'/api/ms/agent/toolbox/search/js/batch-semantic-search' });
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
size
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.store
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
133
|
-
if (!current()) throw new Error('Craft account changed');
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
async status(signal) {
|
|
173
|
-
if (!this.store.getSession().loggedIn) return { authenticated: false, platform: this.base };
|
|
174
|
-
let account;
|
|
175
|
-
try { account = await this.request('me',undefined,undefined,signal); }
|
|
176
|
-
catch (error) {
|
|
177
|
-
if (!this.store.getSession().loggedIn) return { authenticated:false, platform:this.base, authentication_error:{ message:error.message,...error.detail } };
|
|
178
|
-
throw error;
|
|
179
|
-
}
|
|
180
|
-
try { this.#validateAccount(account); if (account.user_id !== this.account().user_id) throw new Error('Craft account changed'); }
|
|
181
|
-
catch (error) { this.logout(); throw error; }
|
|
182
|
-
return { authenticated: true, platform: this.base, ...this.account() };
|
|
183
|
-
}
|
|
184
|
-
async assetUrl(value) {
|
|
185
|
-
this.account();
|
|
186
|
-
this.#metadata ??= await this.request('metadata');
|
|
187
|
-
const base = new URL(this.#metadata.cos_public_addr), url = new URL(value, base.href.replace(/\/$/,'') + '/');
|
|
188
|
-
if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname.replace(/\/$/,'') + '/') || url.username || url.password || url.hash ||
|
|
189
|
-
(url.protocol !== 'https:' && !(new URL(this.base).hostname === '127.0.0.1' && url.hostname === '127.0.0.1'))) throw new Error('Asset URL is outside the platform CDN');
|
|
190
|
-
return url.href;
|
|
191
|
-
}
|
|
192
|
-
async libraryUrl(value) {
|
|
193
|
-
this.account();
|
|
194
|
-
this.#metadata ??= await this.request('metadata');
|
|
195
|
-
return resolveLibraryUrl(value,this.#metadata.cos_public_addr,this.base);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
1
|
+
import { AuthStore } from '../core/auth-store.mjs';
|
|
2
|
+
import { resolveLibraryUrl } from './library-url.mjs';
|
|
3
|
+
import { externalGameUploadRequest, parseExternalGameUploadReceipt } from '#craft-sdk';
|
|
4
|
+
import { publicationSession } from './publication-transport.mjs';
|
|
5
|
+
|
|
6
|
+
const API = Object.freeze({ me: '/api/auth/me', metadata: '/api/ms/gamemeta/file-hashes',
|
|
7
|
+
generate: '/api/res/generate-2-d-text-to-image', generate_image_edit:'/api/res/generate-2-d-image-text-to-image',
|
|
8
|
+
generate_static_mesh:'/api/res/generate-3-d-props-pipeline', generate_skeletal_mesh:'/api/res/generate-3-d-character-pipeline',
|
|
9
|
+
generate_music:'/api/res/generate-music', generate_video:'/api/res/generate-video',
|
|
10
|
+
generate_sprite_sheet:'/api/res/generate-sprite-sheet-pipeline', generate_animation:'/api/res/generate-mocap',
|
|
11
|
+
query: '/api/res/query-tasks', cancel: '/api/res/cancel-task',
|
|
12
|
+
search:'/api/ms/agent/toolbox/search/js/batch-semantic-search' });
|
|
13
|
+
const draftId = /^[a-zA-Z0-9_-]{1,128}$/;
|
|
14
|
+
|
|
15
|
+
export class PlatformError extends Error {
|
|
16
|
+
constructor(message, detail = {}) { super(message); this.detail = detail; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function boundedBody(response, limit) {
|
|
20
|
+
const tooLarge = () => Object.assign(new Error('Response exceeds size limit'),{ code:'CRAFT_RESPONSE_TOO_LARGE' });
|
|
21
|
+
if (Number(response.headers.get('content-length')) > limit) { await response.body?.cancel(); throw tooLarge(); }
|
|
22
|
+
const parts = []; let size = 0;
|
|
23
|
+
for await (const part of response.body ?? []) {
|
|
24
|
+
size += part.length;
|
|
25
|
+
if (size > limit) throw tooLarge();
|
|
26
|
+
parts.push(Buffer.from(part));
|
|
27
|
+
}
|
|
28
|
+
return Buffer.concat(parts);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class CraftAigc {
|
|
32
|
+
#metadata;
|
|
33
|
+
constructor(sessionFile, base, store) {
|
|
34
|
+
if (typeof base !== 'string' || !base.trim()) throw new Error('CRAFT_WEB_URL must be configured');
|
|
35
|
+
this.base = base.trim().replace(/\/+$/,'');
|
|
36
|
+
const url = new URL(this.base);
|
|
37
|
+
if (url.username || url.password || url.search || url.hash ||
|
|
38
|
+
(url.protocol !== 'https:' && !(url.protocol === 'http:' && url.hostname === '127.0.0.1'))) throw new Error('Invalid Craft gateway URL');
|
|
39
|
+
this.store = store ?? new AuthStore(sessionFile);
|
|
40
|
+
this.store.onChange(() => { this.#metadata = undefined; });
|
|
41
|
+
}
|
|
42
|
+
account() {
|
|
43
|
+
const session = this.store.getSession();
|
|
44
|
+
if (!session.loggedIn || !session.token || !session.identity?.userId) throw new Error('Craft login required; use craft_auth_open');
|
|
45
|
+
return { user_id: Number(session.identity.userId), nickname: session.identity.displayName, roles: session.identity.roles };
|
|
46
|
+
}
|
|
47
|
+
async #http(endpoint, method, body, token, signal, bare = false, { form, draft = false, businessErrors = false } = {}) {
|
|
48
|
+
let response, data;
|
|
49
|
+
const search = endpoint === API.search, mutation = !search && !['GET','HEAD'].includes(method);
|
|
50
|
+
const redact = value => (token ? String(value).split(token).join('[REDACTED]') : String(value)).slice(0,400);
|
|
51
|
+
const detail = (delivery_unknown, failure_type) => {
|
|
52
|
+
const requestId = data?.request_id || response?.headers.get('x-request-id');
|
|
53
|
+
return { endpoint, http_status:response?.status, failure_type,
|
|
54
|
+
backend_code:typeof data?.code === 'number' ? data.code : undefined,
|
|
55
|
+
request_id:typeof requestId === 'string' && /^[a-zA-Z0-9_-]{1,128}$/.test(requestId) && !requestId.includes(token) ? requestId : undefined,
|
|
56
|
+
delivery_unknown };
|
|
57
|
+
};
|
|
58
|
+
try {
|
|
59
|
+
const headers = { ...(!form ? { 'Content-Type':'application/json' } : {}),Authorization:'Bearer ' + token };
|
|
60
|
+
const payload = form ?? (body === undefined ? undefined : JSON.stringify(body));
|
|
61
|
+
response = await fetch(this.base + endpoint, { method, redirect:'manual', headers, body:payload,
|
|
62
|
+
signal: AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(draft ? 120000 : search ? 25000 : 15000)]) });
|
|
63
|
+
// The search proxy may return an upstream service-token rejection, not a user-token rejection.
|
|
64
|
+
if (response.status === 401 && !search) this.store.invalidateToken(token);
|
|
65
|
+
if (response.status >= 300 && response.status < 400) {
|
|
66
|
+
await response.body?.cancel();
|
|
67
|
+
throw new PlatformError('Craft 接口返回了跳转,请检查平台地址和接口路由',detail(mutation,'redirect'));
|
|
68
|
+
}
|
|
69
|
+
const raw = await boundedBody(response,2 * 1024 * 1024);
|
|
70
|
+
try { data = JSON.parse(raw.toString()); }
|
|
71
|
+
catch { throw new PlatformError('Craft 接口返回非 JSON 响应,请检查接口路由或服务部署',detail(mutation,'invalid_response')); }
|
|
72
|
+
const object = data !== null && typeof data === 'object' && !Array.isArray(data);
|
|
73
|
+
if (!response.ok || (object && Object.hasOwn(data,'code') && data.code !== 0)) {
|
|
74
|
+
const message = (!draft || businessErrors) && typeof data?.message === 'string' && data.message ? redact(data.message) : 'Craft 平台请求失败';
|
|
75
|
+
throw new PlatformError(message,detail(mutation && response.status >= 500,'http'));
|
|
76
|
+
}
|
|
77
|
+
if (!bare && (!object || data.code !== 0 || !Object.hasOwn(data,'data'))) throw new PlatformError('Craft 接口响应格式不正确',detail(mutation,'invalid_response'));
|
|
78
|
+
return bare ? data : data.data;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof PlatformError) throw error;
|
|
81
|
+
const code = error.cause?.code || error.code;
|
|
82
|
+
const network_code = typeof code === 'string' && /^[A-Z][A-Z0-9_]{1,63}$/.test(code) && !code.includes(token) ? code : undefined;
|
|
83
|
+
const failure_type = code === 'CRAFT_RESPONSE_TOO_LARGE' ? 'response_too_large' :
|
|
84
|
+
error.name === 'TimeoutError' || code === 'UND_ERR_CONNECT_TIMEOUT' ? 'timeout' : signal?.aborted ? 'aborted' : 'network';
|
|
85
|
+
const messages = { response_too_large:'Craft 接口响应超过大小限制',timeout:'连接 Craft 平台超时',aborted:'Craft 请求已取消',network:'无法连接 Craft 平台,请检查网络或代理设置' };
|
|
86
|
+
throw new PlatformError(messages[failure_type],{ ...detail(mutation,failure_type),network_code });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async login(token) {
|
|
90
|
+
if (typeof token !== 'string' || token.length < 8 || token.length > 4096 || /\s/.test(token)) throw new Error('Invalid token');
|
|
91
|
+
const account = await this.#http(API.me, 'GET', undefined, token, undefined, true);
|
|
92
|
+
this.#validateAccount(account);
|
|
93
|
+
this.store.saveTokenSession({ token, identity: { userId: String(account.user_id), staffName: '',
|
|
94
|
+
displayName: String(account.nickname || ''), roles: account.roles } });
|
|
95
|
+
return this.account();
|
|
96
|
+
}
|
|
97
|
+
#validateAccount(account) {
|
|
98
|
+
if (!Number.isSafeInteger(account?.user_id) || account.user_id < 1 || account.disabled || !account.roles?.includes('creator')) {
|
|
99
|
+
throw new Error('An active Craft creator account is required');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
logout() { this.store.clearSession(); return { authenticated: false }; }
|
|
103
|
+
async request(kind, body, owner, signal) {
|
|
104
|
+
if (!Object.hasOwn(API,kind)) throw new Error('Unknown Craft endpoint');
|
|
105
|
+
const account = this.account(), token = this.store.getSession().token;
|
|
106
|
+
if (owner !== undefined && owner !== account.user_id) throw new Error('Craft account changed');
|
|
107
|
+
const method = ['me','metadata'].includes(kind) ? 'GET' : 'POST';
|
|
108
|
+
const data = await this.#http(API[kind], method, body, token, signal, ['me','search'].includes(kind));
|
|
109
|
+
if (this.store.getSession().token !== token) throw new PlatformError('Craft account changed during request', { delivery_unknown: kind !== 'search' && method === 'POST' });
|
|
110
|
+
return kind==='search' ? JSON.parse(JSON.stringify(data).split(token).join('[REDACTED]')) : data;
|
|
111
|
+
}
|
|
112
|
+
draftSession(owner) {
|
|
113
|
+
if (new URL(this.base).pathname !== '/') throw new Error('Draft upload requires a Craft platform origin');
|
|
114
|
+
const session = this.store.getSession(), token = session.token;
|
|
115
|
+
if (!session.loggedIn || owner !== Number(session.identity?.userId) || !token) throw new Error('Craft account changed');
|
|
116
|
+
return (kind, options, signal) => this.#draft(kind,options,owner,token,signal);
|
|
117
|
+
}
|
|
118
|
+
publicationSession(owner) {
|
|
119
|
+
const session = this.store.getSession(), token = session.token;
|
|
120
|
+
if (!session.loggedIn || owner !== Number(session.identity?.userId) || !token) throw new Error('Craft account changed');
|
|
121
|
+
return publicationSession({ base:this.base,token,
|
|
122
|
+
current:()=>{ const value = this.store.getSession(); return value.loggedIn && value.token === token && Number(value.identity?.userId) === owner; },
|
|
123
|
+
http:(endpoint,method,body,signal,options)=>this.#http(endpoint,method,body,token,signal,options?.bare === true,options) });
|
|
124
|
+
}
|
|
125
|
+
async #draft(kind, { id, input, archive }, owner, token, signal) {
|
|
126
|
+
const current = () => {
|
|
127
|
+
const session = this.store.getSession();
|
|
128
|
+
return session.loggedIn && session.token === token && Number(session.identity?.userId) === owner;
|
|
129
|
+
};
|
|
130
|
+
if (!current()) throw new Error('Craft account changed');
|
|
131
|
+
if (id !== undefined && (typeof id !== 'string' || !draftId.test(id) || id.includes(token))) throw new Error('Invalid draft upload ID');
|
|
132
|
+
const { endpoint,method,body }=await externalGameUploadRequest(kind,{ id,input,archive },signal);
|
|
133
|
+
if (!current()) throw new Error('Craft account changed');
|
|
134
|
+
const data=await this.#http(endpoint,method,body,token,signal,false,{ draft:true });
|
|
135
|
+
if (!current()) throw new PlatformError('Craft account changed during draft upload',{ delivery_unknown:method !== 'GET' });
|
|
136
|
+
let result;
|
|
137
|
+
try { result=parseExternalGameUploadReceipt(data,{ uploadId:id,requireUploadPath:kind === 'prepare' }); }
|
|
138
|
+
catch(error) { throw new PlatformError(error.message); }
|
|
139
|
+
for (const key of ['upload_id','conversation_id','version_id']) {
|
|
140
|
+
if (typeof result[key] === 'string' && result[key].includes(token)) throw new PlatformError('Invalid Craft draft response');
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
async status(signal) {
|
|
145
|
+
if (!this.store.getSession().loggedIn) return { authenticated: false, platform: this.base };
|
|
146
|
+
let account;
|
|
147
|
+
try { account = await this.request('me',undefined,undefined,signal); }
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (!this.store.getSession().loggedIn) return { authenticated:false, platform:this.base, authentication_error:{ message:error.message,...error.detail } };
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
try { this.#validateAccount(account); if (account.user_id !== this.account().user_id) throw new Error('Craft account changed'); }
|
|
153
|
+
catch (error) { this.logout(); throw error; }
|
|
154
|
+
return { authenticated: true, platform: this.base, ...this.account() };
|
|
155
|
+
}
|
|
156
|
+
async assetUrl(value) {
|
|
157
|
+
this.account();
|
|
158
|
+
this.#metadata ??= await this.request('metadata');
|
|
159
|
+
const base = new URL(this.#metadata.cos_public_addr), url = new URL(value, base.href.replace(/\/$/,'') + '/');
|
|
160
|
+
if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname.replace(/\/$/,'') + '/') || url.username || url.password || url.hash ||
|
|
161
|
+
(url.protocol !== 'https:' && !(new URL(this.base).hostname === '127.0.0.1' && url.hostname === '127.0.0.1'))) throw new Error('Asset URL is outside the platform CDN');
|
|
162
|
+
return url.href;
|
|
163
|
+
}
|
|
164
|
+
async libraryUrl(value) {
|
|
165
|
+
this.account();
|
|
166
|
+
this.#metadata ??= await this.request('metadata');
|
|
167
|
+
return resolveLibraryUrl(value,this.#metadata.cos_public_addr,this.base);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -37,9 +37,10 @@ export function publicationSession({ base, token, current, http }) {
|
|
|
37
37
|
if (!hashPattern.test(body.external_manifest_sha256)) throw new Error('Invalid publication manifest');
|
|
38
38
|
} else if (kind === 'status') endpoint = `/api/ms/versions/${identifier(options.version_id)}/detail`;
|
|
39
39
|
else throw new Error('Unknown publication operation');
|
|
40
|
-
const data = await http(endpoint,method,body,signal,{ form,draft:true,businessErrors:true });
|
|
40
|
+
const data = await http(endpoint,method,body,signal,{ form,draft:true,businessErrors:true,bare:kind === 'options' });
|
|
41
41
|
if (!current()) throw new Error('Craft account changed during publication');
|
|
42
42
|
if (kind === 'options') {
|
|
43
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new Error('Invalid publication category response');
|
|
43
44
|
const result = {};
|
|
44
45
|
for (const key of ['game_types','art_styles','play_tags']) {
|
|
45
46
|
if (!data || !Object.hasOwn(data,key)) throw new Error('Invalid publication category response');
|
package/package.json
CHANGED
|
@@ -1,67 +1,69 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: craft-game-maker
|
|
3
|
-
description: Make or modify local Craft 2D/Phaser and 3D/Three.js games with WorkBuddy, including AI assets, gameplay checks and preview.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Craft 本地小游戏制作
|
|
7
|
-
|
|
8
|
-
WorkBuddy 负责理解需求、设计、编码和看图验收;Craft MCP 提供工程、素材召回、AIGC、构建和预览,不调用 ForgeAgent。用户描述需求后自动推进,不要求用户指定工具、安装依赖或运行构建。
|
|
9
|
-
|
|
10
|
-
## 默认交互
|
|
11
|
-
|
|
12
|
-
素材来源、获取方式、使用顺序与表现方式遵守当前引擎 `CLAUDE.md`、相关技能及用户要求。`craft_game_info` 的 library / aigc 字段分别列出可用的召回分类与生成类型。调用 AIGC 时使用实际返回的产物;生成按平台规则自动扣分,不要求工程额度或逐项确认。短音效生成已下线,音频召回仍可用。
|
|
13
|
-
|
|
14
|
-
使用平台能力前调用 `craft_auth_status`。已登录直接继续;仅未登录时展示工具返回的 `user_message`,不自行拼地址。`auth_mode:token` 由用户在 WorkBuddy 连接器表单更新凭证并重新连接;普通安装由用户在工具返回的本机页面登录。连接后复用原工程和请求继续。网络错误不要求重新登录;积分不足或服务失败如实报告并保留记录。
|
|
15
|
-
|
|
16
|
-
禁止读取凭据文件、自动填写登录页或连接器凭证表单,或要求用户把 Token 发到聊天、写配置;链接中不得带 Token。
|
|
17
|
-
|
|
18
|
-
后台任务、素材接线、测试、看图和修复持续推进,直到交付或明确受阻;需要用户登录、用户取消时停下说明。交付预览链接、玩法和操作键;生成过图片时附资源 ID 与本地路径。
|
|
19
|
-
|
|
20
|
-
使用召回时,按工程引擎提交 1~8 个 slot/category/query,轮询后检查候选、score、metadata 和错误。选中后用 `craft_assets_import` 传 `source:"library"`、search_id、candidate_id、slot、request_key;一批只含一种来源。AssetId 不当作 AIGC resource_id,不手填下载 URL。搜索操作本身不生成素材;后续素材决策遵守当前引擎上下文与用户要求,不因错误换 key 盲重试,也不把召回素材冒充 AI 产物。
|
|
21
|
-
|
|
22
|
-
## 连续工作流
|
|
23
|
-
|
|
24
|
-
1. **先读引擎说明,再制作游戏。** 新建时用 `craft_game_info(engine)` 选择 `js`(2D/Phaser)或 `js3d`(3D/Three.js),没有 3D 要求时默认 `js`;继续游戏用 `craft_game_info(name)` 获取已保存的引擎。开始设计、编码或修改前,必须用文件工具完整读取 `context.engine.entrypoint` 指向的对应引擎 `CLAUDE.md`,遵循其开发约定。不能用查看路径或本指南代替读取;无法读取时报告阻塞。只读当前引擎,其余参考文档按需加载。
|
|
25
|
-
2. 调用 `craft_game_prepare`,使用稳定的英文 name;新建时传 engine,继续时复用原 name、沿用引擎。必须轮询成功后才用 WorkBuddy 文件工具编辑工程,遵循返回的 instructions/context。工程由本会话占用至 Craft 断开;遇到 CRAFT_PROJECT_IN_USE 时回原会话继续或请用户关闭原会话的 Craft,不绕过锁写文件、不终止其他进程。并行制作使用不同 name。保留模板依赖、runtime、Vite、预览接线和配置结构。
|
|
26
|
-
3. 按当前引擎上下文与用户要求选定的素材方案调用对应工具。使用召回时遵守上述候选导入契约;调用 `craft_assets_generate(name,assets)` 时每批 1~8 项,用 kind 选择 image/image_edit、static_mesh、skeletal_mesh、music、video、sprite_sheet 或 animation。图片按画面选尺寸,角色/道具图可设 `transparent:true`;动画需要视频和宿主骨骼 ID。slot、request_key 保持稳定;恢复用原 key 和全部参数,仅用户要求重做时新建 key。已有 AIGC 任务用 `craft_assets_import` 按 resource_id 导入,禁止另行 curl 下载或重复付费生成。
|
|
27
|
-
4. 返回 task_id 后,用 `craft_task_status(wait_ms:15000)` 轮询至终态;等待生成时可写独立逻辑。遇到 login 展示工具登录链接;asset_preview 则请用户在 Craft 资源中心完成预览确认后复用原请求继续,不自动冒充预览通过。failed/interrupted 查看错误并保留记录,资源未完成不宣称完成。取消用 `craft_task_cancel`,远端 processing 可能继续;导入任务取消只停止本地导入。
|
|
28
|
-
5. 平台没有请求级幂等:超时或提交响应丢失时保留原 key,只查询认领原任务,不盲目重发付费请求;查询未找到不代表未扣分,提交未确认时稍后用原参数重试。
|
|
29
|
-
6. 完成后自动下载主文件和外部依赖,写入返回的 config_file:图片 assets.json、模型 models.json、音频 audio.json、动作 animations.json、视频 videos.json、序列帧 spritesheets.json。按引擎指南实际接线,不只写资源表,不依赖远端 URL。GLB 必须实际加载;序列帧清单的 url 相对清单地址解析;图片检查透明效果。
|
|
30
|
-
7. 调用 `craft_game_check` 执行引擎收尾、构建和浏览器采集。依次提供 `loop`、`settlement`、`restart` 三步,每步包含 action、expected 和真实玩法断言。
|
|
31
|
-
8. gate.passed 后调用 `craft_game_review`,逐一查看初始、主循环、结算、重开四张截图,检查素材、构图、比例、文字、遮挡、透明边缘和玩法反馈;有问题就修复并重验。浏览器或截图不可用时报告未验证。
|
|
32
|
-
9. 玩法和视觉均通过后,调用 `craft_game_deliver(task_id,visual_passed:true,visual_notes)`,填写实际观察。返回 awaiting_host_start 时,由 WorkBuddy 自己用终端/后台进程工具执行 `start.script`;Craft 不启动预览。轮询 `craft_game_info(name).preview`,直到 running=true 且 snapshot 与此次交付一致,打开 URL 确认画布能启动后才交付链接。预览可能被宿主或系统回收;失效时查看 start.logs,重跑启动命令并验证,用 `craft_preview_stop(name)` 停止。源码或构建产物变化后重新检查、交付。
|
|
33
|
-
|
|
34
|
-
用户要求上传 Craft 私有草稿时,先通过检查与看图,再调用 `craft_game_upload(name,check_task_id)`。同一目录、name、账号和平台自动复用 appid,修改后重新检查上传只新增版本;中断时保留原 check_task_id
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
{"phase":"
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
---
|
|
2
|
+
name: craft-game-maker
|
|
3
|
+
description: Make or modify local Craft 2D/Phaser and 3D/Three.js games with WorkBuddy, including AI assets, gameplay checks and preview.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Craft 本地小游戏制作
|
|
7
|
+
|
|
8
|
+
WorkBuddy 负责理解需求、设计、编码和看图验收;Craft MCP 提供工程、素材召回、AIGC、构建和预览,不调用 ForgeAgent。用户描述需求后自动推进,不要求用户指定工具、安装依赖或运行构建。
|
|
9
|
+
|
|
10
|
+
## 默认交互
|
|
11
|
+
|
|
12
|
+
素材来源、获取方式、使用顺序与表现方式遵守当前引擎 `CLAUDE.md`、相关技能及用户要求。`craft_game_info` 的 library / aigc 字段分别列出可用的召回分类与生成类型。调用 AIGC 时使用实际返回的产物;生成按平台规则自动扣分,不要求工程额度或逐项确认。短音效生成已下线,音频召回仍可用。
|
|
13
|
+
|
|
14
|
+
使用平台能力前调用 `craft_auth_status`。已登录直接继续;仅未登录时展示工具返回的 `user_message`,不自行拼地址。`auth_mode:token` 由用户在 WorkBuddy 连接器表单更新凭证并重新连接;普通安装由用户在工具返回的本机页面登录。连接后复用原工程和请求继续。网络错误不要求重新登录;积分不足或服务失败如实报告并保留记录。
|
|
15
|
+
|
|
16
|
+
禁止读取凭据文件、自动填写登录页或连接器凭证表单,或要求用户把 Token 发到聊天、写配置;链接中不得带 Token。
|
|
17
|
+
|
|
18
|
+
后台任务、素材接线、测试、看图和修复持续推进,直到交付或明确受阻;需要用户登录、用户取消时停下说明。交付预览链接、玩法和操作键;生成过图片时附资源 ID 与本地路径。
|
|
19
|
+
|
|
20
|
+
使用召回时,按工程引擎提交 1~8 个 slot/category/query,轮询后检查候选、score、metadata 和错误。选中后用 `craft_assets_import` 传 `source:"library"`、search_id、candidate_id、slot、request_key;一批只含一种来源。AssetId 不当作 AIGC resource_id,不手填下载 URL。搜索操作本身不生成素材;后续素材决策遵守当前引擎上下文与用户要求,不因错误换 key 盲重试,也不把召回素材冒充 AI 产物。
|
|
21
|
+
|
|
22
|
+
## 连续工作流
|
|
23
|
+
|
|
24
|
+
1. **先读引擎说明,再制作游戏。** 新建时用 `craft_game_info(engine)` 选择 `js`(2D/Phaser)或 `js3d`(3D/Three.js),没有 3D 要求时默认 `js`;继续游戏用 `craft_game_info(name)` 获取已保存的引擎。开始设计、编码或修改前,必须用文件工具完整读取 `context.engine.entrypoint` 指向的对应引擎 `CLAUDE.md`,遵循其开发约定。不能用查看路径或本指南代替读取;无法读取时报告阻塞。只读当前引擎,其余参考文档按需加载。
|
|
25
|
+
2. 调用 `craft_game_prepare`,使用稳定的英文 name;新建时传 engine,继续时复用原 name、沿用引擎。必须轮询成功后才用 WorkBuddy 文件工具编辑工程,遵循返回的 instructions/context。工程由本会话占用至 Craft 断开;遇到 CRAFT_PROJECT_IN_USE 时回原会话继续或请用户关闭原会话的 Craft,不绕过锁写文件、不终止其他进程。并行制作使用不同 name。保留模板依赖、runtime、Vite、预览接线和配置结构。
|
|
26
|
+
3. 按当前引擎上下文与用户要求选定的素材方案调用对应工具。使用召回时遵守上述候选导入契约;调用 `craft_assets_generate(name,assets)` 时每批 1~8 项,用 kind 选择 image/image_edit、static_mesh、skeletal_mesh、music、video、sprite_sheet 或 animation。图片按画面选尺寸,角色/道具图可设 `transparent:true`;动画需要视频和宿主骨骼 ID。slot、request_key 保持稳定;恢复用原 key 和全部参数,仅用户要求重做时新建 key。已有 AIGC 任务用 `craft_assets_import` 按 resource_id 导入,禁止另行 curl 下载或重复付费生成。
|
|
27
|
+
4. 返回 task_id 后,用 `craft_task_status(wait_ms:15000)` 轮询至终态;等待生成时可写独立逻辑。遇到 login 展示工具登录链接;asset_preview 则请用户在 Craft 资源中心完成预览确认后复用原请求继续,不自动冒充预览通过。failed/interrupted 查看错误并保留记录,资源未完成不宣称完成。取消用 `craft_task_cancel`,远端 processing 可能继续;导入任务取消只停止本地导入。
|
|
28
|
+
5. 平台没有请求级幂等:超时或提交响应丢失时保留原 key,只查询认领原任务,不盲目重发付费请求;查询未找到不代表未扣分,提交未确认时稍后用原参数重试。
|
|
29
|
+
6. 完成后自动下载主文件和外部依赖,写入返回的 config_file:图片 assets.json、模型 models.json、音频 audio.json、动作 animations.json、视频 videos.json、序列帧 spritesheets.json。按引擎指南实际接线,不只写资源表,不依赖远端 URL。GLB 必须实际加载;序列帧清单的 url 相对清单地址解析;图片检查透明效果。
|
|
30
|
+
7. 调用 `craft_game_check` 执行引擎收尾、构建和浏览器采集。依次提供 `loop`、`settlement`、`restart` 三步,每步包含 action、expected 和真实玩法断言。
|
|
31
|
+
8. gate.passed 后调用 `craft_game_review`,逐一查看初始、主循环、结算、重开四张截图,检查素材、构图、比例、文字、遮挡、透明边缘和玩法反馈;有问题就修复并重验。浏览器或截图不可用时报告未验证。
|
|
32
|
+
9. 玩法和视觉均通过后,调用 `craft_game_deliver(task_id,visual_passed:true,visual_notes)`,填写实际观察。返回 awaiting_host_start 时,由 WorkBuddy 自己用终端/后台进程工具执行 `start.script`;Craft 不启动预览。轮询 `craft_game_info(name).preview`,直到 running=true 且 snapshot 与此次交付一致,打开 URL 确认画布能启动后才交付链接。预览可能被宿主或系统回收;失效时查看 start.logs,重跑启动命令并验证,用 `craft_preview_stop(name)` 停止。源码或构建产物变化后重新检查、交付。
|
|
33
|
+
|
|
34
|
+
用户要求上传 Craft 私有草稿时,先通过检查与看图,再调用 `craft_game_upload(name,check_task_id)`。同一目录、name、账号和平台自动复用 appid,修改后重新检查上传只新增版本;中断时保留原 check_task_id 重试。为后续公开托管保持资源路径可移植,包括本地图片、音频与模型。用 `craft_task_status` 等待上传,用 `craft_game_publish_status(name,check_task_id)` 查询同一版本。`draft_ready` 表示私有上传完成,交付项目 ID、版本 ID 与摘要,不代表公开发布,也不提供云端预览链接。试玩与交付预览沿用 IDE 本地的 `craft_game_deliver` 启动流程,不以云端试玩作为上传完成条件。
|
|
35
|
+
|
|
36
|
+
用户要求公开发布时,优先调用 `craft_game_publish_open(name,check_task_id)` 并向用户展示返回的本地发布页链接。页面可编辑材料、查看验收冻结版本和最终图片,使用原有 30 秒真实采集;只有用户勾选确认具体 revision 后才上传公开图片并提审。页面不依赖安装桌面客户端;同一 publication_id 可重新打开恢复。发布完成以目标版本审核完成及公开链接为准。
|
|
37
|
+
|
|
38
|
+
需要由工具准备材料时,先完成私有上传,调用 `craft_game_publish_options` 获取当前分类。WorkBuddy 根据游戏准备名称、简介/操作说明、分类、标签和封面;封面可用工程内 PNG/JPEG,省略时使用真实游戏截图。调用 `craft_game_publish_prepare(name,check_task_id,materials)`,轮询完成;MCP 对同一冻结版本真实试玩至少 30 秒,生成展示图和审核抽帧,不用四张普通验收图冒充完整采集。
|
|
39
|
+
|
|
40
|
+
随后调用 `craft_game_publish_review(name,publication_id)`,向用户展示完整文案、封面、截图、目标版本、是否开放二创,以及图片上传后为公开 URL 的事实。取得用户对本次 `revision` 的明确确认后,才调用 `craft_game_publish_submit(name,publication_id,revision,confirmed:true)`。材料变化须重新准备、看图和确认;准备完成不表示获得了提交授权。
|
|
41
|
+
|
|
42
|
+
提交任务完成只表示已发起审核。用 `craft_game_publish_status(name,publication_id)` 查询,保留原 ID 恢复超时;只有当前版本 `share_completed` 且返回匹配的 `public_url` 才报告发布成功。审核失败展示原因并修改后重新准备;审核未启用、缺材料或仍在等待时不冒充通过。服务端沿用 Web 发布与 ACE,外部发布须开启平台独立开关。
|
|
43
|
+
|
|
44
|
+
若状态返回 `finalization_retry_required:true`,审核已经通过但最终存储收尾需要重试;复用原 publication_id、revision 和既有确认调用 submit,只恢复同一份已审材料的收尾,不重新准备或另发审核。
|
|
45
|
+
|
|
46
|
+
已公开的同一版本只支持原 publication_id 的幂等重试。修改已公开作品的文案或图片时,重新检查并上传新版本(保留 appid),再准备和确认新材料;旧线上版本在新版本审核期间保持不变。外部包只有 dist,不包含可编辑源码,`open_to_recreate` 必须为 false。
|
|
47
|
+
|
|
48
|
+
## 引擎参考上下文
|
|
49
|
+
|
|
50
|
+
连接时发送通用指南,选定引擎后的 info/prepare 结果附专用指南。`context.workflow` 为通用指南,`context.engine.guide` 为专用指南,`context.engine.directory` 为引擎上下文,`context.references` 为按需文档。
|
|
51
|
+
|
|
52
|
+
引擎目录也供 SDK 生命周期使用。引擎 `CLAUDE.md`、相关技能及用户要求决定素材策略;其中的 Forge 工具和组件接口按当前 MCP 能力适配,不直接调用 skill_load、spawn、game_visual_qa。构建和采集统一用 `craft_game_check`。
|
|
53
|
+
|
|
54
|
+
## 玩法观测
|
|
55
|
+
|
|
56
|
+
保留模板 `globalThis.__GAME_PROBE__.snapshot()` 中真实的 engine、ready、frameCount,增加 `game` 字段读取场景状态,如 `{score,phase,round}`。加载完成才设 ready,不伪造帧数或通过值。
|
|
57
|
+
|
|
58
|
+
测试使用真实输入,不直接改分数或强行结算。Canvas 用坐标,DOM 用 target;`qa:` 仅路由到与玩家操作相同的处理函数,每步 ms ≤ 30000。
|
|
59
|
+
|
|
60
|
+
示例(按实际玩法调整):
|
|
61
|
+
```json
|
|
62
|
+
[
|
|
63
|
+
{"phase":"loop","action":"press","key":"Space","ms":300,"expected":"接到一颗星,分数增加","assertions":[{"path":"game.score","operator":"gte","value":1}]},
|
|
64
|
+
{"phase":"settlement","action":"wait","ms":15000,"expected":"倒计时结束显示结算","assertions":[{"path":"game.phase","operator":"eq","value":"over"}]},
|
|
65
|
+
{"phase":"restart","action":"click","target":"再玩一次","expected":"新一局分数归零","assertions":[{"path":"game.phase","operator":"eq","value":"playing"},{"path":"game.score","operator":"eq","value":0}]}
|
|
66
|
+
]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
支持本地 2D/Phaser、3D/Three.js、图片、模型、音乐、视频、序列帧、视频动捕和平台审核发布;文本动作暂只支持按已有任务 ID 导入,短音效生成、UE 特效未接入。目录校验不构成同 UID 的 OS 沙箱;禁止读取宿主私有状态或修改安装包。
|