@picsart/ai-sdk 6.33.0 → 6.34.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.
Files changed (3) hide show
  1. package/index.d.ts +135 -3
  2. package/index.js +3563 -3138
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -2918,7 +2918,8 @@ interface FilenameHints {
2918
2918
  /**
2919
2919
  * Pick a file extension for a generation. Most to least reliable: the result's
2920
2920
  * MIME type, the result URL's path extension, the requested output format, then
2921
- * the mode default (png / mp4 / mp3).
2921
+ * the mode default (png / mp4 / mp3). An unknown mode resolves to '' — the
2922
+ * filename stays extension-less rather than mislabeled.
2922
2923
  */
2923
2924
  declare function resolveExtension(mode: string, hints?: FilenameHints): string;
2924
2925
  /**
@@ -3063,6 +3064,20 @@ declare class ApiError extends Error {
3063
3064
  constructor(message: string, init: ApiErrorInit);
3064
3065
  }
3065
3066
 
3067
+ /** Catalog query filters — map 1:1 onto `/v1/models-catalog` query params. */
3068
+ interface ModelCatalogFilters {
3069
+ /** Restrict to one or more generation modes (`video`, `image`, …). */
3070
+ mode?: GenerationMode | GenerationMode[];
3071
+ /** Restrict to one or more provider ids. */
3072
+ provider?: string | string[];
3073
+ /** Release tiers to request. Server default: production + general-availability. */
3074
+ release?: ReleaseTag | ReleaseTag[];
3075
+ /** Include models flagged deprecated. */
3076
+ includeDeprecated?: boolean;
3077
+ /** Free-text search across id / name / provider. */
3078
+ search?: string;
3079
+ }
3080
+
3066
3081
  /** Worker-reported progress on a generation.progress event. */
3067
3082
  type GenerationProgress = WorkflowProgress;
3068
3083
  /** A fetch-like function that handles authentication (headers, cookies, etc.). */
@@ -3086,8 +3101,34 @@ interface AppIdentity {
3086
3101
  id: string;
3087
3102
  type: AppType;
3088
3103
  }
3104
+ /**
3105
+ * How the client sources its model catalog and builds generation requests.
3106
+ * - `'static'` (default) — the bundled catalog: per-model workflows and local
3107
+ * payload builders, exactly as before.
3108
+ * - `'dynamic'` — generation routes through the models-hub `v1/models`
3109
+ * workflow (the server builds the vendor payload), and the model catalog is
3110
+ * loaded from the backend via {@link AiClient.initModelCatalog}. Until that
3111
+ * load completes, the sync accessors (`Model()`, `catalog.*`) throw
3112
+ * `ApiError` 409 `catalog_not_loaded`; `generate()`/`submit()` never wait.
3113
+ *
3114
+ * The loaded catalog is process-global (`Model()` and `catalog.*` are
3115
+ * module-level): one catalog source per process, last install wins.
3116
+ *
3117
+ * **One catalog MODE per process, too — do not mix static and dynamic
3118
+ * clients.** Creating a dynamic client flips the process-global catalog:
3119
+ * a static client in the same process then throws `catalog_not_loaded` from
3120
+ * its sync accessors until the load lands, and once the loaded catalog is
3121
+ * installed its generation pipeline would resolve definitions that carry no
3122
+ * payload builders (builders are code and never ride the wire) — producing
3123
+ * invalid vendor payloads. Run static clients in a separate process. Static
3124
+ * mode is the compatibility path and is slated for removal once all
3125
+ * consumers run dynamic.
3126
+ */
3127
+ type SdkMode = 'static' | 'dynamic';
3089
3128
  /** Settings that apply whichever transport serves the client. */
3090
3129
  interface ClientConfigBase {
3130
+ /** Catalog/generation mode — see {@link SdkMode}. Default: `'static'`. */
3131
+ mode?: SdkMode;
3091
3132
  /** Enable Drive integration — auto-save generations to a Drive folder. */
3092
3133
  drive?: DriveConfig;
3093
3134
  /**
@@ -3281,6 +3322,13 @@ interface GenerateOptions {
3281
3322
  */
3282
3323
  app?: AppIdentity;
3283
3324
  }
3325
+
3326
+ /** Options for {@link AiClient.initModelCatalog}. The endpoint is always
3327
+ * `${apiUrl}/gw-v2/v1/models-catalog` — derived from the client's `apiUrl`. */
3328
+ interface InitModelCatalogOptions {
3329
+ /** Restrict what the catalog load requests — mode, provider, release, deprecated, search. */
3330
+ filtersOptions?: ModelCatalogFilters;
3331
+ }
3284
3332
  /** Non-text (image/video/audio) model IDs — the media generation surface. */
3285
3333
  type MediaModelId = Exclude<TypedModelId, TextModelId | JsonModelId>;
3286
3334
  /** AI SDK client with type-safe, model-aware method signatures. */
@@ -3315,8 +3363,27 @@ interface AiClient {
3315
3363
  * exceptions.
3316
3364
  */
3317
3365
  subscribe(model: MediaModelId, generationId: string, options?: GenerationOptions): AsyncGenerator<GenerationEvent, void, void>;
3318
- /** Build the vendor-specific payload for a model without submitting. */
3366
+ /** Build the vendor-specific payload for a model without submitting. Static mode only. */
3319
3367
  buildPayload<M extends TypedModelId>(model: M, params: ModelInputById[M]): Record<string, unknown>;
3368
+ /**
3369
+ * Dynamic mode only: fetch the model catalog from models-hub and install it
3370
+ * as the active catalog — afterwards `Model()`, `catalog.*` and
3371
+ * `ai.validate()` serve the loaded data. The ONLY trigger for the load
3372
+ * (`createClient` never starts it). Idempotent: concurrent/repeat calls
3373
+ * share one in-flight load; a failed load may be retried. Rejects with
3374
+ * `ApiError` 400 `invalid_mode` on a static client, and 409
3375
+ * `catalog_conflict` when a different url/filters catalog is already loaded
3376
+ * in this process.
3377
+ */
3378
+ initModelCatalog(options?: InitModelCatalogOptions): Promise<void>;
3379
+ /**
3380
+ * Validate params against the model's descriptors without generating.
3381
+ * Static mode: resolves immediately off the bundled catalog. Dynamic mode:
3382
+ * awaits the catalog load started by {@link initModelCatalog} — rejects
3383
+ * with `ApiError` 409 `catalog_not_loaded` when it was never called.
3384
+ * Unknown models reject with `ApiError` 400 `unknown_model`.
3385
+ */
3386
+ validate(model: string, params: Record<string, unknown>): Promise<ValidationResult>;
3320
3387
  /**
3321
3388
  * Direct, low-level access to the Picsart model APIs — run any API by name.
3322
3389
  * See {@link ApisClient}.
@@ -3331,6 +3398,23 @@ interface AiClient {
3331
3398
  drive: DriveClient | undefined;
3332
3399
  }
3333
3400
 
3401
+ /** Platform options carried on a {@link ModelsCommand} (ModelsGenAIOptions on the backend). */
3402
+ interface ModelsGenAIOptions {
3403
+ safety_checks?: {
3404
+ enabled?: boolean;
3405
+ };
3406
+ drive?: PayloadDriveOptions;
3407
+ inputs_transformation?: {
3408
+ downscale_oversized_images?: boolean;
3409
+ };
3410
+ }
3411
+ /** The `v1/models` request body: which model, the SDK-shaped params, platform options. */
3412
+ interface ModelsCommand {
3413
+ model: string;
3414
+ params: Record<string, unknown>;
3415
+ options?: ModelsGenAIOptions;
3416
+ }
3417
+
3334
3418
  /**
3335
3419
  * Create an AI SDK client.
3336
3420
  *
@@ -3626,6 +3710,54 @@ declare const Models: {
3626
3710
 
3627
3711
  declare function getVoiceById(id: string): VoiceOption | undefined;
3628
3712
 
3713
+ /** Nested provider block — flattened onto `ModelDefinition.provider*`. */
3714
+ interface CatalogProvider {
3715
+ id: string;
3716
+ name: string;
3717
+ color: string;
3718
+ label: string;
3719
+ }
3720
+ /**
3721
+ * A param as served on the wire: the SDK's flat entry form (descriptor
3722
+ * fields merged with `label` / `required` / `category`), keyed by param
3723
+ * name instead of carrying `key`.
3724
+ */
3725
+ type CatalogParam = {
3726
+ label?: string;
3727
+ required?: boolean;
3728
+ category?: 'asset' | 'reference';
3729
+ } & ParamDescriptor;
3730
+ interface CatalogModel {
3731
+ id: string;
3732
+ name: string;
3733
+ description?: string;
3734
+ mode: GenerationMode;
3735
+ inputType: InputType;
3736
+ provider: CatalogProvider;
3737
+ badges?: BadgeType[];
3738
+ features?: ModelFeature[];
3739
+ release?: ReleaseTag;
3740
+ addedAt?: string;
3741
+ estimatedTime?: number | Record<string, number>;
3742
+ deprecated?: boolean;
3743
+ /** `include=schema` */
3744
+ params?: Record<string, CatalogParam>;
3745
+ /** `include=constraints` */
3746
+ constraints?: Constraint[];
3747
+ /** `include=routing` */
3748
+ workflow?: string;
3749
+ editWorkflow?: string;
3750
+ modelId?: string;
3751
+ syncExecute?: boolean;
3752
+ }
3753
+ interface CatalogModelsResponse {
3754
+ status: 'success';
3755
+ response: {
3756
+ total: number;
3757
+ models: CatalogModel[];
3758
+ };
3759
+ }
3760
+
3629
3761
  /**
3630
3762
  * Pricing internals — owns the ModelPricingClient, the per-model cache, and
3631
3763
  * the credit-range lookup. The Model accessor delegates to the helpers below
@@ -3758,4 +3890,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
3758
3890
  */
3759
3891
  declare const findModel: (ref: string) => ModelDefinition | undefined;
3760
3892
 
3761
- export { ALL_MODELS, 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 CatalogPage, type CatalogPageOptions, type CatalogPreview, 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 JsonModelId, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelInput, type ModelInputById, type ModelMeta, type ModelParams, type ModelParamsAccessor, Models, type ObjectDescriptor, type ObjectEntry, type OptionsResult, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type RunResponse, type SaveParams, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type TextDescriptor, type TextEntry, type TextModelId, type TextModelInputById, type ToolUsage, type TransportPollOptions, type TransportResult, type TypedModelId, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };
3893
+ export { ALL_MODELS, 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 JsonModelId, type ListOptions, type MediaModelId, type MediaTypeFilter, Model, type ModelCatalogFilters, type ModelDefinition, type ModelDescriptor, type ModelFilter, type ModelInput, type ModelInputById, type ModelMeta, type ModelParams, type ModelParamsAccessor, Models, type ModelsCommand, type ModelsGenAIOptions, type ObjectDescriptor, type ObjectEntry, type OptionsResult, type ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, type RunResponse, type SaveParams, type SdkMode, type SdkPayload, type SdkTransport, type SeedanceDraftTask, type TextDescriptor, type TextEntry, type TextModelId, type TextModelInputById, type ToolUsage, type TransportPollOptions, type TransportResult, type TypedModelId, type UnknownDescriptor, type UnknownEntry, type UserReaction, type ValidationResult, type VoiceOption, type WorkflowJobHandle, type WorkflowSubmitRequest, buildFilename, buildGenerationAttributes, catalog, createClient, decodeDeepLinkPayload, encodeDeepLinkPayload, expectedOutputFormat, findModel, getModel, getModelsByMode, getVoiceById, inferResourceType, isVisibleForReleases, parseGeneration, releaseOf, resolveExtension, toAvatarOption, toVoiceOption };