@imgly/plugin-ai-text-generation-web 0.2.17 → 1.68.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -231
- package/README.md +4 -596
- package/dist/.tsbuildinfo +1 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +2 -2
- package/dist/open-ai/index.mjs.map +1 -1
- package/package.json +4 -8
- package/dist/quickActions/__tests__/Translate.test.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,601 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @imgly/plugin-ai-text-generation-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AI text generation plugin for the CE.SDK editor
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
The `@imgly/plugin-ai-text-generation-web` package enables users to generate and transform text using AI directly within CreativeEditor SDK. This plugin provides text generation capabilities through AI models like Anthropic Claude.
|
|
8
|
-
|
|
9
|
-
Features include:
|
|
10
|
-
|
|
11
|
-
- Text-to-text transformations
|
|
12
|
-
- Quick AI actions for text blocks
|
|
13
|
-
- Multiple transformation options:
|
|
14
|
-
- Improve writing
|
|
15
|
-
- Fix spelling and grammar
|
|
16
|
-
- Make text shorter or longer
|
|
17
|
-
- Change tone (professional, casual, friendly, etc.)
|
|
18
|
-
- Translate to various languages
|
|
19
|
-
- Custom text transformation with prompts
|
|
20
|
-
- Seamless integration with CreativeEditor SDK
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm install @imgly/plugin-ai-text-generation-web
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
### Basic Configuration
|
|
31
|
-
|
|
32
|
-
To use the plugin, import it and configure it with your preferred provider(s):
|
|
33
|
-
|
|
34
|
-
#### Single Provider
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
import CreativeEditorSDK from '@cesdk/cesdk-js';
|
|
38
|
-
import TextGeneration from '@imgly/plugin-ai-text-generation-web';
|
|
39
|
-
import Anthropic from '@imgly/plugin-ai-text-generation-web/anthropic';
|
|
40
|
-
|
|
41
|
-
// Initialize CreativeEditor SDK
|
|
42
|
-
CreativeEditorSDK.create(domElement, {
|
|
43
|
-
license: 'your-license-key'
|
|
44
|
-
// Other configuration options...
|
|
45
|
-
}).then(async (cesdk) => {
|
|
46
|
-
// Add the text generation plugin
|
|
47
|
-
cesdk.addPlugin(
|
|
48
|
-
TextGeneration({
|
|
49
|
-
provider: Anthropic.AnthropicProvider({
|
|
50
|
-
proxyUrl: 'http://your-proxy-server.com/api/proxy',
|
|
51
|
-
model: 'claude-3-7-sonnet-20250219', // Optional model selection (this is also the default)
|
|
52
|
-
headers: {
|
|
53
|
-
'x-custom-header': 'value',
|
|
54
|
-
'x-client-version': '1.0.0'
|
|
55
|
-
},
|
|
56
|
-
// Optional: Configure default property values
|
|
57
|
-
properties: {
|
|
58
|
-
temperature: { default: 0.7 },
|
|
59
|
-
max_tokens: { default: 500 }
|
|
60
|
-
}
|
|
61
|
-
}),
|
|
62
|
-
|
|
63
|
-
// Optional configuration
|
|
64
|
-
debug: false
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
// Set canvas menu order to display AI text actions
|
|
69
|
-
cesdk.ui.setCanvasMenuOrder([
|
|
70
|
-
'ly.img.ai.text.canvasMenu',
|
|
71
|
-
...cesdk.ui.getCanvasMenuOrder()
|
|
72
|
-
]);
|
|
73
|
-
});
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
#### Multiple Providers
|
|
77
|
-
|
|
78
|
-
You can configure multiple providers, and users will see a selection box to choose between them:
|
|
79
|
-
|
|
80
|
-
```typescript
|
|
81
|
-
import CreativeEditorSDK from '@cesdk/cesdk-js';
|
|
82
|
-
import TextGeneration from '@imgly/plugin-ai-text-generation-web';
|
|
83
|
-
import Anthropic from '@imgly/plugin-ai-text-generation-web/anthropic';
|
|
84
|
-
|
|
85
|
-
// Initialize CreativeEditor SDK
|
|
86
|
-
CreativeEditorSDK.create(domElement, {
|
|
87
|
-
license: 'your-license-key'
|
|
88
|
-
// Other configuration options...
|
|
89
|
-
}).then(async (cesdk) => {
|
|
90
|
-
// Add the text generation plugin with multiple providers
|
|
91
|
-
cesdk.addPlugin(
|
|
92
|
-
TextGeneration({
|
|
93
|
-
provider: [
|
|
94
|
-
Anthropic.AnthropicProvider({
|
|
95
|
-
proxyUrl: 'http://your-proxy-server.com/api/proxy',
|
|
96
|
-
model: 'claude-3-7-sonnet-20250219', // Optional model selection (this is also the default)
|
|
97
|
-
headers: {
|
|
98
|
-
'x-custom-header': 'value',
|
|
99
|
-
'x-client-version': '1.0.0'
|
|
100
|
-
}
|
|
101
|
-
}),
|
|
102
|
-
// Add more providers here as they become available
|
|
103
|
-
// OtherProvider.SomeModel({
|
|
104
|
-
// proxyUrl: 'http://your-proxy-server.com/api/proxy',
|
|
105
|
-
// headers: {
|
|
106
|
-
// 'x-api-key': 'your-key',
|
|
107
|
-
// 'x-source': 'cesdk'
|
|
108
|
-
// }
|
|
109
|
-
// })
|
|
110
|
-
],
|
|
111
|
-
|
|
112
|
-
// Optional configuration
|
|
113
|
-
debug: false
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
// Set canvas menu order to display AI text actions
|
|
118
|
-
cesdk.ui.setCanvasMenuOrder([
|
|
119
|
-
'ly.img.ai.text.canvasMenu',
|
|
120
|
-
...cesdk.ui.getCanvasMenuOrder()
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### Providers
|
|
126
|
-
|
|
127
|
-
The plugin currently includes the following providers:
|
|
128
|
-
|
|
129
|
-
#### Anthropic Claude
|
|
130
|
-
|
|
131
|
-
A versatile text generation model that handles various text transformations:
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
provider: Anthropic.AnthropicProvider({
|
|
135
|
-
proxyUrl: 'http://your-proxy-server.com/api/proxy',
|
|
136
|
-
|
|
137
|
-
// Optional model selection (this is also the default)
|
|
138
|
-
model: 'claude-3-7-sonnet-20250219',
|
|
139
|
-
|
|
140
|
-
// Optional custom headers for API requests
|
|
141
|
-
headers: {
|
|
142
|
-
'x-custom-header': 'value',
|
|
143
|
-
'x-client-version': '1.0.0',
|
|
144
|
-
'x-request-source': 'cesdk-plugin'
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
// Optional: Configure default property values
|
|
148
|
-
properties: {
|
|
149
|
-
temperature: { default: 0.7 }, // Creativity level (0.0-1.0)
|
|
150
|
-
max_tokens: { default: 500 } // Maximum response length
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
// Optional debug mode
|
|
154
|
-
debug: false
|
|
155
|
-
});
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
**Default Model**: If no model is specified, the provider uses `'claude-3-7-sonnet-20250219'` by default.
|
|
159
|
-
|
|
160
|
-
Key features:
|
|
161
|
-
|
|
162
|
-
- High-quality text transformations
|
|
163
|
-
- Multiple transformation types
|
|
164
|
-
- Supports various languages
|
|
165
|
-
- Natural, human-like outputs
|
|
166
|
-
- Custom headers support for API requests
|
|
167
|
-
- Configurable model selection (Claude 3.5 Sonnet, Claude 3.7 Sonnet, etc.)
|
|
168
|
-
- Default model: Claude 3.7 Sonnet (2025-02-19)
|
|
169
|
-
|
|
170
|
-
**Custom Translations:**
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
cesdk.i18n.setTranslations({
|
|
174
|
-
en: {
|
|
175
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.property.prompt': 'Enter your text transformation request',
|
|
176
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.property.temperature': 'Claude Creativity Level',
|
|
177
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.property.maxTokens': 'Claude Response Length'
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
#### OpenAI GPT
|
|
183
|
-
|
|
184
|
-
A powerful text generation model that handles various text transformations:
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
provider: OpenAIText.OpenAIProvider({
|
|
188
|
-
proxyUrl: 'http://your-proxy-server.com/api/proxy',
|
|
189
|
-
|
|
190
|
-
// Optional model selection (this is also the default)
|
|
191
|
-
model: 'gpt-4o-mini',
|
|
192
|
-
|
|
193
|
-
// Optional custom headers for API requests
|
|
194
|
-
headers: {
|
|
195
|
-
'x-custom-header': 'value',
|
|
196
|
-
'x-client-version': '1.0.0',
|
|
197
|
-
'x-request-source': 'cesdk-plugin'
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
// Optional: Configure default property values
|
|
201
|
-
properties: {
|
|
202
|
-
temperature: { default: 0.7 }, // Creativity level (0.0-2.0)
|
|
203
|
-
max_tokens: { default: 500 }, // Maximum response length
|
|
204
|
-
top_p: { default: 1.0 } // Nucleus sampling (0.0-1.0)
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
// Optional debug mode
|
|
208
|
-
debug: false
|
|
209
|
-
});
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
**Default Model**: If no model is specified, the provider uses `'gpt-4o-mini'` by default.
|
|
213
|
-
|
|
214
|
-
Key features:
|
|
215
|
-
|
|
216
|
-
- High-quality text transformations
|
|
217
|
-
- Multiple transformation types
|
|
218
|
-
- Supports various languages
|
|
219
|
-
- Natural, human-like outputs
|
|
220
|
-
- Custom headers support for API requests
|
|
221
|
-
- Configurable model selection (GPT-4o, GPT-4o-mini, GPT-3.5-turbo, etc.)
|
|
222
|
-
- Default model: GPT-4o-mini
|
|
223
|
-
|
|
224
|
-
**Custom Translations:**
|
|
225
|
-
|
|
226
|
-
```typescript
|
|
227
|
-
cesdk.i18n.setTranslations({
|
|
228
|
-
en: {
|
|
229
|
-
'ly.img.plugin-ai-text-generation-web.openai.property.prompt': 'Enter your text transformation request',
|
|
230
|
-
'ly.img.plugin-ai-text-generation-web.openai.property.temperature': 'GPT Creativity Level',
|
|
231
|
-
'ly.img.plugin-ai-text-generation-web.openai.property.maxTokens': 'GPT Response Length'
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Feature Control
|
|
237
|
-
|
|
238
|
-
You can control various aspects of the text generation plugin using the Feature API:
|
|
239
|
-
|
|
240
|
-
```typescript
|
|
241
|
-
// Disable provider selection dropdown
|
|
242
|
-
cesdk.feature.enable('ly.img.plugin-ai-text-generation-web.providerSelect', false);
|
|
243
|
-
|
|
244
|
-
// Disable all quick actions
|
|
245
|
-
cesdk.feature.enable('ly.img.plugin-ai-text-generation-web.quickAction', false);
|
|
246
|
-
|
|
247
|
-
// Disable specific quick actions
|
|
248
|
-
cesdk.feature.enable('ly.img.plugin-ai-text-generation-web.quickAction.improve', false);
|
|
249
|
-
cesdk.feature.enable('ly.img.plugin-ai-text-generation-web.quickAction.translate', false);
|
|
250
|
-
cesdk.feature.enable('ly.img.plugin-ai-text-generation-web.quickAction.changeTone', false);
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
For more information about Feature API and available feature flags, see the [@imgly/plugin-ai-generation-web documentation](https://github.com/imgly/plugins/tree/main/packages/plugin-ai-generation-web#available-feature-flags).
|
|
254
|
-
|
|
255
|
-
### Customizing Labels and Translations
|
|
256
|
-
|
|
257
|
-
You can customize all labels and text in the AI text generation interface using the translation system. This allows you to provide better labels for your users in any language.
|
|
258
|
-
|
|
259
|
-
#### Translation Key Structure
|
|
260
|
-
|
|
261
|
-
The system checks for translations in this order (highest to lowest priority):
|
|
262
|
-
|
|
263
|
-
1. **Provider-specific**: `ly.img.plugin-ai-text-generation-web.${provider}.property.${field}` - Override labels for a specific AI provider
|
|
264
|
-
2. **Generic**: `ly.img.plugin-ai-generation-web.property.${field}` - Override labels for all AI plugins
|
|
265
|
-
|
|
266
|
-
#### Basic Example
|
|
267
|
-
|
|
268
|
-
```typescript
|
|
269
|
-
// Customize labels for your AI text generation interface
|
|
270
|
-
cesdk.i18n.setTranslations({
|
|
271
|
-
en: {
|
|
272
|
-
// Generic labels (applies to ALL AI plugins)
|
|
273
|
-
'ly.img.plugin-ai-generation-web.property.prompt': 'Describe what you want to create',
|
|
274
|
-
'ly.img.plugin-ai-generation-web.property.temperature': 'Creativity Level',
|
|
275
|
-
'ly.img.plugin-ai-generation-web.property.maxTokens': 'Maximum Response Length',
|
|
276
|
-
|
|
277
|
-
// Provider-specific for Anthropic
|
|
278
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.property.prompt': 'Enter your text transformation prompt',
|
|
279
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.property.temperature': 'Response Creativity',
|
|
280
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.property.maxTokens': 'Max Response Length',
|
|
281
|
-
|
|
282
|
-
// Provider-specific for OpenAI
|
|
283
|
-
'ly.img.plugin-ai-text-generation-web.openai.property.prompt': 'Describe your text transformation',
|
|
284
|
-
'ly.img.plugin-ai-text-generation-web.openai.property.temperature': 'Creativity Setting',
|
|
285
|
-
'ly.img.plugin-ai-text-generation-web.openai.property.maxTokens': 'Response Limit'
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
#### QuickAction Translations
|
|
291
|
-
|
|
292
|
-
Text QuickActions (like "Improve Writing", "Fix Grammar", etc.) use their own translation keys with provider-specific overrides:
|
|
293
|
-
|
|
294
|
-
```typescript
|
|
295
|
-
cesdk.i18n.setTranslations({
|
|
296
|
-
en: {
|
|
297
|
-
// Provider-specific translations (highest priority)
|
|
298
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.quickAction.improve': 'Improve with Claude',
|
|
299
|
-
'ly.img.plugin-ai-text-generation-web.anthropic.quickAction.fix': 'Fix with Claude',
|
|
300
|
-
'ly.img.plugin-ai-text-generation-web.openai.quickAction.translate': 'Translate with GPT',
|
|
301
|
-
|
|
302
|
-
// Generic plugin translations
|
|
303
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.improve': 'Improve Writing',
|
|
304
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.fix': 'Fix Grammar',
|
|
305
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.shorter': 'Make Shorter',
|
|
306
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.longer': 'Make Longer',
|
|
307
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.changeTone': 'Change Tone',
|
|
308
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.translate': 'Translate',
|
|
309
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.changeTextTo': 'Transform Text...',
|
|
310
|
-
|
|
311
|
-
// QuickAction input fields and buttons
|
|
312
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.changeTextTo.prompt': 'Transform Text...',
|
|
313
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.changeTextTo.prompt.placeholder': 'e.g. "Convert to bullet points"',
|
|
314
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.changeTextTo.apply': 'Transform',
|
|
315
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.translate.language': 'Target Language',
|
|
316
|
-
'ly.img.plugin-ai-text-generation-web.quickAction.translate.apply': 'Translate'
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
**QuickAction Translation Priority:**
|
|
322
|
-
1. Provider-specific: `ly.img.plugin-ai-text-generation-web.${provider}.quickAction.${action}.${field}`
|
|
323
|
-
2. Generic plugin: `ly.img.plugin-ai-text-generation-web.quickAction.${action}.${field}`
|
|
324
|
-
|
|
325
|
-
**Translation Structure:**
|
|
326
|
-
- Base key (e.g., `.quickAction.improve`): Button text when QuickAction is collapsed
|
|
327
|
-
- `.prompt`: Label for input field when expanded
|
|
328
|
-
- `.prompt.placeholder`: Placeholder text for input field
|
|
329
|
-
- `.apply`: Text for action/submit button
|
|
330
|
-
- Additional fields like `.language`: Custom field labels
|
|
331
|
-
|
|
332
|
-
### Configuration Options
|
|
333
|
-
|
|
334
|
-
The plugin accepts the following configuration options:
|
|
335
|
-
|
|
336
|
-
| Option | Type | Description | Default |
|
|
337
|
-
| ------------ | -------------------- | ----------------------------------------------- | -------- |
|
|
338
|
-
| `provider` | Provider \| Provider[] | Provider(s) for text generation and transformation. When multiple providers are provided, users can select between them | required |
|
|
339
|
-
| `debug` | boolean | Enable debug logging | false |
|
|
340
|
-
| `middleware` | Function[] | Array of middleware functions for the generation| undefined|
|
|
341
|
-
|
|
342
|
-
### Middleware Configuration
|
|
343
|
-
|
|
344
|
-
The `middleware` option allows you to add pre-processing and post-processing capabilities to the generation process:
|
|
345
|
-
|
|
346
|
-
```typescript
|
|
347
|
-
import TextGeneration from '@imgly/plugin-ai-text-generation-web';
|
|
348
|
-
import Anthropic from '@imgly/plugin-ai-text-generation-web/anthropic';
|
|
349
|
-
import OpenAIText from '@imgly/plugin-ai-text-generation-web/open-ai';
|
|
350
|
-
import { loggingMiddleware, rateLimitMiddleware } from '@imgly/plugin-ai-generation-web';
|
|
351
|
-
|
|
352
|
-
// Create middleware functions
|
|
353
|
-
const logging = loggingMiddleware();
|
|
354
|
-
const rateLimit = rateLimitMiddleware({
|
|
355
|
-
maxRequests: 20,
|
|
356
|
-
timeWindowMs: 60000, // 1 minute
|
|
357
|
-
onRateLimitExceeded: (input, options, info) => {
|
|
358
|
-
console.log(`Text generation rate limit exceeded: ${info.currentCount}/${info.maxRequests}`);
|
|
359
|
-
return false; // Reject request
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
// Create custom middleware
|
|
364
|
-
const customMiddleware = async (input, options, next) => {
|
|
365
|
-
console.log('Before generation:', input);
|
|
366
|
-
|
|
367
|
-
// Add custom fields or modify the input
|
|
368
|
-
const modifiedInput = {
|
|
369
|
-
...input,
|
|
370
|
-
customField: 'custom value'
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
// Call the next middleware or generation function
|
|
374
|
-
const result = await next(modifiedInput, options);
|
|
375
|
-
|
|
376
|
-
console.log('After generation:', result);
|
|
377
|
-
|
|
378
|
-
// You can also modify the result before returning it
|
|
379
|
-
return result;
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
// Apply middleware to plugin
|
|
383
|
-
cesdk.addPlugin(
|
|
384
|
-
TextGeneration({
|
|
385
|
-
provider: Anthropic.AnthropicProvider({
|
|
386
|
-
proxyUrl: 'http://your-proxy-server.com/api/proxy'
|
|
387
|
-
}),
|
|
388
|
-
middleware: [logging, rateLimit, customMiddleware] // Apply middleware in order
|
|
389
|
-
})
|
|
390
|
-
);
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
Built-in middleware options:
|
|
394
|
-
|
|
395
|
-
- **loggingMiddleware**: Logs generation requests and responses
|
|
396
|
-
- **rateLimitMiddleware**: Limits the number of generation requests in a time window
|
|
397
|
-
|
|
398
|
-
You can also create custom middleware functions to meet your specific needs.
|
|
399
|
-
|
|
400
|
-
#### Preventing Default Feedback
|
|
401
|
-
|
|
402
|
-
Middleware can suppress default UI feedback behaviors using `options.preventDefault()`:
|
|
403
|
-
|
|
404
|
-
```typescript
|
|
405
|
-
const customErrorMiddleware = async (input, options, next) => {
|
|
406
|
-
try {
|
|
407
|
-
return await next(input, options);
|
|
408
|
-
} catch (error) {
|
|
409
|
-
// Prevent default error notification
|
|
410
|
-
options.preventDefault();
|
|
411
|
-
|
|
412
|
-
// Show custom error notification
|
|
413
|
-
options.cesdk?.ui.showNotification({
|
|
414
|
-
type: 'error',
|
|
415
|
-
message: `Text generation failed: ${error.message}`,
|
|
416
|
-
action: {
|
|
417
|
-
label: 'Try Again',
|
|
418
|
-
onClick: () => {/* retry logic */}
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
throw error;
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
**What gets prevented:**
|
|
428
|
-
- Error/success notifications
|
|
429
|
-
- Block error state
|
|
430
|
-
- Console error logging
|
|
431
|
-
|
|
432
|
-
**What is NOT prevented:**
|
|
433
|
-
- Pending → Ready transition (loading spinner always stops)
|
|
434
|
-
|
|
435
|
-
For more details, see the [@imgly/plugin-ai-generation-web documentation](https://github.com/imgly/plugins/tree/main/packages/plugin-ai-generation-web#preventing-default-feedback).
|
|
436
|
-
|
|
437
|
-
### Using a Proxy
|
|
438
|
-
|
|
439
|
-
For security reasons, you must use a proxy server to handle API requests to Anthropic. The proxy URL is required when configuring providers:
|
|
440
|
-
|
|
441
|
-
```typescript
|
|
442
|
-
provider: Anthropic.AnthropicProvider({
|
|
443
|
-
proxyUrl: 'http://your-proxy-server.com/api/proxy',
|
|
444
|
-
headers: {
|
|
445
|
-
'x-custom-header': 'value',
|
|
446
|
-
'x-client-version': '1.0.0'
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
Your proxy server should:
|
|
452
|
-
|
|
453
|
-
1. Receive requests from the client
|
|
454
|
-
2. Add the necessary authentication (API key) to the requests
|
|
455
|
-
3. Forward requests to the AI provider API (Anthropic, OpenAI, etc.)
|
|
456
|
-
4. Return responses to the client
|
|
457
|
-
|
|
458
|
-
The `headers` option allows you to include custom HTTP headers in all API requests. This is useful for:
|
|
459
|
-
- Adding custom client identification headers
|
|
460
|
-
- Including version information
|
|
461
|
-
- Passing through metadata required by your API
|
|
462
|
-
- Adding correlation IDs for request tracing
|
|
463
|
-
|
|
464
|
-
Never expose your API keys in client-side code.
|
|
465
|
-
|
|
466
|
-
## API Reference
|
|
467
|
-
|
|
468
|
-
### Main Plugin
|
|
469
|
-
|
|
470
|
-
```typescript
|
|
471
|
-
TextGeneration(options: PluginConfiguration): EditorPlugin
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
Creates and returns a plugin that can be added to CreativeEditor SDK.
|
|
475
|
-
|
|
476
|
-
### Plugin Configuration
|
|
477
|
-
|
|
478
|
-
```typescript
|
|
479
|
-
interface PluginConfiguration {
|
|
480
|
-
// Provider(s) for text generation and transformation
|
|
481
|
-
provider: (context: {
|
|
482
|
-
cesdk: CreativeEditorSDK;
|
|
483
|
-
}) => Promise<Provider<'text', any, any> | Provider<'text', any, any>[]>;
|
|
484
|
-
|
|
485
|
-
// Enable debug logging
|
|
486
|
-
debug?: boolean;
|
|
487
|
-
}
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
### Anthropic Provider Configuration
|
|
491
|
-
|
|
492
|
-
```typescript
|
|
493
|
-
Anthropic.AnthropicProvider(config: {
|
|
494
|
-
proxyUrl: string;
|
|
495
|
-
model?: string;
|
|
496
|
-
headers?: Record<string, string>;
|
|
497
|
-
debug?: boolean;
|
|
498
|
-
})
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
### OpenAI Provider Configuration
|
|
502
|
-
|
|
503
|
-
```typescript
|
|
504
|
-
OpenAIText.OpenAIProvider(config: {
|
|
505
|
-
proxyUrl: string;
|
|
506
|
-
model?: string;
|
|
507
|
-
headers?: Record<string, string>;
|
|
508
|
-
debug?: boolean;
|
|
509
|
-
})
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
## UI Integration
|
|
513
|
-
|
|
514
|
-
The plugin automatically registers the following UI components:
|
|
515
|
-
|
|
516
|
-
1. **Quick Actions**: Canvas menu items for text transformations
|
|
517
|
-
|
|
518
|
-
### Canvas Menu Integration
|
|
519
|
-
|
|
520
|
-
The plugin automatically registers quick actions for text transformation. Here are the available quick actions:
|
|
521
|
-
|
|
522
|
-
#### Available Quick Actions
|
|
523
|
-
|
|
524
|
-
- **`ly.img.improve`**: Improve writing quality
|
|
525
|
-
- Input: `{ prompt: string }`
|
|
526
|
-
|
|
527
|
-
- **`ly.img.fix`**: Fix spelling and grammar
|
|
528
|
-
- Input: `{ prompt: string }`
|
|
529
|
-
|
|
530
|
-
- **`ly.img.shorter`**: Make text shorter
|
|
531
|
-
- Input: `{ prompt: string }`
|
|
532
|
-
|
|
533
|
-
- **`ly.img.longer`**: Make text longer
|
|
534
|
-
- Input: `{ prompt: string }`
|
|
535
|
-
|
|
536
|
-
- **`ly.img.changeTone`**: Change the tone of the text
|
|
537
|
-
- Input: `{ prompt: string, type: string }`
|
|
538
|
-
|
|
539
|
-
- **`ly.img.translate`**: Translate text to different languages
|
|
540
|
-
- Input: `{ prompt: string, language: string }`
|
|
541
|
-
|
|
542
|
-
- **`ly.img.changeTextTo`**: Change text to a different format or style
|
|
543
|
-
- Input: `{ prompt: string, customPrompt: string }`
|
|
544
|
-
|
|
545
|
-
#### Provider Quick Action Support
|
|
546
|
-
|
|
547
|
-
Providers declare which quick actions they support through their configuration:
|
|
548
|
-
|
|
549
|
-
```typescript
|
|
550
|
-
const myTextProvider = {
|
|
551
|
-
// ... other provider config
|
|
552
|
-
input: {
|
|
553
|
-
// ... panel config
|
|
554
|
-
quickActions: {
|
|
555
|
-
supported: {
|
|
556
|
-
'ly.img.improve': {
|
|
557
|
-
mapInput: (quickActionInput) => ({
|
|
558
|
-
prompt: quickActionInput.prompt
|
|
559
|
-
})
|
|
560
|
-
},
|
|
561
|
-
'ly.img.fix': {
|
|
562
|
-
mapInput: (quickActionInput) => ({
|
|
563
|
-
prompt: quickActionInput.prompt
|
|
564
|
-
})
|
|
565
|
-
},
|
|
566
|
-
'ly.img.changeTone': {
|
|
567
|
-
mapInput: (quickActionInput) => ({
|
|
568
|
-
prompt: quickActionInput.prompt,
|
|
569
|
-
tone: quickActionInput.type
|
|
570
|
-
})
|
|
571
|
-
}
|
|
572
|
-
// Add more supported quick actions as needed
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
```
|
|
578
|
-
|
|
579
|
-
To add the AI text menu to your canvas menu, use:
|
|
580
|
-
|
|
581
|
-
```typescript
|
|
582
|
-
cesdk.ui.setCanvasMenuOrder([
|
|
583
|
-
'ly.img.ai.text.canvasMenu',
|
|
584
|
-
...cesdk.ui.getCanvasMenuOrder()
|
|
585
|
-
]);
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
## Translations
|
|
589
|
-
|
|
590
|
-
For customization and localization, see the [translations.json](https://github.com/imgly/plugins/tree/main/packages/plugin-ai-text-generation-web/translations.json) file which contains provider-specific translation keys for text generation interfaces.
|
|
591
|
-
|
|
592
|
-
## Related Packages
|
|
593
|
-
|
|
594
|
-
- [@imgly/plugin-ai-generation-web](https://github.com/imgly/plugins/tree/main/packages/plugin-ai-generation-web) - Core utilities for AI generation
|
|
595
|
-
- [@imgly/plugin-ai-image-generation-web](https://github.com/imgly/plugins/tree/main/packages/plugin-ai-image-generation-web) - AI image generation
|
|
596
|
-
- [@imgly/plugin-ai-video-generation-web](https://github.com/imgly/plugins/tree/main/packages/plugin-ai-video-generation-web) - AI video generation
|
|
597
|
-
- [@imgly/plugin-ai-audio-generation-web](https://github.com/imgly/plugins/tree/main/packages/plugin-ai-audio-generation-web) - AI audio generation
|
|
5
|
+
For documentation, visit: https://img.ly/docs/cesdk
|
|
598
6
|
|
|
599
7
|
## License
|
|
600
8
|
|
|
601
|
-
This plugin is part of the IMG.LY plugin ecosystem for CreativeEditor SDK.
|
|
9
|
+
This plugin is part of the IMG.LY plugin ecosystem for CreativeEditor SDK.
|