@picsart/ai-sdk 7.45.0 → 7.47.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,41 @@ 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
+
278
+ ## Config ID
279
+
280
+ `configId` runs a generation under a specific platform config. It is sent as the
281
+ `x-config-id` header on every generation route — `generate()`, `generateText()`,
282
+ `run()` and `submit()` — and the model's workflow loads that config in place of
283
+ its default.
284
+
285
+ ```typescript
286
+ await ai.generate(modelId, { prompt }, { configId: 'my-config-id' });
287
+ ```
288
+
289
+ The price calls (`getCredits()`, `options()`) do not take a `configId`: they quote under the default config.
290
+
291
+ The id must exist for the model being called: a workflow that cannot find it
292
+ fails the request with `config_not_found`. Left unset, no id is sent and the
293
+ default config applies.
294
+
260
295
  ## Text Generation (LLMs)
261
296
 
262
297
  Claude, GPT, Gemini, Kimi, Grok and MiniMax text models are called with `generateText()`. Single-shot:
@@ -461,6 +496,7 @@ Key exports (see `src/index.ts` for the full list):
461
496
  | `AuthenticatedFetch` | type | `(url, init?) => Promise<Response>` — for the custom-`fetch` path |
462
497
  | `SdkTransport` | type | The transport contract — see [Custom Transport](#custom-transport) |
463
498
  | `ServiceTier` | type | `'auto' \| 'priority'` — see [Service Tier](#service-tier) |
499
+ | `GenerationNotification` | type | `{ enabled?, templateVariables? }` — see [Completion Notifications](#completion-notifications) |
464
500
  | `GenerationOptions` | type | Poll controls for `result()`/`subscribe()` — `{ intervalMs?, maxAttempts?, signal? }` |
465
501
  | `ApiError` | class | Unified error: `{ status, code, reason, message }` — see [Error Handling](#error-handling) |
466
502
 
@@ -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,7 +8,21 @@ 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;
13
+ /**
14
+ * Config id to run the workflow under — the caller's `configId` option. The
15
+ * built-in transport sends it as the `x-config-id` header; unset, the
16
+ * workflow's default config applies.
17
+ */
18
+ configId?: string;
11
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'>;
12
26
  interface WorkflowJobHandle {
13
27
  workflow: string;
14
28
  id: string;
@@ -1425,6 +1439,19 @@ interface GenerateOptions {
1425
1439
  * `generateText()` and `submit()`.
1426
1440
  */
1427
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;
1447
+ /**
1448
+ * Config id to run this generation under, sent as the `x-config-id` header.
1449
+ * The model's workflow loads the config with this id in place of its
1450
+ * default, so the id must exist for the model being called. Unset, no id is
1451
+ * sent and the default config applies. Applies to `run()`, `generate()`,
1452
+ * `generateText()` and `submit()`.
1453
+ */
1454
+ configId?: string;
1428
1455
  /**
1429
1456
  * App identity stamped onto the saved generation (appId/appType).
1430
1457
  * TODO(backend-autosave): temporary — remove once the backend stamps these.
@@ -1750,4 +1777,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
1750
1777
  */
1751
1778
  declare const findModel: (ref: string) => ModelDefinition | undefined;
1752
1779
 
1753
- 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.45.0"};
2623
+ version: "7.47.0"};
2624
2624
 
2625
2625
  // src/client/transport.ts
2626
2626
  var GATEWAY_HEADERS = {
@@ -2653,6 +2653,10 @@ function maybeFetch(config) {
2653
2653
  }
2654
2654
  return null;
2655
2655
  }
2656
+ var CONFIG_ID_HEADER = "x-config-id";
2657
+ function configIdHeaders(configId) {
2658
+ return configId ? { [CONFIG_ID_HEADER]: configId } : void 0;
2659
+ }
2656
2660
  function createWorkflowsClient(apiUrl, authedFetch) {
2657
2661
  return new WorkflowsClient_default({
2658
2662
  baseUrl: apiUrl,
@@ -2684,7 +2688,8 @@ function buildTransport(wc) {
2684
2688
  try {
2685
2689
  const res = await wc.run(request.workflow, request.payload, {
2686
2690
  mode: ExecutionMode.SYNC,
2687
- abortSignal: request.signal
2691
+ abortSignal: request.signal,
2692
+ headers: configIdHeaders(request.configId)
2688
2693
  });
2689
2694
  return asResult(res);
2690
2695
  } catch (err) {
@@ -2693,7 +2698,11 @@ function buildTransport(wc) {
2693
2698
  },
2694
2699
  async submit(request) {
2695
2700
  try {
2696
- const id = await wc.submit(request.workflow, request.payload, { abortSignal: request.signal });
2701
+ const id = await wc.submit(request.workflow, request.payload, {
2702
+ abortSignal: request.signal,
2703
+ notificationConfig: request.notification,
2704
+ headers: configIdHeaders(request.configId)
2705
+ });
2697
2706
  if (!id) {
2698
2707
  throw new ApiError("No task id in response", { status: 502, code: "invalid_response" });
2699
2708
  }
@@ -3669,12 +3678,22 @@ function createClient(config) {
3669
3678
  if (!transport.submit) throw unsupportedTransport("submit");
3670
3679
  if (!transport.poll) throw unsupportedTransport("polling");
3671
3680
  }
3672
- async function submitJob(workflow, payload, signal) {
3681
+ async function submitJob(workflow, payload, signal, configId, notification) {
3673
3682
  if (signal?.aborted) {
3674
3683
  throw new ApiError("Operation aborted", { status: 499, code: "aborted" });
3675
3684
  }
3676
3685
  if (!transport.submit) throw unsupportedTransport("submit");
3677
- const id = await transport.submit({ workflow, payload, signal });
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
+ });
3678
3697
  if (!id) {
3679
3698
  throw new ApiError("No task id in response", { status: 502, code: "invalid_response" });
3680
3699
  }
@@ -3713,13 +3732,14 @@ function createClient(config) {
3713
3732
  }
3714
3733
  async function executeDynamic(command, options) {
3715
3734
  const signal = options?.signal;
3735
+ const configId = options?.configId;
3716
3736
  const payload = command;
3717
3737
  try {
3718
3738
  if (!supportsAsync) {
3719
- const res2 = await transport.execute({ workflow: MODELS_WORKFLOW, payload, signal });
3739
+ const res2 = await transport.execute({ workflow: MODELS_WORKFLOW, payload, signal, configId });
3720
3740
  return toCompletedStatus({ workflow: MODELS_WORKFLOW, id: "" }, res2.result, res2.raw ?? res2.result, res2.usage);
3721
3741
  }
3722
- const id = await submitJob(MODELS_WORKFLOW, payload, signal);
3742
+ const id = await submitJob(MODELS_WORKFLOW, payload, signal, configId);
3723
3743
  const res = await pollJob({ workflow: MODELS_WORKFLOW, id }, pollOptionsFor(options));
3724
3744
  return asCompleted({ workflow: MODELS_WORKFLOW, id }, res);
3725
3745
  } catch (err) {
@@ -3883,7 +3903,7 @@ function createClient(config) {
3883
3903
  inputsNormalization: options?.inputsNormalization
3884
3904
  }, resolveServiceTier(options));
3885
3905
  try {
3886
- return await submitJob(MODELS_WORKFLOW, command, options?.signal);
3906
+ return await submitJob(MODELS_WORKFLOW, command, options?.signal, options?.configId, options?.notification);
3887
3907
  } catch (err) {
3888
3908
  throw toApiError2(err, options?.signal);
3889
3909
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "7.45.0",
3
+ "version": "7.47.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",