@ai-sdk/prodia 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/CHANGELOG.md +7 -0
- package/LICENSE +13 -0
- package/README.md +74 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +429 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +414 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# AI SDK - Prodia Provider
|
|
2
|
+
|
|
3
|
+
The **[Prodia provider](https://ai-sdk.dev/providers/ai-sdk-providers/prodia)** for the [AI SDK](https://ai-sdk.dev/docs) adds image model support for the [Prodia API](https://docs.prodia.com/).
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
The Prodia provider is available in the `@ai-sdk/prodia` module. You can install it with
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @ai-sdk/prodia
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Provider Instance
|
|
14
|
+
|
|
15
|
+
You can import the default provider instance `prodia` from `@ai-sdk/prodia`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { prodia } from '@ai-sdk/prodia';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Image Generation Example
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import fs from 'node:fs';
|
|
25
|
+
import { prodia } from '@ai-sdk/prodia';
|
|
26
|
+
import { generateImage } from 'ai';
|
|
27
|
+
|
|
28
|
+
const { image } = await generateImage({
|
|
29
|
+
model: prodia.image('inference.flux-fast.schnell.txt2img.v2'),
|
|
30
|
+
prompt: 'A cat wearing a intricate robe',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const filename = `image-${Date.now()}.png`;
|
|
34
|
+
fs.writeFileSync(filename, image.uint8Array);
|
|
35
|
+
console.log(`Image saved to ${filename}`);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Additional Options
|
|
39
|
+
|
|
40
|
+
If you want to pass additional inputs to the model besides the prompt, use the `providerOptions.prodia` property:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { prodia, type ProdiaImageProviderOptions } from '@ai-sdk/prodia';
|
|
44
|
+
import { generateImage } from 'ai';
|
|
45
|
+
|
|
46
|
+
const { image } = await generateImage({
|
|
47
|
+
model: prodia.image('inference.flux-fast.schnell.txt2img.v2'),
|
|
48
|
+
prompt: 'A cat wearing an intricate robe',
|
|
49
|
+
providerOptions: {
|
|
50
|
+
prodia: {
|
|
51
|
+
width: 1024,
|
|
52
|
+
height: 1024,
|
|
53
|
+
steps: 4,
|
|
54
|
+
} satisfies ProdiaImageProviderOptions,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Configuring Base URL
|
|
60
|
+
|
|
61
|
+
By default, the provider uses `https://inference.prodia.com/v2`. You can override this if needed:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { createProdia } from '@ai-sdk/prodia';
|
|
65
|
+
|
|
66
|
+
const prodia = createProdia({
|
|
67
|
+
baseURL: 'https://inference.prodia.com/v2',
|
|
68
|
+
apiKey: process.env.PRODIA_TOKEN,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Documentation
|
|
73
|
+
|
|
74
|
+
See the [Prodia provider](https://ai-sdk.dev/providers/ai-sdk-providers/prodia) for more information.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
|
+
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { ProviderV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Prodia job types for image generation.
|
|
7
|
+
*/
|
|
8
|
+
type ProdiaImageModelId = 'inference.flux-fast.schnell.txt2img.v2' | 'inference.flux.schnell.txt2img.v2' | (string & {});
|
|
9
|
+
|
|
10
|
+
declare const prodiaImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
11
|
+
steps?: number | undefined;
|
|
12
|
+
width?: number | undefined;
|
|
13
|
+
height?: number | undefined;
|
|
14
|
+
stylePreset?: "3d-model" | "analog-film" | "anime" | "cinematic" | "comic-book" | "digital-art" | "enhance" | "fantasy-art" | "isometric" | "line-art" | "low-poly" | "neon-punk" | "origami" | "photographic" | "pixel-art" | "texture" | "craft-clay" | undefined;
|
|
15
|
+
loras?: string[] | undefined;
|
|
16
|
+
progressive?: boolean | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
type ProdiaImageProviderOptions = InferSchema<typeof prodiaImageProviderOptionsSchema>;
|
|
19
|
+
|
|
20
|
+
interface ProdiaProviderSettings {
|
|
21
|
+
/**
|
|
22
|
+
* Prodia API key. Default value is taken from the `PRODIA_TOKEN` environment variable.
|
|
23
|
+
*/
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Base URL for the API calls. Defaults to `https://inference.prodia.com/v2`.
|
|
27
|
+
*/
|
|
28
|
+
baseURL?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Custom headers to include in the requests.
|
|
31
|
+
*/
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Custom fetch implementation. You can use it as a middleware to intercept
|
|
35
|
+
* requests, or to provide a custom fetch implementation for e.g. testing.
|
|
36
|
+
*/
|
|
37
|
+
fetch?: FetchFunction;
|
|
38
|
+
}
|
|
39
|
+
interface ProdiaProvider extends ProviderV2 {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a model for image generation.
|
|
42
|
+
*/
|
|
43
|
+
image(modelId: ProdiaImageModelId): ImageModelV2;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a model for image generation.
|
|
46
|
+
*/
|
|
47
|
+
imageModel(modelId: ProdiaImageModelId): ImageModelV2;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use `embeddingModel` instead.
|
|
50
|
+
*/
|
|
51
|
+
textEmbeddingModel(modelId: string): never;
|
|
52
|
+
}
|
|
53
|
+
declare function createProdia(options?: ProdiaProviderSettings): ProdiaProvider;
|
|
54
|
+
declare const prodia: ProdiaProvider;
|
|
55
|
+
|
|
56
|
+
declare const VERSION: string;
|
|
57
|
+
|
|
58
|
+
export { type ProdiaImageModelId, type ProdiaImageProviderOptions, type ProdiaProvider, type ProdiaProviderSettings, VERSION, createProdia, prodia };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
|
+
import { InferSchema, FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { ProviderV2, ImageModelV2 } from '@ai-sdk/provider';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Prodia job types for image generation.
|
|
7
|
+
*/
|
|
8
|
+
type ProdiaImageModelId = 'inference.flux-fast.schnell.txt2img.v2' | 'inference.flux.schnell.txt2img.v2' | (string & {});
|
|
9
|
+
|
|
10
|
+
declare const prodiaImageProviderOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
11
|
+
steps?: number | undefined;
|
|
12
|
+
width?: number | undefined;
|
|
13
|
+
height?: number | undefined;
|
|
14
|
+
stylePreset?: "3d-model" | "analog-film" | "anime" | "cinematic" | "comic-book" | "digital-art" | "enhance" | "fantasy-art" | "isometric" | "line-art" | "low-poly" | "neon-punk" | "origami" | "photographic" | "pixel-art" | "texture" | "craft-clay" | undefined;
|
|
15
|
+
loras?: string[] | undefined;
|
|
16
|
+
progressive?: boolean | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
type ProdiaImageProviderOptions = InferSchema<typeof prodiaImageProviderOptionsSchema>;
|
|
19
|
+
|
|
20
|
+
interface ProdiaProviderSettings {
|
|
21
|
+
/**
|
|
22
|
+
* Prodia API key. Default value is taken from the `PRODIA_TOKEN` environment variable.
|
|
23
|
+
*/
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Base URL for the API calls. Defaults to `https://inference.prodia.com/v2`.
|
|
27
|
+
*/
|
|
28
|
+
baseURL?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Custom headers to include in the requests.
|
|
31
|
+
*/
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Custom fetch implementation. You can use it as a middleware to intercept
|
|
35
|
+
* requests, or to provide a custom fetch implementation for e.g. testing.
|
|
36
|
+
*/
|
|
37
|
+
fetch?: FetchFunction;
|
|
38
|
+
}
|
|
39
|
+
interface ProdiaProvider extends ProviderV2 {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a model for image generation.
|
|
42
|
+
*/
|
|
43
|
+
image(modelId: ProdiaImageModelId): ImageModelV2;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a model for image generation.
|
|
46
|
+
*/
|
|
47
|
+
imageModel(modelId: ProdiaImageModelId): ImageModelV2;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use `embeddingModel` instead.
|
|
50
|
+
*/
|
|
51
|
+
textEmbeddingModel(modelId: string): never;
|
|
52
|
+
}
|
|
53
|
+
declare function createProdia(options?: ProdiaProviderSettings): ProdiaProvider;
|
|
54
|
+
declare const prodia: ProdiaProvider;
|
|
55
|
+
|
|
56
|
+
declare const VERSION: string;
|
|
57
|
+
|
|
58
|
+
export { type ProdiaImageModelId, type ProdiaImageProviderOptions, type ProdiaProvider, type ProdiaProviderSettings, VERSION, createProdia, prodia };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
VERSION: () => VERSION,
|
|
24
|
+
createProdia: () => createProdia,
|
|
25
|
+
prodia: () => prodia
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
|
|
29
|
+
// src/prodia-provider.ts
|
|
30
|
+
var import_provider = require("@ai-sdk/provider");
|
|
31
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
32
|
+
|
|
33
|
+
// src/prodia-image-model.ts
|
|
34
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
35
|
+
var import_v4 = require("zod/v4");
|
|
36
|
+
var ProdiaImageModel = class {
|
|
37
|
+
constructor(modelId, config) {
|
|
38
|
+
this.modelId = modelId;
|
|
39
|
+
this.config = config;
|
|
40
|
+
this.specificationVersion = "v2";
|
|
41
|
+
this.maxImagesPerCall = 1;
|
|
42
|
+
}
|
|
43
|
+
get provider() {
|
|
44
|
+
return this.config.provider;
|
|
45
|
+
}
|
|
46
|
+
async getArgs({
|
|
47
|
+
prompt,
|
|
48
|
+
size,
|
|
49
|
+
seed,
|
|
50
|
+
providerOptions
|
|
51
|
+
}) {
|
|
52
|
+
const warnings = [];
|
|
53
|
+
const prodiaOptions = await (0, import_provider_utils.parseProviderOptions)({
|
|
54
|
+
provider: "prodia",
|
|
55
|
+
providerOptions,
|
|
56
|
+
schema: prodiaImageProviderOptionsSchema
|
|
57
|
+
});
|
|
58
|
+
let width;
|
|
59
|
+
let height;
|
|
60
|
+
if (size) {
|
|
61
|
+
const [widthStr, heightStr] = size.split("x");
|
|
62
|
+
width = Number(widthStr);
|
|
63
|
+
height = Number(heightStr);
|
|
64
|
+
if (!widthStr || !heightStr || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
65
|
+
warnings.push({
|
|
66
|
+
type: "unsupported-setting",
|
|
67
|
+
setting: "size",
|
|
68
|
+
details: `Invalid size format: ${size}. Expected format: WIDTHxHEIGHT (e.g., 1024x1024)`
|
|
69
|
+
});
|
|
70
|
+
width = void 0;
|
|
71
|
+
height = void 0;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const jobConfig = {
|
|
75
|
+
prompt
|
|
76
|
+
};
|
|
77
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.width) !== void 0) {
|
|
78
|
+
jobConfig.width = prodiaOptions.width;
|
|
79
|
+
} else if (width !== void 0) {
|
|
80
|
+
jobConfig.width = width;
|
|
81
|
+
}
|
|
82
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.height) !== void 0) {
|
|
83
|
+
jobConfig.height = prodiaOptions.height;
|
|
84
|
+
} else if (height !== void 0) {
|
|
85
|
+
jobConfig.height = height;
|
|
86
|
+
}
|
|
87
|
+
if (seed !== void 0) {
|
|
88
|
+
jobConfig.seed = seed;
|
|
89
|
+
}
|
|
90
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.steps) !== void 0) {
|
|
91
|
+
jobConfig.steps = prodiaOptions.steps;
|
|
92
|
+
}
|
|
93
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.stylePreset) !== void 0) {
|
|
94
|
+
jobConfig.style_preset = prodiaOptions.stylePreset;
|
|
95
|
+
}
|
|
96
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.loras) !== void 0 && prodiaOptions.loras.length > 0) {
|
|
97
|
+
jobConfig.loras = prodiaOptions.loras;
|
|
98
|
+
}
|
|
99
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.progressive) !== void 0) {
|
|
100
|
+
jobConfig.progressive = prodiaOptions.progressive;
|
|
101
|
+
}
|
|
102
|
+
const body = {
|
|
103
|
+
type: this.modelId,
|
|
104
|
+
config: jobConfig
|
|
105
|
+
};
|
|
106
|
+
return { body, warnings };
|
|
107
|
+
}
|
|
108
|
+
async doGenerate(options) {
|
|
109
|
+
var _a, _b, _c, _d, _e, _f;
|
|
110
|
+
const { body, warnings } = await this.getArgs(options);
|
|
111
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
112
|
+
const combinedHeaders = (0, import_provider_utils.combineHeaders)(
|
|
113
|
+
await (0, import_provider_utils.resolve)(this.config.headers),
|
|
114
|
+
options.headers
|
|
115
|
+
);
|
|
116
|
+
const { value: multipartResult, responseHeaders } = await (0, import_provider_utils.postToApi)({
|
|
117
|
+
url: `${this.config.baseURL}/job`,
|
|
118
|
+
headers: {
|
|
119
|
+
...combinedHeaders,
|
|
120
|
+
Accept: "multipart/form-data; image/png",
|
|
121
|
+
"Content-Type": "application/json"
|
|
122
|
+
},
|
|
123
|
+
body: {
|
|
124
|
+
content: JSON.stringify(body),
|
|
125
|
+
values: body
|
|
126
|
+
},
|
|
127
|
+
failedResponseHandler: prodiaFailedResponseHandler,
|
|
128
|
+
successfulResponseHandler: createMultipartResponseHandler(),
|
|
129
|
+
abortSignal: options.abortSignal,
|
|
130
|
+
fetch: this.config.fetch
|
|
131
|
+
});
|
|
132
|
+
const { jobResult, imageBytes } = multipartResult;
|
|
133
|
+
return {
|
|
134
|
+
images: [imageBytes],
|
|
135
|
+
warnings,
|
|
136
|
+
providerMetadata: {
|
|
137
|
+
prodia: {
|
|
138
|
+
images: [
|
|
139
|
+
{
|
|
140
|
+
jobId: jobResult.id,
|
|
141
|
+
...((_d = jobResult.config) == null ? void 0 : _d.seed) != null && {
|
|
142
|
+
seed: jobResult.config.seed
|
|
143
|
+
},
|
|
144
|
+
...((_e = jobResult.metrics) == null ? void 0 : _e.elapsed) != null && {
|
|
145
|
+
elapsed: jobResult.metrics.elapsed
|
|
146
|
+
},
|
|
147
|
+
...((_f = jobResult.metrics) == null ? void 0 : _f.ips) != null && {
|
|
148
|
+
iterationsPerSecond: jobResult.metrics.ips
|
|
149
|
+
},
|
|
150
|
+
...jobResult.created_at != null && {
|
|
151
|
+
createdAt: jobResult.created_at
|
|
152
|
+
},
|
|
153
|
+
...jobResult.updated_at != null && {
|
|
154
|
+
updatedAt: jobResult.updated_at
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
response: {
|
|
161
|
+
modelId: this.modelId,
|
|
162
|
+
timestamp: currentDate,
|
|
163
|
+
headers: responseHeaders
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var stylePresets = [
|
|
169
|
+
"3d-model",
|
|
170
|
+
"analog-film",
|
|
171
|
+
"anime",
|
|
172
|
+
"cinematic",
|
|
173
|
+
"comic-book",
|
|
174
|
+
"digital-art",
|
|
175
|
+
"enhance",
|
|
176
|
+
"fantasy-art",
|
|
177
|
+
"isometric",
|
|
178
|
+
"line-art",
|
|
179
|
+
"low-poly",
|
|
180
|
+
"neon-punk",
|
|
181
|
+
"origami",
|
|
182
|
+
"photographic",
|
|
183
|
+
"pixel-art",
|
|
184
|
+
"texture",
|
|
185
|
+
"craft-clay"
|
|
186
|
+
];
|
|
187
|
+
var prodiaImageProviderOptionsSchema = (0, import_provider_utils.lazySchema)(
|
|
188
|
+
() => (0, import_provider_utils.zodSchema)(
|
|
189
|
+
import_v4.z.object({
|
|
190
|
+
/**
|
|
191
|
+
* Amount of computational iterations to run. More is typically higher quality.
|
|
192
|
+
*/
|
|
193
|
+
steps: import_v4.z.number().int().min(1).max(4).optional(),
|
|
194
|
+
/**
|
|
195
|
+
* Width of the output image in pixels.
|
|
196
|
+
*/
|
|
197
|
+
width: import_v4.z.number().int().min(256).max(1920).optional(),
|
|
198
|
+
/**
|
|
199
|
+
* Height of the output image in pixels.
|
|
200
|
+
*/
|
|
201
|
+
height: import_v4.z.number().int().min(256).max(1920).optional(),
|
|
202
|
+
/**
|
|
203
|
+
* Apply a visual theme to your output image.
|
|
204
|
+
*/
|
|
205
|
+
stylePreset: import_v4.z.enum(stylePresets).optional(),
|
|
206
|
+
/**
|
|
207
|
+
* Augment the output with a LoRa model.
|
|
208
|
+
*/
|
|
209
|
+
loras: import_v4.z.array(import_v4.z.string()).max(3).optional(),
|
|
210
|
+
/**
|
|
211
|
+
* When using JPEG output, return a progressive JPEG.
|
|
212
|
+
*/
|
|
213
|
+
progressive: import_v4.z.boolean().optional()
|
|
214
|
+
})
|
|
215
|
+
)
|
|
216
|
+
);
|
|
217
|
+
var prodiaJobResultSchema = import_v4.z.object({
|
|
218
|
+
id: import_v4.z.string(),
|
|
219
|
+
created_at: import_v4.z.string().optional(),
|
|
220
|
+
updated_at: import_v4.z.string().optional(),
|
|
221
|
+
expires_at: import_v4.z.string().optional(),
|
|
222
|
+
state: import_v4.z.object({
|
|
223
|
+
current: import_v4.z.string()
|
|
224
|
+
}).optional(),
|
|
225
|
+
config: import_v4.z.object({
|
|
226
|
+
seed: import_v4.z.number().optional()
|
|
227
|
+
}).passthrough().optional(),
|
|
228
|
+
metrics: import_v4.z.object({
|
|
229
|
+
elapsed: import_v4.z.number().optional(),
|
|
230
|
+
ips: import_v4.z.number().optional()
|
|
231
|
+
}).optional()
|
|
232
|
+
});
|
|
233
|
+
function createMultipartResponseHandler() {
|
|
234
|
+
return async ({
|
|
235
|
+
response
|
|
236
|
+
}) => {
|
|
237
|
+
var _a, _b, _c;
|
|
238
|
+
const contentType = (_a = response.headers.get("content-type")) != null ? _a : "";
|
|
239
|
+
const responseHeaders = {};
|
|
240
|
+
response.headers.forEach((value, key) => {
|
|
241
|
+
responseHeaders[key] = value;
|
|
242
|
+
});
|
|
243
|
+
const boundaryMatch = contentType.match(/boundary=([^\s;]+)/);
|
|
244
|
+
if (!boundaryMatch) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
`Prodia response missing multipart boundary in content-type: ${contentType}`
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
const boundary = boundaryMatch[1];
|
|
250
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
251
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
252
|
+
const parts = parseMultipart(bytes, boundary);
|
|
253
|
+
let jobResult;
|
|
254
|
+
let imageBytes;
|
|
255
|
+
for (const part of parts) {
|
|
256
|
+
const contentDisposition = (_b = part.headers["content-disposition"]) != null ? _b : "";
|
|
257
|
+
const partContentType = (_c = part.headers["content-type"]) != null ? _c : "";
|
|
258
|
+
if (contentDisposition.includes('name="job"')) {
|
|
259
|
+
const jsonStr = new TextDecoder().decode(part.body);
|
|
260
|
+
jobResult = prodiaJobResultSchema.parse(JSON.parse(jsonStr));
|
|
261
|
+
} else if (contentDisposition.includes('name="output"')) {
|
|
262
|
+
imageBytes = part.body;
|
|
263
|
+
} else if (partContentType.startsWith("image/")) {
|
|
264
|
+
imageBytes = part.body;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (!jobResult) {
|
|
268
|
+
throw new Error("Prodia multipart response missing job part");
|
|
269
|
+
}
|
|
270
|
+
if (!imageBytes) {
|
|
271
|
+
throw new Error("Prodia multipart response missing output image");
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
value: { jobResult, imageBytes },
|
|
275
|
+
responseHeaders
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function parseMultipart(data, boundary) {
|
|
280
|
+
const parts = [];
|
|
281
|
+
const boundaryBytes = new TextEncoder().encode(`--${boundary}`);
|
|
282
|
+
const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);
|
|
283
|
+
const positions = [];
|
|
284
|
+
for (let i = 0; i <= data.length - boundaryBytes.length; i++) {
|
|
285
|
+
let match = true;
|
|
286
|
+
for (let j = 0; j < boundaryBytes.length; j++) {
|
|
287
|
+
if (data[i + j] !== boundaryBytes[j]) {
|
|
288
|
+
match = false;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (match) {
|
|
293
|
+
positions.push(i);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
for (let i = 0; i < positions.length - 1; i++) {
|
|
297
|
+
const start = positions[i] + boundaryBytes.length;
|
|
298
|
+
const end = positions[i + 1];
|
|
299
|
+
let isEndBoundary = true;
|
|
300
|
+
for (let j = 0; j < endBoundaryBytes.length && isEndBoundary; j++) {
|
|
301
|
+
if (data[positions[i] + j] !== endBoundaryBytes[j]) {
|
|
302
|
+
isEndBoundary = false;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (isEndBoundary && positions[i] + endBoundaryBytes.length <= data.length) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
let partStart = start;
|
|
309
|
+
if (data[partStart] === 13 && data[partStart + 1] === 10) {
|
|
310
|
+
partStart += 2;
|
|
311
|
+
} else if (data[partStart] === 10) {
|
|
312
|
+
partStart += 1;
|
|
313
|
+
}
|
|
314
|
+
let partEnd = end;
|
|
315
|
+
if (data[partEnd - 2] === 13 && data[partEnd - 1] === 10) {
|
|
316
|
+
partEnd -= 2;
|
|
317
|
+
} else if (data[partEnd - 1] === 10) {
|
|
318
|
+
partEnd -= 1;
|
|
319
|
+
}
|
|
320
|
+
const partData = data.slice(partStart, partEnd);
|
|
321
|
+
let headerEnd = -1;
|
|
322
|
+
for (let j = 0; j < partData.length - 3; j++) {
|
|
323
|
+
if (partData[j] === 13 && partData[j + 1] === 10 && partData[j + 2] === 13 && partData[j + 3] === 10) {
|
|
324
|
+
headerEnd = j;
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
if (partData[j] === 10 && partData[j + 1] === 10) {
|
|
328
|
+
headerEnd = j;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (headerEnd === -1) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const headerBytes = partData.slice(0, headerEnd);
|
|
336
|
+
const headerStr = new TextDecoder().decode(headerBytes);
|
|
337
|
+
const headers = {};
|
|
338
|
+
for (const line of headerStr.split(/\r?\n/)) {
|
|
339
|
+
const colonIdx = line.indexOf(":");
|
|
340
|
+
if (colonIdx > 0) {
|
|
341
|
+
const key = line.slice(0, colonIdx).trim().toLowerCase();
|
|
342
|
+
const value = line.slice(colonIdx + 1).trim();
|
|
343
|
+
headers[key] = value;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
let bodyStart = headerEnd + 2;
|
|
347
|
+
if (partData[headerEnd] === 13) {
|
|
348
|
+
bodyStart = headerEnd + 4;
|
|
349
|
+
}
|
|
350
|
+
const body = partData.slice(bodyStart);
|
|
351
|
+
parts.push({ headers, body });
|
|
352
|
+
}
|
|
353
|
+
return parts;
|
|
354
|
+
}
|
|
355
|
+
var prodiaErrorSchema = import_v4.z.object({
|
|
356
|
+
message: import_v4.z.string().optional(),
|
|
357
|
+
detail: import_v4.z.unknown().optional(),
|
|
358
|
+
error: import_v4.z.string().optional()
|
|
359
|
+
});
|
|
360
|
+
var prodiaFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
|
361
|
+
errorSchema: prodiaErrorSchema,
|
|
362
|
+
errorToMessage: (error) => {
|
|
363
|
+
var _a;
|
|
364
|
+
const parsed = prodiaErrorSchema.safeParse(error);
|
|
365
|
+
if (!parsed.success) return "Unknown Prodia error";
|
|
366
|
+
const { message, detail, error: errorField } = parsed.data;
|
|
367
|
+
if (typeof detail === "string") return detail;
|
|
368
|
+
if (detail != null) {
|
|
369
|
+
try {
|
|
370
|
+
return JSON.stringify(detail);
|
|
371
|
+
} catch (e) {
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return (_a = errorField != null ? errorField : message) != null ? _a : "Unknown Prodia error";
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// src/version.ts
|
|
379
|
+
var VERSION = true ? "0.0.1" : "0.0.0-test";
|
|
380
|
+
|
|
381
|
+
// src/prodia-provider.ts
|
|
382
|
+
var defaultBaseURL = "https://inference.prodia.com/v2";
|
|
383
|
+
function createProdia(options = {}) {
|
|
384
|
+
var _a;
|
|
385
|
+
const baseURL = (0, import_provider_utils2.withoutTrailingSlash)((_a = options.baseURL) != null ? _a : defaultBaseURL);
|
|
386
|
+
const getHeaders = () => (0, import_provider_utils2.withUserAgentSuffix)(
|
|
387
|
+
{
|
|
388
|
+
Authorization: `Bearer ${(0, import_provider_utils2.loadApiKey)({
|
|
389
|
+
apiKey: options.apiKey,
|
|
390
|
+
environmentVariableName: "PRODIA_TOKEN",
|
|
391
|
+
description: "Prodia"
|
|
392
|
+
})}`,
|
|
393
|
+
...options.headers
|
|
394
|
+
},
|
|
395
|
+
`ai-sdk/prodia/${VERSION}`
|
|
396
|
+
);
|
|
397
|
+
const createImageModel = (modelId) => new ProdiaImageModel(modelId, {
|
|
398
|
+
provider: "prodia.image",
|
|
399
|
+
baseURL: baseURL != null ? baseURL : defaultBaseURL,
|
|
400
|
+
headers: getHeaders,
|
|
401
|
+
fetch: options.fetch
|
|
402
|
+
});
|
|
403
|
+
const textEmbeddingModel = (modelId) => {
|
|
404
|
+
throw new import_provider.NoSuchModelError({
|
|
405
|
+
modelId,
|
|
406
|
+
modelType: "textEmbeddingModel"
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
const languageModel = (modelId) => {
|
|
410
|
+
throw new import_provider.NoSuchModelError({
|
|
411
|
+
modelId,
|
|
412
|
+
modelType: "languageModel"
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
return {
|
|
416
|
+
imageModel: createImageModel,
|
|
417
|
+
image: createImageModel,
|
|
418
|
+
languageModel,
|
|
419
|
+
textEmbeddingModel
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
var prodia = createProdia();
|
|
423
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
424
|
+
0 && (module.exports = {
|
|
425
|
+
VERSION,
|
|
426
|
+
createProdia,
|
|
427
|
+
prodia
|
|
428
|
+
});
|
|
429
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/prodia-provider.ts","../src/prodia-image-model.ts","../src/version.ts"],"sourcesContent":["export type { ProdiaImageProviderOptions } from './prodia-image-model';\nexport type { ProdiaImageModelId } from './prodia-image-settings';\nexport type { ProdiaProvider, ProdiaProviderSettings } from './prodia-provider';\nexport { createProdia, prodia } from './prodia-provider';\nexport { VERSION } from './version';\n","import {\n type ImageModelV2,\n NoSuchModelError,\n type ProviderV2,\n} from '@ai-sdk/provider';\nimport type { FetchFunction } from '@ai-sdk/provider-utils';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { ProdiaImageModel } from './prodia-image-model';\nimport type { ProdiaImageModelId } from './prodia-image-settings';\nimport { VERSION } from './version';\n\nexport interface ProdiaProviderSettings {\n /**\n * Prodia API key. Default value is taken from the `PRODIA_TOKEN` environment variable.\n */\n apiKey?: string;\n\n /**\n * Base URL for the API calls. Defaults to `https://inference.prodia.com/v2`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept\n * requests, or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface ProdiaProvider extends ProviderV2 {\n /**\n * Creates a model for image generation.\n */\n image(modelId: ProdiaImageModelId): ImageModelV2;\n\n /**\n * Creates a model for image generation.\n */\n imageModel(modelId: ProdiaImageModelId): ImageModelV2;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://inference.prodia.com/v2';\n\nexport function createProdia(\n options: ProdiaProviderSettings = {},\n): ProdiaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'PRODIA_TOKEN',\n description: 'Prodia',\n })}`,\n ...options.headers,\n },\n `ai-sdk/prodia/${VERSION}`,\n );\n\n const createImageModel = (modelId: ProdiaImageModelId) =>\n new ProdiaImageModel(modelId, {\n provider: 'prodia.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'textEmbeddingModel',\n });\n };\n\n const languageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n };\n\n return {\n imageModel: createImageModel,\n image: createImageModel,\n languageModel,\n textEmbeddingModel,\n };\n}\n\nexport const prodia = createProdia();\n","import type { ImageModelV2, ImageModelV2CallWarning } from '@ai-sdk/provider';\nimport type { InferSchema, Resolvable } from '@ai-sdk/provider-utils';\nimport {\n combineHeaders,\n createJsonErrorResponseHandler,\n type FetchFunction,\n lazySchema,\n parseProviderOptions,\n postToApi,\n resolve,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport type { ProdiaImageModelId } from './prodia-image-settings';\n\nexport class ProdiaImageModel implements ImageModelV2 {\n readonly specificationVersion = 'v2';\n readonly maxImagesPerCall = 1;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: ProdiaImageModelId,\n private readonly config: ProdiaImageModelConfig,\n ) {}\n\n private async getArgs({\n prompt,\n size,\n seed,\n providerOptions,\n }: Parameters<ImageModelV2['doGenerate']>[0]) {\n const warnings: Array<ImageModelV2CallWarning> = [];\n\n const prodiaOptions = await parseProviderOptions({\n provider: 'prodia',\n providerOptions,\n schema: prodiaImageProviderOptionsSchema,\n });\n\n let width: number | undefined;\n let height: number | undefined;\n if (size) {\n const [widthStr, heightStr] = size.split('x');\n width = Number(widthStr);\n height = Number(heightStr);\n if (\n !widthStr ||\n !heightStr ||\n !Number.isFinite(width) ||\n !Number.isFinite(height)\n ) {\n warnings.push({\n type: 'unsupported-setting',\n setting: 'size',\n details: `Invalid size format: ${size}. Expected format: WIDTHxHEIGHT (e.g., 1024x1024)`,\n });\n width = undefined;\n height = undefined;\n }\n }\n\n const jobConfig: Record<string, unknown> = {\n prompt,\n };\n\n if (prodiaOptions?.width !== undefined) {\n jobConfig.width = prodiaOptions.width;\n } else if (width !== undefined) {\n jobConfig.width = width;\n }\n\n if (prodiaOptions?.height !== undefined) {\n jobConfig.height = prodiaOptions.height;\n } else if (height !== undefined) {\n jobConfig.height = height;\n }\n\n if (seed !== undefined) {\n jobConfig.seed = seed;\n }\n if (prodiaOptions?.steps !== undefined) {\n jobConfig.steps = prodiaOptions.steps;\n }\n if (prodiaOptions?.stylePreset !== undefined) {\n jobConfig.style_preset = prodiaOptions.stylePreset;\n }\n if (prodiaOptions?.loras !== undefined && prodiaOptions.loras.length > 0) {\n jobConfig.loras = prodiaOptions.loras;\n }\n if (prodiaOptions?.progressive !== undefined) {\n jobConfig.progressive = prodiaOptions.progressive;\n }\n\n const body = {\n type: this.modelId,\n config: jobConfig,\n };\n\n return { body, warnings };\n }\n\n async doGenerate(\n options: Parameters<ImageModelV2['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<ImageModelV2['doGenerate']>>> {\n const { body, warnings } = await this.getArgs(options);\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const combinedHeaders = combineHeaders(\n await resolve(this.config.headers),\n options.headers,\n );\n\n const { value: multipartResult, responseHeaders } = await postToApi({\n url: `${this.config.baseURL}/job`,\n headers: {\n ...combinedHeaders,\n Accept: 'multipart/form-data; image/png',\n 'Content-Type': 'application/json',\n },\n body: {\n content: JSON.stringify(body),\n values: body,\n },\n failedResponseHandler: prodiaFailedResponseHandler,\n successfulResponseHandler: createMultipartResponseHandler(),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n const { jobResult, imageBytes } = multipartResult;\n\n return {\n images: [imageBytes],\n warnings,\n providerMetadata: {\n prodia: {\n images: [\n {\n jobId: jobResult.id,\n ...(jobResult.config?.seed != null && {\n seed: jobResult.config.seed,\n }),\n ...(jobResult.metrics?.elapsed != null && {\n elapsed: jobResult.metrics.elapsed,\n }),\n ...(jobResult.metrics?.ips != null && {\n iterationsPerSecond: jobResult.metrics.ips,\n }),\n ...(jobResult.created_at != null && {\n createdAt: jobResult.created_at,\n }),\n ...(jobResult.updated_at != null && {\n updatedAt: jobResult.updated_at,\n }),\n },\n ],\n },\n },\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n}\n\nconst stylePresets = [\n '3d-model',\n 'analog-film',\n 'anime',\n 'cinematic',\n 'comic-book',\n 'digital-art',\n 'enhance',\n 'fantasy-art',\n 'isometric',\n 'line-art',\n 'low-poly',\n 'neon-punk',\n 'origami',\n 'photographic',\n 'pixel-art',\n 'texture',\n 'craft-clay',\n] as const;\n\nexport const prodiaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z.object({\n /**\n * Amount of computational iterations to run. More is typically higher quality.\n */\n steps: z.number().int().min(1).max(4).optional(),\n /**\n * Width of the output image in pixels.\n */\n width: z.number().int().min(256).max(1920).optional(),\n /**\n * Height of the output image in pixels.\n */\n height: z.number().int().min(256).max(1920).optional(),\n /**\n * Apply a visual theme to your output image.\n */\n stylePreset: z.enum(stylePresets).optional(),\n /**\n * Augment the output with a LoRa model.\n */\n loras: z.array(z.string()).max(3).optional(),\n /**\n * When using JPEG output, return a progressive JPEG.\n */\n progressive: z.boolean().optional(),\n }),\n ),\n);\n\nexport type ProdiaImageProviderOptions = InferSchema<\n typeof prodiaImageProviderOptionsSchema\n>;\n\ninterface ProdiaImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nconst prodiaJobResultSchema = z.object({\n id: z.string(),\n created_at: z.string().optional(),\n updated_at: z.string().optional(),\n expires_at: z.string().optional(),\n state: z\n .object({\n current: z.string(),\n })\n .optional(),\n config: z\n .object({\n seed: z.number().optional(),\n })\n .passthrough()\n .optional(),\n metrics: z\n .object({\n elapsed: z.number().optional(),\n ips: z.number().optional(),\n })\n .optional(),\n});\n\ntype ProdiaJobResult = z.infer<typeof prodiaJobResultSchema>;\n\ninterface MultipartResult {\n jobResult: ProdiaJobResult;\n imageBytes: Uint8Array;\n}\n\nfunction createMultipartResponseHandler() {\n return async ({\n response,\n }: {\n response: Response;\n }): Promise<{\n value: MultipartResult;\n responseHeaders: Record<string, string>;\n }> => {\n const contentType = response.headers.get('content-type') ?? '';\n const responseHeaders: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n responseHeaders[key] = value;\n });\n\n const boundaryMatch = contentType.match(/boundary=([^\\s;]+)/);\n if (!boundaryMatch) {\n throw new Error(\n `Prodia response missing multipart boundary in content-type: ${contentType}`,\n );\n }\n const boundary = boundaryMatch[1];\n\n const arrayBuffer = await response.arrayBuffer();\n const bytes = new Uint8Array(arrayBuffer);\n\n const parts = parseMultipart(bytes, boundary);\n\n let jobResult: ProdiaJobResult | undefined;\n let imageBytes: Uint8Array | undefined;\n\n for (const part of parts) {\n const contentDisposition = part.headers['content-disposition'] ?? '';\n const partContentType = part.headers['content-type'] ?? '';\n\n if (contentDisposition.includes('name=\"job\"')) {\n const jsonStr = new TextDecoder().decode(part.body);\n jobResult = prodiaJobResultSchema.parse(JSON.parse(jsonStr));\n } else if (contentDisposition.includes('name=\"output\"')) {\n imageBytes = part.body;\n } else if (partContentType.startsWith('image/')) {\n imageBytes = part.body;\n }\n }\n\n if (!jobResult) {\n throw new Error('Prodia multipart response missing job part');\n }\n if (!imageBytes) {\n throw new Error('Prodia multipart response missing output image');\n }\n\n return {\n value: { jobResult, imageBytes },\n responseHeaders,\n };\n };\n}\n\ninterface MultipartPart {\n headers: Record<string, string>;\n body: Uint8Array;\n}\n\nfunction parseMultipart(data: Uint8Array, boundary: string): MultipartPart[] {\n const parts: MultipartPart[] = [];\n const boundaryBytes = new TextEncoder().encode(`--${boundary}`);\n const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);\n\n const positions: number[] = [];\n for (let i = 0; i <= data.length - boundaryBytes.length; i++) {\n let match = true;\n for (let j = 0; j < boundaryBytes.length; j++) {\n if (data[i + j] !== boundaryBytes[j]) {\n match = false;\n break;\n }\n }\n if (match) {\n positions.push(i);\n }\n }\n\n for (let i = 0; i < positions.length - 1; i++) {\n const start = positions[i] + boundaryBytes.length;\n const end = positions[i + 1];\n\n let isEndBoundary = true;\n for (let j = 0; j < endBoundaryBytes.length && isEndBoundary; j++) {\n if (data[positions[i] + j] !== endBoundaryBytes[j]) {\n isEndBoundary = false;\n }\n }\n if (\n isEndBoundary &&\n positions[i] + endBoundaryBytes.length <= data.length\n ) {\n continue;\n }\n\n let partStart = start;\n if (data[partStart] === 0x0d && data[partStart + 1] === 0x0a) {\n partStart += 2;\n } else if (data[partStart] === 0x0a) {\n partStart += 1;\n }\n\n let partEnd = end;\n if (data[partEnd - 2] === 0x0d && data[partEnd - 1] === 0x0a) {\n partEnd -= 2;\n } else if (data[partEnd - 1] === 0x0a) {\n partEnd -= 1;\n }\n\n const partData = data.slice(partStart, partEnd);\n\n let headerEnd = -1;\n for (let j = 0; j < partData.length - 3; j++) {\n if (\n partData[j] === 0x0d &&\n partData[j + 1] === 0x0a &&\n partData[j + 2] === 0x0d &&\n partData[j + 3] === 0x0a\n ) {\n headerEnd = j;\n break;\n }\n if (partData[j] === 0x0a && partData[j + 1] === 0x0a) {\n headerEnd = j;\n break;\n }\n }\n\n if (headerEnd === -1) {\n continue;\n }\n\n const headerBytes = partData.slice(0, headerEnd);\n const headerStr = new TextDecoder().decode(headerBytes);\n const headers: Record<string, string> = {};\n for (const line of headerStr.split(/\\r?\\n/)) {\n const colonIdx = line.indexOf(':');\n if (colonIdx > 0) {\n const key = line.slice(0, colonIdx).trim().toLowerCase();\n const value = line.slice(colonIdx + 1).trim();\n headers[key] = value;\n }\n }\n\n let bodyStart = headerEnd + 2;\n if (partData[headerEnd] === 0x0d) {\n bodyStart = headerEnd + 4;\n }\n const body = partData.slice(bodyStart);\n\n parts.push({ headers, body });\n }\n\n return parts;\n}\n\nconst prodiaErrorSchema = z.object({\n message: z.string().optional(),\n detail: z.unknown().optional(),\n error: z.string().optional(),\n});\n\nconst prodiaFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: prodiaErrorSchema,\n errorToMessage: error => {\n const parsed = prodiaErrorSchema.safeParse(error);\n if (!parsed.success) return 'Unknown Prodia error';\n const { message, detail, error: errorField } = parsed.data;\n if (typeof detail === 'string') return detail;\n if (detail != null) {\n try {\n return JSON.stringify(detail);\n } catch {\n // ignore\n }\n }\n return errorField ?? message ?? 'Unknown Prodia error';\n },\n});\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAIO;AAEP,IAAAA,yBAIO;;;ACRP,4BASO;AACP,gBAAkB;AAGX,IAAM,mBAAN,MAA+C;AAAA,EAQpD,YACW,SACQ,QACjB;AAFS;AACQ;AATnB,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAAA,EASzB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAc,QAAQ;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA8C;AAC5C,UAAM,WAA2C,CAAC;AAElD,UAAM,gBAAgB,UAAM,4CAAqB;AAAA,MAC/C,UAAU;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AAED,QAAI;AACJ,QAAI;AACJ,QAAI,MAAM;AACR,YAAM,CAAC,UAAU,SAAS,IAAI,KAAK,MAAM,GAAG;AAC5C,cAAQ,OAAO,QAAQ;AACvB,eAAS,OAAO,SAAS;AACzB,UACE,CAAC,YACD,CAAC,aACD,CAAC,OAAO,SAAS,KAAK,KACtB,CAAC,OAAO,SAAS,MAAM,GACvB;AACA,iBAAS,KAAK;AAAA,UACZ,MAAM;AAAA,UACN,SAAS;AAAA,UACT,SAAS,wBAAwB,IAAI;AAAA,QACvC,CAAC;AACD,gBAAQ;A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
|
|
1
|
+
// src/prodia-provider.ts
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
loadApiKey,
|
|
7
|
+
withoutTrailingSlash,
|
|
8
|
+
withUserAgentSuffix
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
10
|
+
|
|
11
|
+
// src/prodia-image-model.ts
|
|
12
|
+
import {
|
|
13
|
+
combineHeaders,
|
|
14
|
+
createJsonErrorResponseHandler,
|
|
15
|
+
lazySchema,
|
|
16
|
+
parseProviderOptions,
|
|
17
|
+
postToApi,
|
|
18
|
+
resolve,
|
|
19
|
+
zodSchema
|
|
20
|
+
} from "@ai-sdk/provider-utils";
|
|
21
|
+
import { z } from "zod/v4";
|
|
22
|
+
var ProdiaImageModel = class {
|
|
23
|
+
constructor(modelId, config) {
|
|
24
|
+
this.modelId = modelId;
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.specificationVersion = "v2";
|
|
27
|
+
this.maxImagesPerCall = 1;
|
|
28
|
+
}
|
|
29
|
+
get provider() {
|
|
30
|
+
return this.config.provider;
|
|
31
|
+
}
|
|
32
|
+
async getArgs({
|
|
33
|
+
prompt,
|
|
34
|
+
size,
|
|
35
|
+
seed,
|
|
36
|
+
providerOptions
|
|
37
|
+
}) {
|
|
38
|
+
const warnings = [];
|
|
39
|
+
const prodiaOptions = await parseProviderOptions({
|
|
40
|
+
provider: "prodia",
|
|
41
|
+
providerOptions,
|
|
42
|
+
schema: prodiaImageProviderOptionsSchema
|
|
43
|
+
});
|
|
44
|
+
let width;
|
|
45
|
+
let height;
|
|
46
|
+
if (size) {
|
|
47
|
+
const [widthStr, heightStr] = size.split("x");
|
|
48
|
+
width = Number(widthStr);
|
|
49
|
+
height = Number(heightStr);
|
|
50
|
+
if (!widthStr || !heightStr || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
51
|
+
warnings.push({
|
|
52
|
+
type: "unsupported-setting",
|
|
53
|
+
setting: "size",
|
|
54
|
+
details: `Invalid size format: ${size}. Expected format: WIDTHxHEIGHT (e.g., 1024x1024)`
|
|
55
|
+
});
|
|
56
|
+
width = void 0;
|
|
57
|
+
height = void 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const jobConfig = {
|
|
61
|
+
prompt
|
|
62
|
+
};
|
|
63
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.width) !== void 0) {
|
|
64
|
+
jobConfig.width = prodiaOptions.width;
|
|
65
|
+
} else if (width !== void 0) {
|
|
66
|
+
jobConfig.width = width;
|
|
67
|
+
}
|
|
68
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.height) !== void 0) {
|
|
69
|
+
jobConfig.height = prodiaOptions.height;
|
|
70
|
+
} else if (height !== void 0) {
|
|
71
|
+
jobConfig.height = height;
|
|
72
|
+
}
|
|
73
|
+
if (seed !== void 0) {
|
|
74
|
+
jobConfig.seed = seed;
|
|
75
|
+
}
|
|
76
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.steps) !== void 0) {
|
|
77
|
+
jobConfig.steps = prodiaOptions.steps;
|
|
78
|
+
}
|
|
79
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.stylePreset) !== void 0) {
|
|
80
|
+
jobConfig.style_preset = prodiaOptions.stylePreset;
|
|
81
|
+
}
|
|
82
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.loras) !== void 0 && prodiaOptions.loras.length > 0) {
|
|
83
|
+
jobConfig.loras = prodiaOptions.loras;
|
|
84
|
+
}
|
|
85
|
+
if ((prodiaOptions == null ? void 0 : prodiaOptions.progressive) !== void 0) {
|
|
86
|
+
jobConfig.progressive = prodiaOptions.progressive;
|
|
87
|
+
}
|
|
88
|
+
const body = {
|
|
89
|
+
type: this.modelId,
|
|
90
|
+
config: jobConfig
|
|
91
|
+
};
|
|
92
|
+
return { body, warnings };
|
|
93
|
+
}
|
|
94
|
+
async doGenerate(options) {
|
|
95
|
+
var _a, _b, _c, _d, _e, _f;
|
|
96
|
+
const { body, warnings } = await this.getArgs(options);
|
|
97
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
98
|
+
const combinedHeaders = combineHeaders(
|
|
99
|
+
await resolve(this.config.headers),
|
|
100
|
+
options.headers
|
|
101
|
+
);
|
|
102
|
+
const { value: multipartResult, responseHeaders } = await postToApi({
|
|
103
|
+
url: `${this.config.baseURL}/job`,
|
|
104
|
+
headers: {
|
|
105
|
+
...combinedHeaders,
|
|
106
|
+
Accept: "multipart/form-data; image/png",
|
|
107
|
+
"Content-Type": "application/json"
|
|
108
|
+
},
|
|
109
|
+
body: {
|
|
110
|
+
content: JSON.stringify(body),
|
|
111
|
+
values: body
|
|
112
|
+
},
|
|
113
|
+
failedResponseHandler: prodiaFailedResponseHandler,
|
|
114
|
+
successfulResponseHandler: createMultipartResponseHandler(),
|
|
115
|
+
abortSignal: options.abortSignal,
|
|
116
|
+
fetch: this.config.fetch
|
|
117
|
+
});
|
|
118
|
+
const { jobResult, imageBytes } = multipartResult;
|
|
119
|
+
return {
|
|
120
|
+
images: [imageBytes],
|
|
121
|
+
warnings,
|
|
122
|
+
providerMetadata: {
|
|
123
|
+
prodia: {
|
|
124
|
+
images: [
|
|
125
|
+
{
|
|
126
|
+
jobId: jobResult.id,
|
|
127
|
+
...((_d = jobResult.config) == null ? void 0 : _d.seed) != null && {
|
|
128
|
+
seed: jobResult.config.seed
|
|
129
|
+
},
|
|
130
|
+
...((_e = jobResult.metrics) == null ? void 0 : _e.elapsed) != null && {
|
|
131
|
+
elapsed: jobResult.metrics.elapsed
|
|
132
|
+
},
|
|
133
|
+
...((_f = jobResult.metrics) == null ? void 0 : _f.ips) != null && {
|
|
134
|
+
iterationsPerSecond: jobResult.metrics.ips
|
|
135
|
+
},
|
|
136
|
+
...jobResult.created_at != null && {
|
|
137
|
+
createdAt: jobResult.created_at
|
|
138
|
+
},
|
|
139
|
+
...jobResult.updated_at != null && {
|
|
140
|
+
updatedAt: jobResult.updated_at
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
response: {
|
|
147
|
+
modelId: this.modelId,
|
|
148
|
+
timestamp: currentDate,
|
|
149
|
+
headers: responseHeaders
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
var stylePresets = [
|
|
155
|
+
"3d-model",
|
|
156
|
+
"analog-film",
|
|
157
|
+
"anime",
|
|
158
|
+
"cinematic",
|
|
159
|
+
"comic-book",
|
|
160
|
+
"digital-art",
|
|
161
|
+
"enhance",
|
|
162
|
+
"fantasy-art",
|
|
163
|
+
"isometric",
|
|
164
|
+
"line-art",
|
|
165
|
+
"low-poly",
|
|
166
|
+
"neon-punk",
|
|
167
|
+
"origami",
|
|
168
|
+
"photographic",
|
|
169
|
+
"pixel-art",
|
|
170
|
+
"texture",
|
|
171
|
+
"craft-clay"
|
|
172
|
+
];
|
|
173
|
+
var prodiaImageProviderOptionsSchema = lazySchema(
|
|
174
|
+
() => zodSchema(
|
|
175
|
+
z.object({
|
|
176
|
+
/**
|
|
177
|
+
* Amount of computational iterations to run. More is typically higher quality.
|
|
178
|
+
*/
|
|
179
|
+
steps: z.number().int().min(1).max(4).optional(),
|
|
180
|
+
/**
|
|
181
|
+
* Width of the output image in pixels.
|
|
182
|
+
*/
|
|
183
|
+
width: z.number().int().min(256).max(1920).optional(),
|
|
184
|
+
/**
|
|
185
|
+
* Height of the output image in pixels.
|
|
186
|
+
*/
|
|
187
|
+
height: z.number().int().min(256).max(1920).optional(),
|
|
188
|
+
/**
|
|
189
|
+
* Apply a visual theme to your output image.
|
|
190
|
+
*/
|
|
191
|
+
stylePreset: z.enum(stylePresets).optional(),
|
|
192
|
+
/**
|
|
193
|
+
* Augment the output with a LoRa model.
|
|
194
|
+
*/
|
|
195
|
+
loras: z.array(z.string()).max(3).optional(),
|
|
196
|
+
/**
|
|
197
|
+
* When using JPEG output, return a progressive JPEG.
|
|
198
|
+
*/
|
|
199
|
+
progressive: z.boolean().optional()
|
|
200
|
+
})
|
|
201
|
+
)
|
|
202
|
+
);
|
|
203
|
+
var prodiaJobResultSchema = z.object({
|
|
204
|
+
id: z.string(),
|
|
205
|
+
created_at: z.string().optional(),
|
|
206
|
+
updated_at: z.string().optional(),
|
|
207
|
+
expires_at: z.string().optional(),
|
|
208
|
+
state: z.object({
|
|
209
|
+
current: z.string()
|
|
210
|
+
}).optional(),
|
|
211
|
+
config: z.object({
|
|
212
|
+
seed: z.number().optional()
|
|
213
|
+
}).passthrough().optional(),
|
|
214
|
+
metrics: z.object({
|
|
215
|
+
elapsed: z.number().optional(),
|
|
216
|
+
ips: z.number().optional()
|
|
217
|
+
}).optional()
|
|
218
|
+
});
|
|
219
|
+
function createMultipartResponseHandler() {
|
|
220
|
+
return async ({
|
|
221
|
+
response
|
|
222
|
+
}) => {
|
|
223
|
+
var _a, _b, _c;
|
|
224
|
+
const contentType = (_a = response.headers.get("content-type")) != null ? _a : "";
|
|
225
|
+
const responseHeaders = {};
|
|
226
|
+
response.headers.forEach((value, key) => {
|
|
227
|
+
responseHeaders[key] = value;
|
|
228
|
+
});
|
|
229
|
+
const boundaryMatch = contentType.match(/boundary=([^\s;]+)/);
|
|
230
|
+
if (!boundaryMatch) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
`Prodia response missing multipart boundary in content-type: ${contentType}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const boundary = boundaryMatch[1];
|
|
236
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
237
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
238
|
+
const parts = parseMultipart(bytes, boundary);
|
|
239
|
+
let jobResult;
|
|
240
|
+
let imageBytes;
|
|
241
|
+
for (const part of parts) {
|
|
242
|
+
const contentDisposition = (_b = part.headers["content-disposition"]) != null ? _b : "";
|
|
243
|
+
const partContentType = (_c = part.headers["content-type"]) != null ? _c : "";
|
|
244
|
+
if (contentDisposition.includes('name="job"')) {
|
|
245
|
+
const jsonStr = new TextDecoder().decode(part.body);
|
|
246
|
+
jobResult = prodiaJobResultSchema.parse(JSON.parse(jsonStr));
|
|
247
|
+
} else if (contentDisposition.includes('name="output"')) {
|
|
248
|
+
imageBytes = part.body;
|
|
249
|
+
} else if (partContentType.startsWith("image/")) {
|
|
250
|
+
imageBytes = part.body;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (!jobResult) {
|
|
254
|
+
throw new Error("Prodia multipart response missing job part");
|
|
255
|
+
}
|
|
256
|
+
if (!imageBytes) {
|
|
257
|
+
throw new Error("Prodia multipart response missing output image");
|
|
258
|
+
}
|
|
259
|
+
return {
|
|
260
|
+
value: { jobResult, imageBytes },
|
|
261
|
+
responseHeaders
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function parseMultipart(data, boundary) {
|
|
266
|
+
const parts = [];
|
|
267
|
+
const boundaryBytes = new TextEncoder().encode(`--${boundary}`);
|
|
268
|
+
const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);
|
|
269
|
+
const positions = [];
|
|
270
|
+
for (let i = 0; i <= data.length - boundaryBytes.length; i++) {
|
|
271
|
+
let match = true;
|
|
272
|
+
for (let j = 0; j < boundaryBytes.length; j++) {
|
|
273
|
+
if (data[i + j] !== boundaryBytes[j]) {
|
|
274
|
+
match = false;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (match) {
|
|
279
|
+
positions.push(i);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (let i = 0; i < positions.length - 1; i++) {
|
|
283
|
+
const start = positions[i] + boundaryBytes.length;
|
|
284
|
+
const end = positions[i + 1];
|
|
285
|
+
let isEndBoundary = true;
|
|
286
|
+
for (let j = 0; j < endBoundaryBytes.length && isEndBoundary; j++) {
|
|
287
|
+
if (data[positions[i] + j] !== endBoundaryBytes[j]) {
|
|
288
|
+
isEndBoundary = false;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (isEndBoundary && positions[i] + endBoundaryBytes.length <= data.length) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
let partStart = start;
|
|
295
|
+
if (data[partStart] === 13 && data[partStart + 1] === 10) {
|
|
296
|
+
partStart += 2;
|
|
297
|
+
} else if (data[partStart] === 10) {
|
|
298
|
+
partStart += 1;
|
|
299
|
+
}
|
|
300
|
+
let partEnd = end;
|
|
301
|
+
if (data[partEnd - 2] === 13 && data[partEnd - 1] === 10) {
|
|
302
|
+
partEnd -= 2;
|
|
303
|
+
} else if (data[partEnd - 1] === 10) {
|
|
304
|
+
partEnd -= 1;
|
|
305
|
+
}
|
|
306
|
+
const partData = data.slice(partStart, partEnd);
|
|
307
|
+
let headerEnd = -1;
|
|
308
|
+
for (let j = 0; j < partData.length - 3; j++) {
|
|
309
|
+
if (partData[j] === 13 && partData[j + 1] === 10 && partData[j + 2] === 13 && partData[j + 3] === 10) {
|
|
310
|
+
headerEnd = j;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
if (partData[j] === 10 && partData[j + 1] === 10) {
|
|
314
|
+
headerEnd = j;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (headerEnd === -1) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const headerBytes = partData.slice(0, headerEnd);
|
|
322
|
+
const headerStr = new TextDecoder().decode(headerBytes);
|
|
323
|
+
const headers = {};
|
|
324
|
+
for (const line of headerStr.split(/\r?\n/)) {
|
|
325
|
+
const colonIdx = line.indexOf(":");
|
|
326
|
+
if (colonIdx > 0) {
|
|
327
|
+
const key = line.slice(0, colonIdx).trim().toLowerCase();
|
|
328
|
+
const value = line.slice(colonIdx + 1).trim();
|
|
329
|
+
headers[key] = value;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
let bodyStart = headerEnd + 2;
|
|
333
|
+
if (partData[headerEnd] === 13) {
|
|
334
|
+
bodyStart = headerEnd + 4;
|
|
335
|
+
}
|
|
336
|
+
const body = partData.slice(bodyStart);
|
|
337
|
+
parts.push({ headers, body });
|
|
338
|
+
}
|
|
339
|
+
return parts;
|
|
340
|
+
}
|
|
341
|
+
var prodiaErrorSchema = z.object({
|
|
342
|
+
message: z.string().optional(),
|
|
343
|
+
detail: z.unknown().optional(),
|
|
344
|
+
error: z.string().optional()
|
|
345
|
+
});
|
|
346
|
+
var prodiaFailedResponseHandler = createJsonErrorResponseHandler({
|
|
347
|
+
errorSchema: prodiaErrorSchema,
|
|
348
|
+
errorToMessage: (error) => {
|
|
349
|
+
var _a;
|
|
350
|
+
const parsed = prodiaErrorSchema.safeParse(error);
|
|
351
|
+
if (!parsed.success) return "Unknown Prodia error";
|
|
352
|
+
const { message, detail, error: errorField } = parsed.data;
|
|
353
|
+
if (typeof detail === "string") return detail;
|
|
354
|
+
if (detail != null) {
|
|
355
|
+
try {
|
|
356
|
+
return JSON.stringify(detail);
|
|
357
|
+
} catch (e) {
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return (_a = errorField != null ? errorField : message) != null ? _a : "Unknown Prodia error";
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// src/version.ts
|
|
365
|
+
var VERSION = true ? "0.0.1" : "0.0.0-test";
|
|
366
|
+
|
|
367
|
+
// src/prodia-provider.ts
|
|
368
|
+
var defaultBaseURL = "https://inference.prodia.com/v2";
|
|
369
|
+
function createProdia(options = {}) {
|
|
370
|
+
var _a;
|
|
371
|
+
const baseURL = withoutTrailingSlash((_a = options.baseURL) != null ? _a : defaultBaseURL);
|
|
372
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
373
|
+
{
|
|
374
|
+
Authorization: `Bearer ${loadApiKey({
|
|
375
|
+
apiKey: options.apiKey,
|
|
376
|
+
environmentVariableName: "PRODIA_TOKEN",
|
|
377
|
+
description: "Prodia"
|
|
378
|
+
})}`,
|
|
379
|
+
...options.headers
|
|
380
|
+
},
|
|
381
|
+
`ai-sdk/prodia/${VERSION}`
|
|
382
|
+
);
|
|
383
|
+
const createImageModel = (modelId) => new ProdiaImageModel(modelId, {
|
|
384
|
+
provider: "prodia.image",
|
|
385
|
+
baseURL: baseURL != null ? baseURL : defaultBaseURL,
|
|
386
|
+
headers: getHeaders,
|
|
387
|
+
fetch: options.fetch
|
|
388
|
+
});
|
|
389
|
+
const textEmbeddingModel = (modelId) => {
|
|
390
|
+
throw new NoSuchModelError({
|
|
391
|
+
modelId,
|
|
392
|
+
modelType: "textEmbeddingModel"
|
|
393
|
+
});
|
|
394
|
+
};
|
|
395
|
+
const languageModel = (modelId) => {
|
|
396
|
+
throw new NoSuchModelError({
|
|
397
|
+
modelId,
|
|
398
|
+
modelType: "languageModel"
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
return {
|
|
402
|
+
imageModel: createImageModel,
|
|
403
|
+
image: createImageModel,
|
|
404
|
+
languageModel,
|
|
405
|
+
textEmbeddingModel
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
var prodia = createProdia();
|
|
409
|
+
export {
|
|
410
|
+
VERSION,
|
|
411
|
+
createProdia,
|
|
412
|
+
prodia
|
|
413
|
+
};
|
|
414
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/prodia-provider.ts","../src/prodia-image-model.ts","../src/version.ts"],"sourcesContent":["import {\n type ImageModelV2,\n NoSuchModelError,\n type ProviderV2,\n} from '@ai-sdk/provider';\nimport type { FetchFunction } from '@ai-sdk/provider-utils';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { ProdiaImageModel } from './prodia-image-model';\nimport type { ProdiaImageModelId } from './prodia-image-settings';\nimport { VERSION } from './version';\n\nexport interface ProdiaProviderSettings {\n /**\n * Prodia API key. Default value is taken from the `PRODIA_TOKEN` environment variable.\n */\n apiKey?: string;\n\n /**\n * Base URL for the API calls. Defaults to `https://inference.prodia.com/v2`.\n */\n baseURL?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept\n * requests, or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface ProdiaProvider extends ProviderV2 {\n /**\n * Creates a model for image generation.\n */\n image(modelId: ProdiaImageModelId): ImageModelV2;\n\n /**\n * Creates a model for image generation.\n */\n imageModel(modelId: ProdiaImageModelId): ImageModelV2;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://inference.prodia.com/v2';\n\nexport function createProdia(\n options: ProdiaProviderSettings = {},\n): ProdiaProvider {\n const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'PRODIA_TOKEN',\n description: 'Prodia',\n })}`,\n ...options.headers,\n },\n `ai-sdk/prodia/${VERSION}`,\n );\n\n const createImageModel = (modelId: ProdiaImageModelId) =>\n new ProdiaImageModel(modelId, {\n provider: 'prodia.image',\n baseURL: baseURL ?? defaultBaseURL,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'textEmbeddingModel',\n });\n };\n\n const languageModel = (modelId: string) => {\n throw new NoSuchModelError({\n modelId,\n modelType: 'languageModel',\n });\n };\n\n return {\n imageModel: createImageModel,\n image: createImageModel,\n languageModel,\n textEmbeddingModel,\n };\n}\n\nexport const prodia = createProdia();\n","import type { ImageModelV2, ImageModelV2CallWarning } from '@ai-sdk/provider';\nimport type { InferSchema, Resolvable } from '@ai-sdk/provider-utils';\nimport {\n combineHeaders,\n createJsonErrorResponseHandler,\n type FetchFunction,\n lazySchema,\n parseProviderOptions,\n postToApi,\n resolve,\n zodSchema,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport type { ProdiaImageModelId } from './prodia-image-settings';\n\nexport class ProdiaImageModel implements ImageModelV2 {\n readonly specificationVersion = 'v2';\n readonly maxImagesPerCall = 1;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: ProdiaImageModelId,\n private readonly config: ProdiaImageModelConfig,\n ) {}\n\n private async getArgs({\n prompt,\n size,\n seed,\n providerOptions,\n }: Parameters<ImageModelV2['doGenerate']>[0]) {\n const warnings: Array<ImageModelV2CallWarning> = [];\n\n const prodiaOptions = await parseProviderOptions({\n provider: 'prodia',\n providerOptions,\n schema: prodiaImageProviderOptionsSchema,\n });\n\n let width: number | undefined;\n let height: number | undefined;\n if (size) {\n const [widthStr, heightStr] = size.split('x');\n width = Number(widthStr);\n height = Number(heightStr);\n if (\n !widthStr ||\n !heightStr ||\n !Number.isFinite(width) ||\n !Number.isFinite(height)\n ) {\n warnings.push({\n type: 'unsupported-setting',\n setting: 'size',\n details: `Invalid size format: ${size}. Expected format: WIDTHxHEIGHT (e.g., 1024x1024)`,\n });\n width = undefined;\n height = undefined;\n }\n }\n\n const jobConfig: Record<string, unknown> = {\n prompt,\n };\n\n if (prodiaOptions?.width !== undefined) {\n jobConfig.width = prodiaOptions.width;\n } else if (width !== undefined) {\n jobConfig.width = width;\n }\n\n if (prodiaOptions?.height !== undefined) {\n jobConfig.height = prodiaOptions.height;\n } else if (height !== undefined) {\n jobConfig.height = height;\n }\n\n if (seed !== undefined) {\n jobConfig.seed = seed;\n }\n if (prodiaOptions?.steps !== undefined) {\n jobConfig.steps = prodiaOptions.steps;\n }\n if (prodiaOptions?.stylePreset !== undefined) {\n jobConfig.style_preset = prodiaOptions.stylePreset;\n }\n if (prodiaOptions?.loras !== undefined && prodiaOptions.loras.length > 0) {\n jobConfig.loras = prodiaOptions.loras;\n }\n if (prodiaOptions?.progressive !== undefined) {\n jobConfig.progressive = prodiaOptions.progressive;\n }\n\n const body = {\n type: this.modelId,\n config: jobConfig,\n };\n\n return { body, warnings };\n }\n\n async doGenerate(\n options: Parameters<ImageModelV2['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<ImageModelV2['doGenerate']>>> {\n const { body, warnings } = await this.getArgs(options);\n\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const combinedHeaders = combineHeaders(\n await resolve(this.config.headers),\n options.headers,\n );\n\n const { value: multipartResult, responseHeaders } = await postToApi({\n url: `${this.config.baseURL}/job`,\n headers: {\n ...combinedHeaders,\n Accept: 'multipart/form-data; image/png',\n 'Content-Type': 'application/json',\n },\n body: {\n content: JSON.stringify(body),\n values: body,\n },\n failedResponseHandler: prodiaFailedResponseHandler,\n successfulResponseHandler: createMultipartResponseHandler(),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n const { jobResult, imageBytes } = multipartResult;\n\n return {\n images: [imageBytes],\n warnings,\n providerMetadata: {\n prodia: {\n images: [\n {\n jobId: jobResult.id,\n ...(jobResult.config?.seed != null && {\n seed: jobResult.config.seed,\n }),\n ...(jobResult.metrics?.elapsed != null && {\n elapsed: jobResult.metrics.elapsed,\n }),\n ...(jobResult.metrics?.ips != null && {\n iterationsPerSecond: jobResult.metrics.ips,\n }),\n ...(jobResult.created_at != null && {\n createdAt: jobResult.created_at,\n }),\n ...(jobResult.updated_at != null && {\n updatedAt: jobResult.updated_at,\n }),\n },\n ],\n },\n },\n response: {\n modelId: this.modelId,\n timestamp: currentDate,\n headers: responseHeaders,\n },\n };\n }\n}\n\nconst stylePresets = [\n '3d-model',\n 'analog-film',\n 'anime',\n 'cinematic',\n 'comic-book',\n 'digital-art',\n 'enhance',\n 'fantasy-art',\n 'isometric',\n 'line-art',\n 'low-poly',\n 'neon-punk',\n 'origami',\n 'photographic',\n 'pixel-art',\n 'texture',\n 'craft-clay',\n] as const;\n\nexport const prodiaImageProviderOptionsSchema = lazySchema(() =>\n zodSchema(\n z.object({\n /**\n * Amount of computational iterations to run. More is typically higher quality.\n */\n steps: z.number().int().min(1).max(4).optional(),\n /**\n * Width of the output image in pixels.\n */\n width: z.number().int().min(256).max(1920).optional(),\n /**\n * Height of the output image in pixels.\n */\n height: z.number().int().min(256).max(1920).optional(),\n /**\n * Apply a visual theme to your output image.\n */\n stylePreset: z.enum(stylePresets).optional(),\n /**\n * Augment the output with a LoRa model.\n */\n loras: z.array(z.string()).max(3).optional(),\n /**\n * When using JPEG output, return a progressive JPEG.\n */\n progressive: z.boolean().optional(),\n }),\n ),\n);\n\nexport type ProdiaImageProviderOptions = InferSchema<\n typeof prodiaImageProviderOptionsSchema\n>;\n\ninterface ProdiaImageModelConfig {\n provider: string;\n baseURL: string;\n headers?: Resolvable<Record<string, string | undefined>>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nconst prodiaJobResultSchema = z.object({\n id: z.string(),\n created_at: z.string().optional(),\n updated_at: z.string().optional(),\n expires_at: z.string().optional(),\n state: z\n .object({\n current: z.string(),\n })\n .optional(),\n config: z\n .object({\n seed: z.number().optional(),\n })\n .passthrough()\n .optional(),\n metrics: z\n .object({\n elapsed: z.number().optional(),\n ips: z.number().optional(),\n })\n .optional(),\n});\n\ntype ProdiaJobResult = z.infer<typeof prodiaJobResultSchema>;\n\ninterface MultipartResult {\n jobResult: ProdiaJobResult;\n imageBytes: Uint8Array;\n}\n\nfunction createMultipartResponseHandler() {\n return async ({\n response,\n }: {\n response: Response;\n }): Promise<{\n value: MultipartResult;\n responseHeaders: Record<string, string>;\n }> => {\n const contentType = response.headers.get('content-type') ?? '';\n const responseHeaders: Record<string, string> = {};\n response.headers.forEach((value, key) => {\n responseHeaders[key] = value;\n });\n\n const boundaryMatch = contentType.match(/boundary=([^\\s;]+)/);\n if (!boundaryMatch) {\n throw new Error(\n `Prodia response missing multipart boundary in content-type: ${contentType}`,\n );\n }\n const boundary = boundaryMatch[1];\n\n const arrayBuffer = await response.arrayBuffer();\n const bytes = new Uint8Array(arrayBuffer);\n\n const parts = parseMultipart(bytes, boundary);\n\n let jobResult: ProdiaJobResult | undefined;\n let imageBytes: Uint8Array | undefined;\n\n for (const part of parts) {\n const contentDisposition = part.headers['content-disposition'] ?? '';\n const partContentType = part.headers['content-type'] ?? '';\n\n if (contentDisposition.includes('name=\"job\"')) {\n const jsonStr = new TextDecoder().decode(part.body);\n jobResult = prodiaJobResultSchema.parse(JSON.parse(jsonStr));\n } else if (contentDisposition.includes('name=\"output\"')) {\n imageBytes = part.body;\n } else if (partContentType.startsWith('image/')) {\n imageBytes = part.body;\n }\n }\n\n if (!jobResult) {\n throw new Error('Prodia multipart response missing job part');\n }\n if (!imageBytes) {\n throw new Error('Prodia multipart response missing output image');\n }\n\n return {\n value: { jobResult, imageBytes },\n responseHeaders,\n };\n };\n}\n\ninterface MultipartPart {\n headers: Record<string, string>;\n body: Uint8Array;\n}\n\nfunction parseMultipart(data: Uint8Array, boundary: string): MultipartPart[] {\n const parts: MultipartPart[] = [];\n const boundaryBytes = new TextEncoder().encode(`--${boundary}`);\n const endBoundaryBytes = new TextEncoder().encode(`--${boundary}--`);\n\n const positions: number[] = [];\n for (let i = 0; i <= data.length - boundaryBytes.length; i++) {\n let match = true;\n for (let j = 0; j < boundaryBytes.length; j++) {\n if (data[i + j] !== boundaryBytes[j]) {\n match = false;\n break;\n }\n }\n if (match) {\n positions.push(i);\n }\n }\n\n for (let i = 0; i < positions.length - 1; i++) {\n const start = positions[i] + boundaryBytes.length;\n const end = positions[i + 1];\n\n let isEndBoundary = true;\n for (let j = 0; j < endBoundaryBytes.length && isEndBoundary; j++) {\n if (data[positions[i] + j] !== endBoundaryBytes[j]) {\n isEndBoundary = false;\n }\n }\n if (\n isEndBoundary &&\n positions[i] + endBoundaryBytes.length <= data.length\n ) {\n continue;\n }\n\n let partStart = start;\n if (data[partStart] === 0x0d && data[partStart + 1] === 0x0a) {\n partStart += 2;\n } else if (data[partStart] === 0x0a) {\n partStart += 1;\n }\n\n let partEnd = end;\n if (data[partEnd - 2] === 0x0d && data[partEnd - 1] === 0x0a) {\n partEnd -= 2;\n } else if (data[partEnd - 1] === 0x0a) {\n partEnd -= 1;\n }\n\n const partData = data.slice(partStart, partEnd);\n\n let headerEnd = -1;\n for (let j = 0; j < partData.length - 3; j++) {\n if (\n partData[j] === 0x0d &&\n partData[j + 1] === 0x0a &&\n partData[j + 2] === 0x0d &&\n partData[j + 3] === 0x0a\n ) {\n headerEnd = j;\n break;\n }\n if (partData[j] === 0x0a && partData[j + 1] === 0x0a) {\n headerEnd = j;\n break;\n }\n }\n\n if (headerEnd === -1) {\n continue;\n }\n\n const headerBytes = partData.slice(0, headerEnd);\n const headerStr = new TextDecoder().decode(headerBytes);\n const headers: Record<string, string> = {};\n for (const line of headerStr.split(/\\r?\\n/)) {\n const colonIdx = line.indexOf(':');\n if (colonIdx > 0) {\n const key = line.slice(0, colonIdx).trim().toLowerCase();\n const value = line.slice(colonIdx + 1).trim();\n headers[key] = value;\n }\n }\n\n let bodyStart = headerEnd + 2;\n if (partData[headerEnd] === 0x0d) {\n bodyStart = headerEnd + 4;\n }\n const body = partData.slice(bodyStart);\n\n parts.push({ headers, body });\n }\n\n return parts;\n}\n\nconst prodiaErrorSchema = z.object({\n message: z.string().optional(),\n detail: z.unknown().optional(),\n error: z.string().optional(),\n});\n\nconst prodiaFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: prodiaErrorSchema,\n errorToMessage: error => {\n const parsed = prodiaErrorSchema.safeParse(error);\n if (!parsed.success) return 'Unknown Prodia error';\n const { message, detail, error: errorField } = parsed.data;\n if (typeof detail === 'string') return detail;\n if (detail != null) {\n try {\n return JSON.stringify(detail);\n } catch {\n // ignore\n }\n }\n return errorField ?? message ?? 'Unknown Prodia error';\n },\n});\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,OAEK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACRP;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS;AAGX,IAAM,mBAAN,MAA+C;AAAA,EAQpD,YACW,SACQ,QACjB;AAFS;AACQ;AATnB,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAAA,EASzB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAc,QAAQ;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA8C;AAC5C,UAAM,WAA2C,CAAC;AAElD,UAAM,gBAAgB,MAAM,qBAAqB;AAAA,MAC/C,UAAU;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,IACV,CAAC;AAED,QAAI;AACJ,QAAI;AACJ,QAAI,MAAM;AACR,YAAM,CAAC,UAAU,SAAS,IAAI,KAAK,MAAM,GAAG;AAC5C,cAAQ,OAAO,QAAQ;AACvB,eAAS,OAAO,SAAS;AACzB,UACE,CAAC,YACD,CAAC,aACD,CAAC,OAAO,SAAS,KAAK,KACtB,CAAC,OAAO,SAAS,MAAM,GACvB;AACA,iBAAS,KAAK;AAAA,UACZ,MAAM;AAAA,UACN,SAAS;AAAA,UACT,SAAS,wBAAwB,IAAI;AAAA,QACvC,CAAC;AACD,gBAAQ;AACR,iBAAS;AAAA,MACX;AAAA,IACF;AAEA,UAAM,YAAqC;AAAA,MACzC;AAAA,IACF;AAEA,SAAI,+CAAe,WAAU,QAAW;AACtC,gBAAU,QAAQ,cAAc;AAAA,IAClC,WA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AM;AAClB,UAAI;AACF,eAAO,KAAK,UAAU,MAAM;AAAA,MAC9B,SAAQ;AAAA,MAER;AAAA,IACF;AACA,YAAO,uCAAc,YAAd,YAAyB;AAAA,EAClC;AACF,CAAC;;;AC/bM,IAAM,UACX,OACI,UACA;;;AFkDN,IAAM,iBAAiB;AAEhB,SAAS,aACd,UAAkC,CAAC,GACnB;AA3DlB;AA4DE,QAAM,UAAU,sBAAqB,aAAQ,YAAR,YAAmB,cAAc;AACtE,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,iBAAiB,OAAO;AAAA,EAC1B;AAEF,QAAM,mBAAmB,CAAC,YACxB,IAAI,iBAAiB,SAAS;AAAA,IAC5B,UAAU;AAAA,IACV,SAAS,4BAAW;AAAA,IACpB,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB,CAAC;AAEH,QAAM,qBAAqB,CAAC,YAAoB;AAC9C,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,QAAM,gBAAgB,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB;AAAA,MACzB;AAAA,MACA,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,YAAY;AAAA,IACZ,OAAO;AAAA,IACP;AAAA,IACA;AAAA,EACF;AACF;AAEO,IAAM,SAAS,aAAa;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ai-sdk/prodia",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*",
|
|
11
|
+
"CHANGELOG.md"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": "./package.json",
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ai-sdk/provider": "2.0.1",
|
|
23
|
+
"@ai-sdk/provider-utils": "3.0.20"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "20.17.24",
|
|
27
|
+
"tsup": "^8",
|
|
28
|
+
"typescript": "5.8.3",
|
|
29
|
+
"zod": "3.25.76",
|
|
30
|
+
"@vercel/ai-tsconfig": "0.0.0",
|
|
31
|
+
"@ai-sdk/test-server": "0.0.2"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"zod": "^3.25.76 || ^4.1.8"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://ai-sdk.dev/docs",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/vercel/ai.git"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/vercel/ai/issues"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"ai"
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
55
|
+
"build:watch": "pnpm clean && tsup --watch",
|
|
56
|
+
"clean": "del-cli dist *.tsbuildinfo",
|
|
57
|
+
"lint": "eslint \"./**/*.ts*\"",
|
|
58
|
+
"type-check": "tsc --build",
|
|
59
|
+
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
60
|
+
"test": "pnpm test:node && pnpm test:edge",
|
|
61
|
+
"test:update": "pnpm test:node -u",
|
|
62
|
+
"test:watch": "vitest --config vitest.node.config.js",
|
|
63
|
+
"test:edge": "vitest --config vitest.edge.config.js --run",
|
|
64
|
+
"test:node": "vitest --config vitest.node.config.js --run"
|
|
65
|
+
}
|
|
66
|
+
}
|