@kittl/sdk 0.0.1 → 0.0.2

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.
@@ -9,6 +9,9 @@ var isSDKResponseMessage = (data) => {
9
9
  var isStatelessPushMessage = (data) => {
10
10
  return typeof data === "object" && data !== null && "command" in data && data.command === "stateless-message" && "type" in data && typeof data.type === "string" && "payload" in data && typeof data.payload === "object" && data.payload !== null;
11
11
  };
12
+ var isAIGenerationUpdatePushMessage = (data) => {
13
+ return typeof data === "object" && data !== null && "command" in data && data.command === "ai-generation-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "update" in data && typeof data.update === "object" && data.update !== null;
14
+ };
12
15
 
13
16
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
14
17
  var buildMethodPath = (rootPrefix, pathSegments) => {
@@ -117,8 +120,11 @@ var generateMessageId = () => {
117
120
  }
118
121
  return Math.random().toString(36).substring(7);
119
122
  };
120
- var sendMessage = (message) => {
123
+ var postMessageToParent = (message) => {
121
124
  window.parent.postMessage(message, getParentDomain());
125
+ };
126
+ var sendMessage = (message) => {
127
+ postMessageToParent(message);
122
128
  return new Promise((resolve, reject) => {
123
129
  pendingRequests.set(message.messageId, {
124
130
  resolve: (value) => {
@@ -134,7 +140,7 @@ var sendLoaded = () => {
134
140
  return;
135
141
  }
136
142
  const message = { command: "loaded" };
137
- parent.postMessage(message, getParentDomain());
143
+ postMessageToParent(message);
138
144
  };
139
145
 
140
146
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/index.js
@@ -197,6 +203,14 @@ function createApiProxy(apiType) {
197
203
  }
198
204
 
199
205
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/aiApiProxy.js
206
+ var generationHandlers = /* @__PURE__ */ new Map();
207
+ var dispatchAIGenerationUpdate = (subscriptionId, update) => {
208
+ const handler = generationHandlers.get(subscriptionId);
209
+ if (!handler) {
210
+ return;
211
+ }
212
+ void handler(update);
213
+ };
200
214
  function createAIApiProxy() {
201
215
  return {
202
216
  spendCredits: async (options) => {
@@ -215,6 +229,51 @@ function createAIApiProxy() {
215
229
  onDecline?.();
216
230
  }
217
231
  return response;
232
+ },
233
+ startGeneration: (generatorId, inputSettings, output) => {
234
+ const message = {
235
+ command: "sdk-call",
236
+ dots: ["startGeneration"],
237
+ args: [generatorId, inputSettings, output],
238
+ messageId: generateMessageId(),
239
+ apiType: "ai"
240
+ };
241
+ return sendMessage(message);
242
+ },
243
+ registerHandler: async (generatorId, onStatusUpdate) => {
244
+ const subscriptionId = generateMessageId();
245
+ const unregister = () => {
246
+ generationHandlers.delete(subscriptionId);
247
+ const unregisterMessage = {
248
+ command: "ai-unregister-handler",
249
+ subscriptionId
250
+ };
251
+ postMessageToParent(unregisterMessage);
252
+ };
253
+ generationHandlers.set(subscriptionId, onStatusUpdate);
254
+ const registerMessage = {
255
+ command: "ai-register-handler",
256
+ messageId: generateMessageId(),
257
+ generatorId,
258
+ subscriptionId
259
+ };
260
+ try {
261
+ const response = await sendMessage(registerMessage);
262
+ if (!response.isOk) {
263
+ generationHandlers.delete(subscriptionId);
264
+ return response;
265
+ }
266
+ return { isOk: true, result: unregister };
267
+ } catch {
268
+ generationHandlers.delete(subscriptionId);
269
+ return {
270
+ isOk: false,
271
+ error: {
272
+ message: "Failed to register AI handler",
273
+ name: "SdkInternalError"
274
+ }
275
+ };
276
+ }
218
277
  }
219
278
  };
220
279
  }
@@ -385,6 +444,10 @@ var handleIncomingMessage = (event) => {
385
444
  statelessApi.dispatch(data.type, data.payload);
386
445
  return;
387
446
  }
447
+ if (isAIGenerationUpdatePushMessage(data)) {
448
+ dispatchAIGenerationUpdate(data.subscriptionId, data.update);
449
+ return;
450
+ }
388
451
  };
389
452
  var bridgeHandlers = {
390
453
  ai: createAIApiProxy(),
package/dist/kittl-sdk.js CHANGED
@@ -10,6 +10,9 @@
10
10
  var isStatelessPushMessage = (data) => {
11
11
  return typeof data === "object" && data !== null && "command" in data && data.command === "stateless-message" && "type" in data && typeof data.type === "string" && "payload" in data && typeof data.payload === "object" && data.payload !== null;
12
12
  };
13
+ var isAIGenerationUpdatePushMessage = (data) => {
14
+ return typeof data === "object" && data !== null && "command" in data && data.command === "ai-generation-update" && "subscriptionId" in data && typeof data.subscriptionId === "string" && "update" in data && typeof data.update === "object" && data.update !== null;
15
+ };
13
16
 
14
17
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/shared/createApiProxyCore.js
15
18
  var buildMethodPath = (rootPrefix, pathSegments) => {
@@ -118,8 +121,11 @@
118
121
  }
119
122
  return Math.random().toString(36).substring(7);
120
123
  };
121
- var sendMessage = (message) => {
124
+ var postMessageToParent = (message) => {
122
125
  window.parent.postMessage(message, getParentDomain());
126
+ };
127
+ var sendMessage = (message) => {
128
+ postMessageToParent(message);
123
129
  return new Promise((resolve, reject) => {
124
130
  pendingRequests.set(message.messageId, {
125
131
  resolve: (value) => {
@@ -135,7 +141,7 @@
135
141
  return;
136
142
  }
137
143
  const message = { command: "loaded" };
138
- parent.postMessage(message, getParentDomain());
144
+ postMessageToParent(message);
139
145
  };
140
146
 
141
147
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/index.js
@@ -198,6 +204,14 @@
198
204
  }
199
205
 
200
206
  // ../../packages/editor-core/sdk/sdk-bridge/dist/bridge/sandboxed/handlers/apiProxy/aiApiProxy.js
207
+ var generationHandlers = /* @__PURE__ */ new Map();
208
+ var dispatchAIGenerationUpdate = (subscriptionId, update) => {
209
+ const handler = generationHandlers.get(subscriptionId);
210
+ if (!handler) {
211
+ return;
212
+ }
213
+ void handler(update);
214
+ };
201
215
  function createAIApiProxy() {
202
216
  return {
203
217
  spendCredits: async (options) => {
@@ -216,6 +230,51 @@
216
230
  onDecline?.();
217
231
  }
218
232
  return response;
233
+ },
234
+ startGeneration: (generatorId, inputSettings, output) => {
235
+ const message = {
236
+ command: "sdk-call",
237
+ dots: ["startGeneration"],
238
+ args: [generatorId, inputSettings, output],
239
+ messageId: generateMessageId(),
240
+ apiType: "ai"
241
+ };
242
+ return sendMessage(message);
243
+ },
244
+ registerHandler: async (generatorId, onStatusUpdate) => {
245
+ const subscriptionId = generateMessageId();
246
+ const unregister = () => {
247
+ generationHandlers.delete(subscriptionId);
248
+ const unregisterMessage = {
249
+ command: "ai-unregister-handler",
250
+ subscriptionId
251
+ };
252
+ postMessageToParent(unregisterMessage);
253
+ };
254
+ generationHandlers.set(subscriptionId, onStatusUpdate);
255
+ const registerMessage = {
256
+ command: "ai-register-handler",
257
+ messageId: generateMessageId(),
258
+ generatorId,
259
+ subscriptionId
260
+ };
261
+ try {
262
+ const response = await sendMessage(registerMessage);
263
+ if (!response.isOk) {
264
+ generationHandlers.delete(subscriptionId);
265
+ return response;
266
+ }
267
+ return { isOk: true, result: unregister };
268
+ } catch {
269
+ generationHandlers.delete(subscriptionId);
270
+ return {
271
+ isOk: false,
272
+ error: {
273
+ message: "Failed to register AI handler",
274
+ name: "SdkInternalError"
275
+ }
276
+ };
277
+ }
219
278
  }
220
279
  };
221
280
  }
@@ -386,6 +445,10 @@
386
445
  statelessApi.dispatch(data.type, data.payload);
387
446
  return;
388
447
  }
448
+ if (isAIGenerationUpdatePushMessage(data)) {
449
+ dispatchAIGenerationUpdate(data.subscriptionId, data.update);
450
+ return;
451
+ }
389
452
  };
390
453
  var bridgeHandlers = {
391
454
  ai: createAIApiProxy(),
package/dist/sdk.d.ts CHANGED
@@ -193,6 +193,12 @@ declare const GUIDE_DEFAULT_VALUES: {
193
193
  version: string;
194
194
  type: ObjectType.Guide;
195
195
  };
196
+ declare const GenerationStatus: {
197
+ readonly CREATED: "CREATED";
198
+ readonly STARTED: "STARTED";
199
+ readonly COMPLETE: "COMPLETE";
200
+ readonly FAILED: "FAILED";
201
+ };
196
202
  declare const ILLUSTRATION_DEFAULT_VALUES: {
197
203
  hiddenColors?: Record<string, NonNullable<Color>> | undefined;
198
204
  clipPathMaskId?: string | undefined | null;
@@ -349,6 +355,11 @@ declare const RICH_TEXT_DEFAULT_VALUES: {
349
355
  version: string;
350
356
  type: ObjectType.RichText;
351
357
  };
358
+ declare const ResultType: {
359
+ readonly VIDEO: "video";
360
+ readonly IMAGE: "image";
361
+ readonly ERROR: "error";
362
+ };
352
363
  declare const backgroundType = "background";
353
364
  declare const clippingMaskType = "clippingMask";
354
365
  declare const pathType = "path";
@@ -523,8 +534,22 @@ declare global {
523
534
  }
524
535
  }
525
536
  export declare const kittl: KittlSDK;
526
- export interface AIAPI {
527
- spendCredits: (options: SpendCreditsOptions) => SdkResultAsync<SpendCreditsResult, Error>;
537
+ export interface AIGenerationInputSettings {
538
+ prompt: string;
539
+ taskType?: AIGenerationModelTaskType;
540
+ promptStyleId?: number;
541
+ model: {
542
+ id: string;
543
+ };
544
+ additionalParams?: Record<string, unknown>;
545
+ type: AIGenerationContentType;
546
+ }
547
+ export interface AIGenerationOutputSettings {
548
+ id?: string;
549
+ dimensions: {
550
+ width: number;
551
+ height: number;
552
+ };
528
553
  }
529
554
  export interface AppStateAPI {
530
555
  getSelectedObjectsIds(): string[];
@@ -546,7 +571,10 @@ export interface AppStateAPI {
546
571
  setHighlightedObjectId(id: string | null): void;
547
572
  setMany(fields: Partial<AppState>, origin?: Origin): void;
548
573
  }
549
- export interface AsyncAIAPI extends WithAsync<AIAPI> {
574
+ export interface AsyncAIAPI {
575
+ spendCredits: (options: SpendCreditsOptions) => SdkResultAsync<SpendCreditsResult, Error>;
576
+ startGeneration: (generatorId: string, inputSettings: AIGenerationInputSettings, output: AIGenerationOutputSettings) => SdkResultAsync<StartGenerationResult, Error>;
577
+ registerHandler: (generatorId: string, onStatusUpdate: OnGenerationStatusUpdate) => SdkResultAsync<() => void, Error>;
550
578
  }
551
579
  export interface AsyncAppStateAPI extends WithAsync<AppStateAPI> {
552
580
  }
@@ -746,6 +774,11 @@ export interface DragAndDropStartDragImageEventInput {
746
774
  img: HTMLImageElement;
747
775
  persistImage?: boolean;
748
776
  }
777
+ export interface ErrorGenerationResult {
778
+ type: typeof ResultType.ERROR;
779
+ message: string;
780
+ code?: string;
781
+ }
749
782
  export interface FontAPI {
750
783
  createFont: (params: {
751
784
  name: string;
@@ -771,10 +804,22 @@ export interface GeneratableObject {
771
804
  generatorKey: string;
772
805
  };
773
806
  }
807
+ export interface GenerationInputData {
808
+ prompt?: string;
809
+ style?: {
810
+ id: number;
811
+ };
812
+ model?: {
813
+ id: string;
814
+ };
815
+ }
774
816
  export interface GenerationMeta {
775
817
  generationEndsAt?: number;
776
818
  pendingGenerationId: string;
777
819
  }
820
+ export interface GenerationStartedResultCommonProps {
821
+ generationEndsAt?: number;
822
+ }
778
823
  export interface GetExportOptions {
779
824
  format: "png" | "jpg" | "pdf" | "svg" | "mp4";
780
825
  target: {
@@ -853,6 +898,13 @@ export interface ImageAPI {
853
898
  addImage(params: AddImageParams, opts?: DesignApiOptions): SdkResultAsync<NormalizedIllustrationImageObject, SdkError>;
854
899
  updateImage(params: UpdateImageParams, opts?: DesignApiOptions): NormalizedIllustrationImageObject;
855
900
  }
901
+ export interface ImageGenerationResult {
902
+ type: typeof ResultType.IMAGE;
903
+ objectName: string;
904
+ }
905
+ export interface ImageGenerationStartedResult extends GenerationStartedResultCommonProps {
906
+ type: typeof ResultType.IMAGE;
907
+ }
856
908
  export interface KittlContext {
857
909
  dragAndDrop: {
858
910
  offset: DragAndDropOffset;
@@ -1003,8 +1055,12 @@ export interface SpendCreditsResult {
1003
1055
  }
1004
1056
  export interface StandardArtboardOptions extends BaseStandardArtboardOptions<ObjectType.Artboard> {
1005
1057
  }
1058
+ export interface StartGenerationResult {
1059
+ generationId: string;
1060
+ }
1006
1061
  export interface StateAPI {
1007
1062
  implementSubState(params: Partial<NormalizedDesignState>, opts?: DesignApiOptions): Partial<NormalizedDesignState>;
1063
+ getState(): NormalizedDesignState;
1008
1064
  }
1009
1065
  export interface StructureObjectMeta {
1010
1066
  name?: string;
@@ -1077,6 +1133,17 @@ export interface VideoAPI {
1077
1133
  removePlaylistItem(params: RemoveVideoPlaylistItemParams, opts?: DesignApiOptions): NormalizedVideoObject;
1078
1134
  updatePlaylistItem(params: UpdateVideoPlaylistItemParams, opts?: DesignApiOptions): Promise<NormalizedVideoObject>;
1079
1135
  }
1136
+ export interface VideoGenerationResult {
1137
+ type: typeof ResultType.VIDEO;
1138
+ status: "PROCESSING" | "READY" | "FAILED";
1139
+ playbackId?: string;
1140
+ duration?: number;
1141
+ aspectRatio?: string;
1142
+ hostingProvider?: "MUX";
1143
+ }
1144
+ export interface VideoGenerationStartedResult extends GenerationStartedResultCommonProps {
1145
+ type: typeof ResultType.VIDEO;
1146
+ }
1080
1147
  export interface VideoboardAPI {
1081
1148
  addVideoboard(params: AddVideoboardParams, opts?: DesignApiOptions): Promise<NormalizedStandardBoard<VideoboardOptions>>;
1082
1149
  setVideoOnVideoboard(params: SetVideoOnVideoboardParams, opts?: DesignApiOptions): Promise<NormalizedStandardBoard<VideoboardOptions>>;
@@ -1101,6 +1168,8 @@ export interface WithObjectLayout {
1101
1168
  flipX: boolean;
1102
1169
  flipY: boolean;
1103
1170
  }
1171
+ export type AIGenerationContentType = "image" | "video";
1172
+ export type AIGenerationModelTaskType = "IMAGE_TO_IMAGE" | "IMAGE_INPAINT" | "TEXT_TO_IMAGE" | "IMAGE_TO_VIDEO";
1104
1173
  export type APIOptions<T extends Record<string, unknown>> = {
1105
1174
  batchClient?: BatchClient<T>;
1106
1175
  } | {
@@ -1297,6 +1366,28 @@ export type FullColor = {
1297
1366
  visible: boolean;
1298
1367
  };
1299
1368
  export type FunctionType = (...args: never) => unknown;
1369
+ export type GenerationStatus = (typeof GenerationStatus)[keyof typeof GenerationStatus];
1370
+ export type GenerationStatusUpdate = {
1371
+ generationId: string;
1372
+ status: typeof GenerationStatus.CREATED;
1373
+ inputData: undefined;
1374
+ result: undefined;
1375
+ } | {
1376
+ generationId: string;
1377
+ status: typeof GenerationStatus.STARTED;
1378
+ inputData: GenerationInputData;
1379
+ result: StartedGenerationResult;
1380
+ } | {
1381
+ generationId: string;
1382
+ status: typeof GenerationStatus.COMPLETE;
1383
+ inputData: GenerationInputData;
1384
+ result: SuccessGenerationResult;
1385
+ } | {
1386
+ generationId: string;
1387
+ status: typeof GenerationStatus.FAILED;
1388
+ inputData: GenerationInputData | undefined;
1389
+ result: ErrorGenerationResult;
1390
+ };
1300
1391
  export type GuideSerializedObject = typeof GUIDE_DEFAULT_VALUES & OrientationDir;
1301
1392
  export type ID = string;
1302
1393
  export type IllustrationImageSerializedObject = typeof DEFAULT_VALUES$1 & {
@@ -1439,6 +1530,7 @@ export type NormalizedVideoObject = Normalized<VideoSerializedObject>;
1439
1530
  export type NullablePathTextShadowOptions = PathTextShadowOptions | {
1440
1531
  type: null;
1441
1532
  };
1533
+ export type OnGenerationStatusUpdate = (update: GenerationStatusUpdate) => void | Promise<void>;
1442
1534
  export type OrientationConditional = {
1443
1535
  orientation: Orientation.HORIZONTAL;
1444
1536
  top: number;
@@ -1541,6 +1633,7 @@ export type RenameParams = {
1541
1633
  objectId: string;
1542
1634
  newName: string;
1543
1635
  };
1636
+ export type ResultType = (typeof ResultType)[keyof typeof ResultType];
1544
1637
  export type RichTextBasePluginSerializedObject = {
1545
1638
  id: string;
1546
1639
  name: string;
@@ -1666,6 +1759,7 @@ export type SmartboardOptions = ConnectedArtboardOptions<ObjectType.Smartboard>
1666
1759
  } & GeneratableBoard<SmartboardGenerationSettings>;
1667
1760
  export type SmartboardQuality = "auto" | "high" | "medium" | "low";
1668
1761
  export type StandardSerializedObject = BasicShapeSerializedObject | CombinedShapeSerializedObject | IllustrationImageSerializedObject | IllustrationSerializedObject | LoadingCardSerializedObject | MaskSerializedObject | MockupDesignSerializedObject | PathTextSerializedObject | RichTextSerializedObject | VideoSerializedObject;
1762
+ export type StartedGenerationResult = VideoGenerationStartedResult | ImageGenerationStartedResult;
1669
1763
  export type StateGradientInfo = {
1670
1764
  [key: string]: GradientInfo;
1671
1765
  };
@@ -1676,6 +1770,7 @@ export type StringColor = {
1676
1770
  };
1677
1771
  export type StringColorKeysType = (typeof stringColorKeys)[number];
1678
1772
  export type StructureObjectId = string;
1773
+ export type SuccessGenerationResult = VideoGenerationResult | ImageGenerationResult;
1679
1774
  export type TempUserImageUpload = {
1680
1775
  objectId: string;
1681
1776
  mimeType: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kittl/sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "Apache-2.0",
5
5
  "private": false,
6
6
  "type": "module",