@imgly/plugin-ai-generation-web 0.2.8 → 0.2.9

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.
@@ -174,9 +174,57 @@ export type GenerationResult<O extends Output, C = O> = O | AsyncGenerator<O, C>
174
174
  * The options for the generation function.
175
175
  */
176
176
  export type GenerationOptions = {
177
+ /**
178
+ * The block IDs that this generation is operating on.
179
+ * Middleware can use this to target specific blocks.
180
+ * - undefined: Middleware typically fall back to selected blocks
181
+ * - []: Explicitly target no blocks
182
+ * - [1, 2, 3]: Target specific blocks
183
+ *
184
+ * Note: This is passed through to middleware but not required by provider implementations.
185
+ */
186
+ blockIds?: number[];
177
187
  abortSignal?: AbortSignal;
178
188
  engine: CreativeEngine;
179
189
  cesdk?: CreativeEditorSDK;
190
+ /**
191
+ * Prevents default UI feedback behaviors for this generation.
192
+ *
193
+ * **What gets prevented:**
194
+ * - Error/success notifications
195
+ * - Block error state
196
+ * - Console error logging
197
+ *
198
+ * **What is NOT prevented (always happens):**
199
+ * - Pending → Ready block state transition (loading spinner always stops)
200
+ * - Block validity checks
201
+ * - Middleware execution flow
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * catch (error) {
206
+ * options.preventDefault();
207
+ * myCustomErrorHandler(error);
208
+ * throw error;
209
+ * }
210
+ * ```
211
+ */
212
+ preventDefault(): void;
213
+ /**
214
+ * Check if default behaviors have been prevented.
215
+ *
216
+ * @returns `true` if preventDefault() was called
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * if (!options.defaultPrevented()) {
221
+ * // Show default notification
222
+ * }
223
+ * ```
224
+ *
225
+ * @internal
226
+ */
227
+ defaultPrevented(): boolean;
180
228
  };
181
229
  export type RenderCustomProperty = {
182
230
  [key: string]: (context: BuilderRenderFunctionContext<any>, property: Property) => GetPropertyInput;
@@ -1,22 +1,33 @@
1
- import Provider, { Output, OutputKind } from '../core/provider';
1
+ import Provider, { GenerationOptions, Output, OutputKind } from '../core/provider';
2
2
  import { Middleware } from '../middleware/middleware';
3
3
  import CreativeEditorSDK, { CreativeEngine } from '@cesdk/cesdk-js';
4
4
  export type ResultSuccess<O> = {
5
5
  status: 'success';
6
6
  type: 'async';
7
7
  output: AsyncGenerator<O>;
8
+ middlewareOptions?: GenerationOptions;
8
9
  } | {
9
10
  status: 'success';
10
11
  type: 'sync';
11
12
  output: O;
13
+ middlewareOptions?: GenerationOptions;
12
14
  };
13
15
  export type Result<O> = ResultSuccess<O> | {
14
16
  status: 'error';
15
17
  message: string;
18
+ middlewareOptions?: GenerationOptions;
16
19
  } | {
17
20
  status: 'aborted';
21
+ middlewareOptions?: GenerationOptions;
18
22
  };
19
23
  export type Generate<I, O extends Output> = (input: I, options?: {
24
+ /**
25
+ * The block IDs that this generation is operating on.
26
+ * - undefined: Middleware will fall back to selected blocks
27
+ * - []: Explicitly target no blocks
28
+ * - [1, 2, 3]: Target specific blocks (e.g., placeholder block)
29
+ */
30
+ blockIds?: number[];
20
31
  abortSignal?: AbortSignal;
21
32
  middlewares?: Middleware<I, O>[];
22
33
  debug?: boolean;
@@ -1,8 +1,9 @@
1
1
  import CreativeEditorSDK from '@cesdk/cesdk-js';
2
- import Provider, { GetInput, Output, OutputKind } from '../core/provider';
2
+ import Provider, { GenerationOptions, GetInput, Output, OutputKind } from '../core/provider';
3
3
  declare function handleGenerationError<K extends OutputKind, I, O extends Output>(error: unknown, options: {
4
4
  cesdk: CreativeEditorSDK;
5
5
  provider: Provider<K, I, O>;
6
6
  getInput?: GetInput<I>;
7
+ middlewareOptions?: GenerationOptions;
7
8
  }): void;
8
9
  export default handleGenerationError;