@zenaigc/zenmcp 0.1.2 → 0.1.4
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/INSTALL.md +14 -0
- package/dist/src/engine/direct.js +7 -2
- package/dist/src/mcp/guidance.js +85 -0
- package/dist/src/mcp/server.js +191 -44
- package/package.json +1 -1
- package/skills/zenmcp/SKILL.md +22 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-account.json +15 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-account.minimal.json +7 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-budget-confirm.insufficient.json +30 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-budget-confirm.json +30 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-budget-confirm.minimal.json +9 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-budget-confirm.unknown.json +30 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-install-checklist.failed.json +34 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-install-checklist.json +33 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-model-picker.json +25 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-spend-confirm.defaults.json +96 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-spend-confirm.insufficient.json +119 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-spend-confirm.json +119 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-spend-confirm.large.json +119 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-spend-confirm.readonly.json +57 -0
- package/skills/zenmcp/widgets/fixtures/zenmcp-spend-confirm.unknown.json +119 -0
- package/skills/zenmcp/widgets/zenmcp-account/template.json +55 -0
- package/skills/zenmcp/widgets/zenmcp-account/widget.html +28 -0
- package/skills/zenmcp/widgets/zenmcp-budget-confirm/template.json +72 -0
- package/skills/zenmcp/widgets/zenmcp-budget-confirm/widget.html +32 -0
- package/skills/zenmcp/widgets/zenmcp-install-checklist/template.json +55 -0
- package/skills/zenmcp/widgets/zenmcp-install-checklist/widget.html +25 -0
- package/skills/zenmcp/widgets/zenmcp-model-picker/template.json +31 -0
- package/skills/zenmcp/widgets/zenmcp-model-picker/widget.html +28 -0
- package/skills/zenmcp/widgets/zenmcp-spend-confirm/template.json +181 -0
- package/skills/zenmcp/widgets/zenmcp-spend-confirm/widget.html +85 -0
package/INSTALL.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
请按以下七步执行。涉及安装缺失依赖时先征得用户同意;平台 Key 不得在对话或日志中回显明文。
|
|
4
4
|
|
|
5
|
+
## 交互要求
|
|
6
|
+
|
|
7
|
+
- 向用户展示五步清单并随完成情况更新:环境检查 → 安装 → 平台 Key → 客户端配置 → 验证(完成项标记为已完成)。
|
|
8
|
+
- 缺失依赖只合并询问一次,列出所有缺项,提供「全部安装 / 我自行安装」两个选项;使用客户端提供的选项式提问工具(如有)。
|
|
9
|
+
- 将 `zenmcp-doctor` 输出整理成「通过 / 缺失」清单,不直接展示原始 JSON;配置变量状态只说明是否配置,不展示值。
|
|
10
|
+
- Key 不进入聊天:可以先写带占位符的配置并告知用户粘贴位置,给用户在自己终端运行的命令,或使用客户端 MCP 表单;不得要求用户把 Key 发给 Agent。
|
|
11
|
+
- `account_status` 成功后原样展示其「可以这样说」欢迎块;有效可用积分为 0 时,引导前往 https://api.zenaigc.com 充值或调整 Key 限额。
|
|
12
|
+
|
|
13
|
+
| 异常 | 下一步 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| 命令找不到 | 按第 5 步改用命令或 Node 的绝对路径;Windows 先检查 `zenmcp.cmd`。 |
|
|
16
|
+
| `token_missing` / `invalid_credential` | 按第 4–5 步在账户页创建 Key,填入客户端配置 `env.ZENMCP_TOKEN` 后重新加载;不要在聊天中粘贴。 |
|
|
17
|
+
| 网络失败 | 检查网络连接及客户端能否访问 https://api.zenaigc.com,恢复后重试只读账户查询。 |
|
|
18
|
+
|
|
5
19
|
## 1. 检查本机环境
|
|
6
20
|
|
|
7
21
|
运行 `node -v`,确认 Node.js 版本 ≥ 22;运行 `ffmpeg -version`、`ffprobe -version`,并检查 Google Chrome 已安装且可启动。
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** 固定展示文案:外部错误原文脱敏之后才可附加,不能插入外部详情。 */
|
|
2
|
+
export const ACCOUNT_URL = 'https://api.zenaigc.com';
|
|
3
|
+
export const POLL_AFTER_SECONDS = 15;
|
|
4
|
+
// 展示阈值暂定,仅提醒,不参与预算或执行判断。
|
|
5
|
+
export const LARGE_AMOUNT_CREDITS = 100;
|
|
6
|
+
export const LARGE_BALANCE_RATIO = 0.3;
|
|
7
|
+
const keySetup = `请引导用户前往 ${ACCOUNT_URL} 创建平台 Key,填入 MCP 客户端配置 env.ZENMCP_TOKEN 后重新加载客户端;不要让用户在聊天中粘贴 Key。`;
|
|
8
|
+
const sameDirectory = '请保留当前目录与原账户,等待后在同一目录继续调用 get_generation 或 get_job 查询扣费及任务状态。';
|
|
9
|
+
export const ERROR_GUIDANCE = {
|
|
10
|
+
token_missing: { message: '尚未配置平台 Key。', next: keySetup },
|
|
11
|
+
invalid_credential: { message: '平台 Key 无效或已失效。', next: keySetup },
|
|
12
|
+
insufficient_credits: { message: '账户可用积分不足。', next: `请引导用户前往 ${ACCOUNT_URL} 充值后,用 account_status 核实可用积分。` },
|
|
13
|
+
credential_limit_exceeded: { message: '平台 Key 的积分限额不足。', next: `请引导用户前往 ${ACCOUNT_URL} 调整 Key 限额后,用 account_status 核实额度。` },
|
|
14
|
+
unsupported_platform: { message: '暂不支持此分享平台。', next: '请用户提供抖音、小红书、B站、TikTok、Instagram 或 X 的完整分享链接。' },
|
|
15
|
+
post_unavailable: { message: '帖子可能已删除、设为私密或受地区限制。', next: '请用户提供可访问的链接或本地文件。' },
|
|
16
|
+
upstream_unavailable: { message: '上游服务暂时不可用。', next: '请等待后在原目录查询任务状态。' },
|
|
17
|
+
transcription_not_found: { message: '未找到识别任务。', next: '请核对原识别目录,并用相同参数调用 transcribe_media 续查。' },
|
|
18
|
+
audio_unrecognized: { message: '音频中未识别到有效语音。', next: '请用户提供语音清晰的音视频文件。' },
|
|
19
|
+
voice_not_found: { message: '未找到指定音色。', next: '请调用 list_voices 核对可用音色。' },
|
|
20
|
+
voice_limit_reached: { message: '音色数量已达账户上限。', next: '请调用 list_voices 选择已有音色。' },
|
|
21
|
+
voice_not_ready: { message: '音色尚未准备完成。', next: '请等待后调用 list_voices 查询音色状态。' },
|
|
22
|
+
invalid_request: { message: '请求内容不符合要求。', next: '请对照工具参数及 list_models 返回的目录修正输入。' },
|
|
23
|
+
validation_error: { message: '请求参数校验未通过。', next: '请对照工具参数及 list_models 返回的目录修正输入。' },
|
|
24
|
+
account_mismatch: { message: '当前账户与任务绑定账户不一致。', next: sameDirectory },
|
|
25
|
+
access_denied: { message: '当前平台 Key 没有此操作权限。', next: '请用户检查 MCP 配置中的平台 Key 权限后重新加载客户端。' },
|
|
26
|
+
capability_not_available: { message: '所选生成能力当前不可用。', next: '请免费调用 list_models,选择当前可用能力。' },
|
|
27
|
+
asset_not_found: { message: '云端素材不存在或已过期。', next: '请在原目录核对素材及任务状态。' },
|
|
28
|
+
generation_not_found: { message: '暂未查到生成任务,扣费结果仍需核实。', next: sameDirectory },
|
|
29
|
+
attempt_not_found: { message: '暂未查到付款尝试,扣费结果仍需核实。', next: sameDirectory },
|
|
30
|
+
pricing_changed: { message: '价格版本已变化,本次报价已失效。', next: '请调用 quote_generation 获取最新报价,并一次性请用户确认模型、参数、上传文件数和积分。' },
|
|
31
|
+
quote_changed: { message: '生成报价已变化。', next: '请调用 quote_generation 获取最新报价,并一次性请用户确认模型、参数、上传文件数和积分。' },
|
|
32
|
+
idempotency_key_reused: { message: '此请求标识已有记录。', next: sameDirectory },
|
|
33
|
+
rate_limited: { message: '请求已达到服务限额。', next: '请暂停调用,按返回的等待时间稍后续查;每日限额请次日再试。' },
|
|
34
|
+
queue_unavailable: { message: '生成队列暂时不可用。', next: '请等待后在原目录查询任务状态。' },
|
|
35
|
+
outcome_unknown: { message: '提交结果尚未确认,积分可能已预占。', next: sameDirectory },
|
|
36
|
+
cancel_rejected: { message: '当前任务无法取消。', next: sameDirectory },
|
|
37
|
+
authorization_pending: { message: '用户尚未完成设备授权。', next: '请等待用户完成授权后按返回间隔续查。' },
|
|
38
|
+
slow_down: { message: '授权查询过于频繁。', next: '请延长等待时间后继续查询原授权请求。' },
|
|
39
|
+
invalid_grant: { message: '设备授权已失效。', next: '请用户重新开始设备授权。' },
|
|
40
|
+
binding_not_found: { message: '未找到设备授权绑定。', next: '请用户重新开始设备授权。' },
|
|
41
|
+
binding_closed: { message: '设备授权绑定已关闭。', next: '请用户重新开始设备授权。' },
|
|
42
|
+
upload_consent_required: { message: '本地素材上传尚未获得用户同意,报价需要先上传。', next: '请只问一次「将上传 N 个本地文件(列出文件名)到云端用于报价和生成,同意吗?」;获同意后携带 consent_confirmed:true 报价,再展示积分确认卡。' },
|
|
43
|
+
quote_required: { message: '当前目录还没有有效报价。', next: '请先调用 quote_generation 获取免费报价。' },
|
|
44
|
+
request_digest_mismatch: { message: '当前请求与已确认的报价摘要不一致。', next: '请核对 quote_generation 返回的 requestDigest;模型、参数或授权有变化时重新报价并取得用户确认。' },
|
|
45
|
+
approved_budget_required: { message: '尚未提供用户明确批准的积分上限。', next: '请一次性展示模型、关键参数、上传文件数和积分,获批后传入 approvedCredits。' },
|
|
46
|
+
approval_below_quote: { message: '用户批准的积分低于报价。', next: '请展示当前报价并取得用户明确批准的足额积分上限。' },
|
|
47
|
+
retry_requires_approval: { message: '前次尝试已释放,重试需要用户重新批准。', next: '请先取得本次重试的明确积分批准,再携带 retryAfterRelease:true 在原目录执行。' },
|
|
48
|
+
generation_exists: { message: '当前目录已有另一份生成请求。', next: '原请求留在此目录,可用 get_generation 查询;新的请求请换一个新的空目录后调用 quote_generation。' },
|
|
49
|
+
generation_running: { message: '当前目录的生成仍在执行。', next: '请等待 poll_after_seconds 指定的秒数后,在同一目录调用 get_generation 查询。' },
|
|
50
|
+
catalog_required: { message: '尚未取得可用模型目录。', next: '请免费调用 list_models 重新读取目录。' },
|
|
51
|
+
catalog_param_required: { message: '缺少模型要求的参数。', next: '请查看 list_models 中该模型的必填参数,补齐后调用 quote_generation。' },
|
|
52
|
+
catalog_param_invalid: { message: '模型参数的类型、范围或选项不符合要求。', next: '请按 list_models 返回的参数定义修正后调用 quote_generation。' },
|
|
53
|
+
catalog_param_unavailable: { message: '请求包含模型不支持的参数。', next: '请按 list_models 返回的参数定义移除不支持的参数后调用 quote_generation。' },
|
|
54
|
+
catalog_slot_missing: { message: '缺少模型要求的输入素材。', next: '请按 list_models 返回的必填素材槽补齐本地文件,并在上传前取得同意。' },
|
|
55
|
+
catalog_slot_unavailable: { message: '请求包含模型不支持的素材槽。', next: '请按 list_models 返回的素材槽名称修正 inputs。' },
|
|
56
|
+
unsupported_slot_type: { message: '客户端暂不支持此素材槽类型。', next: '请调用 list_models 选择客户端支持输入类型的模型。' },
|
|
57
|
+
unsupported_input_format: { message: '本地素材格式不受支持。', next: '请将素材转换为目录支持的格式后再报价。' },
|
|
58
|
+
input_too_long: { message: '输入素材时长超过模型限制。', next: '请用户选择保留片段,使用 trim_media 截取后再报价。' },
|
|
59
|
+
input_too_large: { message: '输入文件大小超过模型限制。', next: '请压缩素材至 list_models 标注的大小限制内。' },
|
|
60
|
+
invalid_input: { message: '输入不是有效的媒体文件。', next: '请核对本地文件可读且媒体内容完整。' },
|
|
61
|
+
asset_not_ready: { message: '上传素材尚未处理完成。', next: '请稍后在原目录查询或继续原报价步骤。' },
|
|
62
|
+
token_in_input: { message: '输入中含有平台 Key 或其他凭据,已阻止发送。', next: '请从提示词和参数中移除凭据;平台 Key 仅放在 MCP 客户端配置 env.ZENMCP_TOKEN 中。' },
|
|
63
|
+
prior_payment_unresolved: { message: '已有付款尚未核实。', next: sameDirectory },
|
|
64
|
+
payment_mismatch: { message: '付款记录与生成结果不一致。', next: sameDirectory },
|
|
65
|
+
refund_pending: { message: '退款或积分释放尚未确认。', next: sameDirectory },
|
|
66
|
+
generation_failed: { message: '云端生成未能完成。', next: sameDirectory },
|
|
67
|
+
generation_cancelled: { message: '云端生成已取消。', next: sameDirectory },
|
|
68
|
+
generation_rejected: { message: '生成请求未被接受。', next: sameDirectory },
|
|
69
|
+
generation_unsettled: { message: '任务与扣费状态尚未确认。', next: sameDirectory },
|
|
70
|
+
upstream_failed: { message: '上游生成服务未能完成请求。', next: sameDirectory },
|
|
71
|
+
upstream_timeout: { message: '上游处理超时,结果仍需核实。', next: sameDirectory },
|
|
72
|
+
output_purged: { message: '生成文件已过期清理,费用已结算。', next: sameDirectory },
|
|
73
|
+
generation_account_mismatch: { message: '当前账户与原生成付款账户不一致。', next: sameDirectory },
|
|
74
|
+
account_lookup_failed: { message: '暂时无法核实当前账户。', next: sameDirectory },
|
|
75
|
+
generation_state_corrupt: { message: '本地生成记录不完整或不一致,已停止执行。', next: '请保留同一目录的记录并联系支持核实任务与扣费状态。' },
|
|
76
|
+
prompt_mismatch: { message: 'prompt 与 params.prompt 内容不一致。', next: '请统一提示词后再调用 quote_generation。' },
|
|
77
|
+
voice_id_mismatch: { message: 'voice_id 与 params.voice_id 不一致。', next: '请统一音色编号后再调用 quote_generation。' },
|
|
78
|
+
invalid_output: { message: '生成结果尚未成功保存为有效媒体文件。', next: '请保留同一目录查询原任务状态,核实输出与扣费记录。' },
|
|
79
|
+
unsupported_audio_format: { message: '客户端暂不支持此音频输出格式。', next: '请保留原目录核实任务状态;音频输出目前支持 MP3。' },
|
|
80
|
+
file_error: { message: '本地文件读取或写入失败。', next: '请检查当前目录和输入文件的路径、权限及剩余磁盘空间。' },
|
|
81
|
+
step_failed: { message: '步骤未能完成,外部详情已安全隐藏。', next: '请保留当前目录,查询任务状态并检查客户端日志中的安全错误信息。' },
|
|
82
|
+
};
|
|
83
|
+
export function errorGuidance(code) {
|
|
84
|
+
return Object.hasOwn(ERROR_GUIDANCE, code) ? ERROR_GUIDANCE[code] : ERROR_GUIDANCE.step_failed;
|
|
85
|
+
}
|
package/dist/src/mcp/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import { GatewayError, redact } from '../gateway/errors.js';
|
|
|
5
5
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
6
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
7
7
|
import { z } from 'zod';
|
|
8
|
+
import { basename } from 'node:path';
|
|
8
9
|
import { jobSchema, assetSchema } from '../core/index.js';
|
|
9
10
|
import { CloudGateway, scrub } from '../gateway/index.js';
|
|
10
11
|
import { PopTitleRenderer } from '../effects/index.js';
|
|
@@ -12,7 +13,9 @@ import { Engine, analyzeReference, draftJob, safeError } from '../engine/steps.j
|
|
|
12
13
|
import { DirectGeneration } from '../engine/direct.js';
|
|
13
14
|
import { SpeechTools, transcribeInputSchema, cloneInputSchema } from '../speech/tools.js';
|
|
14
15
|
import { trimMedia } from '../acquire/trim.js';
|
|
16
|
+
import { ACCOUNT_URL, ERROR_GUIDANCE, POLL_AFTER_SECONDS, LARGE_AMOUNT_CREDITS, LARGE_BALANCE_RATIO, errorGuidance } from './guidance.js';
|
|
15
17
|
export const DEFAULT_BASE_URL = 'https://api.zenaigc.com/api/v1';
|
|
18
|
+
export const CLIENT_VERSION = '0.1.4';
|
|
16
19
|
const inputSchema = z.object({
|
|
17
20
|
job: jobSchema, reference: z.string().min(1),
|
|
18
21
|
output: z.object({ duration_seconds: z.number().int(), resolution: z.enum(['480P', '720P', '1080P']), ratio: z.string(), seed: z.number().int().optional() }),
|
|
@@ -21,16 +24,51 @@ const inputSchema = z.object({
|
|
|
21
24
|
function response(data) {
|
|
22
25
|
const result = data;
|
|
23
26
|
const markdown = typeof result.markdown === 'string' ? result.markdown : `\`\`\`json\n${JSON.stringify(data, null, 2)}\n\`\`\``;
|
|
24
|
-
return { content: [{ type: 'text', text: markdown }], structuredContent: { ...data, markdown } };
|
|
27
|
+
return { content: [{ type: 'text', text: markdown }, ...(typeof result.next_action === 'string' ? [{ type: 'text', text: `下一步:${result.next_action}` }] : [])], structuredContent: { ...data, markdown } };
|
|
28
|
+
}
|
|
29
|
+
function effectiveAvailableCredits(me) {
|
|
30
|
+
return Math.min(me.credits_available, ...(me.daily_credit_limit === null ? [] : [Math.max(0, me.daily_credit_limit - me.used_today)]), ...(me.total_credit_limit === null ? [] : [Math.max(0, me.total_credit_limit - me.used_total)]));
|
|
31
|
+
}
|
|
32
|
+
const GETTING_STARTED = {
|
|
33
|
+
examples: ['生成一张雨后街头的图片', '用这个链接复刻一段短视频', '把这段录音转成文字'],
|
|
34
|
+
billing_rule: '报价免费,确认后才扣积分;失败退款以任务查询结果为准。',
|
|
35
|
+
};
|
|
36
|
+
function refundText(state) {
|
|
37
|
+
switch (state) {
|
|
38
|
+
case 'refunded': return '积分已退回,预算已释放。';
|
|
39
|
+
case 'pending': return '退款处理中,尚未确认退回,请保留同一目录续查。';
|
|
40
|
+
case 'not_refunded': return '当前记录为未退款;请保留同一目录核实。';
|
|
41
|
+
case 'none': return '当前记录未显示退款,请保留同一目录核实。';
|
|
42
|
+
default: return '退款状态尚未确认,请保留同一目录续查。';
|
|
43
|
+
}
|
|
25
44
|
}
|
|
26
45
|
function formatGenerationText(result) {
|
|
27
|
-
if (!result.charge_notice
|
|
46
|
+
if (!result.charge_notice)
|
|
28
47
|
return result.markdown;
|
|
29
|
-
return `${result.markdown}\n\n${result.charge_notice}
|
|
48
|
+
return `${result.markdown}\n\n${result.charge_notice}:预算已保留。${errorGuidance('outcome_unknown').next}`;
|
|
49
|
+
}
|
|
50
|
+
function pollHint(tool) {
|
|
51
|
+
return `请等待 ${POLL_AFTER_SECONDS} 秒后,在同一目录调用 ${tool} 查询;请勿重复提交。`;
|
|
52
|
+
}
|
|
53
|
+
function outputHint(file) {
|
|
54
|
+
return `输出文件:${file}\n请使用当前客户端提供的媒体展示能力向用户展示;若不支持,请提供此文件路径。`;
|
|
30
55
|
}
|
|
31
56
|
export async function failure(error, tokens) {
|
|
32
57
|
const secret = await tokens.token().catch(() => '');
|
|
33
|
-
|
|
58
|
+
const sanitized = redact(safeError(error, secret), secret);
|
|
59
|
+
const leadingCode = (text) => text.match(/^([a-z][a-z0-9_]*)(?=$|[^a-zA-Z0-9_])/)?.[1];
|
|
60
|
+
const raw = error instanceof GatewayError ? error.code : leadingCode(error instanceof Error ? error.message : '');
|
|
61
|
+
// A raw leading token counts as a code only if it is a known code or sanitizing kept the message (not the scheme of a hidden URL).
|
|
62
|
+
const candidate = raw && (error instanceof GatewayError || Object.hasOwn(ERROR_GUIDANCE, raw) || sanitized.startsWith(raw)) ? raw : undefined;
|
|
63
|
+
const safeCode = redact(candidate ?? leadingCode(sanitized) ?? 'step_failed', secret);
|
|
64
|
+
const code = redact(/^[a-z][a-z0-9_]*$/.test(safeCode) ? safeCode : 'step_failed', secret);
|
|
65
|
+
const guidance = errorGuidance(code);
|
|
66
|
+
// Codes without a table entry keep their own sanitized text; local errors keep their specific detail.
|
|
67
|
+
const known = Object.hasOwn(ERROR_GUIDANCE, code);
|
|
68
|
+
const message = known ? redact(guidance.message, secret) : sanitized;
|
|
69
|
+
const detail = known && !(error instanceof GatewayError) && code !== 'step_failed' && sanitized.startsWith(`${code}:`) ? `\n详情:${sanitized.slice(code.length + 1)}` : '';
|
|
70
|
+
const next_action = redact(guidance.next, secret);
|
|
71
|
+
return { isError: true, content: [{ type: 'text', text: `${known ? `${code}:${message}${detail}` : message}\n下一步:${next_action}` }], structuredContent: { code, message, next_action } };
|
|
34
72
|
}
|
|
35
73
|
const SERVER_INSTRUCTIONS = `Zenmcp tools are atomic. Combine them as follows.
|
|
36
74
|
0. Direct image/video generation
|
|
@@ -55,10 +93,17 @@ const SERVER_INSTRUCTIONS = `Zenmcp tools are atomic. Combine them as follows.
|
|
|
55
93
|
- share_link_unresolved: ask the user to copy the full link.
|
|
56
94
|
- unsupported_platform: list the six supported platforms.
|
|
57
95
|
- rate_limited: tell the user the daily limit is reached and to try again tomorrow.
|
|
58
|
-
- post_unavailable: the post was deleted, is private, or is region-locked
|
|
96
|
+
- post_unavailable: the post was deleted, is private, or is region-locked.
|
|
97
|
+
8. 展示与确认
|
|
98
|
+
- 参数从用户需求与目录默认值填入,不逐项询问;报价前仅将没有默认值的必填缺项合并问一次,其余参数在确认卡中展示和修改。
|
|
99
|
+
- 原样展示工具的 markdown 确认卡;每个付费步骤只发起一次合并确认。无本地文件时只确认积分卡;有本地文件时,先短问一次「将上传 N 个本地文件(文件名)到云端用于报价和生成,同意吗?」,获同意再报价,卡片的上传行只说明本次报价已上传的文件。
|
|
100
|
+
- 仅当用户对当前任务明确给出免再问的总额上限时,可在该额度内执行;每次结果报告已花及剩余额度。retryAfterRelease、音色授权、价格变化后的重新报价及 large:true 的单项始终另需明确批准。
|
|
101
|
+
- 平台 Key 仅写入 MCP 客户端配置 env.ZENMCP_TOKEN,绝不要求用户在聊天中提供 Key。若用户自行粘贴,不回显,写入客户端配置并建议立即在账户页撤销重建,因为原 Key 已留在聊天记录。
|
|
102
|
+
- 提交后只向用户说明一次正在运行、稍后可查询;按 poll_after_seconds 在同一目录轮询,不逐次播报,避免重复提交。扣费状态待确认时保留同一目录续查。
|
|
103
|
+
- 使用当前客户端提供的媒体展示能力展示输出;不支持时提供文件路径。`;
|
|
59
104
|
/** Background tasks live in this MCP process; state and attempts survive its restart. */
|
|
60
105
|
export function createServer(engine, socialOptions = {}, speechOptions = {}) {
|
|
61
|
-
const server = new McpServer({ name: 'zenmcp', version:
|
|
106
|
+
const server = new McpServer({ name: 'zenmcp', version: CLIENT_VERSION }, { instructions: SERVER_INSTRUCTIONS });
|
|
62
107
|
const active = new Map();
|
|
63
108
|
server.registerTool('fetch_social_post', {
|
|
64
109
|
description: '解析抖音/小红书/B站/TikTok/Instagram/X 分享口令或链接,下载视频或图集到本地目录,返回本地路径与标题/正文/话题。免费、限次;不分析内容。视频可直接交给 analyze_reference。',
|
|
@@ -81,15 +126,21 @@ export function createServer(engine, socialOptions = {}, speechOptions = {}) {
|
|
|
81
126
|
if (input)
|
|
82
127
|
await engine.create(directory, input);
|
|
83
128
|
const plan = await engine.plan(directory);
|
|
84
|
-
|
|
129
|
+
const data = plan.result?.data;
|
|
130
|
+
if (typeof data?.totalCredits !== 'number' || typeof data.retryReserveCredits !== 'number')
|
|
131
|
+
return response(plan);
|
|
132
|
+
return response({ ...plan, confirmation: { kind: 'budget', total_credits: data.totalCredits, retry_reserve_credits: data.retryReserveCredits },
|
|
133
|
+
markdown: `${'markdown' in plan ? plan.markdown : ''}\n\n最多扣 ${data.totalCredits} 积分,其中 ${data.retryReserveCredits} 为重试预留,未重试不扣。回复「确认」开始执行。`,
|
|
134
|
+
next_action: '原样展示计划与预算句并只确认一次;获用户批准后携带 approvedCredits 和 planDigest 调用 execute_job。',
|
|
135
|
+
});
|
|
85
136
|
});
|
|
86
|
-
server.registerTool('execute_job', { description: '
|
|
137
|
+
server.registerTool('execute_job', { description: '携带用户一次合并确认批准的积分上限(及可选的已确认计划摘要 planDigest),后台执行;按 poll_after_seconds 等待后在同一目录用 get_job 查询,勿重复提交。', inputSchema: { directory: z.string(), approvedCredits: z.number().int().nonnegative(), planDigest: z.string().min(1).optional() } }, async ({ directory, approvedCredits, planDigest }) => {
|
|
87
138
|
if (active.has(directory))
|
|
88
|
-
return response({ status: 'running', directory });
|
|
139
|
+
return response({ status: 'running', directory, poll_after_seconds: POLL_AFTER_SECONDS, markdown: `任务执行中。${pollHint('get_job')}` });
|
|
89
140
|
// Resolve locking and persisted status inside Engine; never swallow an unhandled rejection.
|
|
90
141
|
const work = engine.execute(directory, approvedCredits, planDigest).catch(() => undefined).finally(() => active.delete(directory));
|
|
91
142
|
active.set(directory, work);
|
|
92
|
-
return response({ status: 'accepted', directory, markdown: '
|
|
143
|
+
return response({ status: 'accepted', directory, poll_after_seconds: POLL_AFTER_SECONDS, markdown: `已接受后台执行。${pollHint('get_job')}` });
|
|
93
144
|
});
|
|
94
145
|
server.registerTool('get_job', { description: '查询落盘步骤、预算占用、报告 Markdown 与文件路径。', inputSchema: { directory: z.string() } }, async ({ directory }) => {
|
|
95
146
|
const job = await engine.get(directory);
|
|
@@ -98,7 +149,15 @@ export function createServer(engine, socialOptions = {}, speechOptions = {}) {
|
|
|
98
149
|
const statusLine = interrupted
|
|
99
150
|
? '任务状态:running(后台任务已中断,请使用 execute_job 在原目录续跑恢复)'
|
|
100
151
|
: `任务状态:${job.state.status}`;
|
|
101
|
-
|
|
152
|
+
const markdown = job.state.steps.report?.output?.data.markdown ?? `${statusLine}\n\n${JSON.stringify(job, null, 2)}`;
|
|
153
|
+
const file = job.state.steps.report?.output?.data.path ?? job.state.steps.export?.output?.data.path;
|
|
154
|
+
const running = job.state.status === 'running';
|
|
155
|
+
const chargeHint = String(markdown).includes('扣费状态待确认') || String(markdown).includes('退款待确认') ? `\n\n${errorGuidance('outcome_unknown').next}` : '';
|
|
156
|
+
const errorText = job.state.error ? `\n\n${(await failure(new Error(job.state.error), engine.tokens)).content[0].text}` : '';
|
|
157
|
+
return response({ ...job, background, interrupted,
|
|
158
|
+
...(running ? { poll_after_seconds: POLL_AFTER_SECONDS } : {}),
|
|
159
|
+
markdown: `${markdown}${errorText}${chargeHint}${running ? `\n\n${pollHint('get_job')}` : job.state.status === 'completed' && typeof file === 'string' ? `\n\n${outputHint(file)}` : ''}`,
|
|
160
|
+
});
|
|
102
161
|
});
|
|
103
162
|
server.registerTool('revise_job', { description: '按段与属性归类:conform/effects/mix 确定性重跑,new_seed 重跑全片;其他修改需用户决定。准备修改后用 execute_job 执行。', inputSchema: { directory: z.string(), segment: z.string(), attribute: z.string(), action: z.string(), approvedCredits: z.number().int().nonnegative().optional() } }, async ({ directory, ...request }) => response(await engine.revise(directory, request)));
|
|
104
163
|
server.registerTool('trim_media', {
|
|
@@ -114,34 +173,42 @@ export function createServer(engine, socialOptions = {}, speechOptions = {}) {
|
|
|
114
173
|
description: '查询当前账户可用积分、日限额与总限额占用情况(只读,不扣费)。',
|
|
115
174
|
inputSchema: {},
|
|
116
175
|
}, async () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
176
|
+
try {
|
|
177
|
+
const secret = await engine.tokens.token().catch(() => '');
|
|
178
|
+
const me = scrub(await engine.options.gateway.me(), secret);
|
|
179
|
+
const effectiveAvailable = effectiveAvailableCredits(me);
|
|
180
|
+
const note = me.daily_credit_limit === null
|
|
181
|
+
? '当前平台 Key 未设置日积分限额,建议在网站账户页为 Key 配置日限额以防超支。'
|
|
182
|
+
: '当前平台 Key 已启用日积分限额保护。';
|
|
183
|
+
const markdown = [
|
|
184
|
+
'# 账户额度状态',
|
|
185
|
+
'',
|
|
186
|
+
`- 可用积分:${me.credits_available}`,
|
|
187
|
+
`- 今日已用 / 日限额:${me.used_today} / ${me.daily_credit_limit ?? '未设置'}`,
|
|
188
|
+
`- 累计已用 / 总限额:${me.used_total} / ${me.total_credit_limit ?? '未设置'}`,
|
|
189
|
+
`- 当前单次可支配上限:${effectiveAvailable}`,
|
|
190
|
+
`- 说明:${note}`,
|
|
191
|
+
...(effectiveAvailable === 0 ? [`- 当前可支配积分为 0,请前往 ${ACCOUNT_URL} 充值或调整平台 Key 限额。`] : []),
|
|
192
|
+
`- 客户端版本:${CLIENT_VERSION}`,
|
|
193
|
+
'', '### 可以这样说', ...GETTING_STARTED.examples.map(example => `- ${example}`), '', GETTING_STARTED.billing_rule,
|
|
194
|
+
].join('\n');
|
|
195
|
+
return response({
|
|
196
|
+
credits_available: me.credits_available,
|
|
197
|
+
daily_credit_limit: me.daily_credit_limit,
|
|
198
|
+
used_today: me.used_today,
|
|
199
|
+
total_credit_limit: me.total_credit_limit,
|
|
200
|
+
used_total: me.used_total,
|
|
201
|
+
effective_available_credits: effectiveAvailable,
|
|
202
|
+
credential_kind: me.credential_kind,
|
|
203
|
+
client_version: CLIENT_VERSION,
|
|
204
|
+
getting_started: GETTING_STARTED,
|
|
205
|
+
note,
|
|
206
|
+
markdown,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
return failure(error, engine.tokens);
|
|
211
|
+
}
|
|
145
212
|
});
|
|
146
213
|
const direct = new DirectGeneration({ gateway: engine.options.gateway, tokens: engine.tokens, poll: engine.options.poll, download: engine.options.download });
|
|
147
214
|
const guarded = (fn) => async (input) => {
|
|
@@ -152,10 +219,83 @@ export function createServer(engine, socialOptions = {}, speechOptions = {}) {
|
|
|
152
219
|
return failure(error, engine.tokens);
|
|
153
220
|
}
|
|
154
221
|
};
|
|
155
|
-
server.registerTool('list_models', { description: '
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
222
|
+
server.registerTool('list_models', { description: '免费列出当前可用图片、视频与语音音频能力、必填参数及素材。选定后调用 quote_generation 免费报价。', inputSchema: { medium: z.enum(['image', 'video', 'audio']).optional() } }, guarded(async (i) => {
|
|
223
|
+
const result = await direct.listModels(i.medium);
|
|
224
|
+
const cell = (value) => value.replace(/\|/g, '\\|').replace(/[\r\n]+/g, ' ');
|
|
225
|
+
const rows = result.models.map(model => [model.id, model.medium, model.model,
|
|
226
|
+
model.assets.filter(a => a.required).map(a => `${a.key} (${a.type ?? '目录未标明类型'})`).join('、') || '无',
|
|
227
|
+
model.params.filter(p => p.required).map(p => `${p.key} (${p.type}${p.options?.length ? `;${p.options.map(o => o.value).join('/')}` : ''})`).join('、') || '无',
|
|
228
|
+
].map(cell).join(' | '));
|
|
229
|
+
return { ...result, markdown: ['| 能力 id | 媒介 | 模型 | 必填素材 | 必填参数 |', '| --- | --- | --- | --- | --- |', ...rows.map(row => `| ${row} |`), '', '下一步:选择能力并调用 quote_generation 免费报价;本地文件上传前须取得用户同意。'].join('\n') };
|
|
230
|
+
}));
|
|
231
|
+
server.registerTool('quote_generation', { description: '免费报价,不提交生成;会上传本地素材,须先取得上传同意。报价后一次性展示模型、关键参数、上传文件数和积分,取得明确批准后携带 requestDigest 调用 run_generation。', inputSchema: { directory: z.string(), capability: z.string(), prompt: z.string().optional(), voice_id: z.string().min(1).optional(), voice_authorized: z.boolean().optional(), params: z.record(z.string(), z.union([z.string(), z.number(), z.boolean()])).optional(), inputs: z.record(z.string(), z.string()).optional(), consent_confirmed: z.boolean().optional() } }, guarded(async (i) => {
|
|
232
|
+
const result = await direct.quote(i);
|
|
233
|
+
// Only read presentation metadata here; the engine remains the execution authority.
|
|
234
|
+
const [{ request }, catalog, me] = await Promise.all([
|
|
235
|
+
direct.get({ directory: i.directory }),
|
|
236
|
+
engine.options.gateway.catalog().catch(() => null),
|
|
237
|
+
engine.options.gateway.me().catch(() => null),
|
|
238
|
+
]);
|
|
239
|
+
const model = catalog?.modified ? catalog.catalog.capabilities.find(c => c.id === request.capability) : undefined;
|
|
240
|
+
const params = Object.entries(request.params).filter(([key]) => key !== 'prompt').map(([key, value]) => {
|
|
241
|
+
const spec = model?.params.find(p => p.key === key);
|
|
242
|
+
return { key, label: spec?.label ?? key, value: spec?.options?.find(o => o.value === value)?.label ?? (typeof value === 'boolean' ? value ? '开启' : '关闭' : value) };
|
|
243
|
+
});
|
|
244
|
+
const prompt = String(request.params.prompt ?? '');
|
|
245
|
+
const preview = [...prompt].slice(0, 120).join('') + ([...prompt].length > 120 ? '…' : '');
|
|
246
|
+
const uploads = Object.values(i.inputs ?? {}).map(path => basename(path.replace(/\\/g, '/')));
|
|
247
|
+
const balance = me?.credits_available ?? null;
|
|
248
|
+
const credits = result.price_credits;
|
|
249
|
+
const sufficient = me ? credits <= effectiveAvailableCredits(me) : null;
|
|
250
|
+
const large = credits >= LARGE_AMOUNT_CREDITS || (balance !== null && credits > balance * LARGE_BALANCE_RATIO);
|
|
251
|
+
const confirmation = { kind: 'spend', credits, balance_before: balance, balance_after: balance === null ? null : balance - credits, sufficient, large, params, uploads, prompt_preview: preview };
|
|
252
|
+
const markdown = [
|
|
253
|
+
'### 生成确认', `- 模型:${model?.name ?? request.capability}(${request.capability})`,
|
|
254
|
+
`- 参数:${params.length ? params.map(p => `${p.label}=${p.value}`).join(' · ') : '无额外参数'}`,
|
|
255
|
+
...(preview ? [`- 提示词:${preview}`] : []),
|
|
256
|
+
...(uploads.length ? [`- 上传:本次报价已上传 ${uploads.length} 个本地文件(${uploads.join('、')})`] : []),
|
|
257
|
+
`- 费用:${credits} 积分${balance === null ? '' : `(余额 ${balance} → ${balance - credits})`}`,
|
|
258
|
+
...(large && sufficient !== false ? ['本次金额较大,请核对后再确认。'] : []),
|
|
259
|
+
sufficient === false ? `当前有效可用积分不足(${effectiveAvailableCredits(me)} 积分),请前往 ${ACCOUNT_URL} 充值或调整平台 Key 限额后再查询额度。`
|
|
260
|
+
: '回复「确认」开始生成;要改参数或换模型直接说。',
|
|
261
|
+
GETTING_STARTED.billing_rule,
|
|
262
|
+
].join('\n');
|
|
263
|
+
const next_action = sufficient === false ? `请展示卡片并引导用户前往 ${ACCOUNT_URL} 补足额度后调用 account_status 核实;现在不要请求积分批准或执行。`
|
|
264
|
+
: `请原样展示 markdown 卡片,只确认一次;获批准后调用 run_generation,approvedCredits=${credits},requestDigest=${result.requestDigest}。有当前任务明确的免再问预算且非 large 时可在余额度内执行;重试、音色授权及价格变化须另获批准。`;
|
|
265
|
+
const secret = await engine.tokens.token().catch(() => '');
|
|
266
|
+
return scrub({ ...result, confirmation, markdown, next_action }, secret);
|
|
267
|
+
}));
|
|
268
|
+
server.registerTool('run_generation', { description: '携带用户一次合并确认明确批准的积分与 requestDigest,后台执行或恢复同一付款尝试。接受后按 poll_after_seconds 等待并在同一目录用 get_generation 查询,勿重复提交。释放后重试需用户重新批准。', inputSchema: { directory: z.string(), approvedCredits: z.number().int().nonnegative(), requestDigest: z.string(), retryAfterRelease: z.boolean().optional(), voice_id: z.string().min(1).optional(), voice_authorized: z.boolean().optional() } }, guarded(async (i) => {
|
|
269
|
+
const result = await direct.run(i);
|
|
270
|
+
if (result.status === 'completed' && result.output)
|
|
271
|
+
return { ...result, markdown: outputHint(result.output.file) };
|
|
272
|
+
return { ...result, poll_after_seconds: POLL_AFTER_SECONDS, markdown: `已接受后台生成。${pollHint('get_generation')}` };
|
|
273
|
+
}));
|
|
274
|
+
server.registerTool('get_generation', { description: '只读查询直通生成状态、账单摘要与本地输出。运行中按 poll_after_seconds 等待续查;完成后用客户端媒体能力展示输出文件,不支持时提供路径。', inputSchema: { directory: z.string() } }, guarded(async (i) => {
|
|
275
|
+
const result = await direct.get(i);
|
|
276
|
+
const running = result.status === 'running' || result.status === 'awaiting_cloud';
|
|
277
|
+
const attempt = result.attempts.at(-1);
|
|
278
|
+
if (result.status === 'completed') {
|
|
279
|
+
const charged = result.attempts.filter(a => a.state === 'completed').at(-1)?.charged_credits ?? null;
|
|
280
|
+
const suggestions = ['再生成一个版本', '调整参数后生成'];
|
|
281
|
+
return { ...result, result_summary: { status: 'completed', charged_credits: charged, output: result.output ?? null, suggestions },
|
|
282
|
+
markdown: [`已完成 · 实扣 ${charged ?? '待确认'} 积分`, ...(result.output ? [`输出文件:${result.output.file}`] : ['输出文件尚未就绪,请保留原目录续查。']), `接下来可以:${suggestions.join(';')}。`].join('\n\n'),
|
|
283
|
+
next_action: `${result.output ? outputHint(result.output.file) : '请保留同一目录核实输出。'} 若用户给过当前任务的总预算,报告已花及剩余额度。`,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
if (result.status === 'failed') {
|
|
287
|
+
const detail = (await failure(new Error(attempt?.rejected_code ?? result.error ?? 'step_failed'), engine.tokens)).structuredContent;
|
|
288
|
+
const status = attempt?.status === 'cancelled' ? 'cancelled' : 'failed';
|
|
289
|
+
const refund = refundText(attempt?.refund_state);
|
|
290
|
+
return { ...result, result_summary: { status, reason: detail.message, refund_state: attempt?.refund_state ?? 'unknown', refund_message: refund },
|
|
291
|
+
markdown: `${status === 'cancelled' ? '生成已取消' : '生成未完成'}:${detail.message}\n\n${refund}${result.charge_notice ? `\n\n${result.charge_notice}:预算已保留。${errorGuidance('outcome_unknown').next}` : ''}`,
|
|
292
|
+
next_action: result.charge_notice ? errorGuidance('outcome_unknown').next : detail.next_action,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
return { ...result, ...(running ? { poll_after_seconds: POLL_AFTER_SECONDS } : {}),
|
|
296
|
+
markdown: [formatGenerationText(result), ...(running ? [pollHint('get_generation')] : [])].join('\n\n'),
|
|
297
|
+
};
|
|
298
|
+
}));
|
|
159
299
|
const speech = new SpeechTools(engine.options.gateway, speechOptions);
|
|
160
300
|
server.registerTool('transcribe_media', {
|
|
161
301
|
description: '识别本地音频或视频中的语音,上传前请取得用户同意。免费、限次;提取为 16kHz 单声道 MP3(≤100MB、≤30分钟),返回全文、毫秒时间戳与分句并保存 transcript.json。output 可为目录或文件,默认媒体同目录;等待超时后使用相同参数续查。',
|
|
@@ -166,6 +306,13 @@ export function createServer(engine, socialOptions = {}, speechOptions = {}) {
|
|
|
166
306
|
inputSchema: cloneInputSchema.shape,
|
|
167
307
|
}, guarded(input => speech.clone(input)));
|
|
168
308
|
server.registerTool('list_voices', { description: '查询当前账户复刻音色及 training、ready、active、failed、expired 状态;不启用、不收费。', inputSchema: {} }, guarded(() => speech.list()));
|
|
309
|
+
const prompts = [
|
|
310
|
+
{ name: 'generate_media', title: '生成图片或视频', text: '请帮我生成图片或视频:先 list_models,再 quote_generation 免费报价。本地素材上传前取得同意;一次性确认模型、关键参数、上传文件数及积分后,携带 requestDigest 调用 run_generation;按 poll_after_seconds 等待后在同一目录 get_generation,并展示输出。' },
|
|
311
|
+
{ name: 'replicate_video', title: '复刻短视频', text: '请复刻我提供的短视频:链接先 fetch_social_post,本地文件直接 analyze_reference;必要时选段并 trim_media。展示素材并确认最终属性后 import_assets,再 plan_job;一次合并确认模型、关键参数、上传文件数及积分后 execute_job,按 poll_after_seconds 在同一目录 get_job,展示输出。' },
|
|
312
|
+
{ name: 'check_setup', title: '检查安装与账户', text: `请检查 Zenmcp 安装和账户:环境异常时运行 zenmcp-doctor,随后 account_status 查询积分与客户端版本。缺少或无效的 Key 请引导用户前往 ${ACCOUNT_URL} 创建,写入 MCP 客户端配置 env.ZENMCP_TOKEN 后重新加载;绝不在聊天中索取 Key。` },
|
|
313
|
+
];
|
|
314
|
+
for (const prompt of prompts)
|
|
315
|
+
server.registerPrompt(prompt.name, { title: prompt.title, description: prompt.title }, async () => ({ messages: [{ role: 'user', content: { type: 'text', text: prompt.text } }] }));
|
|
169
316
|
return server;
|
|
170
317
|
}
|
|
171
318
|
export function createEngine(baseUrl = DEFAULT_BASE_URL, tokens) {
|
|
@@ -174,7 +321,7 @@ export function createEngine(baseUrl = DEFAULT_BASE_URL, tokens) {
|
|
|
174
321
|
const provider = tokens ?? { token: async () => {
|
|
175
322
|
const value = capturedToken ?? process.env.ZENMCP_TOKEN;
|
|
176
323
|
if (!value)
|
|
177
|
-
throw new Error('
|
|
324
|
+
throw new Error('token_missing');
|
|
178
325
|
return value;
|
|
179
326
|
} };
|
|
180
327
|
return new Engine({ effects: job => new PopTitleRenderer(job), gateway: new CloudGateway({ baseUrl, tokens: provider }), tokens: provider, catalogLabel: '云端 catalog(仅运行工具时读取;Wan 可用性以返回目录为准)' });
|
package/package.json
CHANGED
package/skills/zenmcp/SKILL.md
CHANGED
|
@@ -19,6 +19,28 @@ description: 用户需要生图、生视频、复刻短视频、录音识别、
|
|
|
19
19
|
- 标准语音合成:`list_models` → 选择 `doubao-seed-tts-2.0` → `quote_generation` → 用户批准积分 → `run_generation` → `get_generation`。音色训练与复刻暂不开放。
|
|
20
20
|
- 额度查询:用只读工具 `account_status` 查询。
|
|
21
21
|
|
|
22
|
+
## 展示与确认
|
|
23
|
+
|
|
24
|
+
- 参数从用户需求和目录默认值填入,不逐项询问;报价前只将没有默认值的必填缺项合并问一次,其余参数在确认卡中展示并按用户要求修改。
|
|
25
|
+
- 原样展示工具返回的 `markdown` 卡片,按 `next_action` 执行。无本地文件时,仅确认一次模型、参数和积分卡;有本地文件时,先短问一次「将上传 N 个本地文件(文件名)到云端用于报价和生成,同意吗?」,获同意再报价。卡片中的上传行说明本次报价已上传的文件,不再询问上传。
|
|
26
|
+
- 每个付费步骤须获得用户批准。只有用户对当前任务明确给出免再问的总额上限时,才可在额度内执行;每次结果报告累计已花及剩余额度。该预算不覆盖 `retryAfterRelease`、音色授权、价格变化后的重新报价或 `confirmation.large:true` 的单项,这些始终须另获明确批准。
|
|
27
|
+
- 平台 Key 只放在 MCP 客户端配置 `env.ZENMCP_TOKEN` 中,配置后重新加载客户端;绝不让用户在聊天中粘贴 Key。缺失、失效或需充值时,引导用户前往 https://api.zenaigc.com。若用户自行粘贴,不回显,将它写入客户端配置,并建议在账户页立即撤销重建,因为原 Key 已留在聊天记录。
|
|
28
|
+
- 提交后只向用户说明一次正在运行、稍后可以查询;按 `poll_after_seconds` 在同一目录调用 `get_generation` / `get_job` 轮询,不逐次播报。扣费或退款待确认时,保留原目录和原账户续查,不重新报价或提交。
|
|
29
|
+
- 完成后按实际账单报告实扣积分,用客户端媒体能力展示输出,给出再生成或改参数两个建议。失败时只按工具明确的退款状态说明,不提前承诺已退回。其他客户端可使用 Markdown 图片或提供文件路径。
|
|
30
|
+
|
|
31
|
+
### SuperOne(仅当会话中存在相应工具时适用)
|
|
32
|
+
|
|
33
|
+
- **卡片模板**:本 Skill 目录 `widgets/` 下有 `zenmcp-spend-confirm`、`zenmcp-budget-confirm`、`zenmcp-model-picker`、`zenmcp-account`、`zenmcp-install-checklist`。有 `widget_show` 时用卡片承载对应确认;卡片未承载的工具说明不得省略:
|
|
34
|
+
- `quote_generation` 后用 `zenmcp-spend-confirm`,data 为 `{ confirmation, requestDigest, directory, capability, model_label, param_spec, account_url: "https://api.zenaigc.com" }`;`param_spec` 取 `list_models` 中该能力的参数规格,可省略。余额不足时仍展示卡片,不请求批准。
|
|
35
|
+
- `plan_job` 后先原样展示返回的完整 `markdown`(分段、素材角色与属性、输出规格、预算明细及警告),随后用 `zenmcp-budget-confirm`,data 为 `{ confirmation, planDigest, directory, account_url }`。两者合为一次确认,不额外再问;当前 `confirmation` 只有总预算与重试预留,不得从设计示例编造分段、素材或余额。
|
|
36
|
+
- `list_models` 用 `zenmcp-model-picker`,data 为 `{ medium, models: [{ capability, label, medium, price_hint, highlights }] }`;`account_status` 用 `zenmcp-account`,data 为其结果加 `account_url`;安装与配置引导用 `zenmcp-install-checklist`,Key 不进卡片。
|
|
37
|
+
- **取用方式**:每个会话先调用一次 `widget_list_templates`。列表里有以上 id(用户手动保存的可能带后缀,按 `zenmcp-` 前缀匹配)就用 `widget_show({ template, data })`。没有时,征得用户同意后把 `widgets/<id>/` 整个目录一次性复制到 SuperOne 用户模板目录(stable 为 `~/.superone/widget/`,alpha 为 `~/.superone/alpha/widget/`),再查一次列表。仍然没有(Agent 与 SuperOne 桌面不在同一台机器)时,读取 `widgets/<id>/widget.html` 原文作为 `widget_code` 并照样传 `data`,不得改写 HTML。
|
|
38
|
+
- **按钮消息即用户答复**:卡片按钮以用户身份发送固定文字。收到“确认付费生成:…批准 N 积分。requestDigest=…,directory=…”或“确认执行复刻任务,批准 N 积分。planDigest=…,directory=…”才算批准,按其中的积分和摘要调用付费工具。“把参数修改为…然后重新报价”:重新 `quote_generation` 并展示新卡。“取消这次付费,不要扣费。”:结束,不调用付费工具。“本次任务 N 积分内不用再逐次确认…”:按上文免再问预算处理。未收到确认前不得调用付费工具。
|
|
39
|
+
- **结果展示**:生成图片用 `@native/image-gallery`,视频用 `@native/video-gallery`,data 为 `{ images | videos: [{ path }], prompt, params: { 模型, 关键参数, 实扣积分 }, warnings }`;实扣积分取 `result_summary.charged_credits`。复刻视频在 `warnings` 中加入“服装与身份需人工验收”。报告和多份文件用 `@native/files-previewer`。失败时不展示图集,按 `result_summary.reason` 与 `refund_message` 说明。
|
|
40
|
+
- **远程会话**:若展示时报“文件不存在”(Agent 在服务器上),把输出文件复制到 `$SUPERONE_SESSION_DIR/agent/<生成目录名>/`,用新路径展示;原生成目录保留不动,续查依赖它。
|
|
41
|
+
- 有客户端提供的选项式提问工具时,用它呈现模型、参数和片段等选择。
|
|
42
|
+
- 工具不存在时,按通用方式展示 Markdown 图片或文件路径,不调用不存在的工具。
|
|
43
|
+
|
|
22
44
|
## 禁令与错误处理
|
|
23
45
|
|
|
24
46
|
- 不得自动批准积分;`plan_job`、`quote_generation` 只报价,付费执行须获得用户明确批准。
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"credits_available": 200,
|
|
3
|
+
"daily_credit_limit": 100,
|
|
4
|
+
"used_today": 24,
|
|
5
|
+
"effective_available_credits": 76,
|
|
6
|
+
"account_url": "https://example.com/account",
|
|
7
|
+
"getting_started": {
|
|
8
|
+
"examples": [
|
|
9
|
+
"生成一张咖啡店海报",
|
|
10
|
+
"把这张参考图做成 5 秒视频",
|
|
11
|
+
"查看适合商品图的模型"
|
|
12
|
+
],
|
|
13
|
+
"billing_rule": "生成前先报价,经确认后扣除对应积分。"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"confirmation": {
|
|
3
|
+
"kind": "budget",
|
|
4
|
+
"total_credits": 72,
|
|
5
|
+
"retry_reserve_credits": 12,
|
|
6
|
+
"balance_before": 10,
|
|
7
|
+
"balance_after": -62,
|
|
8
|
+
"sufficient": false,
|
|
9
|
+
"large": true,
|
|
10
|
+
"segments": [
|
|
11
|
+
{
|
|
12
|
+
"id": "intro",
|
|
13
|
+
"label": "开场",
|
|
14
|
+
"credits": 24
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "main",
|
|
18
|
+
"label": "主体",
|
|
19
|
+
"credits": 36
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"assets": [
|
|
23
|
+
"参考片.mp4",
|
|
24
|
+
"商品.png"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"planDigest": "plan-example-001",
|
|
28
|
+
"directory": "/tmp/复刻任务",
|
|
29
|
+
"account_url": "https://example.com/account"
|
|
30
|
+
}
|