@zenaigc/zenmcp 0.1.1 → 0.1.2

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.
@@ -89,7 +89,10 @@ export const pricingSchema = z.discriminatedUnion("mode", [
89
89
  z.object({
90
90
  mode: z.literal("tier"),
91
91
  tier_param: z.string(),
92
- tiers: z.array(z.object({ value: z.string(), credits: int })),
92
+ tiers: z.array(z.object({
93
+ value: z.string(), credits: int,
94
+ by_resolution: z.record(z.string(), int).optional(),
95
+ })),
93
96
  }),
94
97
  z.object({
95
98
  mode: z.literal("char_tier"),
@@ -250,21 +253,26 @@ export const errorRules = {
250
253
  unsupported_platform: [422, "ambiguous", "ambiguous", "not_applicable", ["social"]],
251
254
  post_unavailable: [404, "ambiguous", "ambiguous", "not_applicable", ["social"]],
252
255
  upstream_unavailable: [502, "ambiguous", "ambiguous", "not_applicable", ["social"]],
253
- invalid_request: [422, "rejected", "ambiguous", "no_new_hold", ["submit", "price", "upload", "device"]],
254
- validation_error: [422, "rejected", "ambiguous", "no_new_hold", ["social", "submit", "lookup", "price", "upload", "device"]],
255
- invalid_credential: [401, "rejected", "ambiguous", "no_new_hold", ["social", "submit", "price", "read", "lookup", "cancel", "upload"]],
256
+ transcription_not_found: [404, "ambiguous", "ambiguous", "not_applicable", ["transcription"]],
257
+ audio_unrecognized: [422, "ambiguous", "ambiguous", "not_applicable", ["transcription"]],
258
+ voice_not_found: [404, "ambiguous", "ambiguous", "not_applicable", ["voice"]],
259
+ voice_limit_reached: [409, "ambiguous", "ambiguous", "not_applicable", ["voice"]],
260
+ voice_not_ready: [409, "ambiguous", "ambiguous", "not_applicable", ["voice"]],
261
+ invalid_request: [422, "rejected", "ambiguous", "no_new_hold", ["submit", "price", "upload", "device", "transcription", "voice"]],
262
+ validation_error: [422, "rejected", "ambiguous", "no_new_hold", ["social", "submit", "lookup", "price", "upload", "device", "transcription", "voice"]],
263
+ invalid_credential: [401, "rejected", "ambiguous", "no_new_hold", ["social", "submit", "price", "read", "lookup", "cancel", "upload", "transcription", "voice"]],
256
264
  account_mismatch: [403, "rejected", "ambiguous", "no_new_hold", ["submit", "lookup"]],
257
- access_denied: [403, "rejected", "ambiguous", "no_new_hold", ["submit", "price", "read", "lookup", "cancel", "upload"]],
265
+ access_denied: [403, "rejected", "ambiguous", "no_new_hold", ["submit", "price", "read", "lookup", "cancel", "upload", "transcription", "voice"]],
258
266
  capability_not_available: [404, "rejected", "ambiguous", "no_new_hold", ["submit", "price"]],
259
- asset_not_found: [404, "rejected", "ambiguous", "no_new_hold", ["submit", "price", "upload"]],
267
+ asset_not_found: [404, "rejected", "ambiguous", "no_new_hold", ["submit", "price", "upload", "transcription", "voice"]],
260
268
  generation_not_found: [404, "ambiguous", "ambiguous", "unknown", ["read", "cancel"]],
261
269
  attempt_not_found: [404, "ambiguous", "ambiguous", "unknown", ["lookup"]],
262
270
  credential_limit_exceeded: [402, "rejected", "rejected", "key_rejected", ["submit", "lookup"]],
263
271
  insufficient_credits: [402, "rejected", "rejected", "key_rejected", ["submit", "lookup"]],
264
272
  pricing_changed: [409, "rejected", "rejected", "key_rejected", ["submit", "lookup"]],
265
273
  quote_changed: [409, "rejected", "rejected", "key_rejected", ["submit", "lookup"]],
266
- idempotency_key_reused: [409, "ambiguous", "ambiguous", "original_unchanged", ["submit"]],
267
- rate_limited: [429, "retry", "retry", "no_new_hold", ["social", "submit", "price", "read", "lookup", "cancel", "upload", "device"], { first: "rejected", replay: "ambiguous" }],
274
+ idempotency_key_reused: [409, "ambiguous", "ambiguous", "original_unchanged", ["submit", "transcription", "voice"]],
275
+ rate_limited: [429, "retry", "retry", "no_new_hold", ["social", "submit", "price", "read", "lookup", "cancel", "upload", "device", "transcription", "voice"], { first: "rejected", replay: "ambiguous" }],
268
276
  queue_unavailable: [503, "queue_unavailable", "ambiguous", "transaction_rolled_back", ["submit"]],
269
277
  outcome_unknown: [503, "ambiguous", "ambiguous", "held", ["submit"]],
270
278
  cancel_rejected: [409, "ambiguous", "ambiguous", "original_unchanged", ["cancel"]],
@@ -332,3 +340,105 @@ export const socialPostSchema = z.object({
332
340
  if (t && t !== "muxed" && t !== "audio,video")
333
341
  ctx.addIssue({ code: "custom", message: "streams must be [muxed] or [video,audio]" });
334
342
  });
343
+ // ---- v1.3 additive: audio transcriptions & voices (jointly approved by Line 1 & Line 2) ----
344
+ export const transcriptionStatuses = ["queued", "running", "completed", "failed"];
345
+ export const transcriptionErrors = ["upstream_failed", "upstream_timeout", "audio_unrecognized", "result_purged"];
346
+ export const transcriptionCreateSchema = z.strictObject({
347
+ asset_id: uuid,
348
+ language: z.string().min(1).max(32).optional(),
349
+ speaker_info: z.boolean().optional(),
350
+ });
351
+ export const transcriptionWordSchema = z.object({
352
+ start_ms: int,
353
+ end_ms: int,
354
+ text: z.string(),
355
+ }).superRefine((w, ctx) => {
356
+ if (w.end_ms < w.start_ms)
357
+ ctx.addIssue({ code: "custom", message: "word end_ms before start_ms" });
358
+ });
359
+ export const transcriptionSegmentSchema = z.object({
360
+ start_ms: int,
361
+ end_ms: int,
362
+ text: z.string(),
363
+ speaker: z.string().nullable(),
364
+ words: z.array(transcriptionWordSchema),
365
+ }).superRefine((s, ctx) => {
366
+ if (s.end_ms < s.start_ms)
367
+ ctx.addIssue({ code: "custom", message: "segment end_ms before start_ms" });
368
+ for (let i = 0; i < s.words.length; i++) {
369
+ const w = s.words[i];
370
+ if (w.start_ms < s.start_ms || w.end_ms > s.end_ms) {
371
+ ctx.addIssue({ code: "custom", message: "word must fall within segment [start_ms, end_ms]" });
372
+ break;
373
+ }
374
+ if (i > 0 && w.start_ms < s.words[i - 1].start_ms) {
375
+ ctx.addIssue({ code: "custom", message: "words must be ordered by start_ms" });
376
+ break;
377
+ }
378
+ }
379
+ });
380
+ export const transcriptionResultSchema = z.object({
381
+ text: z.string(),
382
+ duration_ms: int,
383
+ segments: z.array(transcriptionSegmentSchema),
384
+ }).superRefine((r, ctx) => {
385
+ for (let i = 1; i < r.segments.length; i++) {
386
+ if (r.segments[i].start_ms < r.segments[i - 1].start_ms) {
387
+ ctx.addIssue({ code: "custom", message: "segments must be ordered by start_ms" });
388
+ break;
389
+ }
390
+ }
391
+ });
392
+ export const transcriptionSchema = z.object({
393
+ id: uuid,
394
+ asset_id: uuid,
395
+ status: z.enum(transcriptionStatuses),
396
+ language: z.string().nullable(),
397
+ created_at: z.iso.datetime(),
398
+ completed_at: z.iso.datetime().nullable(),
399
+ expires_at: z.iso.datetime(),
400
+ error: z.enum(transcriptionErrors).nullable(),
401
+ result: transcriptionResultSchema.nullable(),
402
+ }).superRefine((t, ctx) => {
403
+ if (t.status === "completed") {
404
+ if ((t.result === null) !== (t.error === "result_purged")) {
405
+ ctx.addIssue({ code: "custom", message: "completed transcription requires result or result_purged" });
406
+ }
407
+ if (t.error !== null && t.error !== "result_purged") {
408
+ ctx.addIssue({ code: "custom", message: "completed transcription cannot carry failure error" });
409
+ }
410
+ }
411
+ else {
412
+ if (t.result !== null)
413
+ ctx.addIssue({ code: "custom", message: "non-completed transcription cannot expose result" });
414
+ if (t.error === "result_purged")
415
+ ctx.addIssue({ code: "custom", message: "only completed transcription can be result_purged" });
416
+ if ((t.status === "queued" || t.status === "running") && t.error !== null) {
417
+ ctx.addIssue({ code: "custom", message: "active transcription cannot carry error" });
418
+ }
419
+ if (t.status === "failed" && (t.error === null || t.error === "result_purged")) {
420
+ ctx.addIssue({ code: "custom", message: "failed transcription requires failure error code" });
421
+ }
422
+ }
423
+ });
424
+ export const voiceStatuses = ["training", "ready", "active", "failed", "expired"];
425
+ export const voiceCreateSchema = z.strictObject({
426
+ name: z.string().min(1).max(64),
427
+ sample_asset_id: uuid,
428
+ consent_confirmed: z.literal(true),
429
+ });
430
+ export const voiceSchema = z.object({
431
+ id: uuid,
432
+ name: z.string().min(1).max(64),
433
+ status: z.enum(voiceStatuses),
434
+ created_at: z.iso.datetime(),
435
+ ready_at: z.iso.datetime().nullable(),
436
+ activated_at: z.iso.datetime().nullable(),
437
+ expires_at: z.iso.datetime().nullable(),
438
+ demo_url: z.url().nullable(),
439
+ consent_version: z.string().min(1),
440
+ error: z.string().nullable(),
441
+ });
442
+ export const voiceListSchema = z.object({
443
+ voices: z.array(voiceSchema),
444
+ });
File without changes
@@ -4,6 +4,7 @@ import { join } from 'node:path';
4
4
  import { randomUUID } from 'node:crypto';
5
5
  import { hostname } from 'node:os';
6
6
  import { z } from 'zod';
7
+ import { probeAudio } from '../speech/audio.js';
7
8
  import { sha256File, sha256String, isSafeId } from '../core/index.js';
8
9
  import { inspectImage } from '../assets/index.js';
9
10
  import { child, directory } from '../assets/files.js';
@@ -15,12 +16,12 @@ import { hash, safeError } from './steps.js';
15
16
  import { lockJob, readJson, writeJson } from './storage.js';
16
17
  import { download, fetchOutput, pollAttempt, refreshUnsettledRefunds, replayRequest, terminalError, uploadContentType } from './generate.js';
17
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() });
18
- const requestSchema = z.strictObject({ schema_version: z.literal(1), generation_id: z.guid(), request: z.strictObject({ capability: z.string(), medium: z.enum(['image', 'video']), 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() }) });
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() }) });
19
20
  const stateSchema = z.object({
20
21
  request_digest: z.string(), status: z.enum(['quoted', 'running', 'completed', 'failed']),
21
22
  approvedCredits: z.number().int().nonnegative().optional(), mode: z.enum(['R', 'N1', 'N2']).optional(),
22
23
  error: z.string().optional(), attempt: z.string().optional(),
23
- output: z.object({ file: z.string().regex(/^output\.(png|jpg|webp|mp4)$/), kind: z.enum(['image', 'video']), sha256: z.string().regex(/^[a-f0-9]{64}$/) }).optional(),
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(),
24
25
  });
25
26
  async function loadState(dir, currentDigest) {
26
27
  const raw = await optional(dir, 'state.json');
@@ -107,7 +108,7 @@ export async function validateEvidence(dir, req, gateway) {
107
108
  if (!state || state.request_digest !== req.request_digest)
108
109
  return corrupt();
109
110
  for (const a of records) {
110
- if (a.body.asset_id || a.body.capability !== req.request.capability || hash(a.body.params ?? {}) !== hash(req.request.params))
111
+ if ((a.body.voice_authorized ?? false) !== (req.request.voice_authorized ?? false) || a.body.asset_id || a.body.capability !== req.request.capability || hash(a.body.params ?? {}) !== hash(req.request.params))
111
112
  return corrupt();
112
113
  if (!bindings.submissions.some(s => hash(s.assets) === hash(a.body.assets ?? {})))
113
114
  return corrupt();
@@ -167,7 +168,7 @@ export class DirectGeneration {
167
168
  const c = await this.options.gateway.catalog();
168
169
  if (!c.modified)
169
170
  throw new Error('catalog_required');
170
- return { models: c.catalog.capabilities.filter(c => c.medium !== 'audio' && (!medium || c.medium === medium)) };
171
+ return { models: c.catalog.capabilities.filter(c => !medium || c.medium === medium) };
171
172
  }
172
173
  async request(dir) {
173
174
  let req;
@@ -208,7 +209,7 @@ export class DirectGeneration {
208
209
  }
209
210
  async quote(input) {
210
211
  const secret = await this.options.tokens.token();
211
- const raw = { capability: input.capability, prompt: input.prompt, params: input.params };
212
+ const raw = { capability: input.capability, prompt: input.prompt, params: input.params, voice_id: input.voice_id };
212
213
  if (JSON.stringify(scrub(raw, secret)) !== JSON.stringify(raw) || [input.prompt, ...Object.values(input.params ?? {})].some(v => typeof v === 'string' && /zk_(?:live|test)_[A-Za-z0-9_-]+|Bearer\s+\S+/i.test(v)))
213
214
  throw new Error('token_in_input');
214
215
  await mkdir(input.directory, { recursive: true });
@@ -224,11 +225,13 @@ export class DirectGeneration {
224
225
  if (!catalog.modified)
225
226
  throw new Error('catalog_required');
226
227
  const cap = catalog.catalog.capabilities.find(c => c.id === input.capability);
227
- if (!cap || cap.medium === 'audio')
228
+ if (!cap)
228
229
  throw new Error('capability_not_available');
229
- if (input.params?.prompt !== undefined && input.params.prompt !== input.prompt)
230
+ if (input.prompt !== undefined && input.params?.prompt !== undefined && input.params.prompt !== input.prompt)
230
231
  throw new Error('prompt_mismatch');
231
- const params = parameters(cap, { ...input.params, prompt: input.prompt });
232
+ if (input.voice_id !== undefined && input.params?.voice_id !== undefined && input.params.voice_id !== input.voice_id)
233
+ throw new Error('voice_id_mismatch');
234
+ const params = parameters(cap, { ...input.params, ...(input.prompt === undefined ? {} : { prompt: input.prompt }), ...(input.voice_id === undefined ? {} : { voice_id: input.voice_id }) });
232
235
  const supplied = Object.keys(input.inputs ?? {});
233
236
  for (const slot of supplied) {
234
237
  const s = cap.assets.find(s => s.key === slot);
@@ -296,7 +299,7 @@ export class DirectGeneration {
296
299
  await rm(tmp, { force: true });
297
300
  }
298
301
  }
299
- const request = { capability: cap.id, medium: cap.medium, params, inputs };
302
+ const request = { capability: cap.id, medium: cap.medium, params, inputs, ...(input.voice_authorized === undefined ? {} : { voice_authorized: input.voice_authorized }) };
300
303
  const digest = hash(request);
301
304
  if (attempts.length && digest !== existing.request_digest)
302
305
  throw new Error('generation_exists:请使用新目录。');
@@ -304,13 +307,13 @@ export class DirectGeneration {
304
307
  let assets = await this.uploads(dir, req);
305
308
  let quote;
306
309
  try {
307
- quote = await this.options.gateway.price({ capability: cap.id, params, assets });
310
+ quote = await this.options.gateway.price({ capability: cap.id, params, assets, ...(input.voice_authorized === undefined ? {} : { voice_authorized: input.voice_authorized }) });
308
311
  }
309
312
  catch (e) {
310
313
  if (!(e instanceof GatewayError) || e.code !== 'asset_not_found')
311
314
  throw e;
312
315
  assets = await this.uploads(dir, req, true);
313
- quote = await this.options.gateway.price({ capability: cap.id, params, assets });
316
+ quote = await this.options.gateway.price({ capability: cap.id, params, assets, ...(input.voice_authorized === undefined ? {} : { voice_authorized: input.voice_authorized }) });
314
317
  }
315
318
  req.quote = { price_credits: quote.price_credits, pricing_version: quote.pricing_version, quoted_at: new Date().toISOString() };
316
319
  await writeJson(dir, 'request.json', req);
@@ -334,11 +337,13 @@ export class DirectGeneration {
334
337
  await validateEvidence(dir, undefined, this.options.gateway);
335
338
  throw new Error('quote_required');
336
339
  }
340
+ if ((input.voice_id !== undefined && input.voice_id !== req.request.params.voice_id) || (input.voice_authorized !== undefined && input.voice_authorized !== req.request.voice_authorized))
341
+ throw new Error('request_digest_mismatch:音色或授权变更需要重新报价。');
337
342
  if (input.requestDigest !== req.request_digest)
338
343
  throw new Error('request_digest_mismatch');
339
344
  const attempts = await validateEvidence(dir, req, this.options.gateway);
340
345
  const state = await loadState(dir, attempts.length ? undefined : req.request_digest);
341
- if (state?.request_digest === req.request_digest && state.status === 'completed' && state.output && /^output\.(png|jpg|webp|mp4)$/.test(state.output.file)) {
346
+ if (state?.request_digest === req.request_digest && state.status === 'completed' && state.output && /^output\.(png|jpg|webp|mp4|mp3)$/.test(state.output.file)) {
342
347
  try {
343
348
  await verifyFile(join(dir, state.output.file), state.output.sha256);
344
349
  return { status: 'completed', output: { file: join(dir, state.output.file), kind: state.output.kind, sha256: state.output.sha256 } };
@@ -420,7 +425,7 @@ export class DirectGeneration {
420
425
  const before = await store.list(req.generation_id);
421
426
  assertNewAttemptAllowed(before, state.mode, retry, allowed);
422
427
  try {
423
- attempt = await runner.submit({ capability: req.request.capability, params: req.request.params, assets });
428
+ attempt = await runner.submit({ capability: req.request.capability, params: req.request.params, assets, ...(req.request.voice_authorized === undefined ? {} : { voice_authorized: req.request.voice_authorized }) });
424
429
  if (n === 0 && attempt.state === 'rejected' && attempt.rejected_code === 'asset_not_found') {
425
430
  allowed.add(attempt.idempotency_key);
426
431
  continue;
@@ -441,7 +446,7 @@ export class DirectGeneration {
441
446
  const tmp = await child(dir, 'output.download');
442
447
  let file;
443
448
  try {
444
- await (this.options.download ?? download)(url, tmp, { maxBytes: (req.request.medium === 'image' ? 50 : 500) * 1024 * 1024 });
449
+ await (this.options.download ?? download)(url, tmp, { maxBytes: (req.request.medium === 'video' ? 500 : 50) * 1024 * 1024 });
445
450
  if (req.request.medium === 'image') {
446
451
  const facts = await inspectImage(tmp);
447
452
  const ext = { png: 'png', jpeg: 'jpg', webp: 'webp' }[facts.format];
@@ -449,6 +454,12 @@ export class DirectGeneration {
449
454
  throw new Error('invalid_output');
450
455
  file = `output.${ext}`;
451
456
  }
457
+ else if (req.request.medium === 'audio') {
458
+ await probeAudio(tmp);
459
+ if ((req.request.params.format ?? 'mp3') !== 'mp3')
460
+ throw new Error('unsupported_audio_format');
461
+ file = 'output.mp3';
462
+ }
452
463
  else {
453
464
  await probe(tmp);
454
465
  file = 'output.mp4';
@@ -488,6 +499,6 @@ export class DirectGeneration {
488
499
  locked = e.code !== 'ENOENT';
489
500
  }
490
501
  const secret = await this.options.tokens.token().catch(() => '');
491
- 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)$/.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);
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);
492
503
  }
493
504
  }
@@ -1,3 +1,4 @@
1
+ import { transcriptionCreateSchema, transcriptionSchema, voiceCreateSchema, voiceSchema, voiceListSchema } from "../contract/cloud-v1.js";
1
2
  import { socialPostSchema, socialResolveRequestSchema } from "../contract/cloud-v1.js";
2
3
  import { readFile } from "node:fs/promises";
3
4
  import { basename } from "node:path";
@@ -100,6 +101,41 @@ export class CloudGateway {
100
101
  token: await this.tokens.token(),
101
102
  });
102
103
  }
104
+ async createTranscription(req, idempotencyKey) {
105
+ this.validateSpeechKey(idempotencyKey);
106
+ const body = transcriptionCreateSchema.parse(req);
107
+ return this.api.json(transcriptionSchema, "POST", "/audio/transcriptions", {
108
+ token: await this.tokens.token(), body, headers: { "Idempotency-Key": idempotencyKey },
109
+ });
110
+ }
111
+ async getTranscription(id) {
112
+ return this.api.json(transcriptionSchema, "GET", `/audio/transcriptions/${encodeURIComponent(id)}`, { token: await this.tokens.token() });
113
+ }
114
+ async createVoice(req, idempotencyKey) {
115
+ this.validateSpeechKey(idempotencyKey);
116
+ const body = voiceCreateSchema.parse(req);
117
+ return this.api.json(voiceSchema, "POST", "/voices", {
118
+ token: await this.tokens.token(), body, headers: { "Idempotency-Key": idempotencyKey },
119
+ });
120
+ }
121
+ async listVoices() {
122
+ return this.api.json(voiceListSchema, "GET", "/voices", { token: await this.tokens.token() });
123
+ }
124
+ async getVoice(id) {
125
+ return this.api.json(voiceSchema, "GET", `/voices/${encodeURIComponent(id)}`, { token: await this.tokens.token() });
126
+ }
127
+ async deleteVoice(id) {
128
+ const path = `/voices/${encodeURIComponent(id)}`;
129
+ const token = await this.tokens.token();
130
+ const res = await this.api.send("DELETE", path, { token });
131
+ this.api.check(res, token, path);
132
+ if (res.status !== 204)
133
+ throw new GatewayError("voice deletion requires HTTP 204", { kind: "parse", status: res.status });
134
+ }
135
+ validateSpeechKey(key) {
136
+ if (!/^[A-Za-z0-9_-]{1,128}$/.test(key))
137
+ throw new RangeError("Idempotency-Key must be 1-128 safe characters");
138
+ }
103
139
  /** The presigned URL is itself the credential: no Authorization, never logged or echoed. */
104
140
  async putObject(putUrl, bytes, contentType) {
105
141
  let status;
@@ -36,7 +36,7 @@ function fingerprint(value) {
36
36
  /** The work itself, without price pins or the legacy project tag. */
37
37
  function workFingerprint(body) {
38
38
  const { expected_price_credits: _credits, pricing_version: _version, project_id: _project, ...work } = body;
39
- return fingerprint(work);
39
+ return fingerprint({ ...work, voice_authorized: work.voice_authorized ?? false });
40
40
  }
41
41
  function isRefundConfirmed(attempt) {
42
42
  // A free work has nothing to refund and reports refund_state "none".
@@ -1,7 +1,11 @@
1
1
  import { z } from "zod";
2
2
  import { isSafeId } from "../core/index.js";
3
- import { priceRequestSchema, generationCreateSchema, uploadRequestSchema, meSchema, catalogSchema, priceSchema, generationSchema, uploadTicketSchema, assetStatusSchema, deviceBindingSchema, deviceTokenSchema } from "../contract/cloud-v1.js";
4
- export { priceRequestSchema, generationCreateSchema, uploadRequestSchema, meSchema, catalogSchema, priceSchema, generationSchema, uploadTicketSchema, assetStatusSchema, deviceBindingSchema, deviceTokenSchema };
3
+ import { priceRequestSchema as wirePriceRequestSchema, generationCreateSchema as wireGenerationCreateSchema, uploadRequestSchema, meSchema, catalogSchema, priceSchema, generationSchema, uploadTicketSchema, assetStatusSchema, deviceBindingSchema, deviceTokenSchema } from "../contract/cloud-v1.js";
4
+ // The server owns the false default. Client state must retain omitted authorization.
5
+ export const priceRequestSchema = wirePriceRequestSchema.extend({ voice_authorized: z.boolean().optional() });
6
+ export const generationCreateSchema = wireGenerationCreateSchema.extend({ voice_authorized: z.boolean().optional() });
7
+ export { uploadRequestSchema, meSchema, catalogSchema, priceSchema, generationSchema, uploadTicketSchema, assetStatusSchema, deviceBindingSchema, deviceTokenSchema };
8
+ export { transcriptionCreateSchema, transcriptionSchema, voiceCreateSchema, voiceSchema, voiceListSchema } from "../contract/cloud-v1.js";
5
9
  const uuid = z.guid();
6
10
  const int = z.number().int();
7
11
  const safeId = z.string().refine(isSafeId);
@@ -10,6 +10,7 @@ import { CloudGateway, scrub } from '../gateway/index.js';
10
10
  import { PopTitleRenderer } from '../effects/index.js';
11
11
  import { Engine, analyzeReference, draftJob, safeError } from '../engine/steps.js';
12
12
  import { DirectGeneration } from '../engine/direct.js';
13
+ import { SpeechTools, transcribeInputSchema, cloneInputSchema } from '../speech/tools.js';
13
14
  import { trimMedia } from '../acquire/trim.js';
14
15
  export const DEFAULT_BASE_URL = 'https://api.zenaigc.com/api/v1';
15
16
  const inputSchema = z.object({
@@ -46,14 +47,18 @@ const SERVER_INSTRUCTIONS = `Zenmcp tools are atomic. Combine them as follows.
46
47
  - title, text and hashtags from fetch_social_post are the post caption, not a transcript of speech in the video. Do not claim to know what is said in the video.
47
48
  5. Paid steps
48
49
  - plan_job only quotes; call execute_job only with credits the user approved. Report results with get_job. quote_generation only quotes; run_generation requires explicitly approved credits and requestDigest. Query with get_generation; never automatically approve retryAfterRelease.
49
- 6. Errors from fetch_social_post
50
+ 6. Speech and cloned voices
51
+ - transcribe_media uploads local audio/video for speech recognition; obtain user consent before calling it. It writes transcript.json; repeat identical arguments to resume a pending task.
52
+ - clone_voice requires the user's explicit consent_confirmed: true for the voice sample. list_voices is read-only. Training does not activate a voice.
53
+ - Voice activation and cloned speech use list_models → quote_generation → explicit credit approval → run_generation. voice_id is a catalog parameter. Only pass voice_authorized: true after explicit voice authorization from the user; never infer it from consent_confirmed or requires_voice_authorization. Changing voice or authorization requires a new quote.
54
+ 7. Errors from fetch_social_post
50
55
  - share_link_unresolved: ask the user to copy the full link.
51
56
  - unsupported_platform: list the six supported platforms.
52
57
  - rate_limited: tell the user the daily limit is reached and to try again tomorrow.
53
58
  - post_unavailable: the post was deleted, is private, or is region-locked.`;
54
59
  /** Background tasks live in this MCP process; state and attempts survive its restart. */
55
- export function createServer(engine, socialOptions = {}) {
56
- const server = new McpServer({ name: 'zenmcp', version: '0.1.1' }, { instructions: SERVER_INSTRUCTIONS });
60
+ export function createServer(engine, socialOptions = {}, speechOptions = {}) {
61
+ const server = new McpServer({ name: 'zenmcp', version: '0.1.2' }, { instructions: SERVER_INSTRUCTIONS });
57
62
  const active = new Map();
58
63
  server.registerTool('fetch_social_post', {
59
64
  description: '解析抖音/小红书/B站/TikTok/Instagram/X 分享口令或链接,下载视频或图集到本地目录,返回本地路径与标题/正文/话题。免费、限次;不分析内容。视频可直接交给 analyze_reference。',
@@ -147,10 +152,20 @@ export function createServer(engine, socialOptions = {}) {
147
152
  return failure(error, engine.tokens);
148
153
  }
149
154
  };
150
- server.registerTool('list_models', { description: '免费列出当前可用图片与视频能力。', inputSchema: { medium: z.enum(['image', 'video']).optional() } }, guarded((i) => direct.listModels(i.medium)));
151
- server.registerTool('quote_generation', { description: '校验并上传已获用户同意的本地素材,报价;不提交生成。', inputSchema: { directory: z.string(), capability: z.string(), prompt: z.string(), 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((i) => direct.quote(i)));
152
- server.registerTool('run_generation', { description: '携带明确批准积分与请求摘要,后台执行或恢复同一付款尝试。释放后重试需用户重新批准。', inputSchema: { directory: z.string(), approvedCredits: z.number().int().nonnegative(), requestDigest: z.string(), retryAfterRelease: z.boolean().optional() } }, guarded((i) => direct.run(i)));
155
+ server.registerTool('list_models', { description: '免费列出当前可用图片、视频与语音音频能力及授权要求。', inputSchema: { medium: z.enum(['image', 'video', 'audio']).optional() } }, guarded((i) => direct.listModels(i.medium)));
156
+ server.registerTool('quote_generation', { description: '校验并上传已获用户同意的本地素材,报价;不提交生成。', 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((i) => direct.quote(i)));
157
+ server.registerTool('run_generation', { description: '携带明确批准积分与请求摘要,后台执行或恢复同一付款尝试。释放后重试需用户重新批准。', 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((i) => direct.run(i)));
153
158
  server.registerTool('get_generation', { description: '只读查询直通生成状态、账单摘要与本地输出。', inputSchema: { directory: z.string() } }, guarded(async (i) => { const result = await direct.get(i); return { ...result, markdown: formatGenerationText(result) }; }));
159
+ const speech = new SpeechTools(engine.options.gateway, speechOptions);
160
+ server.registerTool('transcribe_media', {
161
+ description: '识别本地音频或视频中的语音,上传前请取得用户同意。免费、限次;提取为 16kHz 单声道 MP3(≤100MB、≤30分钟),返回全文、毫秒时间戳与分句并保存 transcript.json。output 可为目录或文件,默认媒体同目录;等待超时后使用相同参数续查。',
162
+ inputSchema: transcribeInputSchema.shape,
163
+ }, guarded(input => speech.transcribe(input)));
164
+ server.registerTool('clone_voice', {
165
+ description: '使用用户明确同意的本地音频样本训练复刻音色。必须显式传入 consent_confirmed:true;≤10MB,建议14–30秒。训练不启用音色,付费启用另需报价和批准。相同参数重试可续查。',
166
+ inputSchema: cloneInputSchema.shape,
167
+ }, guarded(input => speech.clone(input)));
168
+ server.registerTool('list_voices', { description: '查询当前账户复刻音色及 training、ready、active、failed、expired 状态;不启用、不收费。', inputSchema: {} }, guarded(() => speech.list()));
154
169
  return server;
155
170
  }
156
171
  export function createEngine(baseUrl = DEFAULT_BASE_URL, tokens) {
@@ -0,0 +1,39 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { stat } from 'node:fs/promises';
4
+ import { resolve } from 'node:path';
5
+ const exec = promisify(execFile);
6
+ export const mediaCommand = async (command, args) => {
7
+ try {
8
+ const { stdout } = await exec(command, args, { encoding: 'utf8', timeout: 300_000, maxBuffer: 4 * 1024 * 1024 });
9
+ return stdout;
10
+ }
11
+ catch {
12
+ // Do not echo arbitrary media metadata or subprocess diagnostics.
13
+ throw new Error(`${command}_failed:请检查本地媒体及 ffmpeg/ffprobe 安装。`);
14
+ }
15
+ };
16
+ /** Audio-only files cannot use the video timeline probe (which requires frames/fps). */
17
+ export async function probeAudio(path, run = mediaCommand) {
18
+ if (!(await stat(path)).isFile())
19
+ throw new Error('invalid_audio:输入必须为本地媒体文件。');
20
+ const raw = await run('ffprobe', ['-v', 'error', '-show_entries', 'stream=codec_type,duration:format=duration', '-of', 'json', resolve(path)]);
21
+ let facts;
22
+ try {
23
+ facts = JSON.parse(raw);
24
+ }
25
+ catch {
26
+ throw new Error('invalid_audio:无法读取媒体属性。');
27
+ }
28
+ const audio = facts?.streams?.find(s => s.codec_type === 'audio');
29
+ if (!audio)
30
+ throw new Error('no_audio_stream:输入媒体没有音频流。');
31
+ const streamDuration = Number(audio.duration);
32
+ const duration_seconds = Number.isFinite(streamDuration) && streamDuration > 0 ? streamDuration : Number(facts.format?.duration);
33
+ if (!Number.isFinite(duration_seconds) || duration_seconds <= 0)
34
+ throw new Error('invalid_audio_duration:无法确定音频时长。');
35
+ return { duration_seconds };
36
+ }
37
+ export async function extractAudio(source, output, run = mediaCommand) {
38
+ await run('ffmpeg', ['-nostdin', '-v', 'error', '-y', '-i', resolve(source), '-map', '0:a:0', '-vn', '-ac', '1', '-ar', '16000', '-c:a', 'libmp3lame', '-b:a', '64k', '-map_metadata', '-1', output]);
39
+ }
@@ -0,0 +1,184 @@
1
+ import { lstat, mkdtemp, mkdir, open, realpath, rename, rm, stat } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
3
+ import { dirname, extname, join, resolve } from 'node:path';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { setTimeout as delay } from 'node:timers/promises';
6
+ import { z } from 'zod';
7
+ import { sha256File } from '../core/index.js';
8
+ import { hash } from '../engine/steps.js';
9
+ import { lockJob, readJson, writeJson } from '../engine/storage.js';
10
+ import { directory } from '../assets/files.js';
11
+ import { transcriptionCreateSchema, voiceCreateSchema } from '../contract/cloud-v1.js';
12
+ import { extractAudio, mediaCommand, probeAudio } from './audio.js';
13
+ export const transcribeInputSchema = z.object({ path: z.string().min(1), language: z.string().min(1).max(32).optional(), speaker_info: z.boolean().optional(), output: z.string().min(1).optional() });
14
+ export const cloneInputSchema = z.object({ name: z.string().min(1).max(64), sample_path: z.string().min(1), consent_confirmed: z.literal(true) });
15
+ const receiptSchema = z.strictObject({ key: z.string().regex(/^[A-Za-z0-9_-]{1,128}$/), body: z.union([transcriptionCreateSchema, voiceCreateSchema]), id: z.guid().optional() });
16
+ const TRANSCRIPTION_MAX_BYTES = 100_000_000;
17
+ const VOICE_MAX_BYTES = 10_000_000;
18
+ function safeVoice(voice) {
19
+ const known = ['training_timeout', 'upstream_failed', 'sample_unavailable'];
20
+ return { ...voice, error: voice.error === null || known.includes(voice.error) ? voice.error : 'voice_training_failed' };
21
+ }
22
+ /** Receipts contain no URLs. A lost POST response is replayed with the same key and body. */
23
+ export class SpeechTools {
24
+ gateway;
25
+ options;
26
+ run;
27
+ sleep;
28
+ now;
29
+ constructor(gateway, options = {}) {
30
+ this.gateway = gateway;
31
+ this.options = options;
32
+ this.run = options.run ?? mediaCommand;
33
+ this.sleep = options.sleep ?? (ms => delay(ms));
34
+ this.now = options.now ?? Date.now;
35
+ }
36
+ async outputPath(source, output) {
37
+ let target = output ? resolve(output) : join(dirname(source), 'transcript.json');
38
+ const info = await stat(target).catch((e) => { if (e.code !== 'ENOENT')
39
+ throw e; return undefined; });
40
+ if (info?.isDirectory() || (!info && extname(target) === ''))
41
+ target = join(target, 'transcript.json');
42
+ await mkdir(dirname(target), { recursive: true });
43
+ const destination = await lstat(target).catch((e) => { if (e.code !== 'ENOENT')
44
+ throw e; return undefined; });
45
+ if (destination && !destination.isFile())
46
+ throw new Error('invalid_output:输出必须是普通文件,不能是符号链接。');
47
+ if (resolve(source) === target || await realpath(target).catch(() => target) === source)
48
+ throw new Error('invalid_output:不能覆盖输入媒体。');
49
+ return target;
50
+ }
51
+ async writeTranscript(output, result) {
52
+ // An explicit output path can contain spaces, unlike internal safe path segments.
53
+ const temp = join(dirname(output), `${randomUUID()}.tmp`);
54
+ try {
55
+ const file = await open(temp, 'wx', 0o600);
56
+ try {
57
+ await file.writeFile(JSON.stringify(result, null, 2));
58
+ await file.sync();
59
+ }
60
+ finally {
61
+ await file.close();
62
+ }
63
+ await rename(temp, output);
64
+ }
65
+ finally {
66
+ await rm(temp, { force: true });
67
+ }
68
+ }
69
+ async receiptDir(source, root, kind, params) {
70
+ const account = await this.gateway.me();
71
+ const fingerprint = hash({ kind, sha256: await sha256File(source), params, deployment: this.gateway.deployment, account: account.user_id });
72
+ const receipts = await directory(root, 'zenmcp-speech');
73
+ return directory(receipts, fingerprint);
74
+ }
75
+ async load(dir) {
76
+ try {
77
+ return receiptSchema.parse(await readJson(dir, 'request.json'));
78
+ }
79
+ catch (e) {
80
+ if (e.code === 'ENOENT')
81
+ return undefined;
82
+ throw new Error('speech_state_corrupt:保留原记录,停止提交。');
83
+ }
84
+ }
85
+ async upload(source, maxBytes, maxSeconds) {
86
+ const temp = await mkdtemp(join(tmpdir(), 'zenmcp-audio-'));
87
+ try {
88
+ const path = join(temp, 'audio.mp3');
89
+ await extractAudio(source, path, this.run);
90
+ const facts = await probeAudio(path, this.run);
91
+ const size = (await stat(path)).size;
92
+ if (size <= 0 || size > maxBytes)
93
+ throw new Error('audio_too_large:转换后音频超出大小限制。');
94
+ if (facts.duration_seconds > maxSeconds)
95
+ throw new Error('audio_too_long:转换后音频超出时长限制。');
96
+ const asset = await this.gateway.upload(path, { consent_confirmed: true, content_type: 'audio/mpeg' });
97
+ if (asset.status !== 'ready')
98
+ throw new Error('asset_not_ready');
99
+ return asset.asset_id;
100
+ }
101
+ finally {
102
+ await rm(temp, { recursive: true, force: true });
103
+ }
104
+ }
105
+ async poll(initial, pending, get, timeoutMs) {
106
+ const deadline = this.now() + timeoutMs;
107
+ let current = initial;
108
+ while (pending(current) && this.now() < deadline) {
109
+ await this.sleep(Math.min(this.options.pollIntervalMs ?? 2_000, Math.max(0, deadline - this.now())));
110
+ if (this.now() >= deadline)
111
+ break;
112
+ current = await get();
113
+ }
114
+ return current;
115
+ }
116
+ async transcribe(raw) {
117
+ const input = transcribeInputSchema.parse(raw);
118
+ const source = await realpath(input.path);
119
+ const facts = await probeAudio(source, this.run);
120
+ if (facts.duration_seconds > 1800)
121
+ throw new Error('audio_too_long:录音识别限 30 分钟,请先截取。');
122
+ const output = await this.outputPath(source, input.output);
123
+ const params = { ...(input.language === undefined ? {} : { language: input.language }), ...(input.speaker_info === undefined ? {} : { speaker_info: input.speaker_info }) };
124
+ const dir = await this.receiptDir(source, dirname(output), 'transcription', params);
125
+ const release = await lockJob(dir);
126
+ try {
127
+ let receipt = await this.load(dir);
128
+ if (!receipt) {
129
+ const asset_id = await this.upload(source, TRANSCRIPTION_MAX_BYTES, 1800);
130
+ receipt = { key: randomUUID(), body: { asset_id, ...params } };
131
+ await writeJson(dir, 'request.json', receipt);
132
+ }
133
+ const created = receipt.id ? await this.gateway.getTranscription(receipt.id) : await this.gateway.createTranscription(transcriptionCreateSchema.parse(receipt.body), receipt.key);
134
+ receipt.id = created.id;
135
+ await writeJson(dir, 'request.json', receipt);
136
+ const result = await this.poll(created, t => t.status === 'queued' || t.status === 'running', () => this.gateway.getTranscription(created.id), this.options.transcriptionTimeoutMs ?? 300_000);
137
+ if (result.status === 'failed')
138
+ throw new Error(`transcription_failed:${result.error};任务 ${result.id}。`);
139
+ if (result.status !== 'completed')
140
+ return { ...result, idempotency_key: receipt.key, path: null, markdown: `转写仍在处理中(${result.status}),本地等待已超时,云端继续处理。请使用相同参数重试以续查任务 ${result.id}。` };
141
+ if (!result.result)
142
+ throw new Error('result_purged:转写结果已过期,不自动重新提交。');
143
+ await this.writeTranscript(output, result);
144
+ return { ...result, idempotency_key: receipt.key, path: output, markdown: `转写完成:${result.result.segments.length} 个分句,${result.result.duration_ms} 毫秒。\n\n文件:${output}\n\n${result.result.text}` };
145
+ }
146
+ finally {
147
+ await release();
148
+ }
149
+ }
150
+ async clone(raw) {
151
+ // Validate explicit consent before reading files or contacting the gateway.
152
+ const input = cloneInputSchema.parse(raw);
153
+ const source = await realpath(input.sample_path);
154
+ if ((await stat(source)).size > VOICE_MAX_BYTES)
155
+ throw new Error('audio_too_large:音色样本限 10MB。');
156
+ const facts = await probeAudio(source, this.run);
157
+ const warning = facts.duration_seconds < 14 || facts.duration_seconds > 30 ? '建议使用 14–30 秒的清晰单人语音样本。' : null;
158
+ const dir = await this.receiptDir(source, dirname(source), 'voice', { name: input.name, consent_confirmed: input.consent_confirmed });
159
+ const release = await lockJob(dir);
160
+ try {
161
+ let receipt = await this.load(dir);
162
+ if (!receipt) {
163
+ const sample_asset_id = await this.upload(source, VOICE_MAX_BYTES, Number.POSITIVE_INFINITY);
164
+ const body = { name: input.name, sample_asset_id, consent_confirmed: input.consent_confirmed };
165
+ receipt = { key: randomUUID(), body };
166
+ await writeJson(dir, 'request.json', receipt);
167
+ }
168
+ const created = receipt.id ? await this.gateway.getVoice(receipt.id) : await this.gateway.createVoice(voiceCreateSchema.parse(receipt.body), receipt.key);
169
+ receipt.id = created.id;
170
+ await writeJson(dir, 'request.json', receipt);
171
+ const voice = await this.poll(created, v => v.status === 'training', () => this.gateway.getVoice(created.id), this.options.voiceTimeoutMs ?? 60_000);
172
+ // Keep provider error text out of tool responses; Voice.error is an open wire string.
173
+ const safe = safeVoice(voice);
174
+ return { ...safe, idempotency_key: receipt.key, warning, markdown: `音色「${voice.name}」状态:${voice.status}(${voice.id})。${voice.status === 'ready' ? '训练完成,尚未付费启用;启用需单独报价及积分批准。' : voice.status === 'training' ? '云端继续训练,使用相同参数重试可续查。' : ''}${warning ?? ''}` };
175
+ }
176
+ finally {
177
+ await release();
178
+ }
179
+ }
180
+ async list() {
181
+ const list = { voices: (await this.gateway.listVoices()).voices.map(safeVoice) };
182
+ return { ...list, markdown: list.voices.length ? list.voices.map(v => `- ${v.name}(${v.id}):${v.status}`).join('\n') : '当前账户暂无复刻音色。' };
183
+ }
184
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenaigc/zenmcp",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "zenmcp": "dist/src/mcp/server.js",
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: zenmcp
3
- description: 用户需要生图、生视频、复刻短视频或进行 ZenMCP 环境配置自检时使用。
3
+ description: 用户需要生图、生视频、复刻短视频、录音识别、标准语音合成或进行 ZenMCP 环境配置自检时使用。
4
4
  ---
5
5
 
6
6
  # ZenMCP
7
7
 
8
8
  环境异常或未安装时运行 `zenmcp-doctor`,或参照同包内的 `INSTALL.md`(安装包根目录,在线地址:https://api.zenaigc.com/install.md)。安装缺失依赖前须征得用户同意。
9
9
 
10
- ## 13 个工具的编排
10
+ ## 工具编排
11
11
 
12
12
  - 直出生成:`list_models` → `quote_generation` → 展示报价并获得用户明确批准的积分 → `run_generation` → `get_generation`。
13
13
  - 每次生成使用新的空目录。本地素材上传前须获得用户同意,并传 `consent_confirmed: true`;提交时携带报价的 `requestDigest`。
@@ -15,6 +15,8 @@ description: 用户需要生图、生视频、复刻短视频或进行 ZenMCP
15
15
  - 分享链接先调用 `fetch_social_post`,每帖使用新的空目录,同一任务不重复抓取同一链接。本地视频跳过抓取,直接分析;抓取与分析无需用户确认。
16
16
  - 视频超过约 30 秒或报价提示时长限制时,先征求用户同意保留的片段,再用 `trim_media` 截取并分析截取后的文件。
17
17
  - 图集先展示图片,由用户确认哪些是产品或模特素材。最终素材及属性确认前不得调用 `import_assets`。
18
+ - 录音识别:先取得本地音视频上传同意,再调用 `transcribe_media`(单次最长 30 分钟,当前服务端使用每日次数限额)。输出 `transcript.json`,相同参数可恢复未完成任务。
19
+ - 标准语音合成:`list_models` → 选择 `doubao-seed-tts-2.0` → `quote_generation` → 用户批准积分 → `run_generation` → `get_generation`。音色训练与复刻暂不开放。
18
20
  - 额度查询:用只读工具 `account_status` 查询。
19
21
 
20
22
  ## 禁令与错误处理