Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

3.9 KB
Raw Blame
import { z } from 'zod/v3';
import type { CreatorTemplateDefinition } from './types.js';

const record = z.record(z.string(), z.unknown()) as never;

export function createLegacyVideoDownloadTemplate(): CreatorTemplateDefinition {
  return {
    id: 'video-download', version: 1, renderer: 'video-download',
    inputSchema: z.object({
      sourceUrl: z.string().default(''),
      formatId: z.string().default('bestvideo+bestaudio/best'),
      currentStage: z.string().nullable().default(null)
    }).passthrough() as never,
    stages: [
      { id: 'probe', executor: 'download', allowedJobStatuses: ['draft', 'running', 'failed', 'needs_input'], inputArtifacts: [], outputArtifacts: [{ kind: 'download_probe', status: 'completed' }] },
      { id: 'download', executor: 'download', dependsOn: ['probe'], allowedJobStatuses: ['draft', 'running', 'failed', 'needs_input'], inputArtifacts: [{ kind: 'download_probe', selector: 'latest-completed' }], outputArtifacts: [{ kind: 'source_video', status: 'completed' }] }
    ],
    actions: [
      { id: 'update-settings', inputSchema: record, allowedStages: ['probe', 'download'] },
      { id: 'run-stage', inputSchema: record, allowedStages: ['probe', 'download'] },
      { id: 'undo-action', inputSchema: record, allowedStages: ['probe', 'download'] }
    ],
    outputs: [{ kind: 'source_video', required: true }],
    agentGuidance: '先探测格式,再使用探测结果下载;不得猜测 formatId。'
  };
}

export function createVideoDownloadTemplate(): CreatorTemplateDefinition {
  return {
    id: 'video-download',
    version: 2,
    renderer: 'video-download',
    inputSchema: z.object({
      sourceUrl: z.string().default(''),
      mediaType: z.enum(['video', 'audio', 'subtitle']).default('video'),
      selectedOptionId: z.string().nullable().default(null),
      currentStage: z.string().nullable().default(null)
    }).passthrough() as never,
    stages: [
      {
        id: 'probe',
        executor: 'download',
        completesJob: false,
        resultVersionPolicy: 'none',
        invalidateDependentArtifacts: false,
        allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
        inputArtifacts: [],
        outputArtifacts: [{ kind: 'download_probe', status: 'completed' }]
      },
      {
        id: 'download',
        executor: 'download',
        dependsOn: ['probe'],
        allowedJobStatuses: ['draft', 'running', 'completed', 'failed', 'needs_input'],
        inputArtifacts: [{
          kind: 'download_probe',
          selector: 'latest-completed'
        }],
        outputArtifacts: [
          { kind: 'source_video', status: 'completed' },
          { kind: 'source_audio', status: 'completed' },
          { kind: 'source_subtitle', status: 'completed' }
        ]
      }
    ],
    actions: [
      {
        id: 'update-settings',
        inputSchema: record,
        allowedStages: ['probe', 'download']
      },
      {
        id: 'run-stage',
        inputSchema: record,
        allowedStages: ['probe', 'download']
      },
      {
        id: 'undo-action',
        inputSchema: record,
        allowedStages: ['probe', 'download']
      }
    ],
    outputs: [
      { kind: 'source_video', required: false },
      { kind: 'source_audio', required: false },
      { kind: 'source_subtitle', required: false }
    ],
    agentGuidance: [
      '支持公开的 YouTube、Bilibili、X、TikTok、Instagram、抖音、Facebook、小红书、Pinterest 和 Reddit 视频链接,可下载视频、提取音频或下载来源提供的 SRT 字幕。',
      '先设置 sourceUrl 并运行 probe,再读取最新 download_probe.options;只选择其中与用户请求的 video、audio 或 subtitle 对应的 option.id,字幕须匹配语言和人工或自动来源。',
      '更新 selectedOptionId 和 mediaType 后运行 download;不得自行构造或写入 formatId。若 probe 没有对应选项,再说明该链接无法提供所需媒体。'
    ].join(' ')
  };
}