@picsart/ai-sdk 6.15.0 → 6.15.1

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
@@ -153,6 +153,35 @@ const folders = await ai.drive.folders()
153
153
  const items = await ai.drive.list()
154
154
  ```
155
155
 
156
+ Generated Drive assets carry `model` and JSON `aiSDKPayload` automatically. Both
157
+ `generate()` and `submit()` record the original SDK inputs; custom Drive attributes
158
+ cannot replace that provenance. These are requested inputs, not a claim that every
159
+ provider default or rewritten prompt has been recovered. The stored prompt is capped
160
+ at 18,000 characters without changing the prompt sent to generation.
161
+
162
+ `apis.run()` remains a direct vendor API pass-through. It does not apply the client’s
163
+ Drive configuration or derive SDK metadata, even when a vendor payload explicitly
164
+ requests Drive saving. Vendor-shaped inputs must never be stored as `aiSDKPayload`;
165
+ that attribute is reserved for original SDK-shaped inputs.
166
+
167
+ For a separate or delayed save, pass the original generation context:
168
+
169
+ ```typescript
170
+ await ai.drive.save({
171
+ url: generatedUrl,
172
+ name: 'clip.mp4',
173
+ resourceType: 'VIDEO',
174
+ generation: { modelId, params: originalGenerationParams },
175
+ })
176
+ // The existing helper also accepts a full params object instead of just a prompt:
177
+ const saveParams = ai.drive.buildSaveParams(generatedUrl, modelId, modelName, 'video', originalGenerationParams)
178
+ ```
179
+
180
+ Legacy `model`/`prompt`/`textScript` saves are normalized at write time. URL-only
181
+ uploads remain ordinary uploads: without generation context the SDK cannot infer
182
+ model, prompt or settings. Existing Drive files are not backfilled. The backend preserves SDK-supplied metadata; it cannot reconstruct SDK input
183
+ names or catalog model IDs from an arbitrary vendor request.
184
+
156
185
  ## Text Generation (LLMs)
157
186
 
158
187
  Claude, GPT, and Gemini text models are called with `generateText()`. Single-shot:
package/index.d.ts CHANGED
@@ -2668,11 +2668,19 @@ interface ListOptions {
2668
2668
  folder?: DriveFolder;
2669
2669
  type?: MediaTypeFilter;
2670
2670
  }
2671
+ /** Original generation inputs, portable across clients and delayed Drive saves. */
2672
+ interface GenerationProvenance {
2673
+ modelId: string;
2674
+ params: Record<string, unknown>;
2675
+ app?: AppIdentity;
2676
+ }
2671
2677
  interface SaveParams {
2672
2678
  url: string;
2673
2679
  name: string;
2674
2680
  resourceType: 'PHOTO' | 'VIDEO' | 'AUDIO';
2675
2681
  attributes?: Record<string, string>;
2682
+ /** Required to retain full provenance when saving a generated URL separately. */
2683
+ generation?: GenerationProvenance;
2676
2684
  previewUrl?: string;
2677
2685
  }
2678
2686
  /** Target folder for backend Drive save. */
@@ -2714,7 +2722,7 @@ interface DriveClient {
2714
2722
  /** Save an asset to Drive. */
2715
2723
  save(params: SaveParams, folder?: DriveFolder): Promise<DriveSaveResult | null>;
2716
2724
  /** Build the save params for a generation result. */
2717
- buildSaveParams(url: string, modelId: string, modelName: string, mode: string, prompt?: string): SaveParams;
2725
+ buildSaveParams(url: string, modelId: string, modelName: string, mode: string, promptOrParams?: string | Record<string, unknown>): SaveParams;
2718
2726
  /** Set a like/dislike reaction on a file. */
2719
2727
  addReaction(fileUid: string, reaction: UserReaction): Promise<boolean>;
2720
2728
  /** Clear the reaction on a file. */
@@ -2744,12 +2752,7 @@ declare function resolveExtension(mode: string, hints?: FilenameHints): string;
2744
2752
  */
2745
2753
  declare function expectedOutputFormat(model: Pick<ModelDefinition, 'paramConfig' | 'outputExtension'>, params: Record<string, unknown>): string | undefined;
2746
2754
  declare function buildFilename(prompt: string | undefined, mode: string, hints?: FilenameHints): string;
2747
- declare function buildGenerationAttributes(input: {
2748
- modelId: string;
2749
- params: Record<string, unknown>;
2750
- /** TODO(backend-autosave): temporary — remove once the backend stamps appId/appType. */
2751
- app?: AppIdentity;
2752
- }): DriveAttributes;
2755
+ declare function buildGenerationAttributes(input: GenerationProvenance): DriveAttributes;
2753
2756
  declare function parseGeneration(file: DriveFile | Record<string, unknown>): GenerationFile;
2754
2757
 
2755
2758
  /** Result of `ai.apis.run()` — the API result plus optional credit usage. */
@@ -3545,4 +3548,4 @@ declare const getModel: (id: string) => ModelDefinition | undefined;
3545
3548
  */
3546
3549
  declare const findModel: (ref: string) => ModelDefinition | undefined;
3547
3550
 
3548
- 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 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 ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, 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 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 };
3551
+ 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 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 ParamDescriptor, type ParamEntry, type ParamOption, type PayloadDriveFolderOptions, type PayloadDriveOptions, type PayloadInputsTransformationOptions, type PricingOptions, type ProviderInfo, type RangeDescriptor, type RangeEntry, type ReleaseTag, 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 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 };
package/index.js CHANGED
@@ -11997,6 +11997,23 @@ function buildGenerationAttributes(input) {
11997
11997
  }
11998
11998
  return attrs;
11999
11999
  }
12000
+ function attributesForSave(params2) {
12001
+ const attributes = { ...params2.attributes };
12002
+ if (params2.generation) {
12003
+ return { ...attributes, ...buildGenerationAttributes(params2.generation) };
12004
+ }
12005
+ if (asString(attributes.model)) {
12006
+ const legacy = adaptLegacyGeneration(attributes);
12007
+ const canonical = parseJsonAttr(attributes.aiSDKPayload);
12008
+ const payload = canonical && typeof canonical.prompt === "string" ? canonical : legacy.aiSDKPayload ?? {};
12009
+ return {
12010
+ ...legacy.appId ? { appId: legacy.appId, appType: legacy.appType } : {},
12011
+ ...attributes,
12012
+ ...buildGenerationAttributes({ modelId: attributes.model, params: payload })
12013
+ };
12014
+ }
12015
+ return attributes;
12016
+ }
12000
12017
  function toMediaItem(file) {
12001
12018
  const url = normalizeUrl(file.sourceUrl);
12002
12019
  if (!url || String(file.name || "").startsWith("__")) return null;
@@ -12332,7 +12349,7 @@ function createDriveClient(f, apiUrl, rootFolderName) {
12332
12349
  width: 1024,
12333
12350
  height: 1024
12334
12351
  },
12335
- attributes: Object.entries(params2.attributes ?? {}).map(([property, value]) => ({
12352
+ attributes: Object.entries(attributesForSave(params2)).map(([property, value]) => ({
12336
12353
  property,
12337
12354
  value
12338
12355
  }))
@@ -12360,15 +12377,17 @@ function createDriveClient(f, apiUrl, rootFolderName) {
12360
12377
  }
12361
12378
  },
12362
12379
  /** Build standard save params from a generation result. */
12363
- buildSaveParams(url, modelId, modelName, mode, prompt) {
12380
+ buildSaveParams(url, modelId, modelName, mode, promptOrParams) {
12381
+ const params2 = typeof promptOrParams === "string" ? { prompt: promptOrParams } : promptOrParams ?? {};
12382
+ const prompt = String(params2.prompt ?? "");
12364
12383
  return {
12365
12384
  url,
12366
12385
  name: buildFilename(prompt, mode, { url }),
12367
12386
  resourceType: inferResourceType(mode),
12368
12387
  attributes: {
12369
12388
  tool: "ai-sdk",
12370
- model: modelId,
12371
- prompt: prompt || "",
12389
+ ...buildGenerationAttributes({ modelId, params: params2 }),
12390
+ prompt,
12372
12391
  service: modelName
12373
12392
  }
12374
12393
  };
@@ -12676,8 +12695,8 @@ function createClient(config) {
12676
12695
  return {
12677
12696
  // Named before the job runs, so the requested/declared format is the best hint.
12678
12697
  name: explicit?.name ?? buildFilename(params2.prompt, model.mode, { format: expectedOutputFormat(model, params2) }),
12679
- // SDK-assembled attributes are the baseline; explicit attributes win per-key.
12680
- attributes: { ...attributes, ...explicit?.attributes ?? {} },
12698
+ // Generation provenance is authoritative; custom attributes cannot replace it.
12699
+ attributes: { ...explicit?.attributes ?? {}, ...attributes },
12681
12700
  folder: explicit?.folder ?? (folderPath ? { path: folderPath } : void 0)
12682
12701
  };
12683
12702
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picsart/ai-sdk",
3
- "version": "6.15.0",
3
+ "version": "6.15.1",
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",