Skip to content

Commit 0b01943

Browse files
authored
Merge pull request #4 from AceDataCloud/feat/multi-provider-and-dual-build
feat: add multi-provider support and dual ESM+CJS build
2 parents 592340b + d21c01d commit 0b01943

8 files changed

Lines changed: 1390 additions & 10 deletions

File tree

typescript/package-lock.json

Lines changed: 1336 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
"version": "0.1.0",
44
"description": "Official TypeScript SDK for AceDataCloud — AI-powered data services",
55
"main": "dist/index.js",
6+
"module": "dist/index.mjs",
67
"types": "dist/index.d.ts",
8+
"exports": {
9+
".": {
10+
"import": {
11+
"types": "./dist/index.d.mts",
12+
"default": "./dist/index.mjs"
13+
},
14+
"require": {
15+
"types": "./dist/index.d.ts",
16+
"default": "./dist/index.js"
17+
}
18+
}
19+
},
720
"license": "MIT",
821
"scripts": {
9-
"build": "tsc",
22+
"build": "tsup",
1023
"test": "jest --forceExit",
1124
"lint": "tsc --noEmit"
1225
},
@@ -16,6 +29,7 @@
1629
"dotenv": "^17.3.1",
1730
"jest": "^29.0.0",
1831
"ts-jest": "^29.0.0",
32+
"tsup": "^8.5.1",
1933
"typescript": "^5.0.0"
2034
},
2135
"files": [

typescript/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ export {
1717
} from './runtime/errors';
1818

1919
export { TaskHandle, TaskHandleOptions } from './runtime/tasks';
20+
21+
export type { ImageProvider } from './resources/images';
22+
export type { VideoProvider } from './resources/video';
23+
export type { AudioProvider } from './resources/audio';

typescript/src/resources/audio.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import { Transport } from '../runtime/transport';
44
import { TaskHandle } from '../runtime/tasks';
55

6+
export type AudioProvider = 'suno' | 'producer' | (string & {});
7+
68
export class Audio {
79
constructor(private transport: Transport) {}
810

911
async generate(opts: {
1012
prompt: string;
13+
provider?: AudioProvider;
1114
model?: string;
1215
tags?: string;
1316
callbackUrl?: string;
@@ -16,18 +19,18 @@ export class Audio {
1619
maxWait?: number;
1720
[key: string]: unknown;
1821
}): Promise<Record<string, unknown> | TaskHandle> {
19-
const { prompt, model, tags, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
22+
const { prompt, provider = 'suno', model, tags, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
2023
const body: Record<string, unknown> = { prompt, ...rest };
2124
if (model !== undefined) body.model = model;
2225
if (tags !== undefined) body.tags = tags;
2326
if (callbackUrl !== undefined) body.callback_url = callbackUrl;
2427

25-
const result = await this.transport.request('POST', '/suno/audios', { json: body });
28+
const result = await this.transport.request('POST', `/${provider}/audios`, { json: body });
2629
const taskId = result.task_id as string | undefined;
2730

2831
if (!taskId || (result.data && !shouldWait)) return result;
2932

30-
const handle = new TaskHandle(taskId, '/suno/tasks', this.transport);
33+
const handle = new TaskHandle(taskId, `/${provider}/tasks`, this.transport);
3134
if (shouldWait) return handle.wait({ pollInterval, maxWait });
3235
return handle;
3336
}

typescript/src/resources/images.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import { Transport } from '../runtime/transport';
44
import { TaskHandle } from '../runtime/tasks';
55

6+
export type ImageProvider = 'nano-banana' | 'midjourney' | 'flux' | 'seedream' | (string & {});
7+
68
export class Images {
79
constructor(private transport: Transport) {}
810

911
async generate(opts: {
1012
prompt: string;
13+
provider?: ImageProvider;
1114
model?: string;
1215
negativePrompt?: string;
1316
imageUrl?: string;
@@ -17,19 +20,20 @@ export class Images {
1720
maxWait?: number;
1821
[key: string]: unknown;
1922
}): Promise<Record<string, unknown> | TaskHandle> {
20-
const { prompt, model, negativePrompt, imageUrl, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
23+
const { prompt, provider = 'nano-banana', model, negativePrompt, imageUrl, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
2124
const body: Record<string, unknown> = { prompt, ...rest };
2225
if (model !== undefined) body.model = model;
2326
if (negativePrompt !== undefined) body.negative_prompt = negativePrompt;
2427
if (imageUrl !== undefined) body.image_url = imageUrl;
2528
if (callbackUrl !== undefined) body.callback_url = callbackUrl;
2629

27-
const result = await this.transport.request('POST', '/nano-banana/images', { json: body });
30+
const endpoint = provider === 'midjourney' ? '/midjourney/imagine' : `/${provider}/images`;
31+
const result = await this.transport.request('POST', endpoint, { json: body });
2832
const taskId = result.task_id as string | undefined;
2933

3034
if (!taskId || (result.data && !shouldWait)) return result;
3135

32-
const handle = new TaskHandle(taskId, '/nano-banana/tasks', this.transport);
36+
const handle = new TaskHandle(taskId, `/${provider}/tasks`, this.transport);
3337
if (shouldWait) return handle.wait({ pollInterval, maxWait });
3438
return handle;
3539
}

typescript/src/resources/tasks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TaskHandle } from '../runtime/tasks';
55

66
const SERVICE_TASK_ENDPOINTS: Record<string, string> = {
77
suno: '/suno/tasks',
8+
producer: '/producer/tasks',
89
'nano-banana': '/nano-banana/tasks',
910
seedream: '/seedream/tasks',
1011
seedance: '/seedance/tasks',
@@ -13,6 +14,11 @@ const SERVICE_TASK_ENDPOINTS: Record<string, string> = {
1314
luma: '/luma/tasks',
1415
veo: '/veo/tasks',
1516
flux: '/flux/tasks',
17+
kling: '/kling/tasks',
18+
hailuo: '/hailuo/tasks',
19+
wan: '/wan/tasks',
20+
pika: '/pika/tasks',
21+
pixverse: '/pixverse/tasks',
1622
};
1723

1824
export class Tasks {

typescript/src/resources/video.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import { Transport } from '../runtime/transport';
44
import { TaskHandle } from '../runtime/tasks';
55

6+
export type VideoProvider = 'sora' | 'luma' | 'veo' | 'kling' | 'hailuo' | 'seedance' | 'wan' | 'pika' | 'pixverse' | (string & {});
7+
68
export class Video {
79
constructor(private transport: Transport) {}
810

911
async generate(opts: {
1012
prompt: string;
13+
provider?: VideoProvider;
1114
model?: string;
1215
imageUrl?: string;
1316
callbackUrl?: string;
@@ -16,18 +19,18 @@ export class Video {
1619
maxWait?: number;
1720
[key: string]: unknown;
1821
}): Promise<Record<string, unknown> | TaskHandle> {
19-
const { prompt, model, imageUrl, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
22+
const { prompt, provider = 'sora', model, imageUrl, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
2023
const body: Record<string, unknown> = { prompt, ...rest };
2124
if (model !== undefined) body.model = model;
2225
if (imageUrl !== undefined) body.image_url = imageUrl;
2326
if (callbackUrl !== undefined) body.callback_url = callbackUrl;
2427

25-
const result = await this.transport.request('POST', '/sora/videos', { json: body });
28+
const result = await this.transport.request('POST', `/${provider}/videos`, { json: body });
2629
const taskId = result.task_id as string | undefined;
2730

2831
if (!taskId || (result.data && !shouldWait)) return result;
2932

30-
const handle = new TaskHandle(taskId, '/sora/tasks', this.transport);
33+
const handle = new TaskHandle(taskId, `/${provider}/tasks`, this.transport);
3134
if (shouldWait) return handle.wait({ pollInterval, maxWait });
3235
return handle;
3336
}

typescript/tsup.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig({
4+
entry: ['src/index.ts'],
5+
format: ['cjs', 'esm'],
6+
dts: true,
7+
clean: true,
8+
splitting: false,
9+
sourcemap: true,
10+
});

0 commit comments

Comments
 (0)