@picsart/ai-sdk 7.46.0 → 7.48.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.
package/README.md CHANGED
@@ -257,6 +257,24 @@ const credits = await ai.getCredits(modelId, { prompt }, { serviceTier: 'priorit
257
257
 
258
258
  Left unset, the option is not sent and the platform applies `auto`.
259
259
 
260
+ ## Completion Notifications
261
+
262
+ `notification` asks the platform to notify the user when a generation finishes,
263
+ for example by email once they have left the page, for tools that have
264
+ notifications set up. It is a `submit()` option only.
265
+
266
+ ```typescript
267
+ await ai.submit(modelId, { prompt }, {
268
+ notification: {
269
+ enabled: true,
270
+ templateVariables: { prompt }, // values for the template's variables
271
+ },
272
+ });
273
+ ```
274
+
275
+ Where the notification leads is set up on the platform for each tool, not by the SDK.
276
+ Left unset, nothing is sent and the task keeps the platform's default.
277
+
260
278
  ## Config ID
261
279
 
262
280
  `configId` runs a generation under a specific platform config. It is sent as the
@@ -478,6 +496,7 @@ Key exports (see `src/index.ts` for the full list):
478
496
  | `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` — for the custom-`fetch` path |
479
497
  | `SdkTransport` | type | The transport contract — see [Custom Transport](#custom-transport) |
480
498
  | `ServiceTier` | type | `'auto' \| 'priority'` — see [Service Tier](#service-tier) |
499
+ | `GenerationNotification` | type | `{ enabled?, templateVariables? }` — see [Completion Notifications](#completion-notifications) |
481
500
  | `GenerationOptions` | type | Poll controls for `result()`/`subscribe()` — `{ intervalMs?, maxAttempts?, signal? }` |
482
501
  | `ApiError` | class | Unified error: `{ status, code, reason, message }` — see [Error Handling](#error-handling) |
483
502
 
@@ -214,6 +214,8 @@ export type ModelInputById = {
214
214
  "qwen-image-2": { prompt: string; count?: 1 | 2 | 4 | 6 | 8 | 10; imageUrls?: string[]; };
215
215
  "qwen-image-2-pro": { prompt: string; negativePrompt?: string; resolution?: "2048x2048" | "2688x1536" | "1536x2688" | "2368x1728" | "1728x2368"; count?: 1 | 2 | 4 | 6; enhancePrompt?: boolean; imageUrls?: string[]; seed?: number; };
216
216
  "qwen-image-3.0-pro": { prompt: string; negativePrompt?: string; resolution?: "2048x2048" | "2688x1536" | "1536x2688" | "2368x1728" | "1728x2368"; count?: 1 | 2 | 4 | 6; enhancePrompt?: boolean; imageUrls?: string[]; seed?: number; promptExtendMode?: "direct" | "agent"; enableThinking?: boolean; };
217
+ "qwen-audio-3.1-tts-next": { prompt: string; audioUrls?: string[]; format?: "wav" | "mp3"; sampleRate?: 8000 | 16000 | 24000 | 44100 | 48000; channels?: 1 | 2; volume?: number; rate?: number; seed?: number; };
218
+ "qwen-audio-3.1-tts-flash": { prompt: string; voiceId?: string; format?: "mp3" | "wav"; sampleRate?: 8000 | 12000 | 16000 | 22050 | 24000 | 44100 | 48000; volume?: number; rate?: number; pitch?: number; seed?: number; };
217
219
  "recraft-creative-upscale": { imageUrls: [string, ...string[]]; };
218
220
  "recraft-crisp-upscale": { imageUrls: [string, ...string[]]; };
219
221
  "recraft-explore": { prompt: string; aspectRatio?: "1:1" | "4:3" | "3:4" | "3:2" | "2:3" | "16:9" | "9:16" | "2:1" | "1:2"; };
@@ -50,6 +50,18 @@ interface WorkflowOptions {
50
50
  price?: number;
51
51
  hasPermission?: boolean;
52
52
  missingPermissions?: string[];
53
+ rateLimitVerdict?: RateLimitVerdict;
54
+ availability?: WorkflowAvailability;
55
+ }
56
+ interface WorkflowAvailability {
57
+ status: 'available' | 'busy' | 'unavailable';
58
+ estimatedWaitSeconds?: number;
59
+ }
60
+ interface RateLimitVerdict {
61
+ type?: 'rate' | 'concurrency';
62
+ overLimit: boolean;
63
+ retryAfterSeconds: number | null;
64
+ label?: string;
53
65
  }
54
66
  type HistoryResponse<R> = PicsartResponse & {
55
67
  response: {
@@ -112,6 +124,10 @@ interface WorkflowResponse<R> {
112
124
  events?: WorkflowEvent[];
113
125
  }
114
126
  interface INotificationContext {
127
+ /** Opts the task in to (true) or out of (false) a completion notification; omitted → the task's default. */
128
+ enabled?: boolean;
129
+ /** Values for the email template's variables, e.g. `{ prompt }`. Overrides the tool config's defaults. */
130
+ templateVariables?: Record<string, string>;
115
131
  projectId?: string;
116
132
  miniappPackageId?: string;
117
133
  actions?: INotificationContextAction[];
@@ -371,4 +387,4 @@ declare class WorkflowsError extends Error {
371
387
  static fromUnknown(error: unknown): WorkflowsError;
372
388
  }
373
389
 
374
- export { type ChannelOpAck, EventTypes, ExecutionMode, ExecutionOptions, STREAM_EVENT_NAME, type SocketConnectionOptions, type SocketLike, type StreamSocketMessage, type SubscribeOptions, type WorkflowEvent, type WorkflowOptions, type WorkflowProgress, type WorkflowResponse, WorkflowStatus, WorkflowsClient, WorkflowsError, type WorkflowsErrorInit, normalizeWorkflowName, taskChannel, workflowChannel };
390
+ export { type ChannelOpAck, EventTypes, ExecutionMode, ExecutionOptions, type RateLimitVerdict, STREAM_EVENT_NAME, type SocketConnectionOptions, type SocketLike, type StreamSocketMessage, type SubscribeOptions, type WorkflowAvailability, type WorkflowEvent, type WorkflowOptions, type WorkflowProgress, type WorkflowResponse, WorkflowStatus, WorkflowsClient, WorkflowsError, type WorkflowsErrorInit, normalizeWorkflowName, taskChannel, workflowChannel };
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { WorkflowTypes, ExecutionOptions, WorkflowResponse } from './_vendor/workflows-client/index';
1
+ import { ExecutionOptions, WorkflowTypes, WorkflowResponse } from './_vendor/workflows-client/index';
2
2
  export { ExecutionMode as ApiRunMode } from './_vendor/workflows-client/index';
3
3
  export { JsonModelId, ModelInput, ModelInputById, TextModelId, TextModelInputById, TypedModelId } from './_vendor/model-types/index';
4
4
  import { ModelPricingClientOptions } from './_vendor/pa-model-pricing-sdk/index';
@@ -8,6 +8,8 @@ interface WorkflowSubmitRequest<TPayload = Record<string, unknown>> {
8
8
  workflow: string;
9
9
  payload: TPayload;
10
10
  signal?: AbortSignal;
11
+ /** submit() only: sent beside the payload as the submit body's `notification`. */
12
+ notification?: GenerationNotification;
11
13
  /**
12
14
  * Config id to run the workflow under — the caller's `configId` option. The
13
15
  * built-in transport sends it as the `x-config-id` header; unset, the
@@ -15,6 +17,12 @@ interface WorkflowSubmitRequest<TPayload = Record<string, unknown>> {
15
17
  */
16
18
  configId?: string;
17
19
  }
20
+ /**
21
+ * Asks the platform to notify the user when a generation finishes, e.g. by
22
+ * email once they have left the page, for tools that have notifications set up.
23
+ * The workflows client's notification type (not exported by name), limited to what the SDK supports.
24
+ */
25
+ type GenerationNotification = Pick<NonNullable<ExecutionOptions['notificationConfig']>, 'enabled' | 'templateVariables'>;
18
26
  interface WorkflowJobHandle {
19
27
  workflow: string;
20
28
  id: string;
@@ -1431,6 +1439,11 @@ interface GenerateOptions {
1431
1439
  * `generateText()` and `submit()`.
1432
1440
  */
1433
1441
  serviceTier?: ServiceTier;
1442
+ /**
1443
+ * Notify the user when the generation finishes — see
1444
+ * {@link GenerationNotification}. Used by `submit()` only; unset, nothing is sent.
1445
+ */
1446
+ notification?: GenerationNotification;
1434
1447
  /**
1435
1448
  * Config id to run this generation under, sent as the `x-config-id` header.
1436
1449
  * The model's workflow loads the config with this id in place of its
@@ -1764,4 +1777,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
1764
1777
  */
1765
1778
  declare const findModel: (ref: string) => ModelDefinition | undefined;
1766
1779
 
1767
- export { type AiClient, ApiError, type ApiErrorCode, type ApiErrorInit, type ApiResponse, type ApiRunOptions, type ApiSchemas, type ApisClient, type AppIdentity, type AppType, type AuthenticatedFetch, type AvatarOption, type BooleanDescriptor, type BooleanEntry, type CatalogDescriptor, type CatalogEntry, type CatalogItem, type CatalogModel, type CatalogModelsResponse, type CatalogPage, type CatalogPageOptions, type CatalogParam, type CatalogPreview, type CatalogProvider, type CatalogQuery, type CatalogResult, type CatalogSource, type CatalogsClient, type CatalogsOptions, type ClientConfig, type CreditRange, type CreditRangeContext, type CreditTier, type CreditUsage, DEFAULT_VISIBLE_RELEASES, type DeepLinkResult, type DriveAttributes, type DriveClient, type DriveConfig, type DriveDraftInfo, type DriveFile, type DriveFileDetails, type DriveFolder, type DriveMediaItem, type DriveSaveResult, type EntryMeta, type EnumDescriptor, type EnumEntry, type EnumOption, type FileDescriptor, type FileEntry, type FlatParamEntry, type GenerateOptions, type GenerateResult, type GenerateResultItem, type GenerateResultItemMetadata, type GenerateTextResult, type GenerationContext, type GenerationEvent, GenerationEventType, type GenerationFile, type GenerationMode, type GenerationOptions, type GenerationProgress, type GenerationProvenance, type InitModelCatalogOptions, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelCatalogFilters, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelMeta, type ModelParams, type ModelParamsAccessor, type ModelsCommand, type ModelsGenAIOptions, type ObjectDescriptor, type ObjectEntry, type OptionsAvailability, type OptionsResult, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsNormalizationOptions, type PayloadInputsTransformationOptions, type PriceOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type RunResponse, type SaveParams, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type ServiceTier, type TextDescriptor, type TextEntry, type ToolUsage, type TransportPollOptions, type TransportResult, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
1780
+ export { type AiClient, ApiError, type ApiErrorCode, type ApiErrorInit, type ApiResponse, type ApiRunOptions, type ApiSchemas, type ApisClient, type AppIdentity, type AppType, type AuthenticatedFetch, type AvatarOption, type BooleanDescriptor, type BooleanEntry, type CatalogDescriptor, type CatalogEntry, type CatalogItem, type CatalogModel, type CatalogModelsResponse, type CatalogPage, type CatalogPageOptions, type CatalogParam, type CatalogPreview, type CatalogProvider, type CatalogQuery, type CatalogResult, type CatalogSource, type CatalogsClient, type CatalogsOptions, type ClientConfig, type CreditRange, type CreditRangeContext, type CreditTier, type CreditUsage, DEFAULT_VISIBLE_RELEASES, type DeepLinkResult, type DriveAttributes, type DriveClient, type DriveConfig, type DriveDraftInfo, type DriveFile, type DriveFileDetails, type DriveFolder, type DriveMediaItem, type DriveSaveResult, type EntryMeta, type EnumDescriptor, type EnumEntry, type EnumOption, type FileDescriptor, type FileEntry, type FlatParamEntry, type GenerateOptions, type GenerateResult, type GenerateResultItem, type GenerateResultItemMetadata, type GenerateTextResult, type GenerationContext, type GenerationEvent, GenerationEventType, type GenerationFile, type GenerationMode, type GenerationNotification, type GenerationOptions, type GenerationProgress, type GenerationProvenance, type InitModelCatalogOptions, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelCatalogFilters, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelMeta, type ModelParams, type ModelParamsAccessor, type ModelsCommand, type ModelsGenAIOptions, type ObjectDescriptor, type ObjectEntry, type OptionsAvailability, type OptionsResult, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsNormalizationOptions, type PayloadInputsTransformationOptions, type PriceOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type RunResponse, type SaveParams, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type ServiceTier, type TextDescriptor, type TextEntry, type ToolUsage, type TransportPollOptions, type TransportResult, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
package/index.js CHANGED
@@ -2620,7 +2620,7 @@ function toApiError(err, workflow, id) {
2620
2620
 
2621
2621
  // package.json
2622
2622
  var package_default = {
2623
- version: "7.46.0"};
2623
+ version: "7.48.0"};
2624
2624
 
2625
2625
  // src/client/transport.ts
2626
2626
  var GATEWAY_HEADERS = {
@@ -2700,6 +2700,7 @@ function buildTransport(wc) {
2700
2700
  try {
2701
2701
  const id = await wc.submit(request.workflow, request.payload, {
2702
2702
  abortSignal: request.signal,
2703
+ notificationConfig: request.notification,
2703
2704
  headers: configIdHeaders(request.configId)
2704
2705
  });
2705
2706
  if (!id) {
@@ -3677,12 +3678,22 @@ function createClient(config) {
3677
3678
  if (!transport.submit) throw unsupportedTransport("submit");
3678
3679
  if (!transport.poll) throw unsupportedTransport("polling");
3679
3680
  }
3680
- async function submitJob(workflow, payload, signal, configId) {
3681
+ async function submitJob(workflow, payload, signal, configId, notification) {
3681
3682
  if (signal?.aborted) {
3682
3683
  throw new ApiError("Operation aborted", { status: 499, code: "aborted" });
3683
3684
  }
3684
3685
  if (!transport.submit) throw unsupportedTransport("submit");
3685
- const id = await transport.submit({ workflow, payload, signal, configId });
3686
+ const supportedNotification = notification && {
3687
+ enabled: notification.enabled,
3688
+ templateVariables: notification.templateVariables
3689
+ };
3690
+ const id = await transport.submit({
3691
+ workflow,
3692
+ payload,
3693
+ signal,
3694
+ configId,
3695
+ notification: supportedNotification
3696
+ });
3686
3697
  if (!id) {
3687
3698
  throw new ApiError("No task id in response", { status: 502, code: "invalid_response" });
3688
3699
  }
@@ -3892,7 +3903,7 @@ function createClient(config) {
3892
3903
  inputsNormalization: options?.inputsNormalization
3893
3904
  }, resolveServiceTier(options));
3894
3905
  try {
3895
- return await submitJob(MODELS_WORKFLOW, command, options?.signal, options?.configId);
3906
+ return await submitJob(MODELS_WORKFLOW, command, options?.signal, options?.configId, options?.notification);
3896
3907
  } catch (err) {
3897
3908
  throw toApiError2(err, options?.signal);
3898
3909
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "7.46.0",
3
+ "version": "7.48.0",
4
4
  "type": "module",
5
5
  "description": "Type-safe SDK for 100+ AI models — image, video, audio, and text generation with Picsart",
6
6
  "license": "MIT",