@zenaigc/zenmcp 0.1.2 → 0.1.3
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.
|
@@ -18,7 +18,7 @@ import { download, fetchOutput, pollAttempt, refreshUnsettledRefunds, replayRequ
|
|
|
18
18
|
const inputSchema = z.strictObject({ slot: z.string(), type: z.enum(['image', 'video']), sha256: z.string().regex(/^[a-f0-9]{64}$/), content_type: z.string(), size_bytes: z.number().int().nonnegative() });
|
|
19
19
|
const requestSchema = z.strictObject({ schema_version: z.literal(1), generation_id: z.guid(), request: z.strictObject({ capability: z.string(), medium: z.enum(['image', 'video', 'audio']), voice_authorized: z.boolean().optional(), params: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])), inputs: z.array(inputSchema) }), request_digest: z.string(), quote: z.strictObject({ price_credits: z.number().int().nonnegative(), pricing_version: z.string(), quoted_at: z.string() }) });
|
|
20
20
|
const stateSchema = z.object({
|
|
21
|
-
request_digest: z.string(), status: z.enum(['quoted', 'running', 'completed', 'failed']),
|
|
21
|
+
request_digest: z.string(), status: z.enum(['quoted', 'running', 'awaiting_cloud', 'completed', 'failed']),
|
|
22
22
|
approvedCredits: z.number().int().nonnegative().optional(), mode: z.enum(['R', 'N1', 'N2']).optional(),
|
|
23
23
|
error: z.string().optional(), attempt: z.string().optional(),
|
|
24
24
|
output: z.object({ file: z.string().regex(/^output\.(png|jpg|webp|mp4|mp3)$/), kind: z.enum(['image', 'video', 'audio']), sha256: z.string().regex(/^[a-f0-9]{64}$/) }).optional(),
|
|
@@ -440,6 +440,11 @@ export class DirectGeneration {
|
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
attempt = await pollAttempt(runner, attempt, this.options.poll ?? { intervalMs: 5000, timeoutMs: req.request.medium === 'image' ? 600000 : 1800000 });
|
|
443
|
+
if (attempt.state === 'submitted') {
|
|
444
|
+
// Polling expired locally; the original cloud attempt and reservation remain live.
|
|
445
|
+
await writeJson(dir, 'state.json', { ...state, status: 'awaiting_cloud', attempt: attempt.idempotency_key });
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
443
448
|
if (attempt.state !== 'completed')
|
|
444
449
|
throw await terminalError(attempt, g);
|
|
445
450
|
const url = await fetchOutput(g, attempt, req.request.medium);
|
|
@@ -499,6 +504,6 @@ export class DirectGeneration {
|
|
|
499
504
|
locked = e.code !== 'ENOENT';
|
|
500
505
|
}
|
|
501
506
|
const secret = await this.options.tokens.token().catch(() => '');
|
|
502
|
-
return scrub({ charge_notice, status: state?.status ?? 'quoted', generation_id: req.generation_id, request_digest: req.request_digest, request: req.request, quote: req.quote, approvedCredits: state?.approvedCredits, budget: new LocalBudget(state?.approvedCredits ?? 0).usage(attempts), attempts: attempts.map(a => ({ key: a.idempotency_key, state: a.state, status: a.status, charged_credits: a.charged_credits, refund_state: a.refund_state, ...(/^[a-z][a-z0-9_]*$/.test(a.rejected_code ?? '') ? { rejected_code: a.rejected_code } : {}) })), output: state?.status === 'completed' && state.output && /^output\.(png|jpg|webp|mp4|mp3)$/.test(state.output.file) ? { file: join(dir, state.output.file), kind: state.output.kind, sha256: state.output.sha256 } : undefined, background, interrupted: state?.status === 'running' && !background && !locked, error: state?.error ? redact(safeError(new Error(state.error), secret), secret) : undefined, markdown: [`生成状态:${state?.status ?? 'quoted'}`, ...(charge_notice ? [charge_notice, '预算已保留,请在同一生成目录续查。'] : [])].join('\n\n') }, secret);
|
|
507
|
+
return scrub({ charge_notice, status: state?.status ?? 'quoted', generation_id: req.generation_id, request_digest: req.request_digest, request: req.request, quote: req.quote, approvedCredits: state?.approvedCredits, budget: new LocalBudget(state?.approvedCredits ?? 0).usage(attempts), attempts: attempts.map(a => ({ key: a.idempotency_key, state: a.state, status: a.status, charged_credits: a.charged_credits, refund_state: a.refund_state, ...(/^[a-z][a-z0-9_]*$/.test(a.rejected_code ?? '') ? { rejected_code: a.rejected_code } : {}) })), output: state?.status === 'completed' && state.output && /^output\.(png|jpg|webp|mp4|mp3)$/.test(state.output.file) ? { file: join(dir, state.output.file), kind: state.output.kind, sha256: state.output.sha256 } : undefined, background, interrupted: state?.status === 'running' && !background && !locked, error: state?.error ? redact(safeError(new Error(state.error), secret), secret) : undefined, markdown: [`生成状态:${state?.status ?? 'quoted'}`, ...(state?.status === 'awaiting_cloud' ? ['本地轮询已超时,云端仍在生成或结果待确认,并非生成失败。', '预占预算已保留。', '请在同一生成目录继续调用 get_generation 查询状态,或调用 run_generation 恢复轮询;续查会复用原任务,不会重复提交扣费。'] : []), ...(charge_notice ? [charge_notice, '预算已保留,请在同一生成目录续查。'] : [])].join('\n\n') }, secret);
|
|
503
508
|
}
|
|
504
509
|
}
|
package/dist/src/mcp/server.js
CHANGED
|
@@ -58,7 +58,7 @@ const SERVER_INSTRUCTIONS = `Zenmcp tools are atomic. Combine them as follows.
|
|
|
58
58
|
- post_unavailable: the post was deleted, is private, or is region-locked.`;
|
|
59
59
|
/** Background tasks live in this MCP process; state and attempts survive its restart. */
|
|
60
60
|
export function createServer(engine, socialOptions = {}, speechOptions = {}) {
|
|
61
|
-
const server = new McpServer({ name: 'zenmcp', version: '0.1.
|
|
61
|
+
const server = new McpServer({ name: 'zenmcp', version: '0.1.3' }, { instructions: SERVER_INSTRUCTIONS });
|
|
62
62
|
const active = new Map();
|
|
63
63
|
server.registerTool('fetch_social_post', {
|
|
64
64
|
description: '解析抖音/小红书/B站/TikTok/Instagram/X 分享口令或链接,下载视频或图集到本地目录,返回本地路径与标题/正文/话题。免费、限次;不分析内容。视频可直接交给 analyze_reference。',
|