@imgly/plugin-ai-generation-web 0.1.8 → 0.1.10

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 ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog - AI Plugins
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.1.10] - 2025-06-20
6
+
7
+ - [all] Fix issue with GPT provider when using text provider
8
+
9
+ ## [0.1.9] - 2025-06-05
10
+
11
+ - [all] Add support for custom headers
12
+
13
+ ## [0.1.8] - 2025-05-26
14
+
15
+ - [ai-apps] Handle `sceneMode` change in upcoming CE.SDK version 1.52.0
16
+
17
+ ## [0.1.0] - 2025-04-17
18
+
19
+ - [all] Initial release
package/README.md CHANGED
@@ -26,11 +26,20 @@ import {
26
26
  Provider,
27
27
  ImageOutput,
28
28
  initProvider,
29
- loggingMiddleware
29
+ loggingMiddleware,
30
+ CommonProviderConfiguration
30
31
  } from '@imgly/plugin-ai-generation-web';
31
32
 
32
- // Create your image generation provider
33
- const myImageProvider: Provider<'image', MyInputType, ImageOutput> = {
33
+ // Define your provider configuration interface
34
+ interface MyProviderConfiguration
35
+ extends CommonProviderConfiguration<MyInputType, ImageOutput> {
36
+ // Add any provider-specific configuration here
37
+ baseURL?: string;
38
+ }
39
+
40
+ // Create a provider factory function
41
+ function createMyImageProvider(config: MyProviderConfiguration): Provider<'image', MyInputType, ImageOutput> {
42
+ return {
34
43
  // Unique identifier for this provider
35
44
  id: 'my-image-provider',
36
45
 
@@ -40,7 +49,10 @@ const myImageProvider: Provider<'image', MyInputType, ImageOutput> = {
40
49
  // Initialize the provider
41
50
  initialize: async ({ engine, cesdk }) => {
42
51
  // Setup APIs, register further components, etc.
43
- myAIApi.configure({ apiKey: 'YOUR_API_KEY' });
52
+ myAIApi.configure({
53
+ apiKey: 'YOUR_API_KEY',
54
+ headers: config.headers // Use custom headers if provided
55
+ });
44
56
  },
45
57
 
46
58
  // Define input panel and UI components
@@ -97,7 +109,9 @@ const myImageProvider: Provider<'image', MyInputType, ImageOutput> = {
97
109
  // Core generation function
98
110
  generate: async (input, { abortSignal, engine }) => {
99
111
  // Call your AI API and return result
100
- const response = await myAIApi.generateImage(input);
112
+ const response = await myAIApi.generateImage(input, {
113
+ headers: config.headers // Pass custom headers to API
114
+ });
101
115
 
102
116
  return {
103
117
  kind: 'image',
@@ -105,7 +119,20 @@ const myImageProvider: Provider<'image', MyInputType, ImageOutput> = {
105
119
  };
106
120
  }
107
121
  }
108
- };
122
+ };
123
+ }
124
+
125
+ // Usage example
126
+ const myImageProvider = createMyImageProvider({
127
+ proxyUrl: 'https://your-api-proxy.example.com',
128
+ headers: {
129
+ 'x-client-version': '1.0.0',
130
+ 'x-request-source': 'cesdk-plugin'
131
+ },
132
+ debug: false,
133
+ middleware: [loggingMiddleware()],
134
+ baseURL: 'https://assets.example.com'
135
+ });
109
136
  ```
110
137
 
111
138
  ## Provider Interface
@@ -120,6 +147,61 @@ The Provider interface is generic and type-safe, supporting four output kinds:
120
147
  interface Provider<K extends OutputKind, I, O extends Output, C = O> { ... }
121
148
  ```
122
149
 
150
+ ## Common Provider Configuration
151
+
152
+ All providers should extend the `CommonProviderConfiguration` interface, which provides standardized configuration options:
153
+
154
+ ```typescript
155
+ interface CommonProviderConfiguration<I, O extends Output> {
156
+ // The proxy URL to use for the provider
157
+ proxyUrl: string;
158
+
159
+ // Enable debug mode for additional logging
160
+ debug?: boolean;
161
+
162
+ // Middleware for request/response processing
163
+ middleware?: Middleware<I, O>[];
164
+
165
+ // Custom headers to include in all API requests
166
+ headers?: Record<string, string>;
167
+ }
168
+ ```
169
+
170
+ The `headers` property allows you to include custom HTTP headers in all API requests made by your provider. This is useful for:
171
+ - Adding custom client identification headers
172
+ - Including version information
173
+ - Passing through metadata required by your API
174
+ - Adding correlation IDs for request tracing
175
+
176
+ **Implementation Note:** When implementing your provider's `generate` function, ensure you merge the custom headers with any required headers for your API. For example:
177
+
178
+ ```typescript
179
+ // In your generate function
180
+ const response = await fetch(apiUrl, {
181
+ method: 'POST',
182
+ headers: {
183
+ 'Content-Type': 'application/json',
184
+ 'Authorization': `Bearer ${apiKey}`,
185
+ ...config.headers // Spread custom headers
186
+ },
187
+ body: JSON.stringify(requestData)
188
+ });
189
+ ```
190
+
191
+ Example provider configuration:
192
+
193
+ ```typescript
194
+ const myProvider = createMyProvider({
195
+ proxyUrl: 'https://api.example.com',
196
+ headers: {
197
+ 'x-client-version': '1.0.0',
198
+ 'x-request-source': 'cesdk-plugin'
199
+ },
200
+ debug: false,
201
+ middleware: [loggingMiddleware()]
202
+ });
203
+ ```
204
+
123
205
  ### Key Provider Options
124
206
 
125
207
  - **id**: Unique identifier for your provider
@@ -235,7 +317,7 @@ input: {
235
317
  imageUrl: (context, property) => {
236
318
  const valueState = context.state('imageUrl', '');
237
319
  context.builder.TextInput('imageUrl', {
238
- label: 'Image URL',
320
+ inputLabel: 'Image URL',
239
321
  ...valueState
240
322
  });
241
323
 
@@ -294,7 +376,7 @@ input: {
294
376
 
295
377
  ### 2. Custom Input Panels
296
378
 
297
- The `custom` type gives you complete control over UI components.
379
+ The `custom` type gives you complete control over UI components. For more details on how to build custom panels and see all available builder components, refer to the [Create a Custom Panel](https://img.ly/docs/cesdk/js/user-interface/ui-extensions/create-custom-panel-d87b83/) guide.
298
380
 
299
381
  ```typescript
300
382
  input: {
@@ -304,14 +386,14 @@ input: {
304
386
  // Use the builder pattern to create UI components
305
387
  const promptState = context.state('prompt', '');
306
388
  context.builder.TextArea('prompt', {
307
- label: 'Prompt',
389
+ inputLabel: 'Prompt',
308
390
  ...promptState
309
391
  });
310
392
 
311
393
  // Set up width selection
312
394
  const widthState = context.state('width', 1024);
313
395
  context.builder.Select('width', {
314
- label: 'Width',
396
+ inputLabel: 'Width',
315
397
  options: [
316
398
  { value: 512, label: '512px' },
317
399
  { value: 1024, label: '1024px' },
@@ -683,7 +765,7 @@ This example shows how to create a quick action that expands into a more complex
683
765
  const promptState = state('prompt', '');
684
766
 
685
767
  builder.TextArea('prompt', {
686
- label: 'Prompt',
768
+ inputLabel: 'Prompt',
687
769
  placeholder: 'Describe the changes you want...',
688
770
  ...promptState
689
771
  });
@@ -759,9 +841,13 @@ The most basic way is to use the `initProvider` function to register your provid
759
841
  ```typescript
760
842
  import { initProvider } from '@imgly/plugin-ai-generation-web';
761
843
 
762
- // Create your provider
844
+ // Create your provider with custom headers
763
845
  const myProvider = createMyProvider({
764
- proxyUrl: 'https://your-api-proxy.example.com'
846
+ proxyUrl: 'https://your-api-proxy.example.com',
847
+ headers: {
848
+ 'x-custom-header': 'value',
849
+ 'x-client-version': '1.0.0'
850
+ }
765
851
  });
766
852
 
767
853
  // Initialize the provider with CreativeEditor SDK
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import CreativeEditorSDK from '@cesdk/cesdk-js';
2
+ import { RenderCustomProperty } from '../generation/provider';
3
+ type Style = {
4
+ id: 'none' | (string & {});
5
+ label: string;
6
+ prompt: string;
7
+ thumbUri: string;
8
+ };
9
+ /**
10
+ * Provides render function for a style transfer property that allows
11
+ * to change a style (of an image) from a library.
12
+ *
13
+ * The style will be appended to the prompt property, so the model does
14
+ * not need to support style transfer directly.
15
+ *
16
+ * By default this expects the property key to be `style`. This can be changed with the option
17
+ * `propertyKey`.
18
+ */
19
+ declare function renderStyleTransferProperty(providerId: string, options: {
20
+ cesdk?: CreativeEditorSDK;
21
+ /**
22
+ * Base URL used for the UI assets used in the plugin.
23
+ */
24
+ baseURL?: string;
25
+ /**
26
+ * What property key to use for the style property.
27
+ */
28
+ propertyKey?: string;
29
+ /**
30
+ * What property key to use for the prompt property.
31
+ */
32
+ propertyKeyForPrompt?: string;
33
+ /**
34
+ * Override the default styles
35
+ */
36
+ styles?: Style[] | ((defaultStyles: Style[]) => Style[]);
37
+ /**
38
+ * Overrides the default i18n translations for the prompt input.
39
+ */
40
+ i18n?: {
41
+ prompt?: {
42
+ inputLabel?: string;
43
+ placeholder?: string;
44
+ };
45
+ };
46
+ }): RenderCustomProperty;
47
+ export default renderStyleTransferProperty;
@@ -2,7 +2,7 @@ import { Builder } from '@cesdk/cesdk-js';
2
2
  import { OpenAPIV3 } from 'openapi-types';
3
3
  export interface Property {
4
4
  id: string;
5
- schema: OpenAPIV3.SchemaObject;
5
+ schema?: OpenAPIV3.SchemaObject;
6
6
  }
7
7
  type PropertyInputForString = {
8
8
  id: string;
@@ -211,6 +211,14 @@ export interface PanelInputSchema<K extends OutputKind, I> extends PanelInputBas
211
211
  * representing the properties.
212
212
  */
213
213
  orderExtensionKeyword?: string | string[];
214
+ /**
215
+ * Defined the order of the properties in the panel. Takes precedence over
216
+ * the order defined in the schema (also see `orderExtensionKeyword`).
217
+ *
218
+ * If a function is provided, it receives the current order of properties from
219
+ * the schema and can return a new order.
220
+ */
221
+ order?: string[] | ((order: string[]) => string[]);
214
222
  /**
215
223
  * Returns the necessary input for the creation of a block.
216
224
  *
@@ -1,6 +1,8 @@
1
1
  import type CreativeEditorSDK from '@cesdk/cesdk-js';
2
2
  import { type CreativeEngine } from '@cesdk/cesdk-js';
3
3
  import type Provider from './provider';
4
+ import { Output } from './provider';
5
+ import { Middleware } from './middleware/middleware';
4
6
  /**
5
7
  * Configuration options for provider initialization
6
8
  */
@@ -31,6 +33,27 @@ export type InitProviderConfiguration = {
31
33
  */
32
34
  middleware?: GenerationMiddleware;
33
35
  };
36
+ /**
37
+ * Common provider configuration that all providers should provide.
38
+ */
39
+ export interface CommonProviderConfiguration<I, O extends Output> {
40
+ /**
41
+ * The proxy URL to use for the provider.
42
+ */
43
+ proxyUrl: string;
44
+ /**
45
+ * Indicates whether the provider is in debug mode and should log additional information.
46
+ */
47
+ debug?: boolean;
48
+ /**
49
+ * Middleware that shall be executed during the generation process.
50
+ */
51
+ middleware?: Middleware<I, O>[];
52
+ /**
53
+ * Headers that shall be sent with the request of the provider.
54
+ */
55
+ headers?: Record<string, string>;
56
+ }
34
57
  export type GenerationMiddleware = (generate: () => Promise<void>, context: {
35
58
  provider: Provider<any, any, any>;
36
59
  abort: () => void;
package/dist/index.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  import renderImageUrlProperty from './common/renderImageUrlProperty';
2
+ import renderStyleTransferProperty from './common/renderStyleTransferProperty';
2
3
  declare const CommonProperties: {
3
4
  ImageUrl: typeof renderImageUrlProperty;
5
+ StyleTransfer: typeof renderStyleTransferProperty;
4
6
  };
5
7
  export { CommonProperties };
6
8
  export { type default as Provider, type ImageOutput, type VideoOutput, type TextOutput, type AudioOutput, type Output, type OutputKind, type PanelInputSchema, type RenderCustomProperty, type GetBlockInput, type GetBlockInputResult, type GetInput, type QuickAction, type QuickActionsInput } from './generation/provider';
7
9
  export { type GetPropertyInput, type Property } from './generation/openapi/types';
8
10
  export { default as initProvider } from './generation/initProvider';
9
- export { type GenerationMiddleware } from './generation/types';
11
+ export { type GenerationMiddleware, type CommonProviderConfiguration } from './generation/types';
10
12
  export { composeMiddlewares, type Middleware } from './generation/middleware/middleware';
11
13
  export { default as loggingMiddleware } from './generation/middleware/loggingMiddleware';
12
14
  export { default as uploadMiddleware } from './generation/middleware/uploadMiddleware';
13
15
  export { default as rateLimitMiddleware, type RateLimitOptions } from './generation/middleware/rateLimitMiddleware';
14
- export { getPanelId, getDurationForVideo, getThumbnailForVideo, getLabelFromId } from './utils';
16
+ export { getPanelId, getDurationForVideo, getThumbnailForVideo, getLabelFromId, isAsyncGenerator } from './utils';
15
17
  export { default as registerDockComponent } from './registerDockComponent';
16
18
  export { default as getQuickActionMenu } from './generation/quickAction/getQuickActionMenu';
17
19
  export { default as registerQuickActionMenuComponent } from './generation/quickAction/registerQuickActionMenuComponent';