@mynthio/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 +197 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/convex/index.d.ts +51 -0
- package/dist/convex/index.d.ts.map +1 -0
- package/dist/convex/index.js +2 -0
- package/dist/convex/utils.d.ts +17 -0
- package/dist/convex/utils.d.ts.map +1 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/task-async.d.ts +79 -0
- package/dist/task-async.d.ts.map +1 -0
- package/dist/task.d.ts +58 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/types.d.ts +272 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# @mynthio/sdk
|
|
2
|
+
|
|
3
|
+
Official SDK for the [Mynth](https://mynth.io) AI image generation API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
// Bun
|
|
9
|
+
bun add @mynthio/sdk
|
|
10
|
+
|
|
11
|
+
// PNPM
|
|
12
|
+
pnpm add @mynthio/sdk
|
|
13
|
+
|
|
14
|
+
// NPM
|
|
15
|
+
npm install @mynthio/sdk
|
|
16
|
+
|
|
17
|
+
// Yarn
|
|
18
|
+
yarn add @mynthio/sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
Add `MYNTH_API_KEY` to your environment variables:
|
|
24
|
+
|
|
25
|
+
```env
|
|
26
|
+
MYNTH_API_KEY=mak_...
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Create mynth client. For example inside `/lib`
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// lib/mynth.ts
|
|
33
|
+
import Mynth from "@mynthio/sdk";
|
|
34
|
+
|
|
35
|
+
export const mynth = new Mynth();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Use client to generate images:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { mynth } from "./lib/mynth";
|
|
42
|
+
|
|
43
|
+
// Generate an image (by default it waits for completion)
|
|
44
|
+
const task = await mynth.generate({
|
|
45
|
+
prompt: "A beautiful sunset over mountains",
|
|
46
|
+
model: "black-forest-labs/flux.1-dev",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.log(task.result.images);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Under the hood we poll for the status of the task, waiting until it's completed. When it's done, the `Task` instance is returned.
|
|
53
|
+
|
|
54
|
+
## Async Mode
|
|
55
|
+
|
|
56
|
+
Sometimes you don't want to wait for the task, and you just want to trigger generation. For example:
|
|
57
|
+
|
|
58
|
+
- You use webhooks to save data, and you just trigger generation
|
|
59
|
+
- You want to poll for images on client side
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { mynth } from "./lib/mynth";
|
|
63
|
+
|
|
64
|
+
const taskAsync = await mynth.generate(
|
|
65
|
+
{
|
|
66
|
+
prompt: "A futuristic cityscape",
|
|
67
|
+
model: "black-forest-labs/flux.1-dev",
|
|
68
|
+
},
|
|
69
|
+
{ mode: "async" },
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
console.log("Task started:", taskAsync.id);
|
|
73
|
+
|
|
74
|
+
// If you want to to get the result later, use .toTask()
|
|
75
|
+
const completedTask = await taskAsync.toTask();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Async mode is especially useful for a client side polling. We support public access tokens, and fetching statuses from client side:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { mynth } from "./lib/mynth";
|
|
82
|
+
|
|
83
|
+
const taskAsync = await mynth.generate(
|
|
84
|
+
{
|
|
85
|
+
prompt: "A futuristic cityscape",
|
|
86
|
+
model: "black-forest-labs/flux.1-dev",
|
|
87
|
+
},
|
|
88
|
+
{ mode: "async" },
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
id: taskAsync.id,
|
|
93
|
+
access: taskAsync.access;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// In frontend:
|
|
97
|
+
// TODO: Do proper example for SWR
|
|
98
|
+
const { data, error, isLoading } = useSWR(`/api/tasks/${response.id}/images`, fetcher, {
|
|
99
|
+
refreshInterval: 1000 // Poll every 1 second
|
|
100
|
+
// Token
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Available Models
|
|
105
|
+
|
|
106
|
+
We provide a helpful object with all supported models, including display names and capabilities so you can use it for validation or generating UIs.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { AVAILABLE_MODELS } from "@mynthio/sdk";
|
|
110
|
+
|
|
111
|
+
console.log(AVAILABLE_MODELS);
|
|
112
|
+
// [
|
|
113
|
+
// {
|
|
114
|
+
// id: "black-forest-labs/flux.1-dev",
|
|
115
|
+
// label: "FLUX.1 Dev",
|
|
116
|
+
// capabilities: ["magic_prompt", "steps"],
|
|
117
|
+
// },
|
|
118
|
+
// ...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Request Options
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
const task = await mynth.generate({
|
|
125
|
+
prompt: {
|
|
126
|
+
positive: "A serene lake at dawn",
|
|
127
|
+
negative: "people, buildings", // Will be used only if supported by model
|
|
128
|
+
magic: false, // Default `true`
|
|
129
|
+
},
|
|
130
|
+
model: "black-forest-labs/flux.1-dev",
|
|
131
|
+
size: "landscape", //Default: "auto", Examples: "portrait", "square", "instagram", { width: 1024, height: 768 }
|
|
132
|
+
count: 1, // Default 1
|
|
133
|
+
output: {
|
|
134
|
+
format: "webp", // Default "webp", Examples: "png", "jpg", "webp"
|
|
135
|
+
quality: 80,
|
|
136
|
+
upscale: 2, // 2x or 4x upscaling
|
|
137
|
+
},
|
|
138
|
+
webhook: {
|
|
139
|
+
enabled: true, // Setting to false will disable webhooks set in dashboard and webhooks configured as `custom` in request
|
|
140
|
+
custom: [{ url: "https://your-webhook.com/endpoint" }],
|
|
141
|
+
},
|
|
142
|
+
/**
|
|
143
|
+
* Single level deep metadata you can attach. It will be send with webhook and returned with result.
|
|
144
|
+
*/
|
|
145
|
+
metadata: {
|
|
146
|
+
internalGenerationId: "gen_123",
|
|
147
|
+
userId: "user_...",
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Convex Integration
|
|
153
|
+
|
|
154
|
+
The SDK includes a Convex webhook handler for easy integration:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { mynthWebhookAction } from "@mynthio/sdk/convex";
|
|
158
|
+
|
|
159
|
+
export const mynthWebhook = mynthWebhookAction({
|
|
160
|
+
imageTaskCompleted: async (payload, { context }) => {
|
|
161
|
+
console.log("Image generated:", payload.result.images);
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Set `MYNTH_WEBHOOK_SECRET` in your environment variables.
|
|
167
|
+
|
|
168
|
+
## Error Handling
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import {
|
|
172
|
+
Mynth,
|
|
173
|
+
TaskAsyncTimeoutError,
|
|
174
|
+
TaskAsyncUnauthorizedError,
|
|
175
|
+
TaskAsyncFetchError,
|
|
176
|
+
} from "@mynthio/sdk";
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
const task = await mynth.generate({ ... });
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (error instanceof TaskAsyncTimeoutError) {
|
|
182
|
+
console.error("Task polling timed out");
|
|
183
|
+
} else if (error instanceof TaskAsyncUnauthorizedError) {
|
|
184
|
+
console.error("Invalid API key or access denied");
|
|
185
|
+
} else if (error instanceof TaskAsyncFetchError) {
|
|
186
|
+
console.error("Network error while polling task status");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Documentation
|
|
192
|
+
|
|
193
|
+
For full documentation, visit [docs.mynth.io](https://docs.mynth.io).
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when an API request fails.
|
|
3
|
+
*/
|
|
4
|
+
export declare class MynthAPIError extends Error {
|
|
5
|
+
/** HTTP status code of the failed request */
|
|
6
|
+
readonly status: number;
|
|
7
|
+
/** Error code from the API response, if available */
|
|
8
|
+
readonly code?: string;
|
|
9
|
+
constructor(message: string, status: number, code?: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Internal HTTP client for making API requests.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare class MynthClient {
|
|
16
|
+
private readonly apiKey;
|
|
17
|
+
private readonly baseUrl;
|
|
18
|
+
constructor(options: {
|
|
19
|
+
apiKey: string;
|
|
20
|
+
baseUrl?: string;
|
|
21
|
+
});
|
|
22
|
+
getAuthHeaders(override?: {
|
|
23
|
+
accessToken?: string;
|
|
24
|
+
}): {
|
|
25
|
+
Authorization: string;
|
|
26
|
+
};
|
|
27
|
+
getUrl(path: string): string;
|
|
28
|
+
post<DataType>(path: string, data: unknown): Promise<DataType>;
|
|
29
|
+
get<DataType>(path: string, { headers, accessToken, }?: {
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
accessToken?: string;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
data: DataType;
|
|
34
|
+
status: number;
|
|
35
|
+
ok: boolean;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export { MynthClient };
|
|
39
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,6CAA6C;IAC7C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,qDAAqD;IACrD,SAAgB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAElB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM;CAM3D;AAQD;;;GAGG;AACH,cAAM,WAAW;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IASzD,cAAc,CAAC,QAAQ,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE;;;IAMlD,MAAM,CAAC,IAAI,EAAE,MAAM;IAIN,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAwB9D,GAAG,CAAC,QAAQ,EACvB,IAAI,EAAE,MAAM,EACZ,EACE,OAAO,EACP,WAAW,GACZ,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO,GACjE,OAAO,CAAC;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,OAAO,CAAA;KAAE,CAAC;CAY5D;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Base URL for the Mynth API */
|
|
2
|
+
export declare const API_URL = "https://api.mynth.io";
|
|
3
|
+
/** Environment variable name for the API key */
|
|
4
|
+
export declare const API_KEY_ENV_VAR = "MYNTH_API_KEY";
|
|
5
|
+
export declare const GENERATE_IMAGE_PATH = "/image/generate";
|
|
6
|
+
export declare const TASK_PATH = "/tasks";
|
|
7
|
+
export declare const TASK_DETAILS_PATH: (id: string) => string;
|
|
8
|
+
export declare const TASK_STATUS_PATH: (id: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Model capabilities that affect available generation options.
|
|
11
|
+
* - `magic_prompt`: Supports automatic prompt enhancement
|
|
12
|
+
* - `negative_prompt`: Supports negative prompts to exclude elements
|
|
13
|
+
* - `steps`: Supports custom inference step count
|
|
14
|
+
*/
|
|
15
|
+
export type ModelCapability = "magic_prompt" | "negative_prompt" | "steps";
|
|
16
|
+
/**
|
|
17
|
+
* Information about an available image generation model.
|
|
18
|
+
*/
|
|
19
|
+
export type AvailableModel = {
|
|
20
|
+
/** Unique model identifier used in API requests */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Human-readable display name */
|
|
23
|
+
label: string;
|
|
24
|
+
/** List of supported capabilities */
|
|
25
|
+
capabilities: readonly ModelCapability[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* List of all available image generation models with their capabilities.
|
|
29
|
+
* Use this to build model selectors or validate model IDs.
|
|
30
|
+
*/
|
|
31
|
+
export declare const AVAILABLE_MODELS: readonly AvailableModel[];
|
|
32
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,eAAO,MAAM,OAAO,yBAAyB,CAAC;AAE9C,gDAAgD;AAChD,eAAO,MAAM,eAAe,kBAAkB,CAAC;AAE/C,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AACrD,eAAO,MAAM,SAAS,WAAW,CAAC;AAClC,eAAO,MAAM,iBAAiB,GAAI,IAAI,MAAM,WAAyB,CAAC;AACtE,eAAO,MAAM,gBAAgB,GAAI,IAAI,MAAM,WAAgC,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,iBAAiB,GAAG,OAAO,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,YAAY,EAAE,SAAS,eAAe,EAAE,CAAC;CAC1C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,cAAc,EA8CrD,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { GenericActionCtx } from "convex/server";
|
|
2
|
+
import type { MynthSDKTypes } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Event handlers for Mynth webhook events.
|
|
5
|
+
*/
|
|
6
|
+
export type EventHandlers<T extends GenericActionCtx<any> = GenericActionCtx<any>> = {
|
|
7
|
+
/** Called when an image generation task completes successfully */
|
|
8
|
+
imageTaskCompleted?: (payload: MynthSDKTypes.WebhookTaskImageCompletedPayload, context: {
|
|
9
|
+
context: T;
|
|
10
|
+
request: Request;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
/** Called when an image generation task fails */
|
|
13
|
+
imageTaskFailed?: (payload: MynthSDKTypes.WebhookTaskImageFailedPayload, context: {
|
|
14
|
+
context: T;
|
|
15
|
+
request: Request;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Options for configuring the webhook action.
|
|
20
|
+
*/
|
|
21
|
+
export type MynthWebhookActionOptions = {
|
|
22
|
+
/** Webhook secret for signature verification. Defaults to MYNTH_WEBHOOK_SECRET env var. */
|
|
23
|
+
webhookSecret?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates a Convex HTTP action handler for Mynth webhooks.
|
|
27
|
+
*
|
|
28
|
+
* @param eventHandlers - Handlers for different webhook events
|
|
29
|
+
* @param options - Configuration options
|
|
30
|
+
* @returns A Convex HTTP action handler
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // In convex/http.ts
|
|
35
|
+
* import { mynthWebhookAction } from "@mynthio/sdk/convex";
|
|
36
|
+
*
|
|
37
|
+
* export const mynthWebhook = mynthWebhookAction({
|
|
38
|
+
* imageTaskCompleted: async (payload, { context }) => {
|
|
39
|
+
* await context.runMutation(internal.images.save, {
|
|
40
|
+
* taskId: payload.task.id,
|
|
41
|
+
* images: payload.result.images,
|
|
42
|
+
* });
|
|
43
|
+
* },
|
|
44
|
+
* imageTaskFailed: async (payload, { context }) => {
|
|
45
|
+
* console.error("Task failed:", payload.errors);
|
|
46
|
+
* },
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const mynthWebhookAction: (eventHandlers: EventHandlers, options?: MynthWebhookActionOptions) => (ctx: GenericActionCtx<any>, request: Request) => Promise<Response>;
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/convex/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAO9C;;GAEG;AAEH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,gBAAgB,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI;IACnF,kEAAkE;IAClE,kBAAkB,CAAC,EAAE,CACnB,OAAO,EAAE,aAAa,CAAC,gCAAgC,EACvD,OAAO,EAAE;QAAE,OAAO,EAAE,CAAC,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,KACtC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,iDAAiD;IACjD,eAAe,CAAC,EAAE,CAChB,OAAO,EAAE,aAAa,CAAC,6BAA6B,EACpD,OAAO,EAAE;QAAE,OAAO,EAAE,CAAC,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,KACtC,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,2FAA2F;IAC3F,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,kBAAkB,GAC7B,eAAe,aAAa,EAC5B,UAAU,yBAAyB,MAcjC,KAAK,gBAAgB,CAAC,GAAG,CAAC,EAC1B,SAAS,OAAO,KACf,OAAO,CAAC,QAAQ,CAyCpB,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var $=()=>{if(typeof process<"u"&&process.env)return process.env.MYNTH_WEBHOOK_SECRET;return};function I(J){let L=J.split(","),z,j;for(let M of L){let[P,Q]=M.split("=");if(P==="t")z=Q;else if(P==="v1")j=Q}if(!z||!j)return null;return{timestamp:z,signature:j}}async function C(J,L,z){let j=I(L);if(!j)return!1;let{timestamp:M,signature:P}=j,Q=`${M}.${J}`,X=new TextEncoder,Z=await crypto.subtle.importKey("raw",X.encode(z),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),Y=await crypto.subtle.sign("HMAC",Z,X.encode(Q)),F=U(new Uint8Array(Y));return V(F,P)}function U(J){let L="";for(let z of J)L+=z.toString(16).padStart(2,"0");return L}function V(J,L){if(J.length!==L.length)return!1;let z=0;for(let j=0;j<J.length;j++)z|=J.charCodeAt(j)^L.charCodeAt(j);return z===0}var B="X-Mynth-Event",D="X-Mynth-Signature",N=(J,L)=>{let z=L?.webhookSecret??$();if(!z)throw Error("MYNTH_WEBHOOK_SECRET is required. Either pass it as an option or set the environment variable.");return async(j,M)=>{let P=M.headers.get(D);if(!P)return new Response("Unauthorized",{status:401});if(!M.headers.get(B))return new Response("Unauthorized",{status:401});let X=await M.text();if(!await C(X,P,z))return new Response("Unauthorized",{status:401});let Y=JSON.parse(X);switch(Y.event){case"task.image.completed":await J.imageTaskCompleted?.(Y,{context:j,request:M});break;case"task.image.failed":await J.imageTaskFailed?.(Y,{context:j,request:M});break;default:return new Response("Unauthorized",{status:401})}return new Response(void 0,{status:200})}};export{N as mynthWebhookAction};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attempts to read the webhook secret from environment variables.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const tryToGetWebhookSecretFromEnv: () => string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Verifies the HMAC-SHA256 signature of a webhook payload.
|
|
8
|
+
* Uses timing-safe comparison to prevent timing attacks.
|
|
9
|
+
*
|
|
10
|
+
* @param body - The raw request body
|
|
11
|
+
* @param signatureHeader - The X-Mynth-Signature header value
|
|
12
|
+
* @param secret - The webhook secret
|
|
13
|
+
* @returns True if the signature is valid
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function verifySignature(body: string, signatureHeader: string, secret: string): Promise<boolean>;
|
|
17
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/convex/utils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,4BAA4B,QAAO,MAAM,GAAG,SAKxD,CAAC;AA8BF;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,MAAM,EACZ,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAyBlB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { MynthAPIError } from "./client";
|
|
2
|
+
import type { AvailableModel, ModelCapability } from "./constants";
|
|
3
|
+
import { AVAILABLE_MODELS } from "./constants";
|
|
4
|
+
import type { Task } from "./task";
|
|
5
|
+
import type { TaskAsyncAccess } from "./task-async";
|
|
6
|
+
import { TaskAsync, TaskAsyncFetchError, TaskAsyncTaskFailedError, TaskAsyncTaskFetchError, TaskAsyncTimeoutError, TaskAsyncUnauthorizedError } from "./task-async";
|
|
7
|
+
import type { MynthSDKTypes } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Options for the generate method.
|
|
10
|
+
*/
|
|
11
|
+
type GenerateOptions = {
|
|
12
|
+
/** Whether to wait for completion ("sync") or return immediately ("async") */
|
|
13
|
+
mode?: "sync" | "async";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Configuration options for the Mynth client.
|
|
17
|
+
*/
|
|
18
|
+
type MynthOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Your Mynth API key. If not provided, reads from MYNTH_API_KEY environment variable.
|
|
21
|
+
*/
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Custom base URL for the API. Useful for proxies or testing.
|
|
25
|
+
*/
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
};
|
|
28
|
+
type ExtractMetadata<T extends MynthSDKTypes.ImageGenerationRequest> = T["metadata"];
|
|
29
|
+
type ExtractContentRatingConfig<T extends MynthSDKTypes.ImageGenerationRequest> = T["content_rating"];
|
|
30
|
+
type ExtractContentRatingLevels<T extends MynthSDKTypes.ImageGenerationRequest> = ExtractContentRatingConfig<T> extends {
|
|
31
|
+
levels: readonly (infer L)[];
|
|
32
|
+
} ? L : ExtractContentRatingConfig<T> extends {
|
|
33
|
+
levels: (infer L)[];
|
|
34
|
+
} ? L : never;
|
|
35
|
+
type ExtractContentRatingLevelValues<T extends MynthSDKTypes.ImageGenerationRequest> = ExtractContentRatingLevels<T> extends {
|
|
36
|
+
value: infer V;
|
|
37
|
+
} ? V extends string ? V : never : never;
|
|
38
|
+
type IsContentRatingCustom<T extends MynthSDKTypes.ImageGenerationRequest> = ExtractContentRatingConfig<T> extends {
|
|
39
|
+
levels: readonly any[] | any[];
|
|
40
|
+
} ? true : false;
|
|
41
|
+
type ExtractContentRatingResponse<T extends MynthSDKTypes.ImageGenerationRequest> = IsContentRatingCustom<T> extends true ? {
|
|
42
|
+
mode: "custom";
|
|
43
|
+
level: ExtractContentRatingLevelValues<T>;
|
|
44
|
+
} : ExtractContentRatingConfig<T> extends {
|
|
45
|
+
enabled?: true;
|
|
46
|
+
} ? {
|
|
47
|
+
mode: "default";
|
|
48
|
+
level: MynthSDKTypes.ImageResultContentRatingDefaultLevel;
|
|
49
|
+
} : MynthSDKTypes.ImageResultContentRating | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Main client for interacting with the Mynth image generation API.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Using environment variable (MYNTH_API_KEY)
|
|
56
|
+
* const mynth = new Mynth();
|
|
57
|
+
*
|
|
58
|
+
* // Or with explicit API key
|
|
59
|
+
* const mynth = new Mynth({ apiKey: "mak_..." });
|
|
60
|
+
*
|
|
61
|
+
* // Generate an image
|
|
62
|
+
* const task = await mynth.generate({
|
|
63
|
+
* prompt: "A beautiful sunset over mountains",
|
|
64
|
+
* model: "black-forest-labs/flux.1-dev",
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* console.log(task.urls); // ["https://..."]
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
declare class Mynth {
|
|
71
|
+
private readonly client;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new Mynth client instance.
|
|
74
|
+
*
|
|
75
|
+
* @param options - Configuration options
|
|
76
|
+
* @param options.apiKey - Your API key (defaults to MYNTH_API_KEY env var)
|
|
77
|
+
* @param options.baseUrl - Custom API base URL
|
|
78
|
+
* @throws {Error} If no API key is provided and MYNTH_API_KEY is not set
|
|
79
|
+
*/
|
|
80
|
+
constructor(options?: MynthOptions);
|
|
81
|
+
/**
|
|
82
|
+
* Generate images from a text prompt.
|
|
83
|
+
*
|
|
84
|
+
* @param request - Image generation request parameters
|
|
85
|
+
* @returns A completed Task with the generation results
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const task = await mynth.generate({
|
|
90
|
+
* prompt: "A serene lake at dawn",
|
|
91
|
+
* model: "black-forest-labs/flux.1-dev",
|
|
92
|
+
* });
|
|
93
|
+
* console.log(task.urls);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
generate<const T extends MynthSDKTypes.ImageGenerationRequest>(request: T): Promise<Task<ExtractMetadata<T>, ExtractContentRatingResponse<T>>>;
|
|
97
|
+
/**
|
|
98
|
+
* Generate images asynchronously without waiting for completion.
|
|
99
|
+
*
|
|
100
|
+
* @param request - Image generation request parameters
|
|
101
|
+
* @param opts - Options with mode set to "async"
|
|
102
|
+
* @returns A TaskAsync that can be polled for completion
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const taskAsync = await mynth.generate(
|
|
107
|
+
* { prompt: "A futuristic cityscape" },
|
|
108
|
+
* { mode: "async" }
|
|
109
|
+
* );
|
|
110
|
+
*
|
|
111
|
+
* // Return task ID for client-side polling
|
|
112
|
+
* return { id: taskAsync.id, access: taskAsync.access };
|
|
113
|
+
*
|
|
114
|
+
* // Or wait for completion later
|
|
115
|
+
* const task = await taskAsync.toTask();
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
generate<const T extends MynthSDKTypes.ImageGenerationRequest>(request: T, opts: {
|
|
119
|
+
mode: "async";
|
|
120
|
+
}): Promise<TaskAsync<ExtractMetadata<T>, ExtractContentRatingResponse<T>>>;
|
|
121
|
+
/**
|
|
122
|
+
* Generate images synchronously, waiting for completion.
|
|
123
|
+
*
|
|
124
|
+
* @param request - Image generation request parameters
|
|
125
|
+
* @param opts - Options with mode set to "sync"
|
|
126
|
+
* @returns A completed Task with the generation results
|
|
127
|
+
*/
|
|
128
|
+
generate<const T extends MynthSDKTypes.ImageGenerationRequest>(request: T, opts: {
|
|
129
|
+
mode: "sync";
|
|
130
|
+
}): Promise<Task<ExtractMetadata<T>, ExtractContentRatingResponse<T>>>;
|
|
131
|
+
}
|
|
132
|
+
export { Mynth, AVAILABLE_MODELS, MynthAPIError, TaskAsyncTimeoutError, TaskAsyncUnauthorizedError, TaskAsyncFetchError, TaskAsyncTaskFetchError, TaskAsyncTaskFailedError, };
|
|
133
|
+
export type { MynthSDKTypes, MynthOptions, GenerateOptions, TaskAsyncAccess, AvailableModel, ModelCapability, };
|
|
134
|
+
export default Mynth;
|
|
135
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAEL,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,8EAA8E;IAC9E,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,KAAK,YAAY,GAAG;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC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,eAAe,GAChB,CAAC;AACF,eAAe,KAAK,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var V="https://api.mynth.io",X="MYNTH_API_KEY",b="/image/generate";var v=(J)=>`/tasks/${J}`,G=(J)=>`/tasks/${J}/status`,P=[{id:"auto",label:"Auto",capabilities:[]},{id:"black-forest-labs/flux.1-dev",label:"FLUX.1 Dev",capabilities:["magic_prompt","steps"]},{id:"black-forest-labs/flux-1-schnell",label:"FLUX.1 Schnell",capabilities:["magic_prompt"]},{id:"tongyi-mai/z-image-turbo",label:"Z Image Turbo",capabilities:["magic_prompt","steps"]},{id:"black-forest-labs/flux.2-dev",label:"FLUX.2 Dev",capabilities:["magic_prompt","steps"]},{id:"john6666/bismuth-illustrious-mix",label:"Bismuth Illustrious Mix",capabilities:["magic_prompt","negative_prompt","steps"]},{id:"google/gemini-3-pro-image-preview",label:"Nano Banana Pro",capabilities:[]},{id:"wan/wan2.6-image",label:"Wan 2.6 Image",capabilities:[]},{id:"xai/grok-imagine-image",label:"Grok Imagine Image",capabilities:[]}];class Y extends Error{status;code;constructor(J,Q,Z){super(J);this.name="MynthAPIError",this.status=Q,this.code=Z}}class H{apiKey;baseUrl;constructor(J){this.apiKey=J.apiKey,this.baseUrl=J.baseUrl?J.baseUrl.endsWith("/")?J.baseUrl.slice(0,-1):J.baseUrl:V}getAuthHeaders(J){return{Authorization:`Bearer ${J?.accessToken??this.apiKey}`}}getUrl(J){return`${this.baseUrl}${J}`}async post(J,Q){let Z=await fetch(this.getUrl(J),{method:"POST",headers:{"Content-Type":"application/json",...this.getAuthHeaders()},body:JSON.stringify(Q)}),$=await Z.json();if(!Z.ok){let x=$,B=x.error||x.message||`Request failed with status ${Z.status}`;throw new Y(B,Z.status,x.code)}return $}async get(J,{headers:Q,accessToken:Z}={}){let $=await fetch(this.getUrl(J),{headers:{...this.getAuthHeaders({accessToken:Z}),...Q}});return{data:await $.json(),status:$.status,ok:$.ok}}}class j{data;constructor(J){this.data=J}get id(){return this.data.id}get status(){return this.data.status}get result(){return this.data.result}get isCompleted(){return this.data.status==="completed"}get isFailed(){return this.data.status==="failed"}get urls(){return this.data.result?.images.filter((J)=>J.status==="succeeded").map((J)=>J.url)??[]}getImages(J={}){if(J.includeFailed)return this.data.result?.images??[];return this.data.result?.images.filter((Q)=>Q.status==="succeeded")??[]}getMetadata(){return this.data.request?.metadata}}var D=300000,g=12000,L=2500,M=5000,_=7;class f extends Error{constructor(J){super(`Task ${J} polling timed out after ${D}ms`);this.name="TaskAsyncTimeoutError"}}class W extends Error{constructor(J){super(`Unauthorized access to task ${J}`);this.name="TaskAsyncUnauthorizedError"}}class q extends Error{constructor(J,Q){super(`Failed to fetch status for task ${J} after multiple retries`);this.name="TaskAsyncFetchError",this.cause=Q}}class w extends Error{constructor(J,Q){let Z=Q?` (status ${Q})`:"";super(`Failed to fetch task ${J}${Z}`);this.name="TaskAsyncTaskFetchError"}}class z extends Error{constructor(J){super(`Task ${J} failed during generation`);this.name="TaskAsyncTaskFailedError"}}class C{id;client;_access;_completionPromise=null;constructor(J,Q){this.id=J,this.client=Q.client,this._access={publicAccessToken:Q.pat}}get access(){return this._access}toString(){return this.id}async toTask(){if(!this._completionPromise)this._completionPromise=this.pollUntilCompleted();return this._completionPromise}async pollUntilCompleted(){let J=Date.now(),Q=0,Z=!1,$;while(!0){let x=Date.now()-J;if(x>=D)throw new f(this.id);let B=await this.fetchStatus(Z);if(B.ok){if(Q=0,B.status==="completed"){let U=await this.fetchTask();return new j(U)}if(B.status==="failed")throw new z(this.id)}else{if(B.unauthorized){if(this._access.publicAccessToken&&!Z){Z=!0;continue}throw new W(this.id)}if(B.retryable){if(Q++,$=B.error,Q>=_)throw new q(this.id,$)}}let R=x<g?L:M,N=Math.random()*500,O=R+N,F=D-x,S=Math.min(O,F);await this.sleep(S)}}async fetchStatus(J){let Q=J||!this._access.publicAccessToken?void 0:this._access.publicAccessToken;try{let Z=await this.client.get(G(this.id),{accessToken:Q});if(Z.ok)return{ok:!0,status:Z.data.status};if(Z.status===401||Z.status===403)return{ok:!1,unauthorized:!0,retryable:!1};if(Z.status===404)return{ok:!1,unauthorized:!0,retryable:!1};if(Z.status>=500)return{ok:!1,unauthorized:!1,retryable:!0};return{ok:!1,unauthorized:!1,retryable:!1}}catch(Z){return{ok:!1,unauthorized:!1,retryable:!0,error:Z instanceof Error?Z:Error(String(Z))}}}async fetchTask(){let J=await this.client.get(v(this.id));if(J.ok)return J.data;if(J.status===401||J.status===403)throw new W(this.id);if(J.status===404)throw new W(this.id);throw new w(this.id,J.status)}sleep(J){return new Promise((Q)=>setTimeout(Q,J))}}function m(){if(typeof process<"u"&&process.env)return process.env[X];return}class K{client;constructor(J={}){let Q=J.apiKey??m();if(!Q)throw Error(`Mynth API key is required. Either pass it as an option or set the ${X} environment variable.`);this.client=new H({apiKey:Q,baseUrl:J.baseUrl})}async generate(J,Q={}){let Z=Q.mode??"sync",$=await this.client.post(b,J),x=new C($.taskId,{client:this.client,pat:$.access?.publicAccessToken});if(Z==="async")return x;return x.toTask()}}var i=K;export{i as default,W as TaskAsyncUnauthorizedError,f as TaskAsyncTimeoutError,w as TaskAsyncTaskFetchError,z as TaskAsyncTaskFailedError,q as TaskAsyncFetchError,Y as MynthAPIError,K as Mynth,P as AVAILABLE_MODELS};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { MynthClient } from "./client";
|
|
2
|
+
import { Task } from "./task";
|
|
3
|
+
import type { MynthSDKTypes } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when task polling exceeds the maximum timeout duration.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TaskAsyncTimeoutError extends Error {
|
|
8
|
+
constructor(taskId: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when access to a task is denied (invalid API key or PAT).
|
|
12
|
+
*/
|
|
13
|
+
export declare class TaskAsyncUnauthorizedError extends Error {
|
|
14
|
+
constructor(taskId: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when fetching task status fails after multiple retries.
|
|
18
|
+
*/
|
|
19
|
+
export declare class TaskAsyncFetchError extends Error {
|
|
20
|
+
constructor(taskId: string, cause?: Error);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown when fetching full task data fails.
|
|
24
|
+
*/
|
|
25
|
+
export declare class TaskAsyncTaskFetchError extends Error {
|
|
26
|
+
constructor(taskId: string, status?: number);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Error thrown when a task fails during generation.
|
|
30
|
+
*/
|
|
31
|
+
export declare class TaskAsyncTaskFailedError extends Error {
|
|
32
|
+
constructor(taskId: string);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Public access information for a task, used for client-side polling.
|
|
36
|
+
*/
|
|
37
|
+
export type TaskAsyncAccess = {
|
|
38
|
+
/** Public access token for client-side status polling */
|
|
39
|
+
publicAccessToken?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Represents an async task that can be polled for completion.
|
|
43
|
+
* Use `toTask()` to wait for completion and get the full task result.
|
|
44
|
+
*
|
|
45
|
+
* @template MetadataT - Type of the metadata attached to the request
|
|
46
|
+
* @template ContentRatingT - Type of the content rating response
|
|
47
|
+
*/
|
|
48
|
+
export declare class TaskAsync<MetadataT = Record<string, unknown> | undefined, ContentRatingT = MynthSDKTypes.ImageResultContentRating | undefined> {
|
|
49
|
+
/** The unique identifier for this task */
|
|
50
|
+
readonly id: string;
|
|
51
|
+
private readonly client;
|
|
52
|
+
private readonly _access;
|
|
53
|
+
private _completionPromise;
|
|
54
|
+
constructor(id: string, options: {
|
|
55
|
+
client: MynthClient;
|
|
56
|
+
pat?: string;
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Public access information for client-side polling.
|
|
60
|
+
* Contains the public access token if one was generated.
|
|
61
|
+
*/
|
|
62
|
+
get access(): TaskAsyncAccess;
|
|
63
|
+
toString(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Polls the task until completion and returns the full Task object.
|
|
66
|
+
* Multiple calls to this method return the same promise.
|
|
67
|
+
*
|
|
68
|
+
* @throws {TaskAsyncTimeoutError} If polling exceeds the timeout
|
|
69
|
+
* @throws {TaskAsyncUnauthorizedError} If access is denied
|
|
70
|
+
* @throws {TaskAsyncFetchError} If fetching status fails repeatedly
|
|
71
|
+
* @throws {TaskAsyncTaskFailedError} If the task fails during generation
|
|
72
|
+
*/
|
|
73
|
+
toTask(): Promise<Task<MetadataT, ContentRatingT>>;
|
|
74
|
+
private pollUntilCompleted;
|
|
75
|
+
private fetchStatus;
|
|
76
|
+
private fetchTask;
|
|
77
|
+
private sleep;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=task-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-async.d.ts","sourceRoot":"","sources":["../src/task-async.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAQ7C;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,MAAM,EAAE,MAAM;CAI3B;AAED;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,MAAM,EAAE,MAAM;CAI3B;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAK1C;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAK5C;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,MAAM,EAAE,MAAM;CAI3B;AAMD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,yDAAyD;IACzD,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,SAAS,CACpB,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC/C,cAAc,GAAG,aAAa,CAAC,wBAAwB,GAAG,SAAS;IAEnE,0CAA0C;IAC1C,SAAgB,EAAE,EAAE,MAAM,CAAC;IAE3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IAErC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAE1C,OAAO,CAAC,kBAAkB,CACnB;gBAEK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE;IAOtE;;;OAGG;IACH,IAAI,MAAM,IAAI,eAAe,CAE5B;IAED,QAAQ,IAAI,MAAM;IAIlB;;;;;;;;OAQG;IACU,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YASjD,kBAAkB;YA+DlB,WAAW;YA6CX,SAAS;IAoBvB,OAAO,CAAC,KAAK;CAGd"}
|
package/dist/task.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { MynthSDKTypes } from "./types";
|
|
2
|
+
/** Typed image result with custom content rating type */
|
|
3
|
+
type TypedImageResultImageSuccess<ContentRatingT> = Omit<MynthSDKTypes.ImageResultImageSuccess, "content_rating"> & {
|
|
4
|
+
content_rating?: ContentRatingT;
|
|
5
|
+
};
|
|
6
|
+
type TypedImageResultImageFailure = MynthSDKTypes.ImageResultImageFailure;
|
|
7
|
+
type TypedImageResultImage<ContentRatingT> = TypedImageResultImageSuccess<ContentRatingT> | TypedImageResultImageFailure;
|
|
8
|
+
/** Typed result with custom content rating type on images */
|
|
9
|
+
type TypedImageResult<ContentRatingT> = Omit<MynthSDKTypes.ImageResult, "images"> & {
|
|
10
|
+
images: TypedImageResultImage<ContentRatingT>[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Represents a completed image generation task.
|
|
14
|
+
*
|
|
15
|
+
* @template MetadataT - Type of the metadata attached to the request
|
|
16
|
+
* @template ContentRatingT - Type of the content rating response
|
|
17
|
+
*/
|
|
18
|
+
export declare class Task<MetadataT = Record<string, unknown> | undefined, ContentRatingT = MynthSDKTypes.ImageResultContentRating | undefined> {
|
|
19
|
+
/** Raw task data from the API */
|
|
20
|
+
readonly data: MynthSDKTypes.TaskData;
|
|
21
|
+
constructor(data: MynthSDKTypes.TaskData);
|
|
22
|
+
/** Unique identifier for this task */
|
|
23
|
+
get id(): string;
|
|
24
|
+
/** Current status of the task */
|
|
25
|
+
get status(): MynthSDKTypes.TaskStatus;
|
|
26
|
+
/**
|
|
27
|
+
* The generation result containing images, cost, and model info.
|
|
28
|
+
* Returns `null` if the task hasn't completed yet.
|
|
29
|
+
*/
|
|
30
|
+
get result(): TypedImageResult<ContentRatingT> | null;
|
|
31
|
+
/** Whether the task completed successfully */
|
|
32
|
+
get isCompleted(): boolean;
|
|
33
|
+
/** Whether the task failed */
|
|
34
|
+
get isFailed(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Get all successfully generated image URLs.
|
|
37
|
+
* Convenience method that extracts just the URLs from successful images.
|
|
38
|
+
*/
|
|
39
|
+
get urls(): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Get generated images from the task result.
|
|
42
|
+
*
|
|
43
|
+
* @param options.includeFailed - If true, includes failed image results
|
|
44
|
+
* @returns Array of image results
|
|
45
|
+
*/
|
|
46
|
+
getImages(options: {
|
|
47
|
+
includeFailed: true;
|
|
48
|
+
}): TypedImageResultImage<ContentRatingT>[];
|
|
49
|
+
getImages(options?: {
|
|
50
|
+
includeFailed?: false;
|
|
51
|
+
}): TypedImageResultImageSuccess<ContentRatingT>[];
|
|
52
|
+
/**
|
|
53
|
+
* Get the metadata that was attached to the generation request.
|
|
54
|
+
*/
|
|
55
|
+
getMetadata(): MetadataT;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../src/task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,yDAAyD;AACzD,KAAK,4BAA4B,CAAC,cAAc,IAAI,IAAI,CACtD,aAAa,CAAC,uBAAuB,EACrC,gBAAgB,CACjB,GAAG;IACF,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,KAAK,4BAA4B,GAAG,aAAa,CAAC,uBAAuB,CAAC;AAE1E,KAAK,qBAAqB,CAAC,cAAc,IACrC,4BAA4B,CAAC,cAAc,CAAC,GAC5C,4BAA4B,CAAC;AAEjC,6DAA6D;AAC7D,KAAK,gBAAgB,CAAC,cAAc,IAAI,IAAI,CAC1C,aAAa,CAAC,WAAW,EACzB,QAAQ,CACT,GAAG;IACF,MAAM,EAAE,qBAAqB,CAAC,cAAc,CAAC,EAAE,CAAC;CACjD,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,IAAI,CACf,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC/C,cAAc,GAAG,aAAa,CAAC,wBAAwB,GAAG,SAAS;IAEnE,iCAAiC;IACjC,SAAgB,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC;gBAEjC,IAAI,EAAE,aAAa,CAAC,QAAQ;IAIxC,sCAAsC;IACtC,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,iCAAiC;IACjC,IAAI,MAAM,IAAI,aAAa,CAAC,UAAU,CAErC;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,gBAAgB,CAAC,cAAc,CAAC,GAAG,IAAI,CAEpD;IAED,8CAA8C;IAC9C,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,8BAA8B;IAC9B,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,EAAE,CASnB;IAED;;;;;OAKG;IACH,SAAS,CAAC,OAAO,EAAE;QACjB,aAAa,EAAE,IAAI,CAAC;KACrB,GAAG,qBAAqB,CAAC,cAAc,CAAC,EAAE;IAC3C,SAAS,CAAC,OAAO,CAAC,EAAE;QAClB,aAAa,CAAC,EAAE,KAAK,CAAC;KACvB,GAAG,4BAA4B,CAAC,cAAc,CAAC,EAAE;IAelD;;OAEG;IACH,WAAW,IAAI,SAAS;CAGzB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Mynth SDK.
|
|
3
|
+
* Import as `import type { MynthSDKTypes } from "@mynthio/sdk"`.
|
|
4
|
+
*/
|
|
5
|
+
export declare namespace MynthSDKTypes {
|
|
6
|
+
/** Status of a generation task */
|
|
7
|
+
type TaskStatus = "pending" | "completed" | "failed";
|
|
8
|
+
/** Type of task (currently only "image" is supported) */
|
|
9
|
+
type TaskType = "image";
|
|
10
|
+
/** Full task data returned from the API */
|
|
11
|
+
type TaskData = {
|
|
12
|
+
/** Unique task identifier */
|
|
13
|
+
id: string;
|
|
14
|
+
/** Current status of the task */
|
|
15
|
+
status: TaskStatus;
|
|
16
|
+
/** Type of task */
|
|
17
|
+
type: TaskType;
|
|
18
|
+
/** ID of the API key used (null for public access) */
|
|
19
|
+
apiKeyId: string | null;
|
|
20
|
+
/** ID of the user who created the task */
|
|
21
|
+
userId: string;
|
|
22
|
+
/** Total cost in string format (null if not yet calculated) */
|
|
23
|
+
cost: string | null;
|
|
24
|
+
/** Generation result (null if not completed) */
|
|
25
|
+
result: ImageResult | null;
|
|
26
|
+
/** Original generation request (null if not available) */
|
|
27
|
+
request: ImageGenerationRequestDb | null;
|
|
28
|
+
/** ISO 8601 timestamp of creation */
|
|
29
|
+
createdAt: string;
|
|
30
|
+
/** ISO 8601 timestamp of last update */
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
};
|
|
33
|
+
/** Available model identifiers */
|
|
34
|
+
type ImageGenerationModelId = "black-forest-labs/flux.1-dev" | "black-forest-labs/flux-1-schnell" | "black-forest-labs/flux.2-dev" | "google/gemini-3-pro-image-preview" | "tongyi-mai/z-image-turbo" | "john6666/bismuth-illustrious-mix" | "wan/wan2.6-image" | "xai/grok-imagine-image";
|
|
35
|
+
/** Model to use for generation ("auto" lets the system choose) */
|
|
36
|
+
type ImageGenerationModel = ImageGenerationModelId | "auto";
|
|
37
|
+
/** Structured prompt with positive and optional negative text */
|
|
38
|
+
type PromptStructured = {
|
|
39
|
+
/** Main prompt describing what to generate */
|
|
40
|
+
positive: string;
|
|
41
|
+
/** Elements to exclude from the generation */
|
|
42
|
+
negative?: string;
|
|
43
|
+
};
|
|
44
|
+
type GenerateImageOptionsIn = {
|
|
45
|
+
prompt: string | PromptStructured;
|
|
46
|
+
};
|
|
47
|
+
type GenerateImageOptions = {
|
|
48
|
+
prompt: PromptStructured;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Prompt input for image generation.
|
|
52
|
+
* Can be a simple string or structured with positive/negative prompts.
|
|
53
|
+
*/
|
|
54
|
+
type ImageGenerationRequestPrompt = string | {
|
|
55
|
+
/** Main prompt describing what to generate */
|
|
56
|
+
positive: string;
|
|
57
|
+
/** Elements to exclude (model support varies) */
|
|
58
|
+
negative?: string;
|
|
59
|
+
/** Enable AI prompt enhancement (default: true) */
|
|
60
|
+
magic?: boolean;
|
|
61
|
+
};
|
|
62
|
+
/** Access configuration for the generated task */
|
|
63
|
+
type ImageGenerationRequestAccess = {
|
|
64
|
+
/** Public access token configuration */
|
|
65
|
+
pat?: {
|
|
66
|
+
/** Generate a public access token for client-side polling */
|
|
67
|
+
enabled?: boolean;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
/** Output image format */
|
|
71
|
+
type ImageGenerationRequestOutputFormat = "png" | "jpg" | "webp";
|
|
72
|
+
/** Upscale configuration */
|
|
73
|
+
type ImageGenerationRequestUpscale = 2 | 4 | {
|
|
74
|
+
enabled?: boolean;
|
|
75
|
+
factor?: 2 | 4;
|
|
76
|
+
};
|
|
77
|
+
/** Output configuration for generated images */
|
|
78
|
+
type ImageGenerationRequestOutput = {
|
|
79
|
+
/** Image format (default: "webp") */
|
|
80
|
+
format?: ImageGenerationRequestOutputFormat;
|
|
81
|
+
/** Quality 1-100 (default varies by format) */
|
|
82
|
+
quality?: number;
|
|
83
|
+
/** Upscale factor (2x or 4x) */
|
|
84
|
+
upscale?: ImageGenerationRequestUpscale;
|
|
85
|
+
};
|
|
86
|
+
/** Custom webhook endpoint configuration */
|
|
87
|
+
type ImageGenerationRequestCustomWebhook = {
|
|
88
|
+
/** URL to receive webhook notifications */
|
|
89
|
+
url: string;
|
|
90
|
+
};
|
|
91
|
+
/** Webhook configuration */
|
|
92
|
+
type ImageGenerationRequestWebhook = {
|
|
93
|
+
/** Enable/disable webhooks (disabling overrides dashboard settings) */
|
|
94
|
+
enabled?: boolean;
|
|
95
|
+
/** Additional custom webhook endpoints */
|
|
96
|
+
custom?: ImageGenerationRequestCustomWebhook[];
|
|
97
|
+
};
|
|
98
|
+
/** Custom content rating level definition */
|
|
99
|
+
type ImageGenerationRequestContentRatingLevel<T extends string = string> = {
|
|
100
|
+
/** Level identifier returned in the result */
|
|
101
|
+
value: T;
|
|
102
|
+
/** Human-readable description for the AI classifier */
|
|
103
|
+
description: string;
|
|
104
|
+
};
|
|
105
|
+
/** Content rating configuration */
|
|
106
|
+
type ImageGenerationRequestContentRating = {
|
|
107
|
+
/** Enable content rating classification */
|
|
108
|
+
enabled?: boolean;
|
|
109
|
+
/** Custom rating levels (uses default sfw/nsfw if not provided) */
|
|
110
|
+
levels?: readonly ImageGenerationRequestContentRatingLevel[];
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Image size specification.
|
|
114
|
+
* Can be a preset name, dimension string, or explicit dimensions.
|
|
115
|
+
*/
|
|
116
|
+
type ImageGenerationRequestSize = "instagram" | "square" | "portrait" | "landscape" | `${number}x${number}` | {
|
|
117
|
+
width: number;
|
|
118
|
+
height: number;
|
|
119
|
+
mode?: "strict" | "preset" | "aligned";
|
|
120
|
+
} | "auto";
|
|
121
|
+
/**
|
|
122
|
+
* Image generation request parameters.
|
|
123
|
+
*/
|
|
124
|
+
type ImageGenerationRequest = {
|
|
125
|
+
/** Text prompt or structured prompt object */
|
|
126
|
+
prompt: ImageGenerationRequestPrompt;
|
|
127
|
+
/** Model to use (default: "auto") */
|
|
128
|
+
model?: ImageGenerationModel;
|
|
129
|
+
/** Image size/dimensions (default: "auto") */
|
|
130
|
+
size?: ImageGenerationRequestSize;
|
|
131
|
+
/** Number of images to generate (default: 1) */
|
|
132
|
+
count?: number;
|
|
133
|
+
/** Output format and quality settings */
|
|
134
|
+
output?: ImageGenerationRequestOutput;
|
|
135
|
+
/** Public access token configuration */
|
|
136
|
+
access?: ImageGenerationRequestAccess;
|
|
137
|
+
/** Webhook notification settings */
|
|
138
|
+
webhook?: ImageGenerationRequestWebhook;
|
|
139
|
+
/** Content rating classification settings */
|
|
140
|
+
content_rating?: ImageGenerationRequestContentRating;
|
|
141
|
+
/** Custom metadata to attach (returned in results and webhooks). Max 2KB. */
|
|
142
|
+
metadata?: Record<string, unknown>;
|
|
143
|
+
};
|
|
144
|
+
/** @internal Stored prompt format */
|
|
145
|
+
type ImageGenerationRequestDbPrompt = {
|
|
146
|
+
positive: string;
|
|
147
|
+
negative?: string;
|
|
148
|
+
magic?: boolean;
|
|
149
|
+
};
|
|
150
|
+
/** @internal */
|
|
151
|
+
type ImageGenerationRequestDbWebhook = ImageGenerationRequestWebhook;
|
|
152
|
+
/** @internal */
|
|
153
|
+
type ImageGenerationRequestDbContentRating = ImageGenerationRequestContentRating;
|
|
154
|
+
/** @internal Stored request format */
|
|
155
|
+
type ImageGenerationRequestDb = {
|
|
156
|
+
prompt: ImageGenerationRequestDbPrompt;
|
|
157
|
+
model?: ImageGenerationModel;
|
|
158
|
+
size?: ImageGenerationRequestSize;
|
|
159
|
+
count: number;
|
|
160
|
+
output?: ImageGenerationRequestOutput;
|
|
161
|
+
webhook?: ImageGenerationRequestDbWebhook;
|
|
162
|
+
content_rating?: ImageGenerationRequestDbContentRating;
|
|
163
|
+
metadata?: Record<string, unknown>;
|
|
164
|
+
};
|
|
165
|
+
/** Default content rating levels */
|
|
166
|
+
type ImageResultContentRatingDefaultLevel = "sfw" | "nsfw";
|
|
167
|
+
/** Content rating result */
|
|
168
|
+
type ImageResultContentRating = {
|
|
169
|
+
mode: "default";
|
|
170
|
+
level: ImageResultContentRatingDefaultLevel;
|
|
171
|
+
} | {
|
|
172
|
+
mode: "custom";
|
|
173
|
+
level: string;
|
|
174
|
+
};
|
|
175
|
+
/** Successfully generated image */
|
|
176
|
+
type ImageResultImageSuccess = {
|
|
177
|
+
status: "succeeded";
|
|
178
|
+
/** CDN URL of the generated image */
|
|
179
|
+
url: string;
|
|
180
|
+
/** Provider-specific image identifier */
|
|
181
|
+
provider_id: string;
|
|
182
|
+
/** Cost for this image in string format */
|
|
183
|
+
cost: string;
|
|
184
|
+
/** Content rating if classification was enabled */
|
|
185
|
+
content_rating?: ImageResultContentRating;
|
|
186
|
+
};
|
|
187
|
+
/** Failed image generation */
|
|
188
|
+
type ImageResultImageFailure = {
|
|
189
|
+
status: "failed";
|
|
190
|
+
/** Error message describing the failure */
|
|
191
|
+
error: string;
|
|
192
|
+
};
|
|
193
|
+
/** Individual image result (success or failure) */
|
|
194
|
+
type ImageResultImage = ImageResultImageSuccess | ImageResultImageFailure;
|
|
195
|
+
/** Cost breakdown for the generation */
|
|
196
|
+
type ImageResultCost = {
|
|
197
|
+
/** Cost of image generation */
|
|
198
|
+
images: string;
|
|
199
|
+
/** Total cost including all fees */
|
|
200
|
+
total: string;
|
|
201
|
+
/** Platform fee */
|
|
202
|
+
fee: string;
|
|
203
|
+
};
|
|
204
|
+
/** Auto-enhanced parameters (when magic prompt is enabled) */
|
|
205
|
+
type ImageResultMagic = {
|
|
206
|
+
/** Model selected by auto mode */
|
|
207
|
+
model?: ImageGenerationModelId;
|
|
208
|
+
/** Size selected by auto mode */
|
|
209
|
+
size?: string;
|
|
210
|
+
/** Enhanced prompt */
|
|
211
|
+
prompt?: {
|
|
212
|
+
positive: string;
|
|
213
|
+
negative?: string;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
/** Model-specific settings used for generation */
|
|
217
|
+
type ImageResultModelSettings = {
|
|
218
|
+
/** Actual resolution used */
|
|
219
|
+
resolution: {
|
|
220
|
+
width: number;
|
|
221
|
+
height: number;
|
|
222
|
+
};
|
|
223
|
+
/** Number of inference steps (model-dependent) */
|
|
224
|
+
steps?: number;
|
|
225
|
+
};
|
|
226
|
+
/** Complete generation result */
|
|
227
|
+
type ImageResult = {
|
|
228
|
+
/** Array of generated images (may include failures) */
|
|
229
|
+
images: ImageResultImage[];
|
|
230
|
+
/** Cost breakdown */
|
|
231
|
+
cost: ImageResultCost;
|
|
232
|
+
/** Model information */
|
|
233
|
+
model: {
|
|
234
|
+
/** Model that was used */
|
|
235
|
+
id: ImageGenerationModelId;
|
|
236
|
+
/** Model-specific settings */
|
|
237
|
+
settings: ImageResultModelSettings;
|
|
238
|
+
};
|
|
239
|
+
/** Auto-enhanced parameters */
|
|
240
|
+
magic: ImageResultMagic;
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Webhook payload for task completion
|
|
244
|
+
*/
|
|
245
|
+
type WebhookTaskImageCompletedPayload = {
|
|
246
|
+
task: {
|
|
247
|
+
id: string;
|
|
248
|
+
};
|
|
249
|
+
event: "task.image.completed";
|
|
250
|
+
result: ImageResult;
|
|
251
|
+
request: ImageGenerationRequestDb;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Webhook payload for task failure
|
|
255
|
+
*/
|
|
256
|
+
type WebhookTaskImageFailedPayload = {
|
|
257
|
+
task: {
|
|
258
|
+
id: string;
|
|
259
|
+
};
|
|
260
|
+
event: "task.image.failed";
|
|
261
|
+
request: ImageGenerationRequestDb;
|
|
262
|
+
errors: {
|
|
263
|
+
code: string;
|
|
264
|
+
message: string;
|
|
265
|
+
}[];
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Webhook payload union
|
|
269
|
+
*/
|
|
270
|
+
type WebhookPayload = WebhookTaskImageCompletedPayload | WebhookTaskImageFailedPayload;
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,yBAAiB,aAAa,CAAC;IAC7B,kCAAkC;IAClC,KAAY,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IAE5D,yDAAyD;IACzD,KAAY,QAAQ,GAAG,OAAO,CAAC;IAE/B,2CAA2C;IAC3C,KAAY,QAAQ,GAAG;QACrB,6BAA6B;QAC7B,EAAE,EAAE,MAAM,CAAC;QACX,iCAAiC;QACjC,MAAM,EAAE,UAAU,CAAC;QACnB,mBAAmB;QACnB,IAAI,EAAE,QAAQ,CAAC;QACf,sDAAsD;QACtD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,0CAA0C;QAC1C,MAAM,EAAE,MAAM,CAAC;QACf,+DAA+D;QAC/D,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,gDAAgD;QAChD,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC;QAC3B,0DAA0D;QAC1D,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAAC;QACzC,qCAAqC;QACrC,SAAS,EAAE,MAAM,CAAC;QAClB,wCAAwC;QACxC,SAAS,EA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E,CAAC;QAC3B,qBAAqB;QACrB,IAAI,EAAE,eAAe,CAAC;QACtB,wBAAwB;QACxB,KAAK,EAAE;YACL,0BAA0B;YAC1B,EAAE,EAAE,sBAAsB,CAAC;YAC3B,8BAA8B;YAC9B,QAAQ,EAAE,wBAAwB,CAAC;SACpC,CAAC;QACF,+BAA+B;QAC/B,KAAK,EAAE,gBAAgB,CAAC;KACzB,CAAC;IAEF;;OAEG;IACH,KAAY,gCAAgC,GAAG;QAC7C,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC;QACrB,KAAK,EAAE,sBAAsB,CAAC;QAC9B,MAAM,EAAE,WAAW,CAAC;QACpB,OAAO,EAAE,wBAAwB,CAAC;KACnC,CAAC;IAEF;;OAEG;IACH,KAAY,6BAA6B,GAAG;QAC1C,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC;QACrB,KAAK,EAAE,mBAAmB,CAAC;QAC3B,OAAO,EAAE,wBAAwB,CAAC;QAClC,MAAM,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;SACjB,EAAE,CAAC;KACL,CAAC;IAEF;;OAEG;IACH,KAAY,cAAc,GACtB,gCAAgC,GAChC,6BAA6B,CAAC;CACnC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mynthio/sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Official Mynth SDK for image generation",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai",
|
|
7
|
+
"image-generation",
|
|
8
|
+
"mynth",
|
|
9
|
+
"sdk"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://mynth.io",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "mynth.io",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/mynth-io/sdk"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./convex": {
|
|
34
|
+
"types": "./dist/convex/index.d.ts",
|
|
35
|
+
"import": "./dist/convex/index.js",
|
|
36
|
+
"default": "./dist/convex/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "bun run build:clean && bun run build:js && bun run build:types",
|
|
41
|
+
"build:clean": "rm -rf dist",
|
|
42
|
+
"build:js": "bun build ./src/index.ts ./src/convex/index.ts --outdir ./dist --format esm --splitting --target bun --minify --packages external",
|
|
43
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
44
|
+
"prepublishOnly": "bun run build",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:watch": "vitest",
|
|
47
|
+
"lint": "oxlint -c .oxlintrc.json .",
|
|
48
|
+
"lint:fix": "oxlint -c .oxlintrc.json --fix .",
|
|
49
|
+
"format": "oxfmt --write",
|
|
50
|
+
"format:check": "oxfmt --check",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"changeset": "changeset",
|
|
53
|
+
"version": "changeset version",
|
|
54
|
+
"release": "bun run build && npm publish --access public"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@changesets/changelog-github": "^0.5.1",
|
|
58
|
+
"@changesets/cli": "^2.29.4",
|
|
59
|
+
"@types/bun": "^1.3.8",
|
|
60
|
+
"convex": "^1.31.7",
|
|
61
|
+
"oxfmt": "^0.27.0",
|
|
62
|
+
"oxlint": "^1.42.0",
|
|
63
|
+
"tsx": "^4.21.0",
|
|
64
|
+
"typescript": "5.9.3",
|
|
65
|
+
"vitest": "^4.0.18"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"convex": "^1.27.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"convex": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|