@acedatacloud/sdk 0.0.1
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/README.md +97 -0
- package/dist/client.d.ts +31 -0
- package/dist/client.js +46 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -0
- package/dist/resources/audio.d.ts +17 -0
- package/dist/resources/audio.js +30 -0
- package/dist/resources/chat.d.ts +30 -0
- package/dist/resources/chat.js +38 -0
- package/dist/resources/files.d.ts +9 -0
- package/dist/resources/files.js +59 -0
- package/dist/resources/images.d.ts +18 -0
- package/dist/resources/images.js +32 -0
- package/dist/resources/openai.d.ts +46 -0
- package/dist/resources/openai.js +59 -0
- package/dist/resources/platform.d.ts +41 -0
- package/dist/resources/platform.js +76 -0
- package/dist/resources/search.d.ts +14 -0
- package/dist/resources/search.js +22 -0
- package/dist/resources/tasks.d.ts +14 -0
- package/dist/resources/tasks.js +36 -0
- package/dist/resources/video.d.ts +17 -0
- package/dist/resources/video.js +30 -0
- package/dist/runtime/errors.d.ts +44 -0
- package/dist/runtime/errors.js +89 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +19 -0
- package/dist/runtime/tasks.d.ts +17 -0
- package/dist/runtime/tasks.js +46 -0
- package/dist/runtime/transport.d.ts +31 -0
- package/dist/runtime/transport.js +210 -0
- package/package.json +28 -0
- package/src/client.ts +56 -0
- package/src/index.ts +19 -0
- package/src/resources/audio.ts +34 -0
- package/src/resources/chat.ts +63 -0
- package/src/resources/files.ts +27 -0
- package/src/resources/images.ts +36 -0
- package/src/resources/openai.ts +96 -0
- package/src/resources/platform.ts +77 -0
- package/src/resources/search.ts +23 -0
- package/src/resources/tasks.ts +38 -0
- package/src/resources/video.ts +34 -0
- package/src/runtime/errors.ts +93 -0
- package/src/runtime/index.ts +15 -0
- package/src/runtime/tasks.ts +57 -0
- package/src/runtime/transport.ts +257 -0
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# AceDataCloud TypeScript SDK
|
|
2
|
+
|
|
3
|
+
Official TypeScript/Node.js client for the [AceDataCloud API](https://platform.acedata.cloud).
|
|
4
|
+
|
|
5
|
+
Requires Node.js 18+ (uses native `fetch`).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @acedatacloud/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AceDataCloud } from '@acedatacloud/sdk';
|
|
17
|
+
|
|
18
|
+
const client = new AceDataCloud({ apiToken: 'your-token' });
|
|
19
|
+
|
|
20
|
+
// OpenAI-compatible chat completions
|
|
21
|
+
const response = await client.openai.chat.completions.create({
|
|
22
|
+
model: 'gpt-4o',
|
|
23
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
24
|
+
});
|
|
25
|
+
console.log(response.choices[0].message.content);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Streaming
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const stream = await client.openai.chat.completions.create({
|
|
32
|
+
model: 'gpt-4o',
|
|
33
|
+
messages: [{ role: 'user', content: 'Tell me a story' }],
|
|
34
|
+
stream: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
for await (const chunk of stream) {
|
|
38
|
+
process.stdout.write(chunk.choices?.[0]?.delta?.content ?? '');
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Resources
|
|
43
|
+
|
|
44
|
+
| Resource | Description |
|
|
45
|
+
|----------|-------------|
|
|
46
|
+
| `client.openai` | OpenAI-compatible chat completions and responses |
|
|
47
|
+
| `client.chat` | Native chat messages |
|
|
48
|
+
| `client.images` | Image generation (Midjourney, Flux, etc.) |
|
|
49
|
+
| `client.audio` | Music generation (Suno) |
|
|
50
|
+
| `client.video` | Video generation (Luma, Sora, Veo, etc.) |
|
|
51
|
+
| `client.search` | Web search (Google SERP) |
|
|
52
|
+
| `client.tasks` | Cross-service async task polling |
|
|
53
|
+
| `client.files` | File uploads |
|
|
54
|
+
| `client.platform` | Applications, credentials, models management |
|
|
55
|
+
|
|
56
|
+
## Image Generation (with Task Polling)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const task = await client.images.generate({ prompt: 'A sunset over mountains' });
|
|
60
|
+
const result = await task.wait();
|
|
61
|
+
console.log(result.image_url);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Error Handling
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { AceDataCloud, AuthenticationError, RateLimitError } from '@acedatacloud/sdk';
|
|
68
|
+
|
|
69
|
+
const client = new AceDataCloud({ apiToken: 'your-token' });
|
|
70
|
+
try {
|
|
71
|
+
await client.search.google({ q: 'test' });
|
|
72
|
+
} catch (err) {
|
|
73
|
+
if (err instanceof AuthenticationError) {
|
|
74
|
+
console.error('Invalid or expired token');
|
|
75
|
+
} else if (err instanceof RateLimitError) {
|
|
76
|
+
console.error('Too many requests');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Configuration
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const client = new AceDataCloud({
|
|
85
|
+
apiToken: 'your-token',
|
|
86
|
+
baseUrl: 'https://api.acedata.cloud',
|
|
87
|
+
platformBaseUrl: 'https://platform.acedata.cloud',
|
|
88
|
+
timeout: 300000, // ms
|
|
89
|
+
maxRetries: 2,
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The token can also be set via the `ACEDATACLOUD_API_TOKEN` environment variable.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Top-level AceDataCloud client for TypeScript. */
|
|
2
|
+
import { Chat } from './resources/chat';
|
|
3
|
+
import { Images } from './resources/images';
|
|
4
|
+
import { Audio } from './resources/audio';
|
|
5
|
+
import { Video } from './resources/video';
|
|
6
|
+
import { Search } from './resources/search';
|
|
7
|
+
import { Tasks } from './resources/tasks';
|
|
8
|
+
import { Files } from './resources/files';
|
|
9
|
+
import { Platform } from './resources/platform';
|
|
10
|
+
import { OpenAI } from './resources/openai';
|
|
11
|
+
export interface AceDataCloudOptions {
|
|
12
|
+
apiToken?: string;
|
|
13
|
+
baseURL?: string;
|
|
14
|
+
platformBaseURL?: string;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
maxRetries?: number;
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
export declare class AceDataCloud {
|
|
20
|
+
readonly chat: Chat;
|
|
21
|
+
readonly images: Images;
|
|
22
|
+
readonly audio: Audio;
|
|
23
|
+
readonly video: Video;
|
|
24
|
+
readonly search: Search;
|
|
25
|
+
readonly tasks: Tasks;
|
|
26
|
+
readonly files: Files;
|
|
27
|
+
readonly platform: Platform;
|
|
28
|
+
readonly openai: OpenAI;
|
|
29
|
+
private transport;
|
|
30
|
+
constructor(opts?: AceDataCloudOptions);
|
|
31
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Top-level AceDataCloud client for TypeScript. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.AceDataCloud = void 0;
|
|
5
|
+
const transport_1 = require("./runtime/transport");
|
|
6
|
+
const chat_1 = require("./resources/chat");
|
|
7
|
+
const images_1 = require("./resources/images");
|
|
8
|
+
const audio_1 = require("./resources/audio");
|
|
9
|
+
const video_1 = require("./resources/video");
|
|
10
|
+
const search_1 = require("./resources/search");
|
|
11
|
+
const tasks_1 = require("./resources/tasks");
|
|
12
|
+
const files_1 = require("./resources/files");
|
|
13
|
+
const platform_1 = require("./resources/platform");
|
|
14
|
+
const openai_1 = require("./resources/openai");
|
|
15
|
+
class AceDataCloud {
|
|
16
|
+
chat;
|
|
17
|
+
images;
|
|
18
|
+
audio;
|
|
19
|
+
video;
|
|
20
|
+
search;
|
|
21
|
+
tasks;
|
|
22
|
+
files;
|
|
23
|
+
platform;
|
|
24
|
+
openai;
|
|
25
|
+
transport;
|
|
26
|
+
constructor(opts = {}) {
|
|
27
|
+
this.transport = new transport_1.Transport({
|
|
28
|
+
apiToken: opts.apiToken,
|
|
29
|
+
baseURL: opts.baseURL,
|
|
30
|
+
platformBaseURL: opts.platformBaseURL,
|
|
31
|
+
timeout: opts.timeout,
|
|
32
|
+
maxRetries: opts.maxRetries,
|
|
33
|
+
headers: opts.headers,
|
|
34
|
+
});
|
|
35
|
+
this.chat = new chat_1.Chat(this.transport);
|
|
36
|
+
this.images = new images_1.Images(this.transport);
|
|
37
|
+
this.audio = new audio_1.Audio(this.transport);
|
|
38
|
+
this.video = new video_1.Video(this.transport);
|
|
39
|
+
this.search = new search_1.Search(this.transport);
|
|
40
|
+
this.tasks = new tasks_1.Tasks(this.transport);
|
|
41
|
+
this.files = new files_1.Files(this.transport);
|
|
42
|
+
this.platform = new platform_1.Platform(this.transport);
|
|
43
|
+
this.openai = new openai_1.OpenAI(this.transport);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.AceDataCloud = AceDataCloud;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** @acedatacloud/sdk — Official TypeScript SDK for AceDataCloud. */
|
|
2
|
+
export { AceDataCloud, AceDataCloudOptions } from './client';
|
|
3
|
+
export { AceDataCloudError, APIError, AuthenticationError, InsufficientBalanceError, ModerationError, RateLimitError, ResourceDisabledError, TimeoutError, TokenMismatchError, TransportError, ValidationError, } from './runtime/errors';
|
|
4
|
+
export { TaskHandle, TaskHandleOptions } from './runtime/tasks';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @acedatacloud/sdk — Official TypeScript SDK for AceDataCloud. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TaskHandle = exports.ValidationError = exports.TransportError = exports.TokenMismatchError = exports.TimeoutError = exports.ResourceDisabledError = exports.RateLimitError = exports.ModerationError = exports.InsufficientBalanceError = exports.AuthenticationError = exports.APIError = exports.AceDataCloudError = exports.AceDataCloud = void 0;
|
|
5
|
+
var client_1 = require("./client");
|
|
6
|
+
Object.defineProperty(exports, "AceDataCloud", { enumerable: true, get: function () { return client_1.AceDataCloud; } });
|
|
7
|
+
var errors_1 = require("./runtime/errors");
|
|
8
|
+
Object.defineProperty(exports, "AceDataCloudError", { enumerable: true, get: function () { return errors_1.AceDataCloudError; } });
|
|
9
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_1.APIError; } });
|
|
10
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
11
|
+
Object.defineProperty(exports, "InsufficientBalanceError", { enumerable: true, get: function () { return errors_1.InsufficientBalanceError; } });
|
|
12
|
+
Object.defineProperty(exports, "ModerationError", { enumerable: true, get: function () { return errors_1.ModerationError; } });
|
|
13
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
|
|
14
|
+
Object.defineProperty(exports, "ResourceDisabledError", { enumerable: true, get: function () { return errors_1.ResourceDisabledError; } });
|
|
15
|
+
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
|
|
16
|
+
Object.defineProperty(exports, "TokenMismatchError", { enumerable: true, get: function () { return errors_1.TokenMismatchError; } });
|
|
17
|
+
Object.defineProperty(exports, "TransportError", { enumerable: true, get: function () { return errors_1.TransportError; } });
|
|
18
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
19
|
+
var tasks_1 = require("./runtime/tasks");
|
|
20
|
+
Object.defineProperty(exports, "TaskHandle", { enumerable: true, get: function () { return tasks_1.TaskHandle; } });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Audio/music generation resources. */
|
|
2
|
+
import { Transport } from '../runtime/transport';
|
|
3
|
+
import { TaskHandle } from '../runtime/tasks';
|
|
4
|
+
export declare class Audio {
|
|
5
|
+
private transport;
|
|
6
|
+
constructor(transport: Transport);
|
|
7
|
+
generate(opts: {
|
|
8
|
+
prompt: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
tags?: string;
|
|
11
|
+
callbackUrl?: string;
|
|
12
|
+
wait?: boolean;
|
|
13
|
+
pollInterval?: number;
|
|
14
|
+
maxWait?: number;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}): Promise<Record<string, unknown> | TaskHandle>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Audio/music generation resources. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Audio = void 0;
|
|
5
|
+
const tasks_1 = require("../runtime/tasks");
|
|
6
|
+
class Audio {
|
|
7
|
+
transport;
|
|
8
|
+
constructor(transport) {
|
|
9
|
+
this.transport = transport;
|
|
10
|
+
}
|
|
11
|
+
async generate(opts) {
|
|
12
|
+
const { prompt, model, tags, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
|
|
13
|
+
const body = { prompt, ...rest };
|
|
14
|
+
if (model !== undefined)
|
|
15
|
+
body.model = model;
|
|
16
|
+
if (tags !== undefined)
|
|
17
|
+
body.tags = tags;
|
|
18
|
+
if (callbackUrl !== undefined)
|
|
19
|
+
body.callback_url = callbackUrl;
|
|
20
|
+
const result = await this.transport.request('POST', '/suno/audios', { json: body });
|
|
21
|
+
const taskId = result.task_id;
|
|
22
|
+
if (!taskId || (result.data && !shouldWait))
|
|
23
|
+
return result;
|
|
24
|
+
const handle = new tasks_1.TaskHandle(taskId, '/suno/tasks', this.transport);
|
|
25
|
+
if (shouldWait)
|
|
26
|
+
return handle.wait({ pollInterval, maxWait });
|
|
27
|
+
return handle;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Audio = Audio;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Chat resources — native provider APIs (Claude Messages). */
|
|
2
|
+
import { Transport } from '../runtime/transport';
|
|
3
|
+
export declare class Messages {
|
|
4
|
+
private transport;
|
|
5
|
+
constructor(transport: Transport);
|
|
6
|
+
create(opts: {
|
|
7
|
+
model: string;
|
|
8
|
+
messages: Array<Record<string, unknown>>;
|
|
9
|
+
maxTokens?: number;
|
|
10
|
+
stream?: false;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}): Promise<Record<string, unknown>>;
|
|
13
|
+
create(opts: {
|
|
14
|
+
model: string;
|
|
15
|
+
messages: Array<Record<string, unknown>>;
|
|
16
|
+
maxTokens?: number;
|
|
17
|
+
stream: true;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}): Promise<AsyncGenerator<Record<string, unknown>>>;
|
|
20
|
+
private stream;
|
|
21
|
+
countTokens(opts: {
|
|
22
|
+
model: string;
|
|
23
|
+
messages: Array<Record<string, unknown>>;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
}): Promise<Record<string, unknown>>;
|
|
26
|
+
}
|
|
27
|
+
export declare class Chat {
|
|
28
|
+
readonly messages: Messages;
|
|
29
|
+
constructor(transport: Transport);
|
|
30
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Chat resources — native provider APIs (Claude Messages). */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Chat = exports.Messages = void 0;
|
|
5
|
+
class Messages {
|
|
6
|
+
transport;
|
|
7
|
+
constructor(transport) {
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
}
|
|
10
|
+
async create(opts) {
|
|
11
|
+
const { model, messages, maxTokens = 4096, stream, ...rest } = opts;
|
|
12
|
+
const body = { model, messages, max_tokens: maxTokens, ...rest };
|
|
13
|
+
if (stream) {
|
|
14
|
+
body.stream = true;
|
|
15
|
+
return this.stream(body);
|
|
16
|
+
}
|
|
17
|
+
return this.transport.request('POST', '/v1/messages', { json: body });
|
|
18
|
+
}
|
|
19
|
+
async *stream(body) {
|
|
20
|
+
for await (const chunk of this.transport.requestStream('POST', '/v1/messages', { json: body })) {
|
|
21
|
+
yield JSON.parse(chunk);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async countTokens(opts) {
|
|
25
|
+
const { model, messages, ...rest } = opts;
|
|
26
|
+
return this.transport.request('POST', '/v1/messages/count_tokens', {
|
|
27
|
+
json: { model, messages, ...rest },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Messages = Messages;
|
|
32
|
+
class Chat {
|
|
33
|
+
messages;
|
|
34
|
+
constructor(transport) {
|
|
35
|
+
this.messages = new Messages(transport);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.Chat = Chat;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** File upload resources. */
|
|
2
|
+
import { Transport } from '../runtime/transport';
|
|
3
|
+
export declare class Files {
|
|
4
|
+
private transport;
|
|
5
|
+
constructor(transport: Transport);
|
|
6
|
+
upload(file: string | Buffer | Uint8Array, opts?: {
|
|
7
|
+
filename?: string;
|
|
8
|
+
}): Promise<Record<string, unknown>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** File upload resources. */
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.Files = void 0;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
class Files {
|
|
41
|
+
transport;
|
|
42
|
+
constructor(transport) {
|
|
43
|
+
this.transport = transport;
|
|
44
|
+
}
|
|
45
|
+
async upload(file, opts = {}) {
|
|
46
|
+
let data;
|
|
47
|
+
let filename;
|
|
48
|
+
if (typeof file === 'string') {
|
|
49
|
+
data = fs.readFileSync(file);
|
|
50
|
+
filename = opts.filename ?? path.basename(file);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
data = file;
|
|
54
|
+
filename = opts.filename ?? 'upload';
|
|
55
|
+
}
|
|
56
|
+
return this.transport.upload('/api/v1/files/', data, filename);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Files = Files;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Image generation resources. */
|
|
2
|
+
import { Transport } from '../runtime/transport';
|
|
3
|
+
import { TaskHandle } from '../runtime/tasks';
|
|
4
|
+
export declare class Images {
|
|
5
|
+
private transport;
|
|
6
|
+
constructor(transport: Transport);
|
|
7
|
+
generate(opts: {
|
|
8
|
+
prompt: string;
|
|
9
|
+
model?: string;
|
|
10
|
+
negativePrompt?: string;
|
|
11
|
+
imageUrl?: string;
|
|
12
|
+
callbackUrl?: string;
|
|
13
|
+
wait?: boolean;
|
|
14
|
+
pollInterval?: number;
|
|
15
|
+
maxWait?: number;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}): Promise<Record<string, unknown> | TaskHandle>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Image generation resources. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Images = void 0;
|
|
5
|
+
const tasks_1 = require("../runtime/tasks");
|
|
6
|
+
class Images {
|
|
7
|
+
transport;
|
|
8
|
+
constructor(transport) {
|
|
9
|
+
this.transport = transport;
|
|
10
|
+
}
|
|
11
|
+
async generate(opts) {
|
|
12
|
+
const { prompt, model, negativePrompt, imageUrl, callbackUrl, wait: shouldWait, pollInterval, maxWait, ...rest } = opts;
|
|
13
|
+
const body = { prompt, ...rest };
|
|
14
|
+
if (model !== undefined)
|
|
15
|
+
body.model = model;
|
|
16
|
+
if (negativePrompt !== undefined)
|
|
17
|
+
body.negative_prompt = negativePrompt;
|
|
18
|
+
if (imageUrl !== undefined)
|
|
19
|
+
body.image_url = imageUrl;
|
|
20
|
+
if (callbackUrl !== undefined)
|
|
21
|
+
body.callback_url = callbackUrl;
|
|
22
|
+
const result = await this.transport.request('POST', '/nano-banana/images', { json: body });
|
|
23
|
+
const taskId = result.task_id;
|
|
24
|
+
if (!taskId || (result.data && !shouldWait))
|
|
25
|
+
return result;
|
|
26
|
+
const handle = new tasks_1.TaskHandle(taskId, '/nano-banana/tasks', this.transport);
|
|
27
|
+
if (shouldWait)
|
|
28
|
+
return handle.wait({ pollInterval, maxWait });
|
|
29
|
+
return handle;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Images = Images;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** OpenAI-compatible facade resources. */
|
|
2
|
+
import { Transport } from '../runtime/transport';
|
|
3
|
+
declare class Completions {
|
|
4
|
+
private transport;
|
|
5
|
+
constructor(transport: Transport);
|
|
6
|
+
create(opts: {
|
|
7
|
+
model: string;
|
|
8
|
+
messages: Array<Record<string, unknown>>;
|
|
9
|
+
stream?: false;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}): Promise<Record<string, unknown>>;
|
|
12
|
+
create(opts: {
|
|
13
|
+
model: string;
|
|
14
|
+
messages: Array<Record<string, unknown>>;
|
|
15
|
+
stream: true;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}): Promise<AsyncGenerator<Record<string, unknown>>>;
|
|
18
|
+
private streamResponse;
|
|
19
|
+
}
|
|
20
|
+
declare class ChatNamespace {
|
|
21
|
+
readonly completions: Completions;
|
|
22
|
+
constructor(transport: Transport);
|
|
23
|
+
}
|
|
24
|
+
declare class Responses {
|
|
25
|
+
private transport;
|
|
26
|
+
constructor(transport: Transport);
|
|
27
|
+
create(opts: {
|
|
28
|
+
model: string;
|
|
29
|
+
input: string | Array<Record<string, unknown>>;
|
|
30
|
+
stream?: false;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}): Promise<Record<string, unknown>>;
|
|
33
|
+
create(opts: {
|
|
34
|
+
model: string;
|
|
35
|
+
input: string | Array<Record<string, unknown>>;
|
|
36
|
+
stream: true;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}): Promise<AsyncGenerator<Record<string, unknown>>>;
|
|
39
|
+
private streamResponse;
|
|
40
|
+
}
|
|
41
|
+
export declare class OpenAI {
|
|
42
|
+
readonly chat: ChatNamespace;
|
|
43
|
+
readonly responses: Responses;
|
|
44
|
+
constructor(transport: Transport);
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** OpenAI-compatible facade resources. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.OpenAI = void 0;
|
|
5
|
+
class Completions {
|
|
6
|
+
transport;
|
|
7
|
+
constructor(transport) {
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
}
|
|
10
|
+
async create(opts) {
|
|
11
|
+
const { model, messages, stream, ...rest } = opts;
|
|
12
|
+
const body = { model, messages, ...rest };
|
|
13
|
+
if (stream) {
|
|
14
|
+
body.stream = true;
|
|
15
|
+
return this.streamResponse(body);
|
|
16
|
+
}
|
|
17
|
+
return this.transport.request('POST', '/v1/chat/completions', { json: body });
|
|
18
|
+
}
|
|
19
|
+
async *streamResponse(body) {
|
|
20
|
+
for await (const chunk of this.transport.requestStream('POST', '/v1/chat/completions', { json: body })) {
|
|
21
|
+
yield JSON.parse(chunk);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
class ChatNamespace {
|
|
26
|
+
completions;
|
|
27
|
+
constructor(transport) {
|
|
28
|
+
this.completions = new Completions(transport);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class Responses {
|
|
32
|
+
transport;
|
|
33
|
+
constructor(transport) {
|
|
34
|
+
this.transport = transport;
|
|
35
|
+
}
|
|
36
|
+
async create(opts) {
|
|
37
|
+
const { model, input, stream, ...rest } = opts;
|
|
38
|
+
const body = { model, input, ...rest };
|
|
39
|
+
if (stream) {
|
|
40
|
+
body.stream = true;
|
|
41
|
+
return this.streamResponse(body);
|
|
42
|
+
}
|
|
43
|
+
return this.transport.request('POST', '/openai/responses', { json: body });
|
|
44
|
+
}
|
|
45
|
+
async *streamResponse(body) {
|
|
46
|
+
for await (const chunk of this.transport.requestStream('POST', '/openai/responses', { json: body })) {
|
|
47
|
+
yield JSON.parse(chunk);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class OpenAI {
|
|
52
|
+
chat;
|
|
53
|
+
responses;
|
|
54
|
+
constructor(transport) {
|
|
55
|
+
this.chat = new ChatNamespace(transport);
|
|
56
|
+
this.responses = new Responses(transport);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.OpenAI = OpenAI;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Management-plane resources. */
|
|
2
|
+
import { Transport } from '../runtime/transport';
|
|
3
|
+
declare class Applications {
|
|
4
|
+
private transport;
|
|
5
|
+
constructor(transport: Transport);
|
|
6
|
+
list(params?: Record<string, string>): Promise<Record<string, unknown>>;
|
|
7
|
+
create(opts: {
|
|
8
|
+
serviceId: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}): Promise<Record<string, unknown>>;
|
|
11
|
+
get(applicationId: string): Promise<Record<string, unknown>>;
|
|
12
|
+
}
|
|
13
|
+
declare class Credentials {
|
|
14
|
+
private transport;
|
|
15
|
+
constructor(transport: Transport);
|
|
16
|
+
list(params?: Record<string, string>): Promise<Record<string, unknown>>;
|
|
17
|
+
create(opts: {
|
|
18
|
+
applicationId: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}): Promise<Record<string, unknown>>;
|
|
21
|
+
rotate(credentialId: string): Promise<Record<string, unknown>>;
|
|
22
|
+
delete(credentialId: string): Promise<Record<string, unknown>>;
|
|
23
|
+
}
|
|
24
|
+
declare class Models {
|
|
25
|
+
private transport;
|
|
26
|
+
constructor(transport: Transport);
|
|
27
|
+
list(params?: Record<string, string>): Promise<Record<string, unknown>>;
|
|
28
|
+
}
|
|
29
|
+
declare class Config {
|
|
30
|
+
private transport;
|
|
31
|
+
constructor(transport: Transport);
|
|
32
|
+
get(): Promise<Record<string, unknown>>;
|
|
33
|
+
}
|
|
34
|
+
export declare class Platform {
|
|
35
|
+
readonly applications: Applications;
|
|
36
|
+
readonly credentials: Credentials;
|
|
37
|
+
readonly models: Models;
|
|
38
|
+
readonly config: Config;
|
|
39
|
+
constructor(transport: Transport);
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Management-plane resources. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Platform = void 0;
|
|
5
|
+
class Applications {
|
|
6
|
+
transport;
|
|
7
|
+
constructor(transport) {
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
}
|
|
10
|
+
async list(params) {
|
|
11
|
+
return this.transport.request('GET', '/api/v1/applications/', { params, platform: true });
|
|
12
|
+
}
|
|
13
|
+
async create(opts) {
|
|
14
|
+
const { serviceId, ...rest } = opts;
|
|
15
|
+
return this.transport.request('POST', '/api/v1/applications/', {
|
|
16
|
+
json: { service_id: serviceId, ...rest },
|
|
17
|
+
platform: true,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async get(applicationId) {
|
|
21
|
+
return this.transport.request('GET', `/api/v1/applications/${applicationId}/`, { platform: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class Credentials {
|
|
25
|
+
transport;
|
|
26
|
+
constructor(transport) {
|
|
27
|
+
this.transport = transport;
|
|
28
|
+
}
|
|
29
|
+
async list(params) {
|
|
30
|
+
return this.transport.request('GET', '/api/v1/credentials/', { params, platform: true });
|
|
31
|
+
}
|
|
32
|
+
async create(opts) {
|
|
33
|
+
const { applicationId, ...rest } = opts;
|
|
34
|
+
return this.transport.request('POST', '/api/v1/credentials/', {
|
|
35
|
+
json: { application_id: applicationId, ...rest },
|
|
36
|
+
platform: true,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async rotate(credentialId) {
|
|
40
|
+
return this.transport.request('POST', `/api/v1/credentials/${credentialId}/rotate/`, { platform: true });
|
|
41
|
+
}
|
|
42
|
+
async delete(credentialId) {
|
|
43
|
+
return this.transport.request('DELETE', `/api/v1/credentials/${credentialId}/`, { platform: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class Models {
|
|
47
|
+
transport;
|
|
48
|
+
constructor(transport) {
|
|
49
|
+
this.transport = transport;
|
|
50
|
+
}
|
|
51
|
+
async list(params) {
|
|
52
|
+
return this.transport.request('GET', '/api/v1/models/', { params, platform: true });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
class Config {
|
|
56
|
+
transport;
|
|
57
|
+
constructor(transport) {
|
|
58
|
+
this.transport = transport;
|
|
59
|
+
}
|
|
60
|
+
async get() {
|
|
61
|
+
return this.transport.request('GET', '/api/v1/config/', { platform: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class Platform {
|
|
65
|
+
applications;
|
|
66
|
+
credentials;
|
|
67
|
+
models;
|
|
68
|
+
config;
|
|
69
|
+
constructor(transport) {
|
|
70
|
+
this.applications = new Applications(transport);
|
|
71
|
+
this.credentials = new Credentials(transport);
|
|
72
|
+
this.models = new Models(transport);
|
|
73
|
+
this.config = new Config(transport);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Platform = Platform;
|