@basementstudio/sanity-ai-image-plugin 0.0.1 → 0.1.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.
Files changed (118) hide show
  1. package/README.md +300 -257
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +3 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/presets/article-featured-image.d.ts +3 -0
  7. package/dist/presets/article-featured-image.d.ts.map +1 -0
  8. package/dist/presets/article-featured-image.js +17 -0
  9. package/dist/presets/article-featured-image.js.map +1 -0
  10. package/dist/server/constants.d.ts +6 -0
  11. package/dist/server/constants.d.ts.map +1 -0
  12. package/{src/server/constants.ts → dist/server/constants.js} +17 -20
  13. package/dist/server/constants.js.map +1 -0
  14. package/dist/server/handle-request.d.ts +5 -0
  15. package/dist/server/handle-request.d.ts.map +1 -0
  16. package/dist/server/handle-request.js +122 -0
  17. package/dist/server/handle-request.js.map +1 -0
  18. package/dist/server/types.d.ts +28 -0
  19. package/dist/server/types.d.ts.map +1 -0
  20. package/dist/server/types.js +2 -0
  21. package/dist/server/types.js.map +1 -0
  22. package/dist/server/utils.d.ts +50 -0
  23. package/dist/server/utils.d.ts.map +1 -0
  24. package/dist/server/utils.js +274 -0
  25. package/dist/server/utils.js.map +1 -0
  26. package/dist/server.d.ts +3 -0
  27. package/dist/server.d.ts.map +1 -0
  28. package/dist/server.js +3 -0
  29. package/dist/server.js.map +1 -0
  30. package/dist/studio/components/asset-source.d.ts +4 -0
  31. package/dist/studio/components/asset-source.d.ts.map +1 -0
  32. package/dist/studio/components/asset-source.js +169 -0
  33. package/dist/studio/components/asset-source.js.map +1 -0
  34. package/dist/studio/components/frontend-rate-limit.d.ts +29 -0
  35. package/dist/studio/components/frontend-rate-limit.d.ts.map +1 -0
  36. package/dist/studio/components/frontend-rate-limit.js +197 -0
  37. package/dist/studio/components/frontend-rate-limit.js.map +1 -0
  38. package/dist/studio/components/generate-button-input.d.ts +8 -0
  39. package/dist/studio/components/generate-button-input.d.ts.map +1 -0
  40. package/dist/studio/components/generate-button-input.js +194 -0
  41. package/dist/studio/components/generate-button-input.js.map +1 -0
  42. package/dist/studio/components/input-router.d.ts +7 -0
  43. package/dist/studio/components/input-router.d.ts.map +1 -0
  44. package/dist/studio/components/input-router.js +21 -0
  45. package/dist/studio/components/input-router.js.map +1 -0
  46. package/dist/studio/files.d.ts +9 -0
  47. package/dist/studio/files.d.ts.map +1 -0
  48. package/dist/studio/files.js +86 -0
  49. package/dist/studio/files.js.map +1 -0
  50. package/dist/studio/frontend-rate-limit.d.ts +29 -0
  51. package/dist/studio/frontend-rate-limit.d.ts.map +1 -0
  52. package/dist/studio/frontend-rate-limit.js +197 -0
  53. package/dist/studio/frontend-rate-limit.js.map +1 -0
  54. package/dist/studio/plugin.d.ts +3 -0
  55. package/dist/studio/plugin.d.ts.map +1 -0
  56. package/dist/studio/plugin.js +47 -0
  57. package/dist/studio/plugin.js.map +1 -0
  58. package/dist/studio/settings/schema.d.ts +8 -0
  59. package/dist/studio/settings/schema.d.ts.map +1 -0
  60. package/dist/studio/settings/schema.js +110 -0
  61. package/dist/studio/settings/schema.js.map +1 -0
  62. package/dist/studio/settings/tool.d.ts +3 -0
  63. package/dist/studio/settings/tool.d.ts.map +1 -0
  64. package/dist/studio/settings/tool.js +292 -0
  65. package/dist/studio/settings/tool.js.map +1 -0
  66. package/dist/studio/settings-data.d.ts +24 -0
  67. package/dist/studio/settings-data.d.ts.map +1 -0
  68. package/dist/studio/settings-data.js +99 -0
  69. package/dist/studio/settings-data.js.map +1 -0
  70. package/dist/studio/shared-secret.d.ts +9 -0
  71. package/dist/studio/shared-secret.d.ts.map +1 -0
  72. package/dist/studio/shared-secret.js +37 -0
  73. package/dist/studio/shared-secret.js.map +1 -0
  74. package/dist/utils/config.d.ts +3 -0
  75. package/dist/utils/config.d.ts.map +1 -0
  76. package/dist/utils/config.js +59 -0
  77. package/dist/utils/config.js.map +1 -0
  78. package/dist/utils/context-fields.d.ts +16 -0
  79. package/dist/utils/context-fields.d.ts.map +1 -0
  80. package/dist/utils/context-fields.js +104 -0
  81. package/dist/utils/context-fields.js.map +1 -0
  82. package/dist/utils/document-paths.d.ts +10 -0
  83. package/dist/utils/document-paths.d.ts.map +1 -0
  84. package/dist/utils/document-paths.js +33 -0
  85. package/dist/utils/document-paths.js.map +1 -0
  86. package/dist/utils/models.d.ts +22 -0
  87. package/dist/utils/models.d.ts.map +1 -0
  88. package/dist/utils/models.js +76 -0
  89. package/dist/utils/models.js.map +1 -0
  90. package/dist/utils/prompts.d.ts +2 -0
  91. package/dist/utils/prompts.d.ts.map +1 -0
  92. package/dist/utils/prompts.js +7 -0
  93. package/dist/utils/prompts.js.map +1 -0
  94. package/dist/utils/shared.d.ts +96 -0
  95. package/dist/utils/shared.d.ts.map +1 -0
  96. package/dist/utils/shared.js +17 -0
  97. package/dist/utils/shared.js.map +1 -0
  98. package/package.json +73 -67
  99. package/src/index.ts +0 -23
  100. package/src/presets/article-featured-image.ts +0 -23
  101. package/src/server/handle-request.ts +0 -207
  102. package/src/server/types.ts +0 -30
  103. package/src/server/utils.ts +0 -395
  104. package/src/server.ts +0 -14
  105. package/src/studio/components/asset-source.tsx +0 -297
  106. package/src/studio/components/generate-button-input.tsx +0 -380
  107. package/src/studio/components/input-router.tsx +0 -41
  108. package/src/studio/files.ts +0 -114
  109. package/src/studio/plugin.tsx +0 -54
  110. package/src/studio/settings/schema.ts +0 -122
  111. package/src/studio/settings/tool.tsx +0 -587
  112. package/src/studio/settings-data.ts +0 -172
  113. package/src/utils/config.ts +0 -55
  114. package/src/utils/context-fields.ts +0 -172
  115. package/src/utils/document-paths.ts +0 -51
  116. package/src/utils/models.ts +0 -126
  117. package/src/utils/prompts.ts +0 -6
  118. package/src/utils/shared.ts +0 -88
package/README.md CHANGED
@@ -1,257 +1,300 @@
1
- # `sanity-ai-image-plugin`
2
-
3
- Portable Sanity Studio plugin and server helper for generating images with
4
- Gemini, OpenAI, and other package-supported image models and dropping the
5
- result straight into Sanity image fields.
6
-
7
- This package is intentionally self-contained so it can be copied into a new repo
8
- or published later without dragging along an app-specific schema layout.
9
-
10
- This repo is source-first while it is being developed here:
11
-
12
- - package exports point at `src/*`
13
-
14
- ## What It Owns
15
-
16
- - a Studio plugin via `aiImagePlugin(...)`
17
- - a plugin-owned settings document and settings tool
18
- - a generic image asset source
19
- - optional generate-button targets for specific image fields
20
- - a server helper export for the app-owned API route
21
-
22
- ## Install Shape
23
-
24
- The package exposes two entrypoints:
25
-
26
- - `sanity-ai-image-plugin`
27
- - `sanity-ai-image-plugin/server`
28
-
29
- ## Consumer Setup
30
-
31
- ### 1. Add the Studio plugin
32
-
33
- ```ts
34
- import { defineConfig } from "sanity";
35
- import {
36
- SUPPORTED_AI_IMAGE_MODELS,
37
- createArticleFeaturedImageTarget,
38
- aiImagePlugin,
39
- } from "sanity-ai-image-plugin";
40
-
41
- const allowedModels = [
42
- SUPPORTED_AI_IMAGE_MODELS[0],
43
- SUPPORTED_AI_IMAGE_MODELS[2],
44
- ] as const;
45
-
46
- export default defineConfig({
47
- // ...your existing config
48
- plugins: [
49
- aiImagePlugin({
50
- apiVersion: "2025-02-19",
51
- allowedModels: [...allowedModels],
52
- assetSource: true,
53
- targets: [
54
- createArticleFeaturedImageTarget(),
55
- {
56
- id: "home-page-featured-image",
57
- type: "generateButton",
58
- title: "Home Page Featured Image",
59
- documentType: "homePage",
60
- fieldPath: "featuredImage",
61
- suggestedContextFieldPaths: ["title", "description"],
62
- },
63
- ],
64
- }),
65
- ],
66
- });
67
- ```
68
-
69
- ### 2. Add the thin app-owned route.
70
-
71
- ```ts
72
- import {
73
- handleAiImageRequest,
74
- SUPPORTED_AI_IMAGE_MODELS,
75
- } from "sanity-ai-image-plugin/server";
76
-
77
- const allowedModels = [
78
- SUPPORTED_AI_IMAGE_MODELS[0],
79
- SUPPORTED_AI_IMAGE_MODELS[2],
80
- ] as const;
81
-
82
- export async function POST(request: Request) {
83
- return handleAiImageRequest(request, {
84
- allowedModels: [...allowedModels],
85
- apiKey: process.env.GEMINI_API_KEY,
86
- openAiApiKey: process.env.OPENAI_API_KEY,
87
- // Same-origin protection is enabled by default.
88
- // Optional overrides:
89
- // model: process.env.AI_IMAGE_MODEL as (typeof allowedModels)[number],
90
- // maxReferenceFileBytes: 8 * 1024 * 1024,
91
- // maxTotalReferenceBytes: 5 * 8 * 1024 * 1024,
92
- })
93
- }
94
- ```
95
-
96
- ### 3. Set env vars
97
-
98
- - `GEMINI_API_KEY` is required when you allow Google models
99
- - `OPENAI_API_KEY` is required when you allow OpenAI models
100
- - `AI_IMAGE_MODEL` is optional and can still override the server default
101
-
102
- ## Supported Models
103
-
104
- The package has an internal supported-model registry. In this first pass it
105
- contains exactly:
106
-
107
- - `gemini-2.5-flash-image`
108
- - `gemini-3.1-flash-image-preview`
109
- - `gpt-image-1`
110
-
111
- Each installation can opt into any non-empty subset of those models with the
112
- ordered `allowedModels` config. The first allowed model becomes the default
113
- model for both the Studio UI and the server helper unless the settings document
114
- or route overrides it.
115
-
116
- ## Settings Model
117
-
118
- The plugin owns one settings document:
119
-
120
- - `_id`: `aiImagePlugin.settings`
121
- - `_type`: `aiImagePluginSettings`
122
-
123
- It stores:
124
-
125
- - `globalModel`
126
- - `globalPrompt`
127
- - `globalReferenceImages`
128
- - `targetConfigs[]`
129
-
130
- Each target config can override:
131
-
132
- - `targetId`
133
- - `prompt`
134
- - `referenceImages`
135
-
136
- ## Behavior
137
-
138
- ### Server helper
139
-
140
- The server helper is same-origin only by default.
141
-
142
- That means requests are accepted when the browser `Origin` matches the API
143
- route origin exactly, for example:
144
-
145
- - `http://localhost:3000/studio` -> `http://localhost:3000/api/ai-image-plugin`
146
- - `https://myapp.vercel.app/studio` -> `https://myapp.vercel.app/api/ai-image-plugin`
147
-
148
- The helper does not inspect the `/studio` path directly because browser
149
- `Origin` headers only include the scheme, host, and port.
150
-
151
- By default it also enforces:
152
-
153
- - `8 MiB` maximum per reference image
154
- - a combined reference-image cap of `maxReferences * 8 MiB`
155
- - the requested `model` must be both package-supported and present in the
156
- route's configured `allowedModels`
157
-
158
- If your framework supports route-level body limits, keep those enabled too.
159
-
160
- ### Asset source
161
-
162
- The generic asset source composes:
163
-
164
- 1. global prompt
165
- 2. asset-source target prompt
166
- 3. editor prompt
167
-
168
- Reference images are combined from:
169
-
170
- 1. global reference images
171
- 2. asset-source target reference images
172
- 3. local editor-uploaded reference images
173
-
174
- The selected model is resolved like this:
175
-
176
- 1. `settings.globalModel` when it is present and allowed
177
- 2. otherwise the first configured `allowedModels` entry
178
-
179
- ### Generate button targets
180
-
181
- Generate-button targets match against:
182
-
183
- - `documentType`
184
- - `fieldPath`
185
-
186
- When matched, the plugin renders a `Generate` button above the normal Sanity
187
- image input.
188
-
189
- Targets can also declare:
190
-
191
- - `suggestedContextFieldPaths`
192
-
193
- When the dialog opens, the plugin inspects the current document schema and shows
194
- eligible top-level document fields as toggle tags. In this first pass, eligible
195
- field types are:
196
-
197
- - `string`
198
- - `text`
199
- - `number`
200
- - `boolean`
201
- - `date`
202
- - `datetime`
203
- - `slug`
204
-
205
- Suggested context field paths are only default-on tags. They are filtered to
206
- fields that exist on the current document type, and editors can toggle them on
207
- or off for each generation.
208
-
209
- Prompt composition order is:
210
-
211
- 1. global prompt
212
- 2. target prompt
213
- 3. optional selected document context
214
- 4. optional editor prompt
215
-
216
- Selected document context is built as generic lines such as:
217
-
218
- - `The field called "title" has content "...".`
219
-
220
- ## Optional Preset
221
-
222
- `createArticleFeaturedImageTarget(...)` is an optional preset for
223
- `article.featuredImage`.
224
-
225
- It feeds the model:
226
-
227
- - shared global settings
228
- - target-specific article settings
229
- - editor-selectable document-derived title + excerpt context suggestions
230
- - optional editor prompt
231
-
232
- If you do not use that preset, the package still works as a generic asset source
233
- and generic generate-button plugin.
234
-
235
- ## Desk Structure
236
-
237
- The plugin does not require custom desk structure wiring. If a consuming app
238
- uses a custom structure and wants to hide `aiImagePluginSettings` from the normal
239
- document list, that is optional and app-owned.
240
-
241
- ## PNG Normalization
242
-
243
- All reference images are converted to PNG before they are sent to the server
244
- helper. That includes:
245
-
246
- - locally uploaded reference files
247
- - stored settings images downloaded from Sanity
248
- - new images uploaded through the settings tool
249
-
250
- ## Development
251
-
252
- ```sh
253
- bun run check
254
- bun run build
255
- bun test
256
- ```
257
-
1
+ # `sanity-ai-image-plugin`
2
+
3
+ Portable Sanity Studio plugin and server helper for generating images with
4
+ Gemini, OpenAI, and other package-supported image models and dropping the
5
+ result straight into Sanity image fields.
6
+
7
+ This package is intentionally self-contained so it can be copied into a new repo
8
+ or published later without dragging along an app-specific schema layout.
9
+
10
+ This repo is source-first while it is being developed here:
11
+
12
+ - package exports point at `src/*`
13
+
14
+ ## What It Owns
15
+
16
+ - a Studio plugin via `aiImagePlugin(...)`
17
+ - a plugin-owned settings document and settings tool
18
+ - a generic image asset source
19
+ - optional generate-button targets for specific image fields
20
+ - a server helper export for the app-owned API route
21
+
22
+ ## Install Shape
23
+
24
+ The package exposes two entrypoints:
25
+
26
+ - `sanity-ai-image-plugin`
27
+ - `sanity-ai-image-plugin/server`
28
+
29
+ ## Consumer Setup
30
+
31
+ ### 1. Add the Studio plugin
32
+
33
+ ```ts
34
+ import { defineConfig } from "sanity";
35
+ import {
36
+ SUPPORTED_AI_IMAGE_MODELS,
37
+ createArticleFeaturedImageTarget,
38
+ aiImagePlugin,
39
+ } from "sanity-ai-image-plugin";
40
+
41
+ const allowedModels = [
42
+ SUPPORTED_AI_IMAGE_MODELS[0],
43
+ SUPPORTED_AI_IMAGE_MODELS[2],
44
+ ] as const;
45
+
46
+ export default defineConfig({
47
+ // ...your existing config
48
+ plugins: [
49
+ aiImagePlugin({
50
+ apiVersion: "2025-02-19",
51
+ allowedModels: [...allowedModels],
52
+ assetSource: true,
53
+ frontendRateLimit: {
54
+ maxRequests: 3,
55
+ windowSecs: 60,
56
+ },
57
+ targets: [
58
+ createArticleFeaturedImageTarget(),
59
+ {
60
+ id: "home-page-featured-image",
61
+ type: "generateButton",
62
+ title: "Home Page Featured Image",
63
+ documentType: "homePage",
64
+ fieldPath: "featuredImage",
65
+ suggestedContextFieldPaths: ["title", "description"],
66
+ },
67
+ ],
68
+ }),
69
+ ],
70
+ });
71
+ ```
72
+
73
+ ### 2. Add the thin app-owned route.
74
+
75
+ ```ts
76
+ import {
77
+ handleAiImageRequest,
78
+ SUPPORTED_AI_IMAGE_MODELS,
79
+ } from "sanity-ai-image-plugin/server";
80
+
81
+ const allowedModels = [
82
+ SUPPORTED_AI_IMAGE_MODELS[0],
83
+ SUPPORTED_AI_IMAGE_MODELS[2],
84
+ ] as const;
85
+
86
+ export async function POST(request: Request) {
87
+ return handleAiImageRequest(request, {
88
+ allowedModels: [...allowedModels],
89
+ apiKey: process.env.GEMINI_API_KEY,
90
+ openAiApiKey: process.env.OPENAI_API_KEY,
91
+ sharedSecret: process.env.AI_IMAGE_PLUGIN_SHARED_SECRET!,
92
+ // Shared-secret auth and same-origin protection are enabled by default.
93
+ // Optional overrides:
94
+ // model: process.env.AI_IMAGE_MODEL as (typeof allowedModels)[number],
95
+ // maxReferenceFileBytes: 8 * 1024 * 1024,
96
+ // maxTotalReferenceBytes: 5 * 8 * 1024 * 1024,
97
+ })
98
+ }
99
+ ```
100
+
101
+ ### 3. Set env vars
102
+
103
+ - `GEMINI_API_KEY` is required when you allow Google models
104
+ - `OPENAI_API_KEY` is required when you allow OpenAI models
105
+ - `AI_IMAGE_PLUGIN_SHARED_SECRET` is required for the app-owned route
106
+ - `AI_IMAGE_MODEL` is optional and can still override the server default
107
+
108
+ ### 4. Configure the shared secret in Studio
109
+
110
+ Open the AI Image Plugin settings tool and configure the same shared secret
111
+ value there.
112
+
113
+ The plugin stores that Studio-side value with `@sanity/studio-secrets`, so it
114
+ is fetched at runtime for logged-in Studio users instead of being bundled into
115
+ the Studio source code.
116
+
117
+ ## Supported Models
118
+
119
+ The package has an internal supported-model registry. In this first pass it
120
+ contains exactly:
121
+
122
+ - `gemini-2.5-flash-image`
123
+ - `gemini-3.1-flash-image-preview`
124
+ - `gpt-image-1`
125
+
126
+ Each installation can opt into any non-empty subset of those models with the
127
+ ordered `allowedModels` config. The first allowed model becomes the fallback
128
+ default for both the Studio UI and the server helper unless the settings
129
+ document or route overrides it.
130
+
131
+ ## Settings Model
132
+
133
+ The plugin owns one settings document:
134
+
135
+ - `_id`: `aiImagePlugin.settings`
136
+ - `_type`: `aiImagePluginSettings`
137
+
138
+ It stores:
139
+
140
+ - `globalModel`
141
+ - `globalPrompt`
142
+ - `globalReferenceImages`
143
+ - `targetConfigs[]`
144
+
145
+ Each target config can override:
146
+
147
+ - `targetId`
148
+ - `prompt`
149
+ - `referenceImages`
150
+
151
+ ## Behavior
152
+
153
+ ### Server helper
154
+
155
+ The server helper requires a valid shared secret and same-origin browser
156
+ requests by default.
157
+
158
+ That means requests are accepted only when:
159
+
160
+ 1. the request includes the correct `x-ai-image-plugin-secret` header
161
+ 2. the browser `Origin` matches the API route origin exactly
162
+
163
+ Same-origin matches look like this:
164
+
165
+ - `http://localhost:3000/studio` -> `http://localhost:3000/api/ai-image-plugin`
166
+ - `https://myapp.vercel.app/studio` -> `https://myapp.vercel.app/api/ai-image-plugin`
167
+
168
+ The helper does not inspect the `/studio` path directly because browser
169
+ `Origin` headers only include the scheme, host, and port. The shared secret is
170
+ managed from the plugin settings tool and stored separately from the plugin's
171
+ normal prompt/reference-image settings document.
172
+
173
+ By default it also enforces:
174
+
175
+ - `8 MiB` maximum per reference image
176
+ - a combined reference-image cap of `maxReferences * 8 MiB`
177
+ - the requested `model` must be both package-supported and present in the
178
+ route's configured `allowedModels`
179
+
180
+ If your framework supports route-level body limits, keep those enabled too.
181
+
182
+ ### Frontend rate limit
183
+
184
+ The Studio UI applies a browser-side rolling-window limiter by default across
185
+ both generation entrypoints in the same browser profile.
186
+
187
+ Default behavior:
188
+
189
+ - `3` generation attempts per `60` seconds
190
+ - shared through `localStorage`, so refreshes and other tabs see the same block
191
+ - configurable with `frontendRateLimit` in `sanity.config`
192
+ - disabled entirely with `frontendRateLimit: false`
193
+
194
+ Only requests that are actually sent to the plugin API route consume quota.
195
+ Local validation failures inside Studio do not.
196
+
197
+ ### Asset source
198
+
199
+ The generic asset source composes:
200
+
201
+ 1. global prompt
202
+ 2. asset-source target prompt
203
+ 3. editor prompt
204
+
205
+ Reference images are combined from:
206
+
207
+ 1. global reference images
208
+ 2. asset-source target reference images
209
+ 3. local editor-uploaded reference images
210
+
211
+ The asset-source model picker starts on:
212
+
213
+ 1. `settings.globalModel` when it is present and allowed
214
+ 2. otherwise the first configured `allowedModels` entry
215
+
216
+ Editors can override that selection for the current request before generating.
217
+
218
+ ### Generate button targets
219
+
220
+ Generate-button targets match against:
221
+
222
+ - `documentType`
223
+ - `fieldPath`
224
+
225
+ When matched, the plugin renders a `Generate` button above the normal Sanity
226
+ image input.
227
+
228
+ Targets can also declare:
229
+
230
+ - `suggestedContextFieldPaths`
231
+
232
+ When the dialog opens, the plugin inspects the current document schema and shows
233
+ eligible top-level document fields as toggle tags. In this first pass, eligible
234
+ field types are:
235
+
236
+ - `string`
237
+ - `text`
238
+ - `number`
239
+ - `boolean`
240
+ - `date`
241
+ - `datetime`
242
+ - `slug`
243
+
244
+ Suggested context field paths are only default-on tags. They are filtered to
245
+ fields that exist on the current document type, and editors can toggle them on
246
+ or off for each generation.
247
+
248
+ The generate dialog also includes a model picker. It starts from the same
249
+ global default resolution as the asset source, but editors can switch to a
250
+ different allowed model for that one generation request.
251
+
252
+ Prompt composition order is:
253
+
254
+ 1. global prompt
255
+ 2. target prompt
256
+ 3. optional selected document context
257
+ 4. optional editor prompt
258
+
259
+ Selected document context is built as generic lines such as:
260
+
261
+ - `The field called "title" has content "...".`
262
+
263
+ ## Optional Preset
264
+
265
+ `createArticleFeaturedImageTarget(...)` is an optional preset for
266
+ `article.featuredImage`.
267
+
268
+ It feeds the model:
269
+
270
+ - shared global settings
271
+ - target-specific article settings
272
+ - editor-selectable document-derived title + excerpt context suggestions
273
+ - optional editor prompt
274
+
275
+ If you do not use that preset, the package still works as a generic asset source
276
+ and generic generate-button plugin.
277
+
278
+ ## Desk Structure
279
+
280
+ The plugin does not require custom desk structure wiring. If a consuming app
281
+ uses a custom structure and wants to hide `aiImagePluginSettings` from the normal
282
+ document list, that is optional and app-owned.
283
+
284
+ ## PNG Normalization
285
+
286
+ All reference images are converted to PNG before they are sent to the server
287
+ helper. That includes:
288
+
289
+ - locally uploaded reference files
290
+ - stored settings images downloaded from Sanity
291
+ - new images uploaded through the settings tool
292
+
293
+ ## Development
294
+
295
+ ```sh
296
+ bun run check
297
+ bun run build
298
+ bun test
299
+ ```
300
+
@@ -0,0 +1,3 @@
1
+ export { SUPPORTED_AI_IMAGE_MODELS } from "./utils/models";
2
+ export { aiImagePlugin } from "./studio/plugin";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { SUPPORTED_AI_IMAGE_MODELS } from "./utils/models";
2
+ export { aiImagePlugin } from "./studio/plugin";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { GenerateButtonTarget } from "../utils/shared";
2
+ export declare function createArticleFeaturedImageTarget(options?: Partial<Omit<GenerateButtonTarget, "type">>): GenerateButtonTarget;
3
+ //# sourceMappingURL=article-featured-image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"article-featured-image.d.ts","sourceRoot":"","sources":["../../src/presets/article-featured-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAE3D,wBAAgB,gCAAgC,CAC9C,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAM,GACxD,oBAAoB,CAkBtB"}
@@ -0,0 +1,17 @@
1
+ export function createArticleFeaturedImageTarget(options = {}) {
2
+ return {
3
+ id: options.id || "article-featured-image",
4
+ type: "generateButton",
5
+ title: options.title || "Article Featured Image",
6
+ description: options.description ||
7
+ "Adds a Generate button that combines shared art direction, article context, and an optional editor prompt.",
8
+ dialogTitle: options.dialogTitle || "Generate Featured Image",
9
+ documentType: options.documentType || "article",
10
+ fieldPath: options.fieldPath || "featuredImage",
11
+ promptLabel: options.promptLabel || "Custom prompt",
12
+ promptPlaceholder: options.promptPlaceholder ||
13
+ "Optional custom instructions for this article image.",
14
+ suggestedContextFieldPaths: options.suggestedContextFieldPaths || ["title", "excerpt"],
15
+ };
16
+ }
17
+ //# sourceMappingURL=article-featured-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"article-featured-image.js","sourceRoot":"","sources":["../../src/presets/article-featured-image.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gCAAgC,CAC9C,UAAuD,EAAE;IAEzD,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,wBAAwB;QAC1C,IAAI,EAAE,gBAAgB;QACtB,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,wBAAwB;QAChD,WAAW,EACT,OAAO,CAAC,WAAW;YACnB,4GAA4G;QAC9G,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,yBAAyB;QAC7D,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,SAAS;QAC/C,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,eAAe;QAC/C,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,eAAe;QACnD,iBAAiB,EACf,OAAO,CAAC,iBAAiB;YACzB,sDAAsD;QACxD,0BAA0B,EACxB,OAAO,CAAC,0BAA0B,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;KAC7D,CAAA;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const DEFAULT_MODEL: "gemini-2.5-flash-image" | "gemini-3.1-flash-image-preview" | "gpt-image-1";
2
+ export declare const DEFAULT_PROVIDER_API_URL = "https://generativelanguage.googleapis.com/v1beta";
3
+ export declare const DEFAULT_MAX_REFERENCE_FILE_BYTES: number;
4
+ export declare const SUPPORTED_REFERENCE_IMAGE_TYPES: Set<string>;
5
+ export declare const OPENAI_SUPPORTED_REFERENCE_IMAGE_TYPES: Set<string>;
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/server/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,6EAAmC,CAAC;AAC9D,eAAO,MAAM,wBAAwB,qDACe,CAAC;AACrD,eAAO,MAAM,gCAAgC,QAAkB,CAAC;AAEhE,eAAO,MAAM,+BAA+B,aAM1C,CAAC;AAEH,eAAO,MAAM,sCAAsC,aAIjD,CAAC"}
@@ -1,20 +1,17 @@
1
- import { DEFAULT_SUPPORTED_AI_IMAGE_MODEL } from "../utils/models";
2
-
3
- export const DEFAULT_MODEL = DEFAULT_SUPPORTED_AI_IMAGE_MODEL;
4
- export const DEFAULT_PROVIDER_API_URL =
5
- "https://generativelanguage.googleapis.com/v1beta";
6
- export const DEFAULT_MAX_REFERENCE_FILE_BYTES = 8 * 1024 * 1024;
7
-
8
- export const SUPPORTED_REFERENCE_IMAGE_TYPES = new Set([
9
- "image/heic",
10
- "image/heif",
11
- "image/jpeg",
12
- "image/png",
13
- "image/webp",
14
- ]);
15
-
16
- export const OPENAI_SUPPORTED_REFERENCE_IMAGE_TYPES = new Set([
17
- "image/jpeg",
18
- "image/png",
19
- "image/webp",
20
- ]);
1
+ import { DEFAULT_SUPPORTED_AI_IMAGE_MODEL } from "../utils/models";
2
+ export const DEFAULT_MODEL = DEFAULT_SUPPORTED_AI_IMAGE_MODEL;
3
+ export const DEFAULT_PROVIDER_API_URL = "https://generativelanguage.googleapis.com/v1beta";
4
+ export const DEFAULT_MAX_REFERENCE_FILE_BYTES = 8 * 1024 * 1024;
5
+ export const SUPPORTED_REFERENCE_IMAGE_TYPES = new Set([
6
+ "image/heic",
7
+ "image/heif",
8
+ "image/jpeg",
9
+ "image/png",
10
+ "image/webp",
11
+ ]);
12
+ export const OPENAI_SUPPORTED_REFERENCE_IMAGE_TYPES = new Set([
13
+ "image/jpeg",
14
+ "image/png",
15
+ "image/webp",
16
+ ]);
17
+ //# sourceMappingURL=constants.js.map