@framers/agentos-ext-image-generation 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Image generation
2
+
3
+ This pack gives an agent a text-to-image tool through the AgentOS SDK, using OpenAI, OpenRouter, Stability AI or Replicate.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @framers/agentos-ext-image-generation
9
+ ```
10
+
11
+ Peer dependency: `@framers/agentos` with range `>=0.10.40`.
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { AgentOS } from '@framers/agentos';
17
+
18
+ const agentos = await AgentOS.create({
19
+ extensionManifest: {
20
+ packs: [
21
+ {
22
+ package: '@framers/agentos-ext-image-generation',
23
+ options: {
24
+ openaiApiKey: process.env.OPENAI_API_KEY,
25
+ openrouterApiKey: process.env.OPENROUTER_API_KEY,
26
+ stabilityApiKey: process.env.STABILITY_API_KEY,
27
+ replicateApiToken: process.env.REPLICATE_API_TOKEN,
28
+ imageDir: process.env.AGENTOS_IMAGE_DIR,
29
+ },
30
+ },
31
+ ],
32
+ },
33
+ });
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ | Option | Secret id | Environment variable | Required | Default |
39
+ | --- | --- | --- | --- | --- |
40
+ | `openaiApiKey` | `openai.apiKey` | `OPENAI_API_KEY` | Yes for selected OpenAI provider | None |
41
+ | `openrouterApiKey` | `openrouter.apiKey` | `OPENROUTER_API_KEY` | Yes for selected OpenRouter provider | None |
42
+ | `stabilityApiKey` | `stability.apiKey` | `STABILITY_API_KEY` | Yes for selected Stability provider | None |
43
+ | `replicateApiToken` | `replicate.apiToken` | `REPLICATE_API_TOKEN` | Yes for selected Replicate provider | None |
44
+ | `defaultProvider` | None | None | No | First configured provider: `openai`, `openrouter`, `stability`, `replicate`; otherwise `openai` |
45
+ | `defaultModel` | None | None | No | `gpt-image-2.5-flare` for OpenAI; `google/gemini-2.5-flash-image` for OpenRouter; `stable-image-core` for Stability; `black-forest-labs/flux-schnell` for Replicate |
46
+ | `defaultSize` | None | None | No | `1024x1024` |
47
+ | `defaultQuality` | None | None | No | `medium` for OpenAI GPT Image models; otherwise unset |
48
+ | `imageDir` | None | `AGENTOS_IMAGE_DIR` | No | POSIX: `os.tmpdir()/agentos-images-${process.getuid()}`; Windows: `os.homedir()/AppData/Local/Temp/agentos-images` |
49
+ | `saveImage` | None | None | No | Save image data locally and return a `file:` URL |
50
+ | `priority` | None | None | No | `50` |
51
+
52
+ Keys resolve from the option, then `getSecret`, then the environment variable. The manifest marks each provider secret optional, but generation requires the selected provider's key. A tool call's `provider` overrides `defaultProvider`; its model, size and quality override their pack defaults.
53
+
54
+ ## Tools
55
+
56
+ | Tool | What it does |
57
+ | --- | --- |
58
+ | `generate_image` | Generates an image from a text prompt using the configured providers and returns its URL. |
59
+
60
+ ### `generate_image`
61
+
62
+ | Parameter | Type | Required | Description |
63
+ | --- | --- | --- | --- |
64
+ | `prompt` | `string` | Yes | Detailed text description of the image to generate. Be specific about style, subject, composition, lighting, and mood. |
65
+ | `size` | `string` | No | Image dimensions: `1024x1024` (square, default), `1536x1024` or `1792x1024` (landscape), `1024x1536` or `1024x1792` (portrait). |
66
+ | `aspectRatio` | `string` | No | Optional aspect ratio hint for providers that support it. |
67
+ | `quality` | `string` | No | Image quality: `low`, `medium` (default), `high`, or `auto`. `standard` and `hd` are read as `medium` and `high`. Higher quality costs more. |
68
+ | `style` | `string` | No | Optional style: `vivid` for hyper-real and dramatic, `natural` for more realistic. |
69
+ | `provider` | `string` | No | Which AI provider to use: `openai`, `openrouter`, `stability` or `replicate`. If omitted, the extension uses its configured default provider. |
70
+ | `model` | `string` | No | Optional: the provider's own model id. |
71
+ | `seed` | `number` | No | Optional seed for providers that support reproducible image generation. |
72
+ | `negativePrompt` | `string` | No | Optional negative prompt for providers that support excluding specific traits or artifacts. |
73
+
74
+ ## Notes
75
+
76
+ The package requires Node.js `>=22`. Generation calls can incur image charges. Missing credentials produce a failed tool result naming the selected provider's environment variable and key page. Empty prompts, invalid schema values, provider errors and storage failures also return failed results.
77
+
78
+ For OpenAI GPT Image models, the service maps `standard` quality to `medium` and `hd` to `high`. It adds the selected style as text in the prompt instead of sending a style parameter. Other model routes receive quality without this conversion.
79
+
80
+ The result uses the first image returned by the provider. Provider HTTP(S) URLs pass through unchanged. Image data is saved as PNG, JPEG or WebP and returned as a URL rather than base64. The tool ignores fields outside its schema, including `n` and `providerOptions`.
81
+
82
+ The default saver checks storage before calling a provider. On POSIX, the images directory belongs to the service user and forbids writes by other users. Its parents belong to that user or root and forbid other users' writes unless sticky. Saved images are scoped by `context.userContext.userId`, or stored under `shared` when absent. The pack does not delete saved images.
83
+
84
+ A custom `saveImage` receives `bytes`, `mimeType`, `tool` and `context`, and must return an HTTP(S) URL that passes the saver's length check. A `file:` URL refers to the machine running the tool; hosts with remote clients supply `saveImage`.
85
+
86
+ ## License
87
+
88
+ Apache-2.0
@@ -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?: 'standard' | 'hd';
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?: '1024x1024' | '1792x1024' | '1024x1792' | '512x512' | '256x256';
36
+ size?: string;
20
37
  aspectRatio?: string;
21
- quality?: 'standard' | 'hd';
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
- generateImage(options: GenerateImageOptions): Promise<GeneratedImage>;
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;;;GAGG;AAEH,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1F,MAAM,WAAW,qBAAqB;IACpC,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,uBAAuB,CAAC;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,c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;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,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;IAuDxF,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
- async generateImage(options) {
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,34 @@ 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);
79
+ // Before the provider bills for an image: a directory the saver refuses.
80
+ // Replicate too: AgentOS asks it in sync mode, where it can answer with a
81
+ // data: URL, which is saved like any other image data.
82
+ await (0, imageFiles_js_1.checkImageStore)(this.store, context);
48
83
  const model = options.model || this.config.defaultModel || this.defaultModelForProvider(provider);
84
+ // A GPT Image model takes neither DALL·E 3's quality names nor its
85
+ // `style` parameter: the names are rewritten, and a style goes into the
86
+ // prompt.
87
+ const gptImage = provider === 'openai' && isGptImageModel(model);
88
+ const quality = options.quality || this.config.defaultQuality;
89
+ const style = gptImage && options.style ? STYLE_SENTENCE[options.style] : undefined;
49
90
  const result = await (0, agentos_1.generateImage)({
50
91
  model: `${provider}:${model}`,
51
- prompt: options.prompt,
92
+ prompt: style ? `${options.prompt}\n\n${style}` : options.prompt,
52
93
  apiKey,
53
94
  size: options.size || this.config.defaultSize || '1024x1024',
54
95
  aspectRatio: options.aspectRatio,
55
- quality: options.quality || this.config.defaultQuality || 'standard',
96
+ quality: gptImage ? gptImageQuality(quality) : quality,
56
97
  n: options.n,
57
98
  seed: options.seed,
58
99
  negativePrompt: options.negativePrompt,
59
- providerOptions,
100
+ providerOptions: this.normalizeProviderOptions(provider, options, gptImage),
60
101
  });
61
- const first = result.images[0];
102
+ const first = result.images?.[0];
62
103
  if (!first) {
63
104
  throw new Error('Image generation returned no images.');
64
105
  }
65
- const url = first.url || first.dataUrl || (first.base64
66
- ? `data:${first.mimeType || 'image/png'};base64,${first.base64}`
67
- : undefined);
106
+ const url = await (0, imageFiles_js_1.storeImage)(first, 'generate_image', this.store, context);
68
107
  if (!url) {
69
108
  throw new Error('Image generation returned no image URL or image data.');
70
109
  }
@@ -113,7 +152,7 @@ class ImageGenerationService {
113
152
  defaultModelForProvider(provider) {
114
153
  switch (provider) {
115
154
  case 'openai':
116
- return 'dall-e-3';
155
+ return OPENAI_IMAGE_MODEL;
117
156
  case 'openrouter':
118
157
  return 'google/gemini-2.5-flash-image';
119
158
  case 'stability':
@@ -121,7 +160,7 @@ class ImageGenerationService {
121
160
  case 'replicate':
122
161
  return 'black-forest-labs/flux-schnell';
123
162
  default:
124
- return 'gpt-image-1';
163
+ return OPENAI_IMAGE_MODEL;
125
164
  }
126
165
  }
127
166
  displayNameForProvider(provider) {
@@ -138,34 +177,33 @@ class ImageGenerationService {
138
177
  return provider;
139
178
  }
140
179
  }
141
- normalizeProviderOptions(provider, options) {
142
- if (!options.providerOptions && !options.style && provider !== 'openai') {
143
- return undefined;
144
- }
145
- const providerOptions = options.providerOptions && typeof options.providerOptions === 'object' && !Array.isArray(options.providerOptions)
180
+ /**
181
+ * The provider options of a call. A `style` goes to an OpenAI model that
182
+ * is not a GPT Image model (one behind a gateway) as its `style` parameter;
183
+ * a GPT Image model is sent none, from the call or from the options.
184
+ */
185
+ normalizeProviderOptions(provider, options, gptImage) {
186
+ const given = options.providerOptions && typeof options.providerOptions === 'object' && !Array.isArray(options.providerOptions)
146
187
  ? { ...options.providerOptions }
147
188
  : undefined;
148
- if (provider === 'openai' && options.style) {
149
- const openAIOptions = {
150
- ...(providerOptions?.openai ?? {}),
151
- style: options.style,
152
- };
153
- return {
154
- ...(providerOptions ?? {}),
155
- openai: openAIOptions,
156
- };
189
+ if (provider !== 'openai')
190
+ return given;
191
+ if (gptImage) {
192
+ if (!given?.openai || typeof given.openai !== 'object')
193
+ return given;
194
+ const { style: _style, ...openai } = given.openai;
195
+ return { ...given, openai };
157
196
  }
158
- if (provider === 'openai') {
159
- return {
160
- ...(providerOptions ?? {}),
161
- openai: {
162
- ...(providerOptions?.openai ?? {}),
163
- style: options.style ?? providerOptions?.openai?.style ?? 'vivid',
164
- },
165
- };
166
- }
167
- return providerOptions;
197
+ if (!options.style)
198
+ return given;
199
+ return { ...(given ?? {}), openai: { ...(given?.openai ?? {}), style: options.style } };
168
200
  }
169
201
  }
170
202
  exports.ImageGenerationService = ImageGenerationService;
203
+ /** The quality a GPT Image model is sent: `medium` when none is given, and for DALL·E 3's `standard`; `high` for its `hd`. */
204
+ function gptImageQuality(quality) {
205
+ if (!quality || quality === 'standard')
206
+ return 'medium';
207
+ return quality === 'hd' ? 'high' : quality;
208
+ }
171
209
  //# sourceMappingURL=ImageGenerationService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ImageGenerationService.js","sourceRoot":"","sources":["../src/ImageGenerationService.ts"],"names":[],"mapp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AAK,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;AAvLD,wDAuLC;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,130 @@
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, and each caller has a
14
+ * subdirectory of its own, which is read by the directory's real path and
15
+ * never through a link. That is the trust boundary: only this user can put a
16
+ * file there, so a file there with the saver's name pattern is one the
17
+ * service wrote, for that caller. It holds only while no other user can
18
+ * change a directory above the images directory: one who could rename an
19
+ * entry there could swap the tree between a check and the write or open
20
+ * that follows it, and Node has no openat to pin a checked directory. So
21
+ * each directory above it must belong to this user or root and be writable
22
+ * by no one else, unless it is sticky, as /tmp is. A Kubernetes emptyDir on
23
+ * disk is 0777 with no sticky bit and is refused as a parent; SKILL.md says
24
+ * which volumes pass.
25
+ */
26
+ /** The most bytes of a saved image the tools read back as a source: 50 MiB. */
27
+ export declare const MAX_SOURCE_BYTES: number;
28
+ /**
29
+ * The images directory: the pack option `imageDir`, else the environment
30
+ * variable `AGENTOS_IMAGE_DIR`, else a folder in the user's temp directory,
31
+ * which the operating system clears (the packs delete nothing). On POSIX the
32
+ * default carries the user id, since `/tmp` is shared. On Windows it is the
33
+ * user's own temp folder whatever `TEMP` says: `os.tmpdir()` reads `TEMP`,
34
+ * which can name a folder every user shares.
35
+ */
36
+ export declare function imageDirectory(option?: unknown): string;
37
+ /**
38
+ * The name of a caller's subdirectory: `u-` and 32 hex characters of the
39
+ * SHA-256 of its user id, or `shared` for a call that carries none. A host
40
+ * with several users gives each call its user (`context.userContext.userId`),
41
+ * so one user's saved image is no source for another.
42
+ */
43
+ export declare function scopeOf(context?: {
44
+ userContext?: {
45
+ userId?: unknown;
46
+ };
47
+ }): string;
48
+ /** The kind of image `bytes` are, by their signature: PNG, JPEG or WebP. */
49
+ export declare function imageKind(bytes: Buffer): {
50
+ ext: 'png' | 'jpg' | 'webp';
51
+ mimeType: string;
52
+ } | undefined;
53
+ /**
54
+ * Saves image bytes as a new file in the caller's subdirectory of `dir` and
55
+ * returns its `file:` URL. The extension comes from the bytes' signature, and
56
+ * the name is random, so a file is never overwritten.
57
+ *
58
+ * @throws When the bytes are not a PNG, JPEG or WebP image, or when the
59
+ * directory cannot be made, is not private to this user, or cannot be
60
+ * written. The message names the directory and the option that sets it.
61
+ */
62
+ export declare function saveImageFile(bytes: Buffer, dir: string, scope: string): Promise<string>;
63
+ /**
64
+ * The bytes of the saved image that `source` names, or `undefined` when
65
+ * `source` is not the `file:` URL of an image the saver wrote for this
66
+ * caller. Every reason gives `undefined`, so the caller's one refusal does
67
+ * not tell which files exist.
68
+ *
69
+ * The file must carry the saver's name pattern and sit directly in the
70
+ * caller's subdirectory of the images directory's real path: the same
71
+ * directory by device and inode, itself a directory and not a link, private
72
+ * to this user, as the images directory is, with no directory above the
73
+ * images directory that another user can change. It must be a regular file with
74
+ * one link and at most {@link MAX_SOURCE_BYTES}, and start with a PNG, JPEG
75
+ * or WebP signature. It is opened once, without following a link, and read
76
+ * from that handle.
77
+ */
78
+ export declare function readSavedImage(source: string, dir: string, scope: string): Promise<Buffer | undefined>;
79
+ /** An image as AgentOS's image functions return it. */
80
+ export interface ReturnedImage {
81
+ url?: string;
82
+ dataUrl?: string;
83
+ base64?: string;
84
+ mimeType?: string;
85
+ }
86
+ /**
87
+ * A host's own saver: it stores the bytes where the host's clients can load
88
+ * them and returns that http(s) URL.
89
+ */
90
+ export type SaveImage = (image: {
91
+ bytes: Buffer;
92
+ mimeType: string;
93
+ tool: string;
94
+ context?: unknown;
95
+ }) => string | Promise<string>;
96
+ /** Where the tools keep image data: the directory of the default saver, and a host's own saver when it gave one. */
97
+ export interface ImageStore {
98
+ /** The images directory (see {@link imageDirectory}). */
99
+ dir: string;
100
+ /** The host's saver, which replaces the default. */
101
+ saveImage?: SaveImage;
102
+ }
103
+ /**
104
+ * Checks, before a provider is called, that the image data it may return can
105
+ * be saved for this caller: with no host `saveImage`, the images directory
106
+ * and the caller's directory in it are made and checked as a save makes and
107
+ * checks them. A provider bills for the image it makes, so a directory the
108
+ * saver would refuse is refused first.
109
+ *
110
+ * @throws The error a save would give, naming the directory and the option.
111
+ */
112
+ export declare function checkImageStore(store: ImageStore, context?: unknown): Promise<void>;
113
+ /** The store for a pack's options: its `imageDir` and its `saveImage`, when that is a function. */
114
+ export declare function imageStore(options?: {
115
+ imageDir?: unknown;
116
+ saveImage?: unknown;
117
+ }): ImageStore;
118
+ /**
119
+ * An image a provider returned, as the reference the caller gets: the
120
+ * provider's http(s) URL as it is, or, for image data, the URL under which
121
+ * it was saved. Image data is never returned itself: as a `data:` URL it
122
+ * would go into the model's next request, megabytes of base64. `undefined`
123
+ * when the provider returned neither a URL nor data.
124
+ *
125
+ * @throws When the data is not a PNG, JPEG or WebP image, when it cannot be
126
+ * saved, or when the host's saver throws or returns anything but an
127
+ * http(s) URL of at most 2,048 characters.
128
+ */
129
+ export declare function storeImage(image: ReturnedImage | undefined, tool: string, store: ImageStore, context?: unknown): Promise<string | undefined>;
130
+ //# sourceMappingURL=imageFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageFiles.d.ts","sourceRoot":"","sources":["../src/imageFiles.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;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;AAED,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAStG;AAyED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAW9F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,M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