@framers/agentos-ext-image-generation 1.1.0 → 2.0.0
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/dist/ImageGenerationService.d.ts +36 -4
- package/dist/ImageGenerationService.d.ts.map +1 -1
- package/dist/ImageGenerationService.js +69 -35
- package/dist/ImageGenerationService.js.map +1 -1
- package/dist/imageFiles.d.ts +113 -0
- package/dist/imageFiles.d.ts.map +1 -0
- package/dist/imageFiles.js +325 -0
- package/dist/imageFiles.js.map +1 -0
- package/dist/index.d.ts +31 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/tools/generateImage.d.ts +14 -4
- package/dist/tools/generateImage.d.ts.map +1 -1
- package/dist/tools/generateImage.js +57 -11
- package/dist/tools/generateImage.js.map +1 -1
- package/manifest.json +2 -2
- package/package.json +3 -3
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Image generation service backed by AgentOS's shared
|
|
3
3
|
* provider-agnostic image API.
|
|
4
|
+
*
|
|
5
|
+
* Image data a provider returns is saved and the result carries the saved
|
|
6
|
+
* copy's URL, never the data: see `imageFiles.ts`.
|
|
4
7
|
*/
|
|
5
8
|
import { type ImageProviderOptionBag } from '@framers/agentos';
|
|
9
|
+
import { type SaveImage } from './imageFiles.js';
|
|
6
10
|
export type ImageGenerationProvider = 'openai' | 'openrouter' | 'stability' | 'replicate';
|
|
11
|
+
/**
|
|
12
|
+
* The quality of an image. OpenAI's GPT Image models take `low`, `medium`,
|
|
13
|
+
* `high` and `auto`; `standard` and `hd` were DALL·E 3's names and are sent
|
|
14
|
+
* to them as `medium` and `high`.
|
|
15
|
+
*/
|
|
16
|
+
export type ImageQuality = 'low' | 'medium' | 'high' | 'auto' | 'standard' | 'hd';
|
|
7
17
|
export interface ImageGenerationConfig {
|
|
8
18
|
openaiApiKey?: string;
|
|
9
19
|
openrouterApiKey?: string;
|
|
@@ -12,13 +22,20 @@ export interface ImageGenerationConfig {
|
|
|
12
22
|
defaultProvider?: ImageGenerationProvider;
|
|
13
23
|
defaultModel?: string;
|
|
14
24
|
defaultSize?: string;
|
|
15
|
-
defaultQuality?:
|
|
25
|
+
defaultQuality?: ImageQuality;
|
|
26
|
+
/**
|
|
27
|
+
* Where image data a provider returns is saved (else `AGENTOS_IMAGE_DIR`,
|
|
28
|
+
* else a folder in the user's temp directory).
|
|
29
|
+
*/
|
|
30
|
+
imageDir?: string;
|
|
31
|
+
/** Stores image data in place of the default saver and returns the http(s) URL the host's clients load. */
|
|
32
|
+
saveImage?: SaveImage;
|
|
16
33
|
}
|
|
17
34
|
export interface GenerateImageOptions {
|
|
18
35
|
prompt: string;
|
|
19
|
-
size?:
|
|
36
|
+
size?: string;
|
|
20
37
|
aspectRatio?: string;
|
|
21
|
-
quality?:
|
|
38
|
+
quality?: ImageQuality;
|
|
22
39
|
style?: 'vivid' | 'natural';
|
|
23
40
|
n?: number;
|
|
24
41
|
provider?: ImageGenerationProvider;
|
|
@@ -28,6 +45,7 @@ export interface GenerateImageOptions {
|
|
|
28
45
|
providerOptions?: ImageProviderOptionBag | Record<string, unknown>;
|
|
29
46
|
}
|
|
30
47
|
export interface GeneratedImage {
|
|
48
|
+
/** The provider's image URL, or the URL of the copy that was saved of the image data it returned. */
|
|
31
49
|
url: string;
|
|
32
50
|
revisedPrompt?: string;
|
|
33
51
|
provider: string;
|
|
@@ -36,6 +54,7 @@ export interface GeneratedImage {
|
|
|
36
54
|
}
|
|
37
55
|
export declare class ImageGenerationService {
|
|
38
56
|
private readonly config;
|
|
57
|
+
private readonly store;
|
|
39
58
|
private initialized;
|
|
40
59
|
constructor(config: ImageGenerationConfig);
|
|
41
60
|
get hasOpenAI(): boolean;
|
|
@@ -44,12 +63,25 @@ export declare class ImageGenerationService {
|
|
|
44
63
|
get hasReplicate(): boolean;
|
|
45
64
|
get hasAnyProvider(): boolean;
|
|
46
65
|
initialize(): Promise<void>;
|
|
47
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Generates one image.
|
|
68
|
+
*
|
|
69
|
+
* @param options - The prompt and its settings.
|
|
70
|
+
* @param context - The tool call's context, when there is one: image data
|
|
71
|
+
* is saved in the calling user's own subdirectory and handed to a host's
|
|
72
|
+
* `saveImage` with it.
|
|
73
|
+
*/
|
|
74
|
+
generateImage(options: GenerateImageOptions, context?: unknown): Promise<GeneratedImage>;
|
|
48
75
|
shutdown(): Promise<void>;
|
|
49
76
|
private resolveProvider;
|
|
50
77
|
private getApiKey;
|
|
51
78
|
private defaultModelForProvider;
|
|
52
79
|
private displayNameForProvider;
|
|
80
|
+
/**
|
|
81
|
+
* The provider options of a call. A `style` goes to an OpenAI model that
|
|
82
|
+
* is not a GPT Image model (one behind a gateway) as its `style` parameter;
|
|
83
|
+
* a GPT Image model is sent none, from the call or from the options.
|
|
84
|
+
*/
|
|
53
85
|
private normalizeProviderOptions;
|
|
54
86
|
}
|
|
55
87
|
//# sourceMappingURL=ImageGenerationService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageGenerationService.d.ts","sourceRoot":"","sources":["../src/ImageGenerationService.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"ImageGenerationService.d.ts","sourceRoot":"","sources":["../src/ImageGenerationService.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAA2C,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE1F,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1F;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,CAAC;AAwBlF,MAAM,WAAW,qBAAqB;IACpC,YAAY,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E,qBAAqB;IAKzC,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,IAAI,cAAc,IAAI,OAAO,CAE5B;IAEK,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;;;;OAOG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC;IAkDxF,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,OAAO,CAAC,eAAe;IAcvB,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,uBAAuB;IAe/B,OAAO,CAAC,sBAAsB;IAe9B;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;CAkBjC"}
|
|
@@ -3,10 +3,33 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Image generation service backed by AgentOS's shared
|
|
5
5
|
* provider-agnostic image API.
|
|
6
|
+
*
|
|
7
|
+
* Image data a provider returns is saved and the result carries the saved
|
|
8
|
+
* copy's URL, never the data: see `imageFiles.ts`.
|
|
6
9
|
*/
|
|
7
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
11
|
exports.ImageGenerationService = void 0;
|
|
9
12
|
const agentos_1 = require("@framers/agentos");
|
|
13
|
+
const imageFiles_js_1 = require("./imageFiles.js");
|
|
14
|
+
/**
|
|
15
|
+
* OpenAI's model for making an image from a prompt. OpenAI shut down
|
|
16
|
+
* `dall-e-2` and `dall-e-3` on 2026-05-12, and shuts down `gpt-image-1` on
|
|
17
|
+
* 2026-10-23 and `gpt-image-1.5` on 2026-12-01
|
|
18
|
+
* (https://developers.openai.com/api/docs/deprecations).
|
|
19
|
+
*/
|
|
20
|
+
const OPENAI_IMAGE_MODEL = 'gpt-image-2.5-flare';
|
|
21
|
+
/** Whether `model` names one of OpenAI's GPT Image models. */
|
|
22
|
+
function isGptImageModel(model) {
|
|
23
|
+
return /^(gpt-image-|chatgpt-image-)/.test(model);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What a GPT Image model is told for a style, in the prompt: it takes no
|
|
27
|
+
* `style` parameter, which was DALL·E 3's.
|
|
28
|
+
*/
|
|
29
|
+
const STYLE_SENTENCE = {
|
|
30
|
+
vivid: 'Style: vivid, hyper-real and dramatic.',
|
|
31
|
+
natural: 'Style: natural and realistic.',
|
|
32
|
+
};
|
|
10
33
|
const PROVIDER_DOCS_URL = {
|
|
11
34
|
openai: 'https://platform.openai.com/api-keys',
|
|
12
35
|
openrouter: 'https://openrouter.ai/settings/keys',
|
|
@@ -17,6 +40,7 @@ class ImageGenerationService {
|
|
|
17
40
|
constructor(config) {
|
|
18
41
|
this.initialized = false;
|
|
19
42
|
this.config = config;
|
|
43
|
+
this.store = (0, imageFiles_js_1.imageStore)(config);
|
|
20
44
|
}
|
|
21
45
|
get hasOpenAI() {
|
|
22
46
|
return !!this.config.openaiApiKey;
|
|
@@ -36,7 +60,15 @@ class ImageGenerationService {
|
|
|
36
60
|
async initialize() {
|
|
37
61
|
this.initialized = true;
|
|
38
62
|
}
|
|
39
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Generates one image.
|
|
65
|
+
*
|
|
66
|
+
* @param options - The prompt and its settings.
|
|
67
|
+
* @param context - The tool call's context, when there is one: image data
|
|
68
|
+
* is saved in the calling user's own subdirectory and handed to a host's
|
|
69
|
+
* `saveImage` with it.
|
|
70
|
+
*/
|
|
71
|
+
async generateImage(options, context) {
|
|
40
72
|
const provider = this.resolveProvider(options.provider);
|
|
41
73
|
const apiKey = this.getApiKey(provider);
|
|
42
74
|
if (!apiKey) {
|
|
@@ -44,27 +76,30 @@ class ImageGenerationService {
|
|
|
44
76
|
throw new Error(`${envVar} is required for ${this.displayNameForProvider(provider)} image generation. `
|
|
45
77
|
+ `Set it in your environment or .env file. Get one at ${PROVIDER_DOCS_URL[provider]}`);
|
|
46
78
|
}
|
|
47
|
-
const providerOptions = this.normalizeProviderOptions(provider, options);
|
|
48
79
|
const model = options.model || this.config.defaultModel || this.defaultModelForProvider(provider);
|
|
80
|
+
// A GPT Image model takes neither DALL·E 3's quality names nor its
|
|
81
|
+
// `style` parameter: the names are rewritten, and a style goes into the
|
|
82
|
+
// prompt.
|
|
83
|
+
const gptImage = provider === 'openai' && isGptImageModel(model);
|
|
84
|
+
const quality = options.quality || this.config.defaultQuality;
|
|
85
|
+
const style = gptImage && options.style ? STYLE_SENTENCE[options.style] : undefined;
|
|
49
86
|
const result = await (0, agentos_1.generateImage)({
|
|
50
87
|
model: `${provider}:${model}`,
|
|
51
|
-
prompt: options.prompt,
|
|
88
|
+
prompt: style ? `${options.prompt}\n\n${style}` : options.prompt,
|
|
52
89
|
apiKey,
|
|
53
90
|
size: options.size || this.config.defaultSize || '1024x1024',
|
|
54
91
|
aspectRatio: options.aspectRatio,
|
|
55
|
-
quality:
|
|
92
|
+
quality: gptImage ? gptImageQuality(quality) : quality,
|
|
56
93
|
n: options.n,
|
|
57
94
|
seed: options.seed,
|
|
58
95
|
negativePrompt: options.negativePrompt,
|
|
59
|
-
providerOptions,
|
|
96
|
+
providerOptions: this.normalizeProviderOptions(provider, options, gptImage),
|
|
60
97
|
});
|
|
61
|
-
const first = result.images[0];
|
|
98
|
+
const first = result.images?.[0];
|
|
62
99
|
if (!first) {
|
|
63
100
|
throw new Error('Image generation returned no images.');
|
|
64
101
|
}
|
|
65
|
-
const url =
|
|
66
|
-
? `data:${first.mimeType || 'image/png'};base64,${first.base64}`
|
|
67
|
-
: undefined);
|
|
102
|
+
const url = await (0, imageFiles_js_1.storeImage)(first, 'generate_image', this.store, context);
|
|
68
103
|
if (!url) {
|
|
69
104
|
throw new Error('Image generation returned no image URL or image data.');
|
|
70
105
|
}
|
|
@@ -113,7 +148,7 @@ class ImageGenerationService {
|
|
|
113
148
|
defaultModelForProvider(provider) {
|
|
114
149
|
switch (provider) {
|
|
115
150
|
case 'openai':
|
|
116
|
-
return
|
|
151
|
+
return OPENAI_IMAGE_MODEL;
|
|
117
152
|
case 'openrouter':
|
|
118
153
|
return 'google/gemini-2.5-flash-image';
|
|
119
154
|
case 'stability':
|
|
@@ -121,7 +156,7 @@ class ImageGenerationService {
|
|
|
121
156
|
case 'replicate':
|
|
122
157
|
return 'black-forest-labs/flux-schnell';
|
|
123
158
|
default:
|
|
124
|
-
return
|
|
159
|
+
return OPENAI_IMAGE_MODEL;
|
|
125
160
|
}
|
|
126
161
|
}
|
|
127
162
|
displayNameForProvider(provider) {
|
|
@@ -138,34 +173,33 @@ class ImageGenerationService {
|
|
|
138
173
|
return provider;
|
|
139
174
|
}
|
|
140
175
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
176
|
+
/**
|
|
177
|
+
* The provider options of a call. A `style` goes to an OpenAI model that
|
|
178
|
+
* is not a GPT Image model (one behind a gateway) as its `style` parameter;
|
|
179
|
+
* a GPT Image model is sent none, from the call or from the options.
|
|
180
|
+
*/
|
|
181
|
+
normalizeProviderOptions(provider, options, gptImage) {
|
|
182
|
+
const given = options.providerOptions && typeof options.providerOptions === 'object' && !Array.isArray(options.providerOptions)
|
|
146
183
|
? { ...options.providerOptions }
|
|
147
184
|
: undefined;
|
|
148
|
-
if (provider
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
openai: openAIOptions,
|
|
156
|
-
};
|
|
185
|
+
if (provider !== 'openai')
|
|
186
|
+
return given;
|
|
187
|
+
if (gptImage) {
|
|
188
|
+
if (!given?.openai || typeof given.openai !== 'object')
|
|
189
|
+
return given;
|
|
190
|
+
const { style: _style, ...openai } = given.openai;
|
|
191
|
+
return { ...given, openai };
|
|
157
192
|
}
|
|
158
|
-
if (
|
|
159
|
-
return
|
|
160
|
-
|
|
161
|
-
openai: {
|
|
162
|
-
...(providerOptions?.openai ?? {}),
|
|
163
|
-
style: options.style ?? providerOptions?.openai?.style ?? 'vivid',
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
return providerOptions;
|
|
193
|
+
if (!options.style)
|
|
194
|
+
return given;
|
|
195
|
+
return { ...(given ?? {}), openai: { ...(given?.openai ?? {}), style: options.style } };
|
|
168
196
|
}
|
|
169
197
|
}
|
|
170
198
|
exports.ImageGenerationService = ImageGenerationService;
|
|
199
|
+
/** The quality a GPT Image model is sent: `medium` when none is given, and for DALL·E 3's `standard`; `high` for its `hd`. */
|
|
200
|
+
function gptImageQuality(quality) {
|
|
201
|
+
if (!quality || quality === 'standard')
|
|
202
|
+
return 'medium';
|
|
203
|
+
return quality === 'hd' ? 'high' : quality;
|
|
204
|
+
}
|
|
171
205
|
//# sourceMappingURL=ImageGenerationService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageGenerationService.js","sourceRoot":"","sources":["../src/ImageGenerationService.ts"],"names":[],"mappings":";AAAA,cAAc;AACd;;;
|
|
1
|
+
{"version":3,"file":"ImageGenerationService.js","sourceRoot":"","sources":["../src/ImageGenerationService.ts"],"names":[],"mappings":";AAAA,cAAc;AACd;;;;;;GAMG;;;AAEH,8CAA8E;AAE9E,mDAA0F;AAW1F;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAEjD,8DAA8D;AAC9D,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,8BAA8B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,cAAc,GAAwC;IAC1D,KAAK,EAAE,wCAAwC;IAC/C,OAAO,EAAE,+BAA+B;CACzC,CAAC;AA2CF,MAAM,iBAAiB,GAA4C;IACjE,MAAM,EAAE,sCAAsC;IAC9C,UAAU,EAAE,qCAAqC;IACjD,SAAS,EAAE,4CAA4C;IACvD,SAAS,EAAE,0CA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AK,QAAQ;YAAE,OAAO,KAAK,CAAC;QACxC,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,EAAE,MAAM,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;gBAAE,OAAO,KAAK,CAAC;YACrE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;YAClD,OAAO,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK;YAAE,OAAO,KAAK,CAAC;QACjC,OAAO,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IAC1F,CAAC;CACF;AAlLD,wDAkLC;AAED,8HAA8H;AAC9H,SAAS,eAAe,CAAC,OAAiC;IACxD,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAC;IACxD,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Where the image tools keep image data, and how a saved image
|
|
3
|
+
* comes back as a source.
|
|
4
|
+
*
|
|
5
|
+
* A provider that answers with image data (OpenAI's GPT Image models always
|
|
6
|
+
* do) used to have that data returned to the model as a `data:` URL: megabytes
|
|
7
|
+
* of base64 in the next request. The tools save the bytes to a file and return
|
|
8
|
+
* its `file:` URL, or hand them to the host's own saver. A saved file's URL is
|
|
9
|
+
* accepted as a source by the image-editing tools and by `vision-pipeline`.
|
|
10
|
+
* The image-generation, image-editing and vision-pipeline packs each carry
|
|
11
|
+
* this file, the same in all three, so they agree on the directory.
|
|
12
|
+
*
|
|
13
|
+
* The directory is private to the service's user, each caller has a
|
|
14
|
+
* subdirectory of its own, and no other user can change a directory above
|
|
15
|
+
* it. That is the trust boundary: only this user can put a file there, or
|
|
16
|
+
* swap the directory for another, so a file there with the saver's name
|
|
17
|
+
* pattern is one the service wrote.
|
|
18
|
+
*/
|
|
19
|
+
/** The most bytes of a saved image the tools read back as a source: 50 MiB. */
|
|
20
|
+
export declare const MAX_SOURCE_BYTES: number;
|
|
21
|
+
/**
|
|
22
|
+
* The images directory: the pack option `imageDir`, else the environment
|
|
23
|
+
* variable `AGENTOS_IMAGE_DIR`, else a folder in the user's temp directory,
|
|
24
|
+
* which the operating system clears (the packs delete nothing). On POSIX the
|
|
25
|
+
* default carries the user id, since `/tmp` is shared. On Windows it is the
|
|
26
|
+
* user's own temp folder whatever `TEMP` says: `os.tmpdir()` reads `TEMP`,
|
|
27
|
+
* which can name a folder every user shares.
|
|
28
|
+
*/
|
|
29
|
+
export declare function imageDirectory(option?: unknown): string;
|
|
30
|
+
/**
|
|
31
|
+
* The name of a caller's subdirectory: `u-` and 32 hex characters of the
|
|
32
|
+
* SHA-256 of its user id, or `shared` for a call that carries none. A host
|
|
33
|
+
* with several users gives each call its user (`context.userContext.userId`),
|
|
34
|
+
* so one user's saved image is no source for another.
|
|
35
|
+
*/
|
|
36
|
+
export declare function scopeOf(context?: {
|
|
37
|
+
userContext?: {
|
|
38
|
+
userId?: unknown;
|
|
39
|
+
};
|
|
40
|
+
}): string;
|
|
41
|
+
/** The kind of image `bytes` are, by their signature: PNG, JPEG or WebP. */
|
|
42
|
+
export declare function imageKind(bytes: Buffer): {
|
|
43
|
+
ext: 'png' | 'jpg' | 'webp';
|
|
44
|
+
mimeType: string;
|
|
45
|
+
} | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Saves image bytes as a new file in the caller's subdirectory of `dir` and
|
|
48
|
+
* returns its `file:` URL. The extension comes from the bytes' signature, and
|
|
49
|
+
* the name is random, so a file is never overwritten.
|
|
50
|
+
*
|
|
51
|
+
* @throws When the bytes are not a PNG, JPEG or WebP image, or when the
|
|
52
|
+
* directory cannot be made, is not private to this user, or cannot be
|
|
53
|
+
* written. The message names the directory and the option that sets it.
|
|
54
|
+
*/
|
|
55
|
+
export declare function saveImageFile(bytes: Buffer, dir: string, scope: string): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* The bytes of the saved image that `source` names, or `undefined` when
|
|
58
|
+
* `source` is not the `file:` URL of an image the saver wrote for this
|
|
59
|
+
* caller. Every reason gives `undefined`, so the caller's one refusal does
|
|
60
|
+
* not tell which files exist.
|
|
61
|
+
*
|
|
62
|
+
* The file must carry the saver's name pattern and sit directly in the
|
|
63
|
+
* caller's subdirectory of the images directory's real path: the same
|
|
64
|
+
* directory by device and inode, itself a directory and not a link, private
|
|
65
|
+
* to this user, as the images directory is, with no directory above it that
|
|
66
|
+
* another user can change. It must be a regular file with one link and at
|
|
67
|
+
* most {@link MAX_SOURCE_BYTES}, and start with a PNG, JPEG or WebP
|
|
68
|
+
* signature. It is opened once, without following a link, and read from
|
|
69
|
+
* that handle.
|
|
70
|
+
*/
|
|
71
|
+
export declare function readSavedImage(source: string, dir: string, scope: string): Promise<Buffer | undefined>;
|
|
72
|
+
/** An image as AgentOS's image functions return it. */
|
|
73
|
+
export interface ReturnedImage {
|
|
74
|
+
url?: string;
|
|
75
|
+
dataUrl?: string;
|
|
76
|
+
base64?: string;
|
|
77
|
+
mimeType?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A host's own saver: it stores the bytes where the host's clients can load
|
|
81
|
+
* them and returns that http(s) URL.
|
|
82
|
+
*/
|
|
83
|
+
export type SaveImage = (image: {
|
|
84
|
+
bytes: Buffer;
|
|
85
|
+
mimeType: string;
|
|
86
|
+
tool: string;
|
|
87
|
+
context?: unknown;
|
|
88
|
+
}) => string | Promise<string>;
|
|
89
|
+
/** Where the tools keep image data: the directory of the default saver, and a host's own saver when it gave one. */
|
|
90
|
+
export interface ImageStore {
|
|
91
|
+
/** The images directory (see {@link imageDirectory}). */
|
|
92
|
+
dir: string;
|
|
93
|
+
/** The host's saver, which replaces the default. */
|
|
94
|
+
saveImage?: SaveImage;
|
|
95
|
+
}
|
|
96
|
+
/** The store for a pack's options: its `imageDir` and its `saveImage`, when that is a function. */
|
|
97
|
+
export declare function imageStore(options?: {
|
|
98
|
+
imageDir?: unknown;
|
|
99
|
+
saveImage?: unknown;
|
|
100
|
+
}): ImageStore;
|
|
101
|
+
/**
|
|
102
|
+
* An image a provider returned, as the reference the caller gets: the
|
|
103
|
+
* provider's http(s) URL as it is, or, for image data, the URL under which
|
|
104
|
+
* it was saved. Image data is never returned itself: as a `data:` URL it
|
|
105
|
+
* would go into the model's next request, megabytes of base64. `undefined`
|
|
106
|
+
* when the provider returned neither a URL nor data.
|
|
107
|
+
*
|
|
108
|
+
* @throws When the data is not a PNG, JPEG or WebP image, when it cannot be
|
|
109
|
+
* saved, or when the host's saver throws or returns anything but an
|
|
110
|
+
* http(s) URL of at most 2,048 characters.
|
|
111
|
+
*/
|
|
112
|
+
export declare function storeImage(image: ReturnedImage | undefined, tool: string, store: ImageStore, context?: unknown): Promise<string | undefined>;
|
|
113
|
+
//# sourceMappingURL=imageFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageFiles.d.ts","sourceRoot":"","sources":["../src/imageFiles.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AASH,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,QAAmB,CAAC;AAQjD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAOvD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,CAKhF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;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,KAAK,EAAE,aAAa,GAAG,SAAS,EAChC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB7B"}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Where the image tools keep image data, and how a saved image
|
|
5
|
+
* comes back as a source.
|
|
6
|
+
*
|
|
7
|
+
* A provider that answers with image data (OpenAI's GPT Image models always
|
|
8
|
+
* do) used to have that data returned to the model as a `data:` URL: megabytes
|
|
9
|
+
* of base64 in the next request. The tools save the bytes to a file and return
|
|
10
|
+
* its `file:` URL, or hand them to the host's own saver. A saved file's URL is
|
|
11
|
+
* accepted as a source by the image-editing tools and by `vision-pipeline`.
|
|
12
|
+
* The image-generation, image-editing and vision-pipeline packs each carry
|
|
13
|
+
* this file, the same in all three, so they agree on the directory.
|
|
14
|
+
*
|
|
15
|
+
* The directory is private to the service's user, each caller has a
|
|
16
|
+
* subdirectory of its own, and no other user can change a directory above
|
|
17
|
+
* it. That is the trust boundary: only this user can put a file there, or
|
|
18
|
+
* swap the directory for another, so a file there with the saver's name
|
|
19
|
+
* pattern is one the service wrote.
|
|
20
|
+
*/
|
|
21
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
24
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
25
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
26
|
+
}
|
|
27
|
+
Object.defineProperty(o, k2, desc);
|
|
28
|
+
}) : (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
o[k2] = m[k];
|
|
31
|
+
}));
|
|
32
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
33
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
34
|
+
}) : function(o, v) {
|
|
35
|
+
o["default"] = v;
|
|
36
|
+
});
|
|
37
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
38
|
+
var ownKeys = function(o) {
|
|
39
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
40
|
+
var ar = [];
|
|
41
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
42
|
+
return ar;
|
|
43
|
+
};
|
|
44
|
+
return ownKeys(o);
|
|
45
|
+
};
|
|
46
|
+
return function (mod) {
|
|
47
|
+
if (mod && mod.__esModule) return mod;
|
|
48
|
+
var result = {};
|
|
49
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
50
|
+
__setModuleDefault(result, mod);
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
})();
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.MAX_SOURCE_BYTES = void 0;
|
|
56
|
+
exports.imageDirectory = imageDirectory;
|
|
57
|
+
exports.scopeOf = scopeOf;
|
|
58
|
+
exports.imageKind = imageKind;
|
|
59
|
+
exports.saveImageFile = saveImageFile;
|
|
60
|
+
exports.readSavedImage = readSavedImage;
|
|
61
|
+
exports.imageStore = imageStore;
|
|
62
|
+
exports.storeImage = storeImage;
|
|
63
|
+
const node_crypto_1 = require("node:crypto");
|
|
64
|
+
const node_fs_1 = require("node:fs");
|
|
65
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
66
|
+
const os = __importStar(require("node:os"));
|
|
67
|
+
const path = __importStar(require("node:path"));
|
|
68
|
+
const node_url_1 = require("node:url");
|
|
69
|
+
/** The most bytes of a saved image the tools read back as a source: 50 MiB. */
|
|
70
|
+
exports.MAX_SOURCE_BYTES = 50 * 1024 * 1024;
|
|
71
|
+
/** The name of a file the saver wrote. */
|
|
72
|
+
const SAVED_NAME = /^agentos-image-[0-9a-f]{32}\.(png|jpg|webp)$/;
|
|
73
|
+
/** The eight bytes every PNG starts with. */
|
|
74
|
+
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
75
|
+
/**
|
|
76
|
+
* The images directory: the pack option `imageDir`, else the environment
|
|
77
|
+
* variable `AGENTOS_IMAGE_DIR`, else a folder in the user's temp directory,
|
|
78
|
+
* which the operating system clears (the packs delete nothing). On POSIX the
|
|
79
|
+
* default carries the user id, since `/tmp` is shared. On Windows it is the
|
|
80
|
+
* user's own temp folder whatever `TEMP` says: `os.tmpdir()` reads `TEMP`,
|
|
81
|
+
* which can name a folder every user shares.
|
|
82
|
+
*/
|
|
83
|
+
function imageDirectory(option) {
|
|
84
|
+
const named = [option, process.env.AGENTOS_IMAGE_DIR]
|
|
85
|
+
.map((value) => (typeof value === 'string' ? value.trim() : ''))
|
|
86
|
+
.find(Boolean);
|
|
87
|
+
if (named)
|
|
88
|
+
return path.resolve(named);
|
|
89
|
+
if (typeof process.getuid === 'function')
|
|
90
|
+
return path.join(os.tmpdir(), `agentos-images-${process.getuid()}`);
|
|
91
|
+
return path.join(os.homedir(), 'AppData', 'Local', 'Temp', 'agentos-images');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The name of a caller's subdirectory: `u-` and 32 hex characters of the
|
|
95
|
+
* SHA-256 of its user id, or `shared` for a call that carries none. A host
|
|
96
|
+
* with several users gives each call its user (`context.userContext.userId`),
|
|
97
|
+
* so one user's saved image is no source for another.
|
|
98
|
+
*/
|
|
99
|
+
function scopeOf(context) {
|
|
100
|
+
const userId = context?.userContext?.userId;
|
|
101
|
+
return typeof userId === 'string' && userId !== ''
|
|
102
|
+
? `u-${(0, node_crypto_1.createHash)('sha256').update(userId).digest('hex').slice(0, 32)}`
|
|
103
|
+
: 'shared';
|
|
104
|
+
}
|
|
105
|
+
/** The kind of image `bytes` are, by their signature: PNG, JPEG or WebP. */
|
|
106
|
+
function imageKind(bytes) {
|
|
107
|
+
if (bytes.length >= 8 && bytes.subarray(0, 8).equals(PNG_SIGNATURE))
|
|
108
|
+
return { ext: 'png', mimeType: 'image/png' };
|
|
109
|
+
if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) {
|
|
110
|
+
return { ext: 'jpg', mimeType: 'image/jpeg' };
|
|
111
|
+
}
|
|
112
|
+
if (bytes.length >= 12 && bytes.toString('latin1', 0, 4) === 'RIFF' && bytes.toString('latin1', 8, 12) === 'WEBP') {
|
|
113
|
+
return { ext: 'webp', mimeType: 'image/webp' };
|
|
114
|
+
}
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether a directory's `stat` (taken with `bigint: true`) shows it private
|
|
119
|
+
* to this user: a directory this user owns that neither its group nor others
|
|
120
|
+
* can write. Where the platform has no user ids (Windows) only the kind is
|
|
121
|
+
* checked: the default there is inside the user's own profile.
|
|
122
|
+
*/
|
|
123
|
+
function isPrivateDirectory(stat) {
|
|
124
|
+
if (!stat.isDirectory())
|
|
125
|
+
return false;
|
|
126
|
+
if (typeof process.getuid !== 'function')
|
|
127
|
+
return true;
|
|
128
|
+
return stat.uid === BigInt(process.getuid()) && (stat.mode & BigInt(0o022)) === BigInt(0);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Whether no other user can rename or replace `dir`, a real path, through a
|
|
132
|
+
* directory above it: each one is owned by this user or by root, and none
|
|
133
|
+
* can be written by its group or by others unless it is sticky (as `/tmp`
|
|
134
|
+
* is), where only an entry's owner can rename it. Where the platform has no
|
|
135
|
+
* user ids (Windows) nothing is checked.
|
|
136
|
+
*/
|
|
137
|
+
async function hasTrustedParents(dir) {
|
|
138
|
+
if (typeof process.getuid !== 'function')
|
|
139
|
+
return true;
|
|
140
|
+
const uid = BigInt(process.getuid());
|
|
141
|
+
for (let parent = path.dirname(dir);; parent = path.dirname(parent)) {
|
|
142
|
+
const stat = await fs.lstat(parent, { bigint: true });
|
|
143
|
+
const sticky = (stat.mode & BigInt(0o1000)) !== BigInt(0);
|
|
144
|
+
const writableByOthers = (stat.mode & BigInt(0o022)) !== BigInt(0);
|
|
145
|
+
if (!stat.isDirectory() || (stat.uid !== uid && stat.uid !== BigInt(0)) || (writableByOthers && !sticky))
|
|
146
|
+
return false;
|
|
147
|
+
if (path.dirname(parent) === parent)
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** The error for a directory that is not private to this user. */
|
|
152
|
+
function notPrivate(dir) {
|
|
153
|
+
return new Error(`${dir} is not a directory that this user owns and no one else can write`);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Saves image bytes as a new file in the caller's subdirectory of `dir` and
|
|
157
|
+
* returns its `file:` URL. The extension comes from the bytes' signature, and
|
|
158
|
+
* the name is random, so a file is never overwritten.
|
|
159
|
+
*
|
|
160
|
+
* @throws When the bytes are not a PNG, JPEG or WebP image, or when the
|
|
161
|
+
* directory cannot be made, is not private to this user, or cannot be
|
|
162
|
+
* written. The message names the directory and the option that sets it.
|
|
163
|
+
*/
|
|
164
|
+
async function saveImageFile(bytes, dir, scope) {
|
|
165
|
+
const kind = imageKind(bytes);
|
|
166
|
+
if (!kind)
|
|
167
|
+
throw new Error('The provider returned data that is not a PNG, JPEG or WebP image.');
|
|
168
|
+
try {
|
|
169
|
+
// The directory is written by its real path, which no other user can
|
|
170
|
+
// change once the directories above it are checked.
|
|
171
|
+
await fs.mkdir(dir, { recursive: true, mode: 0o700 });
|
|
172
|
+
const root = await fs.realpath(dir);
|
|
173
|
+
if (!isPrivateDirectory(await fs.stat(root, { bigint: true })))
|
|
174
|
+
throw notPrivate(root);
|
|
175
|
+
if (!(await hasTrustedParents(root)))
|
|
176
|
+
throw new Error(`another user can change a directory above ${root}`);
|
|
177
|
+
const scopeDir = path.join(root, scope);
|
|
178
|
+
await fs.mkdir(scopeDir, { recursive: true, mode: 0o700 });
|
|
179
|
+
// lstat: a caller's directory that is a link to another caller's is refused.
|
|
180
|
+
if (!isPrivateDirectory(await fs.lstat(scopeDir, { bigint: true })))
|
|
181
|
+
throw notPrivate(scopeDir);
|
|
182
|
+
const file = path.join(scopeDir, `agentos-image-${(0, node_crypto_1.randomBytes)(16).toString('hex')}.${kind.ext}`);
|
|
183
|
+
await fs.writeFile(file, bytes, { flag: 'wx', mode: 0o600 });
|
|
184
|
+
return (0, node_url_1.pathToFileURL)(file).href;
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
188
|
+
throw new Error(`The image could not be saved under ${dir}: ${reason}. Set the pack's imageDir option, or AGENTOS_IMAGE_DIR, to a directory that the service's user owns and no one else can write.`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The bytes of the saved image that `source` names, or `undefined` when
|
|
193
|
+
* `source` is not the `file:` URL of an image the saver wrote for this
|
|
194
|
+
* caller. Every reason gives `undefined`, so the caller's one refusal does
|
|
195
|
+
* not tell which files exist.
|
|
196
|
+
*
|
|
197
|
+
* The file must carry the saver's name pattern and sit directly in the
|
|
198
|
+
* caller's subdirectory of the images directory's real path: the same
|
|
199
|
+
* directory by device and inode, itself a directory and not a link, private
|
|
200
|
+
* to this user, as the images directory is, with no directory above it that
|
|
201
|
+
* another user can change. It must be a regular file with one link and at
|
|
202
|
+
* most {@link MAX_SOURCE_BYTES}, and start with a PNG, JPEG or WebP
|
|
203
|
+
* signature. It is opened once, without following a link, and read from
|
|
204
|
+
* that handle.
|
|
205
|
+
*/
|
|
206
|
+
async function readSavedImage(source, dir, scope) {
|
|
207
|
+
let handle;
|
|
208
|
+
try {
|
|
209
|
+
const url = new URL(source);
|
|
210
|
+
if (url.protocol !== 'file:' || url.hostname !== '')
|
|
211
|
+
return undefined;
|
|
212
|
+
const named = (0, node_url_1.fileURLToPath)(url);
|
|
213
|
+
if (!SAVED_NAME.test(path.basename(named)))
|
|
214
|
+
return undefined;
|
|
215
|
+
// fs.promises.realpath asks the operating system. (fs.realpathSync and
|
|
216
|
+
// fs.realpath resolve ".." in the text first, as path.resolve does.)
|
|
217
|
+
const real = await fs.realpath(named);
|
|
218
|
+
if (!SAVED_NAME.test(path.basename(real)))
|
|
219
|
+
return undefined;
|
|
220
|
+
// The images directory as it is now, by its real path, so a directory
|
|
221
|
+
// swapped in for it is read as what it is; and the caller's directory in
|
|
222
|
+
// it by lstat, so a link to another caller's directory is refused.
|
|
223
|
+
const root = await fs.realpath(dir);
|
|
224
|
+
const [rootDir, parent, scopeDir] = await Promise.all([
|
|
225
|
+
fs.stat(root, { bigint: true }),
|
|
226
|
+
fs.stat(path.dirname(real), { bigint: true }),
|
|
227
|
+
fs.lstat(path.join(root, scope), { bigint: true }),
|
|
228
|
+
]);
|
|
229
|
+
if (!isPrivateDirectory(rootDir) || !isPrivateDirectory(scopeDir))
|
|
230
|
+
return undefined;
|
|
231
|
+
if (parent.dev !== scopeDir.dev || parent.ino !== scopeDir.ino)
|
|
232
|
+
return undefined;
|
|
233
|
+
if (!(await hasTrustedParents(root)))
|
|
234
|
+
return undefined;
|
|
235
|
+
// A FIFO would hold an open until a writer came; only a regular file is opened.
|
|
236
|
+
if (!(await fs.lstat(real)).isFile())
|
|
237
|
+
return undefined;
|
|
238
|
+
handle = await fs.open(real, node_fs_1.constants.O_RDONLY | (node_fs_1.constants.O_NOFOLLOW ?? 0) | (node_fs_1.constants.O_NONBLOCK ?? 0));
|
|
239
|
+
const stat = await handle.stat();
|
|
240
|
+
if (!stat.isFile() || stat.nlink !== 1 || stat.size > exports.MAX_SOURCE_BYTES)
|
|
241
|
+
return undefined;
|
|
242
|
+
// One byte more than the size at open: a file that has grown is refused.
|
|
243
|
+
const buffer = Buffer.alloc(stat.size + 1);
|
|
244
|
+
let length = 0;
|
|
245
|
+
while (length < buffer.length) {
|
|
246
|
+
const { bytesRead } = await handle.read(buffer, length, buffer.length - length, null);
|
|
247
|
+
if (bytesRead === 0)
|
|
248
|
+
break;
|
|
249
|
+
length += bytesRead;
|
|
250
|
+
}
|
|
251
|
+
if (length > stat.size)
|
|
252
|
+
return undefined;
|
|
253
|
+
const bytes = buffer.subarray(0, length);
|
|
254
|
+
return imageKind(bytes) ? bytes : undefined;
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
await handle?.close().catch(() => { });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/** The store for a pack's options: its `imageDir` and its `saveImage`, when that is a function. */
|
|
264
|
+
function imageStore(options) {
|
|
265
|
+
return {
|
|
266
|
+
dir: imageDirectory(options?.imageDir),
|
|
267
|
+
saveImage: typeof options?.saveImage === 'function' ? options.saveImage : undefined,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/** The longest reference a host's saver may return. */
|
|
271
|
+
const MAX_REFERENCE_LENGTH = 2048;
|
|
272
|
+
/** The bytes of a base64 `data:` URL, the form AgentOS's providers give image data in; `undefined` for anything else. */
|
|
273
|
+
function dataUrlBytes(value) {
|
|
274
|
+
if (typeof value !== 'string' || !/^data:/i.test(value))
|
|
275
|
+
return undefined;
|
|
276
|
+
const comma = value.indexOf(',');
|
|
277
|
+
if (comma === -1 || !/; *base64 *$/i.test(value.slice(0, comma)))
|
|
278
|
+
return undefined;
|
|
279
|
+
return Buffer.from(value.slice(comma + 1), 'base64');
|
|
280
|
+
}
|
|
281
|
+
/** Whether a saver's result is an http(s) URL short enough to hand to the model. */
|
|
282
|
+
function isHttpReference(value) {
|
|
283
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > MAX_REFERENCE_LENGTH)
|
|
284
|
+
return false;
|
|
285
|
+
try {
|
|
286
|
+
const { protocol } = new URL(value);
|
|
287
|
+
return protocol === 'http:' || protocol === 'https:';
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* An image a provider returned, as the reference the caller gets: the
|
|
295
|
+
* provider's http(s) URL as it is, or, for image data, the URL under which
|
|
296
|
+
* it was saved. Image data is never returned itself: as a `data:` URL it
|
|
297
|
+
* would go into the model's next request, megabytes of base64. `undefined`
|
|
298
|
+
* when the provider returned neither a URL nor data.
|
|
299
|
+
*
|
|
300
|
+
* @throws When the data is not a PNG, JPEG or WebP image, when it cannot be
|
|
301
|
+
* saved, or when the host's saver throws or returns anything but an
|
|
302
|
+
* http(s) URL of at most 2,048 characters.
|
|
303
|
+
*/
|
|
304
|
+
async function storeImage(image, tool, store, context) {
|
|
305
|
+
if (!image)
|
|
306
|
+
return undefined;
|
|
307
|
+
if (typeof image.url === 'string' && /^https?:\/\//i.test(image.url))
|
|
308
|
+
return image.url;
|
|
309
|
+
const bytes = typeof image.base64 === 'string' && image.base64 !== ''
|
|
310
|
+
? Buffer.from(image.base64, 'base64')
|
|
311
|
+
: (dataUrlBytes(image.dataUrl) ?? dataUrlBytes(image.url));
|
|
312
|
+
if (!bytes || bytes.length === 0)
|
|
313
|
+
return undefined;
|
|
314
|
+
if (!store.saveImage)
|
|
315
|
+
return saveImageFile(bytes, store.dir, scopeOf(context));
|
|
316
|
+
const kind = imageKind(bytes);
|
|
317
|
+
if (!kind)
|
|
318
|
+
throw new Error('The provider returned data that is not a PNG, JPEG or WebP image.');
|
|
319
|
+
const reference = await store.saveImage({ bytes, mimeType: kind.mimeType, tool, context });
|
|
320
|
+
if (!isHttpReference(reference)) {
|
|
321
|
+
throw new Error("The host's saveImage must return an http(s) URL of at most 2,048 characters.");
|
|
322
|
+
}
|
|
323
|
+
return reference;
|
|
324
|
+
}
|
|
325
|
+
//# sourceMapp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SAAS,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Image Generation Extension Pack: the `generate_image` tool on
|
|
3
|
+
* AgentOS's `generateImage`, with OpenAI, OpenRouter, Stability AI and
|
|
4
|
+
* Replicate.
|
|
5
|
+
*
|
|
6
|
+
* Image data a provider returns is saved, never returned: to a file in the
|
|
7
|
+
* images directory (`imageDir`, `AGENTOS_IMAGE_DIR`, or a folder in the
|
|
8
|
+
* user's temp directory), or by the host's `saveImage`.
|
|
9
|
+
*/
|
|
1
10
|
import type { ExtensionPackContext, ExtensionPack } from '@framers/agentos';
|
|
11
|
+
import { type ImageQuality } from './ImageGenerationService.js';
|
|
12
|
+
import type { SaveImage } from './imageFiles.js';
|
|
2
13
|
export interface ImageGenerationOptions {
|
|
3
14
|
openaiApiKey?: string;
|
|
4
15
|
openrouterApiKey?: string;
|
|
@@ -7,11 +18,30 @@ export interface ImageGenerationOptions {
|
|
|
7
18
|
defaultProvider?: 'openai' | 'openrouter' | 'stability' | 'replicate';
|
|
8
19
|
defaultModel?: string;
|
|
9
20
|
defaultSize?: string;
|
|
10
|
-
defaultQuality?:
|
|
21
|
+
defaultQuality?: ImageQuality;
|
|
22
|
+
/**
|
|
23
|
+
* Where image data a provider returns is saved, each caller in a
|
|
24
|
+
* subdirectory of its own (else `AGENTOS_IMAGE_DIR`, else a folder in the
|
|
25
|
+
* user's temp directory). The directory must belong to the service's user,
|
|
26
|
+
* with no one else able to write it, and every directory above it to that
|
|
27
|
+
* user or root, writable by no one else unless it is sticky as `/tmp` is. The image-editing and
|
|
28
|
+
* vision-pipeline packs take the same option: give all three the same
|
|
29
|
+
* directory, so an image this pack saved is a source for them.
|
|
30
|
+
*/
|
|
31
|
+
imageDir?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Stores image data in place of the default saver and returns the http(s)
|
|
34
|
+
* URL under which the host's clients load it. A `file:` URL names a file
|
|
35
|
+
* on the machine that ran the tool, so a host whose clients are elsewhere
|
|
36
|
+
* sets this.
|
|
37
|
+
*/
|
|
38
|
+
saveImage?: SaveImage;
|
|
11
39
|
priority?: number;
|
|
12
40
|
}
|
|
13
41
|
export declare function createExtensionPack(context: ExtensionPackContext): ExtensionPack;
|
|
14
42
|
export { ImageGenerationService } from './ImageGenerationService.js';
|
|
43
|
+
export type { ImageGenerationConfig, GenerateImageOptions, GeneratedImage, ImageQuality } from './ImageGenerationService.js';
|
|
44
|
+
export type { ImageStore, SaveImage } from './imageFiles.js';
|
|
15
45
|
export { GenerateImageTool } from './tools/generateImage.js';
|
|
16
46
|
export default createExtensionPack;
|
|
17
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAEd,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACV,oBAAoB,EACpB,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACxF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAOjD,MAAM,WAAW,sBAAsB;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,QAAQ,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,CAAC;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAwEhF;AAED,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC7H,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,eAAe,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,9 @@ exports.GenerateImageTool = exports.ImageGenerationService = void 0;
|
|
|
4
4
|
exports.createExtensionPack = createExtensionPack;
|
|
5
5
|
const ImageGenerationService_js_1 = require("./ImageGenerationService.js");
|
|
6
6
|
const generateImage_js_1 = require("./tools/generateImage.js");
|
|
7
|
+
// This pack compiles to CommonJS, where `require` reads the package's own
|
|
8
|
+
// version: `import.meta` does not exist there.
|
|
9
|
+
const { version } = require('../package.json');
|
|
7
10
|
function createExtensionPack(context) {
|
|
8
11
|
const options = (context.options ?? {});
|
|
9
12
|
const openaiApiKey = options.openaiApiKey ||
|
|
@@ -27,11 +30,13 @@ function createExtensionPack(context) {
|
|
|
27
30
|
defaultModel: options.defaultModel,
|
|
28
31
|
defaultSize: options.defaultSize,
|
|
29
32
|
defaultQuality: options.defaultQuality,
|
|
33
|
+
imageDir: options.imageDir,
|
|
34
|
+
saveImage: options.saveImage,
|
|
30
35
|
});
|
|
31
36
|
const tool = new generateImage_js_1.GenerateImageTool(service);
|
|
32
37
|
return {
|
|
33
38
|
name: '@framers/agentos-ext-image-generation',
|
|
34
|
-
version
|
|
39
|
+
version,
|
|
35
40
|
descriptors: [
|
|
36
41
|
{
|
|
37
42
|
id: tool.name,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAqDA,kDAwEC;AA7GD,2EAAwF;AAExF,+DAA6D;AAE7D,0EAA0E;AAC1E,+CAA+C;AAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AA+B/C,SAAgB,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAA2B,CAAC;IAElE,MAAM,YAAY,GAChB,OAAO,CAAC,YAAY;QACpB,OAAO,CAAC,SAAS,EAAE,CAAC,eAAe,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAE7B,MAAM,gBAAgB,GACpB,OAAO,CAAC,gBAAgB;QACxB,OAAO,CAAC,SAAS,EAAE,CAAC,mBAAmB,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAEjC,MAAM,eAAe,GACnB,OAAO,CAAC,eAAe;QACvB,OAAO,CAAC,SAAS,EAAE,CAAC,kBAAkB,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAEhC,MAAM,iBAAiB,GACrB,OAAO,CAAC,iBAAiB;QACzB,OAAO,CAAC,SAAS,EAAE,CAAC,oBAAoB,CAAC;QACzC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;IAElC,MAAM,OAAO,GAA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cAAc,CAAC,CAAC;YACzD,IAAI,OAAO,CAAC,YAAY;gBAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACtD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC;gBACjC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;gBACvB,CAAC,CAAC,4GAA4G,CAAC;YACjH,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,0CAA0C,MAAM,EAAE,CAAC,CAAC;QACvE,CAAC;QACD,YAAY,EAAE,KAAK,EAAE,EAA8B,EAAE,EAAE;YACrD,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC;YACzB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,wCAAwC,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC;AAED,yEAAqE;AAA5D,mIAAA,sBAAsB,OAAA;AAG/B,6DAA6D;AAApD,qHAAA,iBAAiB,OAAA;AAC1B,kBAAe,mBAAmB,CAAC"}
|
|
@@ -6,16 +6,18 @@ import type { ITool, JSONSchemaObject, ToolExecutionContext, ToolExecutionResult
|
|
|
6
6
|
import type { ImageGenerationService } from '../ImageGenerationService.js';
|
|
7
7
|
export interface GenerateImageInput {
|
|
8
8
|
prompt: string;
|
|
9
|
-
size?: '1024x1024' | '1792x1024' | '1024x1792';
|
|
9
|
+
size?: '1024x1024' | '1536x1024' | '1024x1536' | '1792x1024' | '1024x1792';
|
|
10
10
|
aspectRatio?: string;
|
|
11
|
-
quality?: 'standard' | 'hd';
|
|
11
|
+
quality?: 'low' | 'medium' | 'high' | 'auto' | 'standard' | 'hd';
|
|
12
12
|
style?: 'vivid' | 'natural';
|
|
13
13
|
provider?: 'openai' | 'openrouter' | 'stability' | 'replicate';
|
|
14
|
+
/** The provider's own model id, without a provider prefix. */
|
|
14
15
|
model?: string;
|
|
15
16
|
seed?: number;
|
|
16
17
|
negativePrompt?: string;
|
|
17
18
|
}
|
|
18
19
|
export interface GenerateImageOutput {
|
|
20
|
+
/** The image as a URL: the provider's, or the file: URL of the copy that was saved of the image data it returned. */
|
|
19
21
|
url: string;
|
|
20
22
|
revisedPrompt?: string;
|
|
21
23
|
provider: string;
|
|
@@ -26,12 +28,20 @@ export declare class GenerateImageTool implements ITool<GenerateImageInput, Gene
|
|
|
26
28
|
readonly id = "tool.generate_image";
|
|
27
29
|
readonly name = "generate_image";
|
|
28
30
|
readonly displayName = "Generate Image";
|
|
29
|
-
readonly description
|
|
31
|
+
readonly description: string;
|
|
30
32
|
readonly category = "media";
|
|
31
33
|
readonly hasSideEffects = false;
|
|
32
34
|
readonly inputSchema: JSONSchemaObject;
|
|
33
35
|
private service;
|
|
34
36
|
constructor(service: ImageGenerationService);
|
|
35
|
-
execute(args: GenerateImageInput,
|
|
37
|
+
execute(args: GenerateImageInput, context?: ToolExecutionContext): Promise<ToolExecutionResult<GenerateImageOutput>>;
|
|
38
|
+
/**
|
|
39
|
+
* The service call for a tool call's arguments, or the error for an
|
|
40
|
+
* argument the schema does not allow. Only the schema's own fields are
|
|
41
|
+
* taken: the model writes the arguments, and anything else it adds (`n`,
|
|
42
|
+
* `providerOptions`, whose `extraBody` goes into the provider's request)
|
|
43
|
+
* is not passed on.
|
|
44
|
+
*/
|
|
45
|
+
private optionsFrom;
|
|
36
46
|
}
|
|
37
47
|
//# sourceMappingURL=generateImage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateImage.d.ts","sourceRoot":"","sources":["../../src/tools/generateImage.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC3G,OAAO,KAAK,EAAE,sBAAsB,EAAwB,MAAM,8BAA8B,CAAC;AAEjG,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,WAAW,GAAG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C,QAAQ,WAAW;IAC5B,QAAQ,CAAC,cAAc,SAAS;IAEhC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CA6CpC;IAEF,OAAO,CAAC,OAAO,CAAyB;gBAE5B,OAAO,EAAE,sBAAsB;IAIrC,OAAO,CACX,IAAI,EAAE,kBAAkB,EACxB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,CAAC;IAiCpD;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;CAsBpB"}
|
|
@@ -6,12 +6,19 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.GenerateImageTool = void 0;
|
|
9
|
+
const SIZES = ['1024x1024', '1536x1024', '1024x1536', '1792x1024', '1024x1792'];
|
|
10
|
+
const QUALITIES = ['low', 'medium', 'high', 'auto', 'standard', 'hd'];
|
|
11
|
+
const STYLES = ['vivid', 'natural'];
|
|
12
|
+
const PROVIDERS = ['openai', 'openrouter', 'stability', 'replicate'];
|
|
13
|
+
/** The arguments that are optional strings with no list of values. */
|
|
14
|
+
const STRING_FIELDS = ['aspectRatio', 'model', 'negativePrompt'];
|
|
9
15
|
class GenerateImageTool {
|
|
10
16
|
constructor(service) {
|
|
11
17
|
this.id = 'tool.generate_image';
|
|
12
18
|
this.name = 'generate_image';
|
|
13
19
|
this.displayName = 'Generate Image';
|
|
14
|
-
this.description = 'Generate an image from a text prompt using the configured image providers. Returns
|
|
20
|
+
this.description = 'Generate an image from a text prompt using the configured image providers. Returns the image as a URL: ' +
|
|
21
|
+
'the provider\'s, or the file: URL of a copy saved on this machine, which the image-editing and vision tools accept as a source.';
|
|
15
22
|
this.category = 'media';
|
|
16
23
|
this.hasSideEffects = false;
|
|
17
24
|
this.inputSchema = {
|
|
@@ -23,8 +30,8 @@ class GenerateImageTool {
|
|
|
23
30
|
},
|
|
24
31
|
size: {
|
|
25
32
|
type: 'string',
|
|
26
|
-
enum:
|
|
27
|
-
description: 'Image dimensions. 1024x1024 (square, default), 1792x1024 (landscape), 1024x1792 (portrait).',
|
|
33
|
+
enum: SIZES,
|
|
34
|
+
description: 'Image dimensions. 1024x1024 (square, default), 1536x1024 or 1792x1024 (landscape), 1024x1536 or 1024x1792 (portrait).',
|
|
28
35
|
},
|
|
29
36
|
aspectRatio: {
|
|
30
37
|
type: 'string',
|
|
@@ -32,22 +39,22 @@ class GenerateImageTool {
|
|
|
32
39
|
},
|
|
33
40
|
quality: {
|
|
34
41
|
type: 'string',
|
|
35
|
-
enum:
|
|
36
|
-
description: 'Image quality. "hd"
|
|
42
|
+
enum: QUALITIES,
|
|
43
|
+
description: 'Image quality: low, medium (default), high, or auto. "standard" and "hd" are read as medium and high. Higher quality costs more.',
|
|
37
44
|
},
|
|
38
45
|
style: {
|
|
39
46
|
type: 'string',
|
|
40
|
-
enum:
|
|
41
|
-
description: '
|
|
47
|
+
enum: STYLES,
|
|
48
|
+
description: 'Optional style: "vivid" for hyper-real and dramatic, "natural" for more realistic.',
|
|
42
49
|
},
|
|
43
50
|
provider: {
|
|
44
51
|
type: 'string',
|
|
45
|
-
enum:
|
|
52
|
+
enum: PROVIDERS,
|
|
46
53
|
description: 'Which AI provider to use. If omitted, the extension uses its configured default provider.',
|
|
47
54
|
},
|
|
48
55
|
model: {
|
|
49
56
|
type: 'string',
|
|
50
|
-
description:
|
|
57
|
+
description: "Optional: the provider's own model id, for example gpt-image-2.5-flare, stable-image-core, or black-forest-labs/flux-schnell.",
|
|
51
58
|
},
|
|
52
59
|
seed: {
|
|
53
60
|
type: 'number',
|
|
@@ -62,9 +69,12 @@ class GenerateImageTool {
|
|
|
62
69
|
};
|
|
63
70
|
this.service = service;
|
|
64
71
|
}
|
|
65
|
-
async execute(args,
|
|
72
|
+
async execute(args, context) {
|
|
73
|
+
const options = this.optionsFrom(args);
|
|
74
|
+
if (typeof options === 'string')
|
|
75
|
+
return { success: false, error: options };
|
|
66
76
|
try {
|
|
67
|
-
const result = await this.service.generateImage(
|
|
77
|
+
const result = await this.service.generateImage(options, context);
|
|
68
78
|
return {
|
|
69
79
|
success: true,
|
|
70
80
|
output: {
|
|
@@ -92,6 +102,42 @@ class GenerateImageTool {
|
|
|
92
102
|
};
|
|
93
103
|
}
|
|
94
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The service call for a tool call's arguments, or the error for an
|
|
107
|
+
* argument the schema does not allow. Only the schema's own fields are
|
|
108
|
+
* taken: the model writes the arguments, and anything else it adds (`n`,
|
|
109
|
+
* `providerOptions`, whose `extraBody` goes into the provider's request)
|
|
110
|
+
* is not passed on.
|
|
111
|
+
*/
|
|
112
|
+
optionsFrom(args) {
|
|
113
|
+
if (typeof args?.prompt !== 'string' || !args.prompt.trim())
|
|
114
|
+
return 'prompt is required.';
|
|
115
|
+
const options = { prompt: args.prompt };
|
|
116
|
+
for (const field of STRING_FIELDS) {
|
|
117
|
+
const value = args[field];
|
|
118
|
+
if (value === undefined || value === null)
|
|
119
|
+
continue;
|
|
120
|
+
if (typeof value !== 'string')
|
|
121
|
+
return `${field} must be a string.`;
|
|
122
|
+
if (value.trim())
|
|
123
|
+
options[field] = value.trim();
|
|
124
|
+
}
|
|
125
|
+
for (const [field, allowed] of [['size', SIZES], ['quality', QUALITIES], ['style', STYLES], ['provider', PROVIDERS]]) {
|
|
126
|
+
const value = args[field];
|
|
127
|
+
if (value === undefined || value === null)
|
|
128
|
+
continue;
|
|
129
|
+
if (!allowed.includes(value))
|
|
130
|
+
return `${field} must be one of ${allowed.join(', ')}.`;
|
|
131
|
+
options[field] = value;
|
|
132
|
+
}
|
|
133
|
+
if (args.seed !== undefined && args.seed !== null) {
|
|
134
|
+
const seed = typeof args.seed === 'string' && args.seed.trim() !== '' ? Number(args.seed) : args.seed;
|
|
135
|
+
if (typeof seed !== 'number' || !Number.isFinite(seed))
|
|
136
|
+
return 'seed must be a number.';
|
|
137
|
+
options.seed = seed;
|
|
138
|
+
}
|
|
139
|
+
return options;
|
|
140
|
+
}
|
|
95
141
|
}
|
|
96
142
|
exports.GenerateImageTool = GenerateImageTool;
|
|
97
143
|
//# sourceMappingURL=generateImage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateImage.js","sourceRoot":"","sources":["../../src/tools/generateImage.ts"],"names":[],"mappings":";AAAA,cAAc;AACd;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"generateImage.js","sourceRoot":"","sources":["../../src/tools/generateImage.ts"],"names":[],"mappings":";AAAA,cAAc;AACd;;;GAGG;;;AA2BH,MAAM,KAAK,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAChF,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;AACtE,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACpC,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AACrE,sEAAsE;AACtE,MAAM,aAAa,GAAG,CAAC,aAAa,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAEjE,MAAa,iBAAiB;IA2D5B,YAAY,OAA+B;QA1DlC,OAAE,GAAG,qBAAqB,CAAC;QAC3B,SAAI,GAAG,gBAAgB,CAAC;QACxB,gBAAW,GAAG,gBAAgB,CAAC;QAC/B,gBAAW,GAClB,yGAAyG;YACzG,iIAAiI,CAAC;QAC3H,aAAQ,GAAG,OAAO,CAAC;QACnB,mBAAc,GAAG,KAAK,CAAC;QAEvB,gBAAW,GAAqB;YACvC,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,wHAAwH;iBACtI;gBACD,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;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HANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"id": "com.framers.tools.image-generation",
|
|
3
3
|
"name": "@framers/agentos-ext-image-generation",
|
|
4
4
|
"displayName": "Image Generation",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "2.0.0",
|
|
6
6
|
"description": "Generate images from text prompts using OpenAI, OpenRouter, Stability AI, or Replicate.",
|
|
7
7
|
"category": "tool",
|
|
8
8
|
"author": "Framers AI",
|
|
9
|
-
"license": "
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
10
|
"entry": "./src/index.ts",
|
|
11
11
|
"tools": ["generate_image"],
|
|
12
12
|
"requiredSecrets": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@framers/agentos-ext-image-generation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Image generation extension for AgentOS — OpenAI, OpenRouter, Stability AI, and Replicate",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"name": "Framers AI",
|
|
22
22
|
"url": "https://frame.dev"
|
|
23
23
|
},
|
|
24
|
-
"license": "
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@framers/agentos": ">=0.10.40"
|
|
27
27
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@types/node": "^20.0.0",
|
|
30
30
|
"typescript": "^5.0.0",
|
|
31
31
|
"vitest": "^3.2.7",
|
|
32
|
-
"@framers/agentos": "^0.
|
|
32
|
+
"@framers/agentos": "^0.13.40"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=22"
|