@imgly/plugin-ai-generation-web 0.1.9 → 0.2.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +270 -426
  3. package/dist/__tests__/ActionRegistry.test.d.ts +1 -0
  4. package/dist/__tests__/compactSeparators.test.d.ts +1 -0
  5. package/dist/__tests__/createConfirmationRenderFunction.test.d.ts +1 -0
  6. package/dist/{generation → assets}/getAssetResultForGenerated.d.ts +1 -1
  7. package/dist/{generation → assets}/getAssetResultForPlaceholder.d.ts +1 -1
  8. package/dist/assets/initializeHistoryAssetLibraryEntry.d.ts +7 -0
  9. package/dist/assets/initializeHistoryAssetSource.d.ts +7 -0
  10. package/dist/assets/initializeHistoryCompositeAssetSource.d.ts +11 -0
  11. package/dist/assets/integrateIntoDefaultAssetLibraryEntry.d.ts +8 -0
  12. package/dist/core/ActionRegistry.d.ts +201 -0
  13. package/dist/core/ProviderRegistry.d.ts +40 -0
  14. package/dist/core/constants.d.ts +1 -0
  15. package/dist/{generation → core}/provider.d.ts +38 -58
  16. package/dist/generation/CallbacksRegistry.d.ts +34 -0
  17. package/dist/generation/createGenerateFunction.d.ts +30 -0
  18. package/dist/generation/handleGenerateFromPanel.d.ts +50 -0
  19. package/dist/generation/handleGenerateFromQuickAction.d.ts +56 -0
  20. package/dist/generation/handleGenerationError.d.ts +2 -3
  21. package/dist/index.d.ts +21 -25
  22. package/dist/index.mjs +9 -6
  23. package/dist/index.mjs.map +4 -4
  24. package/dist/{generation/middleware → middleware}/alwaysOnTopMiddleware.d.ts +1 -1
  25. package/dist/{generation/middleware → middleware}/dryRunMiddleware.d.ts +2 -1
  26. package/dist/{generation/middleware → middleware}/editModeMiddleware.d.ts +1 -1
  27. package/dist/{generation/middleware → middleware}/highlightBlocksMiddleware.d.ts +1 -1
  28. package/dist/middleware/lockEditModeMiddleware.d.ts +17 -0
  29. package/dist/{generation/middleware → middleware}/lockMiddleware.d.ts +1 -1
  30. package/dist/middleware/loggingMiddleware.d.ts +6 -0
  31. package/dist/{generation/middleware → middleware}/middleware.d.ts +1 -1
  32. package/dist/{generation/middleware → middleware}/pendingMiddleware.d.ts +3 -3
  33. package/dist/{generation/middleware → middleware}/rateLimitMiddleware.d.ts +1 -1
  34. package/dist/{generation/middleware → middleware}/uploadMiddleware.d.ts +1 -1
  35. package/dist/{generation/openapi → openapi}/getProperties.d.ts +1 -1
  36. package/dist/{generation/openapi → openapi}/renderProperty.d.ts +3 -3
  37. package/dist/{generation/quickAction/consumeGeneratedResult.d.ts → providers/getApplyCallbacks.d.ts} +13 -8
  38. package/dist/providers/getCanvasMenuComponentId.d.ts +3 -0
  39. package/dist/providers/initializeProvider.d.ts +22 -0
  40. package/dist/providers/initializeProviders.d.ts +38 -0
  41. package/dist/types.d.ts +101 -0
  42. package/dist/{common → ui/common}/renderImageUrlProperty.d.ts +1 -1
  43. package/dist/{common → ui/common}/renderStyleTransferProperty.d.ts +1 -1
  44. package/dist/{generation → ui/components}/renderGenerationComponents.d.ts +6 -5
  45. package/dist/ui/panels/createConfirmationRenderFunction.d.ts +16 -0
  46. package/dist/ui/panels/createPanelRenderFunction.d.ts +9 -0
  47. package/dist/ui/panels/createPanelRenderFunctionFromCustom.d.ts +6 -0
  48. package/dist/ui/panels/createPanelRenderFunctionFromSchema.d.ts +9 -0
  49. package/dist/ui/quickActions/createQuickActionMenuRenderFunction.d.ts +13 -0
  50. package/dist/ui/quickActions/getQuickActionOrder.d.ts +12 -0
  51. package/dist/ui/quickActions/initializeQuickActionComponents.d.ts +15 -0
  52. package/dist/ui/quickActions/types.d.ts +10 -0
  53. package/dist/ui/quickActions/utils.d.ts +7 -0
  54. package/dist/utils/checkAiPluginVersion.d.ts +10 -0
  55. package/dist/utils/compactSeparators.d.ts +7 -0
  56. package/dist/utils/lockSelectionToEditMode.d.ts +12 -0
  57. package/dist/{utils.d.ts → utils/utils.d.ts} +6 -1
  58. package/package.json +2 -2
  59. package/dist/generation/generate.d.ts +0 -16
  60. package/dist/generation/initProvider.d.ts +0 -20
  61. package/dist/generation/middleware/loggingMiddleware.d.ts +0 -4
  62. package/dist/generation/quickAction/common/QuickActionBaseButton.d.ts +0 -11
  63. package/dist/generation/quickAction/common/QuickActionBaseLibrary.d.ts +0 -23
  64. package/dist/generation/quickAction/common/QuickActionBasePrompt.d.ts +0 -13
  65. package/dist/generation/quickAction/common/QuickActionBaseSelect.d.ts +0 -28
  66. package/dist/generation/quickAction/common/QuickActionChangeImage.d.ts +0 -17
  67. package/dist/generation/quickAction/common/QuickActionCombineImages.d.ts +0 -17
  68. package/dist/generation/quickAction/common/QuickActionEditTextStyle.d.ts +0 -17
  69. package/dist/generation/quickAction/common/QuickActionImageVariant.d.ts +0 -17
  70. package/dist/generation/quickAction/common/QuickActionSwapImageBackground.d.ts +0 -17
  71. package/dist/generation/quickAction/generate.d.ts +0 -19
  72. package/dist/generation/quickAction/getQuickActionMenu.d.ts +0 -10
  73. package/dist/generation/quickAction/registerQuickActionMenuComponent.d.ts +0 -12
  74. package/dist/generation/quickAction/types.d.ts +0 -25
  75. package/dist/generation/quickAction/utils.d.ts +0 -13
  76. package/dist/generation/registerPanelInputCustom.d.ts +0 -6
  77. package/dist/generation/registerPanelInputSchema.d.ts +0 -9
  78. package/dist/generation/types.d.ts +0 -79
  79. /package/dist/{generation → assets}/previewUri.d.ts +0 -0
  80. /package/dist/{generation/openapi → openapi}/dereferenceDocument.d.ts +0 -0
  81. /package/dist/{generation/openapi → openapi}/isOpenAPISchema.d.ts +0 -0
  82. /package/dist/{generation/openapi → openapi}/types.d.ts +0 -0
  83. /package/dist/{registerDockComponent.d.ts → ui/components/registerDockComponent.d.ts} +0 -0
  84. /package/dist/{icons.d.ts → ui/icons.d.ts} +0 -0
  85. /package/dist/{generation/quickAction/common → ui/quickActions}/enableImageFill.d.ts +0 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
1
  import { type AssetResult } from '@cesdk/cesdk-js';
2
- import { type OutputKind, GetBlockInputResult, Output } from './provider';
2
+ import { type OutputKind, GetBlockInputResult, Output } from '../core/provider';
3
3
  declare function getAssetResultForGenerated<K extends OutputKind>(id: string, kind: K, blockInputs: GetBlockInputResult<K>, output: Output): Promise<AssetResult>;
4
4
  export default getAssetResultForGenerated;
@@ -1,4 +1,4 @@
1
1
  import { type AssetResult } from '@cesdk/cesdk-js';
2
- import { type OutputKind, GetBlockInputResult } from './provider';
2
+ import { type OutputKind, GetBlockInputResult } from '../core/provider';
3
3
  declare function getAssetResultForPlaceholder<K extends OutputKind>(id: string, kind: K, blockInput: GetBlockInputResult<K>): AssetResult;
4
4
  export default getAssetResultForPlaceholder;
@@ -0,0 +1,7 @@
1
+ import { OutputKind, Output } from '../core/provider';
2
+ import { InitializationContext } from '../types';
3
+ /**
4
+ * Initializes the history asset source for the given provider.
5
+ */
6
+ declare function initializeHistoryAssetLibraryEntry<K extends OutputKind, I, O extends Output>(context: InitializationContext<K, I, O>, historyAssetSourceId?: string): string | undefined;
7
+ export default initializeHistoryAssetLibraryEntry;
@@ -0,0 +1,7 @@
1
+ import { OutputKind, Output } from '../core/provider';
2
+ import { InitializationContext } from '../types';
3
+ /**
4
+ * Initializes the history asset source for the given provider.
5
+ */
6
+ declare function initializeHistoryAssetSource<K extends OutputKind, I, O extends Output>(context: InitializationContext<K, I, O>): string | undefined;
7
+ export default initializeHistoryAssetSource;
@@ -0,0 +1,11 @@
1
+ import { OutputKind } from '../core/provider';
2
+ import CreativeEditorSDK from '@cesdk/cesdk-js';
3
+ /**
4
+ * Initializes the combined history asset source for the given asset sources.
5
+ */
6
+ declare function initializeHistoryCompositeAssetSource<K extends OutputKind>(options: {
7
+ kind: K;
8
+ cesdk: CreativeEditorSDK;
9
+ historAssetSourceIds: string[];
10
+ }): string | undefined;
11
+ export default initializeHistoryCompositeAssetSource;
@@ -0,0 +1,8 @@
1
+ import { OutputKind } from '../core/provider';
2
+ import CreativeEditorSDK from '@cesdk/cesdk-js';
3
+ /**
4
+ * Integrates the asset sources into the default asset library entry for the
5
+ * given kind.
6
+ */
7
+ declare function integrateIntoDefaultAssetLibraryEntry<K extends OutputKind>(kind: K, historAssetSourceIds: string[], cesdk: CreativeEditorSDK): string | undefined;
8
+ export default integrateIntoDefaultAssetLibraryEntry;
@@ -0,0 +1,201 @@
1
+ import { BuilderRenderFunctionContext, CreativeEngine, SceneMode, Scope } from '@cesdk/cesdk-js';
2
+ import { OutputKind, Output } from './provider';
3
+ import { Result } from '../generation/createGenerateFunction';
4
+ /**
5
+ * Base properties shared by all action definitions.
6
+ */
7
+ interface BaseActionDefinition {
8
+ /** Unique identifier for the action */
9
+ id: string;
10
+ /** Human-readable label for the action */
11
+ label?: string;
12
+ /** Detailed description of what the action does */
13
+ description?: string;
14
+ /** Optional metadata for additional information */
15
+ meta?: Record<string, any>;
16
+ /** The scene mode for which this action is only applicable */
17
+ sceneMode?: SceneMode;
18
+ }
19
+ /**
20
+ * Definition for a plugin action - a global action that can be invoked from apps, command palettes, etc.
21
+ */
22
+ export interface PluginActionDefinition extends BaseActionDefinition {
23
+ /** Action type discriminator */
24
+ type: 'plugin';
25
+ /** ID of the plugin that registered this action */
26
+ pluginId: string;
27
+ /** Function to execute the action */
28
+ execute: () => void;
29
+ }
30
+ /**
31
+ * Render context for quick actions with generation capability.
32
+ */
33
+ export interface QuickActionRenderContext<Q = Record<string, any>> {
34
+ /** Toggle between collapsed and expanded state */
35
+ toggleExpand: () => void;
36
+ /** Whether the quick action is currently expanded */
37
+ isExpanded: boolean;
38
+ /** Close the entire quick action popover */
39
+ close: () => void;
40
+ /** Generate output using the quick action input */
41
+ generate: (input: Q, options?: {
42
+ blockIds?: number[];
43
+ }) => Promise<Result<Output>>;
44
+ /** The ID of the provider used for this quick action */
45
+ providerId: string;
46
+ }
47
+ /**
48
+ * Definition for a quick action - a context-sensitive action that operates on selected blocks.
49
+ */
50
+ export interface QuickActionDefinition<Q extends Record<string, any>> extends BaseActionDefinition {
51
+ /** Action type discriminator */
52
+ type: 'quick';
53
+ /** The kind of block this action operates on */
54
+ kind: OutputKind;
55
+ /**
56
+ * Defines if the quick action is enabled or not by using the
57
+ * feature api.
58
+ */
59
+ enable: boolean | ((context: {
60
+ engine: CreativeEngine;
61
+ }) => boolean);
62
+ /**
63
+ * Define the necessary scopes for this quick action.
64
+ */
65
+ scopes?: Scope[];
66
+ /**
67
+ * Overrides the defaults for this quick action.
68
+ */
69
+ defaults?: {
70
+ /** Should the generation be directly applied or does it need confirmation */
71
+ confirmation?: boolean;
72
+ /** Whether the block should be locked */
73
+ lock?: boolean;
74
+ };
75
+ /** Render function for the quick action UI */
76
+ render: (context: BuilderRenderFunctionContext<any> & QuickActionRenderContext<Q>) => void;
77
+ }
78
+ /**
79
+ * Union type of all supported action definitions.
80
+ */
81
+ export type ActionDefinition = PluginActionDefinition | QuickActionDefinition<Record<string, any>>;
82
+ /**
83
+ * Event types for ActionRegistry subscriptions.
84
+ */
85
+ export type ActionRegistryEventType = 'registered' | 'unregistered';
86
+ /**
87
+ * Callback function for ActionRegistry subscriptions.
88
+ */
89
+ export type ActionRegistrySubscriberCallback = (action: ActionDefinition, event: ActionRegistryEventType) => void;
90
+ /**
91
+ * Filters for querying and subscribing to specific types of actions.
92
+ * Used by both getBy() and subscribeBy() methods.
93
+ */
94
+ export interface ActionRegistryFilters {
95
+ /** Filter by action type */
96
+ type?: ActionDefinition['type'];
97
+ /** Filter by plugin ID */
98
+ pluginId?: string;
99
+ /** Filter by action ID */
100
+ id?: string;
101
+ /** Filter by kind (only applicable for quick actions) */
102
+ kind?: OutputKind;
103
+ }
104
+ /**
105
+ * Global registry for managing plugin actions and quick actions.
106
+ * Uses singleton pattern to ensure a single source of truth across the application.
107
+ */
108
+ export declare class ActionRegistry {
109
+ /** Map storing all registered actions by their ID */
110
+ private actions;
111
+ /** Map storing subscribers with their filters (null = subscribe to all) */
112
+ private subscribers;
113
+ private constructor();
114
+ /**
115
+ * Gets the singleton instance of the ActionRegistry.
116
+ * Uses global object storage to ensure singleton across different bundle contexts.
117
+ * @returns The ActionRegistry instance
118
+ */
119
+ static get(): ActionRegistry;
120
+ /**
121
+ * Registers an action in the registry.
122
+ * @param action The action definition to register
123
+ * @returns A disposer function that unregisters the action when called
124
+ */
125
+ register(action: ActionDefinition): () => void;
126
+ /**
127
+ * Gets all registered actions.
128
+ * @returns Array of all action definitions
129
+ */
130
+ getAll(): ActionDefinition[];
131
+ /**
132
+ * Gets actions matching the specified filters with full type safety.
133
+ * @param filters Object containing optional filters for type, pluginId, and id
134
+ * @returns Array of matching actions, typed based on the type filter
135
+ * @example
136
+ * // Get all plugin actions
137
+ * registry.getBy({ type: 'plugin' }) // Returns PluginActionDefinition[]
138
+ *
139
+ * // Get all actions from a specific plugin
140
+ * registry.getBy({ pluginId: 'ai-image-generation' }) // Returns ActionDefinition[]
141
+ *
142
+ * // Get specific action by ID
143
+ * registry.getBy({ id: 'generate-image' }) // Returns ActionDefinition[]
144
+ *
145
+ * // Combine filters
146
+ * registry.getBy({ type: 'quick', pluginId: 'ai-text' }) // Returns QuickActionDefinition[]
147
+ *
148
+ * // Filter quick actions by kind
149
+ * registry.getBy({ type: 'quick', kind: 'image' }) // Returns QuickActionDefinition[]
150
+ */
151
+ getBy<T extends ActionDefinition['type'] | undefined = undefined>(filters: {
152
+ /** Filter by action type */
153
+ type?: T;
154
+ /** Filter by plugin ID */
155
+ pluginId?: string;
156
+ /** Filter by action ID */
157
+ id?: string;
158
+ /** Filter by kind (only applicable for quick actions) */
159
+ kind?: OutputKind;
160
+ }): T extends ActionDefinition['type'] ? Extract<ActionDefinition, {
161
+ type: T;
162
+ }>[] : ActionDefinition[];
163
+ /**
164
+ * Subscribes to all registry events (register/unregister).
165
+ * @param callback Function to call when any action is registered or unregistered
166
+ * @returns Unsubscribe function
167
+ */
168
+ subscribe(callback: ActionRegistrySubscriberCallback): () => void;
169
+ /**
170
+ * Subscribes to registry events for actions matching the specified filters.
171
+ * @param filters Filters to match actions against
172
+ * @param callback Function to call when matching actions are registered or unregistered
173
+ * @returns Unsubscribe function
174
+ * @example
175
+ * // Subscribe to plugin actions only
176
+ * registry.subscribeBy({ type: 'plugin' }, (action, event) => {
177
+ * console.log(`Plugin action ${action.id} was ${event}`);
178
+ * });
179
+ *
180
+ * // Subscribe to actions from specific plugin
181
+ * registry.subscribeBy({ pluginId: 'ai-image' }, (action, event) => {
182
+ * updateUIForPlugin(action, event);
183
+ * });
184
+ */
185
+ subscribeBy(filters: ActionRegistryFilters, callback: ActionRegistrySubscriberCallback): () => void;
186
+ /**
187
+ * Notifies all relevant subscribers about an action event.
188
+ * @param action The action that was registered or unregistered
189
+ * @param event The type of event that occurred
190
+ */
191
+ private notifySubscribers;
192
+ /**
193
+ * Checks if an action matches the given filters.
194
+ * Used by both getBy() and subscribeBy() methods.
195
+ * @param action The action to check
196
+ * @param filters The filters to match against
197
+ * @returns True if the action matches all filters
198
+ */
199
+ private matchesFilters;
200
+ }
201
+ export {};
@@ -0,0 +1,40 @@
1
+ import { ProviderInitializationResult } from '../providers/initializeProvider';
2
+ import { OutputKind } from './provider';
3
+ /**
4
+ * Global registry for managing AI generation providers across all plugins.
5
+ * Uses singleton pattern to ensure cross-plugin provider discovery.
6
+ */
7
+ export declare class ProviderRegistry {
8
+ /** Map storing all registered providers by their ID */
9
+ private providers;
10
+ private constructor();
11
+ /**
12
+ * Gets the singleton instance of the ProviderRegistry.
13
+ * Uses global object storage to ensure singleton across different bundle contexts.
14
+ * @returns The ProviderRegistry instance
15
+ */
16
+ static get(): ProviderRegistry;
17
+ /**
18
+ * Registers a provider in the registry.
19
+ * @param providerInitializationResult The provider to register
20
+ * @returns A disposer function that unregisters the provider when called
21
+ */
22
+ register(providerInitializationResult: ProviderInitializationResult<any, any, any>): () => void;
23
+ /**
24
+ * Gets all registered providers.
25
+ * @returns Array of all provider instances
26
+ */
27
+ getAll(): ProviderInitializationResult<any, any, any>[];
28
+ /**
29
+ * Gets a provider by its ID.
30
+ * @param id The provider ID to look up
31
+ * @returns The provider instance or undefined if not found
32
+ */
33
+ getById(id: string): ProviderInitializationResult<any, any, any> | undefined;
34
+ /**
35
+ * Gets all providers of a specific kind.
36
+ * @param kind The output kind to filter by
37
+ * @returns Array of providers matching the specified kind
38
+ */
39
+ getByKind<K extends OutputKind>(kind: K): ProviderInitializationResult<K, any, any>[];
40
+ }
@@ -0,0 +1 @@
1
+ export declare const ABORT_REASON_USER_CANCEL = "USER_CANCEL";
@@ -1,8 +1,8 @@
1
1
  import { type OpenAPIV3 } from 'openapi-types';
2
2
  import type CreativeEditorSDK from '@cesdk/cesdk-js';
3
- import { type NotificationDuration, type BuilderRenderFunctionContext, type CreativeEngine, Scope } from '@cesdk/cesdk-js';
4
- import { GetPropertyInput, Property } from './openapi/types';
5
- import { Middleware } from './middleware/middleware';
3
+ import { type NotificationDuration, type BuilderRenderFunctionContext, type CreativeEngine } from '@cesdk/cesdk-js';
4
+ import { GetPropertyInput, Property } from '../openapi/types';
5
+ import { Middleware } from '../middleware/middleware';
6
6
  interface Provider<K extends OutputKind, I, O extends Output, C = O> {
7
7
  /**
8
8
  * Defines the kind of the generated asset. Maps to the kind
@@ -39,7 +39,10 @@ interface Provider<K extends OutputKind, I, O extends Output, C = O> {
39
39
  * Is used to generate panel content for the input.
40
40
  */
41
41
  panel?: PanelInput<K, I>;
42
- quickActions?: QuickActionsInput<I, O>;
42
+ /**
43
+ * Defines the input for the generation.
44
+ */
45
+ quickActions?: QuickActionsInput<I>;
43
46
  };
44
47
  /**
45
48
  * Defines the output of the provider, i.e. the asset gneration.
@@ -57,7 +60,7 @@ interface Provider<K extends OutputKind, I, O extends Output, C = O> {
57
60
  * - '@imgly/indexedDB': The asset is stored in the browser's indexed db. On reload, the generated assets are still available, but only in the same browser.
58
61
  * - string: Any other string is used as the asset source ID. The user has to add the asset source during initialization. This can be used for instance to store generated assets in a outside database.
59
62
  */
60
- history?: false | '@imgly/local' | '@imgly/indexedDB' | string;
63
+ history?: false | '@imgly/local' | '@imgly/indexedDB' | (string & {});
61
64
  /**
62
65
  * Configure if and what notification is shown after success and error.
63
66
  */
@@ -166,7 +169,7 @@ export type GenerationResult<O extends Output, C = O> = O | AsyncGenerator<O, C>
166
169
  * The options for the generation function.
167
170
  */
168
171
  export type GenerationOptions = {
169
- abortSignal: AbortSignal;
172
+ abortSignal?: AbortSignal;
170
173
  engine: CreativeEngine;
171
174
  cesdk?: CreativeEditorSDK;
172
175
  };
@@ -277,7 +280,7 @@ export type GetBlockInputResult<K extends OutputKind> = Record<K, InputByKind[K]
277
280
  /**
278
281
  * All possible output kinds.
279
282
  */
280
- export type OutputKind = 'image' | 'video' | 'audio' | 'text';
283
+ export type OutputKind = 'image' | 'video' | 'audio' | 'text' | 'sticker';
281
284
  /**
282
285
  * Mandatory kind-specific input needed for the generation.
283
286
  */
@@ -302,11 +305,16 @@ export type InputByKind = {
302
305
  label?: string;
303
306
  length: number;
304
307
  };
308
+ sticker: {
309
+ label?: string;
310
+ width: number;
311
+ height: number;
312
+ };
305
313
  };
306
314
  /**
307
315
  * The generated output of the provider.
308
316
  */
309
- export type Output = ImageOutput | VideoOutput | AudioOutput | TextOutput;
317
+ export type Output = ImageOutput | VideoOutput | AudioOutput | TextOutput | StickerOutput;
310
318
  type OutputBase<K extends OutputKind> = {
311
319
  kind: K;
312
320
  };
@@ -328,60 +336,32 @@ export interface TextOutput extends OutputBase<'text'> {
328
336
  kind: 'text';
329
337
  text: string;
330
338
  }
331
- export type QuickActionContext<I, O extends Output> = {
332
- blockIds: number[];
333
- closeMenu: () => void;
334
- toggleExpand: () => void;
335
- /**
336
- * Trigger generation with the given input.
337
- *
338
- * @param input The input for the generation.
339
- * @param options The options for the generation.
340
- * @param options.blockIds Use these blocks ids for the generation instead of the currently selected blocks.
341
- */
342
- generate: (input: I, options?: {
343
- blockIds?: number[];
344
- }) => Promise<O>;
339
+ export interface StickerOutput extends OutputBase<'sticker'> {
340
+ kind: 'sticker';
341
+ url: string;
342
+ }
343
+ /**
344
+ * Support mapping for a specific quick action.
345
+ * Maps quick action input to provider input.
346
+ * Allows `true` or empty object `{}` as shorthand when quick action input is compatible with provider input.
347
+ */
348
+ export type QuickActionSupport<I> = true | {
345
349
  /**
346
- * Can be called to show a notification after the generation as it is
347
- * configured for the provider.
350
+ * Map quick action input to provider input.
351
+ * @param quickActionInput The input from the quick action
352
+ * @returns The mapped input for the provider
348
353
  */
349
- handleGenerationError: (error: unknown) => void;
354
+ mapInput: (quickActionInput: any) => I;
355
+ } | {
356
+ [key: string]: any;
350
357
  };
351
- export type QuickActionsInput<I, O extends Output> = {
352
- actions: QuickAction<I, O>[];
353
- };
354
- export type QuickAction<I, O extends Output> = {
355
- id: string;
356
- /**
357
- * If set, the quick action is shown in the menu for this kind, instead
358
- * of the kind of the provider. E.g. a video provider can add a quick action,
359
- * to add a button in the image menu to generate a video from.
360
- */
361
- kind?: OutputKind;
362
- version: '1';
363
- /**
364
- * Defines if the quick action is enabled or not by using the
365
- * feature api.
366
- */
367
- enable: boolean | ((contxt: {
368
- engine: CreativeEngine;
369
- }) => boolean);
370
- /**
371
- * Define the necessary scopes for this quick action.
372
- */
373
- scopes?: Scope[];
358
+ export type QuickActionsInput<I> = {
374
359
  /**
375
- * If set to `true`, after the generation, the canvas menu
376
- * will show a confirmation UI to confirm the generation.
360
+ * Supported global quick actions with input transformations.
361
+ * Key is the quick action ID, value is the transformation mapping.
377
362
  */
378
- confirmation?: boolean;
379
- /**
380
- * If set to `true`, the selection is locked during the confirmation.
381
- * The user cannot change the selection until the confirmation is done.
382
- */
383
- lockDuringConfirmation?: boolean;
384
- render: (context: BuilderRenderFunctionContext<any>, quickActionContext: QuickActionContext<I, O>) => void;
385
- renderExpanded?: (context: BuilderRenderFunctionContext<any>, quickActionContext: QuickActionContext<I, O>) => void;
363
+ supported?: {
364
+ [quickActionId: string]: QuickActionSupport<I>;
365
+ };
386
366
  };
387
367
  export default Provider;
@@ -0,0 +1,34 @@
1
+ import { ApplyCallbacks } from '../providers/getApplyCallbacks';
2
+ export type Callbacks = {
3
+ /**
4
+ * Callbacks for the confirmation process.
5
+ */
6
+ applyCallbacks?: ApplyCallbacks;
7
+ /**
8
+ * Callback when generation is cancelled.
9
+ */
10
+ onCancelGeneration?: () => void;
11
+ };
12
+ /**
13
+ * Global registry for managing callbacks for quick action menus across different
14
+ * components.
15
+ */
16
+ export declare class CallbacksRegistry {
17
+ /** Map storing all registered callbacks by their ID */
18
+ private actions;
19
+ private constructor();
20
+ /**
21
+ * Gets the singleton instance of the CallbacksRegistry.
22
+ * Uses global object storage to ensure singleton across different bundle contexts.
23
+ */
24
+ static get(): CallbacksRegistry;
25
+ /**
26
+ * Registers apply callbacks in the registry.
27
+ */
28
+ register(blockId: number, callbacks: Partial<Callbacks>): void;
29
+ /**
30
+ * Gets the callbacks for the given block id.
31
+ */
32
+ get(blockId: number): Callbacks;
33
+ }
34
+ export default CallbacksRegistry;
@@ -0,0 +1,30 @@
1
+ import Provider, { Output, OutputKind } from '../core/provider';
2
+ import { Middleware } from '../middleware/middleware';
3
+ import CreativeEditorSDK, { CreativeEngine } from '@cesdk/cesdk-js';
4
+ export type ResultSuccess<O> = {
5
+ status: 'success';
6
+ type: 'async';
7
+ output: AsyncGenerator<O>;
8
+ } | {
9
+ status: 'success';
10
+ type: 'sync';
11
+ output: O;
12
+ };
13
+ export type Result<O> = ResultSuccess<O> | {
14
+ status: 'error';
15
+ message: string;
16
+ } | {
17
+ status: 'aborted';
18
+ };
19
+ export type Generate<I, O extends Output> = (input: I, options?: {
20
+ abortSignal?: AbortSignal;
21
+ middlewares?: Middleware<I, O>[];
22
+ debug?: boolean;
23
+ dryRun?: boolean;
24
+ }) => Promise<Result<O>>;
25
+ declare function createGenerateFunction<K extends OutputKind, I, O extends Output>(context: {
26
+ provider: Provider<K, I, O>;
27
+ cesdk: CreativeEditorSDK;
28
+ engine: CreativeEngine;
29
+ }): Generate<I, O>;
30
+ export default createGenerateFunction;
@@ -0,0 +1,50 @@
1
+ import { type GetBlockInput, OutputKind, type Output } from '../core/provider';
2
+ import { Generate, Result } from './createGenerateFunction';
3
+ import CreativeEditorSDK from '@cesdk/cesdk-js';
4
+ import { Middleware } from '../middleware/middleware';
5
+ type PanelGenerationOptions<K extends OutputKind, I, O extends Output> = {
6
+ /**
7
+ * The kind to generate.
8
+ */
9
+ kind: K;
10
+ /**
11
+ * Initialized generate function
12
+ */
13
+ generate: Generate<I, O>;
14
+ /**
15
+ * The user flow for the generation process.
16
+ */
17
+ userFlow: 'placeholder' | 'generation-only';
18
+ /**
19
+ * Function to get block input from the generated input.
20
+ */
21
+ getBlockInput: GetBlockInput<K, I>;
22
+ /**
23
+ * Asset source id of the history library where a generated asset
24
+ * will be added.
25
+ */
26
+ historyAssetSourceId?: string;
27
+ /**
28
+ * Additional middlewares added to the generation process.
29
+ */
30
+ middlewares?: Middleware<I, O>[];
31
+ /**
32
+ * Print debug information to the console.
33
+ */
34
+ debug?: boolean;
35
+ /**
36
+ * Enable dry run mode for testing.
37
+ */
38
+ dryRun?: boolean;
39
+ /**
40
+ * Signal to check if process was aborted.
41
+ */
42
+ abortSignal: AbortSignal;
43
+ cesdk: CreativeEditorSDK;
44
+ };
45
+ /**
46
+ * Handler for generating content from a panel interface.
47
+ * Creates placeholder blocks and manages the generation process.
48
+ */
49
+ declare function handleGenerateFromPanel<K extends OutputKind, I, O extends Output>(options: PanelGenerationOptions<K, I, O>): (input: I) => Promise<Result<O>>;
50
+ export default handleGenerateFromPanel;
@@ -0,0 +1,56 @@
1
+ import { QuickActionDefinition } from '../core/ActionRegistry';
2
+ import { Result } from './createGenerateFunction';
3
+ import { ProviderInitializationResult } from '../providers/initializeProvider';
4
+ import { Middleware } from '../middleware/middleware';
5
+ import { Output, OutputKind } from '../core/provider';
6
+ import CreativeEditorSDK from '@cesdk/cesdk-js';
7
+ type GenerationOptions<Q extends Record<string, any>, K extends OutputKind, I, O extends Output> = {
8
+ /**
9
+ * The blocks that this quick action is running on.
10
+ */
11
+ blockIds: number[];
12
+ /**
13
+ * The initlaized provider that is used to generate the output.
14
+ */
15
+ providerInitializationResult?: ProviderInitializationResult<K, I, O>;
16
+ /**
17
+ * The quick action definition that is used to generate input for the provider
18
+ */
19
+ quickAction: QuickActionDefinition<Q>;
20
+ /**
21
+ * Shall the generation be confirmed before applying the result? Or directly applied?
22
+ */
23
+ confirmation?: boolean;
24
+ /**
25
+ * Should the blocks be locked to edit mode while the generation is running?
26
+ */
27
+ lock?: boolean;
28
+ /**
29
+ * Additional middlewares added to the generation process.
30
+ */
31
+ middlewares?: Middleware<I, O>[];
32
+ /**
33
+ * Print debug information to the console.
34
+ */
35
+ debug?: boolean;
36
+ /**
37
+ * Enable dry run mode for testing.
38
+ */
39
+ dryRun?: boolean;
40
+ /**
41
+ * Signal to check if process was aborted
42
+ */
43
+ abortSignal?: AbortSignal;
44
+ /**
45
+ * Close the quick action menu
46
+ */
47
+ close: () => void;
48
+ cesdk: CreativeEditorSDK;
49
+ };
50
+ /**
51
+ * Handler for generating output from a quick action.
52
+ */
53
+ declare function handleGenerateFromQuickAction<Q extends Record<string, any>, K extends OutputKind, I, O extends Output>(options: GenerationOptions<Q, K, I, O>): (input: Q, generateOptions?: {
54
+ blockIds?: number[];
55
+ }) => Promise<Result<O>>;
56
+ export default handleGenerateFromQuickAction;
@@ -1,9 +1,8 @@
1
1
  import CreativeEditorSDK from '@cesdk/cesdk-js';
2
- import Provider, { GetInput, Output, OutputKind } from './provider';
3
- import { InitProviderConfiguration } from './types';
2
+ import Provider, { GetInput, Output, OutputKind } from '../core/provider';
4
3
  declare function handleGenerationError<K extends OutputKind, I, O extends Output>(error: unknown, options: {
5
4
  cesdk: CreativeEditorSDK;
6
5
  provider: Provider<K, I, O>;
7
6
  getInput?: GetInput<I>;
8
- }, config: InitProviderConfiguration): void;
7
+ }): void;
9
8
  export default handleGenerationError;