@imgly/plugin-ai-generation-web 1.79.0 → 1.80.0-hotfix-mcp.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.
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Typed representation of a failed IMG.LY gateway request.
3
+ *
4
+ * The gateway answers every failure with a single JSON envelope:
5
+ *
6
+ * ```json
7
+ * { "error": { "code": "insufficient_credits", "message": "Insufficient credits" } }
8
+ * ```
9
+ *
10
+ * Provider-originated failures add two more fields:
11
+ *
12
+ * ```json
13
+ * { "error": { "code": "upstream_error", "message": "Rate limit exceeded",
14
+ * "provider": "fal.ai", "upstream_status": 429 } }
15
+ * ```
16
+ *
17
+ * This module turns that envelope into an `Error` subclass so callers can branch
18
+ * on `code` instead of pattern-matching a message string.
19
+ */
20
+ /**
21
+ * Machine-readable failure reason reported by the gateway.
22
+ *
23
+ * The listed members mirror the gateway's own error catalog, but the type stays
24
+ * open on purpose: the gateway may introduce codes before this package is
25
+ * updated, and a closed union would silently mistype them.
26
+ *
27
+ * Two members are client-side sentinels rather than gateway codes: `'unknown'`
28
+ * when no code could be determined (unparseable body, non-gateway origin such as
29
+ * the presigned upload URL), and `'network_error'` when the request never
30
+ * produced a readable response at all.
31
+ */
32
+ export type GatewayErrorCode = 'network_error' | 'insufficient_credits' | 'unauthorized' | 'provider_not_authorized' | 'invalid_request' | 'invalid_model_id' | 'validation_error' | 'provider_not_supported' | 'model_not_found' | 'provider_unavailable' | 'upstream_error' | 'generation_failed' | 'timeout' | 'internal_error' | 'service_error' | 'unknown' | (string & {});
33
+ /** Which gateway interaction failed. */
34
+ export type GatewayOperation = 'schema' | 'upload' | 'generate';
35
+ export interface GatewayErrorInit {
36
+ code: GatewayErrorCode;
37
+ status: number;
38
+ operation: GatewayOperation;
39
+ /** Message reported by the gateway, used to build the developer-facing text. */
40
+ detail?: string;
41
+ provider?: string;
42
+ upstreamStatus?: number;
43
+ requestId?: string;
44
+ }
45
+ export declare class GatewayError extends Error {
46
+ /** Machine-readable failure reason. Prefer this over parsing `message`. */
47
+ readonly code: GatewayErrorCode;
48
+ /**
49
+ * HTTP status of the failed response. `0` when there is no status: a failure
50
+ * reported inside an already-open SSE stream, or a request that never reached
51
+ * the gateway (`network_error`).
52
+ */
53
+ readonly status: number;
54
+ /** Which gateway interaction failed. */
55
+ readonly operation: GatewayOperation;
56
+ /** Upstream model provider, present only for `upstream_error`. */
57
+ readonly provider?: string;
58
+ /** Status the upstream provider returned, present only for `upstream_error`. */
59
+ readonly upstreamStatus?: number;
60
+ /**
61
+ * Gateway request id. Include this when reporting a problem to support.
62
+ *
63
+ * Only present when the gateway makes it reachable: `x-request-id` is not a
64
+ * CORS-safelisted response header, so a cross-origin gateway must send
65
+ * `Access-Control-Expose-Headers: x-request-id` for the header to be readable
66
+ * — otherwise the id has to travel in the error body as `request_id`.
67
+ */
68
+ readonly requestId?: string;
69
+ constructor(init: GatewayErrorInit);
70
+ }
71
+ /**
72
+ * Narrows an unknown thrown value to a `GatewayError`.
73
+ *
74
+ * Uses a structural check rather than `instanceof` so it keeps working when the
75
+ * plugin packages are bundled separately and end up with distinct copies of this
76
+ * module.
77
+ */
78
+ export declare function isGatewayError(error: unknown): error is GatewayError;
79
+ /**
80
+ * Builds a `GatewayError` from a non-OK response.
81
+ *
82
+ * Consumes the response body, so call this only once per response.
83
+ */
84
+ export declare function gatewayErrorFromResponse(response: Response, operation: GatewayOperation): Promise<GatewayError>;
85
+ /**
86
+ * Builds a `GatewayError` for a request that never produced a readable response.
87
+ *
88
+ * `fetch` rejects instead of resolving when the request did not complete at all:
89
+ * the client is offline, DNS or TLS failed, the gateway is unreachable — or the
90
+ * browser blocked the response because it carried no CORS headers. The last case
91
+ * is indistinguishable from the others by design (the browser withholds the
92
+ * details) and is the most likely one in production, since an error page served
93
+ * by an edge proxy in front of the gateway will not add
94
+ * `Access-Control-Allow-Origin`. Whatever the cause, the failure is not a
95
+ * generation failure, and telling the user to try generating again is the wrong
96
+ * advice — so it gets its own code and its own copy.
97
+ */
98
+ export declare function gatewayNetworkError(reason: unknown, operation: GatewayOperation): GatewayError;
@@ -0,0 +1,29 @@
1
+ import type { NotificationDuration } from '@cesdk/cesdk-js';
2
+ /**
3
+ * Translation key shown when nothing more specific applies. Also the documented
4
+ * fallback inside `handleGenerationError`.
5
+ */
6
+ export declare const GENERIC_FAILURE_KEY = "common.ai-generation.failed";
7
+ /**
8
+ * Picks the translation key for a failed generation.
9
+ *
10
+ * Non-gateway errors fall through to the generic key rather than surfacing
11
+ * their raw message, which is usually a third-party string.
12
+ */
13
+ export declare function getGatewayErrorMessageKey(error: unknown): string;
14
+ /**
15
+ * Default `output.notification.error` configuration for gateway providers.
16
+ *
17
+ * Integrators who want different copy, or an action button pointing at their
18
+ * own billing page, add an error-handling middleware — see the "Custom Error
19
+ * Handling Middleware" section of the AI integration guide. A middleware can
20
+ * call `options.preventDefault()` to suppress this notification entirely.
21
+ */
22
+ export declare function createGatewayErrorNotification<I>(): {
23
+ show: true;
24
+ message: (context: {
25
+ input?: I;
26
+ error: unknown;
27
+ }) => string;
28
+ duration: NotificationDuration;
29
+ };
@@ -1,3 +1,4 @@
1
1
  export { createGatewayProvider } from './createGatewayProvider';
2
2
  export { createGatewayClient, type GatewayClient } from './createGatewayClient';
3
+ export { GatewayError, isGatewayError, type GatewayErrorCode, type GatewayOperation } from './GatewayError';
3
4
  export type { GatewayCapability, GatewayProviderConfiguration, GatewayProviderOptions, GatewayInput, GatewaySchemaResult, GatewaySSEOutput, GatewaySSECompletedData, GatewaySSEDeltaData, GatewaySSEFailedData, GatewayUploadResult } from './types';
@@ -211,6 +211,16 @@ export interface GatewaySSEFailedData {
211
211
  status: 'failed';
212
212
  error: {
213
213
  message: string;
214
+ /**
215
+ * Same catalog as the HTTP error envelope. Optional because the gateway does
216
+ * not put it on every failed event yet — without it the client can report
217
+ * that the generation failed, but not why.
218
+ */
219
+ code?: string;
220
+ /** Upstream model provider, for provider-originated failures. */
221
+ provider?: string;
222
+ /** Status the upstream provider returned. */
223
+ upstream_status?: number;
214
224
  };
215
225
  }
216
226
  export interface GatewaySSEDeltaData {
@@ -15,6 +15,12 @@ export type ResultSuccess<O> = {
15
15
  export type Result<O> = ResultSuccess<O> | {
16
16
  status: 'error';
17
17
  message: string;
18
+ /**
19
+ * The value that was thrown, preserved so consumers can inspect it
20
+ * instead of pattern-matching `message`. Gateway failures carry a
21
+ * `GatewayError` here — narrow it with `isGatewayError`.
22
+ */
23
+ error?: unknown;
18
24
  middlewareOptions?: GenerationOptions;
19
25
  } | {
20
26
  status: 'aborted';
package/dist/index.d.ts CHANGED
@@ -31,5 +31,6 @@ export { extractAndSetSchemaTranslations } from './openapi/extractSchemaTranslat
31
31
  export { AI_EDIT_MODE, AI_METADATA_KEY } from './ui/quickActions/utils';
32
32
  export { createGatewayProvider } from './gateway/createGatewayProvider';
33
33
  export { createGatewayClient, type GatewayClient } from './gateway/createGatewayClient';
34
+ export { GatewayError, isGatewayError, type GatewayErrorCode, type GatewayOperation } from './gateway/GatewayError';
34
35
  export type { GatewayProviderConfiguration, GatewayProviderOptions, GatewayInput, GatewaySchemaResult, GatewaySSEOutput, GatewaySSECompletedData, GatewaySSEDeltaData, GatewaySSEFailedData, GatewayUploadResult, GatewayTokenActionResult } from './gateway/types';
35
36
  export { setDefaultTranslations, createTranslationCallback, buildTranslationKeys } from './utils/translationHelpers';