@imgly/plugin-ai-image-generation-web 0.1.0-rc.2 → 0.1.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/README.md
CHANGED
|
@@ -103,7 +103,87 @@ The plugin accepts the following configuration options:
|
|
|
103
103
|
| `image2image` | Provider | Provider for image-to-image transformation | undefined |
|
|
104
104
|
| `debug` | boolean | Enable debug logging | false |
|
|
105
105
|
| `dryRun` | boolean | Simulate generation without API calls | false |
|
|
106
|
-
| `middleware` | Function |
|
|
106
|
+
| `middleware` | Function[] | Array of middleware functions to extend the generation process | undefined |
|
|
107
|
+
|
|
108
|
+
### Middleware Configuration
|
|
109
|
+
|
|
110
|
+
The `middleware` option allows you to add pre-processing and post-processing capabilities to the generation process:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import ImageGeneration from '@imgly/plugin-ai-image-generation-web';
|
|
114
|
+
import FalAiImage from '@imgly/plugin-ai-image-generation-web/fal-ai';
|
|
115
|
+
import { loggingMiddleware, rateLimitMiddleware } from '@imgly/plugin-ai-generation-web';
|
|
116
|
+
|
|
117
|
+
// Create middleware functions
|
|
118
|
+
const logging = loggingMiddleware();
|
|
119
|
+
const rateLimit = rateLimitMiddleware({
|
|
120
|
+
maxRequests: 10,
|
|
121
|
+
timeWindowMs: 60000, // 1 minute
|
|
122
|
+
onRateLimitExceeded: (input, options, info) => {
|
|
123
|
+
console.log(`Rate limit exceeded: ${info.currentCount}/${info.maxRequests}`);
|
|
124
|
+
return false; // Reject request
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Apply middleware to plugin
|
|
129
|
+
cesdk.addPlugin(
|
|
130
|
+
ImageGeneration({
|
|
131
|
+
text2image: FalAiImage.RecraftV3({
|
|
132
|
+
proxyUrl: 'https://your-fal-ai-proxy.example.com'
|
|
133
|
+
}),
|
|
134
|
+
middleware: [logging, rateLimit] // Apply middleware in order
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Built-in middleware options:
|
|
140
|
+
|
|
141
|
+
- **loggingMiddleware**: Logs generation requests and responses
|
|
142
|
+
- **rateLimitMiddleware**: Limits the number of generation requests in a time window
|
|
143
|
+
|
|
144
|
+
#### Creating Custom Middleware
|
|
145
|
+
|
|
146
|
+
Custom middleware functions follow this pattern:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const customMiddleware = async (input, options, next) => {
|
|
150
|
+
// Pre-processing logic
|
|
151
|
+
console.log('Before generation:', input);
|
|
152
|
+
|
|
153
|
+
// Add custom fields or modify the input if needed
|
|
154
|
+
const modifiedInput = {
|
|
155
|
+
...input,
|
|
156
|
+
customField: 'custom value'
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// Call the next middleware or generation function
|
|
160
|
+
const result = await next(modifiedInput, options);
|
|
161
|
+
|
|
162
|
+
// Post-processing logic
|
|
163
|
+
console.log('After generation:', result);
|
|
164
|
+
|
|
165
|
+
// You can also modify the result before returning it
|
|
166
|
+
return result;
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The middleware function signature is:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
type Middleware<I, O extends Output> = (
|
|
174
|
+
input: I,
|
|
175
|
+
options: GenerationOptions & {
|
|
176
|
+
// The block IDs the generation is applied on
|
|
177
|
+
blockIds?: number[] | null;
|
|
178
|
+
|
|
179
|
+
// Function to add a cleanup handler
|
|
180
|
+
addDisposer: (dispose: () => Promise<void>) => void;
|
|
181
|
+
},
|
|
182
|
+
next: (input: I, options: GenerationOptions) => Promise<GenerationResult<O>>
|
|
183
|
+
) => Promise<GenerationResult<O>>;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Middleware functions are applied in order, creating a chain of processing steps. The `next` parameter calls the next middleware in the chain or the generation function itself.
|
|
107
187
|
|
|
108
188
|
### Using a Proxy
|
|
109
189
|
|
|
@@ -10,6 +10,13 @@ type ProviderConfiguration = {
|
|
|
10
10
|
proxyUrl: string;
|
|
11
11
|
debug?: boolean;
|
|
12
12
|
middleware?: Middleware<RecraftV3Input, RecraftV3Output>[];
|
|
13
|
+
/**
|
|
14
|
+
* Base URL used for the UI assets used in the plugin.
|
|
15
|
+
*
|
|
16
|
+
* By default, we load the assets from the IMG.LY CDN You can copy the assets.
|
|
17
|
+
* from the `/assets` folder to your own server and set the base URL to your server.
|
|
18
|
+
*/
|
|
19
|
+
baseURL?: string;
|
|
13
20
|
};
|
|
14
21
|
export declare function RecraftV3(config: ProviderConfiguration): (context: {
|
|
15
22
|
cesdk: CreativeEditorSDK;
|