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.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
import { describe, expect, it, vi } from 'vitest';
import { createCreatorService } from './creator-service.js';
describe('creator web service', () => {
it('controls a single download through its owner and encoded stage ID', async () => {
const client = { get: vi.fn(), post: vi.fn(), delete: vi.fn() };
const service = createCreatorService(client);
for (const action of ['pause', 'resume', 'cancel'] as const) {
await service.controlDownload('job 1', 'stage/2', action);
expect(client.post).toHaveBeenLastCalledWith(`/creator/jobs/job%201/downloads/stage%2F2/${action}`);
}
});
it('uses the public creator endpoints', async () => {
const client = {
get: vi.fn(async () => ({ jobs: [] })),
post: vi.fn(async () => ({ job: { id: 'job_1' } })),
delete: vi.fn(async () => undefined),
postBinary: vi.fn(async () => ({
job: { id: 'job_1' },
artifact: { id: 'artifact_source_1' },
deduplicated: false
})),
rawGet: vi.fn(async () => new Response('artifact'))
};
const service = createCreatorService(client);
await service.preflight('job 1', 'prepare-source-video', { inputResultVersion: 2 });
expect(client.get).toHaveBeenCalledWith('/creator/jobs/job%201/preflight?stageId=prepare-source-video&inputResultVersion=2');
await service.listPresets('en-US');
await service.listJobs('project 1');
await service.listJobs();
await service.createJob({
projectId: 'project 1',
templateId: 'video-translation',
creationKey: 'create-key-1'
});
await service.applyAction('job_1', {
action: 'update-settings',
expectedRevision: 0,
input: { patch: { targetLanguage: 'ja' } }
});
await service.cancelJob('job_1');
await service.resumeJob('job_1');
await service.startAgentTurn('job_1', { message: '开始', clientMessageId: 'message-1' });
await service.steerAgentTurn('job_1', { message: '调整', clientMessageId: 'message-2' });
await service.interruptAgentTurn('job_1');
await service.respondAgentApproval('job_1', 'approval 1', {
decision: 'approved',
processGeneration: 3
});
await service.getAgentTimeline('job_1');
await service.uploadSourceVideo('job_1', {
file: new File(['video'], 'sample.webm', {
type: 'video/webm',
lastModified: 123
}),
expectedRevision: 7
});
await service.uploadReferenceImage('job_1', {
file: new File(['image'], 'reference.png', {
type: 'image/png',
lastModified: 456
}),
expectedRevision: 8
});
await service.uploadArticleImage('job_1', {
file: new File(['image'], 'article.png', {
type: 'image/png',
lastModified: 654
}),
expectedRevision: 9
});
await service.uploadSourceDocument('job_1', {
file: new File(['document'], 'source.pdf', {
type: 'application/pdf',
lastModified: 789
}),
expectedRevision: 9
});
await service.importArtifact('job_1', {
expectedRevision: 9,
sourceJobId: 'source job',
artifactId: 'artifact source',
kind: 'source_video'
});
await service.openProjectCover('job_1');
await service.openArtifact('job_1', 'artifact 1');
await service.openDownloadThumbnail('job 1', 'probe 1');
expect(client.rawGet).toHaveBeenCalledWith('/creator/jobs/job%201/artifacts/probe%201/thumbnail');
await service.deleteJob('job 1');
await service.deleteJob('job 2', { deleteFiles: true });
await service.listVisualAssets('stickman-video', 'style');
await service.openVisualAssetPreview('stickman.style.paper-pencil', 2);
expect(client.get).toHaveBeenCalledWith('/creator/presets?locale=en-US');
expect(client.get).toHaveBeenCalledWith('/creator/jobs?projectId=project%201');
expect(client.get).toHaveBeenCalledWith('/creator/jobs');
expect(client.post).toHaveBeenNthCalledWith(1, '/creator/jobs', {
projectId: 'project 1',
templateId: 'video-translation',
creationKey: 'create-key-1'
});
expect(client.post).toHaveBeenNthCalledWith(2, '/creator/jobs/job_1/actions', expect.any(Object));
expect(client.post).toHaveBeenNthCalledWith(3, '/creator/jobs/job_1/cancel');
expect(client.post).toHaveBeenNthCalledWith(4, '/creator/jobs/job_1/resume');
expect(client.post).toHaveBeenNthCalledWith(5, '/creator/jobs/job_1/agent-turns', expect.any(Object));
expect(client.post).toHaveBeenNthCalledWith(6, '/creator/jobs/job_1/agent-steer', expect.any(Object));
expect(client.post).toHaveBeenNthCalledWith(7, '/creator/jobs/job_1/agent-interrupt');
expect(client.post).toHaveBeenNthCalledWith(
8,
'/creator/jobs/job_1/agent-approvals/approval%201',
expect.any(Object)
);
expect(client.get).toHaveBeenCalledWith('/creator/jobs/job_1/agent-timeline');
expect(client.postBinary).toHaveBeenCalledWith(
'/creator/jobs/job_1/source-video?expectedRevision=7&fileName=sample.webm&mime=video%2Fwebm&lastModified=123',
expect.any(File),
'application/vnd.opencreator.creator-source'
);
expect(client.postBinary).toHaveBeenCalledWith(
'/creator/jobs/job_1/reference-image?expectedRevision=8&fileName=reference.png&mime=image%2Fpng&lastModified=456',
expect.any(File),
'application/vnd.opencreator.creator-reference-image'
);
expect(client.postBinary).toHaveBeenCalledWith(
'/creator/jobs/job_1/article-image?expectedRevision=9&fileName=article.png&mime=image%2Fpng&lastModified=654',
expect.any(File),
'application/vnd.opencreator.creator-reference-image'
);
expect(client.postBinary).toHaveBeenCalledWith(
'/creator/jobs/job_1/source-document?expectedRevision=9&fileName=source.pdf&mime=application%2Fpdf&lastModified=789',
expect.any(File),
'application/vnd.opencreator.creator-document'
);
expect(client.post).toHaveBeenNthCalledWith(
9,
'/creator/jobs/job_1/import-artifact',
{
expectedRevision: 9,
sourceJobId: 'source job',
artifactId: 'artifact source',
kind: 'source_video'
}
);
expect(client.rawGet).toHaveBeenCalledWith('/creator/jobs/job_1/cover');
expect(client.rawGet).toHaveBeenCalledWith('/creator/jobs/job_1/artifacts/artifact%201/content');
expect(client.delete).toHaveBeenNthCalledWith(1, '/creator/jobs/job%201');
expect(client.delete).toHaveBeenNthCalledWith(2, '/creator/jobs/job%202?deleteFiles=true');
expect(client.get).toHaveBeenCalledWith('/creator/visual-assets?templateId=stickman-video&kind=style');
expect(client.rawGet).toHaveBeenCalledWith(
'/creator/visual-assets/stickman.style.paper-pencil/revisions/2/preview'
);
});
it('deduplicates stable SSE ids and reconnects with the last cursor', async () => {
const event = {
id: 'agent:1',
jobId: 'job_1',
revision: 2,
kind: 'agent_item_changed',
payload: {},
createdAt: '2026-08-21T00:00:00.000Z'
} as const;
const frame = `id: ${event.id}\nevent: ${event.kind}\ndata: ${JSON.stringify(event)}\n\n`;
const rawGet = vi.fn()
.mockResolvedValueOnce(new Response(frame + frame))
.mockResolvedValueOnce(new Response(frame));
const service = createCreatorService({
get: vi.fn(),
post: vi.fn(),
delete: vi.fn(),
rawGet
});
const received: string[] = [];
await subscribeUntilDisconnect(service, 'job_1', event => received.push(event.id));
await subscribeUntilDisconnect(service, 'job_1', event => received.push(event.id));
expect(received).toEqual(['agent:1']);
expect(rawGet).toHaveBeenNthCalledWith(
1,
'/creator/jobs/job_1/events',
{ signal: expect.any(AbortSignal) }
);
expect(rawGet).toHaveBeenNthCalledWith(
2,
'/creator/jobs/job_1/events?cursor=agent%3A1',
{ signal: expect.any(AbortSignal) }
);
});
it('aborts the SSE request when the subscription closes', async () => {
let requestSignal: AbortSignal | undefined;
const rawGet = vi.fn((
_path: string,
options?: { signal?: AbortSignal }
) => new Promise<Response>((_resolve, reject) => {
requestSignal = options?.signal;
requestSignal?.addEventListener('abort', () => {
reject(new DOMException('aborted', 'AbortError'));
}, { once: true });
}));
const service = createCreatorService({
get: vi.fn(),
post: vi.fn(),
delete: vi.fn(),
rawGet
});
const onDisconnect = vi.fn();
const subscription = service.subscribeJobEvents('job_1', vi.fn(), onDisconnect);
await vi.waitFor(() => expect(rawGet).toHaveBeenCalledOnce());
expect(requestSignal).toBeDefined();
subscription.close();
expect(requestSignal?.aborted).toBe(true);
await Promise.resolve();
expect(onDisconnect).not.toHaveBeenCalled();
});
});
function subscribeUntilDisconnect(
service: ReturnType<typeof createCreatorService>,
jobId: string,
onEvent: Parameters<ReturnType<typeof createCreatorService>['subscribeJobEvents']>[1]
): Promise<void> {
return new Promise(resolve => {
service.subscribeJobEvents(jobId, onEvent, () => resolve());
});
}